changeset 4802:2fc0e2f18322

Don't create any bignums before pdumping. Add bignum, ratio, and bigfloat finalizers so we don't leak memory with NEW_GC. See xemacs-patches message with ID <870180fe1001060900o46fa2b7o26b58850fadf9aba@mail.gmail.com>.
author Jerry James <james@xemacs.org>
date Wed, 06 Jan 2010 10:01:14 -0700
parents 591091481f20
children 5d120deb60ca
files src/ChangeLog src/emacs.c src/number-gmp.c src/number-gmp.h src/number-mp.c src/number-mp.h src/number.c src/number.h src/symsinit.h
diffstat 9 files changed, 104 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Wed Jan 06 13:56:38 2010 +0100
+++ b/src/ChangeLog	Wed Jan 06 10:01:14 2010 -0700
@@ -1,3 +1,21 @@
+2010-01-06  Jerry James  <james@xemacs.org>
+
+	* emacs.c: Fix FSF address.
+	(main_1): Call reinit_vars_of_number.
+	* number-gmp.c: Fix FSF address.
+	* number-gmp.h: Ditto.
+	* number-mp.c: Ditto.
+	* number-mp.h: Ditto.
+	* number.h: Ditto.
+	* number.c: Ditto.
+	(bignum_finalize): New function.
+	(ratio_finalize): New function.
+	(bigfloat_finalize): New function.
+	(vars_of_number): Don't create a bignum here.
+	(reinit_vars_of_number): New function; create a bignum here.
+	(init_number): Call reinit_vars_of_number if !PDUMP.
+	* symsinit.h: Fix FSF address.  Declare reinit_vars_of_number.
+
 2010-01-05  Jerry James  <james@xemacs.org>
 
 	* font-mgr.c (Ffc_name_unparse): Return value of FcNameUnparse
--- a/src/emacs.c	Wed Jan 06 13:56:38 2010 +0100
+++ b/src/emacs.c	Wed Jan 06 10:01:14 2010 -0700
@@ -18,8 +18,8 @@
 
 You should have received a copy of the GNU General Public License
 along with XEmacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin St - Fifth Floor,
+Boston, MA 02111-1301, USA.  */
 
 /* Synched up with: Mule 2.0, FSF 19.28. */
 
@@ -1895,6 +1895,7 @@
       reinit_opaque_early ();
 #endif /* not NEW_GC */
       reinit_eistring_early ();
+      reinit_vars_of_number ();
 
       reinit_console_type_create_stream ();
 #ifdef HAVE_TTY
--- a/src/number-gmp.c	Wed Jan 06 13:56:38 2010 +0100
+++ b/src/number-gmp.c	Wed Jan 06 10:01:14 2010 -0700
@@ -15,8 +15,8 @@
 
 You should have received a copy of the GNU General Public License
 along with XEmacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin St - Fifth Floor,
+Boston, MA 02111-1301, USA.  */
 
 /* Synched up with: Not in FSF. */
 
--- a/src/number-gmp.h	Wed Jan 06 13:56:38 2010 +0100
+++ b/src/number-gmp.h	Wed Jan 06 10:01:14 2010 -0700
@@ -15,8 +15,8 @@
 
 You should have received a copy of the GNU General Public License
 along with XEmacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin St - Fifth Floor,
+Boston, MA 02111-1301, USA.  */
 
 /* Synched up with: Not in FSF. */
 
--- a/src/number-mp.c	Wed Jan 06 13:56:38 2010 +0100
+++ b/src/number-mp.c	Wed Jan 06 10:01:14 2010 -0700
@@ -15,8 +15,8 @@
 
 You should have received a copy of the GNU General Public License
 along with XEmacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin St - Fifth Floor,
+Boston, MA 02111-1301, USA.  */
 
 /* Synched up with: Not in FSF. */
 
@@ -221,7 +221,7 @@
 
   mbase = MP_ITOM ((short) base);
   MP_MOVE (bignum_zero, b);
-  
+
   for (digit = char_to_number (*s); digit >= 0 && digit < base;
        digit = char_to_number (*++s))
     {
--- a/src/number-mp.h	Wed Jan 06 13:56:38 2010 +0100
+++ b/src/number-mp.h	Wed Jan 06 10:01:14 2010 -0700
@@ -15,8 +15,8 @@
 
 You should have received a copy of the GNU General Public License
 along with XEmacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin St - Fifth Floor,
+Boston, MA 02111-1301, USA.  */
 
 /* Synched up with: Not in FSF. */
 
--- a/src/number.c	Wed Jan 06 13:56:38 2010 +0100
+++ b/src/number.c	Wed Jan 06 10:01:14 2010 -0700
@@ -15,8 +15,8 @@
 
 You should have received a copy of the GNU General Public License
 along with XEmacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin St - Fifth Floor,
+Boston, MA 02111-1301, USA.  */
 
 /* Synched up with: Not in FSF. */
 
@@ -58,6 +58,21 @@
   xfree (bstr, CIbyte *);
 }
 
+#ifdef NEW_GC
+static void
+bignum_finalize (void *header, int for_disksave)
+{
+  if (!for_disksave)
+    {
+      struct Lisp_Bignum *num = (struct Lisp_Bignum *) header;
+      bignum_fini (num->data);
+    }
+}
+#define BIGNUM_FINALIZE bignum_finalize
+#else
+#define BIGNUM_FINALIZE 0
+#endif
+
 static int
 bignum_equal (Lisp_Object obj1, Lisp_Object obj2, int UNUSED (depth))
 {
@@ -107,8 +122,9 @@
 };
 
 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("bignum", bignum, 1, 0, bignum_print,
-				     0, bignum_equal, bignum_hash,
-				     bignum_description, Lisp_Bignum);
+				     BIGNUM_FINALIZE, bignum_equal,
+				     bignum_hash, bignum_description,
+				     Lisp_Bignum);
 
 #endif /* HAVE_BIGNUM */
 
