summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2022-11-26 23:57:26 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2022-11-26 23:57:26 (GMT)
commit513b2d50314fa22ef6df699c698ee0f05b7f59b5 (patch)
treec4417e67a6e82b80abac34e9d224fa6a64357880
parentbfe8928bed8d82210b9a892f1ea0add32ac7ad59 (diff)
downloadtcl-513b2d50314fa22ef6df699c698ee0f05b7f59b5.zip
tcl-513b2d50314fa22ef6df699c698ee0f05b7f59b5.tar.gz
tcl-513b2d50314fa22ef6df699c698ee0f05b7f59b5.tar.bz2
HAS_ABSTRACTLIST_PROC
-rwxr-xr-xgeneric/tclArithSeries.c3
-rw-r--r--generic/tclInt.h18
-rw-r--r--generic/tclListObj.c23
-rw-r--r--generic/tclObj.c20
-rw-r--r--generic/tclUtil.c5
5 files changed, 38 insertions, 31 deletions
diff --git a/generic/tclArithSeries.c b/generic/tclArithSeries.c
index 34c0dd1..70bbb1b 100755
--- a/generic/tclArithSeries.c
+++ b/generic/tclArithSeries.c
@@ -76,8 +76,9 @@ const TclObjTypeWithAbstractList tclArithSeriesType = {
DupArithSeriesInternalRep, /* dupIntRepProc */
UpdateStringOfArithSeries, /* updateStringProc */
SetArithSeriesFromAny, /* setFromAnyProc */
- TCL_OBJTYPE_V0_1},
+ TCL_OBJTYPE_V0_1(
TclArithSeriesObjLength
+ )
};
/*
diff --git a/generic/tclInt.h b/generic/tclInt.h
index a58c401..0ff0d8e 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -1076,14 +1076,6 @@ typedef struct ActiveInterpTrace {
* in reverse order. */
} ActiveInterpTrace;
-
-#define TCL_OBJTYPE_V0_1 ((size_t)1) /* For internal core use only */
-
-typedef struct { /* For internal core use only */
- Tcl_ObjType objType;
- unsigned long long (*lengthProc)(Tcl_Obj *obj);
-} TclObjTypeWithAbstractList;
-
/*
* Flag values designating types of execution traces. See tclTrace.c for
* related flag values.
@@ -1099,6 +1091,16 @@ typedef struct { /* For internal core use only */
#define TCL_TRACE_ENTER_EXEC 1
#define TCL_TRACE_LEAVE_EXEC 2
+typedef struct { /* For internal core use only */
+ Tcl_ObjType objType;
+ unsigned long long (*lengthProc)(Tcl_Obj *obj);
+} TclObjTypeWithAbstractList;
+#define TCL_OBJTYPE_V0_1(lengthProc) (sizeof(TclObjTypeWithAbstractList)) \
+ }, lengthProc /* For internal core use only */
+#define HAS_ABSTRACTLIST_PROC(objPtr, proc) (objPtr->typePtr \
+ && (objPtr->typePtr->version > offsetof(TclObjTypeWithAbstractList, proc)) \
+ && (((const TclObjTypeWithAbstractList *)objPtr->typePtr)->proc))
+
/*
* The structure below defines an entry in the assocData hash table which is
* associated with an interpreter. The entry contains a pointer to a function
diff --git a/generic/tclListObj.c b/generic/tclListObj.c
index 4a5b3ae..565872e 100644
--- a/generic/tclListObj.c
+++ b/generic/tclListObj.c
@@ -158,8 +158,9 @@ const TclObjTypeWithAbstractList tclListType = {
DupListInternalRep, /* dupIntRepProc */
UpdateStringOfList, /* updateStringProc */
SetListFromAny, /* setFromAnyProc */
- TCL_OBJTYPE_V0_1},
- ListLength
+ TCL_OBJTYPE_V0_1(
+ ListLength
+ )
};
/* Macros to manipulate the List internal rep */
@@ -1994,19 +1995,17 @@ Tcl_ListObjLength(
Tcl_Obj *listObj, /* List object whose #elements to return. */
Tcl_Size *lenPtr) /* The resulting int is stored here. */
{
- if (listObj->typePtr && (listObj->typePtr->version == TCL_OBJTYPE_V0_1)) {
+ if (HAS_ABSTRACTLIST_PROC(listObj, lengthProc)) {
const TclObjTypeWithAbstractList *objType = (const TclObjTypeWithAbstractList *)listObj->typePtr;
- if (objType->lengthProc) {
- unsigned long long len = objType->lengthProc(listObj);
- if (len >= TCL_INDEX_NONE) {
- if (interp) {
- Tcl_AppendResult(interp, "List too large");
- }
- return TCL_ERROR;
+ unsigned long long len = objType->lengthProc(listObj);
+ if (len >= TCL_INDEX_NONE) {
+ if (interp) {
+ Tcl_AppendResult(interp, "List too large");
}
- *lenPtr = len;
- return TCL_OK;
+ return TCL_ERROR;
}
+ *lenPtr = len;
+ return TCL_OK;
}
/*
diff --git a/generic/tclObj.c b/generic/tclObj.c
index 5e3f4f1..ca7861f 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -233,8 +233,9 @@ const TclObjTypeWithAbstractList tclBooleanType= {
NULL, /* dupIntRepProc */
NULL, /* updateStringProc */
TclSetBooleanFromAny, /* setFromAnyProc */
- TCL_OBJTYPE_V0_1},
- LengthOne
+ TCL_OBJTYPE_V0_1(
+ LengthOne
+ )
};
const TclObjTypeWithAbstractList tclDoubleType= {
{"double", /* name */
@@ -242,8 +243,9 @@ const TclObjTypeWithAbstractList tclDoubleType= {
NULL, /* dupIntRepProc */
UpdateStringOfDouble, /* updateStringProc */
SetDoubleFromAny, /* setFromAnyProc */
- TCL_OBJTYPE_V0_1},
- LengthOne
+ TCL_OBJTYPE_V0_1(
+ LengthOne
+ )
};
const TclObjTypeWithAbstractList tclIntType = {
{"int", /* name */
@@ -251,8 +253,9 @@ const TclObjTypeWithAbstractList tclIntType = {
NULL, /* dupIntRepProc */
UpdateStringOfInt, /* updateStringProc */
SetIntFromAny, /* setFromAnyProc */
- TCL_OBJTYPE_V0_1},
- LengthOne
+ TCL_OBJTYPE_V0_1(
+ LengthOne
+ )
};
const TclObjTypeWithAbstractList tclBignumType = {
{"bignum", /* name */
@@ -260,8 +263,9 @@ const TclObjTypeWithAbstractList tclBignumType = {
DupBignum, /* dupIntRepProc */
UpdateStringOfBignum, /* updateStringProc */
NULL, /* setFromAnyProc */
- TCL_OBJTYPE_V0_1},
- LengthOne
+ TCL_OBJTYPE_V0_1(
+ LengthOne
+ )
};
/*
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index b23d134..58fb1e4 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -130,8 +130,9 @@ static const TclObjTypeWithAbstractList endOffsetType = {
NULL, /* dupIntRepProc */
NULL, /* updateStringProc */
NULL, /* setFromAnyProc */
- TCL_OBJTYPE_V0_1},
- LengthOne
+ TCL_OBJTYPE_V0_1(
+ LengthOne
+ )
};
/*