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

37 commits

Author SHA1 Message Date
Ludovic Courtès
cd9fc16ba0 Add test for 'string-ref' with a negative index at -O2.
This test would segfault prior to
c0004442b7.

See <https://bugs.gnu.org/60488>.

* test-suite/tests/strings.test ("string-ref"): Use 'with-test-prefix/c&e'.
["negative index"]: Check the reported bounds.
2023-01-17 17:49:05 +01:00
Jan (janneke) Nieuwenhuizen
52809cc630 read: Use "invalid" rather than "illegal".
* libguile/read.c (scm_read_string_like_syntax): All characters are
permitted by law; some aren't valid in certain contexts.
* test-suite/tests/reader.test: Replace occurrences of "illegal" by
"invalid".
* test-suite/tests/strings.test: Likewise.

Co-authored-by: Ludovic Courtès <ludo@gnu.org>
2020-06-18 00:30:11 +02:00
Daniel Llorens
6cfee36543 New function string-replace-substring in (ice-9 string-fun)
By A. Wingo in
https://lists.gnu.org/archive/html/guile-devel/2014-03/msg00058.html.

* module/ice-9/string-fun.scm (string-replace-substring): As stated.
* doc/ref/api-data.texi: Document the new function.
* test-suite/tests/strings.test: Test.
2020-01-06 09:44:01 +01:00
Mark H Weaver
bd50407d1f Strings, i18n: Limit the use of alloca to approximately 8 kilobytes.
* libguile/i18n.c (SCM_MAX_ALLOCA): New macro.
(SCM_STRING_TO_U32_BUF): Accept an additional variable to remember
whether we used malloc to allocate the buffer.  Use malloc if the
allocation size is greater than SCM_MAX_ALLOCA.
(SCM_CLEANUP_U32_BUF): New macro.
(compare_u32_strings, compare_u32_strings_ci, str_to_case): Adapt.
* libguile/strings.c (SCM_MAX_ALLOCA): New macro.
(normalize_str, unistring_escapes_to_r6rs_escapes): Use malloc if the
allocation size is greater than SCM_MAX_ALLOCA.
* test-suite/tests/i18n.test, test-suite/tests/strings.test: Add tests.
2019-05-23 17:51:36 +02:00
Andy Wingo
adf8d9353e Remove mention of vm-error from test suite
* test-suite/test-suite/lib.scm (exception:vm-error): Remove.
* test-suite/tests/strings.test: Remove override of
  exception:wrong-type-arg; not needed since a while ago.
2018-06-27 09:52:10 +02:00
Andy Wingo
d0934df1f2 Stringbufs immutable by default
* libguile/snarf.h (SCM_IMMUTABLE_STRINGBUF): Remove shared flag.
  Stringbufs are immutable by default.
* libguile/strings.c: Rewrite blurb.  Change to have stringbufs be
  immutable by default and mutable only when marked as such.  Going
  mutable means making a private copy.
  (STRINGBUF_MUTABLE, STRINGBUF_F_MUTABLE): New definitions.
  (SET_STRINGBUF_SHARED): Remove.
  (scm_i_print_stringbuf): Simplify to just alias the stringbuf as-is.
  (substring_with_immutable_stringbuf): New helper.
  (scm_i_substring, scm_i_substring_read_only, scm_i_substring_copy):
  use new helper.
  (scm_i_string_ensure_mutable_x): New helper.
  (scm_i_substring_shared): Use scm_i_string_ensure_mutable_x.
  (stringbuf_write_mutex): Remove; yaaaaaaaay.
  (scm_i_string_start_writing): Use scm_i_string_ensure_mutable_x.  No
  more mutex.
  (scm_i_string_stop_writing): Now a no-op.
  (scm_i_make_symbol): Use substring/copy.
  (scm_sys_string_dump, scm_sys_symbol_dump): Update.
* libguile/strings.h (SCM_I_STRINGBUF_F_SHARED): Remove.
  (SCM_I_STRINGBUF_F_MUTABLE): Add.
* module/system/vm/assembler.scm (link-data): Don't add shared flag any
  more.  Existing compiled flags are harmless tho.
* test-suite/tests/strings.test ("string internals"): Update.
2017-02-16 13:11:29 +01:00
Mark H Weaver
e390e5760b 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.
2016-05-22 19:03:37 +02:00
Andy Wingo
39caffe79b remove @apply memoizer
* libguile/memoize.c (memoize): Recognize a primcall to 'apply as
  SCM_M_APPLY.
  (@apply): Remove @apply memoizer.
  (unmemoize): Unmemoize using "apply", not "@apply".

* libguile/memoize.h:
* libguile/expand.c (scm_sym_atapply): Remove.

