This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Patch for strings.c
- To: Guile Mailing List <guile at sourceware dot cygnus dot com>
- Subject: Patch for strings.c
- From: Dirk Herrmann <dirk at ida dot ing dot tu-bs dot de>
- Date: Wed, 26 Jan 2000 09:39:34 +0100 (MET)
Hi!
Getting rid of another call to SCM_NIMP. (OK, you may call this stupid,
but for me it's a way to look for chances for small improvements whenever
my time allows.)
In function scm_string_append:
* Replaced call to SCM_NIMP with SCM_NNULLP.
* Added optional type check for rest arguments.
* Always report position of erroneous parameters.
* Minimized some variable scopes.
* Don't use register keyword.
However, unless GUILE_DEBUG is defined, the rest argument is not checked
to be a proper list. This means, that if GUILE_DEBUG is not defined,
guile could even crash when a user calls scm_string_append from C and
passes anything but a proper list as a rest argument.
Best regards
Dirk Herrmann
Index: strings.c
===================================================================
RCS file: /cvs/guile/guile/guile-core/libguile/strings.c,v
retrieving revision 1.24
diff -u -p -r1.24 strings.c
--- strings.c 2000/01/18 11:24:03 1.24
+++ strings.c 2000/01/25 18:36:48
@@ -321,31 +321,43 @@ SCM_DEFINE (scm_substring, "substring",
}
#undef FUNC_NAME
+
SCM_DEFINE (scm_string_append, "string-append", 0, 0, 1,
(SCM args),
"")
#define FUNC_NAME s_scm_string_append
{
+ unsigned int arg_nr = 0;
+ unsigned long total_length = 0;
SCM res;
- register long i = 0;
- register SCM l, s;
- register unsigned char *data;
- for (l = args;SCM_CONSP (l);) {
- s = SCM_CAR (l);
- SCM_VALIDATE_ROSTRING (SCM_ARGn,s);
- i += SCM_ROLENGTH (s);
- l = SCM_CDR (l);
+ SCM l;
+ unsigned char *data;
+
+#ifdef GUILE_DEBUG
+ if (scm_ilength(args) < 0)
+ SCM_MISC_ERROR("rest arguments do not form a proper list.");
+#endif /* GUILE_DEBUG */
+
+ for (l = args; SCM_NNULLP (l); l = SCM_CDR (l)) {
+ SCM arg;
+
+ ++arg_nr;
+ arg = SCM_CAR (l);
+ SCM_VALIDATE_ROSTRING (arg_nr, arg);
+ total_length += SCM_ROLENGTH (arg);
}
- SCM_ASSERT (SCM_NULLP (l), args, SCM_ARGn, FUNC_NAME);
- res = scm_makstr (i, 0);
+ res = scm_makstr (total_length, 0);
data = SCM_UCHARS (res);
- for (l = args;SCM_NIMP (l);l = SCM_CDR (l)) {
- s = SCM_CAR (l);
- for (i = 0;i<SCM_ROLENGTH (s);i++) *data++ = SCM_ROUCHARS (s)[i];
+ for (l = args; SCM_NNULLP (l); l = SCM_CDR (l)) {
+ SCM s = SCM_CAR (l);
+ unsigned long pos = 0;
+ for (pos = 0; pos < SCM_ROLENGTH (s); pos++)
+ *data++ = SCM_ROUCHARS (s)[pos];
}
return res;
}
#undef FUNC_NAME
+
SCM_DEFINE (scm_make_shared_substring, "make-shared-substring", 1, 2, 0,
(SCM str, SCM frm, SCM to),