summaryrefslogtreecommitdiff
path: root/libguile/strings.c
AgeCommit message (Collapse)AuthorFilesLines
2009-08-09More comments for string functionsMichael Gran1-16/+59
* libguile/strings.c: comments
2009-08-08Add Unicode strings and symbolsMichael Gran1-104/+545
This adds full Unicode strings as a datatype, and it adds some minimal functionality. The terminal and port encoding is assumed to be ISO-8859-1. Non-ISO-8859-1 characters are written or input as string character escapes. The string character escapes now have 3 forms: \xXX \uXXXX and \UXXXXXX, for unprintable characters that have 2, 4 or 6 hex digits. The process for writing to strings has been modified. There is now a function scm_i_string_start_writing that does the copy-on-write conversion if necessary. To compile strings that may be wide, the VM storage of strings and string-likes has changed. Most string-using functions have not yet been updated and may break when used with wide strings. * module/language/assembly/compile-bytecode.scm (write-bytecode): use variable width string bytecode format * module/language/assembly.scm (byte-length): use variable width bytecode format * libguile/vm-i-loader.c (load-string, load-symbol): (load-keyword, define): use variable-width bytecode format * libguile/vm-engine.h (FETCH_WIDTH): new macro * libguile/strings.h: new declarations * libguile/strings.c (make_wide_stringbuf): new function (widen_stringbuf): new function (scm_i_make_wide_string): new function (scm_i_is_narrow_string): new function (scm_i_string_wide_chars): new function (scm_i_string_start_writing): new function (scm_i_string_ref): new function (scm_i_string_set_x): new function (scm_i_is_narrow_symbol): new function (scm_i_symbol_wide_chars, scm_i_symbol_ref): new function (scm_string_width): new function (unistring_escapes_to_guile_escapes): new function (scm_to_stringn): new function (scm_i_stringbuf_free): modify for wide strings (scm_i_substring_copy): modify for wide strings (scm_i_string_chars, scm_string_append): modify for wide strings (scm_i_make_symbol, scm_to_locale_stringn): modify for wide strings (scm_string_dump, scm_symbol_dump, scm_to_locale_stringbuf): (scm_string, scm_i_deprecated_string_chars): modify for wide strings (scm_from_locale_string, scm_from_locale_stringn): add null test * libguile/srfi-13.c: add calls for scm_i_string_start_writing for each call of scm_i_string_stop_writing (scm_string_for_each): modify for wide strings * libguile/socket.c: add calls for scm_i_string_start_writing for each call of scm_i_string_stop_writing * libguile/rw.c: add calls for scm_i_string_start_writing for each call of scm_i_string_stop_writing * libguile/read.c (scm_read_string): allow reading of wide strings * libguile/print.h: add declaration for scm_charprint * libguile/print.c (iprin1): print wide strings and add new string escapes (scm_charprint): new function * libguile/ports.h: new declarations for scm_lfwrite_substr and scm_lfwrite_str * libguile/ports.c (update_port_lf): new function (scm_lfwrite): use update_port_lf (scm_lfwrite_substr): new function (scm_lfwrite_str): new function * test-suite/tests/asm-to-bytecode.test ("compiler"): add string width byte to sting-like asm tests
2009-07-19add registry of vector constructors, make-generalized-vectorAndy Wingo1-0/+2
* libguile/generalized-vectors.h: * libguile/generalized-vectors.c: Add a registry of vector constructors. (scm_make_generalized_vector): New public function, constructs a vector of a given type. * libguile/bitvectors.c: * libguile/bytevectors.c: * libguile/srfi-4.c: * libguile/strings.c: * libguile/vectors.c: Register vector constructors. * libguile/extensions.c (scm_init_extensions): No need to NULL the list of registered extensions here, the static init does it for us. Allows scm_c_register_extension to be called before scm_init_extensions. * libguile/init.c (scm_i_init_guile): Move array initialization earlier, so e.g. scm_init_strings has access to a valid list of array element types when registering its vector constructor.
2009-07-19add generic array implementation facilityAndy Wingo1-1/+30
* libguile/array-handle.c (scm_i_register_array_implementation): (scm_i_array_implementation_for_obj): Add generic array facility, which will (in a few commits) detangle the array code. (scm_array_get_handle): Use the generic array facility. Note that scm_t_array_handle no longer has ref and set function pointers; instead it has a pointer to the array implementation. It is unlikely that code out there used these functions, however, as the supported way was through scm_array_handle_ref/set_x. (scm_array_handle_pos): Move this function here from arrays.c. (scm_array_handle_element_type): New function, returns a Scheme value representing the type of element stored in this array. * libguile/array-handle.h (scm_t_array_element_type): New enum, for generically determining the type of an array. (scm_array_handle_rank): (scm_array_handle_dims): These are now just #defines. * libguile/arrays.c: * libguile/bitvectors.c: * libguile/bytevectors.c: * libguile/srfi-4.c: * libguile/strings.c: * libguile/vectors.c: Register array implementations for all of these. * libguile/inline.h: Update for array_handle_ref/set change. * libguile/deprecated.h: Need to include arrays.h now.
2009-06-17Change Guile license to LGPLv3+Neil Jerram1-6/+7
(Not quite finished, the following will be done tomorrow. module/srfi/*.scm module/rnrs/*.scm module/scripts/*.scm testsuite/*.scm guile-readline/* )
2009-05-20Fix `explicitely' typos, should be `explicitly'Neil Jerram1-1/+1
2009-02-01Fix invalid writes to read-only stringbufs.Ludovic Courtès1-2/+9
* libguile/strings.c (SET_STRINGBUF_SHARED): Don't modify BUF if it's already marked as shared since it might be a read-only stringbuf. This error can be caught when linking with GNU ld with "-z relro".
2009-01-19Merge branch 'boehm-demers-weiser-gc' into bdw-gc-static-allocLudovic Courtès1-17/+14
2009-01-18Use `scm_gc malloc_pointerless ()' in `scm_i allocate_string_pointers ()'.Ludovic Courtès1-18/+15
* libguile/dynl.c (free_string_pointers): Remove. (scm_dynamic_args_call): Remove reference to `free_string_pointers ()' and remove dynwind. * libguile/posix.c (free_string_pointers): Remove. (scm_execl, scm_execlp, scm_execle, scm_environ): Remove references to `free_string_pointers ()'. * libguile/simpos.c (free_string_pointers): Remove. (scm_system_star): Remove reference to `free_string_pointers ()', remove enclosing dynwind. * libguile/strings.c (scm_i_allocate_string_pointers): Use `scm_gc_malloc_pointerless ()' and `scm_gc_malloc ()' instead of `scm_malloc ()' and `scm_to_locale_string ()', so that the result is automatically GC'd when no longer referenced. Remove unneeded dynwind. (scm_i_free_string_pointers): Remove. * libguile/strings.h (scm_i_free_string_pointers): Remove declaration.
2009-01-13Expose some of the string/stringbuf internal flags and tags.Ludovic Courtès1-4/+4
* libguile/strings.h (scm_tc7_ro_string, SCM_I_STRINGBUF_F_SHARED, SCM_I_STRINGBUF_F_INLINE): New macros. * libguile/strings.c (STRINGBUF_F_SHARED): Alias for `SCM_I_STRINGBUF_F_SHARED'. (STRINGBUF_F_INLINE): Alias for `SCM_I_STRINGBUF_F_INLINE'. (RO_STRING_TAG): Alias for `scm_tc7_ro_string'.
2008-12-14Merge branch 'master' into boehm-demers-weiser-gcLudovic Courtès1-2/+16
Conflicts: lib/Makefile.am libguile/struct.c libguile/threads.c m4/gnulib-cache.m4 m4/gnulib-comp.m4
2008-12-02Fix sloppy bound checking in `string-{ref,set!}' with the empty string.Ludovic Courtès1-2/+16
* libguile/strings.c (scm_string_ref): Add proper range checking for the empty string. (scm_string_set_x): Likewise. Reported by Bill Schottstaedt <bil@ccrma.Stanford.EDU>. * test-suite/tests/strings.test ("string-ref"): New test prefix. ("string-set!")["empty string", "empty string and non-zero index", "out of range", "negative index", "regular string"]: New tests. * NEWS: Update.
2008-10-11Merge branch 'master' into boehm-demers-weiser-gcLudovic Courtès1-28/+9
Conflicts: libguile/Makefile.am libguile/threads.c
2008-10-09Revert "Make literal strings (i.e., returned by `read') read-only."Ludovic Courtès1-28/+9
This reverts commit fb2f8886c4d537b0c7d3e9e78a8d4e5e272a36f4. The rationale is that `read' must return mutable strings, as reported by szgyg <szgyg@ludens.elte.hu>.
2008-09-23Merge branch 'master' into boehm-demers-weiser-gcLudovic Courtès1-10/+29
2008-09-23Make literal strings (i.e., returned by `read') read-only.Ludovic Courtès1-9/+28
* libguile/read.c (scm_read_string): Use `scm_i_make_read_only_string ()' to return a read-only string, as mandated by R5RS. Reported by Bill Schottstaedt <bil@ccrma.Stanford.EDU>. * libguile/strings.c (scm_i_make_read_only_string): New function. (scm_i_shared_substring_read_only): Special-case the empty string so that the read-only and read-write empty strings are `eq?'. This optimization is relied on by the `substring/shared' `empty string' test case in `srfi-13.test'. * libguile/strings.h (scm_i_make_read_only_string): New declaration. * test-suite/tests/strings.test ("string-set!")["literal string"]: New test. * NEWS: Update.
2008-09-23Make `symbol->string' return a read-only string.Ludovic Courtès1-1/+1
* libguile/strings.c (scm_i_symbol_substring): Return a read-only string since R5RS requires `symbol->string' to return a read-only string. Reported by Bill Schottstaedt <bil@ccrma.Stanford.EDU>. * test-suite/tests/symbols.test: Add `define-module' clause. (exception:immutable-string): Adjust to current exception. ("symbol->string")["result is an immutable string"]: Use `pass-if-exception' instead of `expect-fail-exception'. * NEWS: Update.
2008-09-17Remove use of `scm_i_thread_put_to_sleep ()' in the string code.Ludovic Courtès1-5/+9
* libguile/strings.c (scm_i_string_writable_chars): Remove use of `scm_i_thread_put_to_sleep ()'. This leaves a race condition, which is hopefully not harmful.
2008-09-16Use immutable double-cells for symbols.Ludovic Courtès1-2/+2
* libguile/strings.c (scm_i_make_symbol): Use `scm_immutable_double_cell ()'.
2008-09-15Remove unused GC string/symbol functions.Ludovic Courtès1-39/+1
* libguile/strings.c (scm_i_stringbuf_mark, scm_i_stringbuf_free, scm_i_string_mark, scm_i_string_free, scm_i_symbol_mark, scm_i_symbol_free): Remove. * libguile/strings.h: Remove corresponding declarations.
2008-09-13Merge branch 'master' into boehm-demers-weiser-gcLudovic Courtès1-0/+3
Conflicts: lib/Makefile.am libguile/gc-card.c libguile/gc-freelist.c libguile/gc-mark.c libguile/gc-segment.c libguile/gc.c libguile/gc.h libguile/gc_os_dep.c libguile/private-gc.h m4/.cvsignore m4/gnulib-cache.m4 m4/gnulib-comp.m4
2008-09-13Include <config.h> in all C files; use `#ifdef HAVE_CONFIG_H' rather than `#if'.Ludovic Courtès1-0/+3
2008-09-10Merge branch 'master' into boehm-demers-weiser-gcLudovic Courtès1-2/+12
Conflicts: libguile/Makefile.am libguile/coop-defs.h libguile/gc-card.c libguile/gc-freelist.c libguile/gc-malloc.c libguile/gc-mark.c libguile/gc-segment.c libguile/gc.c libguile/gc.h libguile/gc_os_dep.c libguile/hashtab.c libguile/hashtab.h libguile/inline.h libguile/private-gc.h libguile/struct.c libguile/struct.h libguile/threads.c libguile/threads.h libguile/vectors.h libguile/weaks.h test-suite/tests/gc.test
2008-09-05Added `scm_gc_malloc_pointerless ()', equivalent to `GC_MALLOC_ATOMIC ()'.Ludovic Courtes1-2/+1
* libguile/gc-malloc.c (scm_gc_register_collectable_memory): Tidied. (scm_gc_unregister_collectable_memory): Likewise. (scm_gc_malloc_pointerless): New. * libguile/gc.h (scm_gc_malloc_pointer_less): New declaration. * libguile/strings.c (make_stringbuf): Use it. git-archimport-id: lcourtes@laas.fr--2005-libre/guile-core--boehm-gc--1.9--patch-5
2008-09-05Small fixes. Gets to the REPL and `abort ()'s soon after.Ludovic Courtes1-1/+2
* libguile/inline.h (scm_cell): Re-added comment about the assignment order of CAR/CDR. * libguile/srcprop.c (scm_make_srcprops): Use `scm_gc_malloc ()' instead of `malloc' + `scm_gc_register_collectable_memory ()'. * libguile/threads.c (guilify_self_1): Likewise. (guilify_self_2): Likewise. * libguile/strings.c (make_stringbuf): Use `GC_MALLOC_ATOMIC ()' instead of `scm_gc_malloc ()'. git-archimport-id: lcourtes@laas.fr--2005-libre/guile-core--boehm-gc--1.9--patch-2
2008-07-05Add `scm_c_symbol_length ()'.Ludovic Courtès1-0/+10
2008-02-07More compilation fixes with Sun CC (bug #21378).Ludovic Courtès1-2/+2
2006-05-27Replace SCM_C_INLINE with SCM_C_INLINE_KEYWORD. Thanks to Mark Gran!Marius Vollmer1-1/+1
2006-04-17merge from 1.8 branchKevin Ryde1-4/+4
2006-01-29Renamed the "frames" that are related to dynamic-wind to "dynamicMarius Vollmer1-3/+3
contexts. Renamed all functions from scm_frame_ to scm_dynwind_. Updated documentation.
2006-01-24patches by Ludovic Courtès for symbol generation.Han-Wen Nienhuys1-3/+35
2005-06-24(scm_take_locale_stringn): Use realloc to make room forKevin Ryde1-17/+17
null-terminator, rather than mallocing a whole new block. (scm_take_locale_string): Use scm_take_locale_stringn len==-1.
2005-05-23The FSF has a new address.Marius Vollmer1-1/+1
2005-03-02See ChangeLog from 2005-03-02.Marius Vollmer1-13/+13
2005-01-24Reverted changed from 2005/01/24 19:14:54, which was a commit to theMarius Vollmer1-13/+13
wrong branch. Sorry.
2005-01-24Threading changes.Marius Vollmer1-13/+13
2005-01-12Turn all deprecated features that once were macros but are nowMarius Vollmer1-3/+3
functions back into macros.
2004-09-29(SCM_STRING_CHARS): Explicitely reject read-only strings with an errorMarius Vollmer1-0/+15
message that blames SCM_STRING_CHARS.
2004-09-22*** empty log message ***Marius Vollmer1-5/+5
2004-09-22(scm_substring_read_only,Marius Vollmer1-2/+59
scm_c_substring_read_only, scm_i_substring_read_only): New. (RO_STRING_TAG, IS_RO_STRING): New. (scm_i_string_writable_chars): Bail on read-only strings.
2004-09-032004-09-03 Stefan Jahn <stefan@lkcc.org>Stefan Jahn1-3/+4
* configure.in (isinf): Let configure find the isinf() function on MinGW32 systems. 2004-09-03 Stefan Jahn <stefan@lkcc.org> * threads.c (scm_threads_mark_stacks): Fixed local variable definitions. * strings.c (scm_i_substring_copy, s_scm_string_append): Fixed local variable definitions. * stime.c (_POSIX_C_SOURCE): Do not define this item on MinGW32 because it conflicts with its pthread headers. (s_scm_mktime): Consider the HAVE_STRUCT_TM_TM_ZONE define. (s_scm_strftime): Using scm_from_locale_string() instead of scm_makfrom0str(). * posix.c (s_scm_putenv): Fixed typo in the !HAVE_UNSETENV part. * numbers.c (scm_init_numbers): Removed check_sanity() call inside GUILE_DEBUG. The function has been removed somewhen... * filesys.c (_POSIX_C_SOURCE): Do not define this item on MinGW32 because it conflicts with its pthread headers. 2004-09-03 Stefan Jahn <stefan@lkcc.org> * srfi-1.c, srfi-1.h: Renamed any 'lst1' into 'list1' because lst1 is a #define on Win32 systems.
2004-08-27(SCM_STRINGP): Accept all strings.Marius Vollmer1-6/+10
(SCM_STRING_CHARS): Reject shared substrings here.
2004-08-26* strings.h, strings.c (scm_i_make_symbol): Added FLAGS parameter.Marius Vollmer1-2/+3
* symbols.h, symbols.c (SCM_I_F_SYMBOL_UNINTERNED, scm_i_symbol_is_interned, scm_i_mem2symbol, scm_i_mem2uninternedsymbol): Use it to store uninternedness flag.
2004-08-22(get_str_buf_start): New helper function.Marius Vollmer1-49/+63
(scm_i_substring, scm_i_substring_copy, scm_i_substring_shared, scm_i_string_char, scm_i_string_writable_chars): Use it. (scm_i_substring_copy): Make START argument optional for C callers, for upcoming SRFI-13 integration.
2004-08-19* strings.h, strings.c: (scm_i_string_chars, scm_i_string_length,Marius Vollmer1-133/+609
scm_i_string_writable_chars, scm_i_string_stop_writing): New, to replace SCM_I_STRING_CHARS and SCM_I_STRING_LENGTH. Updated all uses. (scm_i_make_string, scm_c_make_string): New, to replace scm_allocate_string. Updated all uses. (SCM_STRINGP, SCM_STRING_CHARS, SCM_STRING_UCHARS, SCM_STRING_LENGTH): Deprecated. (scm_allocate_string, scm_take_str, scm_take0str, scm_mem2string, scm_str2string, scm_makfrom0str, scm_makfrom0str_opt): Discouraged. Replaced all uses with scm_from_locale_string or similar, as appropriate. (scm_c_string_length, scm_c_string_ref, scm_c_string_set_x, scm_c_substring, scm_c_substring_shared, scm_c_substring_copy, scm_substring_shared, scm_substring_copy): New. * symbols.c, symbols.h (SCM_SYMBOLP, SCM_SYMBOL_FUNC, SCM_SET_SYMBOL_FUNC, SCM_SYMBOL_PROPS, SCM_SET_SYMBOL_PROPS, SCM_SYMBOL_HASH, SCM_SYMBOL_INTERNED_P, scm_mem2symbol, scm_str2symbol, scm_mem2uninterned_symbol): Discouraged. (SCM_SYMBOL_LENGTH, SCM_SYMBOL_CHARS, scm_c_symbol2str): Deprecated. (SCM_MAKE_SYMBOL_TAG, SCM_SET_SYMBOL_LENGTH, SCM_SET_SYMBOL_CHARS, SCM_PROP_SLOTS, SCM_SET_PROP_SLOTS): Removed. (scm_is_symbol, scm_from_locale_symbol, scm_from_locale_symboln): New, to replace scm_str2symbol and scm_mem2symbol, respectively. Updated all uses. (scm_gensym): Generate only the number suffix in the buffer, just string-append the prefix.
2004-08-12* strings.h, strings.c (scm_i_get_substring_spec): New.Marius Vollmer1-0/+16
* socket.c, rw.c, deprecated.h, validate.h (SCM_VALIDATE_STRING_COPY): Deprecated. Replaced all uses with SCM_VALIDATE_STRING plus SCM_I_STRING_CHARS or scm_to_locale_string, etc. (SCM_VALIDATE_SUBSTRING_SPEC_COPY): Deprecated. Replaced as above, plus scm_i_get_substring_spec.
2004-08-10* strings.h, deprecated.h (SCM_STRING_COERCE_0TERMINATION_X):Marius Vollmer1-80/+167
Moved from string.h to deprecated.h. * deprecated.c, deprecated.h (SCM_CHARS, SCM_LENGTH): Removed. * strings.h, strings.c (SCM_MAKE_STRING_TAG): Rename dto SCM_I_MAKE_STRING_TAG, changed all uses. (SCM_STRING_CHARS, SCM_STRING_UCHARS, SCM_STRING_LENGTH): Renamed to SCM_I_STRING_CHARS, SCM_I_STRING_UCHARS, and SCM_I_LENGTH respectively. For a short time, the old names are still there as aliases. Not all uses have been changed yet, but the ones in strings.c have. (SCM_STRING_MAX_LEN): Do not hardcode to 24 bits, compute from SCM_T_BITS_MAX. (scm_is_string, scm_from_locale_string, scm_from_locale_stringn, scm_take_locale_string, scm_take_locale_stringn, scm_to_locale_string, scm_to_locale_stringn, scm_to_locale_stringbuf): New. (scm_c_string2str, scm_c_substring2str): Deprecated by moving to deprecated.[hc]. Implemented in terms of the new functions above. (scm_take_str, scm_take0str, scm_mem2string, scm_str2string, scm_makfrom0str): Reimplemented in terms of the new functions from above. They will be discouraged shortly. (scm_substring): Do not use scm_mem2string. (scm_i_allocate_string_pointers, scm_i_free_string_pointers): New, to replace similar code from posix.c, simpos.c, and dynl.c. (scm_string_append): Use memcpy instead of explicit loop. Do not use register keyword. Use plain 'char' instead of 'unsigned char'.
2004-08-02* numbers.h, numbers.c, discouraged.h, discouraged.c (scm_short2num,Marius Vollmer1-2/+2
scm_ushort2num, scm_int2num, scm_uint2num, scm_long2num, scm_ulong2num, scm_size2num, scm_ptrdiff2num, scm_num2short, scm_num2ushort, scm_num2int, scm_num2uint, scm_num2long, scm_num2ulong, scm_num2size, scm_num2ptrdiff, scm_long_long2num, scm_ulong_long2num, scm_num2long_long, scm_num2ulong_long): Discouraged by moving to discouraged.h and discouraged.c and reimplementing in terms of scm_from_* and scm_to_*. Changed all uses to the new scm_from_* and scm_to_* functions.
2004-07-23* deprecated.h, deprecated.c, numbers.h (SCM_INUMP, SCM_NINUMP,Marius Vollmer1-23/+13
SCM_INUM): Deprecated by reenaming them to SCM_I_INUMP, SCM_I_NINUMP and SCM_I_INUM, respectively and adding deprecated versions to deprecated.h and deprecated.c. Changed all uses to either use the SCM_I_ variants or scm_is_*, scm_to_*, or scm_from_*, as appropriate.
2004-07-10* validate.h, deprecated.h (SCM_VALIDATE_INUM, SCM_VALIDATE_INUM_COPY,Marius Vollmer1-15/+13
SCM_VALIDATE_BIGINT, SCM_VALIDATE_INUM_MIN, SCM_VALIDATE_INUM_MIN_COPY, SCM_VALIDATE_INUM_MIN_DEF_COPY,SCM_VALIDATE_INUM_DEF, SCM_VALIDATE_INUM_DEF_COPY, SCM_VALIDATE_INUM_RANGE, SCM_VALIDATE_INUM_RANGE_COPY): Deprecated because they make the fixnum/bignum distinction visible. Changed all uses to scm_to_size_t or similar.