unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Stuff to set (sub)char table slots
@ 2012-08-15  9:19 Dmitry Antipov
  2012-08-15 15:51 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Antipov @ 2012-08-15  9:19 UTC (permalink / raw)
  To: Stefan Monnier, Emacs development discussions

[-- Attachment #1: Type: text/plain, Size: 44 bytes --]

Please consider this for the trunk.

Dmitry

[-- Attachment #2: char_tables.patch --]
[-- Type: text/plain, Size: 17027 bytes --]

=== modified file 'src/casetab.c'
--- src/casetab.c	2012-08-13 03:39:07 +0000
+++ src/casetab.c	2012-08-15 09:01:37 +0000
@@ -128,13 +128,13 @@
       up = Fmake_char_table (Qcase_table, Qnil);
       map_char_table (set_identity, Qnil, table, up);
       map_char_table (shuffle, Qnil, table, up);
-      XCHAR_TABLE (table)->extras[0] = up;
+      char_table_set_extras (table, 0, up);
     }
 
   if (NILP (canon))
     {
       canon = Fmake_char_table (Qcase_table, Qnil);
-      XCHAR_TABLE (table)->extras[1] = canon;
+      char_table_set_extras (table, 1, canon);
       map_char_table (set_canon, Qnil, table, table);
     }
 
@@ -143,11 +143,11 @@
       eqv = Fmake_char_table (Qcase_table, Qnil);
       map_char_table (set_identity, Qnil, canon, eqv);
       map_char_table (shuffle, Qnil, canon, eqv);
-      XCHAR_TABLE (table)->extras[2] = eqv;
+      char_table_set_extras (table, 2, eqv);
     }
 
   /* This is so set_image_of_range_1 in regex.c can find the EQV table.  */
-  XCHAR_TABLE (canon)->extras[2] = eqv;
+  char_table_set_extras (canon, 2, eqv);
 
   if (standard)
     {
@@ -260,7 +260,7 @@
 
   down = Fmake_char_table (Qcase_table, Qnil);
   Vascii_downcase_table = down;
-  XCHAR_TABLE (down)->purpose = Qcase_table;
+  CSET (XCHAR_TABLE (down), purpose, Qcase_table);
 
   for (i = 0; i < 128; i++)
     {
@@ -268,10 +268,10 @@
       CHAR_TABLE_SET (down, i, make_number (c));
     }
 
-  XCHAR_TABLE (down)->extras[1] = Fcopy_sequence (down);
+  char_table_set_extras (down, 1, Fcopy_sequence (down));
 
   up = Fmake_char_table (Qcase_table, Qnil);
-  XCHAR_TABLE (down)->extras[0] = up;
+  char_table_set_extras (down, 0, up);
 
   for (i = 0; i < 128; i++)
     {
@@ -281,7 +281,7 @@
       CHAR_TABLE_SET (up, i, make_number (c));
     }
 
-  XCHAR_TABLE (down)->extras[2] = Fcopy_sequence (up);
+  char_table_set_extras (down, 2, Fcopy_sequence (up));
 
   /* Fill in what isn't filled in.  */
   set_case_table (down, 1);

=== modified file 'src/category.c'
--- src/category.c	2012-08-13 03:44:27 +0000
+++ src/category.c	2012-08-15 09:01:37 +0000
@@ -71,11 +71,12 @@
   EMACS_UINT hash;
 
   if (NILP (XCHAR_TABLE (table)->extras[1]))
-    XCHAR_TABLE (table)->extras[1]
-      = make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE),
-			 make_float (DEFAULT_REHASH_SIZE),
-			 make_float (DEFAULT_REHASH_THRESHOLD),
-			 Qnil, Qnil, Qnil);
+    char_table_set_extras
+      (table, 1,
+       make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE),
+			make_float (DEFAULT_REHASH_SIZE),
+			make_float (DEFAULT_REHASH_THRESHOLD),
+			Qnil, Qnil, Qnil));
   h = XHASH_TABLE (XCHAR_TABLE (table)->extras[1]);
   i = hash_lookup (h, category_set, &hash);
   if (i >= 0)
