From: David Kastrup Date: Fri, 19 Sep 2014 11:40:35 +0000 (+0200) Subject: Issue 4325: Replace most uses of scm_{from,to}_locale_* with fixed encodings X-Git-Tag: release/2.19.18-1~13 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=55ff9f5a64a00b6c369be47eb8ca3949250f120b;p=lilypond.git Issue 4325: Replace most uses of scm_{from,to}_locale_* with fixed encodings 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. --- diff --git a/lily/dynamic-performer.cc b/lily/dynamic-performer.cc index 1ed800a03a..6a6f8b8cf9 100644 --- a/lily/dynamic-performer.cc +++ b/lily/dynamic-performer.cc @@ -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)) diff --git a/lily/engraver.cc b/lily/engraver.cc index e2fbe860c0..959a778454 100644 --- a/lily/engraver.cc +++ b/lily/engraver.cc @@ -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; diff --git a/lily/font-config-scheme.cc b/lily/font-config-scheme.cc index a273bcea14..a2bc3ae5d0 100644 --- a/lily/font-config-scheme.cc +++ b/lily/font-config-scheme.cc @@ -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); diff --git a/lily/general-scheme.cc b/lily/general-scheme.cc index 068fb27aad..4e11cc1feb 100644 --- a/lily/general-scheme.cc +++ b/lily/general-scheme.cc @@ -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)); } diff --git a/lily/grob-interface.cc b/lily/grob-interface.cc index d444d3d71d..6c99c849ed 100644 --- a/lily/grob-interface.cc +++ b/lily/grob-interface.cc @@ -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); diff --git a/lily/grob-property.cc b/lily/grob-property.cc index 779f0e91cb..9c6590c5ec 100644 --- a/lily/grob-property.cc +++ b/lily/grob-property.cc @@ -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; diff --git a/lily/guile-init.cc b/lily/guile-init.cc index 975cab0c2b..67ed72822a 100644 --- a/lily/guile-init.cc +++ b/lily/guile-init.cc @@ -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; diff --git a/lily/include/lily-guile-macros.hh b/lily/include/lily-guile-macros.hh index 1196f1ec5d..5fc1c8e7dd 100644 --- a/lily/include/lily-guile-macros.hh +++ b/lily/include/lily-guile-macros.hh @@ -22,6 +22,25 @@ #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 /* diff --git a/lily/lexer.ll b/lily/lexer.ll index 89c8695987..1dd9554d02 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -368,7 +368,7 @@ BOM_UTF8 \357\273\277 {RESTNAME}/[-_] | // pseudo backup rule {RESTNAME} { char const *s = YYText (); - yylval = scm_from_locale_string (s); + yylval = scm_from_ascii_string (s); return RESTNAME; } q/[-_] | // pseudo backup rule @@ -508,11 +508,11 @@ BOM_UTF8 \357\273\277 { \\{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); } } diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index 6896d43d7c..dce8760836 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -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); } /* diff --git a/lily/lily-lexer.cc b/lily/lily-lexer.cc index 4ddd864325..6c118979ae 100644 --- a/lily/lily-lexer.cc +++ b/lily/lily-lexer.cc @@ -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); diff --git a/lily/lookup.cc b/lily/lookup.cc index 9bef343fed..6bd55bbc7d 100644 --- a/lily/lookup.cc +++ b/lily/lookup.cc @@ -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 diff --git a/lily/lyric-engraver.cc b/lily/lyric-engraver.cc index 56ce20dada..0d3ea00dee 100644 --- a/lily/lyric-engraver.cc +++ b/lily/lyric-engraver.cc @@ -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", diff --git a/lily/main.cc b/lily/main.cc index 808274c6e8..69af225c76 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -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 diff --git a/lily/open-type-font-scheme.cc b/lily/open-type-font-scheme.cc index bba695ba00..ed45d86b19 100644 --- a/lily/open-type-font-scheme.cc +++ b/lily/open-type-font-scheme.cc @@ -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, diff --git a/lily/open-type-font.cc b/lily/open-type-font.cc index c6ca27def3..255d5e2b18 100644 --- a/lily/open-type-font.cc +++ b/lily/open-type-font.cc @@ -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); } diff --git a/lily/pango-font.cc b/lily/pango-font.cc index 4212e21392..762e0842f3 100644 --- a/lily/pango-font.cc +++ b/lily/pango-font.cc @@ -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; diff --git a/lily/parser.yy b/lily/parser.yy index 8a050f0ef9..2c324f5000 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -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 diff --git a/lily/pfb-scheme.cc b/lily/pfb-scheme.cc index f8a6c1278f..4a13515472 100644 --- a/lily/pfb-scheme.cc +++ b/lily/pfb-scheme.cc @@ -20,7 +20,7 @@ LY_DEFINE (ly_pfb_2_pfa, "ly:pfb->pfa", vector 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); diff --git a/lily/piano-pedal-engraver.cc b/lily/piano-pedal-engraver.cc index 02c8dff869..546351a0b9 100644 --- a/lily/piano-pedal-engraver.cc +++ b/lily/piano-pedal-engraver.cc @@ -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 ()); diff --git a/lily/source-file.cc b/lily/source-file.cc index 69b18e90e5..1118b9d286 100644 --- a/lily/source-file.cc +++ b/lily/source-file.cc @@ -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_)); } diff --git a/lily/translator.cc b/lily/translator.cc index 5798a0061c..ca96aa5429 100644 --- a/lily/translator.cc +++ b/lily/translator.cc @@ -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_) diff --git a/lily/ttf.cc b/lily/ttf.cc index 6a68f00c3d..c46b9e9f75 100644 --- a/lily/ttf.cc +++ b/lily/ttf.cc @@ -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); diff --git a/lily/tweak-engraver.cc b/lily/tweak-engraver.cc index 560cabfc4f..81138b3670 100644 --- a/lily/tweak-engraver.cc +++ b/lily/tweak-engraver.cc @@ -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)) {