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

yamaken at freedesktop.org yamaken at freedesktop.org
Fri Nov 11 10:08:57 PST 2005


Author: yamaken
Date: 2005-11-11 10:08:52 -0800 (Fri, 11 Nov 2005)
New Revision: 2116

Added:
   branches/r5rs/sigscheme/nullport.c
   branches/r5rs/sigscheme/nullport.h
Modified:
   branches/r5rs/sigscheme/debug.c
   branches/r5rs/sigscheme/io.c
   branches/r5rs/sigscheme/main.c
   branches/r5rs/sigscheme/operations-siod.c
Log:
* This commit fixes the problem reported in [Anthy-dev 2616]. Thanks
  Etsushi.

* sigscheme/nullport.h
  - New file
  - (ScmNullPort_vptr): New variable decl
  - (Scm_nullport_init, ScmNullPort_new): New function decl
* sigscheme/nullport.c
  - New file
  - (OK): New macro
  - (ScmNullPort): New type
  - (ScmNullPort_vtbl): New static variable
  - (ScmNullPort_vptr): New variable
  - (nullport_dyn_cast, nullport_close, nullport_inspect,
    nullport_get_byte, nullport_peek_byte, nullport_byte_readyp,
    nullport_vprintf, nullport_puts, nullport_write, nullport_flush):
    New static function
  - (Scm_nullport_init, ScmNullPort_new): New function
* sigscheme/operations-siod.c
  - Include nullport.c
  - (null_port): New static variable
  - (SigScm_Initialize_SIOD): Add initialization for the null port
  - (SigScm_SetVerboseLevel): Replace the output ports disablement
    when verbose level has been changed to 0 with null_port
* sigscheme/io.c
  - (SigScm_VPortPrintf, SigScm_PortNewline): Remove port existence
    check
* sigscheme/debug.c
  - (SigScm_WriteToPort, SigScm_DisplayToPort): Ditto
* sigscheme/main.c
  - (is_repl_show_result): Removed
  - (repl_loop): Remove port existence check


