("scm_new_port_table_entry"): return a boxed SCM in
authorHan-Wen Nienhuys <hanwen@lilypond.org>
Thu, 8 Aug 2002 23:02:28 +0000 (23:02 +0000)
committerHan-Wen Nienhuys <hanwen@lilypond.org>
Thu, 8 Aug 2002 23:02:28 +0000 (23:02 +0000)
stead of scm_t_port*. The function now takes a tag argument.

libguile/ChangeLog
libguile/fports.c
libguile/ports.c
libguile/ports.h
libguile/strports.c
libguile/vports.c

index 0bb5471..2e8e6fd 100644 (file)
@@ -1,3 +1,8 @@
+2002-08-09  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
+
+       * ports.c ("scm_new_port_table_entry"): return a boxed SCM in
+       stead of scm_t_port*. The function now takes a tag argument.
+
 2002-08-08  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
 
        * gc.h: add scm_debug_cells_gc_interval to public interface
index 36ea331..222b203 100644 (file)
@@ -437,10 +437,10 @@ scm_fdes_to_port (int fdes, char *mode, SCM name)
     }
 
   SCM_DEFER_INTS;
-  pt = scm_new_port_table_entry ();
-  port = scm_cell (scm_tc16_fport | mode_bits, (scm_t_bits) pt);
-  pt->port = port;
-  
+
+  port = scm_new_port_table_entry (scm_tc16_fport);
+  SCM_SET_CELL_TYPE(port, scm_tc16_fport | mode_bits);
+  pt = SCM_PTAB_ENTRY(port);
   {
     scm_t_fport *fp
       = (scm_t_fport *) scm_gc_malloc (sizeof (scm_t_fport), "file port");
index b93fa9d..80ef93d 100644 (file)
@@ -452,10 +452,11 @@ long scm_port_table_size = 0;     /* Number of ports in scm_port_table.  */
 long scm_port_table_room = 20; /* Size of the array.  */
 
 
-scm_t_port *
-scm_new_port_table_entry (void)
+SCM
+scm_new_port_table_entry (scm_t_bits tag)
 #define FUNC_NAME "scm_new_port_table_entry"
 {
+  SCM z = scm_cell (SCM_EOL, SCM_EOL);
   scm_t_port *entry = (scm_t_port *) scm_gc_calloc (sizeof (scm_t_port), "port");
   if (scm_port_table_size == scm_port_table_room)
     {
@@ -468,17 +469,19 @@ scm_new_port_table_entry (void)
       scm_port_table_room *= 2;
     }
 
-  entry->port = SCM_EOL;
   entry->entry = scm_port_table_size;
 
   entry->file_name = SCM_BOOL_F;
   entry->rw_active = SCM_PORT_NEITHER;
 
-
   scm_port_table[scm_port_table_size] = entry;
   scm_port_table_size++;
 
-  return entry;
+  entry->port = z;
+  SCM_SET_CELL_TYPE(z, tag);
+  SCM_SETPTAB_ENTRY(z, entry);
+  
+  return z;
 }
 #undef FUNC_NAME
 
@@ -1521,13 +1524,10 @@ scm_void_port (char *mode_str)
   SCM_DEFER_INTS;
   {
     int mode_bits = scm_mode_bits (mode_str);
-    scm_t_port * pt = scm_new_port_table_entry ();
-    SCM answer;
-    
+    SCM answer = scm_new_port_table_entry (scm_tc16_void_port);
+    scm_t_port * pt = SCM_PTAB_ENTRY(answer);
+
     scm_port_non_buffer (pt);
-    answer = scm_cell (scm_tc16_void_port, 0);
-    SCM_SETPTAB_ENTRY (answer, pt);
-    pt->port = answer;
   
     SCM_SETSTREAM (answer, 0);
     SCM_SET_CELL_TYPE (answer, scm_tc16_void_port | mode_bits);
index 3e7a0df..c85ecfd 100644 (file)
@@ -257,7 +257,7 @@ SCM_API SCM scm_current_load_port (void);
 SCM_API SCM scm_set_current_input_port (SCM port);
 SCM_API SCM scm_set_current_output_port (SCM port);
 SCM_API SCM scm_set_current_error_port (SCM port);
-SCM_API scm_t_port * scm_new_port_table_entry (void);
+SCM_API SCM scm_new_port_table_entry (scm_t_bits tag);
 SCM_API void scm_remove_from_port_table (SCM port);
 SCM_API void scm_grow_port_cbuf (SCM port, size_t requested);
 SCM_API SCM scm_pt_size (void);
index 94aa928..5af68bb 100644 (file)
@@ -281,14 +281,10 @@ scm_mkstrport (SCM pos, SCM str, long modes, const char *caller)
     scm_misc_error ("scm_mkstrport", "port must read or write", SCM_EOL);
 
   SCM_DEFER_INTS;
-  pt = scm_new_port_table_entry ();
-  z = scm_cell (scm_tc16_strport | modes,  0);
-
-  SCM_SETPTAB_ENTRY (z, pt);
-  pt->port = z;
-
-  
+  z = scm_new_port_table_entry (scm_tc16_strport);
+  pt = SCM_PTAB_ENTRY(z);
   SCM_SETSTREAM (z, SCM_UNPACK (str));
+  SCM_SET_CELL_TYPE(z, scm_tc16_strport|modes);
   pt->write_buf = pt->read_buf = SCM_STRING_UCHARS (str);
   pt->read_pos = pt->write_pos = pt->read_buf + SCM_INUM (pos);
   pt->write_buf_size = pt->read_buf_size = str_len;
index 6addd2b..977a69e 100644 (file)
@@ -191,12 +191,10 @@ SCM_DEFINE (scm_make_soft_port, "make-soft-port", 2, 0, 0,
   SCM_VALIDATE_STRING (2, modes);
   
   SCM_DEFER_INTS;
-  pt = scm_new_port_table_entry ();
+  z = scm_new_port_table_entry (scm_tc16_sfport);
   scm_port_non_buffer (pt);
-  z = scm_cell (scm_tc16_sfport | scm_mode_bits (SCM_STRING_CHARS (modes)), 0);
-  SCM_SETPTAB_ENTRY (z, pt);
-  pt->port = z;
-  
+  SCM_SET_CELL_TYPE (z, scm_tc16_sfport | scm_mode_bits (SCM_STRING_CHARS (modes)));
+
   SCM_SETSTREAM (z, SCM_UNPACK (pv));
   SCM_ALLOW_INTS;
   return z;