* lisp.h (header_size, bool_header_size, word_size): Now here.
(struct Lisp_Vector): Add comment.
(struct Lisp_Bool_Vector): Move up to define handy constants.
(VECSIZE, PSEUDOVECSIZE): Simplify.
(SAFE_ALLOCA_LISP): Use new constant. Adjust indentation.
* buffer.c, buffer.h, bytecode.c, callint.c, eval.c, fns.c:
* font.c, fontset.c, keyboard.c, keymap.c, macros.c, menu.c:
* msdos.c, w32menu.c, w32term.h, window.c, xdisp.c, xfaces.c:
* xfont.c, xmenu.c: Use word_size where appropriate.
+2012-08-05 Dmitry Antipov <dmantipov@yandex.ru>
+
+ Generalize common compile-time constants.
+ * lisp.h (header_size, bool_header_size, word_size): Now here.
+ (struct Lisp_Vector): Add comment.
+ (struct Lisp_Bool_Vector): Move up to define handy constants.
+ (VECSIZE, PSEUDOVECSIZE): Simplify.
+ (SAFE_ALLOCA_LISP): Use new constant. Adjust indentation.
+ * buffer.c, buffer.h, bytecode.c, callint.c, eval.c, fns.c:
+ * font.c, fontset.c, keyboard.c, keymap.c, macros.c, menu.c:
+ * msdos.c, w32menu.c, w32term.h, window.c, xdisp.c, xfaces.c:
+ * xfont.c, xmenu.c: Use word_size where appropriate.
+
2012-08-05 Lawrence Mitchell <wence@gmx.li>
* search.c (Freplace_match): Treat \? in the replacement text
/* Default value of gc_cons_threshold (see below). */
-#define GC_DEFAULT_THRESHOLD (100000 * sizeof (Lisp_Object))
+#define GC_DEFAULT_THRESHOLD (100000 * word_size)
/* Global variables. */
struct emacs_globals globals;
static void free_misc (Lisp_Object);
extern Lisp_Object which_symbols (Lisp_Object, EMACS_INT) EXTERNALLY_VISIBLE;
-/* Handy constants for vectorlike objects. */
-enum
- {
- header_size = offsetof (struct Lisp_Vector, contents),
- bool_header_size = offsetof (struct Lisp_Bool_Vector, data),
- word_size = sizeof (Lisp_Object)
- };
-
/* When scanning the C stack for live Lisp objects, Emacs keeps track
of what memory allocated via lisp_malloc is intended for what
purpose. This enumeration specifies the type of memory. */
Lisp_Object val, *objp;
/* Change to SAFE_ALLOCA if you hit this eassert. */
- eassert (count <= MAX_ALLOCA / sizeof (Lisp_Object));
+ eassert (count <= MAX_ALLOCA / word_size);
- objp = alloca (count * sizeof (Lisp_Object));
+ objp = alloca (count * word_size);
objp[0] = arg;
va_start (ap, arg);
for (i = 1; i < count; i++)
/* Maximum length of an overlay vector. */
#define OVERLAY_COUNT_MAX \
((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, \
- min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object)))
+ min (PTRDIFF_MAX, SIZE_MAX) / word_size))
/* Flags indicating which built-in buffer-local variables
are permanent locals. */
ptrdiff_t i;
memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents,
- size * sizeof (Lisp_Object));
+ size * word_size);
gcpro1.var = copy;
gcpro1.nvars = size;
sure that this is still correct. Otherwise, mark_vectorlike may not
trace all Lisp_Objects in buffer_defaults and buffer_local_symbols. */
const int pvecsize
- = (offsetof (struct buffer, own_text) - sizeof (struct vectorlike_header))
- / sizeof (Lisp_Object);
+ = (offsetof (struct buffer, own_text) - header_size) / word_size;
memset (buffer_permanent_local_flags, 0, sizeof buffer_permanent_local_flags);
The local flag bits are in the local_var_flags slot of the buffer. */
/* Nothing can work if this isn't true */
- { verify (sizeof (EMACS_INT) == sizeof (Lisp_Object)); }
+ { verify (sizeof (EMACS_INT) == word_size); }
/* 0 means not a lisp var, -1 means always local, else mask */
memset (&buffer_local_flags, 0, sizeof buffer_local_flags);
#define FOR_EACH_PER_BUFFER_OBJECT_AT(offset) \
for (offset = PER_BUFFER_VAR_OFFSET (name); \
offset <= PER_BUFFER_VAR_OFFSET (cursor_in_non_selected_windows); \
- offset += sizeof (Lisp_Object))
+ offset += word_size)
/* Return the index of buffer-local variable VAR. Each per-buffer
variable has an index > 0 associated with it, except when it always
stack.byte_string = bytestr;
stack.pc = stack.byte_string_start = SDATA (bytestr);
stack.constants = vector;
- if (MAX_ALLOCA / sizeof (Lisp_Object) <= XFASTINT (maxdepth))
+ if (MAX_ALLOCA / word_size <= XFASTINT (maxdepth))
memory_full (SIZE_MAX);
top = alloca ((XFASTINT (maxdepth) + 1) * sizeof *top);
#if BYTE_MAINTAIN_TOP
}
if (min (MOST_POSITIVE_FIXNUM,
- min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object))
+ min (PTRDIFF_MAX, SIZE_MAX) / word_size)
< nargs)
memory_full (SIZE_MAX);
gcpro1.nvars = 1 + numargs;
}
- memcpy (funcall_args, args, nargs * sizeof (Lisp_Object));
+ memcpy (funcall_args, args, nargs * word_size);
/* Spread the last arg we got. Its first element goes in
the slot that it used to occupy, hence this value of I. */
i = nargs - 1;
{
internal_args = alloca (XSUBR (fun)->max_args
* sizeof *internal_args);
- memcpy (internal_args, args + 1, numargs * sizeof (Lisp_Object));
+ memcpy (internal_args, args + 1, numargs * word_size);
for (i = numargs; i < XSUBR (fun)->max_args; i++)
internal_args[i] = Qnil;
}
/* An upper bound on the size of a hash table index. It must fit in
ptrdiff_t and be a valid Emacs fixnum. */
#define INDEX_SIZE_BOUND \
- ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, PTRDIFF_MAX / sizeof (Lisp_Object)))
+ ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, PTRDIFF_MAX / word_size))
/* Create and initialize a new hash table.
font_vconcat_entity_vectors (Lisp_Object list)
{
int nargs = XINT (Flength (list));
- Lisp_Object *args = alloca (sizeof (Lisp_Object) * nargs);
+ Lisp_Object *args = alloca (word_size * nargs);
int i;
for (i = 0; i < nargs; i++, list = XCDR (list))
}
if (score_changed)
- qsort (XVECTOR (vec)->contents, size, sizeof (Lisp_Object),
+ qsort (XVECTOR (vec)->contents, size, word_size,
fontset_compare_rfontdef);
XSETCAR (font_group, make_number (charset_ordered_list_tick));
}
/* Recode fontsets realized on FRAME from the base fontset FONTSET
in the table `realized'. */
- realized[0] = alloca (sizeof (Lisp_Object) * ASIZE (Vfontset_table));
+ realized[0] = alloca (word_size * ASIZE (Vfontset_table));
for (i = j = 0; i < ASIZE (Vfontset_table); i++)
{
elt = FONTSET_FROM_ID (i);
}
realized[0][j] = Qnil;
- realized[1] = alloca (sizeof (Lisp_Object) * ASIZE (Vfontset_table));
+ realized[1] = alloca (word_size * ASIZE (Vfontset_table));
for (i = j = 0; ! NILP (realized[0][i]); i++)
{
elt = FONTSET_DEFAULT (realized[0][i]);
if (end > i + 4)
memmove (aref_addr (menu_bar_items_vector, i),
aref_addr (menu_bar_items_vector, i + 4),
- (end - i - 4) * sizeof (Lisp_Object));
+ (end - i - 4) * word_size);
ASET (menu_bar_items_vector, end - 4, tem0);
ASET (menu_bar_items_vector, end - 3, tem1);
ASET (menu_bar_items_vector, end - 2, tem2);
if (menu_bar_items_index > i + 4)
memmove (aref_addr (menu_bar_items_vector, i),
aref_addr (menu_bar_items_vector, i + 4),
- (menu_bar_items_index - i - 4) * sizeof (Lisp_Object));
+ (menu_bar_items_index - i - 4) * word_size);
menu_bar_items_index -= 4;
}
}
if (ntool_bar_items > i + TOOL_BAR_ITEM_NSLOTS)
memmove (v, v + TOOL_BAR_ITEM_NSLOTS,
((ntool_bar_items - i - TOOL_BAR_ITEM_NSLOTS)
- * sizeof (Lisp_Object)));
+ * word_size));
ntool_bar_items -= TOOL_BAR_ITEM_NSLOTS;
break;
}
{
val = Fvector (NUM_RECENT_KEYS, keys);
memcpy (XVECTOR (val)->contents, keys + recent_keys_index,
- (NUM_RECENT_KEYS - recent_keys_index) * sizeof (Lisp_Object));
+ (NUM_RECENT_KEYS - recent_keys_index) * word_size);
memcpy (XVECTOR (val)->contents + NUM_RECENT_KEYS - recent_keys_index,
- keys, recent_keys_index * sizeof (Lisp_Object));
+ keys, recent_keys_index * word_size);
return val;
}
}
size += XINT (Flength (prefix));
/* This has one extra element at the end that we don't pass to Fconcat. */
- if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object) / 4 < size)
+ if (min (PTRDIFF_MAX, SIZE_MAX) / word_size / 4 < size)
memory_full (SIZE_MAX);
SAFE_ALLOCA_LISP (args, size * 4);
} next;
};
+/* Regular vector is just a header plus array of Lisp_Objects. */
+
struct Lisp_Vector
{
struct vectorlike_header header;
Lisp_Object contents[1];
};
+/* A boolvector is a kind of vectorlike, with contents are like a string. */
+
+struct Lisp_Bool_Vector
+ {
+ /* HEADER.SIZE is the vector's size field. It doesn't have the real size,
+ just the subtype information. */
+ struct vectorlike_header header;
+ /* This is the size in bits. */
+ EMACS_INT size;
+ /* This contains the actual bits, packed into bytes. */
+ unsigned char data[1];
+ };
+
+/* Some handy constants for calculating sizes
+ and offsets, mostly of vectorlike objects. */
+
+enum
+ {
+ header_size = offsetof (struct Lisp_Vector, contents),
+ bool_header_size = offsetof (struct Lisp_Bool_Vector, data),
+ word_size = sizeof (Lisp_Object)
+ };
+
/* If a struct is made to look like a vector, this macro returns the length
of the shortest vector that would hold that struct. */
-#define VECSIZE(type) ((sizeof (type) \
- - offsetof (struct Lisp_Vector, contents[0]) \
- + sizeof (Lisp_Object) - 1) /* Round up. */ \
- / sizeof (Lisp_Object))
+
+#define VECSIZE(type) \
+ ((sizeof (type) - header_size + word_size - 1) / word_size)
/* Like VECSIZE, but used when the pseudo-vector has non-Lisp_Object fields
at the end and we need to compute the number of Lisp_Object fields (the
ones that the GC needs to trace). */
-#define PSEUDOVECSIZE(type, nonlispfield) \
- ((offsetof (type, nonlispfield) - offsetof (struct Lisp_Vector, contents[0])) \
- / sizeof (Lisp_Object))
+
+#define PSEUDOVECSIZE(type, nonlispfield) \
+ ((offsetof (type, nonlispfield) - header_size) / word_size)
/* A char-table is a kind of vectorlike, with contents are like a
vector but with a few other slots. For some purposes, it makes
Lisp_Object contents[1];
};
-/* A boolvector is a kind of vectorlike, with contents are like a string. */
-struct Lisp_Bool_Vector
- {
- /* HEADER.SIZE is the vector's size field. It doesn't have the real size,
- just the subtype information. */
- struct vectorlike_header header;
- /* This is the size in bits. */
- EMACS_INT size;
- /* This contains the actual bits, packed into bytes. */
- unsigned char data[1];
- };
-
/* This structure describes a built-in function.
It is generated by the DEFUN macro only.
defsubr makes it into a Lisp object.
/* SAFE_ALLOCA_LISP allocates an array of Lisp_Objects. */
-#define SAFE_ALLOCA_LISP(buf, nelt) \
- do { \
- if ((nelt) < MAX_ALLOCA / sizeof (Lisp_Object)) \
- buf = alloca ((nelt) * sizeof (Lisp_Object)); \
- else if ((nelt) < min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object)) \
- { \
- Lisp_Object arg_; \
- buf = xmalloc ((nelt) * sizeof (Lisp_Object)); \
- arg_ = make_save_value (buf, nelt); \
- XSAVE_VALUE (arg_)->dogc = 1; \
- sa_must_free = 1; \
- record_unwind_protect (safe_alloca_unwind, arg_); \
- } \
- else \
- memory_full (SIZE_MAX); \
+#define SAFE_ALLOCA_LISP(buf, nelt) \
+ do { \
+ if ((nelt) < MAX_ALLOCA / word_size) \
+ buf = alloca ((nelt) * word_size); \
+ else if ((nelt) < min (PTRDIFF_MAX, SIZE_MAX) / word_size) \
+ { \
+ Lisp_Object arg_; \
+ buf = xmalloc ((nelt) * word_size); \
+ arg_ = make_save_value (buf, nelt); \
+ XSAVE_VALUE (arg_)->dogc = 1; \
+ sa_must_free = 1; \
+ record_unwind_protect (safe_alloca_unwind, arg_); \
+ } \
+ else \
+ memory_full (SIZE_MAX); \
} while (0)
if (!current_kboard->kbd_macro_buffer)
{
- current_kboard->kbd_macro_buffer = xmalloc (30 * sizeof (Lisp_Object));
+ current_kboard->kbd_macro_buffer = xmalloc (30 * word_size);
current_kboard->kbd_macro_bufsize = 30;
}
update_mode_lines++;
{
current_kboard->kbd_macro_buffer
= xrealloc (current_kboard->kbd_macro_buffer,
- 30 * sizeof (Lisp_Object));
+ 30 * word_size);
current_kboard->kbd_macro_bufsize = 30;
}
current_kboard->kbd_macro_ptr = current_kboard->kbd_macro_buffer;
prefix = entry = Qnil;
i = 0;
- subprefix_stack = alloca (menu_items_used * sizeof (Lisp_Object));
+ subprefix_stack = alloca (menu_items_used * word_size);
while (i < menu_items_used)
{
Lisp_Object tail;
int i, j, length = XINT (Flength (alist));
Lisp_Object *parms
- = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
+ = (Lisp_Object *) alloca (length * word_size);
Lisp_Object *values
- = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
+ = (Lisp_Object *) alloca (length * word_size);
/* Do we have to reverse the foreground and background colors? */
int reverse = EQ (Fcdr (Fassq (Qreverse, FVAR (f, param_alist))), Qt);
int redraw = 0, fg_set = 0, bg_set = 0;
{
val = Fvector (NUM_RECENT_DOSKEYS, keys);
memcpy (XVECTOR (val)->contents, keys + recent_doskeys_index,
- (NUM_RECENT_DOSKEYS - recent_doskeys_index) * sizeof (Lisp_Object));
+ (NUM_RECENT_DOSKEYS - recent_doskeys_index) * word_size);
memcpy (XVECTOR (val)->contents + NUM_RECENT_DOSKEYS - recent_doskeys_index,
- keys, recent_doskeys_index * sizeof (Lisp_Object));
+ keys, recent_doskeys_index * word_size);
return val;
}
}
if (!f)
return;
entry = Qnil;
- subprefix_stack = (Lisp_Object *) alloca (f->menu_bar_items_used * sizeof (Lisp_Object));
+ subprefix_stack = (Lisp_Object *) alloca (f->menu_bar_items_used * word_size);
vector = FVAR (f, menu_bar_vector);
prefix = Qnil;
i = 0;
int previous_menu_items_used = f->menu_bar_items_used;
Lisp_Object *previous_items
= (Lisp_Object *) alloca (previous_menu_items_used
- * sizeof (Lisp_Object));
+ * word_size);
/* If we are making a new widget, its contents are empty,
do always reinitialize them. */
/* Save the frame's previous menu bar contents data. */
if (previous_menu_items_used)
memcpy (previous_items, XVECTOR (FVAR (f, menu_bar_vector))->contents,
- previous_menu_items_used * sizeof (Lisp_Object));
+ previous_menu_items_used * word_size);
/* Fill in menu_items with the current menu bar contents.
This can evaluate Lisp code. */
widget_value **submenu_stack
= (widget_value **) alloca (menu_items_used * sizeof (widget_value *));
Lisp_Object *subprefix_stack
- = (Lisp_Object *) alloca (menu_items_used * sizeof (Lisp_Object));
+ = (Lisp_Object *) alloca (menu_items_used * word_size);
int submenu_depth = 0;
int first_pane;
#define SCROLL_BAR_VEC_SIZE \
((sizeof (struct scroll_bar) \
- sizeof (EMACS_INT) - sizeof (struct Lisp_Vector *)) \
- / sizeof (Lisp_Object))
+ / word_size)
/* Turning a lisp vector value into a pointer to a struct scroll_bar. */
#define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
p = allocate_window ();
memcpy ((char *) p + sizeof (struct vectorlike_header),
(char *) o + sizeof (struct vectorlike_header),
- sizeof (Lisp_Object) * VECSIZE (struct window));
+ word_size * VECSIZE (struct window));
XSETWINDOW (parent, p);
p->sequence_number = ++sequence_number;
ptrdiff_t i;
ptrdiff_t count = SPECPDL_INDEX ();
struct gcpro gcpro1;
- Lisp_Object *args = alloca (nargs * sizeof (Lisp_Object));
+ Lisp_Object *args = alloca (nargs * word_size);
args[0] = func;
va_start (ap, func);
vec = Fvconcat (ndrivers, drivers);
nfonts = ASIZE (vec);
- qsort (XVECTOR (vec)->contents, nfonts, sizeof (Lisp_Object),
+ qsort (XVECTOR (vec)->contents, nfonts, word_size,
compare_fonts_by_sort_order);
result = Qnil;
}
memcpy (XVECTOR (copy)->contents, XVECTOR (lface)->contents,
- LFACE_VECTOR_SIZE * sizeof (Lisp_Object));
+ LFACE_VECTOR_SIZE * word_size);
/* Changing a named face means that all realized faces depending on
that face are invalid. Since we cannot tell which realized faces
continue;
}
if (memcmp (props, aref_addr (entity, FONT_FOUNDRY_INDEX),
- sizeof (Lisp_Object) * 7)
+ word_size * 7)
|| ! EQ (AREF (entity, FONT_SPACING_INDEX), props[7]))
{
memcpy (props, aref_addr (entity, FONT_FOUNDRY_INDEX),
- sizeof (Lisp_Object) * 7);
+ word_size * 7);
props[7] = AREF (entity, FONT_SPACING_INDEX);
scripts = xfont_supported_scripts (display, indices[i],
xfont_scratch_props, encoding);
/* Save the frame's previous menu bar contents data. */
if (previous_menu_items_used)
memcpy (previous_items, XVECTOR (FVAR (f, menu_bar_vector))->contents,
- previous_menu_items_used * sizeof (Lisp_Object));
+ previous_menu_items_used * word_size);
/* Fill in menu_items with the current menu bar contents.
This can evaluate Lisp code. */