* module/ice-9/boot-9.scm (apply): Re-implement using apply primcall.
  Use case-lambda, so as to give an appropriate minimum arity.

* module/language/tree-il/compile-glil.scm (flatten-lambda-case):
  Compile a primcall of "apply" specially, not "@apply".

* module/language/tree-il/peval.scm (peval): Match primcalls to "apply",
  not "@apply".  Residualize "apply" primcalls.

* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  (*multiply-valued-primitives*): Remove @apply, and apply primitive
  expander.

* test-suite/tests/peval.test:
* test-suite/tests/tree-il.test: Update tests to expect residualized
  "apply".

* test-suite/tests/procprop.test ("procedure-arity"): Update test for
  better apply arity.

* test-suite/tests/strings.test ("string"): Update expected error.
2013-06-27 22:02:35 +02:00
Daniel Hartwig
5f085775ab In string-split, add support for character sets and predicates.
* libguile/srfi-13.c (string-split): Add support for splitting on
  character sets and predicates, like string-index and others.
* test-suite/tests/strings.test (string-split): Add tests covering
  the new argument types.
* doc/ref/api-data.texi (string-split): Update.

Signed-off-by: Mark H Weaver <mhw@netris.org>
2012-10-12 08:15:08 -04: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
Ludovic Courtès
7614c983a5 Fix type-checking in the optimized path of `string=?'.
* libguile/srfi-13.c (scm_string_eq): Properly type-check S1 and S2.

* test-suite/tests/strings.test ("string=?")["1st argument EOF", "2nd
  argument EOF"]: New tests exposing the problem.
2010-07-13 00:08:09 +02:00
Michael Gran
2e85d145fc Move r6rs-hex-escape tests into reader.test
* test-suite/tests/reader.test (r6rs-hex-escapes): new tests

* test-suite/tests/chars.test (R6RS Hex escapes): remove tests by reverting
  to previous version

* test-suite/tests/strings.test (R6RS Hex escapes): remove tests by
  reverting to previous version
2010-01-12 21:27:30 -08:00
Michael Gran
dea901d66e Reader option for R6RS hex escapes
This adds a reader option 'r6rs-hex-escapes that modifies the
behavior of numeric escapes in characters and strings.  When enabled,
variable-length character hex escapes (#\xNNN) are allowed and become
the default output format for numerically-escaped characters.  Also,
string hex escapes switch to a semicolon terminated hex escape (\xNNNN;).

* libguile/print.c (PRINT_CHAR_ESCAPE): new macro
  (iprin1): use new macro PRINT_CHAR_ESCAPE

* libguile/private-options.h (SCM_R6RS_ESCAPES_P): new #define

* libguile/read.c (scm_read_opts): add new option r6rs-hex-escapes
  (SCM_READ_HEX_ESCAPE): modify to take a terminator parameter
  (scm_read_string): parse R6RS hex string escapes
  (scm_read_character): parse R6RS hex character escapes

* test-suite/tests/chars.test (with-read-options): new procedure
  (R6RS hex escapes): new tests

* test-suite/tests/strings.test (with-read-options): new procedure
  (R6RS hex escapes): new tests
2010-01-12 21:02:41 -08:00
Michael Gran
67a4a16d8e Add R6RS backspace string escape
R6RS suggests that '\b' should be a string escape for the backspace
character.

* libguile/read.c (scm_read_string): parse backspace escape

* test-suite/tests/strings.test (R6RS backslash escapes): new test
  (Guile extensions backslash escapes): remove R6RS escapes from test.

* doc/ref/api-data.texi (Strings): document new string escape
2010-01-10 15:41:37 -08: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
Michael Gran
fee95176df More tests for strings
* test-suite/tests/vectors.test: test make-vector and interactions between
  strings and vectors

* test-suite/tests/strings.test: test string-null?, string? and backslash
  escapes

* test-suite/tests/srfi-13.test: test null input strings in string-any and
  string-every
2009-09-20 20:59:44 -07:00
Ludovic Courtès
ba54a2026b Remove the distinction between inline/outline storage for stringbufs.
* libguile/strings.c (STRINGBUF_HEADER_SIZE, STRINGBUF_HEADER_BYTES):
  New macros.
  (STRINGBUF_F_INLINE, STRINGBUF_INLINE, STRINGBUF_OUTLINE_CHARS,
  STRINGBUF_OUTLINE_LENGTH, STRINGBUF_INLINE_CHARS,
  STRINGBUF_INLINE_LENGTH, STRINGBUF_MAX_INLINE_LEN): Remove.
  (STRINGBUF_CHARS, STRINGBUF_WIDE_CHARS): Adjust to return a fixed
  location.
  (STRINGBUF_LENGTH): Get the length from word 1.
  (make_stringbuf, make_wide_stringbuf): Adjust to use a contiguous
  memory region.
  (wide_stringbuf): Renamed from `widen_stringbuf'.  Adjust similarly.
  Return the new stringbuf.  Callers updated.
  (narrow_stringbuf): Likewise.
  (scm_sys_string_dump, scm_sys_symbol_dump): Remove `stringbuf-inline'
  pair.

* test-suite/tests/strings.test ("string internals")["null strings are
  inlined", "short Latin-1 encoded strings are inlined", "long Latin-1
  encoded strings are not inlined", "short UCS-4 encoded strings are not
  inlined", "long UCS-4 encoded strings are not inlined"]: Remove.

* test-suite/tests/symbols.test ("symbol internals")["null symbols are
  inlined", "short Latin-1 encoded symbols are inlined", "long Latin-1
  encoded symbols are not inlined", "short UCS-4 encoded symbols are not
  inlined", "long UCS-4 encoded symbols are not inlined"]: Remove.
2009-09-01 02:02:43 +02:00
Michael Gran
2759c092d0 Add VM exception in strings.test
* test-suite/tests/strings.test (exception:wrong-type-arg): change regex
2009-08-19 22:15:36 -07:00
Michael Gran
3c7cf7f5c0 Regression, scm_string fails to test for circular lists
* libguile/string.c (scm_string): Restores the functionality
  where scm_string tests for circular lists

* test-suite/tests/strings.test: add test for circular lists
2009-08-12 09:21:37 -07:00
Michael Gran
f5d7662fc8 More string and symbol tests
* test-suite/tests/strings.test: more tests

        * test-suite/tests/symbols.test: more tests
2009-08-10 23:05:52 -07:00
Neil Jerram
53befeb700 Change Guile license to LGPLv3+
(Not quite finished, the following will be done tomorrow.
   module/srfi/*.scm
   module/rnrs/*.scm
   module/scripts/*.scm
   testsuite/*.scm
   guile-readline/*
)
2009-06-17 00:22:09 +01:00
Ludovic Courtès
3ae3166b23 Fix sloppy bound checking in `string-{ref,set!}' with the empty string.
* 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-12-02 19:52:13 +01:00
Ludovic Courtès
45a9f43049 Revert "Make literal strings (i.e., returned by `read') read-only."
This reverts commit fb2f8886c4.

