1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 20:00:19 +02:00
Commit graph

210 commits

Author SHA1 Message Date
Mark H Weaver
9f0ec10fc9 Implement 'string-utf8-length' and 'scm_c_string_utf8_length'.
* libguile/strings.c (utf8_length, scm_c_string_utf8_length)
  (scm_string_utf8_length): New functions.
* libguile/strings.h (scm_c_string_utf8_length, scm_string_utf8_length):
  New prototypes.
* doc/ref/api-data.texi (Bytevectors as Strings): Add docs.
* doc/ref/guile.texi: Update manual copyright date to 2015.
* test-suite/tests/strings.test (string-utf8-length): Add tests.
2015-03-01 22:04:07 -05:00
Mark H Weaver
60617d819d Fix thread-unsafe lazy initializations.
* libguile/backtrace.c (print_exception_var): New static variable.
  (init_print_exception_var): New static function.
  (scm_print_exception): Remove thread-unsafe lazy initialization.
  Call 'init_print_exception_var' using 'scm_i_pthread_once'.
  Use 'print_exception_var'.

* libguile/continuations.c (call_cc): New static variable.
  (init_call_cc): New static function.
  (scm_i_call_with_current_continuation): Remove thread-unsafe lazy
  initialization.  Call 'init_call_cc' using 'scm_i_pthread_once'.

* libguile/debug.c (local_eval_var): New static variable.
  (init_local_eval_var): New static function.
  (scm_local_eval): Remove lazy initialization using mutexes.
  Call 'init_local_eval_var' using 'scm_i_pthread_once'.
  Use 'scm_variable_ref' instead of 'SCM_VARIABLE_REF'.

* libguile/eval.c (map_var, for_each_var): New static variables.
  (init_map_var, init_for_each_var): New static functions.
  (scm_map, scm_for_each): Remove thread-unsafe lazy initializations.
  Call 'init_map_var' (or 'init_for_each_var') using 'scm_i_pthread_once'.
  Use 'map_var' (or 'for_each_var').

* libguile/frames.c (frame_arguments_var): New static variable.
  (init_frame_arguments_var): New static function.
  (scm_frame_arguments): Remove thread-unsafe lazy initialization.
  Call 'init_frame_arguments_var' using 'scm_i_pthread_once'.
  Use 'frame_arguments_var'.  Use 'scm_variable_ref' instead of
  'SCM_VARIABLE_REF'.

* libguile/goops.c (delayed_compile_var): New static variable.
  (init_delayed_compile_var): New static function.
  (make_dispatch_procedure): Remove thread-unsafe lazy initialization.
  Call 'init_delayed_compile_var' using 'scm_i_pthread_once'.
  Use 'delayed_compile_var'.  Use 'scm_variable_ref' instead of
  'SCM_VARIABLE_REF'.

* libguile/instructions.c (instructions_by_name): New static variable.
  (init_instructions_by_name): New static function.
  (scm_lookup_instruction_by_name): Remove thread-unsafe lazy
  initialization.  Call 'init_instructions_by_name' using
  'scm_i_pthread_once'.

* libguile/ports.c (current_warning_port_var)
  (current_warning_port_once): New static variables.
  (init_current_warning_port_var): New static function.
  (scm_current_warning_port): Remove lazy initialization using mutexes.
  Call 'init_current_warning_port_var' using 'scm_i_pthread_once'.
  Use 'current_warning_port_var'.
  (scm_set_current_warning_port): Remove thread-unsafe lazy initialization.
  Call 'init_current_warning_port_var' using 'scm_i_pthread_once'.
  Use 'current_warning_port_var'.

* libguile/strings.c (null_stringbuf): New static variable.
  (init_null_stringbuf): New static function.
  (scm_i_make_string): Remove thread-unsafe lazy initialization.
  Call 'init_null_stringbuf' using 'scm_i_pthread_once'.

* libguile/strports.c (eval_string_var, k_module): New static variables.
  (init_eval_string_var_and_k_module): New static function.
  (scm_eval_string_in_module): Remove lazy initialization using mutexes.
  Call 'init_eval_string_var_and_k_module' using 'scm_i_pthread_once'.
  Use 'eval_string_var'.