@@ -238,10 +239,10 @@
   table = copy_char_table (table);
 
   if (! NILP (XCHAR_TABLE (table)->defalt))
-    XCHAR_TABLE (table)->defalt
-      = Fcopy_sequence (XCHAR_TABLE (table)->defalt);
-  XCHAR_TABLE (table)->extras[0]
-    = Fcopy_sequence (XCHAR_TABLE (table)->extras[0]);
+    CSET (XCHAR_TABLE (table), defalt,
+	  Fcopy_sequence (XCHAR_TABLE (table)->defalt));
+  char_table_set_extras
+    (table, 0, Fcopy_sequence (XCHAR_TABLE (table)->extras[0]));
   map_char_table (copy_category_entry, Qnil, table, table);
 
   return table;
@@ -270,9 +271,9 @@
   int i;
 
   val = Fmake_char_table (Qcategory_table, Qnil);
-  XCHAR_TABLE (val)->defalt = MAKE_CATEGORY_SET;
+  CSET (XCHAR_TABLE (val), defalt, MAKE_CATEGORY_SET);
   for (i = 0; i < (1 << CHARTAB_SIZE_BITS_0); i++)
-    XCHAR_TABLE (val)->contents[i] = MAKE_CATEGORY_SET;
+    char_table_set_contents (val, i, MAKE_CATEGORY_SET);
   Fset_char_table_extra_slot (val, make_number (0),
 			      Fmake_vector (make_number (95), Qnil));
   return val;
@@ -466,7 +467,7 @@
 
   Vstandard_category_table = Fmake_char_table (Qcategory_table, Qnil);
   /* Set a category set which contains nothing to the default.  */
-  XCHAR_TABLE (Vstandard_category_table)->defalt = MAKE_CATEGORY_SET;
+  CSET (XCHAR_TABLE (Vstandard_category_table), defalt, MAKE_CATEGORY_SET);
   Fset_char_table_extra_slot (Vstandard_category_table, make_number (0),
 			      Fmake_vector (make_number (95), Qnil));
 }

=== modified file 'src/chartab.c'
--- src/chartab.c	2012-08-14 16:28:23 +0000
+++ src/chartab.c	2012-08-15 09:06:40 +0000
@@ -115,8 +115,8 @@
   size = VECSIZE (struct Lisp_Char_Table) - 1 + n_extras;
   vector = Fmake_vector (make_number (size), init);
   XSETPVECTYPE (XVECTOR (vector), PVEC_CHAR_TABLE);
-  XCHAR_TABLE (vector)->parent = Qnil;
-  XCHAR_TABLE (vector)->purpose = purpose;
+  CSET (XCHAR_TABLE (vector), parent, Qnil);
+  CSET (XCHAR_TABLE (vector), purpose, purpose);
   XSETCHAR_TABLE (vector, XCHAR_TABLE (vector));
   return vector;
 }
@@ -167,9 +167,9 @@
     {
       val = XSUB_CHAR_TABLE (table)->contents[i];
       if (SUB_CHAR_TABLE_P (val))
-	XSUB_CHAR_TABLE (copy)->contents[i] = copy_sub_char_table (val);
+	sub_char_table_set_contents (copy, i, copy_sub_char_table (val));
       else
-	XSUB_CHAR_TABLE (copy)->contents[i] = val;
+	sub_char_table_set_contents (copy, i, val);
     }
 
   return copy;
@@ -185,18 +185,19 @@
 
   copy = Fmake_vector (make_number (size), Qnil);
   XSETPVECTYPE (XVECTOR (copy), PVEC_CHAR_TABLE);
