Commit 74244d23 authored by Paul Eggert's avatar Paul Eggert
Browse files

Better isolate code that assumes NIL_IS_ZERO

Suggested by Stefan Monnier in:
http://lists.gnu.org/archive/html/emacs-devel/2015-01/msg00588.html
* alloc.c (allocate_pseudovector):
Use memclear, not memsetnil, to remove a 'verify'.
* callint.c (Fcall_interactively):
* dispnew.c (realloc_glyph_pool):
* xdisp.c (init_iterator):
Use memclear, not memset, to remove a 'verify'.
* lisp.h (memclear): Rename from memsetnil, and take a byte
count rather than a word count.  All callers changed.
parent 03346fb0
2015-01-22 Paul Eggert <eggert@cs.ucla.edu>
Isolate NIL_IS_ZERO-assuming code better
Suggested by Stefan Monnier in:
http://lists.gnu.org/archive/html/emacs-devel/2015-01/msg00588.html
* alloc.c (allocate_pseudovector):
Use memclear, not memsetnil, to remove a 'verify'.
* callint.c (Fcall_interactively):
* dispnew.c (realloc_glyph_pool):
* xdisp.c (init_iterator):
Use memclear, not memset, to remove a 'verify'.
* lisp.h (memclear): Rename from memsetnil, and take a byte
count rather than a word count. All callers changed.
2015-01-20 Paul Eggert <eggert@cs.ucla.edu> 2015-01-20 Paul Eggert <eggert@cs.ucla.edu>
   
