summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
Diffstat (limited to 'generic')
-rw-r--r--generic/tcl.decls4
-rw-r--r--generic/tclCompCmdsGR.c3
-rw-r--r--generic/tclCompCmdsSZ.c4
-rw-r--r--generic/tclCompExpr.c3
-rw-r--r--generic/tclDecls.h26
-rw-r--r--generic/tclGet.c9
-rw-r--r--generic/tclInt.h2
-rw-r--r--generic/tclObj.c30
-rw-r--r--generic/tclTest.c29
9 files changed, 63 insertions, 47 deletions
diff --git a/generic/tcl.decls b/generic/tcl.decls
index 3d59139..2c19545 100644
--- a/generic/tcl.decls
+++ b/generic/tcl.decls
@@ -2457,11 +2457,11 @@ declare 668 {
declare 674 {
int Tcl_GetBool(Tcl_Interp *interp, const char *src, int flags,
- void *boolPtr)
+ char *boolPtr)
}
declare 675 {
int Tcl_GetBoolFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
- int flags, void *boolPtr)
+ int flags, char *boolPtr)
}
diff --git a/generic/tclCompCmdsGR.c b/generic/tclCompCmdsGR.c
index da557a4..839fbde 100644
--- a/generic/tclCompCmdsGR.c
+++ b/generic/tclCompCmdsGR.c
@@ -17,6 +17,7 @@
#include "tclInt.h"
#include "tclCompile.h"
#include <assert.h>
+#include <stdbool.h>
/*
* Prototypes for procedures defined later in this file:
@@ -185,7 +186,7 @@ TclCompileIfCmd(
const char *word;
int realCond = 1; /* Set to 0 for static conditions:
* "if 0 {..}" */
- int boolVal; /* Value of static condition. */
+ bool boolVal; /* Value of static condition. */
int compileScripts = 1;
/*
diff --git a/generic/tclCompCmdsSZ.c b/generic/tclCompCmdsSZ.c
index cd3bd37..fa490a1 100644
--- a/generic/tclCompCmdsSZ.c
+++ b/generic/tclCompCmdsSZ.c
@@ -18,6 +18,7 @@
#include "tclInt.h"
#include "tclCompile.h"
#include "tclStringTrim.h"
+#include <stdbool.h>
/*
* Prototypes for procedures defined later in this file:
@@ -3759,7 +3760,8 @@ TclCompileWhileCmd(
DefineLineInformation; /* TIP #280 */
Tcl_Token *testTokenPtr, *bodyTokenPtr;
JumpFixup jumpEvalCondFixup;
- int testCodeOffset, bodyCodeOffset, jumpDist, range, code, boolVal;
+ int testCodeOffset, bodyCodeOffset, jumpDist, range, code;
+ bool boolVal;
int loopMayEnd = 1; /* This is set to 0 if it is recognized as an
* infinite loop. */
Tcl_Obj *boolObj;
diff --git a/generic/tclCompExpr.c b/generic/tclCompExpr.c
index 23d8711..c245b4e 100644
--- a/generic/tclCompExpr.c
+++ b/generic/tclCompExpr.c
@@ -13,6 +13,7 @@
#include "tclInt.h"
#include "tclCompile.h" /* CompileEnv */
+#include <stdbool.h>
/*
* Expression parsing takes place in the routine ParseExpr(). It takes a
@@ -708,7 +709,7 @@ ParseExpr(
*/
if ((NODE_TYPE & lexeme) == 0) {
- int b;
+ bool b;
switch (lexeme) {
case COMMENT:
diff --git a/generic/tclDecls.h b/generic/tclDecls.h
index d75e605..04f8aa3 100644
--- a/generic/tclDecls.h
+++ b/generic/tclDecls.h
@@ -1970,10 +1970,10 @@ EXTERN int Tcl_UniCharLen(const int *uniStr);
/* Slot 673 is reserved */
/* 674 */
EXTERN int Tcl_GetBool(Tcl_Interp *interp, const char *src,
- int flags, void *boolPtr);
+ int flags, char *boolPtr);
/* 675 */
EXTERN int Tcl_GetBoolFromObj(Tcl_Interp *interp,
- Tcl_Obj *objPtr, int flags, void *boolPtr);
+ Tcl_Obj *objPtr, int flags, char *boolPtr);
typedef struct {
const struct TclPlatStubs *tclPlatStubs;
@@ -2683,8 +2683,8 @@ typedef struct TclStubs {
void (*reserved671)(void);
void (*reserved672)(void);
void (*reserved673)(void);
- int (*tcl_GetBool) (Tcl_Interp *interp, const char *src, int flags, void *boolPtr); /* 674 */
- int (*tcl_GetBoolFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, int flags, void *boolPtr); /* 675 */
+ int (*tcl_GetBool) (Tcl_Interp *interp, const char *src, int flags, char *boolPtr); /* 674 */
+ int (*tcl_GetBoolFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, int flags, char *boolPtr); /* 675 */
} TclStubs;
extern const TclStubs *tclStubsPtr;
@@ -4270,12 +4270,22 @@ extern const TclStubs *tclStubsPtr;
Tcl_GetUnicodeFromObj(objPtr, (int *)NULL)
#undef Tcl_GetBytesFromObj
#undef Tcl_GetIndexFromObjStruct
+#undef Tcl_GetBoolean
+#undef Tcl_GetBooleanFromObj
#ifdef TCL_NO_DEPRECATED
#undef Tcl_GetStringFromObj
#undef Tcl_GetUnicodeFromObj
#undef Tcl_GetByteArrayFromObj
#endif
#if defined(USE_TCL_STUBS)
+#define Tcl_GetBoolean(interp, objPtr, boolPtr) \
+ (sizeof(*(boolPtr)) == sizeof(int) ? tclStubsPtr->tcl_GetBoolean(interp, objPtr, (int *)(boolPtr)) : \
+ (sizeof(*(boolPtr)) == sizeof(char) ? tclStubsPtr->tcl_GetBool(interp, objPtr, 0, (char *)(boolPtr)) : \
+ (Tcl_Panic("Invalid boolean variable: sizeof() must be 1 or 4"), TCL_ERROR)))
+#define Tcl_GetBooleanFromObj(interp, objPtr, boolPtr) \
+ (sizeof(*(boolPtr)) == sizeof(int) ? tclStubsPtr->tcl_GetBooleanFromObj(interp, objPtr, (int *)(boolPtr)) : \
+ (sizeof(*(boolPtr)) == sizeof(char) ? tclStubsPtr->tcl_GetBoolFromObj(interp, objPtr, 0, (char *)(boolPtr)) : \
+ (Tcl_Panic("Invalid boolean variable: sizeof() must be 1 or 4"), TCL_ERROR)))
#define Tcl_GetBytesFromObj(interp, objPtr, sizePtr) \
(sizeof(*(sizePtr)) <= sizeof(int) ? tclStubsPtr->tclGetBytesFromObj(interp, objPtr, (int *)(sizePtr)) : tclStubsPtr->tcl_GetBytesFromObj(interp, objPtr, (size_t *)(sizePtr)))
#define Tcl_GetIndexFromObjStruct(interp, objPtr, tablePtr, offset, msg, flags, indexPtr) \
@@ -4289,6 +4299,14 @@ extern const TclStubs *tclStubsPtr;
(sizeof(*(sizePtr)) <= sizeof(int) ? tclStubsPtr->tcl_GetUnicodeFromObj(objPtr, (int *)(sizePtr)) : tclStubsPtr->tclGetUnicodeFromObj(objPtr, (size_t *)(sizePtr)))
#endif
#else
+#define Tcl_GetBoolean(interp, objPtr, boolPtr) \
+ (sizeof(*(boolPtr)) == sizeof(int) ? (Tcl_GetBoolean)(interp, objPtr, (int *)(boolPtr)) : \
+ (sizeof(*(boolPtr)) == sizeof(char) ? (Tcl_GetBool)(interp, objPtr, 0, (char *)(boolPtr)) : \
+ (Tcl_Panic("Invalid boolean variable: sizeof() must be 1 or 4"), TCL_ERROR)))
+#define Tcl_GetBooleanFromObj(interp, objPtr, boolPtr) \
+ (sizeof(*(boolPtr)) == sizeof(int) ? (Tcl_GetBooleanFromObj)(interp, objPtr, (int *)(boolPtr)) : \
+ (sizeof(*(boolPtr)) == sizeof(char) ? (Tcl_GetBoolFromObj)(interp, objPtr, 0, (char *)(boolPtr)) : \
+ (Tcl_Panic("Invalid boolean variable: sizeof() must be 1 or 4"), TCL_ERROR)))
#define Tcl_GetBytesFromObj(interp, objPtr, sizePtr) \
(sizeof(*(sizePtr)) <= sizeof(int) ? (TclGetBytesFromObj)(interp, objPtr, (int *)(sizePtr)) : (Tcl_GetBytesFromObj)(interp, objPtr, (size_t *)(sizePtr)))
#define Tcl_GetIndexFromObjStruct(interp, objPtr, tablePtr, offset, msg, flags, indexPtr) \
diff --git a/generic/tclGet.c b/generic/tclGet.c
index 0e07da1..a60d3a6 100644
--- a/generic/tclGet.c
+++ b/generic/tclGet.c
@@ -128,7 +128,7 @@ Tcl_GetBool(
const char *src, /* String containing one of the boolean values
* 1, 0, true, false, yes, no, on, off. */
int flags,
- void *boolPtr) /* Place to store converted result, which will
+ char *boolPtr) /* Place to store converted result, which will
* be 0 or 1. */
{
Tcl_Obj obj;
@@ -161,7 +161,12 @@ Tcl_GetBoolean(
int *intPtr) /* Place to store converted result, which will
* be 0 or 1. */
{
- return Tcl_GetBool(interp, src, sizeof(int), intPtr);
+ char boolValue;
+ int result = Tcl_GetBool(interp, src, 0, &boolValue);
+ if (intPtr) {
+ *intPtr = boolValue;
+ }
+ return result;
}
/*
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 2ee22f3..61cc3b3 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -2512,7 +2512,7 @@ typedef struct List {
? (*(intPtr) = ((objPtr)->internalRep.wideValue!=0), TCL_OK) \
: ((objPtr)->typePtr == &tclBooleanType) \
? (*(intPtr) = ((objPtr)->internalRep.longValue!=0), TCL_OK) \
- : Tcl_GetBoolFromObj((interp), (objPtr), (int)sizeof(int), (intPtr)))
+ : Tcl_GetBooleanFromObj((interp), (objPtr), (intPtr)))
#ifdef TCL_WIDE_INT_IS_LONG
#define TclGetLongFromObj(interp, objPtr, longPtr) \
diff --git a/generic/tclObj.c b/generic/tclObj.c
index 40fc73b..7842d0d 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -2161,7 +2161,7 @@ Tcl_GetBoolFromObj(
Tcl_Interp *interp, /* Used for error reporting if not NULL. */
Tcl_Obj *objPtr, /* The object from which to get boolean. */
int flags,
- void *boolPtr) /* Place to store resulting boolean. */
+ char *boolPtr) /* Place to store resulting boolean. */
{
int result;
@@ -2171,7 +2171,8 @@ Tcl_GetBoolFromObj(
} else if (objPtr == NULL) {
if (interp) {
TclNewObj(objPtr);
- TclParseNumber(interp, objPtr, "boolean value", NULL,-1,NULL,0);
+ TclParseNumber(interp, objPtr, (flags & TCL_NULL_OK)
+ ? "boolean value or \"\"" : "boolean value", NULL, -1, NULL, 0);
Tcl_DecrRefCount(objPtr);
}
return TCL_ERROR;
@@ -2206,25 +2207,13 @@ Tcl_GetBoolFromObj(
result = 1;
boolEnd:
if (boolPtr != NULL) {
- flags &= (TCL_NULL_OK - 1);
- if (flags & (int)~sizeof(int8_t)) {
- if (flags == sizeof(int16_t)) {
- *(int16_t *)boolPtr = result;
- return TCL_OK;
- } else if (flags == sizeof(int32_t)) {
- *(int32_t *)boolPtr = result;
- return TCL_OK;
- } else if (flags == sizeof(int64_t)) {
- *(int64_t *)boolPtr = result;
- return TCL_OK;
- }
- }
- *(int8_t *)boolPtr = result;
+ *boolPtr = result;
}
return TCL_OK;
}
} while ((ParseBoolean(objPtr) == TCL_OK) || (TCL_OK ==
- TclParseNumber(interp, objPtr, "boolean value", NULL,-1,NULL,0)));
+ TclParseNumber(interp, objPtr, (flags & TCL_NULL_OK)
+ ? "boolean value or \"\"" : "boolean value", NULL,-1,NULL,0)));
return TCL_ERROR;
}
@@ -2235,7 +2224,12 @@ Tcl_GetBooleanFromObj(
Tcl_Obj *objPtr, /* The object from which to get boolean. */
int *intPtr) /* Place to store resulting boolean. */
{
- return Tcl_GetBoolFromObj(interp, objPtr, sizeof(int), intPtr);
+ char boolValue;
+ int result = Tcl_GetBoolFromObj(interp, objPtr, 0, &boolValue);
+ if (intPtr) {
+ *intPtr = boolValue;
+ }
+ return result;
}
/*
diff --git a/generic/tclTest.c b/generic/tclTest.c
index 4cd9bab..39364d6 100644
--- a/generic/tclTest.c
+++ b/generic/tclTest.c
@@ -30,6 +30,7 @@
#endif
#include "tclOO.h"
#include <math.h>
+#include <stdbool.h>
/*
* Required for Testregexp*Cmd
@@ -2262,7 +2263,7 @@ TesteventProc(
Tcl_Obj *command = ev->command;
int result = Tcl_EvalObjEx(interp, command,
TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT);
- char retval[3];
+ bool retval;
if (result != TCL_OK) {
Tcl_AddErrorInfo(interp,
@@ -2270,19 +2271,19 @@ TesteventProc(
Tcl_BackgroundException(interp, TCL_ERROR);
return 1; /* Avoid looping on errors */
}
- if (Tcl_GetBoolFromObj(interp, Tcl_GetObjResult(interp),
- sizeof(retval[1]), &retval[1]) != TCL_OK) {
+ if (Tcl_GetBooleanFromObj(interp, Tcl_GetObjResult(interp),
+ &retval) != TCL_OK) {
Tcl_AddErrorInfo(interp,
" (return value from \"testevent\" callback)");
Tcl_BackgroundException(interp, TCL_ERROR);
return 1;
}
- if (retval[1]) {
+ if (retval) {
Tcl_DecrRefCount(ev->tag);
Tcl_DecrRefCount(ev->command);
}
- return retval[1];
+ return retval;
}
/*
@@ -5277,7 +5278,7 @@ TestsaveresultCmd(
{
Interp* iPtr = (Interp*) interp;
int result, index;
- char b[3];
+ bool discard;
Tcl_SavedResult state;
Tcl_Obj *objPtr;
static const char *const optionStrings[] = {
@@ -5299,17 +5300,11 @@ TestsaveresultCmd(
&index) != TCL_OK) {
return TCL_ERROR;
}
- b[0] = b[1] = b[2] = 100;
- if (Tcl_GetBoolFromObj(interp, objv[3], sizeof(b[1]), b + 1) != TCL_OK)
- {
- return TCL_ERROR;
- }
- if (b[0] != 100 || b[2] != 100) {
- Tcl_Panic("MEMORY OVERWRITE IN Tcl_GetBoolFromObj");
- return TCL_ERROR;
- }
+ if (Tcl_GetBooleanFromObj(interp, objv[3], &discard) != TCL_OK) {
+ return TCL_ERROR;
+ }
- freeCount = 0;
+ freeCount = 0;
objPtr = NULL; /* Lint. */
switch ((enum options) index) {
case RESULT_SMALL:
@@ -5342,7 +5337,7 @@ TestsaveresultCmd(
result = Tcl_EvalEx(interp, Tcl_GetString(objv[2]), -1, 0);
}
- if (b[1]) {
+ if (discard) {
Tcl_DiscardResult(&state);
} else {
Tcl_RestoreResult(interp, &state);