-  XCHAR_TABLE (copy)->defalt = XCHAR_TABLE (table)->defalt;
-  XCHAR_TABLE (copy)->parent = XCHAR_TABLE (table)->parent;
-  XCHAR_TABLE (copy)->purpose = XCHAR_TABLE (table)->purpose;
+  CSET (XCHAR_TABLE (copy), defalt, XCHAR_TABLE (table)->defalt);
+  CSET (XCHAR_TABLE (copy), parent, XCHAR_TABLE (table)->parent);
+  CSET (XCHAR_TABLE (copy), purpose, XCHAR_TABLE (table)->purpose);
   for (i = 0; i < chartab_size[0]; i++)
-    XCHAR_TABLE (copy)->contents[i]
-      = (SUB_CHAR_TABLE_P (XCHAR_TABLE (table)->contents[i])
-	 ? copy_sub_char_table (XCHAR_TABLE (table)->contents[i])
-	 : XCHAR_TABLE (table)->contents[i]);
-  XCHAR_TABLE (copy)->ascii = char_table_ascii (copy);
+    char_table_set_contents
+      (copy, i, 
+       (SUB_CHAR_TABLE_P (XCHAR_TABLE (table)->contents[i])
+	? copy_sub_char_table (XCHAR_TABLE (table)->contents[i])
+	: XCHAR_TABLE (table)->contents[i]));
+  CSET (XCHAR_TABLE (copy), ascii, char_table_ascii (copy));
   size -= VECSIZE (struct Lisp_Char_Table) - 1;
   for (i = 0; i < size; i++)
-    XCHAR_TABLE (copy)->extras[i] = XCHAR_TABLE (table)->extras[i];
+    char_table_set_extras (copy, i, XCHAR_TABLE (table)->extras[i]);
 
   XSETCHAR_TABLE (copy, XCHAR_TABLE (copy));
   return copy;
@@ -394,7 +395,7 @@
   Lisp_Object sub;
 
   if (depth == 3)
-    tbl->contents[i] = val;
+    sub_char_table_set_contents (table, i, val);
   else
     {
       sub = tbl->contents[i];
@@ -407,7 +408,7 @@
 	      sub = make_sub_char_table (depth + 1,
 					 min_char + i * chartab_chars[depth],
 					 sub);
-	      tbl->contents[i] = sub;
+	      sub_char_table_set_contents (table, i, sub);
 	    }
 	}
       sub_char_table_set (sub, c, val, is_uniprop);
@@ -421,9 +422,7 @@
 
   if (ASCII_CHAR_P (c)
       && SUB_CHAR_TABLE_P (tbl->ascii))
-    {
-      XSUB_CHAR_TABLE (tbl->ascii)->contents[c] = val;
-    }
+    sub_char_table_set_contents (tbl->ascii, c, val);
   else
     {
       int i = CHARTAB_IDX (c, 0, 0);
@@ -433,11 +432,11 @@
       if (! SUB_CHAR_TABLE_P (sub))
 	{
 	  sub = make_sub_char_table (1, i * chartab_chars[0], sub);
-	  tbl->contents[i] = sub;
+	  char_table_set_contents (table, i, sub);
 	}
       sub_char_table_set (sub, c, val, UNIPROP_TABLE_P (table));
       if (ASCII_CHAR_P (c))
-	tbl->ascii = char_table_ascii (table);
+	CSET (tbl, ascii, char_table_ascii (table));
     }
   return val;
 }
@@ -461,7 +460,7 @@
       if (c > to)
 	break;
       if (from <= c && c + chars_in_block - 1 <= to)
-	tbl->contents[i] = val;
+	sub_char_table_set_contents (table, i, val);
       else
 	{
 	  Lisp_Object sub = tbl->contents[i];
@@ -472,7 +471,7 @@
 	      else
 		{
 		  sub = make_sub_char_table (depth + 1, c, sub);
-		  tbl->contents[i] = sub;
+		  sub_char_table_set_contents (table, i, sub);
 		}
 	    }
 	  sub_char_table_set_range (sub, from, to, val, is_uniprop);
@@ -500,20 +499,20 @@
 	  if (c > to)
 	    break;
 	  if (from <= c && c + chartab_chars[0] - 1 <= to)
