summaryrefslogtreecommitdiffstats
path: root/generic/tclInt.h
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2022-11-11 21:51:31 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2022-11-11 21:51:31 (GMT)
commit2a94e801888e3dd1b0514c9c20baca08919f8dca (patch)
tree6d5c0ceb2810a9a80f12a702143ffc9f939d40f1 /generic/tclInt.h
parent1b232cf14ce2e75971718160c301d39c97ab4341 (diff)
parent874327229c5e64a52e1fc3b4da6a31936ec07ed2 (diff)
downloadtcl-2a94e801888e3dd1b0514c9c20baca08919f8dca.zip
tcl-2a94e801888e3dd1b0514c9c20baca08919f8dca.tar.gz
tcl-2a94e801888e3dd1b0514c9c20baca08919f8dca.tar.bz2
Merge 8.7
Diffstat (limited to 'generic/tclInt.h')
-rw-r--r--generic/tclInt.h56
1 files changed, 51 insertions, 5 deletions
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 1b817e9..b079364 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -4806,15 +4806,46 @@ MODULE_SCOPE Tcl_LibraryInitProc Procbodytest_SafeInit;
TCL_DTRACE_OBJ_CREATE(objPtr); \
} while (0)
-#define TclNewIndexObj(objPtr, w) \
+#define TclNewUIntObj(objPtr, uw) \
do { \
- size_t _w = (w); \
TclIncrObjsAllocated(); \
TclAllocObjStorage(objPtr); \
(objPtr)->refCount = 0; \
(objPtr)->bytes = NULL; \
- (objPtr)->internalRep.wideValue = ((size_t)(_w) == (size_t)TCL_INDEX_NONE) ? -1 : (Tcl_WideInt)(_w); \
- (objPtr)->typePtr = &tclIntType; \
+ Tcl_WideUInt uw_ = (uw); \
+ if (uw_ > WIDE_MAX) { \
+ mp_int bignumValue_; \
+ if (mp_init_u64(&bignumValue_, uw_) != MP_OKAY) { \
+ Tcl_Panic("%s: memory overflow", "TclNewUIntObj"); \
+ } \
+ TclSetBignumInternalRep((objPtr), &bignumValue_); \
+ } else { \
+ (objPtr)->internalRep.wideValue = (Tcl_WideInt)(uw_); \
+ (objPtr)->typePtr = &tclIntType; \
+ } \
+ TCL_DTRACE_OBJ_CREATE(objPtr); \
+ } while (0)
+
+#define TclNewIndexObj(objPtr, uw) \
+ do { \
+ TclIncrObjsAllocated(); \
+ TclAllocObjStorage(objPtr); \
+ (objPtr)->refCount = 0; \
+ (objPtr)->bytes = NULL; \
+ Tcl_WideUInt uw_ = (uw); \
+ if (uw_ >= TCL_INDEX_NONE) { \
+ (objPtr)->internalRep.wideValue = -1; \
+ (objPtr)->typePtr = &tclIntType; \
+ } else if (uw_ > WIDE_MAX) { \
+ mp_int bignumValue_; \
+ if (mp_init_u64(&bignumValue_, uw_) != MP_OKAY) { \
+ Tcl_Panic("%s: memory overflow", "TclNewUIntObj"); \
+ } \
+ TclSetBignumInternalRep((objPtr), &bignumValue_); \
+ } else { \
+ (objPtr)->internalRep.wideValue = (Tcl_WideInt)(uw_); \
+ (objPtr)->typePtr = &tclIntType; \
+ } \
TCL_DTRACE_OBJ_CREATE(objPtr); \
} while (0)
@@ -4843,8 +4874,23 @@ MODULE_SCOPE Tcl_LibraryInitProc Procbodytest_SafeInit;
#define TclNewIntObj(objPtr, w) \
(objPtr) = Tcl_NewWideIntObj(w)
+#define TclNewUIntObj(objPtr, uw) \
+ do { \
+ Tcl_WideUInt uw_ = (uw); \
+ if (uw_ > WIDE_MAX) { \
+ mp_int bignumValue_; \
+ if (mp_init_u64(&bignumValue_, uw_) == MP_OKAY) { \
+ (objPtr) = Tcl_NewBignumObj(&bignumValue_)); \
+ } else { \
+ (objPtr) = NULL; \
+ } \
+ } else { \
+ (objPtr) = Tcl_NewWideIntObj(uw_); \
+ } \
+ } while (0)
+
#define TclNewIndexObj(objPtr, w) \
- (objPtr) = (((size_t)w) == TCL_INDEX_NONE) ? Tcl_NewWideIntObj(-1) : Tcl_NewWideIntObj(w)
+ (objPtr) = (((Tcl_WideUInt)w) >= TCL_INDEX_NONE) ? Tcl_NewWideIntObj(-1) : Tcl_NewWideIntObj(w)
#define TclNewDoubleObj(objPtr, d) \
(objPtr) = Tcl_NewDoubleObj(d)