From 9e43cbb9739ecfd05d38ff31a49050a0eb04505b Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 20 Sep 2020 21:32:35 +0000 Subject: Improve TclInvalidateStringRep() macro such that (objPtr) is only evaluated once. Addation brackets in TclHasStringRep() macro --- generic/tcl.h | 2 +- generic/tclInt.h | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/generic/tcl.h b/generic/tcl.h index 458072a..914f62b 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -2517,7 +2517,7 @@ EXTERN void Tcl_GetMemoryInfo(Tcl_DString *dsPtr); # define Tcl_DecrRefCount(objPtr) \ do { \ Tcl_Obj *_objPtr = (objPtr); \ - if ((_objPtr)->refCount-- <= 1) { \ + if (_objPtr->refCount-- <= 1) { \ TclFreeObj(_objPtr); \ } \ } while(0) diff --git a/generic/tclInt.h b/generic/tclInt.h index 3dbffeb..f2f097c 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -4369,15 +4369,18 @@ MODULE_SCOPE void TclDbInitNewObj(Tcl_Obj *objPtr, const char *file, */ #define TclInvalidateStringRep(objPtr) \ - if (objPtr->bytes != NULL) { \ - if (objPtr->bytes != tclEmptyStringRep) { \ - ckfree((char *) objPtr->bytes); \ + do { \ + Tcl_Obj *_isobjPtr = (Tcl_Obj *)(objPtr); \ + if (_isobjPtr->bytes != NULL) { \ + if (_isobjPtr->bytes != tclEmptyStringRep) { \ + ckfree((char *)_isobjPtr->bytes); \ + } \ + _isobjPtr->bytes = NULL; \ } \ - objPtr->bytes = NULL; \ - } + } while (0) #define TclHasStringRep(objPtr) \ - (objPtr->bytes != NULL) + ((objPtr)->bytes != NULL) /* *---------------------------------------------------------------- -- cgit v0.12