* libguile/throw.c (CACHE_VAR): Remove incorrect macro.
  (catch_var, throw_var, with_throw_handler_var): New static variables.
  (scm_catch, scm_catch_with_pre_unwind_handler): Remove thread-unsafe
  lazy initialization.  Use 'catch_var'.
  (init_with_throw_handler_var): New static function.
  (scm_with_throw_handler): Remove thread-unsafe lazy initialization.
  Call 'init_with_throw_handler_var' using 'scm_i_pthread_once'.
  Use 'with_throw_handler_var'.
  (scm_throw): Remove thread-unsafe lazy initialization.
  Use 'throw_var'.
  (scm_init_throw): Initialize 'catch_var' and 'throw_var'.
2014-01-23 23:44:11 -05:00
Mark H Weaver
2f13a46672 Make 'string-append' more efficient and robust.
* libguile/strings.c (scm_string_append): Check for numerical overflow
  while computing the length of the result.  Double-check that we don't
  overflow the result string, and that it is the correct length in the
  end (in case another thread changed the list).  When copying a narrow
  string to a wide result, avoid calling 'scm_i_string_length' and
  'scm_i_string_chars' on each character.
2013-04-01 03:47:09 -04:00
Andy Wingo
ee26a9ebe2 reinstate type check to scm_to_utf8_stringn
* libguile/strings.c (scm_to_utf8_stringn): Re-add missing type check,
  inadvertantly removed in e3d4597469.
2012-08-17 16:42:46 +02:00
Ludovic Courtès
b22e94db7c Add the `%default-port-conversion-strategy' fluid.
Fixes <http://bugs.gnu.org/11468>.

* libguile/ports.c (scm_conversion_strategy): Remove.
  (default_conversion_strategy_var, sym_error, sym_substitute,
  sym_escape): New variables.
  (scm_i_get_conversion_strategy, scm_i_set_conversion_strategy_x):
  Remove.
  (scm_i_default_port_conversion_handler,
  scm_i_set_default_port_conversion_handler): New functions.
  (scm_port_conversion_strategy): Use
  `scm_i_default_port_conversion_handler' when PORT is #f.
  (scm_set_port_conversion_strategy_x): Use SYM_ERROR, SYM_SUBSTITUTE,
  and SYM_ESCAPE.  Use `scm_i_set_default_port_conversion_handler' when
  PORT is #f.
  (scm_init_ports): Initialize DEFAULT_CONVERSION_STRATEGY_VAR.

* libguile/ports.h: Update declarations accordingly.

* libguile/foreign.c: Change
  `scm_i_get_conversion_strategy (SCM_BOOL_F)' to
  `scm_i_default_port_conversion_handler ()'.
* libguile/strings.c: Likewise.

* test-suite/tests/ports.test ("%default-port-conversion-strategy"): New
  test prefix.

* test-suite/tests/foreign.test ("pointer<->string")["%default-port-conversion-strategy
  is error", "%default-port-conversion-strategy is soft"]: New tests.

* test-suite/test-suite/lib.scm (exception:encoding-error): Allow the
  regexp to match `scm_to_stringn' error messages.

