summaryrefslogtreecommitdiff
path: root/libguile/strings.c
diff options
context:
space:
mode:
Diffstat (limited to 'libguile/strings.c')
-rw-r--r--libguile/strings.c55
1 files changed, 25 insertions, 30 deletions
diff --git a/libguile/strings.c b/libguile/strings.c
index ffc1eb312..c13802664 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
@@ -689,10 +670,17 @@ SCM_DEFINE (scm_string_ref, "string-ref", 2, 0, 0,
"indexing. @var{k} must be a valid index of @var{str}.")
#define FUNC_NAME s_scm_string_ref
{
+ size_t len;
unsigned long idx;
SCM_VALIDATE_STRING (1, str);
- idx = scm_to_unsigned_integer (k, 0, scm_i_string_length (str)-1);
+
+ len = scm_i_string_length (str);
+ if (SCM_LIKELY (len > 0))
+ idx = scm_to_unsigned_integer (k, 0, len - 1);
+ else
+ scm_out_of_range (NULL, k);
+
return SCM_MAKE_CHAR (scm_i_string_chars (str)[idx]);
}
#undef FUNC_NAME
@@ -712,10 +700,17 @@ SCM_DEFINE (scm_string_set_x, "string-set!", 3, 0, 0,
"@var{str}.")
#define FUNC_NAME s_scm_string_set_x
{
+ size_t len;
unsigned long idx;
SCM_VALIDATE_STRING (1, str);
- idx = scm_to_unsigned_integer (k, 0, scm_i_string_length(str)-1);
+
+ len = scm_i_string_length (str);
+ if (SCM_LIKELY (len > 0))
+ idx = scm_to_unsigned_integer (k, 0, len - 1);
+ else
+ scm_out_of_range (NULL, k);
+
SCM_VALIDATE_CHAR (3, chr);
{
char *dst = scm_i_string_writable_chars (str);