From d0002e5394b792fd71045acc4a43ef1c500009ee Mon Sep 17 00:00:00 2001 From: dgp Date: Fri, 7 Oct 2016 16:36:42 +0000 Subject: New routine Tcl_HasStringRep() and first conversion of callers. --- generic/tcl.decls | 3 +++ generic/tclBasic.c | 14 ++++++++------ generic/tclDecls.h | 5 +++++ generic/tclInt.h | 12 ++++++++++++ generic/tclObj.c | 19 +++++++++++++++++++ generic/tclStubInit.c | 1 + 6 files changed, 48 insertions(+), 6 deletions(-) diff --git a/generic/tcl.decls b/generic/tcl.decls index 953102b..d435fe4 100644 --- a/generic/tcl.decls +++ b/generic/tcl.decls @@ -2341,6 +2341,9 @@ declare 634 { void Tcl_StoreIntRep(Tcl_Obj *objPtr, const Tcl_ObjType *typePtr, const Tcl_ObjIntRep *irPtr) } +declare 635 { + int Tcl_HasStringRep(Tcl_Obj *objPtr) +} # ----- BASELINE -- FOR -- 8.7.0 ----- # diff --git a/generic/tclBasic.c b/generic/tclBasic.c index 9de8d1d..e17a831 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -5791,7 +5791,7 @@ TclArgumentGet( * up by the caller. It knows better than us. */ - if ((obj->bytes == NULL) || TclListObjIsCanonical(obj)) { + if (!TclHasStringRep(obj) || TclListObjIsCanonical(obj)) { return; } @@ -7413,14 +7413,16 @@ ExprAbsFunc( if (l > (long)0) { goto unChanged; } else if (l == (long)0) { - const char *string = objv[1]->bytes; - if (string) { - while (*string != '0') { - if (*string == '-') { + if (TclHasStringRep(objv[1])) { + int numBytes; + const char *bytes = TclGetStringFromObj(objv[1], &numBytes); + + while (numBytes) { + if (*bytes == '-') { Tcl_SetObjResult(interp, Tcl_NewLongObj(0)); return TCL_OK; } - string++; + bytes++; numBytes--; } } goto unChanged; diff --git a/generic/tclDecls.h b/generic/tclDecls.h index ed1e326..71598ab 100644 --- a/generic/tclDecls.h +++ b/generic/tclDecls.h @@ -1828,6 +1828,8 @@ EXTERN Tcl_ObjIntRep * Tcl_FetchIntRep(Tcl_Obj *objPtr, EXTERN void Tcl_StoreIntRep(Tcl_Obj *objPtr, const Tcl_ObjType *typePtr, const Tcl_ObjIntRep *irPtr); +/* 635 */ +EXTERN int Tcl_HasStringRep(Tcl_Obj *objPtr); typedef struct { const struct TclPlatStubs *tclPlatStubs; @@ -2498,6 +2500,7 @@ typedef struct TclStubs { char * (*tcl_InitStringRep) (Tcl_Obj *objPtr, const char *bytes, unsigned int numBytes); /* 632 */ Tcl_ObjIntRep * (*tcl_FetchIntRep) (Tcl_Obj *objPtr, const Tcl_ObjType *typePtr); /* 633 */ void (*tcl_StoreIntRep) (Tcl_Obj *objPtr, const Tcl_ObjType *typePtr, const Tcl_ObjIntRep *irPtr); /* 634 */ + int (*tcl_HasStringRep) (Tcl_Obj *objPtr); /* 635 */ } TclStubs; extern const TclStubs *tclStubsPtr; @@ -3798,6 +3801,8 @@ extern const TclStubs *tclStubsPtr; (tclStubsPtr->tcl_FetchIntRep) /* 633 */ #define Tcl_StoreIntRep \ (tclStubsPtr->tcl_StoreIntRep) /* 634 */ +#define Tcl_HasStringRep \ + (tclStubsPtr->tcl_HasStringRep) /* 635 */ #endif /* defined(USE_TCL_STUBS) */ diff --git a/generic/tclInt.h b/generic/tclInt.h index 6796949..89d9f32 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -4295,6 +4295,18 @@ MODULE_SCOPE void TclDbInitNewObj(Tcl_Obj *objPtr, const char *file, /* *---------------------------------------------------------------- + * Macro used by the Tcl core to test whether an object has a + * string representation (or is a 'pure' internal value). + * The ANSI C "prototype" for this macro is: + * + * MODULE_SCOPE int TclHasStringRep(Tcl_Obj *objPtr); + *---------------------------------------------------------------- + */ + +#define TclHasStringRep(objPtr) ((objPtr)->bytes != NULL) + +/* + *---------------------------------------------------------------- * Macros used by the Tcl core to grow Tcl_Token arrays. They use the same * growth algorithm as used in tclStringObj.c for growing strings. The ANSI C * "prototype" for this macro is: diff --git a/generic/tclObj.c b/generic/tclObj.c index 368ba52..387f92b 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -1810,6 +1810,25 @@ Tcl_InvalidateStringRep( /* *---------------------------------------------------------------------- * + * Tcl_HasStringRep -- + * + * This function reports whether object has a string representation. + * + * Results: + * Boolean. + *---------------------------------------------------------------------- + */ + +int +Tcl_HasStringRep( + Tcl_Obj *objPtr) /* Object to test */ +{ + return TclHasStringRep(objPtr); +} + +/* + *---------------------------------------------------------------------- + * * Tcl_StoreIntRep -- * * This function is called to set the object's internal diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c index 2af47b7..c5c8e80 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -1419,6 +1419,7 @@ const TclStubs tclStubs = { Tcl_InitStringRep, /* 632 */ Tcl_FetchIntRep, /* 633 */ Tcl_StoreIntRep, /* 634 */ + Tcl_HasStringRep, /* 635 */ }; /* !END!: Do not edit above this line. */ -- cgit v0.12