From a098c9308eb2abee17d1f800d5895c12f471097e Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Thu, 16 Aug 2012 07:13:44 +0400 Subject: [PATCH] Simple interface to set Lisp_Object fields of chararcter tables. * lisp.h (CSET): New macro. (char_table_set_extras, char_table_set_contents) (sub_char_table_set_contents): New function. * casetab.c, category.c, chartab.c, fns.c, fontset.c, search.c: * syntax.c: Adjust users. --- src/ChangeLog | 9 ++++++ src/casetab.c | 16 +++++----- src/category.c | 25 ++++++++------- src/chartab.c | 86 +++++++++++++++++++++++++------------------------- src/fns.c | 4 +-- src/fontset.c | 4 +-- src/lisp.h | 29 ++++++++++++++++- src/search.c | 12 +++---- src/syntax.c | 2 +- 9 files changed, 112 insertions(+), 75 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b203908cdb6..27527dbb934 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2012-08-16 Dmitry Antipov + + Simple interface to set Lisp_Object fields of chararcter tables. + * lisp.h (CSET): New macro. + (char_table_set_extras, char_table_set_contents) + (sub_char_table_set_contents): New function. + * casetab.c, category.c, chartab.c, fns.c, fontset.c, search.c: + * syntax.c: Adjust users. + 2012-08-16 Stefan Monnier * eval.c (eval_sub): Bind lexical-binding. diff --git a/src/casetab.c b/src/casetab.c index 4b29c091ca9..6097299047a 100644 --- a/src/casetab.c +++ b/src/casetab.c @@ -128,13 +128,13 @@ set_case_table (Lisp_Object table, int standard) 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 @@ set_case_table (Lisp_Object table, int standard) 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 @@ init_casetab_once (void) 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 @@ init_casetab_once (void) 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 @@ init_casetab_once (void) 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); diff --git a/src/category.c b/src/category.c index 13c6e46d283..3d5b3cff04a 100644 --- a/src/category.c +++ b/src/category.c @@ -71,11 +71,12 @@ hash_get_category_set (Lisp_Object table, Lisp_Object category_set) 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 @@ copy_category_table (Lisp_Object table) 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 @@ DEFUN ("make-category-table", Fmake_category_table, Smake_category_table, 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 @@ init_category_once (void) 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)); } diff --git a/src/chartab.c b/src/chartab.c index c022bc03e66..e79ff73c375 100644 --- a/src/chartab.c +++ b/src/chartab.c @@ -115,8 +115,8 @@ the char-table has no extra slot. */) 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 @@ copy_sub_char_table (Lisp_Object table) { 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_char_table (Lisp_Object table) 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 @@ sub_char_table_set (Lisp_Object table, int c, Lisp_Object val, int is_uniprop) 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_char_table_set (Lisp_Object table, int c, Lisp_Object val, int is_uniprop) 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 @@ char_table_set (Lisp_Object table, int c, Lisp_Object val) 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 @@ char_table_set (Lisp_Object table, int c, Lisp_Object val) 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 @@ sub_char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val, 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 @@ sub_char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val, 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 @@ char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val) 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 @@ Return PARENT. PARENT must be either nil or another char-table. */) 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; } @@ -594,7 +593,8 @@ DEFUN ("set-char-table-extra-slot", Fset_char_table_extra_slot, || XINT (n) >= CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (char_table))) args_out_of_range (char_table, n); - return XCHAR_TABLE (char_table)->extras[XINT (n)] = value; + char_table_set_extras (char_table, XINT (n), value); + return value; } DEFUN ("char-table-range", Fchar_table_range, Schar_table_range, @@ -640,12 +640,12 @@ or a character code. Return VALUE. */) { 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 +728,11 @@ equivalent and can be merged. It defaults to `equal'. */) { 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 +824,9 @@ map_sub_char_table (void (*c_function) (Lisp_Object, Lisp_Object, Lisp_Object), /* 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 +906,9 @@ map_char_table (void (*c_function) (Lisp_Object, Lisp_Object, Lisp_Object), 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 +1143,9 @@ uniprop_table_uncompress (Lisp_Object table, int idx) 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 +1155,8 @@ uniprop_table_uncompress (Lisp_Object table, int idx) 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 +1181,7 @@ uniprop_table_uncompress (Lisp_Object table, int idx) } } 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 +1284,7 @@ uniprop_encode_value_numeric (Lisp_Object table, Lisp_Object value) 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 +1346,7 @@ uniprop_table (Lisp_Object prop) : ! 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; } diff --git a/src/fns.c b/src/fns.c index 12dca917e62..039c208b0d3 100644 --- a/src/fns.c +++ b/src/fns.c @@ -2150,8 +2150,8 @@ ARRAY is a vector, string, char-table, or bool-vector. */) 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)) { diff --git a/src/fontset.c b/src/fontset.c index 3c7e931d121..82d668a3871 100644 --- a/src/fontset.c +++ b/src/fontset.c @@ -1916,7 +1916,7 @@ format is the same as above. */) 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; } @@ -1979,7 +1979,7 @@ format is the same as above. */) 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)) diff --git a/src/lisp.h b/src/lisp.h index a0d47b3895e..42297bf0402 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -936,7 +936,11 @@ enum CHARTAB_SIZE_BITS 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 @@ struct Lisp_Sub_Char_Table /* 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,28 @@ string_set_intervals (Lisp_Object s, INTERVAL i) 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) +{ + eassert (0 <= idx && idx < CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (table))); + XCHAR_TABLE (table)->extras[idx] = val; +} + +LISP_INLINE void +char_table_set_contents (Lisp_Object table, ptrdiff_t idx, Lisp_Object val) +{ + eassert (0 <= idx && idx < (1 << CHARTAB_SIZE_BITS_0)); + 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; diff --git a/src/search.c b/src/search.c index 004e599be9c..4bf4d11c33a 100644 --- a/src/search.c +++ b/src/search.c @@ -278,8 +278,8 @@ looking_at_1 (Lisp_Object string, int posix) 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 @@ string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start, int p } /* 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 @@ search_command (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, } /* 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)) diff --git a/src/syntax.c b/src/syntax.c index 08a63e033b2..1cbad1ae0a4 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -819,7 +819,7 @@ It is a copy of the TABLE, which defaults to the standard syntax table. */) /* 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, -- 2.39.2