* lisp.h (vcopy): New function to copy data into vector.
* dispnew.c (Fframe_or_buffer_changed_p): Use AREF and ASET.
* fns.c (Ffillarray): Use ASET.
* keyboard.c (timer_check_2): Use AREF and ASET.
(append_tool_bar_item, Frecent_keys): Use vcopy.
* lread.c (read_vector): Use ASET.
* msdos.c (Frecent_doskeys): Use vcopy.
* xface.c (Finternal_copy_lisp_face): Use vcopy.
(Finternal_merge_in_global_face): Use ASET and vcopy.
* xfont.c (xfont_list_pattern): Likewise.
+2012-08-21 Dmitry Antipov <dmantipov@yandex.ru>
+
+ Avoid direct writes to contents member of struct Lisp_Vector.
+ * lisp.h (vcopy): New function to copy data into vector.
+ * dispnew.c (Fframe_or_buffer_changed_p): Use AREF and ASET.
+ * fns.c (Ffillarray): Use ASET.
+ * keyboard.c (timer_check_2): Use AREF and ASET.
+ (append_tool_bar_item, Frecent_keys): Use vcopy.
+ * lread.c (read_vector): Use ASET.
+ * msdos.c (Frecent_doskeys): Use vcopy.
+ * xface.c (Finternal_copy_lisp_face): Use vcopy.
+ (Finternal_merge_in_global_face): Use ASET and vcopy.
+ * xfont.c (xfont_list_pattern): Likewise.
+
2012-08-21 Martin Rudalics <rudalics@gmx.at>
* window.c (Fwindow_point): For the selected window always return
(Lisp_Object variable)
{
Lisp_Object state, tail, frame, buf;
- Lisp_Object *vecp, *end;
- ptrdiff_t n;
+ ptrdiff_t n, idx;
if (! NILP (variable))
{
else
state = frame_and_buffer_state;
- vecp = XVECTOR (state)->contents;
- end = vecp + ASIZE (state);
-
+ idx = 0;
FOR_EACH_FRAME (tail, frame)
{
- if (vecp == end)
+ if (idx == ASIZE (state))
goto changed;
- if (!EQ (*vecp++, frame))
+ if (!EQ (AREF (state, idx++), frame))
goto changed;
- if (vecp == end)
+ if (idx == ASIZE (state))
goto changed;
- if (!EQ (*vecp++, XFRAME (frame)->name))
+ if (!EQ (AREF (state, idx++), XFRAME (frame)->name))
goto changed;
}
/* Check that the buffer info matches. */
/* Ignore buffers that aren't included in buffer lists. */
if (SREF (BVAR (XBUFFER (buf), name), 0) == ' ')
continue;
- if (vecp == end)
+ if (idx == ASIZE (state))
goto changed;
- if (!EQ (*vecp++, buf))
+ if (!EQ (AREF (state, idx++), buf))
goto changed;
- if (vecp == end)
+ if (idx == ASIZE (state))
goto changed;
- if (!EQ (*vecp++, BVAR (XBUFFER (buf), read_only)))
+ if (!EQ (AREF (state, idx++), BVAR (XBUFFER (buf), read_only)))
goto changed;
- if (vecp == end)
+ if (idx == ASIZE (state))
goto changed;
- if (!EQ (*vecp++, Fbuffer_modified_p (buf)))
+ if (!EQ (AREF (state, idx++), Fbuffer_modified_p (buf)))
goto changed;
}
- if (vecp == end)
+ if (idx == ASIZE (state))
goto changed;
/* Detect deletion of a buffer at the end of the list. */
- if (EQ (*vecp, Qlambda))
+ if (EQ (AREF (state, idx), Qlambda))
return Qnil;
/* Come here if we decide the data has changed. */
}
/* Record the new data in the (possibly reallocated) vector. */
- vecp = XVECTOR (state)->contents;
+ idx = 0;
FOR_EACH_FRAME (tail, frame)
{
- *vecp++ = frame;
- *vecp++ = XFRAME (frame)->name;
+ ASET (state, idx, frame);
+ idx++;
+ ASET (state, idx, XFRAME (frame)->name);
+ idx++;
}
for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
{
/* Ignore buffers that aren't included in buffer lists. */
if (SREF (BVAR (XBUFFER (buf), name), 0) == ' ')
continue;
- *vecp++ = buf;
- *vecp++ = BVAR (XBUFFER (buf), read_only);
- *vecp++ = Fbuffer_modified_p (buf);
+ ASET (state, idx, buf);
+ idx++;
+ ASET (state, idx, BVAR (XBUFFER (buf), read_only));
+ idx++;
+ ASET (state, idx, Fbuffer_modified_p (buf));
+ idx++;
}
/* Fill up the vector with lambdas (always at least one). */
- *vecp++ = Qlambda;
- while (vecp - XVECTOR (state)->contents
- < ASIZE (state))
- *vecp++ = Qlambda;
+ ASET (state, idx, Qlambda);
+ idx++;
+ while (idx < ASIZE (state))
+ {
+ ASET (state, idx, Qlambda);
+ idx++;
+ }
/* Make sure we didn't overflow the vector. */
- if (vecp - XVECTOR (state)->contents
- > ASIZE (state))
- abort ();
+ eassert (idx <= ASIZE (state));
return Qt;
}
register ptrdiff_t size, idx;
if (VECTORP (array))
- {
- register Lisp_Object *p = XVECTOR (array)->contents;
- size = ASIZE (array);
- for (idx = 0; idx < size; idx++)
- p[idx] = item;
- }
+ for (idx = 0, size = ASIZE (array); idx < size; idx++)
+ ASET (array, idx, item);
else if (CHAR_TABLE_P (array))
{
int i;
while (CONSP (timers) || CONSP (idle_timers))
{
- Lisp_Object *vector;
Lisp_Object timer = Qnil, idle_timer = Qnil;
EMACS_TIME timer_time, idle_timer_time;
EMACS_TIME difference;
/* If timer is ripe, run it if it hasn't been run. */
if (ripe)
{
- vector = XVECTOR (chosen_timer)->contents;
- if (NILP (vector[0]))
+ if (NILP (AREF (chosen_timer, 0)))
{
ptrdiff_t count = SPECPDL_INDEX ();
Lisp_Object old_deactivate_mark = Vdeactivate_mark;
/* Mark the timer as triggered to prevent problems if the lisp
code fails to reschedule it right. */
- vector[0] = Qt;
+ ASET (chosen_timer, 0, Qt);
specbind (Qinhibit_quit, Qt);
static void
append_tool_bar_item (void)
{
- Lisp_Object *to, *from;
ptrdiff_t incr =
(ntool_bar_items
- (ASIZE (tool_bar_items_vector) - TOOL_BAR_ITEM_NSLOTS));
/* Append entries from tool_bar_item_properties to the end of
tool_bar_items_vector. */
- to = XVECTOR (tool_bar_items_vector)->contents + ntool_bar_items;
- from = XVECTOR (tool_bar_item_properties)->contents;
- memcpy (to, from, TOOL_BAR_ITEM_NSLOTS * sizeof *to);
+ vcopy (tool_bar_items_vector, ntool_bar_items,
+ XVECTOR (tool_bar_item_properties)->contents, TOOL_BAR_ITEM_NSLOTS);
ntool_bar_items += TOOL_BAR_ITEM_NSLOTS;
}
else
{
val = Fvector (NUM_RECENT_KEYS, keys);
- memcpy (XVECTOR (val)->contents, keys + recent_keys_index,
- (NUM_RECENT_KEYS - recent_keys_index) * word_size);
- memcpy (XVECTOR (val)->contents + NUM_RECENT_KEYS - recent_keys_index,
- keys, recent_keys_index * word_size);
+ vcopy (val, 0, keys + recent_keys_index,
+ NUM_RECENT_KEYS - recent_keys_index);
+ vcopy (val, NUM_RECENT_KEYS - recent_keys_index,
+ keys, recent_keys_index);
return val;
}
}
XVECTOR (array)->contents[idx] = val;
}
+/* Copy COUNT Lisp_Objects from ARGS to contents of V starting from OFFSET. */
+
+LISP_INLINE void
+vcopy (Lisp_Object v, ptrdiff_t offset, Lisp_Object *args, ptrdiff_t count)
+{
+ ptrdiff_t i;
+
+ eassert (offset + count <= ASIZE (v));
+ for (i = 0; i < count; i++)
+ ASET (v, offset + i, args[i]);
+}
+
+/* Functions to modify hash tables. */
+
LISP_INLINE void
set_hash_key_and_value (struct Lisp_Hash_Table *h, Lisp_Object key_and_value)
{
/* Delay handling the bytecode slot until we know whether
it is lazily-loaded (we can tell by whether the
constants slot is nil). */
- ptr[COMPILED_CONSTANTS] = item;
+ ASET (vector, COMPILED_CONSTANTS, item);
item = Qnil;
}
else if (i == COMPILED_CONSTANTS)
}
/* Now handle the bytecode slot. */
- ptr[COMPILED_BYTECODE] = bytestr;
+ ASET (vector, COMPILED_BYTECODE, bytestr);
}
else if (i == COMPILED_DOC_STRING
&& STRINGP (item)
item = Fstring_as_multibyte (item);
}
}
- ptr[i] = item;
+ ASET (vector, i, item);
otem = XCONS (tem);
tem = Fcdr (tem);
free_cons (otem);
else
{
val = Fvector (NUM_RECENT_DOSKEYS, keys);
- memcpy (XVECTOR (val)->contents, keys + recent_doskeys_index,
- (NUM_RECENT_DOSKEYS - recent_doskeys_index) * word_size);
- memcpy (XVECTOR (val)->contents + NUM_RECENT_DOSKEYS - recent_doskeys_index,
- keys, recent_doskeys_index * word_size);
+ vcopy (val, 0, keys + recent_doskeys_index,
+ NUM_RECENT_DOSKEYS - recent_doskeys_index);
+ vcopy (val, NUM_RECENT_DOSKEYS - recent_doskeys_index,
+ keys, recent_doskeys_index);
return val;
}
}
copy = Finternal_make_lisp_face (to, new_frame);
}
- memcpy (XVECTOR (copy)->contents, XVECTOR (lface)->contents,
- LFACE_VECTOR_SIZE * word_size);
+ vcopy (copy, 0, XVECTOR (lface)->contents, LFACE_VECTOR_SIZE);
/* Changing a named face means that all realized faces depending on
that face are invalid. Since we cannot tell which realized faces
gvec = XVECTOR (global_lface)->contents;
for (i = 1; i < LFACE_VECTOR_SIZE; ++i)
if (IGNORE_DEFFACE_P (gvec[i]))
- lvec[i] = Qunspecified;
+ ASET (local_lface, i, Qunspecified);
else if (! UNSPECIFIEDP (gvec[i]))
- lvec[i] = gvec[i];
+ ASET (local_lface, i, AREF (global_lface, i));
/* If the default face was changed, update the face cache and the
`font' frame parameter. */
the previously-cached vector. */
memcpy (attrs, oldface->lface, sizeof attrs);
merge_face_vectors (f, lvec, attrs, 0);
- memcpy (lvec, attrs, sizeof attrs);
+ vcopy (local_lface, 0, attrs, LFACE_VECTOR_SIZE);
newface = realize_face (c, lvec, DEFAULT_FACE_ID);
if ((! UNSPECIFIEDP (gvec[LFACE_FAMILY_INDEX])
Lisp_Object scripts = Qnil;
for (i = 0; i < ASIZE (xfont_scratch_props); i++)
- props[i] = Qnil;
+ ASET (xfont_scratch_props, i, Qnil);
for (i = 0; i < num_fonts; i++)
indices[i] = names[i];
qsort (indices, num_fonts, sizeof (char *), compare_font_names);
word_size * 7)
|| ! EQ (AREF (entity, FONT_SPACING_INDEX), props[7]))
{
- memcpy (props, aref_addr (entity, FONT_FOUNDRY_INDEX),
- word_size * 7);
- props[7] = AREF (entity, FONT_SPACING_INDEX);
+ vcopy (xfont_scratch_props, 0,
+ aref_addr (entity, FONT_FOUNDRY_INDEX), 7);
+ ASET (xfont_scratch_props, 7, AREF (entity, FONT_SPACING_INDEX));
scripts = xfont_supported_scripts (display, indices[i],
xfont_scratch_props, encoding);
}