diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2024-05-26 14:09:38 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2024-05-26 14:09:38 (GMT) |
commit | ee407b9bf60dbb8dac81770bcc01422decf03c2b (patch) | |
tree | d061081fc6918174fe2cb762c0d00bec4a78584d /generic | |
parent | bac8bdb8bb12e32bbec2724e1ce04959ce13bb8f (diff) | |
parent | b2214142f4719ab73e4979553e03e6daf1ad4508 (diff) | |
download | tcl-ee407b9bf60dbb8dac81770bcc01422decf03c2b.zip tcl-ee407b9bf60dbb8dac81770bcc01422decf03c2b.tar.gz tcl-ee407b9bf60dbb8dac81770bcc01422decf03c2b.tar.bz2 |
Merge 8.7
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclCmdMZ.c | 13 | ||||
-rw-r--r-- | generic/tclCompCmds.c | 16 | ||||
-rw-r--r-- | generic/tclCompCmdsSZ.c | 10 | ||||
-rw-r--r-- | generic/tclConfig.c | 2 | ||||
-rw-r--r-- | generic/tclDictObj.c | 147 | ||||
-rw-r--r-- | generic/tclDisassemble.c | 51 | ||||
-rw-r--r-- | generic/tclEncoding.c | 12 | ||||
-rw-r--r-- | generic/tclEnsemble.c | 5 | ||||
-rw-r--r-- | generic/tclEvent.c | 30 | ||||
-rw-r--r-- | generic/tclIOCmd.c | 3 | ||||
-rw-r--r-- | generic/tclInt.h | 8 | ||||
-rw-r--r-- | generic/tclInterp.c | 41 | ||||
-rw-r--r-- | generic/tclMain.c | 8 | ||||
-rw-r--r-- | generic/tclOOInfo.c | 6 | ||||
-rw-r--r-- | generic/tclProcess.c | 4 | ||||
-rw-r--r-- | generic/tclZipfs.c | 3 | ||||
-rw-r--r-- | generic/tclZlib.c | 88 |
17 files changed, 267 insertions, 180 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index 3effdf1..af97845 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -4850,16 +4850,13 @@ During( * release, or NULL if nothing is to be added. * Designed to be used with Tcl_ObjPrintf. */ { - Tcl_Obj *during, *options; + Tcl_Obj *options; if (errorInfo != NULL) { Tcl_AppendObjToErrorInfo(interp, errorInfo); } options = Tcl_GetReturnOptions(interp, resultCode); - TclNewLiteralStringObj(during, "-during"); - Tcl_IncrRefCount(during); - Tcl_DictObjPut(interp, options, during, oldOptions); - Tcl_DecrRefCount(during); + TclDictPut(interp, options, "-during", oldOptions); Tcl_IncrRefCount(options); Tcl_DecrRefCount(oldOptions); return options; @@ -4951,12 +4948,10 @@ TryPostBody( */ if (code == TCL_ERROR) { - Tcl_Obj *errorCodeName, *errcode, **bits1, **bits2; + Tcl_Obj *errcode, **bits1, **bits2; Tcl_Size len1, len2, j; - TclNewLiteralStringObj(errorCodeName, "-errorcode"); - Tcl_DictObjGet(NULL, options, errorCodeName, &errcode); - Tcl_DecrRefCount(errorCodeName); + TclDictGet(NULL, options, "-errorcode", &errcode); TclListObjGetElements(NULL, info[2], &len1, &bits1); if (TclListObjGetElements(NULL, errcode, &len2, &bits2) != TCL_OK) { diff --git a/generic/tclCompCmds.c b/generic/tclCompCmds.c index bad58f6..6d3eabd 100644 --- a/generic/tclCompCmds.c +++ b/generic/tclCompCmds.c @@ -2397,8 +2397,7 @@ DisassembleDictUpdateInfo( Tcl_ListObjAppendElement(NULL, variables, Tcl_NewWideIntObj(duiPtr->varIndices[i])); } - Tcl_DictObjPut(NULL, dictObj, Tcl_NewStringObj("variables", -1), - variables); + TclDictPut(NULL, dictObj, "variables", variables); } /* @@ -3136,14 +3135,13 @@ DisassembleForeachInfo( Tcl_ListObjAppendElement(NULL, objPtr, Tcl_NewWideIntObj(infoPtr->firstValueTemp + i)); } - Tcl_DictObjPut(NULL, dictObj, Tcl_NewStringObj("data", -1), objPtr); + TclDictPut(NULL, dictObj, "data", objPtr); /* * Loop counter. */ - Tcl_DictObjPut(NULL, dictObj, Tcl_NewStringObj("loop", -1), - Tcl_NewWideIntObj(infoPtr->loopCtTemp)); + TclDictPut(NULL, dictObj, "loop", Tcl_NewWideIntObj(infoPtr->loopCtTemp)); /* * Assignment targets. @@ -3159,7 +3157,7 @@ DisassembleForeachInfo( } Tcl_ListObjAppendElement(NULL, objPtr, innerPtr); } - Tcl_DictObjPut(NULL, dictObj, Tcl_NewStringObj("assign", -1), objPtr); + TclDictPut(NULL, dictObj, "assign", objPtr); } static void @@ -3178,8 +3176,8 @@ DisassembleNewForeachInfo( * Jump offset. */ - Tcl_DictObjPut(NULL, dictObj, Tcl_NewStringObj("jumpOffset", -1), - Tcl_NewWideIntObj(infoPtr->loopCtTemp)); + TclDictPut(NULL, dictObj, "jumpOffset", + Tcl_NewWideIntObj(infoPtr->loopCtTemp)); /* * Assignment targets. @@ -3195,7 +3193,7 @@ DisassembleNewForeachInfo( } Tcl_ListObjAppendElement(NULL, objPtr, innerPtr); } - Tcl_DictObjPut(NULL, dictObj, Tcl_NewStringObj("assign", -1), objPtr); + TclDictPut(NULL, dictObj, "assign", objPtr); } /* diff --git a/generic/tclCompCmdsSZ.c b/generic/tclCompCmdsSZ.c index bc37155..38fd8d6 100644 --- a/generic/tclCompCmdsSZ.c +++ b/generic/tclCompCmdsSZ.c @@ -2628,10 +2628,9 @@ DisassembleJumptableInfo( for (; hPtr ; hPtr = Tcl_NextHashEntry(&search)) { keyPtr = (const char *)Tcl_GetHashKey(&jtPtr->hashTable, hPtr); offset = PTR2INT(Tcl_GetHashValue(hPtr)); - Tcl_DictObjPut(NULL, mapping, Tcl_NewStringObj(keyPtr, -1), - Tcl_NewWideIntObj(offset)); + TclDictPut(NULL, mapping, keyPtr, Tcl_NewWideIntObj(offset)); } - Tcl_DictObjPut(NULL, dictObj, Tcl_NewStringObj("mapping", -1), mapping); + TclDictPut(NULL, dictObj, "mapping", mapping); } /* @@ -2739,11 +2738,10 @@ TclCompileThrowCmd( codeIsValid = codeIsList && (len != 0); if (codeIsValid) { - Tcl_Obj *errPtr, *dictPtr; + Tcl_Obj *dictPtr; - TclNewLiteralStringObj(errPtr, "-errorcode"); TclNewObj(dictPtr); - Tcl_DictObjPut(NULL, dictPtr, errPtr, objPtr); + TclDictPut(NULL, dictPtr, "-errorcode", objPtr); TclEmitPush(TclAddLiteralObj(envPtr, dictPtr, NULL), envPtr); } TclDecrRefCount(objPtr); diff --git a/generic/tclConfig.c b/generic/tclConfig.c index 9fb2fa7..7e77167 100644 --- a/generic/tclConfig.c +++ b/generic/tclConfig.c @@ -127,7 +127,7 @@ Tcl_RegisterConfig( */ for (cfg=configuration ; cfg->key!=NULL && cfg->key[0]!='\0' ; cfg++) { - Tcl_DictObjPut(interp, pkgDict, Tcl_NewStringObj(cfg->key, -1), + TclDictPut(interp, pkgDict, cfg->key, Tcl_NewByteArrayObj((unsigned char *)cfg->value, strlen(cfg->value))); } diff --git a/generic/tclDictObj.c b/generic/tclDictObj.c index 8c34bb8..3c6f352 100644 --- a/generic/tclDictObj.c +++ b/generic/tclDictObj.c @@ -1487,6 +1487,153 @@ Tcl_DbNewDictObj( } #endif +/***** START OF FUNCTIONS ACTING AS HELPERS *****/ + +/* + *---------------------------------------------------------------------- + * + * TclDictGet -- + * + * Given a key, get its value from the dictionary (or NULL if key is not + * found in dictionary.) + * + * Results: + * A standard Tcl result. The variable pointed to by valuePtrPtr is + * updated with the value for the key. Note that it is not an error for + * the key to have no mapping in the dictionary. + * + * Side effects: + * The object pointed to by dictPtr is converted to a dictionary if it is + * not already one. + * + *---------------------------------------------------------------------- + */ +int +TclDictGet( + Tcl_Interp *interp, + Tcl_Obj *dictPtr, + const char *key, /* The key in a C string. */ + Tcl_Obj **valuePtrPtr) /* Where to write the value. */ +{ + Tcl_Obj *keyPtr = Tcl_NewStringObj(key, -1); + int code; + + Tcl_IncrRefCount(keyPtr); + code = Tcl_DictObjGet(interp, dictPtr, keyPtr, valuePtrPtr); + Tcl_DecrRefCount(keyPtr); + return code; +} + +/* + *---------------------------------------------------------------------- + * + * TclDictPut -- + * + * Add a key,value pair to a dictionary, or update the value for a key if + * that key already has a mapping in the dictionary. + * + * If valuePtr is a zero-count object and is not written into the + * dictionary because of an error, it is freed by this routine. The caller + * does NOT need to do reference count management. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * The object pointed to by dictPtr is converted to a dictionary if it is + * not already one, and any string representation that it has is + * invalidated. + * + *---------------------------------------------------------------------- + */ +int +TclDictPut( + Tcl_Interp *interp, + Tcl_Obj *dictPtr, + const char *key, /* The key in a C string. */ + Tcl_Obj *valuePtr) /* The value to write in. */ +{ + Tcl_Obj *keyPtr = Tcl_NewStringObj(key, -1); + int code; + + Tcl_IncrRefCount(keyPtr); + Tcl_IncrRefCount(valuePtr); + code = Tcl_DictObjPut(interp, dictPtr, keyPtr, valuePtr); + Tcl_DecrRefCount(keyPtr); + Tcl_DecrRefCount(valuePtr); + return code; +} + +/* + *---------------------------------------------------------------------- + * + * TclDictPutString -- + * + * Add a key,value pair to a dictionary, or update the value for a key if + * that key already has a mapping in the dictionary. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * The object pointed to by dictPtr is converted to a dictionary if it is + * not already one, and any string representation that it has is + * invalidated. + * + *---------------------------------------------------------------------- + */ +int +TclDictPutString( + Tcl_Interp *interp, + Tcl_Obj *dictPtr, + const char *key, /* The key in a C string. */ + const char *value) /* The value in a C string. */ +{ + Tcl_Obj *keyPtr = Tcl_NewStringObj(key, -1); + Tcl_Obj *valuePtr = Tcl_NewStringObj(value, -1); + int code; + + Tcl_IncrRefCount(keyPtr); + Tcl_IncrRefCount(valuePtr); + code = Tcl_DictObjPut(interp, dictPtr, keyPtr, valuePtr); + Tcl_DecrRefCount(keyPtr); + Tcl_DecrRefCount(valuePtr); + return code; +} + +/* + *---------------------------------------------------------------------- + * + * TclDictRemove -- + * + * Remove the key,value pair with the given key from the dictionary; the + * key does not need to be present in the dictionary. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * The object pointed to by dictPtr is converted to a dictionary if it is + * not already one, and any string representation that it has is + * invalidated. + * + *---------------------------------------------------------------------- + */ +int +TclDictRemove( + Tcl_Interp *interp, + Tcl_Obj *dictPtr, + const char *key) /* The key in a C string. */ +{ + Tcl_Obj *keyPtr = Tcl_NewStringObj(key, -1); + int code; + + Tcl_IncrRefCount(keyPtr); + code = Tcl_DictObjRemove(interp, dictPtr, keyPtr); + Tcl_DecrRefCount(keyPtr); + return code; +} + /***** START OF FUNCTIONS IMPLEMENTING TCL COMMANDS *****/ /* diff --git a/generic/tclDisassemble.c b/generic/tclDisassemble.c index 5a64ff8..7d23845 100644 --- a/generic/tclDisassemble.c +++ b/generic/tclDisassemble.c @@ -1121,7 +1121,7 @@ DisassembleByteCodeAsDicts( Tcl_Obj *desc; TclNewObj(desc); - Tcl_DictObjPut(NULL, desc, Tcl_NewStringObj("name", -1), auxDesc); + TclDictPut(NULL, desc, "name", auxDesc); auxDesc = desc; auxData->type->disassembleProc(auxData->clientData, auxDesc, codePtr, 0); @@ -1188,23 +1188,20 @@ DisassembleByteCodeAsDicts( sourceOffset += Decode(srcOffPtr); sourceLength = Decode(srcLenPtr); TclNewObj(cmd); - Tcl_DictObjPut(NULL, cmd, Tcl_NewStringObj("codefrom", -1), - Tcl_NewWideIntObj(codeOffset)); - Tcl_DictObjPut(NULL, cmd, Tcl_NewStringObj("codeto", -1), - Tcl_NewWideIntObj(codeOffset + codeLength - 1)); + TclDictPut(NULL, cmd, "codefrom", Tcl_NewWideIntObj(codeOffset)); + TclDictPut(NULL, cmd, "codeto", Tcl_NewWideIntObj( + codeOffset + codeLength - 1)); /* * Convert byte offsets to character offsets; important if multibyte * characters are present in the source! */ - Tcl_DictObjPut(NULL, cmd, Tcl_NewStringObj("scriptfrom", -1), - Tcl_NewWideIntObj(Tcl_NumUtfChars(codePtr->source, - sourceOffset))); - Tcl_DictObjPut(NULL, cmd, Tcl_NewStringObj("scriptto", -1), - Tcl_NewWideIntObj(Tcl_NumUtfChars(codePtr->source, - sourceOffset + sourceLength - 1))); - Tcl_DictObjPut(NULL, cmd, Tcl_NewStringObj("script", -1), + TclDictPut(NULL, cmd, "scriptfrom", Tcl_NewWideIntObj( + Tcl_NumUtfChars(codePtr->source, sourceOffset))); + TclDictPut(NULL, cmd, "scriptto", Tcl_NewWideIntObj( + Tcl_NumUtfChars(codePtr->source, sourceOffset + sourceLength - 1))); + TclDictPut(NULL, cmd, "script", Tcl_NewStringObj(codePtr->source+sourceOffset, sourceLength)); Tcl_ListObjAppendElement(NULL, commands, cmd); } @@ -1223,32 +1220,26 @@ DisassembleByteCodeAsDicts( */ TclNewObj(description); - Tcl_DictObjPut(NULL, description, Tcl_NewStringObj("literals", -1), - literals); - Tcl_DictObjPut(NULL, description, Tcl_NewStringObj("variables", -1), - variables); - Tcl_DictObjPut(NULL, description, Tcl_NewStringObj("exception", -1), exn); - Tcl_DictObjPut(NULL, description, Tcl_NewStringObj("instructions", -1), - instructions); - Tcl_DictObjPut(NULL, description, Tcl_NewStringObj("auxiliary", -1), aux); - Tcl_DictObjPut(NULL, description, Tcl_NewStringObj("commands", -1), - commands); - Tcl_DictObjPut(NULL, description, Tcl_NewStringObj("script", -1), + TclDictPut(NULL, description, "literals", literals); + TclDictPut(NULL, description, "variables", variables); + TclDictPut(NULL, description, "exception", exn); + TclDictPut(NULL, description, "instructions", instructions); + TclDictPut(NULL, description, "auxiliary", aux); + TclDictPut(NULL, description, "commands", commands); + TclDictPut(NULL, description, "script", Tcl_NewStringObj(codePtr->source, codePtr->numSrcBytes)); - Tcl_DictObjPut(NULL, description, Tcl_NewStringObj("namespace", -1), + TclDictPut(NULL, description, "namespace", Tcl_NewStringObj(codePtr->nsPtr->fullName, -1)); - Tcl_DictObjPut(NULL, description, Tcl_NewStringObj("stackdepth", -1), + TclDictPut(NULL, description, "stackdepth", Tcl_NewWideIntObj(codePtr->maxStackDepth)); - Tcl_DictObjPut(NULL, description, Tcl_NewStringObj("exceptdepth", -1), + TclDictPut(NULL, description, "exceptdepth", Tcl_NewWideIntObj(codePtr->maxExceptDepth)); if (line >= 0) { - Tcl_DictObjPut(NULL, description, - Tcl_NewStringObj("initiallinenumber", -1), + TclDictPut(NULL, description, "initiallinenumber", Tcl_NewWideIntObj(line)); } if (file) { - Tcl_DictObjPut(NULL, description, - Tcl_NewStringObj("sourcefile", -1), file); + TclDictPut(NULL, description, "sourcefile", file); } return description; } diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index 73b4f54..176838d 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -1736,8 +1736,7 @@ OpenEncodingFileChannel( const char *name) /* The name of the encoding file on disk and * also the name for new encoding. */ { - Tcl_Obj *nameObj = Tcl_NewStringObj(name, TCL_INDEX_NONE); - Tcl_Obj *fileNameObj = Tcl_DuplicateObj(nameObj); + Tcl_Obj *fileNameObj = Tcl_ObjPrintf("%s.enc", name); Tcl_Obj *searchPath = Tcl_DuplicateObj(Tcl_GetEncodingSearchPath()); Tcl_Obj *map = TclGetProcessGlobalValue(&encodingFileMap); Tcl_Obj **dir, *path, *directory = NULL; @@ -1745,10 +1744,8 @@ OpenEncodingFileChannel( Tcl_Size i, numDirs; TclListObjGetElements(NULL, searchPath, &numDirs, &dir); - Tcl_IncrRefCount(nameObj); - Tcl_AppendToObj(fileNameObj, ".enc", TCL_INDEX_NONE); Tcl_IncrRefCount(fileNameObj); - Tcl_DictObjGet(NULL, map, nameObj, &directory); + TclDictGet(NULL, map, name, &directory); /* * Check that any cached directory is still on the encoding search path. @@ -1777,7 +1774,7 @@ OpenEncodingFileChannel( */ map = Tcl_DuplicateObj(map); - Tcl_DictObjRemove(NULL, map, nameObj); + TclDictRemove(NULL, map, name); TclSetProcessGlobalValue(&encodingFileMap, map); directory = NULL; } @@ -1811,7 +1808,7 @@ OpenEncodingFileChannel( */ map = Tcl_DuplicateObj(TclGetProcessGlobalValue(&encodingFileMap)); - Tcl_DictObjPut(NULL, map, nameObj, dir[i]); + TclDictPut(NULL, map, name, dir[i]); TclSetProcessGlobalValue(&encodingFileMap, map); } } @@ -1822,7 +1819,6 @@ OpenEncodingFileChannel( Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "ENCODING", name, (void *)NULL); } Tcl_DecrRefCount(fileNameObj); - Tcl_DecrRefCount(nameObj); Tcl_DecrRefCount(searchPath); return chan; diff --git a/generic/tclEnsemble.c b/generic/tclEnsemble.c index 1ff0921..aad29fa 100644 --- a/generic/tclEnsemble.c +++ b/generic/tclEnsemble.c @@ -1613,17 +1613,16 @@ TclMakeEnsemble( */ if (ensemble != NULL) { - Tcl_Obj *mapDict, *fromObj, *toObj; + Tcl_Obj *mapDict, *toObj; Command *cmdPtr; TclDStringAppendLiteral(&buf, "::"); TclNewObj(mapDict); for (i=0 ; map[i].name != NULL ; i++) { - fromObj = Tcl_NewStringObj(map[i].name, -1); TclNewStringObj(toObj, Tcl_DStringValue(&buf), Tcl_DStringLength(&buf)); Tcl_AppendToObj(toObj, map[i].name, -1); - Tcl_DictObjPut(NULL, mapDict, fromObj, toObj); + TclDictPut(NULL, mapDict, map[i].name, toObj); if (map[i].proc || map[i].nreProc) { /* diff --git a/generic/tclEvent.c b/generic/tclEvent.c index 60a8924..64cbe54 100644 --- a/generic/tclEvent.c +++ b/generic/tclEvent.c @@ -275,13 +275,9 @@ HandleBgErrors( if (errChannel != NULL) { Tcl_Obj *options = Tcl_GetReturnOptions(interp, code); - Tcl_Obj *keyPtr, *valuePtr = NULL; - - TclNewLiteralStringObj(keyPtr, "-errorinfo"); - Tcl_IncrRefCount(keyPtr); - Tcl_DictObjGet(NULL, options, keyPtr, &valuePtr); - Tcl_DecrRefCount(keyPtr); + Tcl_Obj *valuePtr = NULL; + TclDictGet(NULL, options, "-errorinfo", &valuePtr); Tcl_WriteChars(errChannel, "error in background error handler:\n", -1); if (valuePtr) { @@ -329,7 +325,7 @@ TclDefaultBgErrorHandlerObjCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - Tcl_Obj *keyPtr, *valuePtr; + Tcl_Obj *valuePtr; Tcl_Obj *tempObjv[2]; int result, code, level; Tcl_InterpState saved; @@ -343,10 +339,7 @@ TclDefaultBgErrorHandlerObjCmd( * Check for a valid return options dictionary. */ - TclNewLiteralStringObj(keyPtr, "-level"); - Tcl_IncrRefCount(keyPtr); - result = Tcl_DictObjGet(NULL, objv[2], keyPtr, &valuePtr); - Tcl_DecrRefCount(keyPtr); + result = TclDictGet(NULL, objv[2], "-level", &valuePtr); if (result != TCL_OK || valuePtr == NULL) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "missing return option \"-level\"", -1)); @@ -356,10 +349,7 @@ TclDefaultBgErrorHandlerObjCmd( if (Tcl_GetIntFromObj(interp, valuePtr, &level) == TCL_ERROR) { return TCL_ERROR; } - TclNewLiteralStringObj(keyPtr, "-code"); - Tcl_IncrRefCount(keyPtr); - result = Tcl_DictObjGet(NULL, objv[2], keyPtr, &valuePtr); - Tcl_DecrRefCount(keyPtr); + result = TclDictGet(NULL, objv[2], "-code", &valuePtr); if (result != TCL_OK || valuePtr == NULL) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "missing return option \"-code\"", -1)); @@ -421,18 +411,12 @@ TclDefaultBgErrorHandlerObjCmd( Tcl_SetObjResult(interp, tempObjv[1]); } - TclNewLiteralStringObj(keyPtr, "-errorcode"); - Tcl_IncrRefCount(keyPtr); - result = Tcl_DictObjGet(NULL, objv[2], keyPtr, &valuePtr); - Tcl_DecrRefCount(keyPtr); + result = TclDictGet(NULL, objv[2], "-errorcode", &valuePtr); if (result == TCL_OK && valuePtr != NULL) { Tcl_SetObjErrorCode(interp, valuePtr); } - TclNewLiteralStringObj(keyPtr, "-errorinfo"); - Tcl_IncrRefCount(keyPtr); - result = Tcl_DictObjGet(NULL, objv[2], keyPtr, &valuePtr); - Tcl_DecrRefCount(keyPtr); + result = TclDictGet(NULL, objv[2], "-errorinfo", &valuePtr); if (result == TCL_OK && valuePtr != NULL) { Tcl_AppendObjToErrorInfo(interp, valuePtr); } diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c index fc4ddb6..2f3f48e 100644 --- a/generic/tclIOCmd.c +++ b/generic/tclIOCmd.c @@ -2061,8 +2061,7 @@ TclInitChanCmd( * Can assume that reference counts are all incremented. */ - Tcl_DictObjPut(NULL, mapObj, Tcl_NewStringObj(extras[i], -1), - Tcl_NewStringObj(extras[i+1], -1)); + TclDictPutString(NULL, mapObj, extras[i], extras[i + 1]); } Tcl_SetEnsembleMappingDict(interp, ensemble, mapObj); return ensemble; diff --git a/generic/tclInt.h b/generic/tclInt.h index 938090c..bb6c4d0 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -3316,6 +3316,14 @@ MODULE_SCOPE int TclFindDictElement(Tcl_Interp *interp, const char **elementPtr, const char **nextPtr, Tcl_Size *sizePtr, int *literalPtr); MODULE_SCOPE Tcl_Obj * TclDictObjSmartRef(Tcl_Interp *interp, Tcl_Obj *); +MODULE_SCOPE int TclDictGet(Tcl_Interp *interp, Tcl_Obj *dictPtr, + const char *key, Tcl_Obj **valuePtrPtr); +MODULE_SCOPE int TclDictPut(Tcl_Interp *interp, Tcl_Obj *dictPtr, + const char *key, Tcl_Obj *valuePtr); +MODULE_SCOPE int TclDictPutString(Tcl_Interp *interp, Tcl_Obj *dictPtr, + const char *key, const char *value); +MODULE_SCOPE int TclDictRemove(Tcl_Interp *interp, Tcl_Obj *dictPtr, + const char *key); /* TIP #280 - Modified token based evaluation, with line information. */ MODULE_SCOPE int TclEvalEx(Tcl_Interp *interp, const char *script, Tcl_Size numBytes, int flags, Tcl_Size line, diff --git a/generic/tclInterp.c b/generic/tclInterp.c index e38ec2b..e70e6a5 100644 --- a/generic/tclInterp.c +++ b/generic/tclInterp.c @@ -4473,8 +4473,7 @@ ChildCommandLimitCmd( if (hPtr != NULL) { limitCBPtr = (ScriptLimitCallback *)Tcl_GetHashValue(hPtr); if (limitCBPtr != NULL && limitCBPtr->scriptObj != NULL) { - Tcl_DictObjPut(NULL, dictPtr, Tcl_NewStringObj(options[0], -1), - limitCBPtr->scriptObj); + TclDictPut(NULL, dictPtr, options[0], limitCBPtr->scriptObj); } else { goto putEmptyCommandInDict; } @@ -4483,22 +4482,19 @@ ChildCommandLimitCmd( putEmptyCommandInDict: TclNewObj(empty); - Tcl_DictObjPut(NULL, dictPtr, - Tcl_NewStringObj(options[0], -1), empty); + TclDictPut(NULL, dictPtr, options[0], empty); } - Tcl_DictObjPut(NULL, dictPtr, Tcl_NewStringObj(options[1], -1), - Tcl_NewWideIntObj(Tcl_LimitGetGranularity(childInterp, - TCL_LIMIT_COMMANDS))); + TclDictPut(NULL, dictPtr, options[1], Tcl_NewWideIntObj( + Tcl_LimitGetGranularity(childInterp, TCL_LIMIT_COMMANDS))); if (Tcl_LimitTypeEnabled(childInterp, TCL_LIMIT_COMMANDS)) { - Tcl_DictObjPut(NULL, dictPtr, Tcl_NewStringObj(options[2], -1), - Tcl_NewWideIntObj(Tcl_LimitGetCommands(childInterp))); + TclDictPut(NULL, dictPtr, options[2], Tcl_NewWideIntObj( + Tcl_LimitGetCommands(childInterp))); } else { Tcl_Obj *empty; TclNewObj(empty); - Tcl_DictObjPut(NULL, dictPtr, - Tcl_NewStringObj(options[2], -1), empty); + TclDictPut(NULL, dictPtr, options[2], empty); } Tcl_SetObjResult(interp, dictPtr); return TCL_OK; @@ -4660,8 +4656,7 @@ ChildTimeLimitCmd( if (hPtr != NULL) { limitCBPtr = (ScriptLimitCallback *)Tcl_GetHashValue(hPtr); if (limitCBPtr != NULL && limitCBPtr->scriptObj != NULL) { - Tcl_DictObjPut(NULL, dictPtr, Tcl_NewStringObj(options[0], -1), - limitCBPtr->scriptObj); + TclDictPut(NULL, dictPtr, options[0], limitCBPtr->scriptObj); } else { goto putEmptyCommandInDict; } @@ -4669,29 +4664,25 @@ ChildTimeLimitCmd( Tcl_Obj *empty; putEmptyCommandInDict: TclNewObj(empty); - Tcl_DictObjPut(NULL, dictPtr, - Tcl_NewStringObj(options[0], -1), empty); + TclDictPut(NULL, dictPtr, options[0], empty); } - Tcl_DictObjPut(NULL, dictPtr, Tcl_NewStringObj(options[1], -1), - Tcl_NewWideIntObj(Tcl_LimitGetGranularity(childInterp, - TCL_LIMIT_TIME))); + TclDictPut(NULL, dictPtr, options[1], Tcl_NewWideIntObj( + Tcl_LimitGetGranularity(childInterp, TCL_LIMIT_TIME))); if (Tcl_LimitTypeEnabled(childInterp, TCL_LIMIT_TIME)) { Tcl_Time limitMoment; Tcl_LimitGetTime(childInterp, &limitMoment); - Tcl_DictObjPut(NULL, dictPtr, Tcl_NewStringObj(options[2], -1), - Tcl_NewWideIntObj(limitMoment.usec/1000)); - Tcl_DictObjPut(NULL, dictPtr, Tcl_NewStringObj(options[3], -1), + TclDictPut(NULL, dictPtr, options[2], + Tcl_NewWideIntObj(limitMoment.usec / 1000)); + TclDictPut(NULL, dictPtr, options[3], Tcl_NewWideIntObj(limitMoment.sec)); } else { Tcl_Obj *empty; TclNewObj(empty); - Tcl_DictObjPut(NULL, dictPtr, - Tcl_NewStringObj(options[2], -1), empty); - Tcl_DictObjPut(NULL, dictPtr, - Tcl_NewStringObj(options[3], -1), empty); + TclDictPut(NULL, dictPtr, options[2], empty); + TclDictPut(NULL, dictPtr, options[3], empty); } Tcl_SetObjResult(interp, dictPtr); return TCL_OK; diff --git a/generic/tclMain.c b/generic/tclMain.c index a7cb7fb..ad36b3f 100644 --- a/generic/tclMain.c +++ b/generic/tclMain.c @@ -406,13 +406,9 @@ Tcl_MainEx( chan = Tcl_GetStdChannel(TCL_STDERR); if (chan) { Tcl_Obj *options = Tcl_GetReturnOptions(interp, code); - Tcl_Obj *keyPtr, *valuePtr; - - TclNewLiteralStringObj(keyPtr, "-errorinfo"); - Tcl_IncrRefCount(keyPtr); - Tcl_DictObjGet(NULL, options, keyPtr, &valuePtr); - Tcl_DecrRefCount(keyPtr); + Tcl_Obj *valuePtr = NULL; + TclDictGet(NULL, options, "-errorinfo", &valuePtr); if (valuePtr) { if (Tcl_WriteObj(chan, valuePtr) < 0) { Tcl_WriteChars(chan, ENCODING_ERROR, -1); diff --git a/generic/tclOOInfo.c b/generic/tclOOInfo.c index 7435fff..be329d7 100644 --- a/generic/tclOOInfo.c +++ b/generic/tclOOInfo.c @@ -125,10 +125,8 @@ TclOOInitInfo( infoCmd = Tcl_FindCommand(interp, "info", NULL, TCL_GLOBAL_ONLY); if (infoCmd) { Tcl_GetEnsembleMappingDict(NULL, infoCmd, &mapDict); - Tcl_DictObjPut(NULL, mapDict, Tcl_NewStringObj("object", -1), - Tcl_NewStringObj("::oo::InfoObject", -1)); - Tcl_DictObjPut(NULL, mapDict, Tcl_NewStringObj("class", -1), - Tcl_NewStringObj("::oo::InfoClass", -1)); + TclDictPutString(NULL, mapDict, "object", "::oo::InfoObject"); + TclDictPutString(NULL, mapDict, "class", "::oo::InfoClass"); Tcl_SetEnsembleMappingDict(interp, infoCmd, mapDict); } } diff --git a/generic/tclProcess.c b/generic/tclProcess.c index a5607d9..bed3a60 100644 --- a/generic/tclProcess.c +++ b/generic/tclProcess.c @@ -538,7 +538,7 @@ ProcessStatusObjCmd( * Add to result. */ - Tcl_DictObjPut(interp, dict, Tcl_NewWideIntObj(info->resolvedPid), + Tcl_DictObjPut(NULL, dict, Tcl_NewIntObj(info->resolvedPid), BuildProcessStatusObj(info)); } } @@ -588,7 +588,7 @@ ProcessStatusObjCmd( * Add to result. */ - Tcl_DictObjPut(interp, dict, Tcl_NewWideIntObj(info->resolvedPid), + Tcl_DictObjPut(NULL, dict, Tcl_NewIntObj(info->resolvedPid), BuildProcessStatusObj(info)); } } diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index b0bb383..f09030a 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -6262,8 +6262,7 @@ TclZipfs_Init( */ Tcl_GetEnsembleMappingDict(NULL, ensemble, &mapObj); - Tcl_DictObjPut(NULL, mapObj, Tcl_NewStringObj("find", -1), - Tcl_NewStringObj("::tcl::zipfs::find", -1)); + TclDictPutString(NULL, mapObj, "find", "::tcl::zipfs::find"); Tcl_CreateObjCommand(interp, "::tcl::zipfs::tcl_library_init", ZipFSTclLibraryObjCmd, NULL, NULL); Tcl_PkgProvide(interp, "tcl::zipfs", "2.0"); diff --git a/generic/tclZlib.c b/generic/tclZlib.c index 595ddf4..ff360d6 100644 --- a/generic/tclZlib.c +++ b/generic/tclZlib.c @@ -228,6 +228,26 @@ static const Tcl_ChannelType zlibChannelType = { /* *---------------------------------------------------------------------- * + * Latin1 -- + * Helper to definitely get the ISO 8859-1 encoding. It's internally + * defined by Tcl so this operation should always succeed. + * + *---------------------------------------------------------------------- + */ +static inline Tcl_Encoding +Latin1(void) +{ + Tcl_Encoding latin1enc = Tcl_GetEncoding(NULL, "iso8859-1"); + + if (latin1enc == NULL) { + Tcl_Panic("no latin-1 encoding"); + } + return latin1enc; +} + +/* + *---------------------------------------------------------------------- + * * ConvertError -- * * Utility function for converting a zlib error into a Tcl error. @@ -388,7 +408,7 @@ ConvertErrorToList( * GenerateHeader -- * * Function for creating a gzip header from the contents of a dictionary - * (as described in the documentation). GetValue is a helper function. + * (as described in the documentation). * * Results: * A Tcl result code. @@ -401,33 +421,6 @@ ConvertErrorToList( *---------------------------------------------------------------------- */ -static inline int -GetValue( - Tcl_Interp *interp, - Tcl_Obj *dictObj, - const char *nameStr, - Tcl_Obj **valuePtrPtr) -{ - Tcl_Obj *name = Tcl_NewStringObj(nameStr, TCL_AUTO_LENGTH); - int result = Tcl_DictObjGet(interp, dictObj, name, valuePtrPtr); - - TclDecrRefCount(name); - return result; -} - -/* - * RFC 1952 says that header strings are in ISO 8859-1 (LATIN-1). - */ -static inline Tcl_Encoding -Latin1(void) -{ - Tcl_Encoding latin1enc = Tcl_GetEncoding(NULL, "iso8859-1"); - if (latin1enc == NULL) { - Tcl_Panic("no latin-1 encoding"); - } - return latin1enc; -} - static int GenerateHeader( Tcl_Interp *interp, /* Where to put error messages. */ @@ -447,7 +440,7 @@ GenerateHeader( "binary", "text" }; - if (GetValue(interp, dictObj, "comment", &value) != TCL_OK) { + if (TclDictGet(interp, dictObj, "comment", &value) != TCL_OK) { goto error; } else if (value != NULL) { Tcl_EncodingState state; @@ -476,14 +469,14 @@ GenerateHeader( } } - if (GetValue(interp, dictObj, "crc", &value) != TCL_OK) { + if (TclDictGet(interp, dictObj, "crc", &value) != TCL_OK) { goto error; } else if (value != NULL && Tcl_GetBooleanFromObj(interp, value, &headerPtr->header.hcrc)) { goto error; } - if (GetValue(interp, dictObj, "filename", &value) != TCL_OK) { + if (TclDictGet(interp, dictObj, "filename", &value) != TCL_OK) { goto error; } else if (value != NULL) { Tcl_EncodingState state; @@ -512,7 +505,7 @@ GenerateHeader( } } - if (GetValue(interp, dictObj, "os", &value) != TCL_OK) { + if (TclDictGet(interp, dictObj, "os", &value) != TCL_OK) { goto error; } else if (value != NULL && Tcl_GetIntFromObj(interp, value, &headerPtr->header.os) != TCL_OK) { @@ -524,7 +517,7 @@ GenerateHeader( * input data. */ - if (GetValue(interp, dictObj, "time", &value) != TCL_OK) { + if (TclDictGet(interp, dictObj, "time", &value) != TCL_OK) { goto error; } else if (value != NULL && TclGetWideIntFromObj(interp, value, &wideValue) != TCL_OK) { @@ -532,7 +525,7 @@ GenerateHeader( } headerPtr->header.time = wideValue; - if (GetValue(interp, dictObj, "type", &value) != TCL_OK) { + if (TclDictGet(interp, dictObj, "type", &value) != TCL_OK) { goto error; } else if (value != NULL && Tcl_GetIndexFromObj(interp, value, types, "type", TCL_EXACT, &headerPtr->header.text) != TCL_OK) { @@ -551,7 +544,6 @@ GenerateHeader( * ExtractHeader -- * * Take the values out of a gzip header and store them in a dictionary. - * SetValue is a helper macro. * * Results: * None. @@ -562,28 +554,24 @@ GenerateHeader( *---------------------------------------------------------------------- */ -#define SetValue(dictObj, key, value) \ - Tcl_DictObjPut(NULL, (dictObj), Tcl_NewStringObj( \ - (key), TCL_AUTO_LENGTH), (value)) - static void ExtractHeader( gz_header *headerPtr, /* The gzip header to extract from. */ Tcl_Obj *dictObj) /* The dictionary to store in. */ { Tcl_Encoding latin1enc = NULL; + /* RFC 1952 says that header strings are in + * ISO 8859-1 (LATIN-1). */ Tcl_DString tmp; if (headerPtr->comment != Z_NULL) { - if (latin1enc == NULL) { - latin1enc = Latin1(); - } + latin1enc = Latin1(); (void) Tcl_ExternalToUtfDString(latin1enc, (char *) headerPtr->comment, TCL_AUTO_LENGTH, &tmp); - SetValue(dictObj, "comment", Tcl_DStringToObj(&tmp)); + TclDictPut(NULL, dictObj, "comment", Tcl_DStringToObj(&tmp)); } - SetValue(dictObj, "crc", Tcl_NewBooleanObj(headerPtr->hcrc)); + TclDictPut(NULL, dictObj, "crc", Tcl_NewBooleanObj(headerPtr->hcrc)); if (headerPtr->name != Z_NULL) { if (latin1enc == NULL) { latin1enc = Latin1(); @@ -591,17 +579,17 @@ ExtractHeader( (void) Tcl_ExternalToUtfDString(latin1enc, (char *) headerPtr->name, TCL_AUTO_LENGTH, &tmp); - SetValue(dictObj, "filename", Tcl_DStringToObj(&tmp)); + TclDictPut(NULL, dictObj, "filename", Tcl_DStringToObj(&tmp)); } if (headerPtr->os != 255) { - SetValue(dictObj, "os", Tcl_NewWideIntObj(headerPtr->os)); + TclDictPut(NULL, dictObj, "os", Tcl_NewWideIntObj(headerPtr->os)); } if (headerPtr->time != 0 /* magic - no time */) { - SetValue(dictObj, "time", Tcl_NewWideIntObj(headerPtr->time)); + TclDictPut(NULL, dictObj, "time", Tcl_NewWideIntObj(headerPtr->time)); } if (headerPtr->text != Z_UNKNOWN) { - SetValue(dictObj, "type", Tcl_NewStringObj( - headerPtr->text ? "text" : "binary", TCL_AUTO_LENGTH)); + TclDictPutString(NULL, dictObj, "type", + headerPtr->text ? "text" : "binary"); } if (latin1enc != NULL) { @@ -1917,7 +1905,7 @@ Tcl_ZlibInflate( Tcl_SetByteArrayLength(obj, stream.total_out); if (headerPtr != NULL) { ExtractHeader(&header, gzipHeaderDictObj); - SetValue(gzipHeaderDictObj, "size", + TclDictPut(NULL, gzipHeaderDictObj, "size", Tcl_NewWideIntObj(stream.total_out)); Tcl_Free(nameBuf); Tcl_Free(commentBuf); |