# HG changeset patch # User Andreas Schwab # Date 1278873283 -7200 # Node ID a0d2db31314d7ae789270ac8c81031cd0a0a20d7 # Parent 108c259501dacb7bb0460e2e617e0022c5f11bde Use offsetof instead of own definition * lisp.h: Include . (OFFSETOF): Don't define. (VECSIZE): Use offsetof instead of OFFSETOF. (PSEUDOVECSIZE): Likewise. * process.c (conv_sockaddr_to_lisp): Likewise. * alloc.c: Don't include . * buffer.h (PER_BUFFER_VAR_OFFSET): Use offsetof. diff -r 108c259501da -r a0d2db31314d src/ChangeLog --- a/src/ChangeLog Sun Jul 11 20:19:16 2010 +0200 +++ b/src/ChangeLog Sun Jul 11 20:34:43 2010 +0200 @@ -1,5 +1,13 @@ 2010-07-11 Andreas Schwab + * lisp.h: Include . + (OFFSETOF): Don't define. + (VECSIZE): Use offsetof instead of OFFSETOF. + (PSEUDOVECSIZE): Likewise. + * process.c (conv_sockaddr_to_lisp): Likewise. + * alloc.c: Don't include . + * buffer.h (PER_BUFFER_VAR_OFFSET): Use offsetof. + * process.c: Remove obsolete comment. 2010-07-11 Chong Yidong diff -r 108c259501da -r a0d2db31314d src/alloc.c --- a/src/alloc.c Sun Jul 11 20:19:16 2010 +0200 +++ b/src/alloc.c Sun Jul 11 20:34:43 2010 +0200 @@ -23,10 +23,6 @@ #include /* For CHAR_BIT. */ #include -#ifdef STDC_HEADERS -#include /* For offsetof, used by PSEUDOVECSIZE. */ -#endif - #ifdef ALLOC_DEBUG #undef INLINE #endif diff -r 108c259501da -r a0d2db31314d src/buffer.h --- a/src/buffer.h Sun Jul 11 20:19:16 2010 +0200 +++ b/src/buffer.h Sun Jul 11 20:34:43 2010 +0200 @@ -954,7 +954,7 @@ 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 diff -r 108c259501da -r a0d2db31314d src/lisp.h --- a/src/lisp.h Sun Jul 11 20:19:16 2010 +0200 +++ b/src/lisp.h Sun Jul 11 20:34:43 2010 +0200 @@ -22,6 +22,7 @@ #define EMACS_LISP_H #include +#include /* Use the configure flag --enable-checking[=LIST] to enable various types of run time checks for Lisp objects. */ @@ -784,13 +785,6 @@ 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 @@ /* 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 @@ 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 diff -r 108c259501da -r a0d2db31314d src/process.c --- a/src/process.c Sun Jul 11 20:19:16 2010 +0200 +++ b/src/process.c Sun Jul 11 20:34:43 2010 +0200 @@ -2263,7 +2263,7 @@ /* 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 @@ } #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));