diff options
author | pooryorick <com.digitalsmarties@pooryorick.com> | 2023-05-17 12:26:11 (GMT) |
---|---|---|
committer | pooryorick <com.digitalsmarties@pooryorick.com> | 2023-05-17 12:26:11 (GMT) |
commit | ac555b905c136e91ee92a89d6b225b9a46851e8d (patch) | |
tree | 020a6935435777cb8e313cc5268351a1229fed6a /generic | |
parent | 599038222278a31912d42c4a6db1aee88052c40b (diff) | |
download | tcl-ac555b905c136e91ee92a89d6b225b9a46851e8d.zip tcl-ac555b905c136e91ee92a89d6b225b9a46851e8d.tar.gz tcl-ac555b905c136e91ee92a89d6b225b9a46851e8d.tar.bz2 |
New functions: TclUndoRefCount() and TclDictGetSize().
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclDictObj.c | 20 | ||||
-rw-r--r-- | generic/tclInt.h | 2 | ||||
-rw-r--r-- | generic/tclObj.c | 22 |
3 files changed, 44 insertions, 0 deletions
diff --git a/generic/tclDictObj.c b/generic/tclDictObj.c index f996f4b..c4ff0fa 100644 --- a/generic/tclDictObj.c +++ b/generic/tclDictObj.c @@ -1048,6 +1048,26 @@ Tcl_DictObjRemove( /* *---------------------------------------------------------------------- * + * Tcl_DictGetSize + * + * Returns the size of dictPtr. Caller must ensure that dictPtr has type + * 'tclDicttype'. + * + * + *---------------------------------------------------------------------- + */ + +Tcl_Size +TclDictGetSize(Tcl_Obj *dictPtr) +{ + Dict *dict; + DictGetInternalRep(dictPtr, dict); + return dict->table.numEntries; +} + +/* + *---------------------------------------------------------------------- + * * Tcl_DictObjSize -- * * How many key,value pairs are there in the dictionary? diff --git a/generic/tclInt.h b/generic/tclInt.h index 19e878e..979284d 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -3116,6 +3116,7 @@ MODULE_SCOPE Tcl_Command TclCreateEnsembleInNs(Tcl_Interp *interp, Tcl_Namespace *ensembleNamespacePtr, int flags); MODULE_SCOPE void TclDeleteNamespaceVars(Namespace *nsPtr); MODULE_SCOPE void TclDeleteNamespaceChildren(Namespace *nsPtr); +MODULE_SCOPE Tcl_Size TclDictGetSize(Tcl_Obj *dictPtr); MODULE_SCOPE Tcl_Obj* TclDuplicatePureObj(Tcl_Obj * objPtr); MODULE_SCOPE int TclFindDictElement(Tcl_Interp *interp, const char *dict, Tcl_Size dictLength, @@ -3289,6 +3290,7 @@ MODULE_SCOPE void TclParseInit(Tcl_Interp *interp, const char *string, MODULE_SCOPE Tcl_Size TclParseAllWhiteSpace(const char *src, Tcl_Size numBytes); MODULE_SCOPE int TclProcessReturn(Tcl_Interp *interp, int code, int level, Tcl_Obj *returnOpts); +MODULE_SCOPE void TclUndoRefCount(Tcl_Obj *objPtr); MODULE_SCOPE int TclpObjLstat(Tcl_Obj *pathPtr, Tcl_StatBuf *buf); MODULE_SCOPE Tcl_Obj * TclpTempFileName(void); MODULE_SCOPE Tcl_Obj * TclpTempFileNameForLibrary(Tcl_Interp *interp, diff --git a/generic/tclObj.c b/generic/tclObj.c index 58eb71d..ba3c626 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -3780,6 +3780,28 @@ Tcl_DecrRefCount( /* *---------------------------------------------------------------------- * + * TclUndoRefCount -- + * + * Decrement the refCount of objPtr without causing it to be freed if it + * drops from 1 to 0. This allows a function increment a refCount but + * then decrement it and still be able to pass return it to a caller, + * possibly with a refCount of 0. The caller must have previously + * incremented the refCount. + * + *---------------------------------------------------------------------- + */ +void +TclUndoRefCount( + Tcl_Obj *objPtr) /* The object we are releasing a reference to. */ +{ + if (objPtr->refCount > 0) { + --objPtr->refCount; + } +} + +/* + *---------------------------------------------------------------------- + * * Tcl_IsShared -- * * Tests if the object has a ref count greater than one. |