XEmacs 21.2.30 "Hygeia".
[chise/xemacs-chise.git.1] / src / objects.c
index 4161718..e91dbed 100644 (file)
@@ -57,12 +57,12 @@ finalose (void *ptr)
 Lisp_Object Qcolor_instancep;
 
 static Lisp_Object
-mark_color_instance (Lisp_Object obj, void (*markobj) (Lisp_Object))
+mark_color_instance (Lisp_Object obj)
 {
-  struct Lisp_Color_Instance *c = XCOLOR_INSTANCE (obj);
-  ((markobj) (c->name));
+  Lisp_Color_Instance *c = XCOLOR_INSTANCE (obj);
+  mark_object (c->name);
   if (!NILP (c->device)) /* Vthe_null_color_instance */
-    MAYBE_DEVMETH (XDEVICE (c->device), mark_color_instance, (c, markobj));
+    MAYBE_DEVMETH (XDEVICE (c->device), mark_color_instance, (c));
 
   return c->device;
 }
@@ -72,7 +72,7 @@ print_color_instance (Lisp_Object obj, Lisp_Object printcharfun,
                      int escapeflag)
 {
   char buf[100];
-  struct Lisp_Color_Instance *c = XCOLOR_INSTANCE (obj);
+  Lisp_Color_Instance *c = XCOLOR_INSTANCE (obj);
   if (print_readably)
     error ("printing unreadable object #<color-instance 0x%x>",
            c->header.uid);
@@ -90,7 +90,7 @@ print_color_instance (Lisp_Object obj, Lisp_Object printcharfun,
 static void
 finalize_color_instance (void *header, int for_disksave)
 {
-  struct Lisp_Color_Instance *c = (struct Lisp_Color_Instance *) header;
+  Lisp_Color_Instance *c = (Lisp_Color_Instance *) header;
 
   if (!NILP (c->device))
     {
@@ -100,24 +100,22 @@ finalize_color_instance (void *header, int for_disksave)
 }
 
 static int
-color_instance_equal (Lisp_Object o1, Lisp_Object o2, int depth)
+color_instance_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
 {
-  struct Lisp_Color_Instance *c1 = XCOLOR_INSTANCE (o1);
-  struct Lisp_Color_Instance *c2 = XCOLOR_INSTANCE (o2);
-  struct device *d1 = DEVICEP (c1->device) ? XDEVICE (c1->device) : 0;
-  struct device *d2 = DEVICEP (c2->device) ? XDEVICE (c2->device) : 0;
-
-  if (d1 != d2)
-    return 0;
-  if (!d1 || !HAS_DEVMETH_P (d1, color_instance_equal))
-    return EQ (o1, o2);
-  return DEVMETH (d1, color_instance_equal, (c1, c2, depth));
+  Lisp_Color_Instance *c1 = XCOLOR_INSTANCE (obj1);
+  Lisp_Color_Instance *c2 = XCOLOR_INSTANCE (obj2);
+
+  return (c1 == c2) ||
+    (EQ (c1->device, c2->device) &&
+     DEVICEP (c1->device) &&
+     HAS_DEVMETH_P (XDEVICE (c1->device), color_instance_equal) &&
+     DEVMETH (XDEVICE (c1->device), color_instance_equal, (c1, c2, depth)));
 }
 
 static unsigned long
 color_instance_hash (Lisp_Object obj, int depth)
 {
-  struct Lisp_Color_Instance *c = XCOLOR_INSTANCE (obj);
+  Lisp_Color_Instance *c = XCOLOR_INSTANCE (obj);
   struct device *d = DEVICEP (c->device) ? XDEVICE (c->device) : 0;
 
   return HASH2 ((unsigned long) d,
@@ -129,8 +127,8 @@ color_instance_hash (Lisp_Object obj, int depth)
 DEFINE_LRECORD_IMPLEMENTATION ("color-instance", color_instance,
                               mark_color_instance, print_color_instance,
                               finalize_color_instance, color_instance_equal,
-                              color_instance_hash,
-                              struct Lisp_Color_Instance);
+                              color_instance_hash, 0,
+                              Lisp_Color_Instance);
 \f
 DEFUN ("make-color-instance", Fmake_color_instance, 1, 3, 0, /*
 Return a new `color-instance' object named NAME (a string).
@@ -151,14 +149,14 @@ is deallocated as well.
 */
        (name, device, no_error))
 {
-  struct Lisp_Color_Instance *c;
+  Lisp_Color_Instance *c;
   Lisp_Object val;
   int retval;
 
   CHECK_STRING (name);
   XSETDEVICE (device, decode_device (device));
 
-  c = alloc_lcrecord_type (struct Lisp_Color_Instance, lrecord_color_instance);
+  c = alloc_lcrecord_type (Lisp_Color_Instance, &lrecord_color_instance);
   c->name = name;
   c->device = device;
   c->data = 0;
@@ -197,7 +195,7 @@ Component values range from 0 to 65535.
 */
        (color_instance))
 {
-  struct Lisp_Color_Instance *c;
+  Lisp_Color_Instance *c;
 
   CHECK_COLOR_INSTANCE (color_instance);
   c = XCOLOR_INSTANCE (color_instance);
@@ -239,13 +237,13 @@ static Lisp_Object font_instance_truename_internal (Lisp_Object xfont,
                                                    Error_behavior errb);
 
 static Lisp_Object
-mark_font_instance (Lisp_Object obj, void (*markobj) (Lisp_Object))
+mark_font_instance (Lisp_Object obj)
 {
-  struct Lisp_Font_Instance *f = XFONT_INSTANCE (obj);
+  Lisp_Font_Instance *f = XFONT_INSTANCE (obj);
 
-  ((markobj) (f->name));
+  mark_object (f->name);
   if (!NILP (f->device)) /* Vthe_null_font_instance */
-    MAYBE_DEVMETH (XDEVICE (f->device), mark_font_instance, (f, markobj));
+    MAYBE_DEVMETH (XDEVICE (f->device), mark_font_instance, (f));
 
   return f->device;
 }
@@ -254,15 +252,16 @@ static void
 print_font_instance (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
 {
   char buf[200];
-  struct Lisp_Font_Instance *f = XFONT_INSTANCE (obj);
+  Lisp_Font_Instance *f = XFONT_INSTANCE (obj);
   if (print_readably)
     error ("printing unreadable object #<font-instance 0x%x>", f->header.uid);
   write_c_string ("#<font-instance ", printcharfun);
   print_internal (f->name, printcharfun, 1);
   write_c_string (" on ", printcharfun);
   print_internal (f->device, printcharfun, 0);
-  MAYBE_DEVMETH (XDEVICE (f->device), print_font_instance,
-                (f, printcharfun, escapeflag));
+  if (!NILP (f->device))
+    MAYBE_DEVMETH (XDEVICE (f->device), print_font_instance,
+                  (f, printcharfun, escapeflag));
   sprintf (buf, " 0x%x>", f->header.uid);
   write_c_string (buf, printcharfun);
 }
@@ -270,7 +269,7 @@ print_font_instance (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
 static void
 finalize_font_instance (void *header, int for_disksave)
 {
-  struct Lisp_Font_Instance *f = (struct Lisp_Font_Instance *) header;
+  Lisp_Font_Instance *f = (Lisp_Font_Instance *) header;
 
   if (!NILP (f->device))
     {
@@ -284,11 +283,11 @@ finalize_font_instance (void *header, int for_disksave)
    this means the `equal' could cause XListFonts to be run the first time.
  */
 static int
-font_instance_equal (Lisp_Object o1, Lisp_Object o2, int depth)
+font_instance_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
 {
   /* #### should this be moved into a device method? */
-  return internal_equal (font_instance_truename_internal (o1, ERROR_ME_NOT),
-                        font_instance_truename_internal (o2, ERROR_ME_NOT),
+  return internal_equal (font_instance_truename_internal (obj1, ERROR_ME_NOT),
+                        font_instance_truename_internal (obj2, ERROR_ME_NOT),
                         depth + 1);
 }
 
@@ -302,7 +301,7 @@ font_instance_hash (Lisp_Object obj, int depth)
 DEFINE_LRECORD_IMPLEMENTATION ("font-instance", font_instance,
                               mark_font_instance, print_font_instance,
                               finalize_font_instance, font_instance_equal,
-                              font_instance_hash, struct Lisp_Font_Instance);
+                              font_instance_hash, 0, Lisp_Font_Instance);
 \f
 DEFUN ("make-font-instance", Fmake_font_instance, 1, 3, 0, /*
 Return a new `font-instance' object named NAME.
@@ -318,7 +317,7 @@ these objects are GCed, the underlying X data is deallocated as well.
 */
        (name, device, no_error))
 {
-  struct Lisp_Font_Instance *f;
+  Lisp_Font_Instance *f;
   Lisp_Object val;
   int retval = 0;
   Error_behavior errb = decode_error_behavior_flag (no_error);
@@ -330,7 +329,7 @@ these objects are GCed, the underlying X data is deallocated as well.
 
   XSETDEVICE (device, decode_device (device));
 
-  f = alloc_lcrecord_type (struct Lisp_Font_Instance, lrecord_font_instance);
+  f = alloc_lcrecord_type (Lisp_Font_Instance, &lrecord_font_instance);
   f->name = name;
   f->device = device;
 
@@ -418,9 +417,17 @@ static Lisp_Object
 font_instance_truename_internal (Lisp_Object font_instance,
                                 Error_behavior errb)
 {
-  struct Lisp_Font_Instance *f = XFONT_INSTANCE (font_instance);
-  struct device *d = XDEVICE (f->device);
-  return DEVMETH_OR_GIVEN (d, font_instance_truename, (f, errb), f->name);
+  Lisp_Font_Instance *f = XFONT_INSTANCE (font_instance);
+
+  if (NILP (f->device))
+    {
+      maybe_signal_simple_error ("Couldn't determine font truename",
+                                font_instance, Qfont, errb);
+      return Qnil;
+    }
+
+  return DEVMETH_OR_GIVEN (XDEVICE (f->device),
+                          font_instance_truename, (f, errb), f->name);
 }
 
 DEFUN ("font-instance-truename", Ffont_instance_truename, 1, 1, 0, /*
@@ -440,11 +447,14 @@ Return the properties (an alist or nil) of FONT-INSTANCE.
 */
        (font_instance))
 {
-  struct Lisp_Font_Instance *f;
+  Lisp_Font_Instance *f;
 
   CHECK_FONT_INSTANCE (font_instance);
   f = XFONT_INSTANCE (font_instance);
 
+  if (NILP (f->device))
+    return Qnil;
+
   return MAYBE_LISP_DEVMETH (XDEVICE (f->device),
                             font_instance_properties, (f));
 }
@@ -472,19 +482,19 @@ DEFINE_SPECIFIER_TYPE (color);
 static void
 color_create (Lisp_Object obj)
 {
-  struct Lisp_Specifier *color = XCOLOR_SPECIFIER (obj);
+  Lisp_Specifier *color = XCOLOR_SPECIFIER (obj);
 
   COLOR_SPECIFIER_FACE (color) = Qnil;
   COLOR_SPECIFIER_FACE_PROPERTY (color) = Qnil;
 }
 
 static void
-color_mark (Lisp_Object obj, void (*markobj) (Lisp_Object))
+color_mark (Lisp_Object obj)
 {
-  struct Lisp_Specifier *color = XCOLOR_SPECIFIER (obj);
+  Lisp_Specifier *color = XCOLOR_SPECIFIER (obj);
 
-  ((markobj) (COLOR_SPECIFIER_FACE (color)));
-  ((markobj) (COLOR_SPECIFIER_FACE_PROPERTY (color)));
+  mark_object (COLOR_SPECIFIER_FACE (color));
+  mark_object (COLOR_SPECIFIER_FACE_PROPERTY (color));
 }
 
 /* No equal or hash methods; ignore the face the color is based off
@@ -499,7 +509,6 @@ color_instantiate (Lisp_Object specifier, Lisp_Object matchspec,
      so we can freely error. */
   Lisp_Object device = DFW_DEVICE (domain);
   struct device *d = XDEVICE (device);
-  Lisp_Object instance;
 
   if (COLOR_INSTANCEP (instantiator))
     {
@@ -516,7 +525,8 @@ color_instantiate (Lisp_Object specifier, Lisp_Object matchspec,
   if (STRINGP (instantiator))
     {
       /* First, look to see if we can retrieve a cached value. */
-      instance = Fgethash (instantiator, d->color_instance_cache, Qunbound);
+      Lisp_Object instance =
+       Fgethash (instantiator, d->color_instance_cache, Qunbound);
       /* Otherwise, make a new one. */
       if (UNBOUNDP (instance))
        {
@@ -612,7 +622,7 @@ color_after_change (Lisp_Object specifier, Lisp_Object locale)
 void
 set_color_attached_to (Lisp_Object obj, Lisp_Object face, Lisp_Object property)
 {
-  struct Lisp_Specifier *color = XCOLOR_SPECIFIER (obj);
+  Lisp_Specifier *color = XCOLOR_SPECIFIER (obj);
 
   COLOR_SPECIFIER_FACE (color) = face;
   COLOR_SPECIFIER_FACE_PROPERTY (color) = property;
@@ -650,19 +660,19 @@ DEFINE_SPECIFIER_TYPE (font);
 static void
 font_create (Lisp_Object obj)
 {
-  struct Lisp_Specifier *font = XFONT_SPECIFIER (obj);
+  Lisp_Specifier *font = XFONT_SPECIFIER (obj);
 
   FONT_SPECIFIER_FACE (font) = Qnil;
   FONT_SPECIFIER_FACE_PROPERTY (font) = Qnil;
 }
 
 static void
-font_mark (Lisp_Object obj, void (*markobj) (Lisp_Object))
+font_mark (Lisp_Object obj)
 {
-  struct Lisp_Specifier *font = XFONT_SPECIFIER (obj);
+  Lisp_Specifier *font = XFONT_SPECIFIER (obj);
 
-  ((markobj) (FONT_SPECIFIER_FACE (font)));
-  ((markobj) (FONT_SPECIFIER_FACE_PROPERTY (font)));
+  mark_object (FONT_SPECIFIER_FACE (font));
+  mark_object (FONT_SPECIFIER_FACE_PROPERTY (font));
 }
 
 /* No equal or hash methods; ignore the face the font is based off
@@ -672,7 +682,7 @@ font_mark (Lisp_Object obj, void (*markobj) (Lisp_Object))
 
 int
 font_spec_matches_charset (struct device *d, Lisp_Object charset,
-                          CONST Bufbyte *nonreloc, Lisp_Object reloc,
+                          const Bufbyte *nonreloc, Lisp_Object reloc,
                           Bytecount offset, Bytecount length)
 {
   return DEVMETH_OR_GIVEN (d, font_spec_matches_charset,
@@ -736,17 +746,17 @@ font_instantiate (Lisp_Object specifier, Lisp_Object matchspec,
             iterate over all possible fonts, and a regexp match
             on each one.  So we cache the results. */
          Lisp_Object matching_font = Qunbound;
-         Lisp_Object hashtab = Fgethash (matchspec, d->charset_font_cache,
+         Lisp_Object hash_table = Fgethash (matchspec, d->charset_font_cache,
                                          Qunbound);
-         if (UNBOUNDP (hashtab))
+         if (UNBOUNDP (hash_table))
            {
              /* need to make a sub hash table. */
-             hashtab = make_lisp_hashtable (20, HASHTABLE_KEY_WEAK,
-                                            HASHTABLE_EQUAL);
-             Fputhash (matchspec, hashtab, d->charset_font_cache);
+             hash_table = make_lisp_hash_table (20, HASH_TABLE_KEY_WEAK,
+                                                HASH_TABLE_EQUAL);
+             Fputhash (matchspec, hash_table, d->charset_font_cache);
            }
          else
-           matching_font = Fgethash (instantiator, hashtab, Qunbound);
+           matching_font = Fgethash (instantiator, hash_table, Qunbound);
 
          if (UNBOUNDP (matching_font))
            {
@@ -755,7 +765,7 @@ font_instantiate (Lisp_Object specifier, Lisp_Object matchspec,
                 DEVMETH_OR_GIVEN (d, find_charset_font,
                                   (device, instantiator, matchspec),
                                   instantiator);
-             Fputhash (instantiator, matching_font, hashtab);
+             Fputhash (instantiator, matching_font, hash_table);
            }
          if (NILP (matching_font))
            return Qunbound;
@@ -822,7 +832,7 @@ font_after_change (Lisp_Object specifier, Lisp_Object locale)
 void
 set_font_attached_to (Lisp_Object obj, Lisp_Object face, Lisp_Object property)
 {
-  struct Lisp_Specifier *font = XFONT_SPECIFIER (obj);
+  Lisp_Specifier *font = XFONT_SPECIFIER (obj);
 
   FONT_SPECIFIER_FACE (font) = face;
   FONT_SPECIFIER_FACE_PROPERTY (font) = property;
@@ -857,19 +867,19 @@ Lisp_Object Qface_boolean;
 static void
 face_boolean_create (Lisp_Object obj)
 {
-  struct Lisp_Specifier *face_boolean = XFACE_BOOLEAN_SPECIFIER (obj);
+  Lisp_Specifier *face_boolean = XFACE_BOOLEAN_SPECIFIER (obj);
 
   FACE_BOOLEAN_SPECIFIER_FACE (face_boolean) = Qnil;
   FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY (face_boolean) = Qnil;
 }
 
 static void
-face_boolean_mark (Lisp_Object obj, void (*markobj) (Lisp_Object))
+face_boolean_mark (Lisp_Object obj)
 {
-  struct Lisp_Specifier *face_boolean = XFACE_BOOLEAN_SPECIFIER (obj);
+  Lisp_Specifier *face_boolean = XFACE_BOOLEAN_SPECIFIER (obj);
 
-  ((markobj) (FACE_BOOLEAN_SPECIFIER_FACE (face_boolean)));
-  ((markobj) (FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY (face_boolean)));
+  mark_object (FACE_BOOLEAN_SPECIFIER_FACE (face_boolean));
+  mark_object (FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY (face_boolean));
 }
 
 /* No equal or hash methods; ignore the face the face-boolean is based off
@@ -967,7 +977,7 @@ void
 set_face_boolean_attached_to (Lisp_Object obj, Lisp_Object face,
                              Lisp_Object property)
 {
-  struct Lisp_Specifier *face_boolean = XFACE_BOOLEAN_SPECIFIER (obj);
+  Lisp_Specifier *face_boolean = XFACE_BOOLEAN_SPECIFIER (obj);
 
   FACE_BOOLEAN_SPECIFIER_FACE (face_boolean) = face;
   FACE_BOOLEAN_SPECIFIER_FACE_PROPERTY (face_boolean) = property;
@@ -999,6 +1009,9 @@ Valid instantiators for face-boolean specifiers are
 void
 syms_of_objects (void)
 {
+  INIT_LRECORD_IMPLEMENTATION (color_instance);
+  INIT_LRECORD_IMPLEMENTATION (font_instance);
+
   DEFSUBR (Fcolor_specifier_p);
   DEFSUBR (Ffont_specifier_p);
   DEFSUBR (Fface_boolean_specifier_p);
@@ -1026,6 +1039,24 @@ syms_of_objects (void)
   defsymbol (&Qface_boolean, "face-boolean");
 }
 
+static const struct lrecord_description color_specifier_description[] = {
+  { XD_LISP_OBJECT, specifier_data_offset + offsetof (struct color_specifier, face) },
+  { XD_LISP_OBJECT, specifier_data_offset + offsetof (struct color_specifier, face_property) },
+  { XD_END }
+};
+
+static const struct lrecord_description font_specifier_description[] = {
+  { XD_LISP_OBJECT, specifier_data_offset + offsetof (struct font_specifier, face) },
+  { XD_LISP_OBJECT, specifier_data_offset + offsetof (struct font_specifier, face_property) },
+  { XD_END }
+};
+
+static const struct lrecord_description face_boolean_specifier_description[] = {
+  { XD_LISP_OBJECT, specifier_data_offset + offsetof (struct face_boolean_specifier, face) },
+  { XD_LISP_OBJECT, specifier_data_offset + offsetof (struct face_boolean_specifier, face_property) },
+  { XD_END }
+};
+
 void
 specifier_type_create_objects (void)
 {
@@ -1060,12 +1091,20 @@ specifier_type_create_objects (void)
 }
 
 void
-vars_of_objects (void)
+reinit_specifier_type_create_objects (void)
+{
+  REINITIALIZE_SPECIFIER_TYPE (color);
+  REINITIALIZE_SPECIFIER_TYPE (font);
+  REINITIALIZE_SPECIFIER_TYPE (face_boolean);
+}
+
+void
+reinit_vars_of_objects (void)
 {
-  staticpro (&Vthe_null_color_instance);
+  staticpro_nodump (&Vthe_null_color_instance);
   {
-    struct Lisp_Color_Instance *c =
-      alloc_lcrecord_type (struct Lisp_Color_Instance, lrecord_color_instance);
+    Lisp_Color_Instance *c =
+      alloc_lcrecord_type (Lisp_Color_Instance, &lrecord_color_instance);
     c->name = Qnil;
     c->device = Qnil;
     c->data = 0;
@@ -1073,10 +1112,10 @@ vars_of_objects (void)
     XSETCOLOR_INSTANCE (Vthe_null_color_instance, c);
   }
 
-  staticpro (&Vthe_null_font_instance);
+  staticpro_nodump (&Vthe_null_font_instance);
   {
-    struct Lisp_Font_Instance *f =
-      alloc_lcrecord_type (struct Lisp_Font_Instance, lrecord_font_instance);
+    Lisp_Font_Instance *f =
+      alloc_lcrecord_type (Lisp_Font_Instance, &lrecord_font_instance);
     f->name = Qnil;
     f->device = Qnil;
     f->data = 0;
@@ -1089,3 +1128,9 @@ vars_of_objects (void)
     XSETFONT_INSTANCE (Vthe_null_font_instance, f);
   }
 }
+
+void
+vars_of_objects (void)
+{
+  reinit_vars_of_objects ();
+}