diff src/lstream.c @ 5178:97eb4942aec8

merge
author Ben Wing <ben@xemacs.org>
date Mon, 29 Mar 2010 21:28:13 -0500
parents 1fae11d56ad2
children 308d34e9f07d
line wrap: on
line diff
--- a/src/lstream.c	Tue Feb 23 07:28:35 2010 -0600
+++ b/src/lstream.c	Mon Mar 29 21:28:13 2010 -0500
@@ -1,7 +1,7 @@
 /* Generic stream implementation.
    Copyright (C) 1995 Free Software Foundation, Inc.
    Copyright (C) 1995 Sun Microsystems, Inc.
-   Copyright (C) 1996, 2001, 2002 Ben Wing.
+   Copyright (C) 1996, 2001, 2002, 2010 Ben Wing.
 
 This file is part of XEmacs.
 
@@ -64,42 +64,36 @@
   Lstream *lstr = XLSTREAM (obj);
 
   write_fmt_string (printcharfun,
-		    "#<INTERNAL OBJECT (XEmacs bug?) (%s lstream) 0x%lx>",
-		    lstr->imp->name, (long) lstr);
+		    "#<INTERNAL OBJECT (XEmacs bug?) (%s lstream) 0x%x>",
+		    lstr->imp->name, LISP_OBJECT_UID (obj));
 }
 
 static void
-finalize_lstream (void *header, int for_disksave)
+finalize_lstream (Lisp_Object obj)
 {
   /* WARNING WARNING WARNING.  This function (and all finalize functions)
-     may get called more than once on the same object, and may get called
-     (at dump time) on objects that are not being released. */
-  Lstream *lstr = (Lstream *) header;
+     may get called more than once on the same object. */
+  Lstream *lstr = XLSTREAM (obj);
+
+  if (lstr->flags & LSTREAM_FL_IS_OPEN)
+    Lstream_close (lstr);
+
+  if (lstr->imp->finalizer)
+    (lstr->imp->finalizer) (lstr);
+}
+
+static void
+disksave_lstream (Lisp_Object lstream)
+{
+  Lstream *lstr = XLSTREAM (lstream);
 
 #if 0 /* this may cause weird Broken Pipes? */
-  if (for_disksave)
-    {
-      Lstream_pseudo_close (lstr);
-      return;
-    }
+  Lstream_pseudo_close (lstr);
+  return;
 #endif
-  if (lstr->flags & LSTREAM_FL_IS_OPEN)
-    {
-      if (for_disksave)
-	{
-	  if (lstr->flags & LSTREAM_FL_CLOSE_AT_DISKSAVE)
-	    Lstream_close (lstr);
-	}
-      else
-	/* Just close. */
-	Lstream_close (lstr);
-    }
-
-  if (!for_disksave)
-    {
-      if (lstr->imp->finalizer)
-	(lstr->imp->finalizer) (lstr);
-    }
+  if ((lstr->flags & LSTREAM_FL_IS_OPEN) &&
+      (lstr->flags & LSTREAM_FL_CLOSE_AT_DISKSAVE))
+    Lstream_close (lstr);
 }
 
 inline static Bytecount
@@ -110,9 +104,9 @@
 }
 
 static Bytecount
-sizeof_lstream (const void *header)
+sizeof_lstream (Lisp_Object obj)
 {
-  return aligned_sizeof_lstream (((const Lstream *) header)->imp->size);
+  return aligned_sizeof_lstream (XLSTREAM (obj)->imp->size);
 }
 
 static const struct memory_description lstream_implementation_description_1[]
@@ -150,12 +144,12 @@
   0, lstream_empty_extra_description_1
 };
 
-DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION ("stream", lstream,
-					0, /*dumpable-flag*/
-					mark_lstream, print_lstream,
-					finalize_lstream, 0, 0,
-					lstream_description,
-					sizeof_lstream, Lstream);
+DEFINE_NODUMP_SIZABLE_LISP_OBJECT ("stream", lstream,
+				   mark_lstream, print_lstream,
+				   finalize_lstream,
+				   0, 0, /* no equal or hash */
+				   lstream_description,
+				   sizeof_lstream, Lstream);
 
 
 /* Change the buffering of a stream.  See lstream.h.  By default the
@@ -197,9 +191,8 @@
 {
   Lstream *p;
 #ifdef NEW_GC
-  p = XLSTREAM (wrap_pointer_1 
-		(alloc_lrecord (aligned_sizeof_lstream (imp->size),
-				&lrecord_lstream)));
+  p = XLSTREAM (ALLOC_SIZED_LISP_OBJECT (aligned_sizeof_lstream (imp->size),
+					 lstream));
 #else /* not NEW_GC */
   int i;
 
@@ -221,9 +214,10 @@
 
   p = XLSTREAM (alloc_managed_lcrecord (Vlstream_free_list[i]));
 #endif /* not NEW_GC */
-  /* Zero it out, except the header. */
-  memset ((char *) p + sizeof (p->header), '\0',
-	  aligned_sizeof_lstream (imp->size) - sizeof (p->header));
+  /* Formerly, we zeroed out the object minus its header, but it's now
+     handled automatically.  ALLOC_SIZED_LISP_OBJECT() always zeroes out
+     the whole object other than its header, and alloc_managed_lcrecord()
+     does the same. */
   p->imp = imp;
   Lstream_set_buffering (p, LSTREAM_BLOCK_BUFFERED, 0);
   p->flags = LSTREAM_FL_IS_OPEN;
@@ -302,7 +296,7 @@
   Lisp_Object val = wrap_lstream (lstr);
 
 #ifdef NEW_GC
-  free_lrecord (val);
+  free_normal_lisp_object (val);
 #else /* not NEW_GC */
   for (i = 0; i < lstream_type_count; i++)
     {
@@ -1826,6 +1820,18 @@
 /************************************************************************/
 
 void
+syms_of_lstream (void)
+{
+  INIT_LISP_OBJECT (lstream);
+}
+
+void
+lstream_objects_create (void)
+{
+  OBJECT_HAS_PREMETHOD (lstream, disksave);
+}
+
+void
 lstream_type_create (void)
 {
   LSTREAM_HAS_METHOD (stdio, reader);
@@ -1881,5 +1887,4 @@
 void
 vars_of_lstream (void)
 {
-  INIT_LRECORD_IMPLEMENTATION (lstream);
 }