-	    tbl->contents[i] = val;
+	    char_table_set_contents (table, i, val);
 	  else
 	    {
 	      Lisp_Object sub = tbl->contents[i];
 	      if (! SUB_CHAR_TABLE_P (sub))
 		{
 		  sub = make_sub_char_table (1, i * chartab_chars[0], sub);
-		  tbl->contents[i] = sub;
+		  char_table_set_contents (table, i, sub);
 		}
 	      sub_char_table_set_range (sub, from, to, val, is_uniprop);
 	    }
 	}
       if (ASCII_CHAR_P (from))
-	tbl->ascii = char_table_ascii (table);
+	CSET (tbl, ascii, char_table_ascii (table));
     }
   return val;
 }
@@ -563,7 +562,7 @@
 	  error ("Attempt to make a chartable be its own parent");
     }
 
-  XCHAR_TABLE (char_table)->parent = parent;
+  CSET (XCHAR_TABLE (char_table), parent, parent);
 
   return parent;
 }
@@ -640,12 +639,12 @@
     {
       int i;
 
-      XCHAR_TABLE (char_table)->ascii = value;
+      CSET (XCHAR_TABLE (char_table), ascii, value);
       for (i = 0; i < chartab_size[0]; i++)
-	XCHAR_TABLE (char_table)->contents[i] = value;
+	char_table_set_contents (char_table, i, value);
     }
   else if (EQ (range, Qnil))
-    XCHAR_TABLE (char_table)->defalt = value;
+    CSET (XCHAR_TABLE (char_table), defalt, value);
   else if (CHARACTERP (range))
     char_table_set (char_table, XINT (range), value);
   else if (CONSP (range))
@@ -728,11 +727,11 @@
     {
       elt = XCHAR_TABLE (char_table)->contents[i];
       if (SUB_CHAR_TABLE_P (elt))
-	XCHAR_TABLE (char_table)->contents[i]
-	  = optimize_sub_char_table (elt, test);
+	char_table_set_contents
+	  (char_table, i, optimize_sub_char_table (elt, test));
     }
   /* Reset the `ascii' cache, in case it got optimized away.  */
-  XCHAR_TABLE (char_table)->ascii = char_table_ascii (char_table);
+  CSET (XCHAR_TABLE (char_table), ascii, char_table_ascii (char_table));
 
   return Qnil;
 }
@@ -824,9 +823,9 @@
 
 		      /* This is to get a value of FROM in PARENT
 			 without checking the parent of PARENT.  */
-		      XCHAR_TABLE (parent)->parent = Qnil;
+		      CSET (XCHAR_TABLE (parent), parent, Qnil);
 		      val = CHAR_TABLE_REF (parent, from);
-		      XCHAR_TABLE (parent)->parent = temp;
+		      CSET (XCHAR_TABLE (parent), parent, temp);
 		      XSETCDR (range, make_number (c - 1));
 		      val = map_sub_char_table (c_function, function,
 						parent, arg, val, range,
@@ -906,9 +905,9 @@
       temp = XCHAR_TABLE (parent)->parent;
       /* This is to get a value of FROM in PARENT without checking the
 	 parent of PARENT.  */
-      XCHAR_TABLE (parent)->parent = Qnil;
+      CSET (XCHAR_TABLE (parent), parent, Qnil);
       val = CHAR_TABLE_REF (parent, from);
-      XCHAR_TABLE (parent)->parent = temp;
+      CSET (XCHAR_TABLE (parent), parent, temp);
       val = map_sub_char_table (c_function, function, parent, arg, val, range,
 				parent);
       table = parent;
@@ -1143,10 +1142,9 @@
   int min_char = (XINT (XSUB_CHAR_TABLE (table)->min_char)
 		  + chartab_chars[2] * idx);
   Lisp_Object sub = make_sub_char_table (3, min_char, Qnil);
-  struct Lisp_Sub_Char_Table *subtbl = XSUB_CHAR_TABLE (sub);
   const unsigned char *p, *pend;
 
-  XSUB_CHAR_TABLE (table)->contents[idx] = sub;
+  sub_char_table_set_contents (table, idx, sub);
   p = SDATA (val), pend = p + SBYTES (val);
   if (*p == 1)
     {
@@ -1156,7 +1154,8 @@
       while (p < pend && idx < chartab_chars[2])
 	{
 	  int v = STRING_CHAR_ADVANCE (p);
-	  subtbl->contents[idx++] = v > 0 ? make_number (v) : Qnil;
+	  sub_char_table_set_contents
+	    (sub, idx++, v > 0 ? make_number (v) : Qnil);
 	}
     }
   else if (*p == 2)
@@ -1181,7 +1180,7 @@
 		}
 	    }
 	  while (count-- > 0)
