diff options
| author | donal.k.fellows@manchester.ac.uk <dkf> | 2012-12-19 11:43:40 (GMT) |
|---|---|---|
| committer | donal.k.fellows@manchester.ac.uk <dkf> | 2012-12-19 11:43:40 (GMT) |
| commit | bc87bbb4d9b94ea5b2716adde55d18f632b82768 (patch) | |
| tree | acb9b00e796181e99a10ffb0d8552cf7318e5a33 /generic/tclZlib.c | |
| parent | 3e55ef9d38f9ad0ce68ab947b51a37b144046100 (diff) | |
| parent | 52f5b9733f350a2667c73be72e0add3225bf327c (diff) | |
| download | tcl-bc87bbb4d9b94ea5b2716adde55d18f632b82768.zip tcl-bc87bbb4d9b94ea5b2716adde55d18f632b82768.tar.gz tcl-bc87bbb4d9b94ea5b2716adde55d18f632b82768.tar.bz2 | |
merge main dev branch
Diffstat (limited to 'generic/tclZlib.c')
| -rw-r--r-- | generic/tclZlib.c | 71 |
1 files changed, 31 insertions, 40 deletions
diff --git a/generic/tclZlib.c b/generic/tclZlib.c index 11490f1..9c1176e 100644 --- a/generic/tclZlib.c +++ b/generic/tclZlib.c @@ -507,7 +507,7 @@ GenerateHeader( * ExtractHeader -- * * Take the values out of a gzip header and store them in a dictionary. - * SetValue is a helper function. + * SetValue is a helper macro. * * Results: * None. @@ -518,18 +518,8 @@ GenerateHeader( *---------------------------------------------------------------------- */ -static inline void -SetValue( - Tcl_Obj *dictObj, - const char *key, - Tcl_Obj *value) -{ - Tcl_Obj *keyObj = Tcl_NewStringObj(key, -1); - - Tcl_IncrRefCount(keyObj); - Tcl_DictObjPut(NULL, dictObj, keyObj, value); - TclDecrRefCount(keyObj); -} +#define SetValue(dictObj, key, value) \ + Tcl_DictObjPut(NULL, (dictObj), Tcl_NewStringObj((key), -1), (value)) static void ExtractHeader( @@ -2119,9 +2109,6 @@ ZlibCmd( } if (headerVarObj != NULL && Tcl_ObjSetVar2(interp, headerVarObj, NULL, headerDictObj, TCL_LEAVE_ERR_MSG) == NULL) { - if (headerDictObj) { - TclDecrRefCount(headerDictObj); - } return TCL_ERROR; } return TCL_OK; @@ -2177,29 +2164,36 @@ ZlibStreamSubcmd( FMT_INFLATE }; int i, format, mode = 0, option, level; + enum objIndices { + OPT_COMPRESSION_DICTIONARY = 0, + OPT_GZIP_HEADER = 1, + OPT_COMPRESSION_LEVEL = 2, + OPT_END = -1 + }; + Tcl_Obj *obj[3] = { NULL, NULL, NULL }; +#define compDictObj obj[OPT_COMPRESSION_DICTIONARY] +#define gzipHeaderObj obj[OPT_GZIP_HEADER] +#define levelObj obj[OPT_COMPRESSION_LEVEL] typedef struct { const char *name; - Tcl_Obj **valueVar; + enum objIndices offset; } OptDescriptor; - Tcl_Obj *compDictObj = NULL; - Tcl_Obj *gzipHeaderObj = NULL; - Tcl_Obj *levelObj = NULL; - const OptDescriptor compressionOpts[] = { - { "-dictionary", &compDictObj }, - { "-level", &levelObj }, - { NULL, NULL } + static const OptDescriptor compressionOpts[] = { + { "-dictionary", OPT_COMPRESSION_DICTIONARY }, + { "-level", OPT_COMPRESSION_LEVEL }, + { NULL, OPT_END } }; - const OptDescriptor gzipOpts[] = { - { "-header", &gzipHeaderObj }, - { "-level", &levelObj }, - { NULL, NULL } + static const OptDescriptor gzipOpts[] = { + { "-header", OPT_GZIP_HEADER }, + { "-level", OPT_COMPRESSION_LEVEL }, + { NULL, OPT_END } }; - const OptDescriptor expansionOpts[] = { - { "-dictionary", &compDictObj }, - { NULL, NULL } + static const OptDescriptor expansionOpts[] = { + { "-dictionary", OPT_COMPRESSION_DICTIONARY }, + { NULL, OPT_END } }; - const OptDescriptor gunzipOpts[] = { - { NULL, NULL } + static const OptDescriptor gunzipOpts[] = { + { NULL, OPT_END } }; const OptDescriptor *desc = NULL; Tcl_ZlibStream zh; @@ -2262,13 +2256,7 @@ ZlibStreamSubcmd( sizeof(OptDescriptor), "option", 0, &option) != TCL_OK) { return TCL_ERROR; } - *desc[option].valueVar = objv[i+1]; - - /* - * Drop the cache on the option name; table address not constant. - */ - - TclFreeIntRep(objv[i]); + obj[desc[option].offset] = objv[i+1]; } /* @@ -2300,6 +2288,9 @@ ZlibStreamSubcmd( } Tcl_SetObjResult(interp, Tcl_ZlibStreamGetCommandName(zh)); return TCL_OK; +#undef compDictObj +#undef gzipHeaderObj +#undef levelObj } /* |