The rationale is that `read' must return mutable strings, as reported
by szgyg <szgyg@ludens.elte.hu>.
2008-10-09 22:21:33 +02:00
Ludovic Courtès
fb2f8886c4 Make literal strings (i.e., returned by `read') read-only.
* 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-23 18:45:27 +02:00
Kevin Ryde
6e7d5622ee merge from 1.8 branch 2006-04-16 23:37:40 +00:00
Kevin Ryde
50e20a6061 (string-split): Try splitting on an 8-bit char. 2005-06-05 21:33:33 +00:00
Marius Vollmer
92205699d0 The FSF has a new address. 2005-05-23 19:57:22 +00:00
Marius Vollmer
b144a33c42 (string-set!): Explicitely construct read-only string. String
literals are not yet read-only.
2004-09-30 11:58:26 +00:00
Marius Vollmer
d7e4c2da23 * tests/ports.test ("string ports"): Copy string literal so that
it can be modified.
* tests/srfi-13.test ("string-copy!"): Likewise.
* tests/strings.test ("substring/shared"): Likewise.
2004-09-22 14:32:47 +00:00
Marius Vollmer
7aa29a87f9 Two more tests for double indirect substring modification. 2004-08-24 22:14:57 +00:00
Marius Vollmer
1c17f6b0c8 Two tests for substring/shared. Also, use (test-suite lib). 2004-08-19 22:23:23 +00:00
Dirk Herrmann
049fa4495b * Extracted tests from exceptions.test into strings.test and symbols.test.
* Added some tests to strings.test.
2001-03-01 17:57:50 +00:00
Dirk Herrmann
6b4113afc5 * Provide and use new convenience macros to test for exceptions. 2001-02-28 11:25:40 +00:00
Dirk Herrmann
b3b8952a94 * Reflect the fact that string=? is fixed in the test-suite. 2000-10-30 17:32:55 +00:00
Dirk Herrmann
548b925289 * Remember that string=? and friends need fixing. 2000-09-26 20:39:03 +00:00
Jim Blandy
0bfcc6e0d4 * tests/strings.test: Add test for substring-move! argument checking. 1999-09-11 18:46:48 +00:00
Jim Blandy
9aa2c79671 * tests/strings.test: New test file. 1999-08-30 07:46:01 +00:00