diff --git a/lily/guile-init.cc b/lily/guile-init.cc index 4270aa01d6..c1bbf7e650 100644 --- a/lily/guile-init.cc +++ b/lily/guile-init.cc @@ -56,6 +56,14 @@ ly_init_ly_module () for (vsize i = scm_init_funcs_->size (); i--;) (scm_init_funcs_->at (i)) (); +#if GUILEV2 + // We need binary ports for any of our standard input operations, + // and the precompiled API calls for those crash inexplicably if we + // have not explicitly loaded the module anyway. + // Cf . + (void) scm_c_resolve_module ("ice-9 binary-ports"); +#endif + if (is_loglevel (LOG_DEBUG)) { debug_output ("[", true); diff --git a/lily/include/lily-imports.hh b/lily/include/lily-imports.hh index cc61ea7d9a..1276d2dea7 100644 --- a/lily/include/lily-imports.hh +++ b/lily/include/lily-imports.hh @@ -37,6 +37,7 @@ namespace Guile_user { extern Variable module_use_x; extern Variable symbol_p; extern Variable the_root_module; + extern Variable default_port_encoding; } namespace Display { diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index f37380f024..9b7e62320c 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -126,12 +126,13 @@ ly_scm2string (SCM str) { assert (scm_is_string (str)); string result; - size_t len = scm_c_string_length (str); + size_t len; + char *c_string = scm_to_locale_stringn (str, &len); if (len) { - result.resize (len); - scm_to_locale_stringbuf (str, &result.at (0), len); + result.assign (c_string, len); } + free (c_string); return result; } diff --git a/lily/lily-imports.cc b/lily/lily-imports.cc index 5bb4863168..e0aaa36788 100644 --- a/lily/lily-imports.cc +++ b/lily/lily-imports.cc @@ -33,6 +33,7 @@ namespace Guile_user { Variable module_use_x ("module-use!"); Variable symbol_p ("symbol?"); Variable the_root_module ("the-root-module"); + Variable default_port_encoding ("%default-port-encoding"); } namespace Display { diff --git a/lily/paper-outputter-scheme.cc b/lily/paper-outputter-scheme.cc index 145e9bfa93..ad3b74f344 100644 --- a/lily/paper-outputter-scheme.cc +++ b/lily/paper-outputter-scheme.cc @@ -44,6 +44,9 @@ LY_DEFINE (ly_make_paper_outputter, "ly:make-paper-outputter", progress_indication ("\n"); Paper_outputter *po = new Paper_outputter (port, f); + if (f == "ps") + scm_set_port_encoding_x(port, ly_string2scm("ISO-8859-1")); + po->unprotect (); return po->self_scm (); } diff --git a/lily/parse-scm.cc b/lily/parse-scm.cc index 576591dc97..20627ed96b 100644 --- a/lily/parse-scm.cc +++ b/lily/parse-scm.cc @@ -54,7 +54,14 @@ internal_ly_parse_scm (Parse_start *ps) if (multiple) (void) scm_read_char (port); +#if GUILEV2 + SCM current_encoding = scm_port_encoding (port); + scm_set_port_encoding_x (port, ly_string2scm("UTF-8")); SCM form = scm_read (port); + scm_set_port_encoding_x (port, current_encoding); +#else + SCM form = scm_read (port); +#endif SCM to = scm_ftell (port); hi.set (hi.get_source_file (), diff --git a/lily/source-file.cc b/lily/source-file.cc index 14fdf2beb3..7a8d290524 100644 --- a/lily/source-file.cc +++ b/lily/source-file.cc @@ -41,6 +41,7 @@ using namespace std; #include "international.hh" #include "misc.hh" #include "warn.hh" +#include "lily-imports.hh" void Source_file::load_stdin () @@ -151,8 +152,22 @@ Source_file::init_port () // 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 +#if GUILEV2 + SCM str = scm_c_make_bytevector (length () - 1); + memcpy (SCM_BYTEVECTOR_CONTENTS (str), c_str (), length () - 1); + // Setting %default-port-encoding to binary before calling + // open-bytevector-input-port appears quite unnecessary regarding + // the documented semantics, but at least GUILE 2.0.11 is not + // particularly interested in sticking to its documentation. + // + scm_dynwind_begin ((scm_t_dynwind_flags)0); + scm_dynwind_fluid (Guile_user::default_port_encoding, SCM_BOOL_F); + str_port_ = scm_open_bytevector_input_port (str, SCM_UNDEFINED); + scm_dynwind_end (); +#else SCM str = scm_from_latin1_string (c_str ()); str_port_ = scm_mkstrport (SCM_INUM0, str, SCM_OPN | SCM_RDNG, __FUNCTION__); +#endif scm_set_port_filename_x (str_port_, ly_string2scm (name_)); } diff --git a/ly/init.ly b/ly/init.ly index 394b122f31..8fdc6e2b17 100644 --- a/ly/init.ly +++ b/ly/init.ly @@ -7,7 +7,10 @@ \version "2.19.22" #(if (guile-v2) - (use-modules (ice-9 curried-definitions))) + (begin + (use-modules (ice-9 curried-definitions)) + (setlocale LC_ALL "") + (setlocale LC_NUMERIC "C"))) #(session-initialize (lambda ()