-	    subtbl->contents[idx++] = make_number (v);
+	    sub_char_table_set_contents (sub, idx++, make_number (v));
 	}
     }
 /* It seems that we don't need this function because C code won't need
@@ -1284,7 +1283,7 @@
 
       args[0] = XCHAR_TABLE (table)->extras[4];
       args[1] = Fmake_vector (make_number (1), value);
-      XCHAR_TABLE (table)->extras[4] = Fvconcat (2, args);
+      char_table_set_extras (table, 4, Fvconcat (2, args));
     }
   return make_number (i);
 }
@@ -1346,7 +1345,7 @@
       : ! NILP (val))
     return Qnil;
   /* Prepare ASCII values in advance for CHAR_TABLE_REF.  */
-  XCHAR_TABLE (table)->ascii = char_table_ascii (table);
+  CSET (XCHAR_TABLE (table), ascii, char_table_ascii (table));
   return table;
 }
 

=== modified file 'src/fns.c'
--- src/fns.c	2012-08-08 10:23:04 +0000
+++ src/fns.c	2012-08-15 09:01:37 +0000
@@ -2150,8 +2150,8 @@
       int i;
 
       for (i = 0; i < (1 << CHARTAB_SIZE_BITS_0); i++)
-	XCHAR_TABLE (array)->contents[i] = item;
-      XCHAR_TABLE (array)->defalt = item;
+	char_table_set_contents (array, i, item);
+      CSET (XCHAR_TABLE (array), defalt, item);
     }
   else if (STRINGP (array))
     {

=== modified file 'src/fontset.c'
--- src/fontset.c	2012-08-07 07:33:18 +0000
+++ src/fontset.c	2012-08-15 09:01:37 +0000
@@ -1918,7 +1918,7 @@
   if (!EQ (fontset, Vdefault_fontset))
     {
       tables[1] = Fmake_char_table (Qnil, Qnil);
-      XCHAR_TABLE (tables[0])->extras[0] = tables[1];
+      char_table_set_extras (tables[0], 0, tables[1]);
       fontsets[1] = Vdefault_fontset;
     }
 
@@ -1981,7 +1981,7 @@
 	      if (c <= MAX_5_BYTE_CHAR)
 		char_table_set_range (tables[k], c, to, alist);
 	      else
-		XCHAR_TABLE (tables[k])->defalt = alist;
+		CSET (XCHAR_TABLE (tables[k]), defalt, alist);
 
 	      /* At last, change each elements to font names.  */
 	      for (; CONSP (alist); alist = XCDR (alist))

=== modified file 'src/lisp.h'
--- src/lisp.h	2012-08-14 17:45:25 +0000
+++ src/lisp.h	2012-08-15 09:04:19 +0000
@@ -936,7 +936,11 @@
 
 extern const int chartab_size[4];
 
-struct Lisp_Sub_Char_Table;
+/* Most code should use this macro to set non-array Lisp fields in struct
+   Lisp_Char_Table.  For CONTENTS and EXTRAS, use char_table_set_contents
+   and char_table_set_extras, respectively.  */
+
+#define CSET(c, field, value) ((c)->field = (value))
 
 struct Lisp_Char_Table
   {
@@ -986,6 +990,7 @@
     /* Minimum character covered by the sub char-table.  */
     Lisp_Object min_char;
 
+    /* Use sub_char_table_set_contents to set this.  */
     Lisp_Object contents[1];
   };
 
@@ -2431,6 +2436,26 @@
   XSTRING (s)->intervals = i;
 }
 
