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

yamaken at freedesktop.org yamaken at freedesktop.org
Thu Dec 15 20:32:57 PST 2005


Author: yamaken
Date: 2005-12-15 20:32:53 -0800 (Thu, 15 Dec 2005)
New Revision: 2594

Modified:
   branches/r5rs/sigscheme/basecport.c
   branches/r5rs/sigscheme/baseport.h
   branches/r5rs/sigscheme/fileport.c
   branches/r5rs/sigscheme/mbcport.c
   branches/r5rs/sigscheme/nullport.c
   branches/r5rs/sigscheme/sbcport.c
   branches/r5rs/sigscheme/sigscheme.h
   branches/r5rs/sigscheme/strport.c
Log:
* sigscheme/baseport.h
  - (SCM_PORT_ALLOC): Removed
  - (SCM_PORT_MALLOC, SCM_PORT_CALLOC, SCM_PORT_REALLOC): New macro
* sigscheme/sigscheme.h
  - (SCM_PORT_MALLOC, SCM_PORT_CALLOC, SCM_PORT_REALLOC): New macro
* sigscheme/mbcport.c
  - (ScmMultiByteCharPort_new): Replace SCM_PORT_ALLOC() with
    SCM_PORT_MALLOC()
* sigscheme/sbcport.c
  - (ScmSingleByteCharPort_new): Ditto
* sigscheme/nullport.c
  - (ScmNullPort_new): Ditto
* sigscheme/fileport.c
  - (fileport_new_internal): Ditto
  - (fileport_inspect): Add allocation error check by
    SCM_PORT_MALLOC()
* sigscheme/basecport.c
  - (ScmBaseCharPort_inspect): Ditto
* sigscheme/strport.c
  - (istrport_new, ScmOutputStrPort_new): Replace SCM_PORT_ALLOC()
    with SCM_PORT_MALLOC()
  - (ostrport_append): Replace manual error handling with
    SCM_PORT_REALLOC()


Modified: branches/r5rs/sigscheme/basecport.c
===================================================================
--- branches/r5rs/sigscheme/basecport.c	2005-12-16 03:07:54 UTC (rev 2593)
+++ branches/r5rs/sigscheme/basecport.c	2005-12-16 04:32:53 UTC (rev 2594)
@@ -121,7 +121,7 @@
     bport_part = SCM_BYTEPORT_INSPECT((ScmBytePort *)port->bport);
     size = strlen(header) + strlen(encoding) + strlen(bport_part)
         + sizeof("  ");
-    combined = malloc(size);
+    combined = SCM_PORT_MALLOC(size);
     snprintf(combined, size, "%s %s %s", header, encoding, bport_part);
     free(bport_part);
 

Modified: branches/r5rs/sigscheme/baseport.h
===================================================================
--- branches/r5rs/sigscheme/baseport.h	2005-12-16 03:07:54 UTC (rev 2593)
+++ branches/r5rs/sigscheme/baseport.h	2005-12-16 04:32:53 UTC (rev 2594)
@@ -76,12 +76,16 @@
 #define SCM_PORT_ERROR_NOMEM(klass, port, type)                              \
     SCM_##klass##PORT_ERROR((port), #type ": Out of memory")
 
