]> git.eshelyaron.com Git - emacs.git/commitdiff
* alloc.c (allocate_window): Zero out non-Lisp part of newly
authorDmitry Antipov <dmantipov@yandex.ru>
Tue, 26 Jun 2012 14:41:01 +0000 (18:41 +0400)
committerDmitry Antipov <dmantipov@yandex.ru>
Tue, 26 Jun 2012 14:41:01 +0000 (18:41 +0400)
allocated window.
(allocate_process): Likewise for new process.
(allocate_terminal): Changed to use offsetof.
(allocate_frame): Likewise.
* frame.c (make_frame): Omit redundant initialization.
* window.c (make_parent_window): Use memset.
(make_window): Omit redundant initialization.
* process.c (make_process): Omit redundant initialization.
* terminal.c (create_terminal): Likewise.

src/ChangeLog
src/alloc.c
src/frame.c
src/process.c
src/terminal.c
src/window.c

index 9c6bf77785bfdc62d608fbb9e73f4f609a93a725..c7922ee8a8c47fbc8751017e5ed128d4dba496f4 100644 (file)
@@ -1,3 +1,16 @@
+2012-06-26  Dmitry Antipov  <dmantipov@yandex.ru>
+
+       * alloc.c (allocate_window): Zero out non-Lisp part of newly
+       allocated window.
+       (allocate_process): Likewise for new process.
+       (allocate_terminal): Changed to use offsetof.
+       (allocate_frame): Likewise.
+       * frame.c (make_frame): Omit redundant initialization.
+       * window.c (make_parent_window): Use memset.
+       (make_window): Omit redundant initialization.
+       * process.c (make_process): Omit redundant initialization.
+       * terminal.c (create_terminal): Likewise.
+
 2012-06-26  Dmitry Antipov  <dmantipov@yandex.ru>
 
        * term.c (delete_tty): Remove redundant call to memset.
index 6f7cc968b81d6ae489e515d7a8e7f5c7a216fd54..7f9574d43d115231028e40fc3ad9e60f00e51818 100644 (file)
@@ -3278,44 +3278,53 @@ allocate_hash_table (void)
   return ALLOCATE_PSEUDOVECTOR (struct Lisp_Hash_Table, count, PVEC_HASH_TABLE);
 }
 
-
 struct window *
 allocate_window (void)
 {
-  return ALLOCATE_PSEUDOVECTOR (struct window, current_matrix, PVEC_WINDOW);
-}
+  struct window *w;
 
+  w = ALLOCATE_PSEUDOVECTOR (struct window, current_matrix, PVEC_WINDOW);
+  /* Users assumes that non-Lisp data is zeroed.  */
+  memset (&w->current_matrix, 0,
+         sizeof (*w) - offsetof (struct window, current_matrix));
+  return w;
+}
 
 struct terminal *
 allocate_terminal (void)
 {
-  struct terminal *t = ALLOCATE_PSEUDOVECTOR (struct terminal,
-                                             next_terminal, PVEC_TERMINAL);
-  /* Zero out the non-GC'd fields.  FIXME: This should be made unnecessary.  */
-  memset (&t->next_terminal, 0,
-         (char*) (t + 1) - (char*) &t->next_terminal);
+  struct terminal *t;
 
+  t = ALLOCATE_PSEUDOVECTOR (struct terminal, next_terminal, PVEC_TERMINAL);
+  /* Users assumes that non-Lisp data is zeroed.  */
+  memset (&t->next_terminal, 0,
+         sizeof (*t) - offsetof (struct terminal, next_terminal));
   return t;
 }
 
 struct frame *
 allocate_frame (void)
 {
-  struct frame *f = ALLOCATE_PSEUDOVECTOR (struct frame,
-                                          face_cache, PVEC_FRAME);
-  /* Zero out the non-GC'd fields.  FIXME: This should be made unnecessary.  */
+  struct frame *f;
+
+  f = ALLOCATE_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
+  /* Users assumes that non-Lisp data is zeroed.  */
   memset (&f->face_cache, 0,
-         (char *) (f + 1) - (char *) &f->face_cache);
+         sizeof (*f) - offsetof (struct frame, face_cache));
   return f;
 }
 
-
 struct Lisp_Process *
 allocate_process (void)
 {
-  return ALLOCATE_PSEUDOVECTOR (struct Lisp_Process, pid, PVEC_PROCESS);
-}
+  struct Lisp_Process *p;
 
