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

yamaken at freedesktop.org yamaken at freedesktop.org
Mon Oct 31 12:17:54 PST 2005


Author: yamaken
Date: 2005-10-31 12:17:49 -0800 (Mon, 31 Oct 2005)
New Revision: 1910

Modified:
   branches/r5rs/sigscheme/strport.c
   branches/r5rs/sigscheme/strport.h
Log:
* sigscheme/strport.h
  - (ScmInputStrPort_finalizer, ScmOutputStrPort_finalizer): New type
  - (ScmInputStrPort_new, ScmInputStrPort_new_copying,
    ScmInputStrPort_new_const, ScmOutputStrPort_new): Add finalizer arg
* sigscheme/strport.c
  - (struct ScmInputStrPort_, struct ScmOutputStrPort_, istrport_new,
    ScmInputStrPort_new, ScmInputStrPort_new_copying,
    ScmInputStrPort_new_const, istrport_close, ScmOutputStrPort_new,
    ostrport_close): Add finalizer support


Modified: branches/r5rs/sigscheme/strport.c
===================================================================
--- branches/r5rs/sigscheme/strport.c	2005-10-31 18:30:32 UTC (rev 1909)
+++ branches/r5rs/sigscheme/strport.c	2005-10-31 20:17:49 UTC (rev 1910)
@@ -71,6 +71,7 @@
     const char *cur;
     int has_str_ownership;
     void *opaque;  /* client-specific opaque information */
+    ScmInputStrPort_finalizer finalize;
 };
 
 /* inherits ScmBytePort */
@@ -81,12 +82,14 @@
     size_t cur;       /* offset to terminal '\0' */
     size_t buf_size;
     void *opaque;     /* client-specific opaque information */
+    ScmOutputStrPort_finalizer finalize;
 };
 
 /*=======================================
   File Local Function Declarations
 =======================================*/
-static ScmBytePort *istrport_new(char *str, int ownership);
+static ScmBytePort *istrport_new(char *str, int ownership,
+                                 ScmInputStrPort_finalizer finalize);
 
 static ScmBytePort *istrport_dyn_cast(ScmBytePort *bport,
                                       const ScmBytePortVTbl *dest_vptr);
@@ -160,7 +163,7 @@
 }
 
 static ScmBytePort *
-istrport_new(char *str, int ownership)
+istrport_new(char *str, int ownership, ScmInputStrPort_finalizer finalize)
 {
     ScmInputStrPort *port;
 
@@ -172,27 +175,29 @@
     port->cur = port->str = str;
     port->has_str_ownership = ownership;
     port->opaque = NULL;
+    port->finalize = finalize;
 
     return (ScmBytePort *)port;
 }
 
 ScmBytePort *
-ScmInputStrPort_new(char *str)
+ScmInputStrPort_new(char *str, ScmInputStrPort_finalizer finalize)
 {
-    return istrport_new(str, TRUE);
+    return istrport_new(str, TRUE, finalize);
 }
 
 ScmBytePort *
-ScmInputStrPort_new_copying(const char *str)
+ScmInputStrPort_new_copying(const char *str,
+                            ScmInputStrPort_finalizer finalize)
 {
-    return istrport_new(strdup(str), TRUE);
+    return istrport_new(strdup(str), TRUE, finalize);
 }
 
 ScmBytePort *
-ScmInputStrPort_new_const(const char *str)
+ScmInputStrPort_new_const(const char *str, ScmInputStrPort_finalizer finalize)
 {
     /* str is actually treated as const */
-    return istrport_new((char *)str, FALSE);
+    return istrport_new((char *)str, FALSE, finalize);
 }
 
 void **
@@ -219,6 +224,8 @@
 static int
 istrport_close(ScmInputStrPort *port)
 {
+    if (port->finalize)
+        (*port->finalize)(&port->str, port->has_str_ownership, &port->opaque);
     if (port->has_str_ownership)
         free(port->str);
     free(port);
@@ -274,7 +281,7 @@
 
 
 ScmBytePort *
-ScmOutputStrPort_new(void)
+ScmOutputStrPort_new(ScmOutputStrPort_finalizer finalize)
 {
     ScmOutputStrPort *port;
 
@@ -287,6 +294,7 @@
     port->cur = 0;
     port->buf_size = 0;
     port->opaque = NULL;
+    port->finalize = finalize;
 
     return (ScmBytePort *)port;
 }
@@ -328,6 +336,8 @@
 static int
 ostrport_close(ScmOutputStrPort *port)
 {
+    if (port->finalize)
+        (*port->finalize)(&port->str, port->buf_size, &port->opaque);
     free(port->str);
     free(port);
 

Modified: branches/r5rs/sigscheme/strport.h
===================================================================
--- branches/r5rs/sigscheme/strport.h	2005-10-31 18:30:32 UTC (rev 1909)
+++ branches/r5rs/sigscheme/strport.h	2005-10-31 20:17:49 UTC (rev 1910)
@@ -56,6 +56,10 @@
 /*=======================================
   Type Definitions
 =======================================*/
+typedef void (*ScmInputStrPort_finalizer)(char **str, int ownership,
+                                          void **opaque);
+typedef void (*ScmOutputStrPort_finalizer)(char **str, size_t buf_size,
+                                           void **opaque);
 
 /*=======================================
    Variable Declarations
@@ -68,12 +72,15 @@
 =======================================*/
 void Scm_strport_init(void);
 
-ScmBytePort *ScmInputStrPort_new(char *str);
-ScmBytePort *ScmInputStrPort_new_copying(const char *str);
-ScmBytePort *ScmInputStrPort_new_const(const char *str);
+ScmBytePort *ScmInputStrPort_new(char *str,
+                                 ScmInputStrPort_finalizer finalize);
+ScmBytePort *ScmInputStrPort_new_copying(const char *str,
+                                         ScmInputStrPort_finalizer finalize);
+ScmBytePort *ScmInputStrPort_new_const(const char *str,
+                                       ScmInputStrPort_finalizer finalize);
 void **ScmInputStrPort_ref_opaque(ScmBytePort *bport);
 
-ScmBytePort *ScmOutputStrPort_new(void);
+ScmBytePort *ScmOutputStrPort_new(ScmOutputStrPort_finalizer finalize);
 const char *ScmOutputStrPort_str(ScmBytePort *bport);
 void **ScmOutputStrPort_ref_opaque(ScmBytePort *bport);
 



More information about the uim-commit mailing list