a few fixups to primitive functions
authorGary Houston <ghouston@arglist.com>
Sun, 4 Aug 1996 22:32:07 +0000 (22:32 +0000)
committerGary Houston <ghouston@arglist.com>
Sun, 4 Aug 1996 22:32:07 +0000 (22:32 +0000)
ice-9/ChangeLog
ice-9/boot-9.scm
libguile/ChangeLog
libguile/fports.c
libguile/ioext.c
libguile/ports.c

index 0a66f2b..3ad5a0e 100644 (file)
@@ -1,3 +1,13 @@
+Sat Aug  3 06:16:35 1996  Gary Houston  <ghouston@actrix.gen.nz>
+
+       * boot-9.scm (*null-device*): global constant from goonix.
+       (move->fdes): adjusted for boolean primitive-move->fdes.  return
+       the modified port, always set revealed count to 1 (SCSH compatible).
+       (release-port-handle port): from goonix (SCSH compatible).
+       (%open-file): removed.
+       (open-input-file, open-output-file, file-exists?, file-is-directory?):
+       modified for open-file change (does not return #f).
+
 Thu Aug  1 02:52:42 1996  Jim Blandy  <jimb@totoro.cyclic.com>
 
        * Makefile.in (dist-dir): New target for new dist system.
index 9c8c307..e40d07d 100644 (file)
@@ -90,7 +90,6 @@
 ;;; {Silly Naming Cleanups and Trivial Functions}
 ;;;
 
-(define %open-file open-file)
 (define (id x) x)
 (define < <?)
 (define <= <=?)
                    ((MS-DOS WINDOWS ATARIST) "r+b")
                    (else "r+")))
 
