diff options
author | patthoyts <patthoyts@users.sourceforge.net> | 2007-08-01 13:27:46 (GMT) |
---|---|---|
committer | patthoyts <patthoyts@users.sourceforge.net> | 2007-08-01 13:27:46 (GMT) |
commit | 151923cca7b86c51a2292b427fbf70e75b05bbe3 (patch) | |
tree | 21bf6522d2470c253e81d43377bbbb994415144c | |
parent | 24d28892567192aedf221dde8efe1939487fd017 (diff) | |
download | tcl-151923cca7b86c51a2292b427fbf70e75b05bbe3.zip tcl-151923cca7b86c51a2292b427fbf70e75b05bbe3.tar.gz tcl-151923cca7b86c51a2292b427fbf70e75b05bbe3.tar.bz2 |
Abstracted the 'offsetof' to a TclOffset macro as per Tk_Offset to permit
compilation with MSVC6 and anything else that may not define this macro.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | generic/tclExecute.c | 4 | ||||
-rw-r--r-- | generic/tclInt.h | 14 | ||||
-rw-r--r-- | generic/tclVar.c | 4 |
4 files changed, 23 insertions, 5 deletions
@@ -1,3 +1,9 @@ +2007-08-01 Pat Thoyts <patthoyts@users.sourceforge.net> + + * generic/tclInt.h: Added a TclOffset macro ala Tk_Offset to + * generic/tclVar.c: abstract out 'offsetof' which may not be + * generic/tclExceute.c: defined (eg: msvc6). + 2007-08-01 Miguel Sofer <msofer@users.sf.net> * generic/tclVar.c (TclCleanupVar): fix [Bug 1765225], thx Larry diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 1112c40..fe625a8 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclExecute.c,v 1.307 2007/07/31 17:03:37 msofer Exp $ + * RCS: @(#) $Id: tclExecute.c,v 1.308 2007/08/01 13:27:47 patthoyts Exp $ */ #include "tclInt.h" @@ -181,7 +181,7 @@ static BuiltinFunc tclBuiltinFuncTable[] = { */ #define VarHashGetValue(hPtr) \ - ((Var *) ((char *)hPtr - offsetof(VarInHash, entry))) + ((Var *) ((char *)hPtr - TclOffset(VarInHash, entry))) static inline Var * VarHashCreateVar(TclVarHashTable *tablePtr, Tcl_Obj *key, int *newPtr) diff --git a/generic/tclInt.h b/generic/tclInt.h index 032a2f6..947d6ec 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclInt.h,v 1.325 2007/07/31 17:03:38 msofer Exp $ + * RCS: @(#) $Id: tclInt.h,v 1.326 2007/08/01 13:27:47 patthoyts Exp $ */ #ifndef _TCLINT @@ -3488,6 +3488,18 @@ MODULE_SCOPE void TclBNInitBignumFromWideUInt(mp_int *bignum, #endif /* + * ---------------------------------------------------------------------- + * Macro to use to find the offset of a field in a structure. + * Computes number of bytes from beginning of structure to a given field. + */ + +#ifdef offsetof +#define TclOffset(type, field) ((int) offsetof(type, field)) +#else +#define TclOffset(type, field) ((int) ((char *) &((type *) 0)->field)) +#endif + +/* *---------------------------------------------------------------- * Inline version of Tcl_GetCurrentNamespace and Tcl_GetGlobalNamespace */ diff --git a/generic/tclVar.c b/generic/tclVar.c index 967f539..58849c0 100644 --- a/generic/tclVar.c +++ b/generic/tclVar.c @@ -16,7 +16,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclVar.c,v 1.146 2007/08/01 12:09:04 msofer Exp $ + * RCS: @(#) $Id: tclVar.c,v 1.147 2007/08/01 13:27:48 patthoyts Exp $ */ #include "tclInt.h" @@ -46,7 +46,7 @@ static inline Var * VarHashNextVar(Tcl_HashSearch *searchPtr); static inline void CleanupVar(Var *varPtr, Var *arrayPtr); #define VarHashGetValue(hPtr) \ - ((Var *) ((char *)hPtr - offsetof(VarInHash, entry))) + ((Var *) ((char *)hPtr - TclOffset(VarInHash, entry))) static inline Var * VarHashCreateVar(TclVarHashTable *tablePtr, Tcl_Obj *key, int *newPtr) |