diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-11-04 11:11:18 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-11-04 11:11:18 (GMT) |
commit | f3896e51875d3696de089804ab5e205403ee842a (patch) | |
tree | 6c843420d6515f8c0db1db0fdd47b1089a5f3b53 /generic/tclObj.c | |
parent | 6ab05e04d1c2e4d0a473c114f67d7a8f1cab4dbd (diff) | |
download | tcl-f3896e51875d3696de089804ab5e205403ee842a.zip tcl-f3896e51875d3696de089804ab5e205403ee842a.tar.gz tcl-f3896e51875d3696de089804ab5e205403ee842a.tar.bz2 |
New functions Tcl_NewWideUIntObj()/Tcl_SetWideUIntObj() (still experimental)
Diffstat (limited to 'generic/tclObj.c')
-rw-r--r-- | generic/tclObj.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/generic/tclObj.c b/generic/tclObj.c index ce8e610..806f910 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -3219,6 +3219,34 @@ 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; + + TclNewObj(objPtr); + Tcl_SetWideUIntObj(objPtr, uwideValue); + return objPtr; +} + +/* + *---------------------------------------------------------------------- + * * Tcl_DbNewWideIntObj -- * * If a client is compiled with TCL_MEM_DEBUG defined, calls to @@ -3312,6 +3340,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_i64(&bignumValue, uwideValue) != MP_OKAY) { + Tcl_Panic("%s called with shared object", "Tcl_SetWideUIntObj"); + } + TclSetBignumInternalRep(objPtr, &bignumValue); + } { + TclSetIntObj(objPtr, (Tcl_WideInt)uwideValue); + } +} /* *---------------------------------------------------------------------- |