summaryrefslogtreecommitdiffstats
path: root/generic/tcl.h
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2025-04-13 22:16:52 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2025-04-13 22:16:52 (GMT)
commit2b0fe4a3ef75940978059b4b33672f2d1c63dced (patch)
tree4d6908ac453dc6ccba9b0a0593e77af3511609c6 /generic/tcl.h
parentd46e9784ab0ff5b3e9bf35dc56c903fd9503c936 (diff)
downloadtcl-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.h33
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 */