+  p = ALLOCATE_PSEUDOVECTOR (struct Lisp_Process, pid, PVEC_PROCESS);
+  /* Users assumes that non-Lisp data is zeroed.  */
+  memset (&p->pid, 0,
+         sizeof (*p) - offsetof (struct Lisp_Process, pid));
+  return p;
+}
 
 DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0,
        doc: /* Return a newly created vector of length LENGTH, with each element being INIT.
index fc52b07923dfc02a35ccb208963647c8c7186fe8..b048327abfb7d81fa1997e9800692e45103eb3b2 100644 (file)
@@ -267,63 +267,23 @@ make_frame (int mini_p)
   f = allocate_frame ();
   XSETFRAME (frame, f);
 
-  f->desired_matrix = 0;
-  f->current_matrix = 0;
-  f->desired_pool = 0;
-  f->current_pool = 0;
-  f->glyphs_initialized_p = 0;
-  f->decode_mode_spec_buffer = 0;
-  f->visible = 0;
-  f->async_visible = 0;
-  f->output_data.nothing = 0;
-  f->iconified = 0;
-  f->async_iconified = 0;
+  /* Initialize Lisp data.  Note that allocate_frame initializes all
+     Lisp data to nil, so do it only for slots which should not be nil.  */
+  f->tool_bar_position = Qtop;
+
+  /* Initialize non-Lisp data.  Note that allocate_frame zeroes out all
+     non-Lisp data, so do it only for slots which should not be zero.
+     To avoid subtle bugs and for the sake of readability, it's better to
+     initialize enum members explicitly even if their values are zero.  */
   f->wants_modeline = 1;
-  f->auto_raise = 0;
-  f->auto_lower = 0;
-  f->no_split = 0;
   f->garbaged = 1;
   f->has_minibuffer = mini_p;
-  f->focus_frame = Qnil;
-  f->explicit_name = 0;
-  f->can_have_scroll_bars = 0;
   f->vertical_scroll_bar_type = vertical_scroll_bar_none;
-  f->param_alist = Qnil;
-  f->scroll_bars = Qnil;
-  f->condemned_scroll_bars = Qnil;
-  f->face_alist = Qnil;
-  f->face_cache = NULL;
-  f->menu_bar_items = Qnil;
-  f->menu_bar_vector = Qnil;
-  f->menu_bar_items_used = 0;
-  f->buffer_predicate = Qnil;
-  f->buffer_list = Qnil;
-  f->buried_buffer_list = Qnil;
-  f->namebuf = 0;
-  f->title = Qnil;
-  f->menu_bar_window = Qnil;
-  f->tool_bar_window = Qnil;
-  f->tool_bar_items = Qnil;
-  f->tool_bar_position = Qtop;
-  f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
-  f->n_tool_bar_items = 0;
-  f->left_fringe_width = f->right_fringe_width = 0;
-  f->fringe_cols = 0;
-  f->menu_bar_lines = 0;
-  f->tool_bar_lines = 0;
-  f->scroll_bar_actual_width = 0;
-  f->border_width = 0;
-  f->internal_border_width = 0;
   f->column_width = 1;  /* !FRAME_WINDOW_P value */
   f->line_height = 1;  /* !FRAME_WINDOW_P value */
-  f->x_pixels_diff = f->y_pixels_diff = 0;
 #ifdef HAVE_WINDOW_SYSTEM
   f->want_fullscreen = FULLSCREEN_NONE;
 #endif
-  f->size_hint_flags = 0;
-  f->win_gravity = 0;
-  f->font_driver_list = NULL;
-  f->font_data_list = NULL;
 
   root_window = make_window ();
   if (mini_p)
@@ -399,8 +359,6 @@ make_frame (int mini_p)
   ++window_select_count;
   XSETFASTINT (XWINDOW (f->selected_window)->use_time, window_select_count);
 
-  f->default_face_done_p = 0;
-
   return f;
 }
 \f
index e39710078d241589666e2e33a319765483b598f0..1508e4b13fc03bb4c4086e9094a9d3f569554353 100644 (file)
@@ -625,35 +625,18 @@ make_process (Lisp_Object name)
   printmax_t i;
 
   p = allocate_process ();
-
-  p->infd = -1;
-  p->outfd = -1;
-  p->tick = 0;
-  p->update_tick = 0;
-  p->pid = 0;
-  p->pty_flag = 0;
-  p->raw_status_new = 0;
+  /* Initialize Lisp data.  Note that allocate_process initializes all
+     Lisp data to nil, so do it only for slots which should not be nil.  */
   p->status = Qrun;
   p->mark = Fmake_marker ();
-  p->kill_without_query = 0;
-  p->write_queue = Qnil;
 
-#ifdef ADAPTIVE_READ_BUFFERING
-  p->adaptive_read_buffering = 0;
-  p->read_output_delay = 0;
-  p->read_output_skip = 0;
-#endif
+  /* Initialize non-Lisp data.  Note that allocate_process zeroes out all
+     non-Lisp data, so do it only for slots which should not be zero.  */
+  p->infd = -1;
+  p->outfd = -1;
 
 #ifdef HAVE_GNUTLS
   p->gnutls_initstage = GNUTLS_STAGE_EMPTY;
-  /* Default log level.  */
-  p->gnutls_log_level = 0;
-  /* GnuTLS handshakes attempted for this connection.  */
-  p->gnutls_handshakes_tried = 0;
-  p->gnutls_p = 0;
-  p->gnutls_state = NULL;
-  p->gnutls_x509_cred = NULL;
-  p->gnutls_anon_cred = NULL;
 #endif
 
   /* If name is already in use, modify it until it is unused.  */