* doc/ref/api-io.texi (Ports): Document `%default-port-conversion-strategy'.
2012-05-31 00:50:36 +02:00
Mark H Weaver
bbb9f000ad Fix scm_to_utf8_stringn once and for all; optimize; add tests
* libguile/strings.c (scm_to_utf8_stringn): Fix another new bug in this
  recent comedy of errors: pass the size of the preallocated buffer to
  u32_to_u8.  Arrange to call 'scm_i_string_wide_chars' and
  'scm_i_string_length' only once each.  Rename local variables for
  improved code clarity.

* test-suite/standalone/test-conversion.c (test_to_utf8_stringn): New
  function to test scm_to_utf8_stringn.
2012-04-04 18:58:44 -04:00
Mark H Weaver
51853eee69 Fix scm_to_utf8_stringn to NUL-terminate properly
* libguile/strings.c (scm_to_utf8_stringn): NUL-terminate using the
  correct pointer.
2012-04-03 09:50:20 -04:00
Mark H Weaver
e26da7a24e Fix scm_to_utf8_stringn to return the length in bytes, et al
* libguile/strings.c (u32_u8_length_in_bytes): Internal static function
  renamed from u32_u8_strlen, whose name was potentially confusing.  For
  added safety, handle everything that can be encoded in the more
  general UTF-8 encoding: up to six bytes for each code point, with code
  points up to 2^31-1.

  (scm_to_utf8_stringn): NUL-terminate only if (lenp == NULL).
  If (lenp != NULL) return the length in bytes in *lenp.
2012-04-02 18:55:45 -04:00
Andy Wingo
2c1b79513b fix scm_to_utf8_stringn for wide strings to NUL-append the strings
* libguile/strings.c (u32_u8_strlen, scm_to_utf8_stringn): Sigh, fix the
  u32-to-u8 optimization to ensure that the utf8 string is
  NUL-terminated.
2012-04-01 14:07:07 -07:00
Mark H Weaver
1a4d765381 Don't call SYMBOL_STRINGBUF on a string
* libguile/strings.c (scm_i_make_symbol): Use STRING_STRINGBUF
  instead of SYMBOL_STRINGBUF to get the stringbuf of a string.
2012-03-04 22:47:04 -05:00
Andy Wingo
e3d4597469 more efficient scm_to_utf8_stringn, scm_to_utf32_stringn
* libguile/strings.c (scm_to_utf8_stringn): More efficient
  implementation than calling scm_to_stringn.
  (scm_to_utf32_stringn): Likewise.
2012-02-10 13:42:15 +01:00
Mark H Weaver
d5b75b6c80 Optimize empty substring case of scm_i_substring_copy
* libguile/strings.c (scm_i_substring_copy): When asked to create an
  empty substring, use 'scm_i_make_string' to make use of its
  optimization for empty strings that reuses the global null_stringbuf.
2012-02-08 15:29:10 -05:00
Bake Timmons
b7e64f8b26 Improve the usage of variable names in C docstrings.
* libguile/alist.c:
* libguile/array-map.c:
* libguile/arrays.c:
* libguile/bitvectors.c:
* libguile/filesys.c:
* libguile/foreign.c:
* libguile/generalized-arrays.c:
* libguile/hashtab.c:
* libguile/ioext.c:
* libguile/load.c:
* libguile/numbers.c:
* libguile/ports.c:
* libguile/posix.c:
* libguile/print.c:
* libguile/procprop.c:
* libguile/promises.c:
* libguile/simpos.c:
* libguile/socket.c:
* libguile/srfi-1.c:
* libguile/srfi-13.c:
* libguile/srfi-14.c:
* libguile/stacks.c:
* libguile/stime.c:
* libguile/strings.c:
* libguile/struct.c:
* libguile/symbols.c:
* libguile/threads.c:
* libguile/weak-table.c:
* libguile/weak-vector.c: Make the variable names in the C docstrings more
  consistent.  Replace a few instances of @var with @code when appropriate.
2012-02-02 12:22:10 +01:00
Mark H Weaver
69cd5299e3 Use a common null stringbuf in `scm_i_make_string'
* libguile/strings.c (scm_i_make_string): Use a common null stringbuf
  for newly-allocated empty strings.
2012-01-10 10:13:43 -05:00
Mark H Weaver
17bec5451b Empty substrings no longer reference the original stringbuf
* libguile/strings.c (scm_i_substring, scm_i_substring_read_only,
  scm_i_substring_shared): When asked to create an empty substring,
  return a freshly allocated null string.  Previously, an empty
  substring needlessly held a reference to the original stringbuf.
2012-01-10 09:39:57 -05:00
Mark H Weaver
d6a569c191 scm_i_substring_copy tries to narrow the substring
* libguile/strings.c (scm_i_substring_copy): Try to narrow the substring
  if it came from a wide string.
2012-01-10 07:50:28 -05:00
Mark H Weaver
7532125912 Avoid calling `u32_conv_from_encoding' on the null string
* libguile/strings.c (scm_from_stringn): Avoid calling
  `u32_conv_from_encoding' on the null string, by using the same
  fast-path code used if (encoding == NULL).  This is an optimization,
  and also avoids any possible encoding errors.
2012-01-10 06:33:17 -05:00
Mark H Weaver
86c63a8251 Remove null string optimization from scm_from_stringn
* libguile/strings.c (scm_from_stringn): Always return a freshly
  allocated string from scm_from_stringn, even when asked to construct
  the null string, in accordance with the R5RS.  Previously, we
  optimized the null string case by returning a reference to a global
  null string object (scm_nullstr).
