summaryrefslogtreecommitdiffstats
path: root/generic/tclObj.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2022-10-17 18:19:25 (GMT)
committerdgp <dgp@users.sourceforge.net>2022-10-17 18:19:25 (GMT)
commit79d18dcb7e14f36bfa13202b744c6e759a00f7d2 (patch)
tree6682e9879a3c7b15f2a6552f3211559a8a717f7c /generic/tclObj.c
parent7593fce2300c45d321ff47f31909d0fafe03bf68 (diff)
parent5bcff4802f2a2a4eaa5156160ff3110fa05b4b99 (diff)
downloadtcl-79d18dcb7e14f36bfa13202b744c6e759a00f7d2.zip
tcl-79d18dcb7e14f36bfa13202b744c6e759a00f7d2.tar.gz
tcl-79d18dcb7e14f36bfa13202b744c6e759a00f7d2.tar.bz2
Implementation of TIP 638.
Diffstat (limited to 'generic/tclObj.c')
-rw-r--r--generic/tclObj.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/generic/tclObj.c b/generic/tclObj.c
index 4963b22..8970ab0 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -3897,7 +3897,7 @@ TclSetBignumInternalRep(
/*
*----------------------------------------------------------------------
*
- * TclGetNumberFromObj --
+ * Tcl_GetNumberFromObj --
*
* Extracts a number (of any possible numeric type) from an object.
*
@@ -3915,7 +3915,7 @@ TclSetBignumInternalRep(
*/
int
-TclGetNumberFromObj(
+Tcl_GetNumberFromObj(
Tcl_Interp *interp,
Tcl_Obj *objPtr,
void **clientDataPtr,
@@ -3950,6 +3950,42 @@ TclGetNumberFromObj(
TclParseNumber(interp, objPtr, "number", NULL, -1, NULL, 0));
return TCL_ERROR;
}
+
+int
+Tcl_GetNumber(
+ Tcl_Interp *interp,
+ const char *bytes,
+ size_t numBytes,
+ ClientData *clientDataPtr,
+ int *typePtr)
+{
+ static Tcl_ThreadDataKey numberCacheKey;
+ Tcl_Obj *objPtr = (Tcl_Obj *)Tcl_GetThreadData(&numberCacheKey,
+ sizeof(Tcl_Obj));
+
+ Tcl_FreeInternalRep(objPtr);
+
+ if (bytes == NULL) {
+ bytes = &tclEmptyString;
+ numBytes = 0;
+ }
+ if (numBytes == (size_t)TCL_INDEX_NONE) {
+ numBytes = strlen(bytes);
+ }
+ if (numBytes > INT_MAX) {
+ if (interp) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "max size for a Tcl value (%d bytes) exceeded", INT_MAX));
+ Tcl_SetErrorCode(interp, "TCL", "MEMORY", NULL);
+ }
+ return TCL_ERROR;
+ }
+
+ objPtr->bytes = (char *) bytes;
+ objPtr->length = numBytes;
+
+ return Tcl_GetNumberFromObj(interp, objPtr, clientDataPtr, typePtr);
+}
/*
*----------------------------------------------------------------------