emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r109987: Prefer assignment to memcpy


From: Paul Eggert
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r109987: Prefer assignment to memcpy when either will do.
Date: Tue, 11 Sep 2012 15:59:50 -0700
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 109987
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Tue 2012-09-11 15:59:50 -0700
message:
  Prefer assignment to memcpy when either will do.
  
  * lib-src/pop.c (socket_connection) [HAVE_GETADDRINFO]:
  * src/bidi.c (bidi_push_it, bidi_pop_it):
  * src/fns.c (copy_hash_table):
  * src/image.c (define_image_type):
  * src/keyboard.c (kbd_buffer_store_event_hold):
  * src/process.c (Fprocess_send_eof):
  * src/xfaces.c (x_create_gc) [HAVE_NS]:
  * src/xgselect.c (xg_select):
  Use assignment, not memcpy, as either will do here, and assignment is
  more likely to catch type errors.
modified:
  lib-src/ChangeLog
  lib-src/pop.c
  src/ChangeLog
  src/bidi.c
  src/fns.c
  src/image.c
  src/keyboard.c
  src/process.c
  src/xfaces.c
  src/xgselect.c
=== modified file 'lib-src/ChangeLog'
--- a/lib-src/ChangeLog 2012-08-31 16:53:48 +0000
+++ b/lib-src/ChangeLog 2012-09-11 22:59:50 +0000
@@ -1,3 +1,8 @@
+2012-09-11  Paul Eggert  <address@hidden>
+
+       * pop.c (socket_connection) [HAVE_GETADDRINFO]:
+       Prefer assignment to memcpy when either will do.
+
 2012-08-31  Andreas Schwab  <address@hidden>
 
        * etags.c (consider_token): Always zero-terminate token buffer.

=== modified file 'lib-src/pop.c'
--- a/lib-src/pop.c     2012-07-10 21:48:34 +0000
+++ b/lib-src/pop.c     2012-09-11 22:59:50 +0000
@@ -1083,7 +1083,7 @@
           if (it->ai_addrlen == sizeof (addr))
             {
               struct sockaddr_in *in_a = (struct sockaddr_in *) it->ai_addr;
-              memcpy (&addr.sin_addr, &in_a->sin_addr, sizeof (addr.sin_addr));
+              addr.sin_addr = in_a->sin_addr;
               if (! connect (sock, (struct sockaddr *) &addr, sizeof (addr)))
                 break;
             }

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-09-11 20:35:23 +0000
+++ b/src/ChangeLog     2012-09-11 22:59:50 +0000
@@ -1,5 +1,14 @@
 2012-09-11  Paul Eggert  <address@hidden>
 
+       * bidi.c (bidi_push_it, bidi_pop_it):
+       * fns.c (copy_hash_table):
+       * image.c (define_image_type):
+       * keyboard.c (kbd_buffer_store_event_hold):
+       * process.c (Fprocess_send_eof):
+       * xfaces.c (x_create_gc) [HAVE_NS]:
+       * xgselect.c (xg_select):
+       Prefer assignment to memcpy when either will do.
+
        * alloc.c (discard_killed_buffers): Tune and simplify a bit.
        Use pointer-to-a-pointer to simplify and avoid a NILP check each
        time an item is removed.  No need to mark this function 'inline';

=== modified file 'src/bidi.c'
--- a/src/bidi.c        2012-09-04 17:34:54 +0000
+++ b/src/bidi.c        2012-09-11 22:59:50 +0000
@@ -612,7 +612,7 @@
   /* Save the current iterator state in its entirety after the last
      used cache slot.  */
   bidi_cache_ensure_space (bidi_cache_idx);
-  memcpy (&bidi_cache[bidi_cache_idx++], bidi_it, sizeof (struct bidi_it));
+  bidi_cache[bidi_cache_idx++] = *bidi_it;
 
   /* Push the current cache start onto the stack.  */
   eassert (bidi_cache_sp < IT_STACK_SIZE);
