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

kzk at freedesktop.org kzk at freedesktop.org
Mon Aug 29 01:38:17 EST 2005


Author: kzk
Date: 2005-08-28 08:38:13 -0700 (Sun, 28 Aug 2005)
New Revision: 1345

Modified:
   branches/r5rs/sigscheme/read.c
Log:
* abolish memory leaks

* sigscheme/read.c
  - (parse_number): change argument. and free the string got by calling
    read_word()
  - (read_number_or_str): free the result of read_word()
  - (read_sexpression): use parse_number()


Modified: branches/r5rs/sigscheme/read.c
===================================================================
--- branches/r5rs/sigscheme/read.c	2005-08-28 15:00:30 UTC (rev 1344)
+++ branches/r5rs/sigscheme/read.c	2005-08-28 15:38:13 UTC (rev 1345)
@@ -92,7 +92,7 @@
 static ScmObj read_char(ScmObj port);
 static ScmObj read_string(ScmObj port);
 static ScmObj read_symbol(ScmObj port);
-static ScmObj parse_number(const char *str);
+static ScmObj parse_number(ScmObj port);
 static ScmObj read_number_or_symbol(ScmObj port);
 static ScmObj read_quote(ScmObj port, ScmObj quoter);
 
@@ -197,7 +197,7 @@
                 return read_char(port);
             case 'b': case 'o': case 'd': case 'x':
                 SCM_PORT_UNGETC(port, c1);
-                return parse_number(read_word(port));
+                return parse_number(port);
             case EOF:
                 SigScm_Error("end in #\n");
             default:
@@ -392,8 +392,9 @@
 {
     int number = 0;
     int str_len = 0;
-    char  *str = NULL;
-    char  *first_nondigit = NULL;
+    char *str = NULL;
+    char *first_nondigit = NULL;
+    ScmObj ret = SCM_NULL;
 
 #if DEBUG_PARSER
     printf("read_number_or_symbol\n");
@@ -406,10 +407,13 @@
     /* see if it's a decimal integer */
     number = (int)strtol(str, &first_nondigit, 10);
 
-    if (*first_nondigit)
-        return Scm_Intern(str);
+    /* set return obj */
+    ret = (*first_nondigit) ? Scm_Intern(str) : Scm_NewInt(number);
 
-    return Scm_NewInt(number);
+    /* free */
+    free(str);
+
+    return ret;
 }
 
 
@@ -491,25 +495,29 @@
 }
 
 /* str should be what appeared right after '#' (eg. #b123) */
-static ScmObj parse_number(const char *str)
+static ScmObj parse_number(ScmObj port)
 {
     int radix  = 0;
     int number = 0;
     char *first_nondigit = NULL;
+    char *numstr = read_word(port);
 
-    switch (str[0]) {
+    switch (numstr[0]) {
     case 'b': radix = 2;  break;
     case 'o': radix = 8;  break;
     case 'd': radix = 10; break;
     case 'x': radix = 16; break;
     default:
-        SigScm_Error("ill-formatted number: #%s\n", str);
+        SigScm_Error("ill-formatted number: #%s\n", numstr);
     }
 
-    number = (int)strtol(str+1, &first_nondigit, radix);
-
+    /* get num */
+    number = (int)strtol(numstr+1, &first_nondigit, radix);
     if (*first_nondigit)
-        SigScm_Error("ill-formatted number: #%s\n", str);
+        SigScm_Error("ill-formatted number: #%s\n", numstr);
 
+    /* free str */
+    free(numstr);
+
     return Scm_NewInt(number);
 }



More information about the uim-commit mailing list