Modified: branches/r5rs/sigscheme/debug.c
===================================================================
--- branches/r5rs/sigscheme/debug.c	2005-11-11 14:58:55 UTC (rev 2115)
+++ branches/r5rs/sigscheme/debug.c	2005-11-11 18:08:52 UTC (rev 2116)
@@ -181,9 +181,6 @@
 {
     DECLARE_INTERNAL_FUNCTION("SigScm_WriteToPort");
 
-    if (FALSEP(port))
-        return;
-
     ASSERT_PORTP(port);
     SCM_ASSERT_LIVE_PORT(port);
     if (!(SCM_PORT_FLAG(port) & SCM_PORTFLAG_OUTPUT))
@@ -200,9 +197,6 @@
 {
     DECLARE_INTERNAL_FUNCTION("SigScm_DisplayToPort");
 
-    if (FALSEP(port))
-        return;
-
     ASSERT_PORTP(port);
     SCM_ASSERT_LIVE_PORT(port);
     if (!(SCM_PORT_FLAG(port) & SCM_PORTFLAG_OUTPUT))

Modified: branches/r5rs/sigscheme/io.c
===================================================================
--- branches/r5rs/sigscheme/io.c	2005-11-11 14:58:55 UTC (rev 2115)
+++ branches/r5rs/sigscheme/io.c	2005-11-11 18:08:52 UTC (rev 2116)
@@ -127,20 +127,16 @@
 
 void SigScm_VPortPrintf(ScmObj port, const char *fmt, va_list args)
 {
-    if (!FALSEP(port)) {
-        SCM_PORT_VPRINTF(port, fmt, args);
+    SCM_PORT_VPRINTF(port, fmt, args);
 #if SCM_VOLATILE_OUTPUT
-        SCM_PORT_FLUSH(port);
+    SCM_PORT_FLUSH(port);
 #endif
-    }
 }
 
 void SigScm_PortNewline(ScmObj port)
 {
-    if (!FALSEP(port)) {
-        SCM_PORT_PUTS(port, SCM_NEWLINE_STR);
-        SCM_PORT_FLUSH(port);  /* required */
-    }
+    SCM_PORT_PUTS(port, SCM_NEWLINE_STR);
+    SCM_PORT_FLUSH(port);  /* required */
 }
 
 void SigScm_ErrorPrintf(const char *fmt, ...)

Modified: branches/r5rs/sigscheme/main.c
===================================================================
--- branches/r5rs/sigscheme/main.c	2005-11-11 14:58:55 UTC (rev 2115)
+++ branches/r5rs/sigscheme/main.c	2005-11-11 18:08:52 UTC (rev 2116)
@@ -66,7 +66,6 @@
 static void repl(void);
 static void repl_loop(void);
 static int  is_repl_prompt(void);
-static int  is_repl_show_result(void);
 
 /*=======================================
   Function Implementations
@@ -95,7 +94,6 @@
     ScmObj s_exp  = SCM_NULL;
     ScmObj result = SCM_NULL;
     int is_prompt      = is_repl_prompt();
-    int is_show_result = is_repl_show_result();
 
     if (is_prompt)
         SigScm_PortPrintf(scm_current_output_port, PROMPT_STR);
@@ -117,15 +115,13 @@
 #else /* SCM_USE_SRFI34 */
         result = EVAL(s_exp, SCM_INTERACTION_ENV);
 #endif
-        if (is_show_result)
-        {
+
 #if SCM_USE_SRFI38
-            SigScm_WriteToPortWithSharedStructure(scm_current_output_port, result);
+        SigScm_WriteToPortWithSharedStructure(scm_current_output_port, result);
 #else
-            SigScm_WriteToPort(scm_current_output_port, result);
+        SigScm_WriteToPort(scm_current_output_port, result);
 #endif
-            SigScm_PortNewline(scm_current_output_port);
-        }
+        SigScm_PortNewline(scm_current_output_port);
 
         if (is_prompt)
             SigScm_PortPrintf(scm_current_output_port, PROMPT_STR);
@@ -142,16 +138,6 @@
 #endif
 }
 
-static int is_repl_show_result(void)
-{
-#if SCM_COMPAT_SIOD
-    return (FALSEP(ScmOp_providedp(feature_id_siod))
-            || SigScm_GetVerboseLevel() >= 1);
-#else
-    return TRUE;
-#endif
-}
-
 int main(int argc, char **argv)
 {
     char *filename = argv[1];

Added: branches/r5rs/sigscheme/nullport.c
===================================================================
--- branches/r5rs/sigscheme/nullport.c	2005-11-11 14:58:55 UTC (rev 2115)
+++ branches/r5rs/sigscheme/nullport.c	2005-11-11 18:08:52 UTC (rev 2116)
@@ -0,0 +1,180 @@
+/*===========================================================================
+ *  FileName : nullport.c
+ *  About    : A ScmBytePort implementation for null read/write
+ *
+ *  Copyright (C) 2005      by YamaKen (yamaken AT bp.iij4u.or.jp)
+ *
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *  1. Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *  2. Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *  3. Neither the name of authors nor the names of its contributors
+ *     may be used to endorse or promote products derived from this software
+ *     without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
+ *  IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ *  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+===========================================================================*/
+
+/*
+ * - This file is intended to be portable. Don't depend on SigScheme.
+ * - To isolate and hide implementation-dependent things, don't merge this file
+ *   into another
+ */
+
+/*=======================================
+  System Include
+=======================================*/
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+
+/*=======================================
+  Local Include
+=======================================*/
+#include "baseport.h"
+#include "nullport.h"
+
+/*=======================================
+  File Local Macro Definitions
+=======================================*/
+#define OK 0
+
+/*=======================================
+  File Local Type Definitions
+=======================================*/
+typedef ScmBytePort ScmNullPort;
+
+/*=======================================
+  File Local Function Declarations
+=======================================*/
+static ScmBytePort *nullport_dyn_cast(ScmBytePort *bport,
+                                      const ScmBytePortVTbl *dest_vptr);
+static int nullport_close(ScmNullPort *bport);
+static char *nullport_inspect(ScmNullPort *port);
+static int nullport_get_byte(ScmNullPort *bport);
+static int nullport_peek_byte(ScmNullPort *bport);
+static int nullport_byte_readyp(ScmNullPort *bport);
+static int nullport_vprintf(ScmNullPort *bport, const char *str, va_list args);
+static int nullport_puts(ScmNullPort *bport, const char *str);
+static size_t nullport_write(ScmNullPort *bport,
+                             size_t nbytes, const char *buf);
+static int nullport_flush(ScmNullPort *bport);
+
+/*=======================================
+  Variable Declarations
+=======================================*/
+static const ScmBytePortVTbl ScmNullPort_vtbl = {
+    (ScmBytePortMethod_dyn_cast)   &nullport_dyn_cast,
+    (ScmBytePortMethod_close)      &nullport_close,
+    (ScmBytePortMethod_inspect)    &nullport_inspect,
+    (ScmBytePortMethod_get_byte)   &nullport_get_byte,
+    (ScmBytePortMethod_peek_byte)  &nullport_peek_byte,
+    (ScmBytePortMethod_byte_readyp)&nullport_byte_readyp,
+    (ScmBytePortMethod_vprintf)    &nullport_vprintf,
+    (ScmBytePortMethod_puts)       &nullport_puts,
+    (ScmBytePortMethod_write)      &nullport_write,
+    (ScmBytePortMethod_flush)      &nullport_flush
+};
+const ScmBytePortVTbl *ScmNullPort_vptr = &ScmNullPort_vtbl;
+
+/*=======================================
+  Function Implementations
+=======================================*/
+
+/*
+ * Client code must call this first even if current implementation does not
+ * contain actual code.
+ */
+void Scm_nullport_init(void)
+{
+}
+
+ScmBytePort *
+ScmNullPort_new(void)
+{
+    ScmNullPort *port;
+
+    SCM_PORT_ALLOC(BYTE, port, ScmNullPort);
+
+    port->vptr = ScmNullPort_vptr;
+
+    return (ScmBytePort *)port;
+}
+
+static ScmBytePort *
+nullport_dyn_cast(ScmBytePort *bport, const ScmBytePortVTbl *dst_vptr)
+{
+    return (dst_vptr == ScmNullPort_vptr) ? bport : NULL;
+}
+
+static int
+nullport_close(ScmNullPort *port)
+{
+    return OK;
+}
+
+static char *
+nullport_inspect(ScmNullPort *port)
+{
+    return strdup("null");
+}
+
+static int
+nullport_get_byte(ScmNullPort *port)
+{
+    return EOF;
+}
+
+static int
+nullport_peek_byte(ScmNullPort *port)
+{
+    return EOF;
+}
+
+static int
+nullport_byte_readyp(ScmNullPort *port)
+{
+    return TRUE;
+}
+
+static int
+nullport_vprintf(ScmNullPort *port, const char *str, va_list args)
+{
+    return 0;
+}
+
+static int
+nullport_puts(ScmNullPort *port, const char *str)
+{
+    return 0;
+}
+
+static size_t
+nullport_write(ScmNullPort *port, size_t nbytes, const char *buf)
+{
+    return nbytes;
+}
+
+static int
+nullport_flush(ScmNullPort *port)
+{
+    return OK;
+}

Added: branches/r5rs/sigscheme/nullport.h
===================================================================
--- branches/r5rs/sigscheme/nullport.h	2005-11-11 14:58:55 UTC (rev 2115)
+++ branches/r5rs/sigscheme/nullport.h	2005-11-11 18:08:52 UTC (rev 2116)
@@ -0,0 +1,72 @@
+/*===========================================================================
+ *  FileName : nullport.h
+ *  About    : A ScmBytePort implementation for null read/write
+ *
+ *  Copyright (C) 2005      by YamaKen (yamaken AT bp.iij4u.or.jp)
+ *
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *  1. Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *  2. Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *  3. Neither the name of authors nor the names of its contributors
+ *     may be used to endorse or promote products derived from this software
+ *     without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
+ *  IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ *  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+===========================================================================*/
+
+/*
+ * This file is intended to be portable. Don't depend on SigScheme and don't
+ * merge into another file.
+ */
+
+#ifndef __SCM_NULLPORT_H
+#define __SCM_NULLPORT_H
+
+/*=======================================
+  System Include
+=======================================*/
+
+/*=======================================
+  Local Include
+=======================================*/
+#include "baseport.h"
+
+/*=======================================
+  Macro Definitions
+=======================================*/
+
+/*=======================================
+  Type Definitions
+=======================================*/
+
+/*=======================================
+   Variable Declarations
+=======================================*/
+extern const ScmBytePortVTbl *ScmNullPort_vptr;
+
+/*=======================================
+   Function Declarations
+=======================================*/
+void Scm_nullport_init(void);
+
+ScmBytePort *ScmNullPort_new(void);
+
+#endif /* __SCM_NULLPORT_H */

Modified: branches/r5rs/sigscheme/operations-siod.c
===================================================================
--- branches/r5rs/sigscheme/operations-siod.c	2005-11-11 14:58:55 UTC (rev 2115)
+++ branches/r5rs/sigscheme/operations-siod.c	2005-11-11 18:08:52 UTC (rev 2116)
@@ -36,6 +36,8 @@
 =======================================*/
 #include "sigscheme.h"
 #include "sigschemeinternal.h"
+#include "sbcport.h"
+#include "nullport.h"
 
 /*=======================================
   Local Include
@@ -81,7 +83,8 @@
 };
 static long sscm_verbose_level = -1;
 
-static ScmObj saved_output_port  = NULL;
+static ScmObj null_port         = NULL;
+static ScmObj saved_output_port = NULL;
 static ScmObj saved_error_port  = NULL;
 
 /*=======================================
@@ -107,11 +110,17 @@
     REGISTER_FUNC_TABLE(siod_func_info_table);
     Scm_DefineAlias("=", "%%=");
 
+    null_port         = SCM_FALSE;
     saved_output_port = SCM_FALSE;
     saved_error_port  = SCM_FALSE;
+    SigScm_GC_Protect(&null_port);
     SigScm_GC_Protect(&saved_output_port);
     SigScm_GC_Protect(&saved_error_port);
 
+    Scm_nullport_init();
+    null_port = Scm_NewPort(ScmSingleByteCharPort_new(ScmNullPort_new()),
+                            SCM_PORTFLAG_INPUT | SCM_PORTFLAG_OUTPUT);
+
     SigScm_SetVerboseLevel(2);
 }
 
@@ -247,8 +256,8 @@
         saved_error_port = scm_current_error_port;
         saved_output_port = scm_current_output_port;
 
-        scm_current_error_port = SCM_FALSE;
-        scm_current_output_port = SCM_FALSE;
+        scm_current_error_port = null_port;
+        scm_current_output_port = null_port;
     } else {
         if (FALSEP(scm_current_error_port))
             scm_current_error_port = saved_error_port;
@@ -256,3 +265,6 @@
             scm_current_output_port = saved_output_port;
     }
 }
+
+/* FIXME: link conditionally with autoconf */
+#include "nullport.c"



More information about the uim-commit mailing list