[uim-commit] r2329 - branches/r5rs/sigscheme

yamaken at freedesktop.org yamaken at freedesktop.org
Sat Dec 3 10:18:17 PST 2005


Author: yamaken
Date: 2005-12-03 10:18:13 -0800 (Sat, 03 Dec 2005)
New Revision: 2329

Modified:
   branches/r5rs/sigscheme/config.h
   branches/r5rs/sigscheme/read.c
Log:
* sigscheme/config.h
  - (SCM_INITIAL_STRING_BUF_SIZE, SCM_INITIAL_SYMBOL_BUF_SIZE,
    SCM_LBUF_F_STRING, SCM_LBUF_F_SYMBOL): New macro
* sigscheme/read.c
  - (MB_MAX_SIZE): New macro
  - (INITIAL_STRING_BUF_SIZE): Removed
  - (read_string): Replace the fixed size buffer with LBUF and fix the
    stack problem


Modified: branches/r5rs/sigscheme/config.h
===================================================================
--- branches/r5rs/sigscheme/config.h	2005-12-03 18:16:46 UTC (rev 2328)
+++ branches/r5rs/sigscheme/config.h	2005-12-03 18:18:13 UTC (rev 2329)
@@ -87,6 +87,17 @@
 #define SCM_GCC4_READY_GC       1  /* use experimental gcc4-ready stack protection */
 
 /*===========================================================================
+  Tunings
+===========================================================================*/
+/* on-stack initial token buffer size for parser */
+#define SCM_INITIAL_STRING_BUF_SIZE 64
+#define SCM_INITIAL_SYMBOL_BUF_SIZE 64
+
+/* token buffer size extender function */
+#define SCM_LBUF_F_STRING LBUF_F_LINEAR
+#define SCM_LBUF_F_SYMBOL LBUF_F_LINEAR
+
+/*===========================================================================
   Debugging
 ===========================================================================*/
 #define SCM_DEBUG               1  /* enable debugging features */

Modified: branches/r5rs/sigscheme/read.c
===================================================================
--- branches/r5rs/sigscheme/read.c	2005-12-03 18:16:46 UTC (rev 2328)
+++ branches/r5rs/sigscheme/read.c	2005-12-03 18:18:13 UTC (rev 2329)
@@ -73,14 +73,14 @@
 /*=======================================
   File Local Macro Declarations
 =======================================*/
+#define MB_MAX_SIZE (SCM_MB_MAX_LEN + sizeof((char)'\0'))
+
 /* can accept "backspace" of R5RS and "U0010FFFF" of SRFI-75 */
 #define CHAR_LITERAL_LEN_MAX (sizeof("backspace") - sizeof((char)'\0'))
 
 /* #b-010101... */
 #define INT_LITERAL_LEN_MAX  (sizeof("-") + sizeof(int) * CHAR_BIT - sizeof((char)'\0'))
 
-#define INITIAL_STRING_BUF_SIZE 1024
-
 #define WHITESPACE_CHARS " \t\n\r\v\f"
 #define DELIMITER_CHARS  "()\";" WHITESPACE_CHARS
 
@@ -448,30 +448,32 @@
     ScmObj obj;
     const ScmSpecialCharInfo *info;
     int c;
-    size_t bufsize;
-    char *p, *buf;
-    char autobuf[INITIAL_STRING_BUF_SIZE];
+    size_t offset;
+    char *p;
+    ScmLBuf(char) lbuf;
+    char init_buf[SCM_INITIAL_STRING_BUF_SIZE];
 
     CDBG((SCM_DBG_PARSER, "read_string"));
 
-    buf = autobuf;
-    bufsize = sizeof(autobuf);
-    for (p = buf; p < &buf[bufsize];) {
+    LBUF_INIT(lbuf, init_buf, sizeof(init_buf));
+
+    for (offset = 0, p = LBUF_BUF(lbuf);; offset = p - LBUF_BUF(lbuf)) {
         c = SCM_PORT_GET_CHAR(port);
 
         CDBG((SCM_DBG_PARSER, "read_string c = %c", c));
 
         switch (c) {
         case EOF:
+            LBUF_EXTEND(lbuf, SCM_LBUF_F_STRING, offset + 1);
             *p = '\0';
-            ERR("EOF in string: \"%s<eof>", buf);
+            ERR("EOF in string: \"%s<eof>", LBUF_BUF(lbuf));
             break;
 
         case '\"':
+            LBUF_EXTEND(lbuf, SCM_LBUF_F_STRING, offset + 1);
             *p = '\0';
-            obj = Scm_NewImmutableStringCopying(buf);
-            if (buf != autobuf)
-                free(buf);
+            obj = Scm_NewImmutableStringCopying(LBUF_BUF(lbuf));
+            LBUF_FREE(lbuf);
             return obj;
 
         case '\\':
@@ -479,6 +481,8 @@
 #if SCM_USE_SRFI75
             if (strchr("xuU", c)) {
                 c = read_unicode_sequence(port, c);
+                LBUF_EXTEND(lbuf, SCM_LBUF_F_STRING, offset + MB_MAX_SIZE);
+                p = &LBUF_BUF(lbuf)[offset];
                 /* FIXME: check Unicode capability of Scm_current_char_codec */
                 p = SCM_CHARCODEC_INT2STR(Scm_current_char_codec,
                                           p, c, SCM_MB_STATELESS);
@@ -491,6 +495,8 @@
                 /* escape sequences */
                 for (info = Scm_special_char_table; info->esc_seq; info++) {
                     if (strlen(info->esc_seq) == 2 && c == info->esc_seq[1]) {
+                        LBUF_EXTEND(lbuf, SCM_LBUF_F_STRING, offset + 1);
+                        p = &LBUF_BUF(lbuf)[offset];
                         *p++ = info->code;
                         goto found;
                     }
@@ -501,6 +507,8 @@
             break;
 
         default:
+            LBUF_EXTEND(lbuf, SCM_LBUF_F_STRING, offset + MB_MAX_SIZE);
+            p = &LBUF_BUF(lbuf)[offset];
             /* FIXME: support stateful encoding */
             p = SCM_CHARCODEC_INT2STR(Scm_current_char_codec,
                                       p, c, SCM_MB_STATELESS);
@@ -509,8 +517,8 @@
             break;
         }
     }
-    buf[bufsize - 1] = '\0';
-    ERR("too long string: \"%s\"", buf);
+    LBUF_END(lbuf)[-1] = '\0';
+    ERR("too long string: \"%s\"", LBUF_BUF(lbuf));
     /* NOTREACHED */
 }
 



More information about the uim-commit mailing list