2012-01-09 18:24:22 -05:00
Mark H Weaver
49d09292ac Fix bugs related to mutation-sharing substrings
* libguile/strings.c (scm_i_is_narrow_string, scm_i_try_narrow_string,
  scm_i_string_set_x): Check to see if the provided string is a
  mutation-sharing substring, and do the right thing in that case.
  Previously, if such a string was passed to these functions, they would
  behave very badly: while trying to fetch and/or mutate the cell
  containing the stringbuf, they were actually fetching or mutating the
  cell containing the original shared string.  That's because
  mutation-sharing substrings store the original string in CELL_1,
  whereas all other strings store the stringbuf there.
2012-01-07 10:36:22 -05:00
Mark H Weaver
a7e392c1ff Make scm_nullstr mutable
* libguile/strings.c (scm_init_strings): Make scm_nullstr mutable.  It
  is still usable as a common object, because of course it contains no
  characters to mutate anyway.  It is returned by several procedures
  that are specified to return mutable strings, and string mutators
  raise errors when passed an immutable string, even if it is the null
  string.
2012-01-07 04:46:46 -05:00
Andy Wingo
fe13364050 fix scm_to_latin1_stringn for substrings
* libguile/strings.c (scm_to_latin1_stringn): Fix for substrings.

* test-suite/standalone/Makefile.am:
* test-suite/standalone/test-scm-to-latin1-string.c: Add test case.

  Thanks to David Hansen for the bug report and test case, and Stefan
  Israelsson Tampe for the fix.
2011-09-10 11:38:25 -07:00
Andy Wingo
fb031aba42 fix a couple of leaks
* libguile/bytevectors.h:
* libguile/bytevectors.c (scm_c_take_gc_bytevector): Rename this
  internal function, from scm_c_take_bytevector.  This indicates that
  unlike the other scm_take_* functions, this one takes GC-managed
  memory.

* libguile/objcodes.c (scm_objcode_to_bytecode):
* libguile/vm.c (really_make_boot_program): Use
  scm_gc_malloc_pointerless, not scm_malloc.  Thanks to Stefan
  Israelsson Tampe!

* libguile/r6rs-ports.c:
* libguile/strings.c: Adapt to renames.
2011-08-18 12:53:28 +02:00
Mark H Weaver
7505c6e024 Fix several POSIX functions to use the locale encoding
* libguile/strings.c (scm_i_allocate_string_pointers): Encode strings
  using the current locale.  Previously, Latin-1 was used.  Indirectly,
  this affects the encoding of strings in `system*', `execl', `execlp',
  `execle', `environ', and `dynamic-args-call'.

  (scm_makfromstrs): In header comment, clarify that the C strings are
  interpreted according to the current locale encoding.

* NEWS: Add NEWS entry.
2011-06-16 15:07:30 -04:00
Andy Wingo
65619ebe9a deprecate scm_immutable_{double_,}cell
* libguile/inline.h:
* libguile/deprecated.h:
* libguile/deprecated.c (scm_immutable_cell, scm_immutable_double_cell):
  Deprecate these, as the GC_STUBBORN API doesn't do anything any more.

* libguile/strings.c (scm_i_c_make_symbol): Change the one use of
  scm_immutable_double_cell to scm_double_cell.
2011-05-26 12:34:30 +02:00
Andy Wingo
d050ef66ec latin1 subr and message in internal scm_{encoding,decoding}_error
* libguile/strings.c (scm_encoding_error, scm_decoding_error): Use
  scm_from_latin1_string for the subr and message args, as these are
  internal functions, and we know their callers.
2011-04-01 11:05:37 +02:00
Ludovic Courtès
190d4b0d93 Make VM string literals immutable.
* libguile/strings.c (scm_i_make_string, scm_i_make_wide_string): Add
  `read_only_p' parameter.  All callers updated.

* libguile/vm-i-loader.c (load_string, load_wide_string): Push read-only
  strings.

* test-suite/tests/strings.test ("literals"): New test prefix.
2011-03-20 23:34:42 +01:00
Andy Wingo
95f5e303bc scm_{to,from}_locale_string use current locale, not current ports
* libguile/strings.c (scm_to_locale_stringn, scm_from_locale_stringn):
  Use the encoding of the current locale, not of the current i/o ports.
  Also use the current conversion strategy.

* doc/ref/api-data.texi (Conversion to/from C): Update docs.
2011-03-17 18:29:08 +01:00
Ludovic Courtès
6851d3be80 Change `scm_encoding_error' to pass the port and faulty character.
* libguile/strings.c (scm_encoding_error): Remove the `from', `to', and
  `string_or_bv' parameters; add `port' and `chr'.
  (scm_to_stringn): Update accordingly.