@@ -636,7 +636,7 @@
   bidi_cache_idx = bidi_cache_start - 1;
 
   /* Restore the bidi iterator state saved in the cache.  */
-  memcpy (bidi_it, &bidi_cache[bidi_cache_idx], sizeof (struct bidi_it));
+  *bidi_it = bidi_cache[bidi_cache_idx];
 
   /* Pop the previous cache start from the stack.  */
   if (bidi_cache_sp <= 0)

=== modified file 'src/fns.c'
--- a/src/fns.c 2012-09-10 03:25:10 +0000
+++ b/src/fns.c 2012-09-11 22:59:50 +0000
@@ -3680,7 +3680,7 @@
 
   h2 = allocate_hash_table ();
   next = h2->header.next.vector;
-  memcpy (h2, h1, sizeof *h2);
+  *h2 = *h1;
   h2->header.next.vector = next;
   h2->key_and_value = Fcopy_sequence (h1->key_and_value);
   h2->hash = Fcopy_sequence (h1->hash);

=== modified file 'src/image.c'
--- a/src/image.c       2012-09-09 16:06:33 +0000
+++ b/src/image.c       2012-09-11 22:59:50 +0000
@@ -593,7 +593,7 @@
       /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
          The initialized data segment is read-only.  */
       struct image_type *p = xmalloc (sizeof *p);
-      memcpy (p, type, sizeof *p);
+      *p = *type;
       p->next = image_types;
       image_types = p;
       success = Qt;

=== modified file 'src/keyboard.c'
--- a/src/keyboard.c    2012-09-07 01:27:44 +0000
+++ b/src/keyboard.c    2012-09-11 22:59:50 +0000
@@ -3602,7 +3602,7 @@
 
          if (hold_quit)
            {
-             memcpy (hold_quit, event, sizeof (*event));
+             *hold_quit = *event;
              return;
            }
 

=== modified file 'src/process.c'
--- a/src/process.c     2012-09-11 04:22:03 +0000
+++ b/src/process.c     2012-09-11 22:59:50 +0000
@@ -6367,9 +6367,8 @@
       if (!proc_encode_coding_system[new_outfd])
        proc_encode_coding_system[new_outfd]
          = xmalloc (sizeof (struct coding_system));
-      memcpy (proc_encode_coding_system[new_outfd],
-             proc_encode_coding_system[old_outfd],
-             sizeof (struct coding_system));
+      *proc_encode_coding_system[new_outfd]
+       = *proc_encode_coding_system[old_outfd];
       memset (proc_encode_coding_system[old_outfd], 0,
              sizeof (struct coding_system));
 

=== modified file 'src/xfaces.c'
--- a/src/xfaces.c      2012-09-04 17:34:54 +0000
+++ b/src/xfaces.c      2012-09-11 22:59:50 +0000
@@ -661,7 +661,7 @@
             XGCValues *xgcv)
 {
   GC gc = xmalloc (sizeof *gc);
-  memcpy (gc, xgcv, sizeof (XGCValues));
+  *gc = *xgcv;
   return gc;
 }
 

=== modified file 'src/xgselect.c'
--- a/src/xgselect.c    2012-08-25 20:31:04 +0000
+++ b/src/xgselect.c    2012-09-11 22:59:50 +0000
@@ -49,9 +49,9 @@
         && g_main_context_pending (context = g_main_context_default ())))
     return pselect (fds_lim, rfds, wfds, efds, timeout, sigmask);
 
-  if (rfds) memcpy (&all_rfds, rfds, sizeof (all_rfds));
+  if (rfds) all_rfds = *rfds;
   else FD_ZERO (&all_rfds);
-  if (wfds) memcpy (&all_wfds, wfds, sizeof (all_rfds));
+  if (wfds) all_wfds = *wfds;
   else FD_ZERO (&all_wfds);
 
   n_gfds = g_main_context_query (context, G_PRIORITY_LOW, &tmo_in_millisec,


reply via email to

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