* strings.c (scm_string_set_x): Require the argument to be a
authorJim Blandy <jimb@red-bean.com>
Wed, 7 Oct 1998 15:52:31 +0000 (15:52 +0000)
committerJim Blandy <jimb@red-bean.com>
Wed, 7 Oct 1998 15:52:31 +0000 (15:52 +0000)
writable string, not a substring or a symbol.
* strings.h (SCM_RWSTRINGP, SCM_NRWSTRINGP): New predicates.

libguile/strings.c
libguile/strings.h

index 3582bac..54feb32 100644 (file)
@@ -282,10 +282,14 @@ scm_string_set_x (str, k, chr)
      SCM k;
      SCM chr;
 {
-  SCM_ASSERT (SCM_NIMP (str) && SCM_STRINGP (str), str, SCM_ARG1, s_string_set_x);
+  SCM_ASSERT (SCM_NIMP (str) && SCM_STRINGP (str),
+             str, SCM_ARG1, s_string_set_x);
   SCM_ASSERT (SCM_INUMP (k), k, SCM_ARG2, s_string_set_x);
   SCM_ASSERT (SCM_ICHRP (chr), chr, SCM_ARG3, s_string_set_x);
-  SCM_ASSERT (SCM_INUM (k) < SCM_LENGTH (str) && SCM_INUM (k) >= 0, k, SCM_OUTOFRANGE, s_string_set_x);
+  if (! SCM_RWSTRINGP (str))
+    scm_misc_error (s_string_set_x, "argument is a read-only string", str);
+  SCM_ASSERT (SCM_INUM (k) < SCM_LENGTH (str) && SCM_INUM (k) >= 0,
+             k, SCM_OUTOFRANGE, s_string_set_x);
   SCM_UCHARS (str)[SCM_INUM (k)] = SCM_ICHR (chr);
   return SCM_UNSPECIFIED;
 }
index 5243255..a597ddc 100644 (file)
 #define SCM_STRINGP(x) (SCM_TYP7S(x)==scm_tc7_string)
 #define SCM_NSTRINGP(x) (!SCM_STRINGP(x))
 
+/* Is X a writable string (i.e., not a substring)?  */
+#define SCM_RWSTRINGP(x) (SCM_TYP7(x) == scm_tc7_string)
+#define SCM_NRWSTRINGP(x) (! SCM_RWSTRINGP (x))
+
 \f