* libguile/strings.h (scm_encoding_error): Update accordingly.

* libguile/ports.c (scm_ungetc): Update accordingly.

* libguile/print.c (iprin1, scm_write_char): Update accordingly.

* test-suite/tests/encoding-escapes.test ("display output
  errors")["ultima", "Rashomon"]: Check the arguments of
  `encoding-error'.
  ["tekniko"]: New test.

* test-suite/tests/ports.test ("string ports")["wrong encoding"]: Adjust
  to new `encoding-error' arguments.
2011-02-02 18:06:29 +01:00
Ludovic Courtès
c62da8f891 Have read-char' & co. throw to decoding-error'.
* libguile/ports.c (scm_read_char): Mention `decoding-error' in the
  docstring.
  (get_codepoint): Change to return an error code; add `codepoint'
  output parameter.  Don't raise an error from here.
  (scm_getc): Raise an error with `scm_decoding_error' if
  `get_codepoint' returns an error.
  (scm_peek_char): Likewise.  Update docstring.

* libguile/strings.c (scm_decoding_error_key): New variable.
  (scm_decoding_error): New function.
  (scm_from_stringn): Use `scm_decoding_error' instead of
  `scm_encoding_error'.

* libguile/strings.h (scm_decoding_error): New declaration.

* test-suite/tests/ports.test ("string ports")["read-char, wrong
  encoding, error"]: Change to expect `decoding-error'.  Make sure PORT
  points past the error.
  ["read-char, wrong encoding, escape"]: Likewise.
  ["peek-char, wrong encoding, error"]: New test.

* test-suite/tests/r6rs-ports.test ("7.2.11 Binary
  Output")["put-bytevector with wrong-encoding string port"]: Change to
  expect `decoding-error'.
  ("8.2.6  Input and output ports")["transcoded-port [error handling
  mode = raise]"]: Likewise.

* test-suite/tests/rdelim.test ("read-line")["decoding error", "decoding
  error, substitute"]: New tests.

* doc/ref/api-io.texi (Reading): Update documentation of `read-char' and
  `peek-char'.
  (Line/Delimited): Update documentation of `read-line'.
2011-02-02 18:06:28 +01:00
Ludovic Courtès
647dc1ac23 Add `scm_{to,from}_utf32_string'.
* libguile/strings.c (scm_from_utf32_string, scm_from_utf32_stringn,
  scm_to_utf32_string, scm_to_utf32_stringn): New functions.

* libguile/strings.h (scm_from_utf32_string, scm_from_utf32_stringn,
  scm_to_utf32_string, scm_to_utf32_stringn): New declarations.

* doc/ref/api-data.texi (Conversion to/from C): Document
  `scm_{to,from}_{utf8,utf32}_stringn'.
2011-01-26 00:29:50 +01:00
Ludovic Courtès
e9a35a965b Optimize `scm_{to,from}_latin1_string'.
* libguile/strings.c (scm_from_latin1_stringn): Directly return a narrow
  string instead of going through `scm_from_stringn'.
  (scm_to_latin1_stringn): Directly return a copy of STR's raw bytes when
  it's narrow.
2011-01-26 00:29:50 +01:00
Ludovic Courtès
31d4d02be7 Hide the string escaping hacks.
* libguile/strings.c (scm_i_unistring_escapes_to_guile_escapes): Rename
  to...
  (unistring_escapes_to_guile_escapes): ... this.  Make `static'.
  (scm_i_unistring_escapes_to_r6rs_escapes): Rename to...
  (unistring_escapes_to_r6rs_escapes): ... this.  Make `static'.

* libguile/strings.h (scm_i_unistring_escapes_to_guile_escapes,
  scm_i_unistring_escapes_to_r6rs_escapes): Remove declarations.
2011-01-23 00:37:25 +01:00
Andy Wingo
a574564c24 fix scm_from_stringn empty string case
* libguile/strings.c (scm_from_stringn): Fix empty string case
  (oops...).
2011-01-07 22:16:10 -08:00
Andy Wingo
4a655e50a3 use scm_from_latin1_symboln for string literals and load-symbol
* libguile/bytevectors.c:
* libguile/eval.c:
* libguile/goops.c:
* libguile/i18n.c:
* libguile/load.c:
* libguile/memoize.c:
* libguile/modules.c:
* libguile/ports.c:
* libguile/print.c:
* libguile/procs.c:
* libguile/programs.c:
* libguile/read.c:
* libguile/script.c:
* libguile/srfi-14.c:
* libguile/stacks.c:
* libguile/strings.c:
* libguile/throw.c:
* libguile/vm.c: Use scm_from_latin1_symboln to make symbols from string
  literals, because they aren't in the user's locale -- they are in
  ASCII, and we can optimize this case.

* libguile/vm-i-loader.c: Also use scm_from_latin1_symboln when loading
  narrow symbols.
2011-01-07 09:18:41 -08:00
Andy Wingo
d40e1ca893 add scm_{to,from}_{utf8,latin1}_string{n,}
* libguile/strings.h:
* libguile/strings.c (scm_from_latin1_string, scm_to_latin1_string): New
  functions, in terms of the latin1_stringn variants.
  (scm_from_utf8_string, scm_from_utf8_stringn)
  (scm_to_utf8_string, scm_to_utf8_stringn): New functions.
  (scm_i_from_utf8_string, scm_i_to_utf8_string): Removed these internal
  functions.
  (scm_from_stringn): Handle -1 as a length. Unlike the previous
  behavior of scm_from_locale_string (NULL), which returned the empty
  string, we now raise an error.  The null pointer is not the same as
  the empty string.

* libguile/stime.c (scm_strftime, scm_strptime): Adapt to publishing of
  utf8 functions.
2011-01-07 09:18:36 -08:00
Ludovic Courtès
183f784947 Inline `scm_is_string'.
* libguile/strings.c (scm_is_string): Move to...
* libguile/inline.h (scm_is_string): ... here.  Inline.
2010-12-16 23:45:23 +01:00
Andy Wingo
3ef6650def make-string et al nulls memory if not given an initializer
* libguile/gc-malloc.c: Add a note that the gc-malloc does not clear the
  memory block, so users need to make sure it is initialized.

* libguile/bitvectors.c (scm_c_make_bitvector):
* libguile/bytevectors.c (scm_make_bytevector):
* libguile/strings.c (scm_c_make_string): If no initializer is given,
  initialize the bytes to 0. Prevents information leakage if an app uses
  make-string et al without initializers.

* libguile/foreign.c (make_cif): Initialize this too, to prevent leakage
  in the struct holes. Paranoia...
2010-12-04 19:31:20 +01:00
Ludovic Courtès
cdd47ec7e5 Include <alloca.h> wherever `alloca' is used.
Patch provided by <carlo.bramix@libero.it> (tiny change).

* libguile/control.c, libguile/fluids.c, libguile/foreign.c,
  libguile/hashtab.c, libguile/strings.c: Include <alloca.h>.
2010-11-19 14:14:53 +01:00
Ludovic Courtès
f1ee6d54d2 Fix write-beyond-end-of-string error in the conversion to R6RS string escapes.
Reported by Mike Gran <spk121@yahoo.com>.

* libguile/strings.c (scm_i_unistring_escapes_to_guile_escapes,
  scm_i_unistring_escapes_to_r6rs_escapes): Augment comments.
  (scm_to_stringn): When `handler ==
  SCM_FAILED_CONVERSION_ESCAPE_SEQUENCE && SCM_R6RS_ESCAPES_P', realloc
  BUF so that it's large enough for the worst case.

* libguile/print.c (display_character): When `result != NULL && strategy
  == SCM_FAILED_CONVERSION_ESCAPE_SEQUENCE && SCM_R6RS_ESCAPES_P', make
  LOCALE_ENCODED large enough to hold an R6RS escape.
2010-09-15 23:32:28 +02:00
Ludovic Courtès
4ff2b9f4b6 Internally expose `scm_i_unistring_escapes_to_{guile,r6rs}_escapes'.
* libguile/strings.c (unistring_escapes_to_guile_escapes): Rename to...
  (scm_i_unistring_escapes_to_guile_escapes): ... this.  Change `char **bufp'
  to `char *buf'; leave realloc responsibility to the caller.  Update caller.
  (unistring_escapes_to_r6rs_escapes): Rename to...
  (scm_i_unistring_escapes_to_r6rs_escapes): ... this.  Likewise.
2010-09-14 16:10:08 +02:00
Michael Gran
cf313a947b Provide non-locale C/Scheme string conversion functions
* doc/ref/api-data.texi: document scm_to_stringn, scm_from_stringn,
  scm_to_latin1_stringn, and scm_from_latin1_stringn
* libguile/strings.h (scm_to_stringn): make public
  (scm_to_latin1_stringn): new declaration
  (scm_from_latin1_stringn): new declaration
* libguile/strings.c (scm_to_latin1_stringn): new function
  (scm_from_latin1_stringn): new function
2010-09-12 08:29:31 -07:00
Ludovic Courtès
d14418a535 Expose `scm_encoding_error'.
* libguile/strings.c (scm_encoding_error): Make public.

* libguile/strings.h (scm_encoding_error): New internal declaration.
2010-07-15 23:12:57 +02:00
Ludovic Courtès
100e20c7fa Add `scm_i_string_data'.
* libguile/strings.c (STRINGBUF_CONTENTS): New macro.
  (STRINGBUF_CHARS, STRINGBUF_WIDE_CHARS): Use it.
  (scm_i_string_data): New function.

* libguile/strings.h (scm_i_string_data): New declaration.
2010-07-04 18:38:53 +02:00
Ludovic Courtès
ef7e4ba373 Improve encoding error reporting.
* libguile/strings.c (scm_encoding_error): Change arguments to convey
  more information.  Raise the error with `scm_throw ()', passing all
  the information to the handler.
  (scm_from_stringn, scm_to_stringn): Update accordingly.

* test-suite/tests/ports.test ("string ports")["wrong encoding"]: Check
  the arguments passed to the `throw' handler.

* test-suite/tests/r6rs-ports.test ("7.2.11 Binary
  Output")["put-bytevector with wrong-encoding string port"]: Likewise.
2010-03-18 20:41:03 +01:00
Michael Gran
d31b951951 R6RS string escapes broken on string output
scm_to_stringn failed to do the necessary escape conversion for
R6RS hex escapes

* libguile/strings.c (unistring_escapes_to_r6rs_escapes): new function
  (scm_to_stringn): use new function when r6rs hex escapes are enabled

* test-suite/tests/reader.test: new test for string display
2010-01-23 09:21:46 -08:00
Ludovic Courtès
a3d7d5d508 Use encoding-error' instead of misc-error' for string encoding errors.
* libguile/strings.c (scm_encoding_error): New function.
  (scm_from_stringn, scm_to_stringn): Use it instead of `scm_misc_error ()'.

* test-suite/lib.scm (exception:encoding-error): Adjust accordingly.

* test-suite/tests/encoding-escapes.test (exception:conversion):
  Remove.  Use `exception:encoding-error' instead.

* test-suite/tests/encoding-iso88591.test: Likewise.

* test-suite/tests/encoding-iso88597.test: Likewise.

* test-suite/tests/encoding-utf8.test: Likewise.
2010-01-07 11:10:35 +01:00
Ludovic Courtès
29bcdbb059 Add in-source documentation of `scm_to_stringn ()'.
* libguile/strings.c (scm_to_stringn): Add documentation comment.
2010-01-07 11:10:35 +01:00
Julian Graham
d8164b046c Attempt to narrow normalized strings.
* libguile/strings.c (normalize_str): Clean up indentation.  Add call to
  scm_i_try_narrow_string.
2010-01-06 23:03:22 -05:00
Julian Graham
edb7bb4766 Support for Unicode string normalization functions
* libguile/strings.c, libguile/strings.h (normalize_str,
  scm_string_normalize_nfc, scm_string_normalize_nfd, scm_normalize_nfkc,
  scm_string_normalize_nfkd): New functions.
* test-suite/tests/strings.test: Unit tests for `string-normalize-nfc',
  `string-normalize-nfd', `string-normalize-nfkc', and
  `string-normalize-nfkd'.
* doc/ref/api-data.texi (String Comparison): Documentation for normalization
  functions.
2010-01-03 01:08:37 -05:00
Andy Wingo
c5f171027d fix bug in string array implementation type mask
* libguile/strings.c (SCM_ARRAY_IMPLEMENTATION): The mask for the string
  array implementation should be 0x7f, without masking out 0x2.
  Otherwise numbers were being thought to be vectors!

* test-suite/tests/unif.test: Add test.

* libguile/vectors.c (SCM_ARRAY_IMPLEMENTATION): Only register one
  implementation, because weak vectors can be checked with the mask &
  ~2, and the functions are the same.
2009-12-29 13:29:02 +01:00