emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r108746: * alloc.c (allocate_window):


From: Dmitry Antipov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r108746: * alloc.c (allocate_window): Zero out non-Lisp part of newly
Date: Tue, 26 Jun 2012 18:41:01 +0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 108746
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Tue 2012-06-26 18:41:01 +0400
message:
  * 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.
modified:
  src/ChangeLog
  src/alloc.c
  src/frame.c
  src/process.c
  src/terminal.c
  src/window.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-06-26 05:40:33 +0000
+++ b/src/ChangeLog     2012-06-26 14:41:01 +0000
@@ -1,5 +1,18 @@
 2012-06-26  Dmitry Antipov  <address@hidden>
 
+       * 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  <address@hidden>
+
        * term.c (delete_tty): Remove redundant call to memset.
 
 2012-06-26  Dmitry Antipov  <address@hidden>

=== modified file 'src/alloc.c'
--- a/src/alloc.c       2012-06-26 05:00:30 +0000
+++ b/src/alloc.c       2012-06-26 14:41:01 +0000
@@ -3278,45 +3278,54 @@
   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.  */
+  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,
-         (char*) (t + 1) - (char*) &t->next_terminal);
-
+         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.
 See also the function `vector'.  */)

=== modified file 'src/frame.c'
--- a/src/frame.c       2012-06-19 06:49:50 +0000
+++ b/src/frame.c       2012-06-26 14:41:01 +0000
@@ -267,63 +267,23 @@
   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 @@
   ++window_select_count;
   XSETFASTINT (XWINDOW (f->selected_window)->use_time, window_select_count);
 
-  f->default_face_done_p = 0;
-
   return f;
 }
 

=== modified file 'src/process.c'
--- a/src/process.c     2012-06-24 20:34:48 +0000
+++ b/src/process.c     2012-06-26 14:41:01 +0000
@@ -625,35 +625,18 @@
   printmax_t i;
 
   p = allocate_process ();
+  /* 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 ();
 
+  /* 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;
-  p->tick = 0;
-  p->update_tick = 0;
-  p->pid = 0;
-  p->pty_flag = 0;
-  p->raw_status_new = 0;
-  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
 
 #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.  */

=== modified file 'src/terminal.c'
--- a/src/terminal.c    2012-01-19 07:21:25 +0000
+++ b/src/terminal.c    2012-06-26 14:41:01 +0000
@@ -225,7 +225,6 @@
   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 @@
   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;
 }
 

=== modified file 'src/window.c'
--- a/src/window.c      2012-06-19 16:56:28 +0000
+++ b/src/window.c      2012-06-26 14:41:01 +0000
@@ -3242,13 +3242,12 @@
 {
   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 @@
   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 @@
   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.  */


reply via email to

[Prev in Thread] Current Thread [Next in Thread]