summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2008-10-09 22:21:33 +0200
committerLudovic Courtès <ludo@gnu.org>2008-10-09 22:21:33 +0200
commit45a9f4304955599ee4e772069e56d131401695dd (patch)
treed4f3afcc9528c8462ec3b45d6c3a4d9185a40ccc
parent89bc270db3c207b2210736f066ce18721e0dbc76 (diff)
downloadguile-45a9f4304955599ee4e772069e56d131401695dd.tar.gz
Revert "Make literal strings (i.e., returned by `read') read-only."
This reverts commit fb2f8886c4d537b0c7d3e9e78a8d4e5e272a36f4. The rationale is that `read' must return mutable strings, as reported by szgyg <szgyg@ludens.elte.hu>.
-rw-r--r--NEWS1
-rw-r--r--libguile/read.c2
-rw-r--r--libguile/strings.c37
-rw-r--r--libguile/strings.h1
-rw-r--r--test-suite/tests/strings.test8
5 files changed, 12 insertions, 37 deletions
diff --git a/NEWS b/NEWS
index 2c3e226e9..567fc1b86 100644
--- a/NEWS
+++ b/NEWS
@@ -66,7 +66,6 @@ available: Guile is now always configured in "maintainer mode".
* Bugs fixed
** `symbol->string' now returns a read-only string, as per R5RS
-** Literal strings as returned by `read' are now read-only, as per R5RS
** Fix incorrect handling of the FLAGS argument of `fold-matches'
** `guile-config link' now prints `-L$libdir' before `-lguile'
** Fix memory corruption involving GOOPS' `class-redefinition'
diff --git a/libguile/read.c b/libguile/read.c
index abe1cb9ad..47b80041e 100644
--- a/libguile/read.c
+++ b/libguile/read.c
@@ -484,7 +484,7 @@ scm_read_string (int chr, SCM port)
else
str = (str == SCM_BOOL_F) ? scm_nullstr : str;
- return scm_i_make_read_only_string (str);
+ return str;
}
#undef FUNC_NAME
diff --git a/libguile/strings.c b/libguile/strings.c
index ffc1eb312..7399d8831 100644
--- a/libguile/strings.c
+++ b/libguile/strings.c
@@ -218,12 +218,6 @@ get_str_buf_start (SCM *str, SCM *buf, size_t *start)
}
SCM
-scm_i_make_read_only_string (SCM str)
-{
- return scm_i_substring_read_only (str, 0, STRING_LENGTH (str));
-}
-
-SCM
scm_i_substring (SCM str, size_t start, size_t end)
{
SCM buf;
@@ -240,28 +234,15 @@ scm_i_substring (SCM str, size_t start, size_t end)
SCM
scm_i_substring_read_only (SCM str, size_t start, size_t end)
{
- SCM result;
-
- if (SCM_UNLIKELY (STRING_LENGTH (str) == 0))
- /* We want the empty string to be `eq?' with the read-only empty
- string. */
- result = str;
- else
- {
- SCM buf;
- size_t str_start;
-
- get_str_buf_start (&str, &buf, &str_start);
- scm_i_pthread_mutex_lock (&stringbuf_write_mutex);
- SET_STRINGBUF_SHARED (buf);
- scm_i_pthread_mutex_unlock (&stringbuf_write_mutex);
-
- result = scm_double_cell (RO_STRING_TAG, SCM_UNPACK (buf),
- (scm_t_bits) str_start + start,
- (scm_t_bits) end - start);
- }
-
- return result;
+ SCM buf;
+ size_t str_start;
+ get_str_buf_start (&str, &buf, &str_start);
+ scm_i_pthread_mutex_lock (&stringbuf_write_mutex);
+ SET_STRINGBUF_SHARED (buf);
+ scm_i_pthread_mutex_unlock (&stringbuf_write_mutex);
+ return scm_double_cell (RO_STRING_TAG, SCM_UNPACK(buf),
+ (scm_t_bits)str_start + start,
+ (scm_t_bits) end - start);
}
SCM
diff --git a/libguile/strings.h b/libguile/strings.h
index cf5862803..ca5f52cd2 100644
--- a/libguile/strings.h
+++ b/libguile/strings.h
@@ -152,7 +152,6 @@ SCM_INTERNAL void scm_i_get_substring_spec (size_t len,
SCM start, size_t *cstart,
SCM end, size_t *cend);
SCM_INTERNAL SCM scm_i_take_stringbufn (char *str, size_t len);
-SCM_INTERNAL SCM scm_i_make_read_only_string (SCM str);
/* deprecated stuff */
diff --git a/test-suite/tests/strings.test b/test-suite/tests/strings.test
index 735258a24..aa9196e68 100644
--- a/test-suite/tests/strings.test
+++ b/test-suite/tests/strings.test
@@ -1,7 +1,7 @@
;;;; strings.test --- test suite for Guile's string functions -*- scheme -*-
;;;; Jim Blandy <jimb@red-bean.com> --- August 1999
;;;;
-;;;; Copyright (C) 1999, 2001, 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
+;;;; Copyright (C) 1999, 2001, 2004, 2005, 2006 Free Software Foundation, Inc.
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
@@ -168,11 +168,7 @@
(pass-if-exception "read-only string"
exception:read-only-string
- (string-set! (substring/read-only "abc" 0) 1 #\space))
-
- (pass-if-exception "literal string"
- exception:read-only-string
- (string-set! "an immutable string" 0 #\a)))
+ (string-set! (substring/read-only "abc" 0) 1 #\space)))
(with-test-prefix "string-split"