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

yamaken at freedesktop.org yamaken at freedesktop.org
Tue Nov 1 03:53:38 PST 2005


Author: yamaken
Date: 2005-11-01 03:53:33 -0800 (Tue, 01 Nov 2005)
New Revision: 1931

Modified:
   branches/r5rs/sigscheme/fileport.c
   branches/r5rs/sigscheme/fileport.h
   branches/r5rs/sigscheme/sigscheme.c
Log:
* sigscheme/fileport.h
  - (ScmFilePort_new_shared): New function decl
* sigscheme/fileport.c
  - (OK): New macro
  - (struct ScmFilePort_): Add member 'ownership'
  - (fileport_new_internal): New static function inherits codes of
    ScmFilePort_new()
  - (ScmFilePort_new): Reimplement as wrapper to fileport_new_internal()
  - (ScmFilePort_new_shared): New function
  - (fileport_close): Add ownership-aware fclose() handling
* sigscheme/sigscheme.c
  - (SigScm_Initialize_internal): Fix unwanted fclose() of stdio streams


Modified: branches/r5rs/sigscheme/fileport.c
===================================================================
--- branches/r5rs/sigscheme/fileport.c	2005-11-01 11:22:18 UTC (rev 1930)
+++ branches/r5rs/sigscheme/fileport.c	2005-11-01 11:53:33 UTC (rev 1931)
@@ -56,6 +56,7 @@
 /*=======================================
   File Local Macro Definitions
 =======================================*/
+#define OK 0
 
 /*=======================================
   File Local Type Definitions
@@ -67,11 +68,15 @@
 
     FILE *file;
     char *aux_info;  /* human readable auxilialy information about the file */
+    int ownership;   /* whether close the file at fileport_close() */
 };
 
 /*=======================================
   File Local Function Declarations
 =======================================*/
+static ScmBytePort *fileport_new_internal(FILE *file, const char *aux_info,
+                                          int ownership);
+
 static ScmBytePort *fileport_dyn_cast(ScmBytePort *bport,
                                       const ScmBytePortVTbl *dest_vptr);
 static int fileport_close(ScmFilePort *bport);
@@ -115,9 +120,9 @@
     return;
 }
 
-ScmBytePort *
-ScmFilePort_new(FILE *file, const char *aux_info)
- {
+static ScmBytePort *
+fileport_new_internal(FILE *file, const char *aux_info, int ownership)
+{
     ScmFilePort *port;
 
     SCM_PORT_ALLOC(BYTE, port, ScmFilePort);
@@ -125,11 +130,24 @@
     port->vptr = ScmFilePort_vptr;
     port->file = file;
     port->aux_info = strdup(aux_info);
+    port->ownership = ownership;
 
     return (ScmBytePort *)port;
 }
 
 ScmBytePort *
+ScmFilePort_new(FILE *file, const char *aux_info)
+{
+    return fileport_new_internal(file, aux_info, TRUE);
+}
+
+ScmBytePort *
+ScmFilePort_new_shared(FILE *file, const char *aux_info)
+{
+    return fileport_new_internal(file, aux_info, FALSE);
+}
+
+ScmBytePort *
 ScmFilePort_open_input_file(const char *path)
 {
     FILE *file;
@@ -161,7 +179,7 @@
 {
     int err;
 
-    err = fclose(port->file);
+    err = (port->ownership) ? fclose(port->file) : OK;
     free(port->aux_info);
     free(port);
 

Modified: branches/r5rs/sigscheme/fileport.h
===================================================================
--- branches/r5rs/sigscheme/fileport.h	2005-11-01 11:22:18 UTC (rev 1930)
+++ branches/r5rs/sigscheme/fileport.h	2005-11-01 11:53:33 UTC (rev 1931)
@@ -70,6 +70,7 @@
 void Scm_fileport_init(void);
 
 ScmBytePort *ScmFilePort_new(FILE *file, const char *aux_info);
+ScmBytePort *ScmFilePort_new_shared(FILE *file, const char *aux_info);
 ScmBytePort *ScmFilePort_open_input_file(const char *path);
 ScmBytePort *ScmFilePort_open_output_file(const char *path);
 

Modified: branches/r5rs/sigscheme/sigscheme.c
===================================================================
--- branches/r5rs/sigscheme/sigscheme.c	2005-11-01 11:22:18 UTC (rev 1930)
+++ branches/r5rs/sigscheme/sigscheme.c	2005-11-01 11:53:33 UTC (rev 1931)
@@ -168,13 +168,13 @@
     Scm_fileport_init();
     Scm_sbcport_init();
 
-    bport = ScmFilePort_new(stdin, "stdin");
+    bport = ScmFilePort_new_shared(stdin, "stdin");
     scm_current_input_port = Scm_NewPort(ScmSingleByteCharPort_new(bport),
                                          SCM_PORTFLAG_INPUT);
-    bport = ScmFilePort_new(stdout, "stdout");
+    bport = ScmFilePort_new_shared(stdout, "stdout");
     scm_current_output_port = Scm_NewPort(ScmSingleByteCharPort_new(bport),
                                           SCM_PORTFLAG_OUTPUT);
-    bport = ScmFilePort_new(stderr, "stderr");
+    bport = ScmFilePort_new_shared(stderr, "stderr");
     scm_current_error_port = Scm_NewPort(ScmSingleByteCharPort_new(bport),
                                          SCM_PORTFLAG_OUTPUT);
 #else /* SCM_USE_NEWPORT */



More information about the uim-commit mailing list