summaryrefslogtreecommitdiffstats
path: root/generic/tclObj.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2024-04-20 22:23:45 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2024-04-20 22:23:45 (GMT)
commit0fef61d372c72ef6f6eaae70fc2bf9087e0f3789 (patch)
tree3b6bc85dd3c22260f2880497df13aad94502fc28 /generic/tclObj.c
parent200d3711e7e5c5a249a3f272ae8338931329e0d8 (diff)
parentec54c35ce008768e317a58468b971a8f82af634a (diff)
downloadtcl-0fef61d372c72ef6f6eaae70fc2bf9087e0f3789.zip
tcl-0fef61d372c72ef6f6eaae70fc2bf9087e0f3789.tar.gz
tcl-0fef61d372c72ef6f6eaae70fc2bf9087e0f3789.tar.bz2
TIP #648: New functions Tcl_NewWideUIntObj()/Tcl_SetWideUIntObj()
Diffstat (limited to 'generic/tclObj.c')
-rw-r--r--generic/tclObj.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/generic/tclObj.c b/generic/tclObj.c
index e23d900..30634a0 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -2792,6 +2792,33 @@ Tcl_NewWideIntObj(
/*
*----------------------------------------------------------------------
*
+ * Tcl_NewWideUIntObj --
+ *
+ * Results:
+ * The newly created object is returned. This object will have an invalid
+ * string representation. The returned object has ref count 0.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+Tcl_Obj *
+Tcl_NewWideUIntObj(
+ Tcl_WideUInt uwideValue)
+ /* Wide integer used to initialize the new
+ * object. */
+{
+ Tcl_Obj *objPtr;
+
+ TclNewUIntObj(objPtr, uwideValue);
+ return objPtr;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* Tcl_DbNewWideIntObj --
*
* If a client is compiled with TCL_MEM_DEBUG defined, calls to
@@ -2885,6 +2912,46 @@ Tcl_SetWideIntObj(
TclSetIntObj(objPtr, wideValue);
}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Tcl_SetWideUIntObj --
+ *
+ * Modify an object to be a wide integer object or a bignum object
+ * and to have the specified unsigned wide integer value.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * The object's old string rep, if any, is freed. Also, any old internal
+ * rep is freed.
+ *
+ *----------------------------------------------------------------------
+ */
+
+void
+Tcl_SetWideUIntObj(
+ Tcl_Obj *objPtr, /* Object w. internal rep to init. */
+ Tcl_WideUInt uwideValue)
+ /* Wide integer used to initialize the
+ * object's value. */
+{
+ if (Tcl_IsShared(objPtr)) {
+ Tcl_Panic("%s called with shared object", "Tcl_SetWideUIntObj");
+ }
+
+ if (uwideValue > WIDE_MAX) {
+ mp_int bignumValue;
+ if (mp_init_u64(&bignumValue, uwideValue) != MP_OKAY) {
+ Tcl_Panic("%s: memory overflow", "Tcl_SetWideUIntObj");
+ }
+ TclSetBignumInternalRep(objPtr, &bignumValue);
+ } {
+ TclSetIntObj(objPtr, (Tcl_WideInt)uwideValue);
+ }
+}
/*
*----------------------------------------------------------------------