From 309f24d1ec07646fb1a090ee10fe456e79aea097 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Fri, 9 Aug 2013 16:25:34 +0400 Subject: Use xstrdup and build_unibyte_string where applicable. * alloc.c (xstrdup): Tiny cleanup. Add eassert. * xfns.c (x_window): * xrdb.c (x_get_customization_string): * xterm.c (xim_initialize): * w32fns.c (w32_window): Use xstrdup. (w32_display_monitor_attributes_list): * emacs.c (init_cmdargs): * keyboard.c (PUSH_C_STR): * nsfont.m (nsfont_open): * sysdep.c (system_process_attributes): * w32.c (system_process_attributes): * xdisp.c (message1, message1_nolog): Use build_unibyte_string. --- src/alloc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index c8141d22f95..19418bd6686 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -796,10 +796,8 @@ xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min, char * xstrdup (const char *s) { - size_t len = strlen (s) + 1; - char *p = xmalloc (len); - memcpy (p, s, len); - return p; + eassert (s); + return strcpy (xmalloc (strlen (s) + 1), s); } /* Like putenv, but (1) use the equivalent of xmalloc and (2) the -- cgit v1.2.1 From 9acc107445a159001e56bae04ef2dc2792aa16d7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 10 Aug 2013 08:42:08 -0700 Subject: Minor string-length refactoring. * alloc.c (xstrdup): Use memcpy, not strcpy, since the length's known. * frame.c (make_monitor_attribute_list): Prefer build_string to strlen + make_string. --- src/alloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index 19418bd6686..f9bcaed0117 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -796,8 +796,10 @@ xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min, char * xstrdup (const char *s) { + ptrdiff_t size; eassert (s); - return strcpy (xmalloc (strlen (s) + 1), s); + size = strlen (s) + 1; + return memcpy (xmalloc (size), s, size); } /* Like putenv, but (1) use the equivalent of xmalloc and (2) the -- cgit v1.2.1 From 7d652d97681c4f1b67018f44f64c619ef5edd990 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 10 Aug 2013 18:30:20 -0700 Subject: Omit some unnecessary casts. Many of these go back to the old pre-C89 days, when they may have been needed, but we've been assuming C89 or later for a while now. * alloc.c (live_string_p, live_cons_p, live_symbol_p) (live_float_p, live_misc_p, live_vector_p): * buffer.c (compare_overlays, cmp_for_strings, mmap_find) (mmap_alloc, alloc_buffer_text, enlarge_buffer_text) (defvar_per_buffer): * callint.c (Fcall_interactively): * doc.c (Fsubstitute_command_keys): * filelock.c (get_boot_time): * frame.c (xrdb_get_resource): * gtkutil.c (hierarchy_ch_cb, qttip_cb, style_changed_cb) (delete_cb, xg_dialog_response_cb, xg_maybe_add_timer) (xg_get_file_name_from_selector, menuitem_destroy_callback) (menuitem_highlight_callback, menu_destroy_callback) (xg_update_menu_item, xg_modify_menubar_widgets, menubar_map_cb) (xg_tool_bar_callback, xg_get_tool_bar_widgets) (xg_tool_bar_detach_callback, xg_tool_bar_attach_callback) (xg_tool_bar_help_callback, tb_size_cb): * image.c (xpm_alloc_color, png_read_from_memory) (png_read_from_file, png_load_body, our_memory_skip_input_data) (jpeg_memory_src, jpeg_file_src, imagemagick_load_image) (syms_of_image): * keymap.c (describe_map): * nsfns.m (Fns_display_monitor_attributes_list): * nsmenu.m (process_dialog:): * nsterm.m (hold_event): * process.c (wait_reading_process_output): * regex.c (REGEX_REALLOCATE, re_set_registers, re_exec, regexec): * scroll.c (do_direct_scrolling, scrolling_1): * termcap.c (tgetent): * window.c (check_window_containing, add_window_to_list) (freeze_window_starts): * xdisp.c (compare_overlay_entries, vmessage): * xfns.c (x_window, x_get_monitor_attributes_xinerama) (x_get_monitor_attributes_xrandr) (Fx_display_monitor_attributes_list, x_display_info_for_name) (Fx_open_connection, file_dialog_cb, file_dialog_unmap_cb): * xfont.c (xfont_match, xfont_open): * xmenu.c (x_menu_wait_for_event, menu_highlight_callback) (menubar_selection_callback, menu_position_func) (popup_selection_callback, create_and_show_popup_menu) (dialog_selection_callback, create_and_show_dialog): * xrdb.c (x_get_string_resource): (main) [TESTRM]: * xsmfns.c (x_session_check_input): * xterm.c (x_draw_glyphless_glyph_string_foreground) (xm_scroll_callback, xg_scroll_callback, xg_end_scroll_callback) (xaw_jump_callback, xaw_scroll_callback): Omit unnecessary casts. --- src/alloc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index f9bcaed0117..2c2232601cb 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -4058,7 +4058,7 @@ live_string_p (struct mem_node *m, void *p) { if (m->type == MEM_TYPE_STRING) { - struct string_block *b = (struct string_block *) m->start; + struct string_block *b = m->start; ptrdiff_t offset = (char *) p - (char *) &b->strings[0]; /* P must point to the start of a Lisp_String structure, and it @@ -4081,7 +4081,7 @@ live_cons_p (struct mem_node *m, void *p) { if (m->type == MEM_TYPE_CONS) { - struct cons_block *b = (struct cons_block *) m->start; + struct cons_block *b = m->start; ptrdiff_t offset = (char *) p - (char *) &b->conses[0]; /* P must point to the start of a Lisp_Cons, not be @@ -4107,7 +4107,7 @@ live_symbol_p (struct mem_node *m, void *p) { if (m->type == MEM_TYPE_SYMBOL) { - struct symbol_block *b = (struct symbol_block *) m->start; + struct symbol_block *b = m->start; ptrdiff_t offset = (char *) p - (char *) &b->symbols[0]; /* P must point to the start of a Lisp_Symbol, not be @@ -4133,7 +4133,7 @@ live_float_p (struct mem_node *m, void *p) { if (m->type == MEM_TYPE_FLOAT) { - struct float_block *b = (struct float_block *) m->start; + struct float_block *b = m->start; ptrdiff_t offset = (char *) p - (char *) &b->floats[0]; /* P must point to the start of a Lisp_Float and not be @@ -4157,7 +4157,7 @@ live_misc_p (struct mem_node *m, void *p) { if (m->type == MEM_TYPE_MISC) { - struct marker_block *b = (struct marker_block *) m->start; + struct marker_block *b = m->start; ptrdiff_t offset = (char *) p - (char *) &b->markers[0]; /* P must point to the start of a Lisp_Misc, not be @@ -4184,7 +4184,7 @@ live_vector_p (struct mem_node *m, void *p) if (m->type == MEM_TYPE_VECTOR_BLOCK) { /* This memory node corresponds to a vector block. */ - struct vector_block *block = (struct vector_block *) m->start; + struct vector_block *block = m->start; struct Lisp_Vector *vector = (struct Lisp_Vector *) block->data; /* P is in the block's allocation range. Scan the block -- cgit v1.2.1 From 5b71542de3ef7f08b7c30e93340502d7cc120910 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Wed, 14 Aug 2013 20:36:16 +0400 Subject: Utility function and macro to copy Lisp string to C string. * lisp.h (xlispstrdupa): New macro. (xlispstrdup): New prototype. * alloc.c (xlispstrdup): New function. * callint.c (Fcall_interactively): * fileio.c (Ffile_name_directory, Fexpand_file_name) (Fsubstitute_in_file_name): * frame.c (Fmake_terminal_frame): Use xlispstrdupa. * image.c (x_create_bitmap_from_file): * w32term.c (w32_term_init): * xterm.c (x_term_init): Use xlispstrdup. --- src/alloc.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index 2c2232601cb..c0d8c32b440 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -802,6 +802,15 @@ xstrdup (const char *s) return memcpy (xmalloc (size), s, size); } +/* Like above, but duplicates Lisp string to C string. */ + +char * +xlispstrdup (Lisp_Object string) +{ + ptrdiff_t size = SBYTES (string) + 1; + return memcpy (xmalloc (size), SSDATA (string), size); +} + /* Like putenv, but (1) use the equivalent of xmalloc and (2) the argument is a const pointer. */ -- cgit v1.2.1 From 0c5307b05f8a31204b409756248f30add802377c Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Wed, 21 Aug 2013 11:02:45 +0400 Subject: Fix compilation with GC_MARK_STACK == GC_USE_GCPROS_AS_BEFORE and GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES. * alloc.c (toplevel): Remove unnecessary nested #if...#endif. (mark_maybe_object) [!GC_MARK_STACK]: Define to emacs_abort to shut up compiler in mark_object. (dump_zombies): Convert to global and add EXTERNALLY_VISIBLE. --- src/alloc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index c0d8c32b440..81742e1ffc1 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -318,7 +318,6 @@ static void *min_heap_address, *max_heap_address; static struct mem_node mem_z; #define MEM_NIL &mem_z -#if GC_MARK_STACK || defined GC_MALLOC_CHECK static struct mem_node *mem_insert (void *, void *, enum mem_type); static void mem_insert_fixup (struct mem_node *); static void mem_rotate_left (struct mem_node *); @@ -326,7 +325,6 @@ static void mem_rotate_right (struct mem_node *); static void mem_delete (struct mem_node *); static void mem_delete_fixup (struct mem_node *); static struct mem_node *mem_find (void *); -#endif #endif /* GC_MARK_STACK || GC_MALLOC_CHECK */ @@ -4238,6 +4236,10 @@ live_buffer_p (struct mem_node *m, void *p) #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES +/* Currently not used, but may be called from gdb. */ + +void dump_zombies (void) EXTERNALLY_VISIBLE; + /* Array of objects that are kept alive because the C stack contains a pattern that looks like a reference to them . */ @@ -4620,7 +4622,7 @@ check_gcpros (void) #elif GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES -static void +void dump_zombies (void) { int i; @@ -4757,6 +4759,10 @@ mark_stack (void) #endif } +#else /* GC_MARK_STACK == 0 */ + +#define mark_maybe_object(obj) emacs_abort () + #endif /* GC_MARK_STACK != 0 */ -- cgit v1.2.1 From 1570ae92dcd05e68509aff5a68d091af9a653c88 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Mon, 26 Aug 2013 09:26:06 +0400 Subject: * alloc.c (sweep_vectors): Do not initialize 'block' twice. --- src/alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index 81742e1ffc1..70a23488613 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -2805,7 +2805,7 @@ vector_nbytes (struct Lisp_Vector *v) static void sweep_vectors (void) { - struct vector_block *block = vector_blocks, **bprev = &vector_blocks; + struct vector_block *block, **bprev = &vector_blocks; struct large_vector *lv, **lvprev = &large_vectors; struct Lisp_Vector *vector, *next; -- cgit v1.2.1 From 43aac990c339c0fc3304aa476ebc8ea8467f107e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 27 Aug 2013 11:47:55 -0700 Subject: Simplify EMACS_TIME-related code. This portability layer is no longer needed, since Emacs has been using struct timespec as a portability layer for some time. Merge from gnulib, incorporating: 2013-08-27 timespec: new convenience constants and function * src/atimer.h, src/buffer.h, src/dispextern.h, src/xgselect.h: Include rather than "systime.h"; that's all that's needed now. * src/dispnew.c: Include rather than "systime.h"; that's all that's needed now. * src/systime.h (EMACS_TIME): Remove. All uses changed to struct timespec. (EMACS_TIME_RESOLUTION): Remove. All uses changed to TIMESPEC_RESOLUTION. (LOG10_EMACS_TIME_RESOLUTION): Remove. All uses changed to LOG10_TIMESPEC_RESOLUTION. (EMACS_SECS, emacs_secs_addr): Remove. All uses changed to tv_sec. (EMACS_NSECS): Remove. All uses changed to tv_nsec. (make_emacs_time): Remove. All used changed to make_timespec. (invalid_timespec): Rename from invalid_emacs_time. All uses changed. (current_timespec): Rename from current_emacs_time. All uses changed. (add_emacs_time): Remove. All uses changed to timespec_add. (sub_emacs_time): Remove. All uses change dot timespec_sub. (EMACS_TIME_SIGN): Remove. All uses changed to timespec_sign. (timespec_valid_p): Rename from EMACS_TIME_VALID_P. All uses changed. (EMACS_TIME_FROM_DOUBLE): Remove. All uses changed to dtotimespec. (EMACS_TIME_TO_DOUBLE): Remove. All uses changed to timespectod. (current_timespec): Rename from current_emacs_time. All uses changed. (EMACS_TIME_EQ, EMACS_TIME_LT, EMACS_TIME_LE): Remove. All uses changed to timespec_cmp. * src/xgselect.c: Include , since our .h files don't. --- src/alloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index 70a23488613..ebb8ef58991 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -5233,7 +5233,7 @@ See Info node `(elisp)Garbage Collection'. */) ptrdiff_t i; bool message_p; ptrdiff_t count = SPECPDL_INDEX (); - EMACS_TIME start; + struct timespec start; Lisp_Object retval = Qnil; size_t tot_before = 0; @@ -5258,7 +5258,7 @@ See Info node `(elisp)Garbage Collection'. */) if (profiler_memory_running) tot_before = total_bytes_of_live_objects (); - start = current_emacs_time (); + start = current_timespec (); /* In case user calls debug_print during GC, don't let that cause a recursive GC. */ @@ -5521,9 +5521,9 @@ See Info node `(elisp)Garbage Collection'. */) /* Accumulate statistics. */ if (FLOATP (Vgc_elapsed)) { - EMACS_TIME since_start = sub_emacs_time (current_emacs_time (), start); + struct timespec since_start = timespec_sub (current_timespec (), start); Vgc_elapsed = make_float (XFLOAT_DATA (Vgc_elapsed) - + EMACS_TIME_TO_DOUBLE (since_start)); + + timespectod (since_start)); } gcs_done++; -- cgit v1.2.1 From 101ed2bbbd42b780675fabb7a990f7613b1fb154 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Thu, 29 Aug 2013 15:22:28 +0400 Subject: * alloc.c (Fmake_marker, build_marker): Zero need_adjustment field of new marker (for sanity and safety). --- src/alloc.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index ebb8ef58991..8417ef4982b 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -3479,6 +3479,7 @@ DEFUN ("make-marker", Fmake_marker, Smake_marker, 0, 0, 0, p->charpos = 0; p->next = NULL; p->insertion_type = 0; + p->need_adjustment = 0; return val; } @@ -3503,6 +3504,7 @@ build_marker (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t bytepos) m->charpos = charpos; m->bytepos = bytepos; m->insertion_type = 0; + m->need_adjustment = 0; m->next = BUF_MARKERS (buf); BUF_MARKERS (buf) = m; return obj; -- cgit v1.2.1