]> git.eshelyaron.com Git - emacs.git/commitdiff
Use offsetof instead of own definition
authorAndreas Schwab <schwab@linux-m68k.org>
Sun, 11 Jul 2010 18:34:43 +0000 (20:34 +0200)
committerAndreas Schwab <schwab@linux-m68k.org>
Sun, 11 Jul 2010 18:34:43 +0000 (20:34 +0200)
* lisp.h: Include <stddef.h>.
(OFFSETOF): Don't define.
(VECSIZE): Use offsetof instead of OFFSETOF.
(PSEUDOVECSIZE): Likewise.
* process.c (conv_sockaddr_to_lisp): Likewise.
* alloc.c: Don't include <stddef.h>.
* buffer.h (PER_BUFFER_VAR_OFFSET): Use offsetof.

src/ChangeLog
src/alloc.c
src/buffer.h
src/lisp.h
src/process.c

index 48ba055280ca3d7e1e7afe968396070612df1007..2e5ea4658dc0376d2742eca545622d328a46c965 100644 (file)
@@ -1,5 +1,13 @@
 2010-07-11  Andreas Schwab  <schwab@linux-m68k.org>
 
+       * lisp.h: Include <stddef.h>.
+       (OFFSETOF): Don't define.
+       (VECSIZE): Use offsetof instead of OFFSETOF.
+       (PSEUDOVECSIZE): Likewise.
+       * process.c (conv_sockaddr_to_lisp): Likewise.
+       * alloc.c: Don't include <stddef.h>.
+       * buffer.h (PER_BUFFER_VAR_OFFSET): Use offsetof.
+
        * process.c: Remove obsolete comment.
 
 2010-07-11  Chong Yidong  <cyd@stupidchicken.com>
index 02c6022e47503402b1bedbad384ef4fe18480fb9..5c860bc1f8e6812d7431b05846fad63e5167308e 100644 (file)
@@ -23,10 +23,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <limits.h>            /* For CHAR_BIT.  */
 #include <setjmp.h>
 
-#ifdef STDC_HEADERS
-#include <stddef.h>            /* For offsetof, used by PSEUDOVECSIZE. */
-#endif
-
 #ifdef ALLOC_DEBUG
 #undef INLINE
 #endif
index 8e4e5d569ae0cc3dc96a057b6b81850c6572446e..339e7d9bb6dfc53a97a6748e48da6971e4957456 100644 (file)
@@ -954,7 +954,7 @@ extern int last_per_buffer_idx;
    from the start of a buffer structure.  */
 
 #define PER_BUFFER_VAR_OFFSET(VAR) \
-  ((char *) &((struct buffer *)0)->VAR - (char *) ((struct buffer *)0))
+  offsetof (struct buffer, VAR)
 
 /* Return the index of buffer-local variable VAR.  Each per-buffer
    variable has an index > 0 associated with it, except when it always
index d59b75caa2f1435ddac6fef7b777028564397493..656e8fbb62481a379d7def3edfb29e0456349d15 100644 (file)
@@ -22,6 +22,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #define EMACS_LISP_H
 
 #include <stdarg.h>
+#include <stddef.h>
 
 /* Use the configure flag --enable-checking[=LIST] to enable various
    types of run time checks for Lisp objects.  */
@@ -784,13 +785,6 @@ struct Lisp_String
     unsigned char *data;
   };
 
-#ifdef offsetof
-#define OFFSETOF(type,field) offsetof(type,field)
-#else
-#define OFFSETOF(type,field) \
-  ((int)((char*)&((type*)0)->field - (char*)0))
-#endif
-
 struct Lisp_Vector
   {
     EMACS_UINT size;
@@ -801,7 +795,7 @@ struct Lisp_Vector
 /* If a struct is made to look like a vector, this macro returns the length
    of the shortest vector that would hold that struct.  */
 #define VECSIZE(type) ((sizeof (type)                                    \
-                       - OFFSETOF (struct Lisp_Vector, contents[0])      \
+                       - offsetof (struct Lisp_Vector, contents[0])      \
                         + sizeof(Lisp_Object) - 1) /* round up */        \
                       / sizeof (Lisp_Object))
 
@@ -809,7 +803,7 @@ struct Lisp_Vector
    at the end and we need to compute the number of Lisp_Object fields (the
    ones that the GC needs to trace).  */
 #define PSEUDOVECSIZE(type, nonlispfield) \
-  ((OFFSETOF(type, nonlispfield) - OFFSETOF(struct Lisp_Vector, contents[0])) \
+  ((offsetof(type, nonlispfield) - offsetof(struct Lisp_Vector, contents[0])) \
    / sizeof (Lisp_Object))
 
 /* A char-table is a kind of vectorlike, with contents are like a
index ed31657b01c425e74efcb847a84a38b1b75dfaa2..0fec550ad8f46783316ea0a0aeabe7a881bd0fb1 100644 (file)
@@ -2263,7 +2263,7 @@ conv_sockaddr_to_lisp (struct sockaddr *sa, int len)
   /* Workaround for a bug in getsockname on BSD: Names bound to
      sockets in the UNIX domain are inaccessible; getsockname returns
      a zero length name.  */
-  if (len < OFFSETOF (struct sockaddr, sa_family) + sizeof (sa->sa_family))
+  if (len < offsetof (struct sockaddr, sa_family) + sizeof (sa->sa_family))
     return empty_unibyte_string;
 
   switch (sa->sa_family)
@@ -2303,7 +2303,7 @@ conv_sockaddr_to_lisp (struct sockaddr *sa, int len)
       }
 #endif
     default:
-      len -= OFFSETOF (struct sockaddr, sa_family) + sizeof (sa->sa_family);
+      len -= offsetof (struct sockaddr, sa_family) + sizeof (sa->sa_family);
       address = Fcons (make_number (sa->sa_family),
                       Fmake_vector (make_number (len), Qnil));
       p = XVECTOR (XCDR (address));