+(define *null-device* "/dev/null")
+
 (define (open-input-file str)
-  (or (open-file str OPEN_READ)
-      (error "OPEN-INPUT-FILE couldn't find file " str)))
+  (open-file str OPEN_READ))
 
 (define (open-output-file str)
-  (or (open-file str OPEN_WRITE)
-      (error "OPEN-OUTPUT-FILE couldn't find file " str)))
+  (open-file str OPEN_WRITE))
 
 (define (open-io-file str) (open-file str OPEN_BOTH))
 (define close-input-port close-port)
 ;;;
 
 (define (file-exists? str)
-  (let ((port (open-file str OPEN_READ)))
+  ;; we don't have false-if-exception (or defmacro) yet.
+  (let ((port (catch #t (lambda () (open-file str OPEN_READ))
+                    (lambda args #f))))
     (if port (begin (close-port port) #t)
        #f)))
 
 (define (file-is-directory? str)
-  (let ((port (open-file (string-append str "/.") OPEN_READ)))
+  (let ((port (catch #t (lambda () (open-file (string-append str "/.")
+                                             OPEN_READ))
+                    (lambda args #f))))
     (if port (begin (close-port port) #t)
        #f)))
 
 (define (setprotoent arg) (setproto arg))
 (define (setpwent arg) (setpw arg))
 (define (setservent arg) (setserv arg))
+
 (define (move->fdes port fd)
-  (if (= 1 (primitive-move->fdes port fd))
-      (set-port-revealed! port 1)))
+  (primitive-move->fdes port fd)
+  (set-port-revealed! port 1)
+  port)
+
+(define (release-port-handle port)
+  (let ((revealed (port-revealed port)))
+    (if (> revealed 0)
+       (set-port-revealed! port (- revealed 1)))))
 
 \f
 ;;; {Load Paths}
index 170abf6..5776033 100644 (file)
@@ -1,5 +1,18 @@
 Sat Aug  3 01:27:14 1996  Gary Houston  <ghouston@actrix.gen.nz>
 
+       * ioext.c (scm_sys_fdopen): fix the port-table assignment.
+
+       * fports.c (scm_open_file): don't return #f, throw error.
+
+       * ioext.c (fileno): renamed from %fileno.
+       (soft-fileno): deleted.
+
+       * ports.c (scm_port_revealed): don't need to check for -1 from
+       scm_revealed_count.
+       (scm_set_port_revealed_x): return unspecified, not #f.
+
+       * ioext.c (primitive-move->fdes): return #t or #f, not 1 or 0.
+
        * fdsocket.c: getsockopt, setsockopt: use HAVE_STRUCT_LINGER.
 
        * scmconfig.h.in: add HAVE_STRUCT_LINGER.
index 234c21d..34264a7 100644 (file)
@@ -193,10 +193,12 @@ scm_open_file (filename, modes)
   if (SCM_SUBSTRP (modes))
     modes = scm_makfromstr (SCM_ROCHARS (modes), SCM_ROLENGTH (modes), 0);
   port = scm_mkfile (SCM_ROCHARS (filename), SCM_ROCHARS (modes));
-  /* Force the compiler to keep filename and modes alive:
-   */
-  if (port == SCM_BOOL_F)
+
+  if (port == SCM_BOOL_F) {
+    SCM_SYSERROR (s_open_file);
+    /* Force the compiler to keep filename and modes alive.  */
     scm_cons (filename, modes);
+  }
   return port;
 }
 
index 707a95e..4dea9f7 100644 (file)
@@ -210,7 +210,7 @@ scm_sys_redirect_port (into_pt, from_pt)
   return SCM_UNSPECIFIED;
 }
 
-SCM_PROC (s_sys_fileno, "%fileno", 1, 0, 0, scm_sys_fileno);
+SCM_PROC (s_sys_fileno, "fileno", 1, 0, 0, scm_sys_fileno);
 #ifdef __STDC__
 SCM 
 scm_sys_fileno (SCM port)
@@ -228,27 +228,6 @@ scm_sys_fileno (port)
   return SCM_MAKINUM (fd);
 }
 
-SCM_PROC (s_sys_soft_fileno, "soft-fileno", 1, 0, 0, scm_sys_soft_fileno);
-#ifdef __STDC__
-SCM 
-scm_sys_soft_fileno (SCM port)
-#else
-SCM 
-scm_sys_soft_fileno (port)
-     SCM port;
-#endif
-{
-  int fd;
-  SCM_ASSERT (SCM_NIMP (port) && SCM_OPFPORTP (port), port, SCM_ARG1, s_sys_fileno);
-
-  fd = fileno ((FILE *)SCM_STREAM (port));
-  if (fd == -1)
-    SCM_SYSERROR (s_sys_soft_fileno);
-  return SCM_MAKINUM (fd);
-}
-
-
-
 SCM_PROC (s_sys_isatty, "isatty?", 1, 0, 0, scm_sys_isatty_p);
 #ifdef __STDC__
 SCM 
@@ -283,17 +262,21 @@ scm_sys_fdopen (fdes, modes)
 {
   FILE *f;
   SCM port;
+  struct scm_port_table * pt;
 
   SCM_ASSERT (SCM_INUMP (fdes), fdes, SCM_ARG1, s_sys_fdopen);
   SCM_ASSERT (SCM_NIMP (modes) && SCM_STRINGP (modes), modes, SCM_ARG2, s_sys_fdopen);
+  SCM_NEWCELL (port);
   SCM_DEFER_INTS;
   f = fdopen (SCM_INUM (fdes), SCM_CHARS (modes));
   if (f == NULL)
     SCM_SYSERROR (s_sys_fdopen);
-  SCM_NEWCELL (port);
-  SCM_CAR (port) = scm_tc16_fport | scm_mode_bits (SCM_CHARS (modes));
-  SCM_SETSTREAM (port,(SCM)f);
-  scm_add_to_port_table (port);
+  pt = scm_add_to_port_table (port);
+  SCM_SETPTAB_ENTRY (port, pt);
+  if (SCM_BUF0 & (SCM_CAR (port) = scm_tc16_fport
+                 | scm_mode_bits (SCM_CHARS (modes))))
+    scm_setbuf0 (port);
+  SCM_SETSTREAM (port, (SCM)f);
   SCM_ALLOW_INTS;
   return port;
 }
@@ -301,8 +284,8 @@ scm_sys_fdopen (fdes, modes)
 
 
 /* Move a port's underlying file descriptor to a given value.
- * Returns  0 if fdes is already the given value.
- *          1 if fdes moved. 
+ * Returns  #f if fdes is already the given value.
+ *          #t if fdes moved. 
  * MOVE->FDES is implemented in Scheme and calls this primitive.
  */
 SCM_PROC (s_sys_primitive_move_to_fdes, "primitive-move->fdes", 2, 0, 0, scm_sys_primitive_move_to_fdes);
@@ -330,7 +313,7 @@ scm_sys_primitive_move_to_fdes (port, fd)
   if  (old_fd == new_fd)
     {
       SCM_ALLOW_INTS;
-      return SCM_MAKINUM (0);
+      return SCM_BOOL_F;
     }
   scm_evict_ports (new_fd);
   rv = dup2 (old_fd, new_fd);
@@ -339,7 +322,7 @@ scm_sys_primitive_move_to_fdes (port, fd)
   scm_setfileno (stream, new_fd);
   SCM_SYSCALL (close (old_fd));  
   SCM_ALLOW_INTS;
-  return SCM_MAKINUM (1);
+  return SCM_BOOL_T;
 }
 
 #ifdef __STDC__
index cbaecbc..b571552 100644 (file)
@@ -438,9 +438,8 @@ scm_pt_member (member)
 #endif
 
 
-/* Find a port in the table and return its revealed count.  Return -1
- * if the port isn't in the table (should not happen).  Also used by
- * the garbage collector.
+/* Find a port in the table and return its revealed count.
+   Also used by the garbage collector.
  */
 #ifdef __STDC__
 int
@@ -468,14 +467,8 @@ scm_port_revealed (port)
      SCM port;
 #endif
 {
-  int result;
-
   SCM_ASSERT (SCM_NIMP (port) && SCM_PORTP (port), port, SCM_ARG1, s_port_revealed);
-
-  if ((result = scm_revealed_count (port)) == -1)
-    return SCM_BOOL_F;
-  else
-    return SCM_MAKINUM (result);
+  return SCM_MAKINUM (scm_revealed_count (port));
 }
 
 /* Set the revealed count for a port.  */
@@ -495,7 +488,7 @@ scm_set_port_revealed_x (port, rcount)
   SCM_DEFER_INTS;
   SCM_REVEALED (port) = SCM_INUM (rcount);
   SCM_ALLOW_INTS;
-  return SCM_BOOL_F;
+  return SCM_UNSPECIFIED;
 }
 
 /* scm_close_port