gc-benchmarks: Adapt `gcold.scm' so that if conforms to the framework.
[bpt/guile.git] / libguile / fports.c
index 7819fda..5e4e6df 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,7 @@
 \f
 #define _LARGEFILE64_SOURCE      /* ask for stat64 etc */
 
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
 
@@ -119,7 +119,7 @@ scm_fport_buffer_add (SCM port, long read_size, int write_size)
 
   if (SCM_INPUT_PORT_P (port) && read_size > 0)
     {
-      pt->read_buf = scm_gc_malloc (read_size, "port buffer");
+      pt->read_buf = scm_gc_malloc_pointerless (read_size, "port buffer");
       pt->read_pos = pt->read_end = pt->read_buf;
       pt->read_buf_size = read_size;
     }
@@ -131,7 +131,7 @@ scm_fport_buffer_add (SCM port, long read_size, int write_size)
 
   if (SCM_OUTPUT_PORT_P (port) && write_size > 0)
     {
-      pt->write_buf = scm_gc_malloc (write_size, "port buffer");
+      pt->write_buf = scm_gc_malloc_pointerless (write_size, "port buffer");
       pt->write_pos = pt->write_buf;
       pt->write_buf_size = write_size;
     }
@@ -221,17 +221,22 @@ SCM_DEFINE (scm_setvbuf, "setvbuf", 2, 1, 0,
 /* Move ports with the specified file descriptor to new descriptors,
  * resetting the revealed count to 0.
  */
-static SCM
-scm_i_evict_port (SCM handle, void *closure)
+static void
+scm_i_evict_port (void *closure, SCM port)
 {
   int fd = * (int*) closure;
-  SCM port = SCM_CAR (handle);
 
   if (SCM_FPORTP (port))
     {
-      scm_t_fport *fp = SCM_FSTREAM (port);
+      scm_t_port *p;
+      scm_t_fport *fp;
+
+      /* XXX: In some cases, we can encounter a port with no associated ptab
+        entry.  */
+      p = SCM_PTAB_ENTRY (port);
+      fp = (p != NULL) ? (scm_t_fport *) p->stream : NULL;
 
-      if (fp->fdes == fd)
+      if ((fp != NULL) && (fp->fdes == fd))
        {
          fp->fdes = dup (fd);
          if (fp->fdes == -1)
@@ -239,18 +244,12 @@ scm_i_evict_port (SCM handle, void *closure)
          scm_set_port_revealed_x (port, scm_from_int (0));
        }
     }
-
-  return handle;
 }
 
 void
 scm_evict_ports (int fd)
 {
-  scm_i_scm_pthread_mutex_lock (&scm_i_port_table_mutex);
-  scm_internal_hash_for_each_handle (&scm_i_evict_port,
-                                    (void*) &fd,
-                                    scm_i_port_weak_hash);
-  scm_i_pthread_mutex_unlock (&scm_i_port_table_mutex);
+  scm_c_port_for_each (scm_i_evict_port, (void *) &fd);
 }
 
 
@@ -463,7 +462,8 @@ scm_i_fdes_to_port (int fdes, long mode_bits, SCM name)
   pt = SCM_PTAB_ENTRY(port);
   {
     scm_t_fport *fp
-      = (scm_t_fport *) scm_gc_malloc (sizeof (scm_t_fport), "file port");
+      = (scm_t_fport *) scm_gc_malloc_pointerless (sizeof (scm_t_fport),
+                                                  "file port");
 
     fp->fdes = fdes;
     pt->rw_random = SCM_FDES_RANDOM_P (fdes);
@@ -674,7 +674,7 @@ fport_seek_or_seek64 (SCM port, off_t_or_off64_t offset, int whence)
    case on NetBSD apparently), then fport_seek_or_seek64 is right to be
    fport_seek already.  */
 
-#if HAVE_STAT64 && SIZEOF_OFF_T != SIZEOF_OFF64_T
+#if GUILE_USE_64_CALLS && HAVE_STAT64 && SIZEOF_OFF_T != SIZEOF_OFF64_T
 static off_t
 fport_seek (SCM port, off_t offset, int whence)
 {