GOOPS: Statically allocate the SMOB class array.
authorLudovic Courtès <ludo@gnu.org>
Sun, 18 Jan 2009 15:53:01 +0000 (16:53 +0100)
committerLudovic Courtès <ludo@gnu.org>
Mon, 2 Feb 2009 23:02:50 +0000 (00:02 +0100)
* libguile/goops.c (scm_smob_class): Statically allocate it.
  (create_smob_classes): Don't malloc(3) `scm_smob_class'.

* libguile/goops.h (scm_smob_class): Update declaration.

* libguile/smob.c (scm_make_smob_type, scm_set_smob_apply): When
  checking whether GOOPS is initialized, check whether the first element
  of SCM_SMOB_CLASS is non-zero.

libguile/goops.c
libguile/goops.h
libguile/smob.c

index 84bfc02..1794441 100644 (file)
@@ -153,7 +153,7 @@ SCM scm_class_scm;
 SCM scm_class_int, scm_class_float, scm_class_double;
 
 SCM *scm_port_class = 0;
-SCM *scm_smob_class = 0;
+SCM scm_smob_class[SCM_I_MAX_SMOB_TYPE_COUNT];
 
 SCM scm_no_applicable_method;
 
@@ -2694,7 +2694,6 @@ create_smob_classes (void)
 {
   long i;
 
-  scm_smob_class = scm_malloc (SCM_I_MAX_SMOB_TYPE_COUNT * sizeof (SCM));
   for (i = 0; i < SCM_I_MAX_SMOB_TYPE_COUNT; ++i)
     scm_smob_class[i] = 0;
 
index 6b88ae2..545dac3 100644 (file)
@@ -3,7 +3,7 @@
 #ifndef SCM_GOOPS_H
 #define SCM_GOOPS_H
 
-/* Copyright (C) 1998,1999,2000,2001,2002,2003, 2006, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 1998,1999,2000,2001,2002,2003, 2006, 2008, 2009 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
@@ -169,7 +169,7 @@ SCM_API SCM scm_class_integer;
 SCM_API SCM scm_class_fraction;
 SCM_API SCM scm_class_unknown;
 SCM_API SCM *scm_port_class;
-SCM_API SCM *scm_smob_class;
+SCM_API SCM scm_smob_class[];
 SCM_API SCM scm_class_top;
 SCM_API SCM scm_class_object;
 SCM_API SCM scm_class_class;
index 2e781ed..8991979 100644 (file)
@@ -309,7 +309,7 @@ scm_make_smob_type (char const *name, size_t size)
     }
 
   /* Make a class object if Goops is present. */
-  if (scm_smob_class)
+  if (SCM_UNPACK (scm_smob_class[0]) != 0)
     scm_smob_class[new_smob] = scm_make_extended_class (name, 0);
 
   return scm_tc7_smob + new_smob * 256;
@@ -449,8 +449,8 @@ scm_set_smob_apply (scm_t_bits tc, SCM (*apply) (),
   scm_smobs[SCM_TC2SMOBNUM (tc)].apply_2 = apply_2;
   scm_smobs[SCM_TC2SMOBNUM (tc)].apply_3 = apply_3;
   scm_smobs[SCM_TC2SMOBNUM (tc)].gsubr_type = type;
-  
-  if (scm_smob_class)
+
+  if (SCM_UNPACK (scm_smob_class[0]) != 0)
     scm_i_inherit_applicable (scm_smob_class[SCM_TC2SMOBNUM (tc)]);
 }