Undo port to hypothetical nonzero Qnil case Undo port to hypothetical nonzero Qnil case
......
...@@ -3174,11 +3174,8 @@ allocate_pseudovector (int memlen, int lisplen, ...@@ -3174,11 +3174,8 @@ allocate_pseudovector (int memlen, int lisplen,
eassert (memlen - lisplen <= (1 << PSEUDOVECTOR_REST_BITS) - 1); eassert (memlen - lisplen <= (1 << PSEUDOVECTOR_REST_BITS) - 1);
eassert (lisplen <= (1 << PSEUDOVECTOR_SIZE_BITS) - 1); eassert (lisplen <= (1 << PSEUDOVECTOR_SIZE_BITS) - 1);
/* Only the first LISPLEN slots will be traced normally by the GC. /* Only the first LISPLEN slots will be traced normally by the GC. */
Since Qnil == 0, we can memset Lisp and non-Lisp data at one go. */ memclear (v->contents, zerolen * word_size);
verify (NIL_IS_ZERO);
memsetnil (v->contents, zerolen);
XSETPVECTYPESIZE (v, tag, lisplen, memlen - lisplen); XSETPVECTYPESIZE (v, tag, lisplen, memlen - lisplen);
return v; return v;
} }
......
...@@ -509,8 +509,7 @@ invoke it. If KEYS is omitted or nil, the return value of ...@@ -509,8 +509,7 @@ invoke it. If KEYS is omitted or nil, the return value of
visargs = args + nargs; visargs = args + nargs;
varies = (signed char *) (visargs + nargs); varies = (signed char *) (visargs + nargs);
verify (NIL_IS_ZERO); memclear (args, nargs * (2 * word_size + 1));
memset (args, 0, nargs * (2 * word_size + 1));
GCPRO5 (prefix_arg, function, *args, *visargs, up_event); GCPRO5 (prefix_arg, function, *args, *visargs, up_event);
gcpro3.nvars = nargs; gcpro3.nvars = nargs;
......
...@@ -11273,7 +11273,7 @@ internal character representation. */); ...@@ -11273,7 +11273,7 @@ internal character representation. */);
{ {
Lisp_Object args[coding_arg_undecided_max]; Lisp_Object args[coding_arg_undecided_max];
memsetnil (args, ARRAYELTS (args)); memclear (args, sizeof args);
Lisp_Object plist[16]; Lisp_Object plist[16];
plist[0] = intern_c_string (":name"); plist[0] = intern_c_string (":name");
......
...@@ -1339,13 +1339,7 @@ realloc_glyph_pool (struct glyph_pool *pool, struct dim matrix_dim) ...@@ -1339,13 +1339,7 @@ realloc_glyph_pool (struct glyph_pool *pool, struct dim matrix_dim)
ptrdiff_t old_nglyphs = pool->nglyphs; ptrdiff_t old_nglyphs = pool->nglyphs;
pool->glyphs = xpalloc (pool->glyphs, &pool->nglyphs, pool->glyphs = xpalloc (pool->glyphs, &pool->nglyphs,
needed - old_nglyphs, -1, sizeof *pool->glyphs); needed - old_nglyphs, -1, sizeof *pool->glyphs);
memclear (pool->glyphs + old_nglyphs,
/* Redisplay relies on nil as the object of special glyphs
(truncation and continuation glyphs and also blanks used to
extend each line on a TTY), so verify that memset does this. */
verify (NIL_IS_ZERO);
memset (pool->glyphs + old_nglyphs, 0,
(pool->nglyphs - old_nglyphs) * sizeof *pool->glyphs); (pool->nglyphs - old_nglyphs) * sizeof *pool->glyphs);
} }
......
...@@ -2299,7 +2299,8 @@ usage: (apply FUNCTION &rest ARGUMENTS) */) ...@@ -2299,7 +2299,8 @@ usage: (apply FUNCTION &rest ARGUMENTS) */)
/* Avoid making funcall cons up a yet another new vector of arguments /* Avoid making funcall cons up a yet another new vector of arguments
by explicitly supplying nil's for optional values. */ by explicitly supplying nil's for optional values. */
SAFE_ALLOCA_LISP (funcall_args, 1 + XSUBR (fun)->max_args); SAFE_ALLOCA_LISP (funcall_args, 1 + XSUBR (fun)->max_args);
memsetnil (funcall_args + numargs + 1, XSUBR (fun)->max_args - numargs); memclear (funcall_args + numargs + 1,
(XSUBR (fun)->max_args - numargs) * word_size);
funcall_nargs = 1 + XSUBR (fun)->max_args; funcall_nargs = 1 + XSUBR (fun)->max_args;
} }
else else
...@@ -2693,8 +2694,8 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */) ...@@ -2693,8 +2694,8 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */)
eassert (XSUBR (fun)->max_args <= ARRAYELTS (internal_argbuf)); eassert (XSUBR (fun)->max_args <= ARRAYELTS (internal_argbuf));
internal_args = internal_argbuf; internal_args = internal_argbuf;
memcpy (internal_args, args + 1, numargs * word_size); memcpy (internal_args, args + 1, numargs * word_size);
memsetnil (internal_args + numargs, memclear (internal_args + numargs,
XSUBR (fun)->max_args - numargs); (XSUBR (fun)->max_args - numargs) * word_size);
} }
else else
internal_args = args + 1; internal_args = args + 1;
......
...@@ -2524,7 +2524,7 @@ mapcar1 (EMACS_INT leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq) ...@@ -2524,7 +2524,7 @@ mapcar1 (EMACS_INT leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq)
if (vals) if (vals)
{ {
/* Don't let vals contain any garbage when GC happens. */ /* Don't let vals contain any garbage when GC happens. */
memsetnil (vals, leni); memclear (vals, leni * word_size);
GCPRO3 (dummy, fn, seq); GCPRO3 (dummy, fn, seq);
gcpro1.var = vals; gcpro1.var = vals;
...@@ -3700,7 +3700,7 @@ larger_vector (Lisp_Object vec, ptrdiff_t incr_min, ptrdiff_t nitems_max) ...@@ -3700,7 +3700,7 @@ larger_vector (Lisp_Object vec, ptrdiff_t incr_min, ptrdiff_t nitems_max)
new_size = old_size + incr; new_size = old_size + incr;
v = allocate_vector (new_size); v = allocate_vector (new_size);
memcpy (v->contents, XVECTOR (vec)->contents, old_size * sizeof *v->contents); memcpy (v->contents, XVECTOR (vec)->contents, old_size * sizeof *v->contents);
memsetnil (v->contents + old_size, new_size - old_size); memclear (v->contents + old_size, incr * word_size);
XSETVECTOR (vec, v); XSETVECTOR (vec, v);
return vec; return vec;
} }
......
...@@ -989,14 +989,14 @@ font_expand_wildcards (Lisp_Object *field, int n) ...@@ -989,14 +989,14 @@ font_expand_wildcards (Lisp_Object *field, int n)
if (i == 0 || ! NILP (tmp[i - 1])) if (i == 0 || ! NILP (tmp[i - 1]))
/* None of TMP[X] corresponds to Jth field. */ /* None of TMP[X] corresponds to Jth field. */
return -1; return -1;
memsetnil (field + j, range[i].from - j); memclear (field + j, (range[i].from - j) * word_size);
j = range[i].from; j = range[i].from;
} }
field[j++] = tmp[i]; field[j++] = tmp[i];
} }
if (! NILP (tmp[n - 1]) && j < XLFD_REGISTRY_INDEX) if (! NILP (tmp[n - 1]) && j < XLFD_REGISTRY_INDEX)
return -1; return -1;
memsetnil (field + j, XLFD_LAST_INDEX - j); memclear (field + j, (XLFD_LAST_INDEX - j) * word_size);
if (INTEGERP (field[XLFD_ENCODING_INDEX])) if (INTEGERP (field[XLFD_ENCODING_INDEX]))
field[XLFD_ENCODING_INDEX] field[XLFD_ENCODING_INDEX]
= Fintern (Fnumber_to_string (field[XLFD_ENCODING_INDEX]), Qnil); = Fintern (Fnumber_to_string (field[XLFD_ENCODING_INDEX]), Qnil);
......
...@@ -1508,13 +1508,15 @@ gc_aset (Lisp_Object array, ptrdiff_t idx, Lisp_Object val) ...@@ -1508,13 +1508,15 @@ gc_aset (Lisp_Object array, ptrdiff_t idx, Lisp_Object val)
to find such assumptions later if we change Qnil to be nonzero. */ to find such assumptions later if we change Qnil to be nonzero. */
enum { NIL_IS_ZERO = XLI_BUILTIN_LISPSYM (iQnil) == 0 }; enum { NIL_IS_ZERO = XLI_BUILTIN_LISPSYM (iQnil) == 0 };
/* Set a Lisp_Object array V's N entries to nil. */ /* Clear the object addressed by P, with size NBYTES, so that all its
bytes are zero and all its Lisp values are nil. */
INLINE void INLINE void
memsetnil (Lisp_Object *v, ptrdiff_t n) memclear (void *p, ptrdiff_t nbytes)
{ {
eassert (0 <= n); eassert (0 <= nbytes);
verify (NIL_IS_ZERO); verify (NIL_IS_ZERO);
memset (v, 0, n * sizeof *v); /* Since Qnil is zero, memset suffices. */
memset (p, 0, nbytes);
} }
/* If a struct is made to look like a vector, this macro returns the length /* If a struct is made to look like a vector, this macro returns the length
......
...@@ -2746,13 +2746,7 @@ init_iterator (struct it *it, struct window *w, ...@@ -2746,13 +2746,7 @@ init_iterator (struct it *it, struct window *w,
row = MATRIX_HEADER_LINE_ROW (w->desired_matrix); row = MATRIX_HEADER_LINE_ROW (w->desired_matrix);
} }
   
/* Clear IT. */ memclear (it, sizeof *it);
/* The code assumes it->object and other Lisp_Object components are
set to nil, so verify that memset does this. */
verify (NIL_IS_ZERO);
memset (it, 0, sizeof *it);
it->current.overlay_string_index = -1; it->current.overlay_string_index = -1;
it->current.dpvec_index = -1; it->current.dpvec_index = -1;
it->base_face_id = remapped_base_face_id; it->base_face_id = remapped_base_face_id;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment