diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2025-04-13 22:16:52 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2025-04-13 22:16:52 (GMT) |
commit | 2b0fe4a3ef75940978059b4b33672f2d1c63dced (patch) | |
tree | 4d6908ac453dc6ccba9b0a0593e77af3511609c6 /generic/tcl.h | |
parent | d46e9784ab0ff5b3e9bf35dc56c903fd9503c936 (diff) | |
download | tcl-core-attemptcreatehashentry.zip tcl-core-attemptcreatehashentry.tar.gz tcl-core-attemptcreatehashentry.tar.bz2 |
Implement Tcl_AttemptCreateHashEntry()core-attemptcreatehashentry
Diffstat (limited to 'generic/tcl.h')
-rw-r--r-- | generic/tcl.h | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/generic/tcl.h b/generic/tcl.h index f2ad6e8..06ca3b7 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -2513,11 +2513,40 @@ TclBounceRefCount( * hash tables: */ -#undef Tcl_FindHashEntry #define Tcl_FindHashEntry(tablePtr, key) \ (*((tablePtr)->createProc))(tablePtr, (const char *)(key), (int *)-1) -#undef Tcl_CreateHashEntry + +#ifdef TCL_MEM_DEBUG +static inline Tcl_HashEntry * +TclDbPanicIfNull( + Tcl_HashEntry *entry, + int *newPtr, + const char *file, + const char *line) +{ + if (!entry && newPtr != (int *)-1) { + Tcl_Panic("%s: Memory overflow in file %s:%d", "Tcl_CreateHashEntry", file, line); + } + return entry; +} +#define Tcl_CreateHashEntry(tablePtr, key, newPtr) \ + TclDbPanicIfNull((*((tablePtr)->createProc))(tablePtr, (const char *)(key), (newPtr)), (newPtr), __FILE__, __LINE__) +#else +static inline Tcl_HashEntry * +TclPanicIfNull( + Tcl_HashEntry *entry, + int *newPtr) +{ + if (!entry && newPtr != (int *)-1) { + Tcl_Panic("%s: Memory overflow", "Tcl_CreateHashEntry"); + } + return entry; +} #define Tcl_CreateHashEntry(tablePtr, key, newPtr) \ + TclPanicIfNull((*((tablePtr)->createProc))(tablePtr, (const char *)(key), (newPtr)), (newPtr)) +#endif + +#define Tcl_AttemptCreateHashEntry(tablePtr, key, newPtr) \ (*((tablePtr)->createProc))(tablePtr, (const char *)(key), newPtr) #endif /* RC_INVOKED */ |