]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4325: Replace most uses of scm_{from,to}_locale_* with fixed encodings
authorDavid Kastrup <dak@gnu.org>
Fri, 19 Sep 2014 11:40:35 +0000 (13:40 +0200)
committerDavid Kastrup <dak@gnu.org>
Mon, 23 Mar 2015 11:10:29 +0000 (12:10 +0100)
Most are either identifiable as utf8, or as byte stream (more or less
called latin1) or pure ASCII.

Since conversion to C++ strings is factored through separate (and too
few) functions, those accesses are not yet reordered in a satisfactory
manner.

24 files changed:
lily/dynamic-performer.cc
lily/engraver.cc
lily/font-config-scheme.cc
lily/general-scheme.cc
lily/grob-interface.cc
lily/grob-property.cc
lily/guile-init.cc
lily/include/lily-guile-macros.hh
lily/lexer.ll
lily/lily-guile.cc
lily/lily-lexer.cc
lily/lookup.cc
lily/lyric-engraver.cc
lily/main.cc
lily/open-type-font-scheme.cc
lily/open-type-font.cc
lily/pango-font.cc
lily/parser.yy
lily/pfb-scheme.cc
lily/piano-pedal-engraver.cc
lily/source-file.cc
lily/translator.cc
lily/ttf.cc
lily/tweak-engraver.cc

index 1ed800a03ab6b3efdf7c6872819458f5a1371b31..6a6f8b8cf9acefceb7235547568556133609388e 100644 (file)
@@ -87,7 +87,7 @@ Dynamic_performer::equalize_volume (Real volume)
         s = get_property ("instrumentName");
 
       if (!scm_is_string (s))
-        s = scm_from_locale_string ("piano");
+        s = scm_from_ascii_string ("piano");
 
       SCM eq = get_property ("instrumentEqualizer");
       if (ly_is_procedure (eq))
index e2fbe860c092a44cf2e2b0f40a9174c4c2027711..959a7784546ffda9d51fc24f022b6607f647a4e6 100644 (file)
@@ -138,8 +138,8 @@ Engraver::internal_make_grob (SCM symbol,
 #ifndef NDEBUG
   if (ly_is_procedure (creation_callback))
     scm_apply_0 (creation_callback,
-                 scm_list_n (grob->self_scm (), scm_from_locale_string (file),
-                             scm_from_int (line), scm_from_locale_string (fun), SCM_UNDEFINED));
+                 scm_list_n (grob->self_scm (), scm_from_utf8_string (file),
+                             scm_from_int (line), scm_from_ascii_string (fun), SCM_UNDEFINED));
 #endif
 
   return grob;