+/* Set different slots in (sub)character tables.  */
+
+LISP_INLINE void
+char_table_set_extras (Lisp_Object table, ptrdiff_t idx, Lisp_Object val)
+{
+  XCHAR_TABLE (table)->extras[idx] = val;
+}
+
+LISP_INLINE void
+char_table_set_contents (Lisp_Object table, ptrdiff_t idx, Lisp_Object val)
+{
+  XCHAR_TABLE (table)->contents[idx] = val;
+}
+
+LISP_INLINE void
+sub_char_table_set_contents (Lisp_Object table, ptrdiff_t idx, Lisp_Object val)
+{
+  XSUB_CHAR_TABLE (table)->contents[idx] = val;
+}
+
 /* Defined in data.c.  */
 extern Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound;
 extern Lisp_Object Qerror_conditions, Qerror_message, Qtop_level;

=== modified file 'src/search.c'
--- src/search.c	2012-08-05 13:30:15 +0000
+++ src/search.c	2012-08-15 09:01:37 +0000
@@ -278,8 +278,8 @@
     save_search_regs ();
 
   /* This is so set_image_of_range_1 in regex.c can find the EQV table.  */
-  XCHAR_TABLE (BVAR (current_buffer, case_canon_table))->extras[2]
-    = BVAR (current_buffer, case_eqv_table);
+  char_table_set_extras (BVAR (current_buffer, case_canon_table), 2,
+			 BVAR (current_buffer, case_eqv_table));
 
   CHECK_STRING (string);
   bufp = compile_pattern (string,
@@ -393,8 +393,8 @@
     }
 
   /* This is so set_image_of_range_1 in regex.c can find the EQV table.  */
-  XCHAR_TABLE (BVAR (current_buffer, case_canon_table))->extras[2]
-    = BVAR (current_buffer, case_eqv_table);
+  char_table_set_extras (BVAR (current_buffer, case_canon_table), 2,
+			 BVAR (current_buffer, case_eqv_table));
 
   bufp = compile_pattern (regexp,
 			  (NILP (Vinhibit_changing_match_data)
@@ -990,8 +990,8 @@
     }
 
   /* This is so set_image_of_range_1 in regex.c can find the EQV table.  */
-  XCHAR_TABLE (BVAR (current_buffer, case_canon_table))->extras[2]
-    = BVAR (current_buffer, case_eqv_table);
+  char_table_set_extras (BVAR (current_buffer, case_canon_table), 2,
+			 BVAR (current_buffer, case_eqv_table));
 
   np = search_buffer (string, PT, PT_BYTE, lim, lim_byte, n, RE,
 		      (!NILP (BVAR (current_buffer, case_fold_search))

=== modified file 'src/syntax.c'
--- src/syntax.c	2012-08-13 03:39:07 +0000
+++ src/syntax.c	2012-08-15 09:01:37 +0000
@@ -819,7 +819,7 @@
 
   /* Only the standard syntax table should have a default element.
      Other syntax tables should inherit from parents instead.  */
-  XCHAR_TABLE (copy)->defalt = Qnil;
+  CSET (XCHAR_TABLE (copy), defalt, Qnil);
 
   /* Copied syntax tables should all have parents.
      If we copied one with no parent, such as the standard syntax table,


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Stuff to set (sub)char table slots
  2012-08-15  9:19 Stuff to set (sub)char table slots Dmitry Antipov
@ 2012-08-15 15:51 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2012-08-15 15:51 UTC (permalink / raw)
  To: Dmitry Antipov; +Cc: Emacs development discussions

> Please consider this for the trunk.

Looks OK,


        Stefan



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-08-15 15:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-15  9:19 Stuff to set (sub)char table slots Dmitry Antipov
2012-08-15 15:51 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).