-#define SCM_PORT_ALLOC(klass, port, type)                                    \
-    do {                                                                     \
-        (port) = malloc(sizeof(type));                                       \
-        if (!(port))                                                         \
-            SCM_PORT_ERROR_NOMEM(klass, NULL, type);                         \
-    } while (/* CONSTCOND */ 0)
+/* Allocation error handling in the macros is strongly recommended. */
+#ifndef SCM_PORT_MALLOC
+#define SCM_PORT_MALLOC(size) (malloc(size))
+#endif /* SCM_PORT_MALLOC */
+#ifndef SCM_PORT_CALLOC
+#define SCM_PORT_CALLOC(number, size) (calloc(number, size))
+#endif /* SCM_PORT_CALLOC */
+#ifndef SCM_PORT_REALLOC
+#define SCM_PORT_REALLOC(ptr, size) (realloc(ptr, size))
+#endif /* SCM_PORT_REALLOC */
 
 /*
  * To allow safe method invocation (contains from subclasses), all non-standard

Modified: branches/r5rs/sigscheme/fileport.c
===================================================================
--- branches/r5rs/sigscheme/fileport.c	2005-12-16 03:07:54 UTC (rev 2593)
+++ branches/r5rs/sigscheme/fileport.c	2005-12-16 04:32:53 UTC (rev 2594)
@@ -132,7 +132,7 @@
 {
     ScmFilePort *port;
 
-    SCM_PORT_ALLOC(BYTE, port, ScmFilePort);
+    port = SCM_PORT_MALLOC(sizeof(ScmFilePort));
 
     port->vptr = ScmFilePort_vptr;
     port->file = file;
@@ -198,7 +198,7 @@
 
     if (port->aux_info) {
         size = sizeof("file ") + strlen(port->aux_info);
-        combined = malloc(size);
+        combined = SCM_PORT_MALLOC(size);
         snprintf(combined, size, "file %s", port->aux_info);
         return combined;
     } else {

Modified: branches/r5rs/sigscheme/mbcport.c
===================================================================
--- branches/r5rs/sigscheme/mbcport.c	2005-12-16 03:07:54 UTC (rev 2593)
+++ branches/r5rs/sigscheme/mbcport.c	2005-12-16 04:32:53 UTC (rev 2594)
@@ -135,7 +135,7 @@
 {
     ScmMultiByteCharPort *cport;
 
-    SCM_PORT_ALLOC(CHAR, cport, ScmMultiByteCharPort);
+    cport = SCM_PORT_MALLOC(sizeof(ScmMultiByteCharPort));
     ScmMultiByteCharPort_construct(cport, ScmMultiByteCharPort_vptr,
                                    bport, codec);
 

Modified: branches/r5rs/sigscheme/nullport.c
===================================================================
--- branches/r5rs/sigscheme/nullport.c	2005-12-16 03:07:54 UTC (rev 2593)
+++ branches/r5rs/sigscheme/nullport.c	2005-12-16 04:32:53 UTC (rev 2594)
@@ -112,7 +112,7 @@
 {
     ScmNullPort *port;
 
-    SCM_PORT_ALLOC(BYTE, port, ScmNullPort);
+    port = SCM_PORT_MALLOC(sizeof(ScmNullPort));
 
     port->vptr = ScmNullPort_vptr;
 

Modified: branches/r5rs/sigscheme/sbcport.c
===================================================================
--- branches/r5rs/sigscheme/sbcport.c	2005-12-16 03:07:54 UTC (rev 2593)
+++ branches/r5rs/sigscheme/sbcport.c	2005-12-16 04:32:53 UTC (rev 2594)
@@ -108,7 +108,7 @@
 {
     ScmSingleByteCharPort *cport;
 
-    SCM_PORT_ALLOC(CHAR, cport, ScmSingleByteCharPort);
+    cport = SCM_PORT_MALLOC(sizeof(ScmSingleByteCharPort));
     ScmSingleByteCharPort_construct(cport, ScmSingleByteCharPort_vptr, bport);
 
     return (ScmCharPort *)cport;

Modified: branches/r5rs/sigscheme/sigscheme.h
===================================================================
--- branches/r5rs/sigscheme/sigscheme.h	2005-12-16 03:07:54 UTC (rev 2593)
+++ branches/r5rs/sigscheme/sigscheme.h	2005-12-16 04:32:53 UTC (rev 2594)
@@ -165,6 +165,9 @@
  */
 #define SCM_CHARPORT_ERROR(cport, msg) (SigScm_Error(msg))
 #define SCM_BYTEPORT_ERROR(bport, msg) (SigScm_Error(msg))
+#define SCM_PORT_MALLOC(size)          (scm_malloc(size))
+#define SCM_PORT_CALLOC(number, size)  (scm_calloc(number, size))
+#define SCM_PORT_REALLOC(ptr, size)    (scm_realloc(ptr, size))
 
 #define SCM_ASSERT_LIVE_PORT(port)                                           \
     (SCM_PORT_IMPL(port)                                                     \

Modified: branches/r5rs/sigscheme/strport.c
===================================================================
--- branches/r5rs/sigscheme/strport.c	2005-12-16 03:07:54 UTC (rev 2593)
+++ branches/r5rs/sigscheme/strport.c	2005-12-16 04:32:53 UTC (rev 2594)
@@ -169,7 +169,7 @@
 {
     ScmInputStrPort *port;
 
-    SCM_PORT_ALLOC(BYTE, port, ScmInputStrPort);
+    port = SCM_PORT_MALLOC(sizeof(ScmInputStrPort));
 
     port->vptr = ScmInputStrPort_vptr;
     port->cur = port->str = str;
@@ -289,7 +289,7 @@
 {
     ScmOutputStrPort *port;
 
-    SCM_PORT_ALLOC(BYTE, port, ScmOutputStrPort);
+    port = SCM_PORT_MALLOC(sizeof(ScmOutputStrPort));
 
     port->vptr = ScmOutputStrPort_vptr;
     port->str = NULL;
@@ -412,15 +412,10 @@
 static size_t
 ostrport_append(ScmOutputStrPort *port, size_t len, const char *str)
 {
-    char *new_str;
-
     /* extend the buffer */
     if (port->buf_size - port->cur < len + sizeof((char)'\0')) {
         port->buf_size += (!port->buf_size) ? len + sizeof((char)'\0') : len;
-        new_str = realloc(port->str, port->buf_size);
-        if (!new_str)
-            SCM_PORT_ERROR_NOMEM(BYTE, NULL, ScmOutputStrPort);
-        port->str = new_str;
+        port->str = SCM_PORT_REALLOC(port->str, port->buf_size);
     }
 
     memcpy(port->str + port->cur, str, len);



More information about the uim-commit mailing list