diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2017-10-27 08:45:13 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2017-10-27 08:45:13 (GMT) |
commit | 67e505d2abdb7ddb2d38ee7e579785a410008188 (patch) | |
tree | b105df348fa85a22d3395f5b8e02ea8d48f9dcb9 /generic/tclObj.c | |
parent | fa2e7e8949ad5728da4d3dfdd796a4f7e3e0e811 (diff) | |
download | tcl-67e505d2abdb7ddb2d38ee7e579785a410008188.zip tcl-67e505d2abdb7ddb2d38ee7e579785a410008188.tar.gz tcl-67e505d2abdb7ddb2d38ee7e579785a410008188.tar.bz2 |
First implementation of [http://core.tcl.tk/tips/doc/trunk/tip/481.md|TIP #481]: Extend size range of various Tcl_Get*() functions
Diffstat (limited to 'generic/tclObj.c')
-rw-r--r-- | generic/tclObj.c | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/generic/tclObj.c b/generic/tclObj.c index 1a00011..f61ccb7 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -1659,7 +1659,7 @@ Tcl_GetString( /* *---------------------------------------------------------------------- * - * Tcl_GetStringFromObj -- + * Tcl_GetStringFromObj/Tcl_GetStringFromObj2 -- * * Returns the string representation's byte array pointer and length for * an object. @@ -1679,6 +1679,7 @@ Tcl_GetString( *---------------------------------------------------------------------- */ +#undef Tcl_GetStringFromObj char * Tcl_GetStringFromObj( register Tcl_Obj *objPtr, /* Object whose string rep byte pointer should @@ -1694,6 +1695,21 @@ Tcl_GetStringFromObj( } return objPtr->bytes; } +char * +Tcl_GetStringFromObj2( + register Tcl_Obj *objPtr, /* Object whose string rep byte pointer should + * be returned. */ + register size_t *lengthPtr) /* If non-NULL, the location where the string + * rep's byte array length should * be stored. + * If NULL, no length is stored. */ +{ + (void) TclGetString(objPtr); + + if (lengthPtr != NULL) { + *lengthPtr = objPtr->length; + } + return objPtr->bytes; +} /* *---------------------------------------------------------------------- @@ -2273,6 +2289,7 @@ Tcl_SetDoubleObj( *---------------------------------------------------------------------- */ +#undef Tcl_GetDoubleFromObj int Tcl_GetDoubleFromObj( Tcl_Interp *interp, /* Used for error reporting if not NULL. */ @@ -2466,7 +2483,7 @@ Tcl_SetIntObj( /* *---------------------------------------------------------------------- * - * Tcl_GetIntFromObj -- + * Tcl_GetIntFromObj/Tcl_GetValue -- * * Attempt to return an int from the Tcl object "objPtr". If the object * is not already an int, an attempt will be made to convert it to one. @@ -2489,6 +2506,7 @@ Tcl_SetIntObj( *---------------------------------------------------------------------- */ +#undef Tcl_GetIntFromObj int Tcl_GetIntFromObj( Tcl_Interp *interp, /* Used for error reporting if not NULL. */ @@ -2516,6 +2534,32 @@ Tcl_GetIntFromObj( return TCL_OK; #endif } +int +Tcl_GetValue( + Tcl_Interp *interp, /* Used for error reporting if not NULL. */ + register Tcl_Obj *objPtr, /* The object from which to get a int. */ + register void *ptr, /* Place to store resulting int. */ + register int flags) +{ + double value; + int result; + if (flags == TCL_TYPE_I(int)) { + return Tcl_GetIntFromObj(interp, objPtr, ptr); + } + if (flags == TCL_TYPE_I(Tcl_WideInt)) { + return Tcl_GetWideIntFromObj(interp, objPtr, ptr); + } + if (flags == TCL_TYPE_D(double)) { + return Tcl_GetDoubleFromObj(interp, objPtr, ptr); + } + result = Tcl_GetDoubleFromObj(interp, objPtr, &value); + if (flags == TCL_TYPE_D(float)) { + *(float *)ptr = (float) value; + } else { + *(long double *)ptr = (long double) value; + } + return result; +} /* *---------------------------------------------------------------------- |