@@ -166,6 +182,21 @@
   xfree (rstr, CIbyte *);
 }
 
+#ifdef NEW_GC
+static void
+ratio_finalize (void *header, int for_disksave)
+{
+  if (!for_disksave)
+    {
+      struct Lisp_Ratio *num = (struct Lisp_Ratio *) header;
+      ratio_fini (num->data);
+    }
+}
+#define RATIO_FINALIZE ratio_finalize
+#else
+#define RATIO_FINALIZE 0
+#endif
+
 static int
 ratio_equal (Lisp_Object obj1, Lisp_Object obj2, int UNUSED (depth))
 {
@@ -184,7 +215,7 @@
 };
 
 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("ratio", ratio, 0, 0, ratio_print,
-				     0, ratio_equal, ratio_hash,
+				     RATIO_FINALIZE, ratio_equal, ratio_hash,
 				     ratio_description, Lisp_Ratio);
 
 #endif /* HAVE_RATIO */
@@ -253,6 +284,21 @@
   xfree (fstr, CIbyte *);
 }
 
+#ifdef NEW_GC
+static void
+bigfloat_finalize (void *header, int for_disksave)
+{
+  if (!for_disksave)
+    {
+      struct Lisp_Bigfloat *num = (struct Lisp_Bigfloat *) header;
+      bigfloat_fini (num->bf);
+    }
+}
+#define BIGFLOAT_FINALIZE bigfloat_finalize
+#else
+#define BIGFLOAT_FINALIZE 0
+#endif
+
 static int
 bigfloat_equal (Lisp_Object obj1, Lisp_Object obj2, int UNUSED (depth))
 {
@@ -271,7 +317,7 @@
 };
 
 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("bigfloat", bigfloat, 1, 0,
-				     bigfloat_print, 0,
+				     bigfloat_print, BIGFLOAT_FINALIZE,
 				     bigfloat_equal, bigfloat_hash,
 				     bigfloat_description, Lisp_Bigfloat);
 
@@ -345,7 +391,7 @@
 #ifdef HAVE_BIGFLOAT
   if (INTP (*val))
     prec = XINT (*val);
-  else 
+  else
     {
       if (!bignum_fits_ulong_p (XBIGNUM_DATA (*val)))
 	args_out_of_range_3 (*val, Qzero, Vbigfloat_max_prec);
@@ -655,7 +701,7 @@
 				      0UL);
       return type2;
     }
-  
+
   if (type2 < type1)
     {
       *arg2 = internal_coerce_number (*arg2, type1,
@@ -800,12 +846,9 @@
 */);
 
 #ifdef HAVE_BIGFLOAT
-#ifdef HAVE_BIGNUM
-  Vbigfloat_max_prec = make_bignum (0L);
-  bignum_set_ulong (XBIGNUM_DATA (Vbigfloat_max_prec), ULONG_MAX);
-#else
+  /* Don't create a bignum here.  Otherwise, we lose with NEW_GC + pdump.
+     See reinit_vars_of_number(). */
   Vbigfloat_max_prec = make_int (EMACS_INT_MAX);
-#endif
 #else
   Vbigfloat_max_prec = make_int (0);
 #endif /* HAVE_BIGFLOAT */
@@ -833,6 +876,15 @@
 }
 
 void
+reinit_vars_of_number (void)
+{
+#if defined(HAVE_BIGFLOAT) && defined(HAVE_BIGNUM)
+  Vbigfloat_max_prec = make_bignum (0L);
+  bignum_set_ulong (XBIGNUM_DATA (Vbigfloat_max_prec), ULONG_MAX);
+#endif
+}
+
+void
 init_number (void)
 {
   if (!number_initialized)
@@ -860,5 +912,9 @@
       bigfloat_init (scratch_bigfloat);
       bigfloat_init (scratch_bigfloat2);
 #endif
+
+#ifndef PDUMP
+      reinit_vars_of_number ();
+#endif
     }
 }
--- a/src/number.h	Wed Jan 06 13:56:38 2010 +0100
+++ b/src/number.h	Wed Jan 06 10:01:14 2010 -0700
@@ -15,8 +15,8 @@
 
 You should have received a copy of the GNU General Public License
 along with XEmacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin St - Fifth Floor,
+Boston, MA 02111-1301, USA.  */
 
 /* Synched up with: Not in FSF. */
 
--- a/src/symsinit.h	Wed Jan 06 13:56:38 2010 +0100
+++ b/src/symsinit.h	Wed Jan 06 10:01:14 2010 -0700
@@ -16,8 +16,8 @@
 
 You should have received a copy of the GNU General Public License
 along with XEmacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin St - Fifth Floor,
+Boston, MA 02111-1301, USA.  */
 
 /* Synched up with: Not in FSF. */
 
@@ -398,6 +398,7 @@
 void reinit_vars_of_mule_wnn (void);
 void vars_of_nt (void);
 void vars_of_number (void);
+void reinit_vars_of_number (void);
 void vars_of_objects (void);
 void vars_of_font_mgr (void);
 void reinit_vars_of_font_mgr (void);