+2012-07-05 Paul Eggert <eggert@cs.ucla.edu>
+
+ More xmalloc and related cleanup.
+ * alloc.c, bidi.c, buffer.c, buffer.h, bytecode.c, callint.c:
+ * callproc.c, charset.c, coding.c, composite.c, data.c, dispnew.c:
+ * doc.c, editfns.c, emacs.c, eval.c, fileio.c, filelock.c, fns.c:
+ * font.c, fontset.c, frame.c, fringe.c, ftfont.c, ftxfont.c, gmalloc.c:
+ * gtkutil.c, image.c, keyboard.c, keymap.c, lread.c, macros.c, menu.c:
+ * nsfns.m, nsfont.m, nsmenu.m, nsterm.m, print.c, process.c, ralloc.c:
+ * regex.c, region-cache.c, scroll.c, search.c, sound.c, syntax.c:
+ * sysdep.c, term.c, termcap.c, unexmacosx.c, window.c, xdisp.c:
+ * xfaces.c, xfns.c, xftfont.c, xgselect.c, xmenu.c, xrdb.c, xselect.c:
+ * xterm.c:
+ Omit needless casts involving void * pointers and allocation.
+ Prefer "P = xmalloc (sizeof *P)" to "P = xmalloc (sizeof (TYPE_OF_P))",
+ as the former is more robust if P's type is changed.
+ Prefer xzalloc to xmalloc + memset 0.
+ Simplify malloc-or-realloc to realloc.
+ Don't worry about xmalloc returning a null pointer.
+ Prefer xstrdup to xmalloc + strcpy.
+ * editfns.c (Fmessage_box): Grow message_text by at least 80 when
+ growing it.
+ * keyboard.c (apply_modifiers_uncached): Prefer local array to
+ alloca of a constant.
+
2012-07-05 Eli Zaretskii <eliz@gnu.org>
* xdisp.c (display_line): Fix horizontal pixel coordinates when
if (SIZE_MAX - overhead < size)
abort ();
- val = (unsigned char *) malloc (size + overhead);
+ val = malloc (size + overhead);
if (val && check_depth == 1)
{
memcpy (val, xmalloc_overrun_check_header, XMALLOC_OVERRUN_CHECK_SIZE);
allocated_mem_type = type;
#endif
- val = (void *) malloc (nbytes);
+ val = malloc (nbytes);
#if ! USE_LSB_TAG
/* If the memory just allocated cannot be addressed thru a Lisp
__malloc_extra_blocks = malloc_hysteresis;
#endif
- value = (void *) malloc (size);
+ value = malloc (size);
#ifdef GC_MALLOC_CHECK
{
dont_register_blocks = 1;
#endif /* GC_MALLOC_CHECK */
- value = (void *) realloc (ptr, size);
+ value = realloc (ptr, size);
#ifdef GC_MALLOC_CHECK
dont_register_blocks = 0;
{
if (interval_block_index == INTERVAL_BLOCK_SIZE)
{
- register struct interval_block *newi;
-
- newi = (struct interval_block *) lisp_malloc (sizeof *newi,
- MEM_TYPE_NON_LISP);
+ struct interval_block *newi
+ = lisp_malloc (sizeof *newi, MEM_TYPE_NON_LISP);
newi->next = interval_block;
interval_block = newi;
add all the Lisp_Strings in it to the free-list. */
if (string_free_list == NULL)
{
- struct string_block *b;
+ struct string_block *b = lisp_malloc (sizeof *b, MEM_TYPE_STRING);
int i;
- b = (struct string_block *) lisp_malloc (sizeof *b, MEM_TYPE_STRING);
b->next = string_blocks;
string_blocks = b;
mallopt (M_MMAP_MAX, 0);
#endif
- b = (struct sblock *) lisp_malloc (size + GC_STRING_EXTRA, MEM_TYPE_NON_LISP);
+ b = lisp_malloc (size + GC_STRING_EXTRA, MEM_TYPE_NON_LISP);
#ifdef DOUG_LEA_MALLOC
/* Back to a reasonable maximum of mmap'ed areas. */
< (needed + GC_STRING_EXTRA)))
{
/* Not enough room in the current sblock. */
- b = (struct sblock *) lisp_malloc (SBLOCK_SIZE, MEM_TYPE_NON_LISP);
+ b = lisp_malloc (SBLOCK_SIZE, MEM_TYPE_NON_LISP);
b->next_free = &b->first_data;
b->first_data.string = NULL;
b->next = NULL;
{
if (float_block_index == FLOAT_BLOCK_SIZE)
{
- register struct float_block *new;
-
- new = (struct float_block *) lisp_align_malloc (sizeof *new,
- MEM_TYPE_FLOAT);
+ struct float_block *new
+ = lisp_align_malloc (sizeof *new, MEM_TYPE_FLOAT);
new->next = float_block;
memset (new->gcmarkbits, 0, sizeof new->gcmarkbits);
float_block = new;
{
if (cons_block_index == CONS_BLOCK_SIZE)
{
- register struct cons_block *new;
- new = (struct cons_block *) lisp_align_malloc (sizeof *new,
- MEM_TYPE_CONS);
+ struct cons_block *new
+ = lisp_align_malloc (sizeof *new, MEM_TYPE_CONS);
memset (new->gcmarkbits, 0, sizeof new->gcmarkbits);
new->next = cons_block;
cons_block = new;
static struct vector_block *
allocate_vector_block (void)
{
- struct vector_block *block = xmalloc (sizeof (struct vector_block));
+ struct vector_block *block = xmalloc (sizeof *block);
#if GC_MARK_STACK && !defined GC_MALLOC_CHECK
mem_insert (block->data, block->data + VECTOR_BLOCK_BYTES,
p = allocate_vector_from_block (vroundup (nbytes));
else
{
- p = (struct Lisp_Vector *) lisp_malloc (nbytes, MEM_TYPE_VECTORLIKE);
+ p = lisp_malloc (nbytes, MEM_TYPE_VECTORLIKE);
p->header.next.vector = large_vectors;
large_vectors = p;
}
struct buffer *
allocate_buffer (void)
{
- struct buffer *b = lisp_malloc (sizeof (struct buffer), MEM_TYPE_BUFFER);
+ struct buffer *b = lisp_malloc (sizeof *b, MEM_TYPE_BUFFER);
XSETPVECTYPESIZE (b, PVEC_BUFFER, (offsetof (struct buffer, own_text)
- header_size) / word_size);
{
if (symbol_block_index == SYMBOL_BLOCK_SIZE)
{
- struct symbol_block *new;
- new = (struct symbol_block *) lisp_malloc (sizeof *new,
- MEM_TYPE_SYMBOL);
+ struct symbol_block *new
+ = lisp_malloc (sizeof *new, MEM_TYPE_SYMBOL);
new->next = symbol_block;
symbol_block = new;
symbol_block_index = 0;
{
if (marker_block_index == MARKER_BLOCK_SIZE)
{
- struct marker_block *new;
- new = (struct marker_block *) lisp_malloc (sizeof *new,
- MEM_TYPE_MISC);
+ struct marker_block *new = lisp_malloc (sizeof *new, MEM_TYPE_MISC);
new->next = marker_block;
marker_block = new;
marker_block_index = 0;
{
#ifndef SYSTEM_MALLOC
if (spare_memory[0] == 0)
- spare_memory[0] = (char *) malloc (SPARE_MEMORY);
+ spare_memory[0] = malloc (SPARE_MEMORY);
if (spare_memory[1] == 0)
- spare_memory[1] = (char *) lisp_align_malloc (sizeof (struct cons_block),
+ spare_memory[1] = lisp_align_malloc (sizeof (struct cons_block),
MEM_TYPE_CONS);
if (spare_memory[2] == 0)
- spare_memory[2] = (char *) lisp_align_malloc (sizeof (struct cons_block),
- MEM_TYPE_CONS);
+ spare_memory[2] = lisp_align_malloc (sizeof (struct cons_block),
+ MEM_TYPE_CONS);
if (spare_memory[3] == 0)
- spare_memory[3] = (char *) lisp_align_malloc (sizeof (struct cons_block),
- MEM_TYPE_CONS);
+ spare_memory[3] = lisp_align_malloc (sizeof (struct cons_block),
+ MEM_TYPE_CONS);
if (spare_memory[4] == 0)
- spare_memory[4] = (char *) lisp_align_malloc (sizeof (struct cons_block),
- MEM_TYPE_CONS);
+ spare_memory[4] = lisp_align_malloc (sizeof (struct cons_block),
+ MEM_TYPE_CONS);
if (spare_memory[5] == 0)
- spare_memory[5] = (char *) lisp_malloc (sizeof (struct string_block),
- MEM_TYPE_STRING);
+ spare_memory[5] = lisp_malloc (sizeof (struct string_block),
+ MEM_TYPE_STRING);
if (spare_memory[6] == 0)
- spare_memory[6] = (char *) lisp_malloc (sizeof (struct string_block),
- MEM_TYPE_STRING);
+ spare_memory[6] = lisp_malloc (sizeof (struct string_block),
+ MEM_TYPE_STRING);
if (spare_memory[0] && spare_memory[1] && spare_memory[5])
Vmemory_full = Qnil;
#endif
/* Create a new node. */
#ifdef GC_MALLOC_CHECK
- x = (struct mem_node *) _malloc_internal (sizeof *x);
+ x = _malloc_internal (sizeof *x);
if (x == NULL)
abort ();
#else
{
if (stack_copy_size < stack_size)
{
- stack_copy = (char *) xrealloc (stack_copy, stack_size);
+ stack_copy = xrealloc (stack_copy, stack_size);
stack_copy_size = stack_size;
}
memcpy (stack_copy, stack, stack_size);
{
if (bidi_cache_size > BIDI_CACHE_CHUNK)
{
- bidi_cache
- = (struct bidi_it *) xrealloc (bidi_cache, BIDI_CACHE_CHUNK * elsz);
+ bidi_cache = xrealloc (bidi_cache, BIDI_CACHE_CHUNK * elsz);
bidi_cache_size = BIDI_CACHE_CHUNK;
}
bidi_cache_reset ();
Lisp_Object *v, tem;
size = 10;
- v = (Lisp_Object *) alloca (size * sizeof *v);
+ v = alloca (size * sizeof *v);
n = overlays_in (start, end, 0, &v, &size, NULL, NULL);
if (n > size)
{
- v = (Lisp_Object *) alloca (n * sizeof *v);
+ v = alloca (n * sizeof *v);
overlays_in (start, end, 0, &v, &n, NULL, NULL);
}
sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w)
{
ptrdiff_t i, j;
- struct sortvec *sortvec;
- sortvec = (struct sortvec *) alloca (noverlays * sizeof (struct sortvec));
+ struct sortvec *sortvec = alloca (noverlays * sizeof *sortvec);
/* Put the valid and relevant overlays into sortvec. */
len = 10;
/* We can't use alloca here because overlays_at can call xrealloc. */
- overlay_vec = xmalloc (len * sizeof (Lisp_Object));
+ overlay_vec = xmalloc (len * sizeof *overlay_vec);
/* Put all the overlays we want in a vector in overlay_vec.
Store the length in len. */
CHECK_NUMBER_COERCE_MARKER (end);
len = 10;
- overlay_vec = xmalloc (len * sizeof (Lisp_Object));
+ overlay_vec = xmalloc (len * sizeof *overlay_vec);
/* Put all the overlays we want in a vector in overlay_vec.
Store the length in len. */
CHECK_NUMBER_COERCE_MARKER (pos);
len = 10;
- overlay_vec = xmalloc (len * sizeof (Lisp_Object));
+ overlay_vec = xmalloc (len * sizeof *overlay_vec);
/* Put all the overlays we want in a vector in overlay_vec.
Store the length in len.
return pos;
len = 10;
- overlay_vec = xmalloc (len * sizeof (Lisp_Object));
+ overlay_vec = xmalloc (len * sizeof *overlay_vec);
/* Put all the overlays we want in a vector in overlay_vec.
Store the length in len.
First copy the vector contents, in case some of these hooks
do subsequent modification of the buffer. */
ptrdiff_t size = last_overlay_modification_hooks_used;
- Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object));
+ Lisp_Object *copy = alloca (size * sizeof *copy);
ptrdiff_t i;
memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents,
/* If you add, remove, or reorder Lisp_Objects in a struct buffer, make
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
+ const int pvecsize
= (offsetof (struct buffer, own_text) - sizeof (struct vectorlike_header))
/ sizeof (Lisp_Object);
if (!(IS_DIRECTORY_SEP (pwd[len - 1])))
{
/* Grow buffer to add directory separator and '\0'. */
- pwd = (char *) realloc (pwd, len + 2);
+ pwd = realloc (pwd, len + 2);
if (!pwd)
fatal ("`get_current_dir_name' failed: %s\n", strerror (errno));
pwd[len] = DIRECTORY_SEP;
#define GET_OVERLAYS_AT(posn, overlays, noverlays, nextp, chrq) \
do { \
ptrdiff_t maxlen = 40; \
- overlays = (Lisp_Object *) alloca (maxlen * sizeof (Lisp_Object)); \
+ overlays = alloca (maxlen * sizeof *overlays); \
noverlays = overlays_at (posn, 0, &overlays, &maxlen, \
nextp, NULL, chrq); \
if (noverlays > maxlen) \
{ \
maxlen = noverlays; \
- overlays = (Lisp_Object *) alloca (maxlen * sizeof (Lisp_Object)); \
+ overlays = alloca (maxlen * sizeof *overlays); \
noverlays = overlays_at (posn, 0, &overlays, &maxlen, \
nextp, NULL, chrq); \
} \
stack.constants = vector;
if (MAX_ALLOCA / sizeof (Lisp_Object) <= XFASTINT (maxdepth))
memory_full (SIZE_MAX);
- top = (Lisp_Object *) alloca ((XFASTINT (maxdepth) + 1)
- * sizeof (Lisp_Object));
+ top = alloca ((XFASTINT (maxdepth) + 1) * sizeof *top);
#if BYTE_MAINTAIN_TOP
stack.bottom = top + 1;
stack.top = NULL;
{
/* Make a copy of string so that if a GC relocates specs,
`string' will still be valid. */
- string = (char *) alloca (SBYTES (specs) + 1);
+ string = alloca (SBYTES (specs) + 1);
memcpy (string, SSDATA (specs), SBYTES (specs) + 1);
}
else
< nargs)
memory_full (SIZE_MAX);
- args = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object));
- visargs = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object));
- varies = (signed char *) alloca (nargs);
+ args = alloca (nargs * sizeof *args);
+ visargs = alloca (nargs * sizeof *visargs);
+ varies = alloca (nargs * sizeof *varies);
for (i = 0; i < nargs; i++)
{
on that. */
pwd_var = xmalloc (i + 6);
#else
- pwd_var = (char *) alloca (i + 6);
+ pwd_var = alloca (i + 6);
#endif
temp = pwd_var + 4;
memcpy (pwd_var, "PWD=", 4);
}
/* new_length + 2 to include PWD and terminating 0. */
- env = new_env = (char **) alloca ((new_length + 2) * sizeof (char *));
+ env = new_env = alloca ((new_length + 2) * sizeof *env);
/* If we have a PWD envvar, pass one down,
but with corrected value. */
if (egetenv ("PWD"))
if (STRINGP (display))
{
- char *vdata = (char *) alloca (sizeof "DISPLAY=" + SBYTES (display));
+ char *vdata = alloca (sizeof "DISPLAY=" + SBYTES (display));
strcpy (vdata, "DISPLAY=");
strcat (vdata, SSDATA (display));
new_env = add_env (env, new_env, vdata);
else
{
if (! temp_charset_work)
- temp_charset_work = xmalloc (sizeof (*temp_charset_work));
+ temp_charset_work = xmalloc (sizeof *temp_charset_work);
if (control_flag == 1)
{
memset (temp_charset_work->table.decoder, -1,
{
if (STRING_BYTES_BOUND - coding->dst_bytes < bytes)
string_overflow ();
- coding->destination = (unsigned char *) xrealloc (coding->destination,
- coding->dst_bytes + bytes);
+ coding->destination = xrealloc (coding->destination,
+ coding->dst_bytes + bytes);
coding->dst_bytes += bytes;
}
coding->charbuf = NULL; \
while (size > 1024) \
{ \
- coding->charbuf = (int *) alloca (sizeof (int) * size); \
+ coding->charbuf = alloca (sizeof (int) * size); \
if (coding->charbuf) \
break; \
size >>= 1; \
{
Lisp_Object subsidiaries;
ptrdiff_t base_name_len = SBYTES (SYMBOL_NAME (base));
- char *buf = (char *) alloca (base_name_len + 6);
+ char *buf = alloca (base_name_len + 6);
int i;
memcpy (buf, SDATA (SYMBOL_NAME (base)), base_name_len);
memory_full (SIZE_MAX);
/* Register the composition in composition_table. */
- cmp = xmalloc (sizeof (struct composition));
+ cmp = xmalloc (sizeof *cmp);
cmp->method = method;
cmp->hash_index = hash_index;
static struct Lisp_Buffer_Local_Value *
make_blv (struct Lisp_Symbol *sym, int forwarded, union Lisp_Val_Fwd valcontents)
{
- struct Lisp_Buffer_Local_Value *blv
- = xmalloc (sizeof (struct Lisp_Buffer_Local_Value));
+ struct Lisp_Buffer_Local_Value *blv = xmalloc (sizeof *blv);
Lisp_Object symbol;
Lisp_Object tem;
save_current_matrix (struct frame *f)
{
int i;
- struct glyph_matrix *saved;
-
- saved = xzalloc (sizeof *saved);
+ struct glyph_matrix *saved = xzalloc (sizeof *saved);
saved->nrows = f->current_matrix->nrows;
saved->rows = xzalloc (saved->nrows * sizeof *saved->rows);
static void
adjust_frame_message_buffer (struct frame *f)
{
- ptrdiff_t size = FRAME_MESSAGE_BUF_SIZE (f) + 1;
-
- if (FRAME_MESSAGE_BUF (f))
- {
- char *buffer = FRAME_MESSAGE_BUF (f);
- char *new_buffer = (char *) xrealloc (buffer, size);
- FRAME_MESSAGE_BUF (f) = new_buffer;
- }
- else
- FRAME_MESSAGE_BUF (f) = xmalloc (size);
+ FRAME_MESSAGE_BUF (f) = xrealloc (FRAME_MESSAGE_BUF (f),
+ FRAME_MESSAGE_BUF_SIZE (f) + 1);
}
static void
adjust_decode_mode_spec_buffer (struct frame *f)
{
- f->decode_mode_spec_buffer
- = (char *) xrealloc (f->decode_mode_spec_buffer,
- FRAME_MESSAGE_BUF_SIZE (f) + 1);
+ f->decode_mode_spec_buffer = xrealloc (f->decode_mode_spec_buffer,
+ FRAME_MESSAGE_BUF_SIZE (f) + 1);
}
int i;
/* Make a copy of the original rows. */
- old_rows = (struct glyph_row *) alloca (nlines * sizeof *old_rows);
+ old_rows = alloca (nlines * sizeof *old_rows);
memcpy (old_rows, new_rows, nlines * sizeof *old_rows);
/* Assign new rows, maybe clear lines. */
struct glyph_row *old_rows;
/* Make a copy of the original rows of matrix m. */
- old_rows = (struct glyph_row *) alloca (m->nrows * sizeof *old_rows);
+ old_rows = alloca (m->nrows * sizeof *old_rows);
memcpy (old_rows, m->rows, m->nrows * sizeof *old_rows);
for (i = 0; i < nlines; ++i)
int unchanged_at_top, unchanged_at_bottom;
int window_size;
int changed_lines;
- int *old_hash = (int *) alloca (FRAME_LINES (frame) * sizeof (int));
- int *new_hash = (int *) alloca (FRAME_LINES (frame) * sizeof (int));
- int *draw_cost = (int *) alloca (FRAME_LINES (frame) * sizeof (int));
- int *old_draw_cost = (int *) alloca (FRAME_LINES (frame) * sizeof (int));
+ int *old_hash = alloca (FRAME_LINES (frame) * sizeof (int));
+ int *new_hash = alloca (FRAME_LINES (frame) * sizeof (int));
+ int *draw_cost = alloca (FRAME_LINES (frame) * sizeof (int));
+ int *old_draw_cost = alloca (FRAME_LINES (frame) * sizeof (int));
register int i;
int free_at_end_vpos = FRAME_LINES (frame);
struct glyph_matrix *current_matrix = frame->current_matrix;
(0)
#endif /* CANNOT_DUMP */
{
- name = (char *) alloca (SCHARS (filename) + 14);
+ name = alloca (SCHARS (filename) + 14);
strcpy (name, "../etc/");
}
else
{
CHECK_STRING (Vdoc_directory);
- name = (char *) alloca (SCHARS (filename)
- + SCHARS (Vdoc_directory) + 1);
+ name = alloca (SCHARS (filename) + SCHARS (Vdoc_directory) + 1);
strcpy (name, SSDATA (Vdoc_directory));
}
strcat (name, SSDATA (filename)); /*** Add this line ***/
ptrdiff_t offset = bufp - buf;
if (STRING_BYTES_BOUND - 4 < bsize)
string_overflow ();
- buf = (char *) xrealloc (buf, bsize += 4);
+ buf = xrealloc (buf, bsize += 4);
bufp = buf + offset;
memcpy (bufp, "M-x ", 4);
bufp += 4;
ptrdiff_t offset = bufp - buf;
if (STRING_BYTES_BOUND - length_byte < bsize)
string_overflow ();
- buf = (char *) xrealloc (buf, bsize += length_byte);
+ buf = xrealloc (buf, bsize += length_byte);
bufp = buf + offset;
memcpy (bufp, start, length_byte);
bufp += length_byte;
/* First try with room for 40 overlays. */
noverlays = 40;
- overlay_vec = (Lisp_Object *) alloca (noverlays * sizeof (Lisp_Object));
+ overlay_vec = alloca (noverlays * sizeof *overlay_vec);
noverlays = overlays_around (posn, overlay_vec, noverlays);
/* If there are more than 40,
make enough space for all, and try again. */
if (noverlays > 40)
{
- overlay_vec = (Lisp_Object *) alloca (noverlays * sizeof (Lisp_Object));
+ overlay_vec = alloca (noverlays * sizeof *overlay_vec);
noverlays = overlays_around (posn, overlay_vec, noverlays);
}
noverlays = sort_overlays (overlay_vec, noverlays, NULL);
Lisp_Object login;
login = Fuser_login_name (make_number (pw->pw_uid));
- r = (char *) alloca (strlen (p) + SCHARS (login) + 1);
+ r = alloca (strlen (p) + SCHARS (login) + 1);
memcpy (r, p, q - p);
r[q - p] = 0;
strcat (r, SSDATA (login));
for (from = environ; *from; from++)
continue;
envptrs = from - environ + 2;
- newenv = to = xmalloc (envptrs * sizeof (char *)
+ newenv = to = xmalloc (envptrs * sizeof *newenv
+ (tzstring ? strlen (tzstring) + 4 : 0));
/* Add TZSTRING to the end of environ, as a value for TZ. */
}
#endif /* HAVE_MENUS */
/* Copy the data so that it won't move when we GC. */
- if (! message_text)
- {
- message_text = xmalloc (80);
- message_length = 80;
- }
if (SBYTES (val) > message_length)
{
- message_text = (char *) xrealloc (message_text, SBYTES (val));
- message_length = SBYTES (val);
+ ptrdiff_t new_length = SBYTES (val) + 80;
+ message_text = xrealloc (message_text, new_length);
+ message_length = new_length;
}
memcpy (message_text, SDATA (val), SBYTES (val));
message2 (message_text, SBYTES (val),
static void
sort_args (int argc, char **argv)
{
- char **new = xmalloc (sizeof (char *) * argc);
+ char **new = xmalloc (argc * sizeof *new);
/* For each element of argv,
the corresponding element of options is:
0 for an option that takes no arguments,
init_eval_once (void)
{
enum { size = 50 };
- specpdl = xmalloc (size * sizeof (struct specbinding));
+ specpdl = xmalloc (size * sizeof *specpdl);
specpdl_size = size;
specpdl_ptr = specpdl;
/* Don't forget to update docs (lispref node "Local Variables"). */
{
if (XSUBR (fun)->max_args > numargs)
{
- internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object));
+ internal_args = alloca (XSUBR (fun)->max_args
+ * sizeof *internal_args);
memcpy (internal_args, args + 1, numargs * sizeof (Lisp_Object));
for (i = numargs; i < XSUBR (fun)->max_args; i++)
internal_args[i] = Qnil;
filename = FILE_SYSTEM_CASE (filename);
#ifdef DOS_NT
- beg = (char *) alloca (SBYTES (filename) + 1);
+ beg = alloca (SBYTES (filename) + 1);
memcpy (beg, SSDATA (filename), SBYTES (filename) + 1);
#else
beg = SSDATA (filename);
error ("Invalid handler in `file-name-handler-alist'");
}
- buf = (char *) alloca (SBYTES (file) + 10);
+ buf = alloca (SBYTES (file) + 10);
file_name_as_directory (buf, SSDATA (file));
return make_specified_string (buf, -1, strlen (buf),
STRING_MULTIBYTE (file));
error ("Invalid handler in `file-name-handler-alist'");
}
- buf = (char *) alloca (SBYTES (directory) + 20);
+ buf = alloca (SBYTES (directory) + 20);
directory_file_name (SSDATA (directory), buf);
return make_specified_string (buf, -1, strlen (buf),
STRING_MULTIBYTE (directory));
}
/* Make a local copy of nm[] to protect it from GC in DECODE_FILE below. */
- nm = (char *) alloca (SBYTES (name) + 1);
+ nm = alloca (SBYTES (name) + 1);
memcpy (nm, SSDATA (name), SBYTES (name) + 1);
#ifdef DOS_NT
#endif
)
{
- char *temp = (char *) alloca (length);
+ char *temp = alloca (length);
memcpy (temp, newdir, length - 1);
temp[length - 1] = 0;
newdir = temp;
/* Reserve space for drive specifier and escape prefix, since either
or both may need to be inserted. (The Microsoft x86 compiler
produces incorrect code if the following two lines are combined.) */
- target = (char *) alloca (tlen + 4);
+ target = alloca (tlen + 4);
target += 4;
#else /* not DOS_NT */
- target = (char *) alloca (tlen);
+ target = alloca (tlen);
#endif /* not DOS_NT */
*target = 0;
unsigned char *ptr = (unsigned char *) strchr (user, '/');
ptrdiff_t len = ptr ? ptr - user : strlen (user);
/* Copy the user name into temp storage. */
- o = (unsigned char *) alloca (len + 1);
+ o = alloca (len + 1);
memcpy (o, user, len);
o[len] = 0;
/* Now concatenate the directory and name to new space in the stack frame. */
tlen = (newdir ? strlen (newdir) + 1 : 0) + strlen (nm) + 1;
- target = (unsigned char *) alloca (tlen);
+ target = alloca (tlen);
*target = 0;
if (newdir)
/* Always work on a copy of the string, in case GC happens during
decode of environment variables, causing the original Lisp_String
data to be relocated. */
- nm = (char *) alloca (SBYTES (filename) + 1);
+ nm = alloca (SBYTES (filename) + 1);
memcpy (nm, SDATA (filename), SBYTES (filename) + 1);
#ifdef DOS_NT
}
/* Copy out the variable name. */
- target = (char *) alloca (s - o + 1);
+ target = alloca (s - o + 1);
strncpy (target, o, s - o);
target[s - o] = 0;
#ifdef DOS_NT
/* If substitution required, recopy the string and do it. */
/* Make space in stack frame for the new copy. */
- xnm = (char *) alloca (SBYTES (filename) + total + 1);
+ xnm = alloca (SBYTES (filename) + total + 1);
x = xnm;
/* Copy the rest of the name through, replacing $ constructs with values. */
}
/* Copy out the variable name. */
- target = (char *) alloca (s - o + 1);
+ target = alloca (s - o + 1);
strncpy (target, o, s - o);
target[s - o] = 0;
#ifdef DOS_NT
trailing period plus one for the digit after it plus one for the
null. */
#define MAKE_LOCK_NAME(lock, file) \
- (lock = (char *) alloca (SBYTES (file) + 2 + 1 + 1 + 1), \
+ (lock = alloca (SBYTES (file) + 2 + 1 + 1 + 1), \
fill_in_lock_file_name (lock, (file)))
static void
/* The vector `used' is used to keep track of arguments that
have been consumed. */
- used = (char *) alloca (nargs * sizeof *used);
+ used = alloca (nargs * sizeof *used);
memset (used, 0, nargs * sizeof *used);
/* See if there's a `:test TEST' among the arguments. */
if (EQ (list->driver->type, driver->type))
error ("Duplicated font driver: %s", SDATA (SYMBOL_NAME (driver->type)));
- list = xmalloc (sizeof (struct font_driver_list));
+ list = xmalloc (sizeof *list);
list->on = 0;
list->driver = driver;
list->next = NULL;
if (! list)
{
- list = xmalloc (sizeof (struct font_data_list));
+ list = xmalloc (sizeof *list);
list->driver = driver;
list->next = f->font_data_list;
f->font_data_list = list;
we convert "*" to "[^-]*" which is much faster in regular
expression matching. */
if (ndashes < 14)
- p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 2 * nstars + 2 * nescs + 1);
+ p1 = regex = alloca (SBYTES (pattern) + 2 * nstars + 2 * nescs + 1);
else
- p1 = regex = (unsigned char *) alloca (SBYTES (pattern) + 5 * nstars + 2 * nescs + 1);
+ p1 = regex = alloca (SBYTES (pattern) + 5 * nstars + 2 * nescs + 1);
*p1++ = '^';
for (p0 = SDATA (pattern); *p0; p0++)
/* Recode fontsets realized on FRAME from the base fontset FONTSET
in the table `realized'. */
- realized[0] = (Lisp_Object *) alloca (sizeof (Lisp_Object)
- * ASIZE (Vfontset_table));
+ realized[0] = alloca (sizeof (Lisp_Object) * ASIZE (Vfontset_table));
for (i = j = 0; i < ASIZE (Vfontset_table); i++)
{
elt = FONTSET_FROM_ID (i);
}
realized[0][j] = Qnil;
- realized[1] = (Lisp_Object *) alloca (sizeof (Lisp_Object)
- * ASIZE (Vfontset_table));
+ realized[1] = alloca (sizeof (Lisp_Object) * ASIZE (Vfontset_table));
for (i = j = 0; ! NILP (realized[0][i]); i++)
{
elt = FONTSET_DEFAULT (realized[0][i]);
: NULL));
if (!NILP (tty))
{
- name = (char *) alloca (SBYTES (tty) + 1);
+ name = alloca (SBYTES (tty) + 1);
strncpy (name, SSDATA (tty), SBYTES (tty));
name[SBYTES (tty)] = 0;
}
: NULL));
if (!NILP (tty_type))
{
- type = (char *) alloca (SBYTES (tty_type) + 1);
+ type = alloca (SBYTES (tty_type) + 1);
strncpy (type, SSDATA (tty_type), SBYTES (tty_type));
type[SBYTES (tty_type)] = 0;
}
for (tail = alist; CONSP (tail); tail = Fcdr (tail))
i++;
- parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
- values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
+ parms = alloca (i * sizeof *parms);
+ values = alloca (i * sizeof *values);
/* Extract parm names and values into those vectors. */
/* Allocate space for the components, the dots which separate them,
and the final '\0'. Make them big enough for the worst case. */
- name_key = (char *) alloca (SBYTES (Vx_resource_name)
- + (STRINGP (component)
- ? SBYTES (component) : 0)
- + SBYTES (attribute)
- + 3);
-
- class_key = (char *) alloca (SBYTES (Vx_resource_class)
- + SBYTES (class)
- + (STRINGP (subclass)
- ? SBYTES (subclass) : 0)
- + 3);
+ name_key = alloca (SBYTES (Vx_resource_name)
+ + (STRINGP (component)
+ ? SBYTES (component) : 0)
+ + SBYTES (attribute)
+ + 3);
+
+ class_key = alloca (SBYTES (Vx_resource_class)
+ + SBYTES (class)
+ + (STRINGP (subclass)
+ ? SBYTES (subclass) : 0)
+ + 3);
/* Start with emacs.FRAMENAME for the name (the specific one)
and with `Emacs' for the class key (the general one). */
/* Allocate space for the components, the dots which separate them,
and the final '\0'. */
SAFE_ALLOCA (name_key, char *, invocation_namelen + strlen (attribute) + 2);
- class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
- + strlen (class) + 2);
+ class_key = alloca ((sizeof (EMACS_CLASS) - 1) + strlen (class) + 2);
esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
sprintf (class_key, "%s.%s", EMACS_CLASS, class);
error ("No free fringe bitmap slots");
i = max_fringe_bitmaps;
- fringe_bitmaps
- = ((struct fringe_bitmap **)
- xrealloc (fringe_bitmaps, bitmaps * sizeof *fringe_bitmaps));
- fringe_faces
- = (Lisp_Object *) xrealloc (fringe_faces,
- bitmaps * sizeof *fringe_faces);
+ fringe_bitmaps = xrealloc (fringe_bitmaps,
+ bitmaps * sizeof *fringe_bitmaps);
+ fringe_faces = xrealloc (fringe_faces,
+ bitmaps * sizeof *fringe_faces);
for (i = max_fringe_bitmaps; i < bitmaps; i++)
{
max_fringe_bitmaps = MAX_STANDARD_FRINGE_BITMAPS + 20;
- fringe_bitmaps
- = xzalloc (max_fringe_bitmaps * sizeof (struct fringe_bitmap *));
- fringe_faces = xmalloc (max_fringe_bitmaps * sizeof (Lisp_Object));
+ fringe_bitmaps = xzalloc (max_fringe_bitmaps * sizeof *fringe_bitmaps);
+ fringe_faces = xmalloc (max_fringe_bitmaps * sizeof *fringe_faces);
for (i = 0; i < max_fringe_bitmaps; i++)
fringe_faces[i] = Qnil;
args[1] = Qequal;
ft_face_cache = Fmake_hash_table (2, args);
}
- cache_data = xmalloc (sizeof (struct ftfont_cache_data));
+ cache_data = xmalloc (sizeof *cache_data);
cache_data->ft_face = NULL;
cache_data->fc_charset = NULL;
val = make_save_value (NULL, 0);
static struct OpenTypeSpec *
ftfont_get_open_type_spec (Lisp_Object otf_spec)
{
- struct OpenTypeSpec *spec = malloc (sizeof (struct OpenTypeSpec));
+ struct OpenTypeSpec *spec = malloc (sizeof *spec);
Lisp_Object val;
int i, j, negative;
spec->features[i] =
(min (PTRDIFF_MAX, SIZE_MAX) / sizeof (int) < XINT (len)
? 0
- : malloc (sizeof (int) * XINT (len)));
+ : malloc (XINT (len) * sizeof *spec->features[i]));
if (! spec->features[i])
{
if (i > 0 && spec->features[0])
if (gstring.allocated == 0)
{
gstring.glyph_size = sizeof (MFLTGlyph);
- gstring.glyphs = xnmalloc (len * 2, sizeof (MFLTGlyph));
+ gstring.glyphs = xnmalloc (len * 2, sizeof *gstring.glyphs);
gstring.allocated = len * 2;
}
else if (gstring.allocated < len * 2)
{
- gstring.glyphs = xnrealloc (gstring.glyphs, len * 2, sizeof (MFLTGlyph));
+ gstring.glyphs = xnrealloc (gstring.glyphs, len * 2,
+ sizeof *gstring.glyphs);
gstring.allocated = len * 2;
}
- memset (gstring.glyphs, 0, sizeof (MFLTGlyph) * len);
+ memset (gstring.glyphs, 0, len * sizeof *gstring.glyphs);
for (i = 0; i < len; i++)
{
Lisp_Object g = LGSTRING_GLYPH (lgstring, i);
}
}
- new = malloc (sizeof (struct ftxfont_frame_data));
+ new = malloc (sizeof *new);
if (! new)
return NULL;
new->next = this;
break;
if (l == NULL)
{
- l = malloc (sizeof (struct alignlist));
+ l = malloc (sizeof *l);
if (l != NULL)
{
l->next = _aligned_blocks;
struct hdr *hdr;
__malloc_hook = old_malloc_hook;
- hdr = malloc (sizeof (struct hdr) + size + 1);
+ hdr = malloc (sizeof *hdr + size + 1);
__malloc_hook = mallochook;
if (hdr == NULL)
return NULL;
__free_hook = old_free_hook;
__malloc_hook = old_malloc_hook;
__realloc_hook = old_realloc_hook;
- hdr = realloc (hdr, sizeof (struct hdr) + size + 1);
+ hdr = realloc (hdr, sizeof *hdr + size + 1);
__free_hook = freehook;
__malloc_hook = mallochook;
__realloc_hook = reallochook;
}
else
{
- wv = xmalloc (sizeof (widget_value));
+ wv = xmalloc (sizeof *wv);
malloc_cpt++;
}
memset (wv, 0, sizeof (widget_value));
{
if (! cl_data)
{
- cl_data = xmalloc (sizeof (*cl_data));
+ cl_data = xmalloc (sizeof *cl_data);
cl_data->f = f;
cl_data->menu_bar_vector = f->menu_bar_vector;
cl_data->menu_bar_items_used = f->menu_bar_items_used;
if (utf8_label) g_free (utf8_label);
if (utf8_key) g_free (utf8_key);
- cb_data = xmalloc (sizeof (xg_menu_item_cb_data));
+ cb_data = xmalloc (sizeof *cb_data);
xg_list_insert (&xg_menu_item_cb_list, &cb_data->ptrs);
{
#ifdef HAVE_GTK3
int ret = 0;
- if (GTK_IS_BOX (vb))
+ if (GTK_IS_BOX (vb))
{
GtkOrientation ori = gtk_orientable_get_orientation (GTK_ORIENTABLE (vb));
ret = (ori == GTK_ORIENTATION_HORIZONTAL && is_horizontal)
/* This isn't called frequently so we get away with simply
reallocating the color vector to the needed size, here. */
ptrdiff_t ncolors = img->ncolors + 1;
- img->colors =
- (unsigned long *) xrealloc (img->colors,
- ncolors * sizeof *img->colors);
+ img->colors = xrealloc (img->colors, ncolors * sizeof *img->colors);
img->colors[ncolors - 1] = color.pixel;
img->ncolors = ncolors;
result = color.pixel;
w1 = (width + 7) / 8; /* nb of 8bits elt in X bitmap */
w2 = ((width + 15) / 16) * 2; /* nb of 16bits elt in W32 bitmap */
- bits = (unsigned char *) alloca (height * w2);
+ bits = alloca (height * w2);
memset (bits, 0, height * w2);
for (i = 0; i < height; i++)
{
char *p;
int nbytes = (img->width + BITS_PER_CHAR - 1) / BITS_PER_CHAR;
- p = bits = (char *) alloca (nbytes * img->height);
+ p = bits = alloca (nbytes * img->height);
for (i = 0; i < img->height; ++i, p += nbytes)
{
Lisp_Object line = AREF (data, i);
invertedBits = bits;
nbytes = (img->width + BITS_PER_CHAR - 1) / BITS_PER_CHAR
* img->height;
- bits = (char *) alloca (nbytes);
+ bits = alloca (nbytes);
for (i = 0; i < nbytes; i++)
bits[i] = XBM_BIT_SHUFFLE (invertedBits[i]);
}
/* Allocate an XpmColorSymbol array. */
size = attrs.numsymbols * sizeof *xpm_syms;
- xpm_syms = (XpmColorSymbol *) alloca (size);
+ xpm_syms = alloca (size);
memset (xpm_syms, 0, size);
attrs.colorsymbols = xpm_syms;
color = XCDR (XCAR (tail));
if (STRINGP (name))
{
- xpm_syms[i].name = (char *) alloca (SCHARS (name) + 1);
+ xpm_syms[i].name = alloca (SCHARS (name) + 1);
strcpy (xpm_syms[i].name, SSDATA (name));
}
else
xpm_syms[i].name = empty_string;
if (STRINGP (color))
{
- xpm_syms[i].value = (char *) alloca (SCHARS (color) + 1);
+ xpm_syms[i].value = alloca (SCHARS (color) + 1);
strcpy (xpm_syms[i].value, SSDATA (color));
}
else
a default color, and we don't have to care about which colors
can be freed safely, and which can't. */
init_color_table ();
- colors = (unsigned long *) alloca (cinfo.actual_number_of_colors
- * sizeof *colors);
+ colors = alloca (cinfo.actual_number_of_colors * sizeof *colors);
for (i = 0; i < cinfo.actual_number_of_colors; ++i)
{
if (current_kboard->immediate_echo)
{
int size = KEY_DESCRIPTION_SIZE + 100;
- char *buffer = (char *) alloca (size);
+ char *buffer = alloca (size);
char *ptr = buffer;
Lisp_Object echo_string;
{
int offset = ptr - buffer;
size = max (2 * size, size + nbytes);
- buffer = (char *) alloca (size);
+ buffer = alloca (size);
ptr = buffer + offset;
}
{
int offset = ptr - buffer;
size += len;
- buffer = (char *) alloca (size);
+ buffer = alloca (size);
ptr = buffer + offset;
}
void
push_kboard (struct kboard *k)
{
- struct kboard_stack *p = xmalloc (sizeof (struct kboard_stack));
+ struct kboard_stack *p = xmalloc (sizeof *p);
p->next = kboard_stack;
p->kboard = current_kboard;
/* Since BASE could contain nulls, we can't use intern here; we have
to use Fintern, which expects a genuine Lisp_String, and keeps a
reference to it. */
- char *new_mods
- = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
+ char new_mods[sizeof "A-C-H-M-S-s-down-drag-double-triple-"];
int mod_len;
{
/* Already added. */
return;
- p = xmalloc (sizeof (struct user_signal_info));
+ p = xmalloc (sizeof *p);
p->sig = sig;
p->name = xstrdup (name);
p->npending = 0;
Lisp_Object tem;
ptrdiff_t nminor;
nminor = current_minor_maps (NULL, &tmaps);
- maps = (Lisp_Object *) alloca ((nminor + 3) * sizeof (maps[0]));
+ maps = alloca ((nminor + 3) * sizeof *maps);
nmaps = 0;
if (tem = get_local_map (PT, current_buffer, Qkeymap), !NILP (tem))
maps[nmaps++] = tem;
if (!NILP (Voverriding_local_map_menu_flag))
{
/* Yes, use them (if non-nil) as well as the global map. */
- maps = (Lisp_Object *) alloca (3 * sizeof (maps[0]));
+ maps = alloca (3 * sizeof *maps);
nmaps = 0;
if (!NILP (KVAR (current_kboard, Voverriding_terminal_local_map)))
maps[nmaps++] = KVAR (current_kboard, Voverriding_terminal_local_map);
Lisp_Object tem;
ptrdiff_t nminor;
nminor = current_minor_maps (NULL, &tmaps);
- maps = (Lisp_Object *) alloca ((nminor + 3) * sizeof (maps[0]));
+ maps = alloca ((nminor + 3) * sizeof *maps);
nmaps = 0;
if (tem = get_local_map (PT, current_buffer, Qkeymap), !NILP (tem))
maps[nmaps++] = tem;
&& !EQ (XCAR (prev_event), Qtool_bar))
{
/* Display the menu and get the selection. */
- Lisp_Object *realmaps
- = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
+ Lisp_Object *realmaps = alloca (nmaps * sizeof *realmaps);
Lisp_Object value;
ptrdiff_t nmaps1 = 0;
if (width + 4 > read_char_minibuf_menu_width)
{
read_char_minibuf_menu_text
- = (char *) xrealloc (read_char_minibuf_menu_text, width + 4);
+ = xrealloc (read_char_minibuf_menu_text, width + 4);
read_char_minibuf_menu_width = width + 4;
}
menu = read_char_minibuf_menu_text;
{
if (2 > nmaps_allocated)
{
- submaps = (Lisp_Object *) alloca (2 * sizeof (submaps[0]));
- defs = (Lisp_Object *) alloca (2 * sizeof (defs[0]));
+ submaps = alloca (2 * sizeof *submaps);
+ defs = alloca (2 * sizeof *defs);
nmaps_allocated = 2;
}
submaps[nmaps++] = KVAR (current_kboard, Voverriding_terminal_local_map);
{
if (2 > nmaps_allocated)
{
- submaps = (Lisp_Object *) alloca (2 * sizeof (submaps[0]));
- defs = (Lisp_Object *) alloca (2 * sizeof (defs[0]));
+ submaps = alloca (2 * sizeof *submaps);
+ defs = alloca (2 * sizeof *defs);
nmaps_allocated = 2;
}
submaps[nmaps++] = Voverriding_local_map;
if (total > nmaps_allocated)
{
- submaps = (Lisp_Object *) alloca (total * sizeof (submaps[0]));
- defs = (Lisp_Object *) alloca (total * sizeof (defs[0]));
+ submaps = alloca (total * sizeof *submaps);
+ defs = alloca (total * sizeof *defs);
nmaps_allocated = total;
}
Vdebug_on_event = intern_c_string ("sigusr2");
/* Create the initial keyboard. */
- initial_kboard = xmalloc (sizeof (KBOARD));
+ initial_kboard = xmalloc (sizeof *initial_kboard);
init_kboard (initial_kboard);
/* Vwindow_system is left at t for now. */
initial_kboard->next_kboard = all_kboards;
/* Use malloc here. See the comment above this function.
Avoid realloc here; it causes spurious traps on GNU/Linux [KFS] */
BLOCK_INPUT;
- newmodes = (Lisp_Object *) malloc (allocsize);
+ newmodes = malloc (allocsize);
if (newmodes)
{
if (cmm_modes)
cmm_modes = newmodes;
}
- newmaps = (Lisp_Object *) malloc (allocsize);
+ newmaps = malloc (allocsize);
if (newmaps)
{
if (cmm_maps)
if (!SYMBOLP (modes[i]))
abort ();
- p = title = (char *) alloca (42 + SCHARS (SYMBOL_NAME (modes[i])));
+ p = title = alloca (42 + SCHARS (SYMBOL_NAME (modes[i])));
*p++ = '\f';
*p++ = '\n';
*p++ = '`';
this path element/specified file name and any possible suffix. */
want_length = max_suffix_len + SBYTES (filename);
if (fn_size <= want_length)
- fn = (char *) alloca (fn_size = 100 + want_length);
+ fn = alloca (fn_size = 100 + want_length);
/* Loop over suffixes. */
for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : suffixes;
}
if (nskip > saved_doc_string_size)
{
- saved_doc_string = (char *) xrealloc (saved_doc_string,
- nskip + extra);
+ saved_doc_string = xrealloc (saved_doc_string, nskip + extra);
saved_doc_string_size = nskip + extra;
}
ptrdiff_t offset = p - read_buffer;
if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
memory_full (SIZE_MAX);
- read_buffer = (char *) xrealloc (read_buffer,
- read_buffer_size * 2);
+ read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
read_buffer_size *= 2;
p = read_buffer + offset;
end = read_buffer + read_buffer_size;
ptrdiff_t offset = p - read_buffer;
if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
memory_full (SIZE_MAX);
- read_buffer = (char *) xrealloc (read_buffer,
- read_buffer_size * 2);
+ read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
read_buffer_size *= 2;
p = read_buffer + offset;
end = read_buffer + read_buffer_size;
ptrdiff_t offset = p - read_buffer;
if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
memory_full (SIZE_MAX);
- read_buffer = (char *) xrealloc (read_buffer,
- read_buffer_size * 2);
+ read_buffer = xrealloc (read_buffer, read_buffer_size * 2);
read_buffer_size *= 2;
p = read_buffer + offset;
end = read_buffer + read_buffer_size;
if (!current_kboard->kbd_macro_buffer)
{
- current_kboard->kbd_macro_buffer
- = (Lisp_Object *)xmalloc (30 * sizeof (Lisp_Object));
+ current_kboard->kbd_macro_buffer = xmalloc (30 * sizeof (Lisp_Object));
current_kboard->kbd_macro_bufsize = 30;
}
update_mode_lines++;
< kb->kbd_macro_bufsize)
memory_full (SIZE_MAX);
nbytes = kb->kbd_macro_bufsize * (2 * sizeof *kb->kbd_macro_buffer);
- kb->kbd_macro_buffer
- = (Lisp_Object *) xrealloc (kb->kbd_macro_buffer, nbytes);
+ kb->kbd_macro_buffer = xrealloc (kb->kbd_macro_buffer, nbytes);
kb->kbd_macro_bufsize *= 2;
kb->kbd_macro_ptr = kb->kbd_macro_buffer + ptr_offset;
kb->kbd_macro_end = kb->kbd_macro_buffer + end_offset;
widget_value **submenu_stack;
int panes_seen = 0;
- submenu_stack
- = (widget_value **) alloca (menu_items_used * sizeof (widget_value *));
+ submenu_stack = alloca (menu_items_used * sizeof *submenu_stack);
wv = xmalloc_widget_value ();
wv->name = "menu";
wv->value = 0;
int i;
entry = Qnil;
- subprefix_stack = (Lisp_Object *) alloca (menu_bar_items_used * sizeof (Lisp_Object));
+ subprefix_stack = alloca (menu_bar_items_used * sizeof *subprefix_stack);
prefix = Qnil;
i = 0;
f->terminal = dpyinfo->terminal;
f->output_method = output_ns;
- f->output_data.ns = (struct ns_output *)xmalloc (sizeof *(f->output_data.ns));
- memset (f->output_data.ns, 0, sizeof *(f->output_data.ns));
+ f->output_data.ns = xzalloc (sizeof *f->output_data.ns);
FRAME_FONTSET (f) = -1;
[fdAttrs setObject: tdict forKey: NSFontTraitsAttribute];
fdesc = [NSFontDescriptor fontDescriptorWithFontAttributes: fdAttrs];
- if (family != nil)
+ if (family != nil)
{
fdesc = [fdesc fontDescriptorWithFamily: family];
}
if (!font)
return Qnil; /* FIXME: other terms do, but return Qnil causes segfault */
- font_info->glyphs = (unsigned short **)
- xmalloc (0x100 * sizeof (unsigned short *));
- font_info->metrics = (struct font_metrics **)
- xmalloc (0x100 * sizeof (struct font_metrics *));
- if (!font_info->glyphs || !font_info->metrics)
- return Qnil;
- memset (font_info->glyphs, 0, 0x100 * sizeof (unsigned short *));
- memset (font_info->metrics, 0, 0x100 * sizeof (struct font_metrics *));
+ font_info->glyphs = xzalloc (0x100 * sizeof *font_info->glyphs);
+ font_info->metrics = xzalloc (0x100 * sizeof *font_info->metrics);
BLOCK_INPUT;
[font_info->nsfont retain];
/* set up ns_font (defined in nsgui.h) */
- font_info->name = (char *)xmalloc (strlen (fontName)+1);
- strcpy (font_info->name, fontName);
+ font_info->name = xstrdup (fontName);
font_info->bold = [fontMgr traitsOfFont: nsfont] & NSBoldFontMask;
font_info->ital =
synthItal || ([fontMgr traitsOfFont: nsfont] & NSItalicFontMask);
BLOCK_INPUT;
sfont = [font_info->nsfont screenFont];
- font_info->metrics[block] = xmalloc (0x100 * sizeof (struct font_metrics));
- memset (font_info->metrics[block], 0, 0x100 * sizeof (struct font_metrics));
+ font_info->metrics[block] = xzalloc (0x100 * sizeof (struct font_metrics));
if (!(font_info->metrics[block]))
abort ();
maxChar = 0;
maxGlyph = 0;
dict = [NSMutableDictionary new];
- cglyphs = (CGGlyph *)xmalloc (c * sizeof (CGGlyph));
+ cglyphs = xmalloc (c * sizeof (CGGlyph));
return self;
}
ptrdiff_t specpdl_count = SPECPDL_INDEX ();
int previous_menu_items_used = f->menu_bar_items_used;
Lisp_Object *previous_items
- = (Lisp_Object *) alloca (previous_menu_items_used
- * sizeof (Lisp_Object));
+ = alloca (previous_menu_items_used * sizeof *previous_items);
/* lisp preliminaries */
buffer = XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer;
menu_items = f->menu_bar_vector;
menu_items_allocated = VECTORP (menu_items) ? ASIZE (menu_items) : 0;
- submenu_start = (int *) alloca (ASIZE (items) * sizeof (int *));
- submenu_end = (int *) alloca (ASIZE (items) * sizeof (int *));
- submenu_n_panes = (int *) alloca (ASIZE (items) * sizeof (int));
- submenu_top_level_items
- = (int *) alloca (ASIZE (items) * sizeof (int *));
+ submenu_start = alloca (ASIZE (items) * sizeof *submenu_start);
+ submenu_end = alloca (ASIZE (items) * sizeof *submenu_end);
+ submenu_n_panes = alloca (ASIZE (items) * sizeof *submenu_n_panes);
+ submenu_top_level_items = alloca (ASIZE (items)
+ * sizeof *submenu_top_level_items);
init_menu_items ();
for (i = 0; i < ASIZE (items); i += 4)
{
{
widget_value *save_wv = 0, *prev_wv = 0;
widget_value **submenu_stack
- = (widget_value **) alloca (menu_items_used * sizeof (widget_value *));
+ = alloca (menu_items_used * sizeof *submenu_stack);
/* Lisp_Object *subprefix_stack
- = (Lisp_Object *) alloca (menu_items_used * sizeof (Lisp_Object)); */
+ = alloca (menu_items_used * sizeof *subprefix_stack); */
int submenu_depth = 0;
int first_pane = 1;
int i;
{
color_table->size = NS_COLOR_CAPACITY;
color_table->avail = 1; /* skip idx=0 as marker */
- color_table->colors
- = (NSColor **)xmalloc (color_table->size * sizeof (NSColor *));
+ color_table->colors = xmalloc (color_table->size * sizeof (NSColor *));
color_table->colors[0] = nil;
color_table->empty_indices = [[NSMutableSet alloc] init];
}
/* grow bimgs if needed */
if (nBimgs < max_used_fringe_bitmap)
{
- EmacsImage **newBimgs
- = xmalloc (max_used_fringe_bitmap * sizeof (EmacsImage *));
- memset (newBimgs, 0, max_used_fringe_bitmap * sizeof (EmacsImage *));
-
- if (nBimgs)
- {
- memcpy (newBimgs, bimgs, nBimgs * sizeof (EmacsImage *));
- xfree (bimgs);
- }
-
- bimgs = newBimgs;
+ bimgs = xrealloc (bimgs, max_used_fringe_bitmap * sizeof *bimgs);
+ memset (bimgs + nBimgs, 0,
+ (max_used_fringe_bitmap - nBimgs) * sizeof *bimgs);
nBimgs = max_used_fringe_bitmap;
}
NSColorSpaceFromDepth (depth)];
dpyinfo->n_planes = NSBitsPerPixelFromDepth (depth);
dpyinfo->image_cache = make_image_cache ();
- dpyinfo->color_table
- = (struct ns_color_table *)xmalloc (sizeof (struct ns_color_table));
+ dpyinfo->color_table = xmalloc (sizeof *dpyinfo->color_table);
dpyinfo->color_table->colors = NULL;
dpyinfo->root_window = 42; /* a placeholder.. */
selector: @selector (logNotification:)
name: nil object: nil]; */
- dpyinfo = (struct ns_display_info *)xmalloc (sizeof (struct ns_display_info));
- memset (dpyinfo, 0, sizeof (struct ns_display_info));
+ dpyinfo = xzalloc (sizeof *dpyinfo);
ns_initialize_display_info (dpyinfo);
terminal = ns_create_terminal (dpyinfo);
- terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
+ terminal->kboard = xmalloc (sizeof *terminal->kboard);
init_kboard (terminal->kboard);
KVAR (terminal->kboard, Vwindow_system) = Qns;
terminal->kboard->next_kboard = all_kboards;
dpyinfo->name_list_element = XCAR (ns_display_name_list);
/* Set the name of the terminal. */
- terminal->name = (char *) xmalloc (SBYTES (display_name) + 1);
+ terminal->name = xmalloc (SBYTES (display_name) + 1);
strncpy (terminal->name, SDATA (display_name), SBYTES (display_name));
terminal->name[SBYTES (display_name)] = 0;
char *pos = strstr (t, " — ");
if (pos)
*pos = '\0';
- old_title = (char *) xmalloc (strlen (t) + 1);
- strcpy (old_title, t);
+ old_title = xstrdup (t);
}
size_title = xmalloc (strlen (old_title) + 40);
esprintf (size_title, "%s — (%d x %d)", old_title, cols, rows);
if (nr_screens == 1)
return [super constrainFrameRect:frameRect toScreen:screen];
-
+
if (f->output_data.ns->dont_constrain
|| ns_menu_bar_should_be_hidden ())
return frameRect;
if (print_buffer_pos != print_buffer_pos_byte \
&& NILP (BVAR (current_buffer, enable_multibyte_characters))) \
{ \
- unsigned char *temp \
- = (unsigned char *) alloca (print_buffer_pos + 1); \
+ unsigned char *temp = alloca (print_buffer_pos + 1); \
copy_text ((unsigned char *) print_buffer, temp, \
print_buffer_pos_byte, 1, 0); \
insert_1_both ((char *) temp, print_buffer_pos, \
val = Vcoding_system_for_read;
if (NILP (val))
{
- args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
+ args2 = alloca ((nargs + 1) * sizeof *args2);
args2[0] = Qstart_process;
for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
GCPRO2 (proc, current_dir);
{
if (EQ (coding_systems, Qt))
{
- args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
+ args2 = alloca ((nargs + 1) * sizeof *args2);
args2[0] = Qstart_process;
for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
GCPRO2 (proc, current_dir);
/* Now that everything is encoded we can collect the strings into
NEW_ARGV. */
- new_argv = (unsigned char **) alloca ((nargs - 1) * sizeof (char *));
+ new_argv = alloca ((nargs - 1) * sizeof *new_argv);
new_argv[nargs - 2] = 0;
for (i = nargs - 2; i-- != 0; )
ptrdiff_t count = SPECPDL_INDEX ();
Lisp_Object odeactivate;
- chars = (char *) alloca (carryover + readmax);
+ chars = alloca (carryover + readmax);
if (carryover)
/* See the comment above. */
memcpy (chars, SDATA (p->decoding_buf), carryover);
return;
if (!proc_decode_coding_system[inch])
- proc_decode_coding_system[inch]
- = xmalloc (sizeof (struct coding_system));
+ proc_decode_coding_system[inch] = xmalloc (sizeof (struct coding_system));
coding_system = p->decode_coding_system;
if (! NILP (p->filter))
;
setup_coding_system (coding_system, proc_decode_coding_system[inch]);
if (!proc_encode_coding_system[outch])
- proc_encode_coding_system[outch]
- = xmalloc (sizeof (struct coding_system));
+ proc_encode_coding_system[outch] = xmalloc (sizeof (struct coding_system));
setup_coding_system (p->encode_coding_system,
proc_encode_coding_system[outch]);
#endif
register bloc_ptr new_bloc;
register heap_ptr heap;
- if (! (new_bloc = (bloc_ptr) malloc (BLOC_PTR_SIZE))
+ if (! (new_bloc = malloc (BLOC_PTR_SIZE))
|| ! (new_bloc->data = obtain (break_value, size)))
{
free (new_bloc);
static void *
xmalloc (size_t size)
{
- register void *val;
- val = (void *) malloc (size);
+ void *val = malloc (size);
if (!val && size)
{
write (2, "virtual memory exhausted\n", 25);
static void *
xrealloc (void *block, size_t size)
{
- register void *val;
+ void *val;
/* We must call malloc explicitly when BLOCK is 0, since some
reallocs don't do this. */
if (! block)
- val = (void *) malloc (size);
+ val = malloc (size);
else
- val = (void *) realloc (block, size);
+ val = realloc (block, size);
if (!val && size)
{
write (2, "virtual memory exhausted\n", 25);
#ifdef MATCH_MAY_ALLOCATE
# define INIT_FAIL_STACK() \
do { \
- fail_stack.stack = (fail_stack_elt_t *) \
+ fail_stack.stack = \
REGEX_ALLOCATE_STACK (INIT_FAILURE_ALLOC * TYPICAL_FAILURE_SIZE \
* sizeof (fail_stack_elt_t)); \
\
>= re_max_failures * TYPICAL_FAILURE_SIZE) \
? 0 \
: ((fail_stack).stack \
- = (fail_stack_elt_t *) \
- REGEX_REALLOCATE_STACK ((fail_stack).stack, \
+ = REGEX_REALLOCATE_STACK ((fail_stack).stack, \
(fail_stack).size * sizeof (fail_stack_elt_t), \
MIN (re_max_failures * TYPICAL_FAILURE_SIZE, \
((fail_stack).size * sizeof (fail_stack_elt_t) \
extend_range_table_work_area (struct range_table_work_area *work_area)
{
work_area->allocated += 16 * sizeof (int);
- if (work_area->table)
- work_area->table
- = (int *) realloc (work_area->table, work_area->allocated);
- else
- work_area->table
- = (int *) malloc (work_area->allocated);
+ work_area->table = realloc (work_area->table, work_area->allocated);
}
#if 0
if (fail_stack.size < re_max_failures * TYPICAL_FAILURE_SIZE)
{
fail_stack.size = re_max_failures * TYPICAL_FAILURE_SIZE;
-
- if (! fail_stack.stack)
- fail_stack.stack
- = (fail_stack_elt_t *) malloc (fail_stack.size
- * sizeof (fail_stack_elt_t));
- else
- fail_stack.stack
- = (fail_stack_elt_t *) realloc (fail_stack.stack,
- (fail_stack.size
- * sizeof (fail_stack_elt_t)));
+ falk_stack.stack = realloc (fail_stack.stack,
+ fail_stack.size * sizeof *falk_stack.stack);
}
regex_grow_registers (num_regs);
if (!re_comp_buf.buffer)
{
- re_comp_buf.buffer = (unsigned char *) malloc (200);
+ re_comp_buf.buffer = malloc (200);
if (re_comp_buf.buffer == NULL)
/* Yes, we're discarding `const' here if !HAVE_LIBINTL. */
return (char *) gettext (re_error_msgid[(int) REG_ESPACE]);
re_comp_buf.allocated = 200;
- re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH);
+ re_comp_buf.fastmap = malloc (1 << BYTEWIDTH);
if (re_comp_buf.fastmap == NULL)
/* Yes, we're discarding `const' here if !HAVE_LIBINTL. */
return (char *) gettext (re_error_msgid[(int) REG_ESPACE]);
preg->used = 0;
/* Try to allocate space for the fastmap. */
- preg->fastmap = (char *) malloc (1 << BYTEWIDTH);
+ preg->fastmap = malloc (1 << BYTEWIDTH);
if (cflags & REG_ICASE)
{
unsigned i;
- preg->translate
- = (RE_TRANSLATE_TYPE) malloc (CHAR_SET_SIZE
- * sizeof (*(RE_TRANSLATE_TYPE)0));
+ preg->translate = malloc (CHAR_SET_SIZE * sizeof *preg->translate);
if (preg->translate == NULL)
return (int) REG_ESPACE;
struct region_cache *
new_region_cache (void)
{
- struct region_cache *c = xmalloc (sizeof (struct region_cache));
+ struct region_cache *c = xmalloc (sizeof *c);
c->gap_start = 0;
c->gap_len = NEW_CACHE_GAP;
/* A queue for line insertions to be done. */
struct queue { int count, pos; };
struct queue *queue_start
- = (struct queue *) alloca (current_matrix->nrows * sizeof (struct queue));
+ = alloca (current_matrix->nrows * sizeof *queue_start);
struct queue *queue = queue_start;
- char *retained_p = (char *) alloca (window_size * sizeof (char));
- int *copy_from = (int *) alloca (window_size * sizeof (int));
+ char *retained_p = alloca (window_size * sizeof *retained_p);
+ int *copy_from = alloca (window_size * sizeof *copy_from);
/* Zero means line is empty. */
memset (retained_p, 0, window_size * sizeof (char));
int write_follows_p = 1;
/* For each row in the new matrix what row of the old matrix it is. */
- int *copy_from = (int *) alloca (window_size * sizeof (int));
+ int *copy_from = alloca (window_size * sizeof *copy_from);
/* Non-zero for each row in the new matrix that is retained from the
old matrix. Lines not retained are empty. */
- char *retained_p = (char *) alloca (window_size * sizeof (char));
+ char *retained_p = alloca (window_size * sizeof *retained_p);
memset (retained_p, 0, window_size * sizeof (char));
for (cp = searchbuf_head; cp != 0; cp = cp->next)
{
cp->buf.allocated = cp->buf.used;
- cp->buf.buffer
- = (unsigned char *) xrealloc (cp->buf.buffer, cp->buf.used);
+ cp->buf.buffer = xrealloc (cp->buf.buffer, cp->buf.used);
}
}
raw_pattern_size_byte
= count_size_as_multibyte (SDATA (string),
raw_pattern_size);
- raw_pattern = (unsigned char *) alloca (raw_pattern_size_byte + 1);
+ raw_pattern = alloca (raw_pattern_size_byte + 1);
copy_text (SDATA (string), raw_pattern,
SCHARS (string), 0, 1);
}
the chosen single-byte character set can possibly match. */
raw_pattern_size = SCHARS (string);
raw_pattern_size_byte = SCHARS (string);
- raw_pattern = (unsigned char *) alloca (raw_pattern_size + 1);
+ raw_pattern = alloca (raw_pattern_size + 1);
copy_text (SDATA (string), raw_pattern,
SBYTES (string), 1, 0);
}
/* Copy and optionally translate the pattern. */
len = raw_pattern_size;
len_byte = raw_pattern_size_byte;
- patbuf = (unsigned char *) alloca (len * MAX_MULTIBYTE_LENGTH);
+ patbuf = alloca (len * MAX_MULTIBYTE_LENGTH);
pat = patbuf;
base_pat = raw_pattern;
if (multibyte)
prev = Qnil;
- data = (Lisp_Object *) alloca ((2 * search_regs.num_regs + 1)
- * sizeof (Lisp_Object));
+ data = alloca ((2 * search_regs.num_regs + 1) * sizeof *data);
len = 0;
for (i = 0; i < search_regs.num_regs; i++)
CHECK_STRING (string);
- temp = (char *) alloca (SBYTES (string) * 2);
+ temp = alloca (SBYTES (string) * 2);
/* Now copy the data into the new string, inserting escapes. */
ptrdiff_t blksize = sd->period_size ? sd->period_size (sd) : 2048;
ptrdiff_t data_left = header->data_length;
- buffer = (char *) alloca (blksize);
+ buffer = alloca (blksize);
lseek (s->fd, sizeof *header, SEEK_SET);
while (data_left > 0
&& (nbytes = emacs_read (s->fd, buffer, blksize)) > 0)
lseek (s->fd, header->data_offset, SEEK_SET);
/* Copy sound data to the device. */
- buffer = (char *) alloca (blksize);
+ buffer = alloca (blksize);
while ((nbytes = emacs_read (s->fd, buffer, blksize)) > 0)
sd->write (sd, buffer, nbytes);
else
file = DEFAULT_ALSA_SOUND_DEVICE;
- p = xmalloc (sizeof (*p));
+ p = xmalloc (sizeof *p);
p->handle = NULL;
p->hwparams = NULL;
p->swparams = NULL;
#ifndef WINDOWSNT
file = Qnil;
GCPRO2 (sound, file);
- current_sound_device = xzalloc (sizeof (struct sound_device));
- current_sound = xzalloc (sizeof (struct sound));
+ current_sound_device = xzalloc (sizeof *current_sound_device);
+ current_sound = xzalloc (sizeof *current_sound);
record_unwind_protect (sound_cleanup, Qnil);
- current_sound->header = (char *) alloca (MAX_SOUND_HEADER_BYTES);
+ current_sound->header = alloca (MAX_SOUND_HEADER_BYTES);
if (STRINGP (attrs[SOUND_FILE]))
{
if (STRINGP (attrs[SOUND_DEVICE]))
{
int len = SCHARS (attrs[SOUND_DEVICE]);
- current_sound_device->file = (char *) alloca (len + 1);
+ current_sound_device->file = alloca (len + 1);
strcpy (current_sound_device->file, SSDATA (attrs[SOUND_DEVICE]));
}
lo_file = Fexpand_file_name (attrs[SOUND_FILE], Qnil);
len = XSTRING (lo_file)->size;
- psz_file = (char *) alloca (len + 1);
+ psz_file = alloca (len + 1);
strcpy (psz_file, XSTRING (lo_file)->data);
if (INTEGERP (attrs[SOUND_VOLUME]))
{
fastmap[CHAR_LEADING_CODE (c)] = 1;
range_start_byte = i;
range_start_char = c;
- char_ranges = (int *) alloca (sizeof (int) * 128 * 2);
+ char_ranges = alloca (sizeof *char_ranges * 128 * 2);
for (i = 129; i < 0400; i++)
{
c = BYTE8_TO_CHAR (i);
}
else /* STRING is multibyte */
{
- char_ranges = (int *) alloca (sizeof (int) * SCHARS (string) * 2);
+ char_ranges = alloca (sizeof *char_ranges * SCHARS (string) * 2);
while (i_byte < size_byte)
{
#endif
)
{
- buf = (char *) malloc (strlen (pwd) + 1);
+ buf = malloc (strlen (pwd) + 1);
if (!buf)
return NULL;
strcpy (buf, pwd);
else
{
size_t buf_size = 1024;
- buf = (char *) malloc (buf_size);
+ buf = malloc (buf_size);
if (!buf)
return NULL;
for (;;)
return NULL;
}
buf_size *= 2;
- buf = (char *) realloc (buf, buf_size);
+ buf = realloc (buf, buf_size);
if (!buf)
return NULL;
}
else
{
/* We need MAXPATHLEN here. */
- buf = (char *) malloc (MAXPATHLEN + 1);
+ buf = malloc (MAXPATHLEN + 1);
if (!buf)
return NULL;
if (getwd (buf) == NULL)
goto xyzzy;
dir = expand_and_dir_to_file (Funhandled_file_name_directory (dir), Qnil);
- str_volatile = str = (unsigned char *) alloca (SCHARS (dir) + 2);
+ str_volatile = str = alloca (SCHARS (dir) + 2);
len = SCHARS (dir);
memcpy (str, SDATA (dir), len);
if (str[len - 1] != '/') str[len++] = '/';
return; /* The tty is suspended. */
if (! tty_out->old_tty)
- tty_out->old_tty = xmalloc (sizeof (struct emacs_tty));
+ tty_out->old_tty = xmalloc (sizeof *tty_out->old_tty);
emacs_get_tty (fileno (tty_out->input), tty_out->old_tty);
Vsystem_name = build_string (uts.nodename);
#else /* HAVE_GETHOSTNAME */
unsigned int hostname_size = 256;
- char *hostname = (char *) alloca (hostname_size);
+ char *hostname = alloca (hostname_size);
/* Try to get the host name; if the buffer is too short, try
again. Apparently, the only indication gethostname gives of
break;
hostname_size <<= 1;
- hostname = (char *) alloca (hostname_size);
+ hostname = alloca (hostname_size);
}
#ifdef HAVE_SOCKETS
/* Turn the hostname into the official, fully-qualified hostname.
void
create_tty_output (struct frame *f)
{
- struct tty_output *t;
+ struct tty_output *t = xzalloc (sizeof *t);
if (! FRAME_TERMCAP_P (f))
abort ();
- t = xzalloc (sizeof (struct tty_output));
-
t->display_info = FRAME_TERMINAL (f)->display_info.tty;
f->output_data.tty = t;
been_here = 1;
tty = &the_only_display_info;
#else
- tty = xzalloc (sizeof (struct tty_display_info));
+ tty = xzalloc (sizeof *tty);
#endif
tty->next = tty_list;
tty_list = tty;
terminal->display_info.tty = tty;
tty->terminal = terminal;
- tty->Wcm = xmalloc (sizeof (struct cm));
+ tty->Wcm = xmalloc (sizeof *tty->Wcm);
Wcm_clear (tty);
encode_terminal_src_size = 0;
tty->mouse_highlight.mouse_face_window = Qnil;
#endif
- terminal->kboard = xmalloc (sizeof (KBOARD));
+ terminal->kboard = xmalloc (sizeof *terminal->kboard);
init_kboard (terminal->kboard);
KVAR (terminal->kboard, Vwindow_system) = Qnil;
terminal->kboard->next_kboard = all_kboards;
{
ptrdiff_t offset1 = bp1 - bp, offset2 = tc_search_point - bp;
malloc_size = offset1 + buf.size;
- bp = termcap_name = (char *) xrealloc (bp, malloc_size);
+ bp = termcap_name = xrealloc (bp, malloc_size);
bp1 = termcap_name + offset1;
tc_search_point = termcap_name + offset2;
}
xfree (buf.beg);
if (malloc_size)
- bp = (char *) xrealloc (bp, bp1 - bp + 1);
+ bp = xrealloc (bp, bp1 - bp + 1);
ret:
term_entry = bp;
}
else
{
- r = (struct region_t *) malloc (sizeof (struct region_t));
+ r = malloc (sizeof *r);
if (!r)
unexec_error ("cannot allocate region structure");
#endif
nlc = mh.ncmds;
- lca = (struct load_command **) malloc (nlc * sizeof (struct load_command *));
+ lca = malloc (nlc * sizeof *lca);
for (i = 0; i < nlc; i++)
{
size first and then read the rest. */
if (!unexec_read (&lc, sizeof (struct load_command)))
unexec_error ("cannot read load command");
- lca[i] = (struct load_command *) malloc (lc.cmdsize);
+ lca[i] = malloc (lc.cmdsize);
memcpy (lca[i], &lc, sizeof (struct load_command));
if (!unexec_read (lca[i] + 1, lc.cmdsize - sizeof (struct load_command)))
unexec_error ("cannot read content of load command");
size_t old_size = ((unexec_malloc_header_t *) old_ptr)[-1].u.size;
size_t size = new_size > old_size ? old_size : new_size;
- p = (size_t *) malloc (new_size);
+ p = malloc (new_size);
if (size)
memcpy (p, old_ptr, size);
}
really like to do is to free only those matrices not reused
below. */
root_window = XWINDOW (FRAME_ROOT_WINDOW (f));
- leaf_windows
- = (struct window **) alloca (count_windows (root_window)
- * sizeof (struct window *));
+ leaf_windows = alloca (count_windows (root_window)
+ * sizeof *leaf_windows);
n_leaf_windows = get_leaf_windows (root_window, leaf_windows, 0);
/* Kludge Alert!
ptrdiff_t size = 20;
ptrdiff_t n = 0, i, j;
int invis_p;
- struct overlay_entry *entries
- = (struct overlay_entry *) alloca (size * sizeof *entries);
+ struct overlay_entry *entries = alloca (size * sizeof *entries);
USE_SAFE_ALLOCA;
if (charpos <= 0)
return rc;
#endif
- /* Previously, there was a check for Lisp integer in the
+ /* Previously, there was a check for Lisp integer in the
if-statement below. Now, this field is converted to
ptrdiff_t, thus zero means invalid position in a buffer. */
eassert (w->last_point > 0);
for (area = LEFT_MARGIN_AREA; area < LAST_AREA; ++area)
{
- char *s = (char *) alloca (row->used[area] + 1);
+ char *s = alloca (row->used[area] + 1);
int i;
for (i = 0; i < row->used[area]; ++i)
}
else if (CHARACTERP (eoltype))
{
- unsigned char *tmp = (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH);
+ unsigned char *tmp = alloca (MAX_MULTIBYTE_LENGTH);
int c = XFASTINT (eoltype);
eol_str_len = CHAR_STRING (c, tmp);
eol_str = tmp;
#define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
do \
{ \
- s = (struct glyph_string *) alloca (sizeof *s); \
+ s = alloca (sizeof *s); \
INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
START = fill_stretch_glyph_string (s, START, END); \
append_glyph_string (&HEAD, &TAIL, s); \
#define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
do \
{ \
- s = (struct glyph_string *) alloca (sizeof *s); \
+ s = alloca (sizeof *s); \
INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
fill_image_glyph_string (s); \
append_glyph_string (&HEAD, &TAIL, s); \
\
face_id = (row)->glyphs[area][START].face_id; \
\
- s = (struct glyph_string *) alloca (sizeof *s); \
- char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
+ s = alloca (sizeof *s); \
+ char2b = alloca ((END - START) * sizeof *char2b); \
INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
append_glyph_string (&HEAD, &TAIL, s); \
s->x = (X); \
struct glyph_string *first_s = NULL; \
int n; \
\
- char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
+ char2b = alloca (cmp->glyph_len * sizeof *char2b); \
\
/* Make glyph_strings for each glyph sequence that is drawable by \
the same face, and append them to HEAD/TAIL. */ \
for (n = 0; n < cmp->glyph_len;) \
{ \
- s = (struct glyph_string *) alloca (sizeof *s); \
+ s = alloca (sizeof *s); \
INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
append_glyph_string (&(HEAD), &(TAIL), s); \
s->cmp = cmp; \
face_id = (row)->glyphs[area][START].face_id; \
gstring = (composition_gstring_from_id \
((row)->glyphs[area][START].u.cmp.id)); \
- s = (struct glyph_string *) alloca (sizeof *s); \
- char2b = (XChar2b *) alloca ((sizeof *char2b) \
- * LGSTRING_GLYPH_LEN (gstring)); \
+ s = alloca (sizeof *s); \
+ char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
append_glyph_string (&(HEAD), &(TAIL), s); \
s->x = (X); \
\
face_id = (row)->glyphs[area][START].face_id; \
\
- s = (struct glyph_string *) alloca (sizeof *s); \
+ s = alloca (sizeof *s); \
INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
append_glyph_string (&HEAD, &TAIL, s); \
s->x = (X); \
unsigned long mask,
XGCValues *xgcv)
{
- GC gc = xmalloc (sizeof (*gc));
- if (gc)
- memcpy (gc, xgcv, sizeof (XGCValues));
+ GC gc = xmalloc (sizeof *gc);
+ memcpy (gc, xgcv, sizeof (XGCValues));
return gc;
}
else if (EQ (attr, QCunderline))
{
int valid_p = 0;
-
+
if (UNSPECIFIEDP (value) || IGNORE_DEFFACE_P (value))
valid_p = 1;
else if (NILP (value) || EQ (value, Qt))
list = CDR_SAFE (list);
val = CAR_SAFE (list);
list = CDR_SAFE (list);
-
- if(NILP (key) || NILP (val))
+
+ if (NILP (key) || NILP (val))
{
valid_p = 0;
break;
valid_p = 0;
break;
}
-
- else if (EQ (key, QCstyle)
+
+ else if (EQ (key, QCstyle)
&& !(EQ (val, Qline) || EQ (val, Qwave)))
{
valid_p = 0;
}
}
}
-
+
if (!valid_p)
signal_error ("Invalid face underline", value);
-
+
old_value = LFACE_UNDERLINE (lface);
LFACE_UNDERLINE (lface) = value;
}
}
else if (CONSP (underline))
{
- /* `(:color COLOR :style STYLE)'.
+ /* `(:color COLOR :style STYLE)'.
STYLE being one of `line' or `wave'. */
face->underline_p = 1;
face->underline_color = 0;
}
}
}
-
+
overline = attrs[LFACE_OVERLINE_INDEX];
if (STRINGP (overline))
{
/* Make a fontset name from the base font name. */
if (xic_default_fontset == base_fontname)
- {
+ {
/* There is no base font name, use the default. */
fontsetname = xmalloc (strlen (base_fontname) + 2);
strcpy (fontsetname, base_fontname);
/* Build the font spec that matches all charsets. */
len = p - base_fontname + strlen (allcs) + 1;
- font_allcs = (char *) alloca (len);
+ font_allcs = alloca (len);
memcpy (font_allcs, base_fontname, p - base_fontname);
strcat (font_allcs, allcs);
/* Build the font spec that matches all families and
add-styles. */
len = p - p1 + strlen (allcs) + strlen (allfamilies) + 1;
- font_allfamilies = (char *) alloca (len);
+ font_allfamilies = alloca (len);
strcpy (font_allfamilies, allfamilies);
memcpy (font_allfamilies + strlen (allfamilies), p1, p - p1);
strcat (font_allfamilies, allcs);
/* Build the font spec that matches all. */
len = p - p2 + strlen (allcs) + strlen (all) + strlen (allfamilies) + 1;
- font_all = (char *) alloca (len);
+ font_all = alloca (len);
strcpy (font_all, allfamilies);
strcat (font_all, all);
memcpy (font_all + strlen (all) + strlen (allfamilies), p2, p - p2);
f->terminal = dpyinfo->terminal;
f->output_method = output_x_window;
- f->output_data.x = xzalloc (sizeof (struct x_output));
+ f->output_data.x = xzalloc (sizeof *f->output_data.x);
f->output_data.x->icon_bitmap = -1;
FRAME_FONTSET (f) = -1;
f->output_data.x->scroll_bar_foreground_pixel = -1;
/* VALUE should be of the form CLASS-DEPTH, where CLASS is one
of `PseudoColor', `TrueColor' etc. and DEPTH is the color
depth, a decimal number. NAME is compared with case ignored. */
- char *s = (char *) alloca (SBYTES (value) + 1);
+ char *s = alloca (SBYTES (value) + 1);
char *dash;
int i, class = -1;
XVisualInfo vinfo;
from this point on, x_destroy_window might screw up reference
counts etc. */
f->output_method = output_x_window;
- f->output_data.x = xzalloc (sizeof (struct x_output));
+ f->output_data.x = xzalloc (sizeof *f->output_data.x);
f->output_data.x->icon_bitmap = -1;
FRAME_FONTSET (f) = -1;
f->output_data.x->scroll_bar_foreground_pixel = -1;
}
#endif
- xftface_info = malloc (sizeof (struct xftface_info));
+ xftface_info = malloc (sizeof *xftface_info);
if (! xftface_info)
return -1;
xftfont_get_colors (f, face, face->gc, NULL,
{
#if defined (USE_GTK) || defined (HAVE_GCONF) || defined (HAVE_GSETTINGS)
gfds_size = 128;
- gfds = xmalloc (sizeof (*gfds)*gfds_size);
+ gfds = xmalloc (gfds_size * sizeof *gfds);
#endif
}
ptrdiff_t specpdl_count = SPECPDL_INDEX ();
int previous_menu_items_used = f->menu_bar_items_used;
Lisp_Object *previous_items
- = (Lisp_Object *) alloca (previous_menu_items_used
- * sizeof (Lisp_Object));
+ = alloca (previous_menu_items_used * sizeof *previous_items);
int subitems;
/* If we are making a new widget, its contents are empty,
menu_items = f->menu_bar_vector;
menu_items_allocated = VECTORP (menu_items) ? ASIZE (menu_items) : 0;
subitems = ASIZE (items) / 4;
- submenu_start = (int *) alloca ((subitems + 1) * sizeof (int));
- submenu_end = (int *) alloca (subitems * sizeof (int));
- submenu_n_panes = (int *) alloca (subitems * sizeof (int));
- submenu_top_level_items = (int *) alloca (subitems * sizeof (int));
+ submenu_start = alloca ((subitems + 1) * sizeof *submenu_start);
+ submenu_end = alloca (subitems * sizeof *submenu_end);
+ submenu_n_panes = alloca (subitems * sizeof *submenu_n_panes);
+ submenu_top_level_items = alloca (subitems
+ * sizeof *submenu_top_level_items);
init_menu_items ();
for (i = 0; i < subitems; i++)
{
int i;
widget_value *wv, *save_wv = 0, *first_wv = 0, *prev_wv = 0;
widget_value **submenu_stack
- = (widget_value **) alloca (menu_items_used * sizeof (widget_value *));
+ = alloca (menu_items_used * sizeof *submenu_stack);
Lisp_Object *subprefix_stack
- = (Lisp_Object *) alloca (menu_items_used * sizeof (Lisp_Object));
+ = alloca (menu_items_used * sizeof *subprefix_stack);
int submenu_depth = 0;
int first_pane;
{
/* if alloca is fast, use that to make the space,
to reduce gc needs. */
- item_data = (char *) alloca (maxwidth + SBYTES (descrip) + 1);
+ item_data = alloca (maxwidth + SBYTES (descrip) + 1);
memcpy (item_data, SSDATA (item_name), SBYTES (item_name));
for (j = SCHARS (item_name); j < maxwidth; j++)
item_data[j] = ' ';
x_get_customization_string (XrmDatabase db, const char *name,
const char *class)
{
- char *full_name
- = (char *) alloca (strlen (name) + sizeof ("customization") + 3);
- char *full_class
- = (char *) alloca (strlen (class) + sizeof ("Customization") + 3);
+ char *full_name = alloca (strlen (name) + sizeof "customization" + 3);
+ char *full_class = alloca (strlen (class) + sizeof "Customization" + 3);
char *result;
sprintf (full_name, "%s.%s", name, "customization");
if (min (PTRDIFF_MAX, SIZE_MAX) / 2 - 1 - path_len < next_len)
memory_full (SIZE_MAX);
path_size = (path_len + next_len + 1) * 2;
- path = (char *) xrealloc (path, path_size);
+ path = xrealloc (path, path_size);
}
memcpy (path + path_len, next, next_len);
char *xdefault;
home = gethomedir ();
- xdefault = xmalloc (strlen (home) + sizeof (".Xdefaults"));
+ xdefault = xmalloc (strlen (home) + sizeof ".Xdefaults");
strcpy (xdefault, home);
strcat (xdefault, ".Xdefaults");
db = XrmGetFileDatabase (xdefault);
char *home = gethomedir ();
char const *host = get_system_name ();
ptrdiff_t pathsize = strlen (home) + sizeof xdefaults + strlen (host);
- path = (char *) xrealloc (home, pathsize);
+ path = xrealloc (home, pathsize);
strcat (strcat (path, xdefaults), host);
p = path;
}
}
}
- queue_tmp = xmalloc (sizeof (struct selection_event_queue));
+ queue_tmp = xmalloc (sizeof *queue_tmp);
TRACE1 ("QUEUE SELECTION EVENT %p", queue_tmp);
queue_tmp->event = *event;
queue_tmp->next = selection_queue;
{
if (for_multiple)
{
- cs = xmalloc (sizeof (struct selection_data));
+ cs = xmalloc (sizeof *cs);
cs->data = (unsigned char *) &conversion_fail_tag;
cs->size = 1;
cs->format = 32;
}
/* Otherwise, record the converted selection to binary. */
- cs = xmalloc (sizeof (struct selection_data));
+ cs = xmalloc (sizeof *cs);
cs->data = NULL;
cs->nofree = 1;
cs->property = property;
}
else if (SYMBOLP (obj))
{
- *data_ret = xmalloc (sizeof (Atom) + 1);
+ void *data = xmalloc (sizeof (Atom) + 1);
+ Atom *x_atom_ptr = data;
+ *data_ret = data;
*format_ret = 32;
*size_ret = 1;
(*data_ret) [sizeof (Atom)] = 0;
- (*(Atom **) data_ret) [0] = symbol_to_x_atom (dpyinfo, obj);
+ *x_atom_ptr = symbol_to_x_atom (dpyinfo, obj);
if (NILP (type)) type = QATOM;
}
else if (RANGED_INTEGERP (X_SHRT_MIN, obj, X_SHRT_MAX))
{
- *data_ret = xmalloc (sizeof (short) + 1);
+ void *data = xmalloc (sizeof (short) + 1);
+ short *short_ptr = data;
+ *data_ret = data;
*format_ret = 16;
*size_ret = 1;
(*data_ret) [sizeof (short)] = 0;
- (*(short **) data_ret) [0] = XINT (obj);
+ *short_ptr = XINT (obj);
if (NILP (type)) type = QINTEGER;
}
else if (INTEGERP (obj)
|| (CONSP (XCDR (obj))
&& INTEGERP (XCAR (XCDR (obj)))))))
{
- *data_ret = xmalloc (sizeof (unsigned long) + 1);
+ void *data = xmalloc (sizeof (unsigned long) + 1);
+ unsigned long *x_long_ptr = data;
+ *data_ret = data;
*format_ret = 32;
*size_ret = 1;
(*data_ret) [sizeof (unsigned long)] = 0;
- (*(unsigned long **) data_ret) [0] = cons_to_x_long (obj);
+ *x_long_ptr = cons_to_x_long (obj);
if (NILP (type)) type = QINTEGER;
}
else if (VECTORP (obj))
if (SYMBOLP (AREF (obj, 0)))
/* This vector is an ATOM set */
{
+ void *data;
+ Atom *x_atoms;
if (NILP (type)) type = QATOM;
for (i = 0; i < size; i++)
if (!SYMBOLP (AREF (obj, i)))
signal_error ("All elements of selection vector must have same type", obj);
- *data_ret = xnmalloc (size, sizeof (Atom));
+ *data_ret = data = xnmalloc (size, sizeof *x_atoms);
+ x_atoms = data;
*format_ret = 32;
*size_ret = size;
for (i = 0; i < size; i++)
- (*(Atom **) data_ret) [i]
- = symbol_to_x_atom (dpyinfo, AREF (obj, i));
+ x_atoms[i] = symbol_to_x_atom (dpyinfo, AREF (obj, i));
}
else
/* This vector is an INTEGER set, or something like it */
{
int format = 16;
int data_size = sizeof (short);
+ void *data;
+ unsigned long *x_atoms;
+ short *shorts;
if (NILP (type)) type = QINTEGER;
for (i = 0; i < size; i++)
{
break;
}
}
- *data_ret = xnmalloc (size, data_size);
+ *data_ret = data = xnmalloc (size, data_size);
+ x_atoms = data;
+ shorts = data;
*format_ret = format;
*size_ret = size;
for (i = 0; i < size; i++)
{
if (format == 32)
- (*((unsigned long **) data_ret)) [i] =
- cons_to_x_long (AREF (obj, i));
+ x_atoms[i] = cons_to_x_long (AREF (obj, i));
else
- (*((short **) data_ret)) [i] =
- XINT (AREF (obj, i));
+ shorts[i] = XINT (AREF (obj, i));
}
}
}
if (status_return == XBufferOverflow)
{
copy_bufsiz = nbytes + 1;
- copy_bufptr = (unsigned char *) alloca (copy_bufsiz);
+ copy_bufptr = alloca (copy_bufsiz);
nbytes = XmbLookupString (FRAME_XIC (f),
&event.xkey, (char *) copy_bufptr,
copy_bufsiz, &keysym,
void
x_catch_errors (Display *dpy)
{
- struct x_error_message_stack *data = xmalloc (sizeof (*data));
+ struct x_error_message_stack *data = xmalloc (sizeof *data);
/* Make sure any errors from previous requests have been dealt with. */
XSync (dpy, False);
Lisp_Object frame, tail;
ptrdiff_t idx = SPECPDL_INDEX ();
- error_msg = (char *) alloca (strlen (error_message) + 1);
+ error_msg = alloca (strlen (error_message) + 1);
strcpy (error_msg, error_message);
handling_signal = 0;
if (use_xim)
{
#ifdef HAVE_X11R6_XIM
- struct xim_inst_t *xim_inst;
+ struct xim_inst_t *xim_inst = xmalloc (sizeof *xim_inst);
ptrdiff_t len;
- xim_inst = xmalloc (sizeof (struct xim_inst_t));
dpyinfo->xim_callback_data = xim_inst;
xim_inst->dpyinfo = dpyinfo;
len = strlen (resource_name);
/* We have definitely succeeded. Record the new connection. */
- dpyinfo = xzalloc (sizeof (struct x_display_info));
+ dpyinfo = xzalloc (sizeof *dpyinfo);
hlinfo = &dpyinfo->mouse_highlight;
terminal = x_create_terminal (dpyinfo);
terminal->kboard = share->terminal->kboard;
else
{
- terminal->kboard = xmalloc (sizeof (KBOARD));
+ terminal->kboard = xmalloc (sizeof *terminal->kboard);
init_kboard (terminal->kboard);
KVAR (terminal->kboard, Vwindow_system) = Qx;
const int atom_count = sizeof (atom_refs) / sizeof (atom_refs[0]);
/* 1 for _XSETTINGS_SN */
const int total_atom_count = 1 + atom_count;
- Atom *atoms_return = xmalloc (sizeof (Atom) * total_atom_count);
- char **atom_names = xmalloc (sizeof (char *) * total_atom_count);
+ Atom *atoms_return = xmalloc (total_atom_count * sizeof *atoms_return);
+ char **atom_names = xmalloc (total_atom_count * sizeof *atom_names);
static char const xsettings_fmt[] = "_XSETTINGS_S%d";
char xsettings_atom_name[sizeof xsettings_fmt - 2
+ INT_STRLEN_BOUND (int)];
dpyinfo->x_dnd_atoms_size = 8;
dpyinfo->x_dnd_atoms_length = 0;
- dpyinfo->x_dnd_atoms = xmalloc (sizeof (*dpyinfo->x_dnd_atoms)
+ dpyinfo->x_dnd_atoms = xmalloc (sizeof *dpyinfo->x_dnd_atoms
* dpyinfo->x_dnd_atoms_size);
dpyinfo->net_supported_atoms = NULL;