index a273bcea144d3d1ddee053fbe2a78d5c16e9810c..a2bc3ae5d0f7111df71e39ff11cbbb3b05a827ff 100644 (file)
@@ -120,7 +120,7 @@ LY_DEFINE (ly_font_config_get_font_file, "ly:font-config-get-font-file", 1, 0, 0
   pat = FcFontMatch (NULL, pat, &result);
   FcChar8 *str = 0;
   if (FcPatternGetString (pat, FC_FILE, 0, &str) == FcResultMatch)
-    scm_result = scm_from_locale_string ((char const *)str);
+    scm_result = scm_from_utf8_string ((char const *)str);
 
   FcPatternDestroy (pat);
 
index 068fb27aad255427f4c6239bfa8c370242985a19..4e11cc1feb9b0fa5e910a29ba6b61b998368545d 100644 (file)
@@ -96,7 +96,7 @@ LY_DEFINE (ly_gulp_file, "ly:gulp-file",
     }
 
   string contents = gulp_file_to_string (ly_scm2string (name), true, sz);
-  return scm_from_locale_stringn (contents.c_str (), contents.length ());
+  return scm_from_latin1_stringn (contents.c_str (), contents.length ());
 }
 
 LY_DEFINE (ly_dir_p, "ly:dir?",
@@ -239,7 +239,7 @@ LY_DEFINE (ly_number_2_string, "ly:number->string",
   else
     snprintf (str, sizeof (str), "%d", int (scm_to_int (s)));
 
-  return scm_from_locale_string (str);
+  return scm_from_ascii_string (str);
 }
 
 LY_DEFINE (ly_version, "ly:version", 0, 0, 0, (),
@@ -254,7 +254,7 @@ LY_DEFINE (ly_version, "ly:version", 0, 0, 0, (),
 LY_DEFINE (ly_unit, "ly:unit", 0, 0, 0, (),
            "Return the unit used for lengths as a string.")
 {
-  return scm_from_locale_string (INTERNAL_UNIT);
+  return scm_from_ascii_string (INTERNAL_UNIT);
 }
 
 LY_DEFINE (ly_dimension_p, "ly:dimension?", 1, 0, 0, (SCM d),
@@ -342,7 +342,7 @@ LY_DEFINE (ly_wide_char_2_utf_8, "ly:wide-char->utf-8",
     }
   *p = 0;
 
-  return scm_from_locale_string (buf);
+  return scm_from_utf8_string (buf);
 }
 
 LY_DEFINE (ly_effective_prefix, "ly:effective-prefix",
@@ -506,7 +506,7 @@ format_single_argument (SCM arg, int precision, bool escape = false)
     return (ly_symbol2string (arg));
   else
     {
-      ly_progress (scm_from_locale_string ("\nUnsupported SCM value for format: ~a"),
+      ly_progress (scm_from_ascii_string ("\nUnsupported SCM value for format: ~a"),
                    scm_list_1 (arg));
     }
 
index d444d3d71dd1cdaf97fb3cd46dcbb79c63d5c0f1..6c99c849ed804805283c213573e411dc487606c9 100644 (file)
@@ -37,7 +37,7 @@ SCM add_interface (char const *cxx_name,
     lispy_name += suffix;
 
   SCM s = ly_symbol2scm (lispy_name.c_str ());
-  SCM d = scm_from_locale_string (descr);
+  SCM d = scm_from_utf8_string (descr);
   SCM l = parse_symbol_list (vars);
 
   internal_add_interface (s, d, l);
index 779f0e91cbcb4712deb96e765e5f4db4f8c4c506..9c6590c5ec1f613c76c71fdf89bc729cdfd250e0 100644 (file)
@@ -83,7 +83,7 @@ Grob::instrumented_set_property (SCM sym, SCM v,
                  scm_list_n (self_scm (),
                              scm_from_locale_string (file),
                              scm_from_int (line),
-                             scm_from_locale_string (fun),
+                             scm_from_ascii_string (fun),
                              sym, v, SCM_UNDEFINED));
 #else
   (void) file;
index 975cab0c2bb8b769c56ff8ea6e0d54269985a397..67ed72822ace306853e6b9ac6dd33a3867c1dc9a 100644 (file)
@@ -51,7 +51,7 @@ ly_init_ly_module (void *)
       debug_output ("]\n", false);
     }
 
-  scm_primitive_load_path (scm_from_locale_string ("lily.scm"));
+  scm_primitive_load_path (scm_from_ascii_string ("lily.scm"));
 }
 
 SCM global_lily_module;
index 1196f1ec5dd683eef581b8f5654296b9c7a44f29..5fc1c8e7dd45a57a71985a307c7257b3151ff754 100644 (file)
 
 #include "config.hh"
 
+#if GUILEV2
+// if Guile's internal representation switches to utf8, this should be
+// changed accordingly for efficiency's sake.  This is used for
+// strings known to be in ASCII entirely, including any string
+// constants in the C code.
+#define scm_from_ascii_string scm_from_latin1_string
+#define scm_from_ascii_stringn scm_from_latin1_stringn
+#define scm_from_ascii_symbol scm_from_latin1_symbol
+#else
+#define scm_from_ascii_string scm_from_locale_string
+#define scm_from_ascii_stringn scm_from_locale_stringn
+#define scm_from_ascii_symbol scm_from_locale_symbol
+#define scm_from_latin1_string scm_from_locale_string
+#define scm_from_latin1_stringn scm_from_locale_stringn
+#define scm_from_utf8_string scm_from_locale_string
+#define scm_from_utf8_symbol scm_from_locale_symbol
+#define scm_to_utf8_string scm_to_locale_string
+#endif
+
 #ifndef SMOB_FREE_RETURN_VAL
 #define SMOB_FREE_RETURN_VAL(CL) 0
 #endif
@@ -48,7 +67,7 @@ typedef SCM (*scm_t_subr) (GUILE_ELLIPSIS);
 /* this lets us "overload" macros such as get_property to take
    symbols as well as strings */
 inline SCM
-scm_or_str2symbol (char const *c) { return scm_from_locale_symbol (c); }
+scm_or_str2symbol (char const *c) { return scm_from_utf8_symbol (c); }
 
 inline SCM
 scm_or_str2symbol (SCM s)
@@ -77,7 +96,7 @@ scm_or_str2symbol (SCM s)
     value;                                                              \
   })
 #else
-inline SCM ly_symbol2scm (char const *x) { return scm_from_locale_symbol ((x)); }
+inline SCM ly_symbol2scm (char const *x) { return scm_from_utf8_symbol ((x)); }
 #endif
 
 /*
index 89c8695987af4ef8b71e2a18d74dc964e70738b0..1dd9554d025b43540c1fbf9c62a0ecbbe9ba2b6a 100644 (file)
@@ -368,7 +368,7 @@ BOM_UTF8    \357\273\277
 <chords,notes,figures>{RESTNAME}/[-_]  |  // pseudo backup rule
 <chords,notes,figures>{RESTNAME}       {
        char const *s = YYText ();
-       yylval = scm_from_locale_string (s);
+       yylval = scm_from_ascii_string (s);
        return RESTNAME;
 }
 <chords,notes,figures>q/[-_]   | // pseudo backup rule
@@ -508,11 +508,11 @@ BOM_UTF8  \357\273\277
 <quote,commandquote>{
        \\{ESCAPED}     {
                 char c = escaped_char (YYText ()[1]);
-               yylval = scm_cons (scm_from_locale_stringn (&c, 1),
+               yylval = scm_cons (scm_from_ascii_stringn (&c, 1),
                                    yylval);
        }
        [^\\""]+        {
-                yylval = scm_cons (scm_from_locale_string (YYText_utf8 ()),
+                yylval = scm_cons (scm_from_utf8_string (YYText_utf8 ()),
                                    yylval);
        }
        \"      {
@@ -533,7 +533,7 @@ BOM_UTF8    \357\273\277
                return STRING;
        }
        \\      {
-                yylval = scm_cons (scm_from_locale_string (YYText ()),
+                yylval = scm_cons (scm_from_ascii_string (YYText ()),
                                    yylval);
        }
 }
index 6896d43d7c2c9ed269d4fe6ff95d9bf5b2a7a686..dce87608364bfd17b449a860b1864c65772dbd8a 100644 (file)
@@ -144,7 +144,7 @@ ly_string2scm (string const &str)
 char *
 ly_scm2str0 (SCM str)
 {
-  return scm_to_locale_string (str);
+  return scm_to_utf8_string (str);
 }
 
 /*
index 4ddd8643252585b2c5e032e20f1e1455a73a3c44..6c118979ae39e4dca10bbd01e9926985129ffd07 100644 (file)
@@ -193,7 +193,7 @@ Lily_lexer::keyword_list () const
   SCM *tail = &l;
   for (vsize i = 0; i < keytable_->table_.size (); i++)
     {
-      *tail = scm_acons (scm_from_locale_string (keytable_->table_[i].name_),
+      *tail = scm_acons (scm_from_utf8_string (keytable_->table_[i].name_),
                          scm_from_int (keytable_->table_[i].tokcode_),
                          SCM_EOL);
 
index 9bef343fedd5625714c1e6846ef1b7ee64a41c1d..6bd55bbc7d3826ced290d51bb8f0ff537e4a54c9 100644 (file)
@@ -121,7 +121,7 @@ Lookup::horizontal_line (Interval w, Real th)
 Stencil
 Lookup::blank (Box b)
 {
-  return Stencil (b, scm_from_locale_string (""));
+  return Stencil (b, scm_string (SCM_EOL));
 }
 
 Stencil
index 56ce20dadac66a7ef4b223dd7b6b066e7475bbe6..0d3ea00dee27448243201e2cb2fa6686e2ebc2ab 100644 (file)
@@ -70,7 +70,7 @@ Lyric_engraver::process_music ()
     {
       SCM text = event_->get_property ("text");
 
-      if (ly_is_equal (text, scm_from_locale_string (" ")))
+      if (ly_is_equal (text, scm_from_ascii_string (" ")))
         {
           if (last_text_)
             last_text_->set_property ("self-alignment-X",
index 808274c6e843c5959853a2d032279631690b4196..69af225c7651f4c117b34b050abcea564aa1a1d2 100644 (file)
@@ -480,8 +480,8 @@ main_with_guile (void *, int, char **)
    //  " \"" + lilypond_datadir + "/scm/out\")";
    //scm_c_eval_string (scm_pct_set_fallback.c_str() );
    scm_primitive_eval
-     (scm_list_3 (scm_from_locale_symbol ("set!"),
-                  scm_from_locale_symbol ("%compile-fallback-path"),
+     (scm_list_3 (scm_from_latin1_symbol ("set!"),
+                  scm_from_latin1_symbol ("%compile-fallback-path"),
                   scm_from_locale_string (ly_scm_go_dir.c_str())));
 #endif
 
index bba695ba00c147c5412cfd3934f877f7322501c2..ed45d86b192a9cc5c7d05533b550da2f052175cd 100644 (file)
@@ -70,7 +70,7 @@ LY_DEFINE (ly_otf_font_table_data, "ly:otf-font-table-data", 2, 0, 0,
 
   string tab = otf->get_otf_table (string (ctag));
 
-  return scm_from_locale_stringn ((char const *) tab.data (), tab.length ());
+  return scm_from_latin1_stringn ((char const *) tab.data (), tab.length ());
 }
 
 LY_DEFINE (ly_otf_font_p, "ly:otf-font?", 1, 0, 0,
index c6ca27def33d1fcbcae0e9e9204db5379c290ff1..255d5e2b18ca8f36c1e30cc8bf15faf0ea2a6b6f 100644 (file)
@@ -77,7 +77,11 @@ load_scheme_table (char const *tag_str, FT_Face face)
       string contents ((char const *)buffer, length);
       contents = "(quote (" + contents + "))";
 
+#if GUILEV2
+      tab = scm_eval_string (scm_from_utf8_string (contents.c_str ()));
+#else
       tab = scm_c_eval_string (contents.c_str ());
+#endif
       free (buffer);
     }
   return tab;
@@ -337,7 +341,7 @@ Open_type_font::glyph_list () const
         warning (_f ("FT_Get_Glyph_Name () error: %s",
                      freetype_error_string (code).c_str ()));
 
-      *tail = scm_cons (scm_from_locale_string (name), SCM_EOL);
+      *tail = scm_cons (scm_from_ascii_string (name), SCM_EOL);
       tail = SCM_CDRLOC (*tail);
     }
 
index 4212e213928d14b3c86f9b82650492144c56b898..762e0842f3db9a6889ba8ebd85c9de99bd04944f 100644 (file)
@@ -290,7 +290,7 @@ Pango_font::pango_item_string_stencil (PangoGlyphItem const *glyph_item) const
           char_id = scm_from_uint32 (pg);
         }
       else
-        char_id = scm_from_locale_string (glyph_name);
+        char_id = scm_from_utf8_string (glyph_name);
 
       PangoRectangle logical_sub_rect;
       PangoRectangle ink_sub_rect;
index 8a050f0ef938ee091a29fcb455d62caa90eb0d6f..2c324f50000117b5d872af8751883371ec3037a8 100644 (file)
@@ -3002,25 +3002,25 @@ fingering:
 
 script_abbreviation:
        '^'             {
-               $$ = scm_from_locale_string ("Hat");
+               $$ = scm_from_ascii_string ("Hat");
        }
        | '+'           {
-               $$ = scm_from_locale_string ("Plus");
+               $$ = scm_from_ascii_string ("Plus");
        }
        | '-'           {
-               $$ = scm_from_locale_string ("Dash");
+               $$ = scm_from_ascii_string ("Dash");
        }
        | '!'           {
-               $$ = scm_from_locale_string ("Bang");
+               $$ = scm_from_ascii_string ("Bang");
        }
        | ANGLE_CLOSE   {
-               $$ = scm_from_locale_string ("Larger");
+               $$ = scm_from_ascii_string ("Larger");
        }
        | '.'           {
-               $$ = scm_from_locale_string ("Dot");
+               $$ = scm_from_ascii_string ("Dot");
        }
        | '_' {
-               $$ = scm_from_locale_string ("Underscore");
+               $$ = scm_from_ascii_string ("Underscore");
        }
        ;
 
@@ -3751,7 +3751,7 @@ Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
 SCM
 get_next_unique_context_id ()
 {
-       return scm_from_locale_string ("$uniqueContextId");
+       return scm_from_ascii_string ("$uniqueContextId");
 }
 
 
@@ -3761,7 +3761,7 @@ get_next_unique_lyrics_context_id ()
        static int new_context_count;
        char s[128];
        snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
-       return scm_from_locale_string (s);
+       return scm_from_ascii_string (s);
 }
 
 // check_scheme_arg checks one argument with a given predicate for use
index f8a6c1278f38ab7a530ef0d36533c1739401f889..4a1351547230abd68d06c72ad882778c09be4f88 100644 (file)
@@ -20,7 +20,7 @@ LY_DEFINE (ly_pfb_2_pfa, "ly:pfb->pfa",
   vector<char> pfb_string = gulp_file (file_name, 0);
   char *pfa = pfb2pfa ((Byte *) &pfb_string[0], pfb_string.size ());
 
-  SCM pfa_scm = scm_from_locale_string (pfa);
+  SCM pfa_scm = scm_from_latin1_string (pfa);
   free (pfa);
 
   debug_output ("]", false);
@@ -41,7 +41,7 @@ LY_DEFINE (ly_otf_2_cff, "ly:otf->cff",
   FT_Face face = open_ft_face (file_name, 0 /* index */);
   string table = get_otf_table (face, "CFF ");
 
-  SCM asscm = scm_from_locale_stringn ((char *) table.data (),
+  SCM asscm = scm_from_latin1_stringn ((char *) table.data (),
                                        table.length ());
 
   debug_output ("]", false);
index 02c8dff8691e9487fc8eb9ffc740ece512013ad1..546351a0b9a2f8cb1620e5fc7615a18306786f2d 100644 (file)
@@ -166,9 +166,9 @@ init_pedal_types ()
         be careful, as we don't want to loose references to the _sym_ members.
        */
       Pedal_type_info info;
-      info.event_class_sym_ = scm_from_locale_symbol ((base_ident + "-event").c_str ());
-      info.style_sym_ = scm_from_locale_symbol (("pedal" + base_name + "Style").c_str ());
-      info.strings_sym_ = scm_from_locale_symbol (("pedal" + base_name + "Strings").c_str ());
+      info.event_class_sym_ = scm_from_ascii_symbol ((base_ident + "-event").c_str ());
+      info.style_sym_ = scm_from_ascii_symbol (("pedal" + base_name + "Style").c_str ());
+      info.strings_sym_ = scm_from_ascii_symbol (("pedal" + base_name + "Strings").c_str ());
 
       info.base_name_ = name;
       info.pedal_c_str_ = strdup ((base_name + "Pedal").c_str ());
index 69b18e90e5440bc6a5d4a643e91b38fee84ee1fe..1118b9d286ee29a823c6ce0b2a7d6041a9ed19aa 100644 (file)
@@ -148,7 +148,10 @@ Source_file::Source_file (const string &filename_string)
 void
 Source_file::init_port ()
 {
-  SCM str = scm_from_locale_string (c_str ());
+  // This is somewhat icky: the string will in general be in utf8, but
+  // we do our own utf8 encoding and verification in the parser, so we
+  // use the no-conversion equivalent of latin1
+  SCM str = scm_from_latin1_string (c_str ());
   str_port_ = scm_mkstrport (SCM_INUM0, str, SCM_OPN | SCM_RDNG, __FUNCTION__);
   scm_set_port_filename_x (str_port_, ly_string2scm (name_));
 }
index 5798a0061c15d195bd8d008af773f1211d833fb3..ca96aa5429e2c696732520150f4b204706f65b41 100644 (file)
@@ -154,7 +154,7 @@ Translator::add_translator_listener (translator_listener_record **listener_list,
   // the static translator_listener_record chains while garbage
   // collecting.
 
-  SCM class_sym = scm_permanent_object (scm_from_locale_symbol (name.c_str ()));
+  SCM class_sym = scm_permanent_object (scm_from_ascii_symbol (name.c_str ()));
 
   r->event_class_ = class_sym;
   r->get_listener_ = get_listener;
@@ -178,7 +178,7 @@ Translator::static_translator_description (const char *grobs,
                                  parse_symbol_list (grobs), static_properties);
 
   static_properties = scm_acons (ly_symbol2scm ("description"),
-                                 scm_from_locale_string (desc), static_properties);
+                                 scm_from_utf8_string (desc), static_properties);
 
   SCM list = SCM_EOL;
   for (; listener_list; listener_list = listener_list->next_)
index 6a68f00c3d4697f9af9f39f65c3ea2c07e011ede..c46b9e9f75ed0343b0e3e4e1798cff2273444cb5 100644 (file)
@@ -570,7 +570,7 @@ LY_DEFINE (ly_ttf_2_pfa, "ly:ttf->pfa",
   Memory_out_stream stream;
 
   create_type42_font (&stream, file_name, i);
-  SCM asscm = scm_from_locale_stringn (stream.get_string (),
+  SCM asscm = scm_from_latin1_stringn (stream.get_string (),
                                        stream.get_length ());
 
   debug_output ("]", false);
index 560cabfc4f2f50f21b5305e19cc373a3cb4959a8..81138b3670ebd749b84f360b06ca99ac5eb13195 100644 (file)
@@ -60,7 +60,7 @@ Tweak_engraver::acknowledge_grob (Grob_info info)
               if (scm_is_symbol (scm_caaar (s)))
                 {
                   if (SCM_UNBNDP (grobname))
-                    grobname = scm_from_locale_symbol
+                    grobname = scm_from_utf8_symbol
                       (info.grob ()->name ().c_str ());
                   if (scm_is_eq (scm_caaar (s), grobname))
                     {