index 9579d1dbd665e7f3a6da8f659c1b3fcf695a1655..a3cae585d9a1edbde0f3d255f8f043ca49995f01 100644 (file)
@@ -225,7 +225,6 @@ create_terminal (void)
   struct terminal *terminal = allocate_terminal ();
   Lisp_Object terminal_coding, keyboard_coding;
 
-  terminal->name = NULL;
   terminal->next_terminal = terminal_list;
   terminal_list = terminal;
 
@@ -255,9 +254,6 @@ create_terminal (void)
   setup_coding_system (keyboard_coding, terminal->keyboard_coding);
   setup_coding_system (terminal_coding, terminal->terminal_coding);
 
-  terminal->param_alist = Qnil;
-  terminal->charset_list = Qnil;
-  terminal->Vselection_alist = Qnil;
   return terminal;
 }
 
index 9420d733bc13be3a72819d04e2cd86ec2ffd1616..05749c12bb9d1cec6c0f632981497d3bb89246f4 100644 (file)
@@ -3242,13 +3242,12 @@ make_parent_window (Lisp_Object window, int horflag)
 {
   Lisp_Object parent;
   register struct window *o, *p;
-  int i;
 
   o = XWINDOW (window);
   p = allocate_window ();
-  for (i = 0; i < VECSIZE (struct window); ++i)
-    ((struct Lisp_Vector *) p)->contents[i]
-      = ((struct Lisp_Vector *) o)->contents[i];
+  memcpy ((char *) p + sizeof (struct vectorlike_header), 
+         (char *) o + sizeof (struct vectorlike_header),
+         sizeof (Lisp_Object) * VECSIZE (struct window));
   XSETWINDOW (parent, p);
 
   ++sequence_number;
@@ -3277,10 +3276,8 @@ make_window (void)
   register struct window *w;
 
   w = allocate_window ();
-  /* Initialize all Lisp data.  */
-  w->frame = Qnil;
-  w->mini = 0;
-  w->next = w->prev = w->hchild = w->vchild = w->parent = Qnil;
+  /* Initialize Lisp data.  Note that allocate_window initializes all
+     Lisp data to nil, so do it only for slots which should not be nil.  */
   XSETFASTINT (w->left_col, 0);
   XSETFASTINT (w->top_line, 0);
   XSETFASTINT (w->total_lines, 0);
@@ -3289,47 +3286,24 @@ make_window (void)
   w->normal_cols = make_float (1.0);
   XSETFASTINT (w->new_total, 0);
   XSETFASTINT (w->new_normal, 0);
-  w->buffer = Qnil;
   w->start = Fmake_marker ();
   w->pointm = Fmake_marker ();
-  w->force_start = w->optional_new_start = 0;
   XSETFASTINT (w->hscroll, 0);
   XSETFASTINT (w->min_hscroll, 0);
   XSETFASTINT (w->use_time, 0);
   ++sequence_number;
   XSETFASTINT (w->sequence_number, sequence_number);
-  w->temslot = w->last_modified = w->last_overlay_modified = Qnil;
   XSETFASTINT (w->last_point, 0);
-  w->last_had_star = 0;
-  w->vertical_scroll_bar = Qnil;
-  w->left_margin_cols = w->right_margin_cols = Qnil;
-  w->left_fringe_width = w->right_fringe_width = Qnil;
-  w->fringes_outside_margins = Qnil;
-  w->scroll_bar_width = Qnil;
   w->vertical_scroll_bar_type = Qt;
   XSETFASTINT (w->window_end_pos, 0);
   XSETFASTINT (w->window_end_vpos, 0);
-  w->window_end_valid = w->display_table = Qnil;
-  w->update_mode_line = w->start_at_line_beg = 0;
-  w->dedicated = Qnil;
-  w->base_line_number = w->base_line_pos = w->region_showing = Qnil;
-  w->column_number_displayed = w->redisplay_end_trigger = Qnil;
-  w->combination_limit = w->window_parameters = Qnil;
-  w->prev_buffers = w->next_buffers = Qnil;
-  /* Initialize non-Lisp data.  */
-  w->desired_matrix = w->current_matrix = 0;
+
+  /* Initialize non-Lisp data.  Note that allocate_window zeroes out all
+     non-Lisp data, so do it only for slots which should not be zero.  */
   w->nrows_scale_factor = w->ncols_scale_factor = 1;
-  memset (&w->cursor, 0, sizeof (w->cursor));
-  memset (&w->last_cursor, 0, sizeof (w->last_cursor));
-  memset (&w->phys_cursor, 0, sizeof (w->phys_cursor));
   w->phys_cursor_type = -1;
   w->phys_cursor_width = -1;
-  w->phys_cursor_on_p = 0;
-  w->last_cursor_off_p = w->cursor_off_p = 0;
-  w->must_be_updated_p = 0;
-  w->pseudo_window_p = 0;
-  w->frozen_window_start_p = 0;
-  w->vscroll = 0;
+
   /* Reset window_list.  */
   Vwindow_list = Qnil;
   /* Return window.  */