summaryrefslogtreecommitdiff
path: root/libguile/strings.c
AgeCommit message (Collapse)AuthorFilesLines
2012-10-30Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver1-0/+4
Moved scm_i_struct_hash from struct.c to hash.c and made it static. The port's alist is now a field of 'scm_t_port'. Conflicts: libguile/arrays.c libguile/hash.c libguile/ports.c libguile/print.h libguile/read.c
2012-08-17reinstate type check to scm_to_utf8_stringnAndy Wingo1-0/+4
* libguile/strings.c (scm_to_utf8_stringn): Re-add missing type check, inadvertantly removed in e3d4597469a543d97c4997b128509c2ceb13ca2b.
2012-06-22Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-3/+3
Conflicts: libguile/deprecated.c libguile/ports.c libguile/ports.h libguile/strports.c test-suite/tests/cse.test
2012-05-31Add the `%default-port-conversion-strategy' fluid.Ludovic Courtès1-3/+3
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-04-26Merge commit 'd10f7b572c0ca1ccef87f9c46069daa30946e0cf'Andy Wingo1-3/+86
Conflicts: libguile/smob.c libguile/smob.h test-suite/tests/tree-il.test
2012-04-04Fix scm_to_utf8_stringn once and for all; optimize; add testsMark H Weaver1-11/+11
* 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-03Fix scm_to_utf8_stringn to NUL-terminate properlyMark H Weaver1-1/+1
* libguile/strings.c (scm_to_utf8_stringn): NUL-terminate using the correct pointer.
2012-04-02Fix scm_to_utf8_stringn to return the length in bytes, et alMark H Weaver1-16/+36
* 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-01fix scm_to_utf8_stringn for wide strings to NUL-append the stringsAndy Wingo1-3/+66
* 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-03-08Merge remote-tracking branch 'local-2.0/stable-2.0'Andy Wingo1-1/+1
Conflicts: configure.ac libguile/finalizers.c libguile/finalizers.h libguile/gc.c libguile/gc.h libguile/inline.c libguile/inline.h libguile/ports.c libguile/smob.c libguile/smob.h module/ice-9/deprecated.scm module/ice-9/r4rs.scm
2012-03-04Don't call SYMBOL_STRINGBUF on a stringMark H Weaver1-1/+1
* libguile/strings.c (scm_i_make_symbol): Use STRING_STRINGBUF instead of SYMBOL_STRINGBUF to get the stringbuf of a string.
2012-02-23Revert "install pthread_atfork handlers for guile's static mutexen"Andy Wingo1-1/+0
This reverts commit 6a97b1f93aace5c7c976aef51d36b3ae9cfd5630.
2012-02-23Revert "wrap iconv_open / iconv_close with a lock to help in thread/fork issues"Andy Wingo1-25/+0
This reverts commit 8dfb7bbfd908ca883d0fdd0d868e13e6b20803ae.
2012-02-17wrap iconv_open / iconv_close with a lock to help in thread/fork issuesAndy Wingo1-0/+25
* libguile/bytevectors.c (STRING_TO_UTF, scm_string_to_utf8) (UTF_TO_STRING): * libguile/ports.c (open_iconv_descriptors, close_iconv_descriptors): * libguile/strings.c (scm_from_stringn, scm_to_stringn): Wrap operations that acquire and destroy iconv contexts with a mutex. While iconv is threadsafe, internally it uses a lock, and we need to make sure when we fork() that no one has that lock -- so we surround it with another one. Gross.
2012-02-17install pthread_atfork handlers for guile's static mutexenAndy Wingo1-0/+1
* libguile/async.c: * libguile/deprecation.c: * libguile/fluids.c: * libguile/gc.c: * libguile/instructions.c: * libguile/ports.c: * libguile/posix.c: * libguile/strings.c: * libguile/threads.c: Use the SCM_PTHREAD_ATFORK_LOCK_STATIC_MUTEX mechanism to lock a number of static mutexen.
2012-02-14scm_from_stringn utf8 optimizationAndy Wingo1-7/+3
* libguile/strings.c (scm_from_stringn): Optimize scm_from_stringn for utf-8.
2012-02-14fix buggy scm_from_utf8_stringn (!)Andy Wingo1-2/+2
* libguile/strings.c (scm_from_utf8_stringn): Embarassingly, my scm_from_utf8_stringn implementation was buggy for non-ascii characters, since October (41d1d984). Fixed. Will be tested with the next patch.
2012-02-11Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-26/+79
Conflicts: libguile/read.c test-suite/tests/tree-il.test
2012-02-10more efficient scm_to_utf8_stringn, scm_to_utf32_stringnAndy Wingo1-4/+52
* libguile/strings.c (scm_to_utf8_stringn): More efficient implementation than calling scm_to_stringn. (scm_to_utf32_stringn): Likewise.
2012-02-08Optimize empty substring case of scm_i_substring_copyMark H Weaver1-22/+27
* 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-08Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-1/+1
Conflicts: GUILE-VERSION libguile/gc-malloc.c libguile/ports.c
2012-02-02Improve the usage of variable names in C docstrings.Bake Timmons1-1/+1
* 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-01-30Merge commit '9b0975f1dc41ddd10d81fb5b0965b9e9a54ef37a'Andy Wingo1-29/+56
Conflicts: libguile/foreign.c module/ice-9/psyntax-pp.scm module/ice-9/psyntax.scm
2012-01-10Use a common null stringbuf in `scm_i_make_string'Mark H Weaver1-1/+15
* libguile/strings.c (scm_i_make_string): Use a common null stringbuf for newly-allocated empty strings.
2012-01-10Empty substrings no longer reference the original stringbufMark H Weaver1-19/+31
* 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-10scm_i_substring_copy tries to narrow the substringMark H Weaver1-5/+8
* libguile/strings.c (scm_i_substring_copy): Try to narrow the substring if it came from a wide string.
2012-01-10Avoid calling `u32_conv_from_encoding' on the null stringMark H Weaver1-2/+2
* 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-10Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-2/+14
Conflicts: libguile/__scm.h libguile/array-map.c libguile/procprop.c libguile/tags.h module/ice-9/deprecated.scm module/ice-9/psyntax-pp.scm module/ice-9/psyntax.scm test-suite/standalone/test-num2integral.c test-suite/tests/regexp.test
2012-01-09Remove null string optimization from scm_from_stringnMark H Weaver1-2/+0
* 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-07Fix bugs related to mutation-sharing substringsMark H Weaver1-0/+12
* 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-07Make scm_nullstr mutableMark H Weaver1-2/+2
* 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.
2011-10-25optimize scm_from_utf8_stringnAndy Wingo1-14/+93
* libguile/strings.c (decoding_error): Factor out of scm_from_stringn, properly handling errno. (scm_from_stringn): Adapt. (scm_from_utf8_stringn): Inline the conversion here, to avoid going through iconv.
2011-10-24add SCM_{PACK,UNPACK}_POINTERAndy Wingo1-2/+2
* libguile/tags.h (SCM_UNPACK_POINTER, SCM_PACK_POINTER): New macros. The old SCM2PTR and PTR2SCM were defined in such a way that round-tripping through a pointer could lose precision, even in the case in which you weren't interested in actually dereferencing the pointer, it was simply that you needed to plumb a SCM through APIs that take pointers. These new macros are more like SCM_PACK and SCM_UNPACK, but for pointer types. The bit representation of the pointer should be the same as the scm_t_bits representation. * libguile/gc.h (PTR2SCM, SCM2PTR): Remove support for (old) UNICOS pointers. We are going to try tagging the SCM object itself in the future, and I don't think that keeping this support is worth its cost. It probably doesn't work anyway. * libguile/backtrace.c: * libguile/bytevectors.c: * libguile/continuations.c: * libguile/fluids.c: * libguile/foreign.c: * libguile/gc.h: * libguile/guardians.c: * libguile/hashtab.c: * libguile/load.c: * libguile/numbers.c: * libguile/ports.c: * libguile/smob.c: * libguile/strings.c: * libguile/symbols.c: * libguile/vm.c: * libguile/weak-set.c: * libguile/weak-table.c: * libguile/weak-vector.c: Update many sites to use the new macros.
2011-10-24refactor tc7 and tc16 checksAndy Wingo1-1/+1
* libguile/tags.h (SCM_HAS_TYP7, SCM_HAS_TYP7S, SCM_HAS_TYP16): New macros. * libguile/bytevectors.h (SCM_BYTEVECTOR_P): * libguile/control.h (SCM_PROMPT_P): * libguile/filesys.h (SCM_DIRP): * libguile/fluids.h (SCM_WITH_FLUIDS_P, SCM_FLUID_P) (SCM_I_DYNAMIC_STATE_P): * libguile/foreign.h (SCM_POINTER_P): * libguile/fports.h (SCM_FPORTP): * libguile/frames.h (SCM_VM_FRAME_P): * libguile/hashtab.h (SCM_HASHTABLE_P): * libguile/inline.h (scm_get_byte_or_eof): * libguile/numbers.h (SCM_REALP, SCM_BIGP, SCM_COMPLEXP, SCM_FRACTIONP): * libguile/objcodes.h (SCM_OBJCODE_P): * libguile/ports.h (SCM_OUTPUT_PORT_P): * libguile/programs.h (SCM_PROGRAM_P): * libguile/smob.h (SCM_SMOB_PREDICATE): * libguile/srfi-14.h (SCM_CHARSETP): * libguile/strings.c (IS_STRING): * libguile/strports.h (SCM_STRPORTP): * libguile/symbols.h (scm_is_symbol): * libguile/variable.h (SCM_VARIABLEP): * libguile/vectors.h (SCM_I_IS_VECTOR, SCM_I_IS_NONWEAK_VECTOR): * libguile/vm-i-system.c (call, tail-call, mv-call) * libguile/vm.h (SCM_VM_P, SCM_VM_CONT_P): * libguile/weak-set.c (SCM_WEAK_SET_P): * libguile/weak-table.c (SCM_WEAK_TABLE_P): * libguile/weak-vector.h (SCM_I_WVECTP): Use them.
2011-09-29Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-3/+5
This was a pretty big merge involving a fair amount of porting, especially to peval and its tests. I did not update psyntax-pp.scm, that comes in the next commit. Conflicts: module/ice-9/boot-9.scm module/ice-9/psyntax-pp.scm module/language/ecmascript/compile-tree-il.scm module/language/tree-il.scm module/language/tree-il/analyze.scm module/language/tree-il/inline.scm test-suite/tests/tree-il.test
2011-09-10fix scm_to_latin1_stringn for substringsAndy Wingo1-3/+5
* 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-08-31Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-1/+1
Conflicts: libguile/bytevectors.c libguile/bytevectors.h libguile/objcodes.c libguile/r6rs-ports.c libguile/strings.c libguile/vm.c
2011-08-18fix a couple of leaksAndy Wingo1-1/+1
* 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-06-18Merge remote-tracking branch 'local-2.0/stable-2.0'Andy Wingo1-17/+24
Conflicts: module/ice-9/psyntax-pp.scm module/language/tree-il/compile-glil.scm
2011-06-16Fix several POSIX functions to use the locale encodingMark H Weaver1-17/+24
* 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-05-26Merge remote-tracking branch 'local-2.0/stable-2.0'Andy Wingo1-2/+2
2011-05-26deprecate scm_immutable_{double_,}cellAndy Wingo1-2/+2
* 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-12remove all deprecated codeAndy Wingo1-60/+0
* libguile/async.c: * libguile/async.h: * libguile/debug.h: * libguile/deprecated.c: * libguile/deprecated.h: * libguile/evalext.h: * libguile/gc-malloc.c: * libguile/gc.h: * libguile/gen-scmconfig.c: * libguile/numbers.c: * libguile/ports.c: * libguile/ports.h: * libguile/procprop.c: * libguile/procprop.h: * libguile/read.c: * libguile/socket.c: * libguile/srfi-4.h: * libguile/strings.c: * libguile/strings.h: * libguile/tags.h: * module/ice-9/boot-9.scm: * module/ice-9/deprecated.scm: Remove all deprecated code. CPP defines that were not previously issuing warnings were changed so that their expansions would indicate the replacement forms to use, e.g. scm_sizet__GONE__REPLACE_WITH__size_t. The two exceptions were SCM_LISTN, which did not produce warnings before, and the string-filter argument order stuff. Drops the initial dirty memory usage of Guile down to 2.8 MB on my machine, from 4.4 MB.
2011-05-07bytevectors have internal parent fieldAndy Wingo1-1/+1
* libguile/bytevectors.h (SCM_BYTEVECTOR_HEADER_SIZE): Bump, giving bytevectors another word: a parent pointer. Will allow for sub-bytevectors and efficient mmap bindings. * libguile/bytevectors.c (make_bytevector): (make_bytevector_from_buffer): Init parent to #f. (scm_c_take_bytevector, scm_c_take_typed_bytevector): Another argument, the parent, which gets set in the bytevector. * libguile/foreign.c (scm_pointer_to_bytevector): Use the parent field instead of registering a weak reference from bytevector to foreign pointer. * libguile/objcodes.c (scm_objcode_to_bytecode): Use the parent field to avoid copying the objcode. * libguile/srfi-4.c (DEFINE_SRFI_4_C_FUNCS): * libguile/strings.c (scm_from_stringn): * libguile/vm.c (really_make_boot_program): * libguile/r6rs-ports.c (scm_get_bytevector_some) (scm_get_bytevector_all, bytevector_output_port_procedure): Set the parent to #f.
2011-04-01latin1 subr and message in internal scm_{encoding,decoding}_errorAndy Wingo1-4/+4
* 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-03-20Make VM string literals immutable.Ludovic Courtès1-23/+27
* 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-17scm_{to,from}_locale_string use current locale, not current portsAndy Wingo1-33/+3
* 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-02-02Change `scm_encoding_error' to pass the port and faulty character.Ludovic Courtès1-12/+12
* 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-02Have `read-char' & co. throw to `decoding-error'.Ludovic Courtès1-4/+21
* 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-01-26Add `scm_{to,from}_utf32_string'.Ludovic Courtès1-0/+58
* 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'.