mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
Unoptimize 'read' to return freshly allocated empty strings
* libguile/read.c (scm_read_string): Return a freshly allocated string every time, even for empty strings. The motivation is to allow source properties to be added to all strings. Previously, the shared global 'scm_nullstr' was returned for empty strings. Note that empty strings still share a common global 'null_stringbuf'. * test-suite/tests/srfi-13.test (substring/shared): Fix tests to reflect the fact that empty string literals are no longer guaranteed to be 'eq?' to each other.
This commit is contained in:
parent
d5b75b6c80
commit
043850d984
2 changed files with 9 additions and 13 deletions
|
@ -580,14 +580,8 @@ scm_read_string (int chr, SCM port)
|
|||
scm_i_string_set_x (str, c_str_len++, c);
|
||||
scm_i_string_stop_writing ();
|
||||
}
|
||||
|
||||
if (c_str_len > 0)
|
||||
{
|
||||
return scm_i_substring_copy (str, 0, c_str_len);
|
||||
}
|
||||
|
||||
return scm_nullstr;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
;;;; srfi-13.test --- Test suite for Guile's SRFI-13 functions. -*- scheme -*-
|
||||
;;;; Martin Grabmueller, 2001-05-07
|
||||
;;;;
|
||||
;;;; Copyright (C) 2001, 2004, 2005, 2006, 2011 Free Software Foundation, Inc.
|
||||
;;;; Copyright (C) 2001, 2004, 2005, 2006, 2011, 2012 Free Software Foundation, Inc.
|
||||
;;;;
|
||||
;;;; This library is free software; you can redistribute it and/or
|
||||
;;;; modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -561,13 +561,15 @@
|
|||
(with-test-prefix "substring/shared"
|
||||
|
||||
(pass-if "empty string"
|
||||
(eq? "" (substring/shared "" 0)))
|
||||
|
||||
(pass-if "non-empty string"
|
||||
(string=? "foo" (substring/shared "foo-bar" 0 3)))
|
||||
(let ((s ""))
|
||||
(eq? s (substring/shared s 0))))
|
||||
|
||||
(pass-if "non-empty string, not eq?"
|
||||
(string=? "foo-bar" (substring/shared "foo-bar" 0 7))))
|
||||
(string=? "foo" (substring/shared "foo-bar" 0 3)))
|
||||
|
||||
(pass-if "shared copy of non-empty string is eq?"
|
||||
(let ((s "foo-bar"))
|
||||
(eq? s (substring/shared s 0 7)))))
|
||||
|
||||
(with-test-prefix "string-copy!"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue