Mercurial > hg > xemacs-beta
diff src/lstream.c @ 5133:444a448b2f53
Merge branch ben-lisp-object into default branch
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Sun, 07 Mar 2010 06:47:37 -0600 |
parents | a9c41067dd88 |
children | 88bd4f3ef8e4 |
line wrap: on
line diff
--- a/src/lstream.c Sun Mar 07 06:43:19 2010 -0600 +++ b/src/lstream.c Sun Mar 07 06:47:37 2010 -0600 @@ -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. @@ -69,37 +69,31 @@ } 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,14 @@ 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_GENERAL_LISP_OBJECT ("stream", lstream, + mark_lstream, print_lstream, + finalize_lstream, + 0, 0, /* no equal or hash */ + lstream_description, + 0, 0, 0, 0, /* no property meths */ + disksave_lstream, + sizeof_lstream, Lstream); /* Change the buffering of a stream. See lstream.h. By default the @@ -197,9 +193,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 +216,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 +298,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++) { @@ -1881,5 +1877,5 @@ void vars_of_lstream (void) { - INIT_LRECORD_IMPLEMENTATION (lstream); + INIT_LISP_OBJECT (lstream); }