Tcl Source Code

Check-in [b0ceb88495]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[array size] should 0 if argument does not name an array. TODO: Distinguish between existence errors and trace errors. Hide the former and report the latter for compatibility with [array size].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | amg-array-enum-c-api
Files: files | file ages | folders
SHA1: b0ceb884951321ca4566a56ced60e5f2c5847092
User & Date: andy 2016-11-21 18:25:04
Context
2016-11-24
18:34
Rename part1Ptr arguments to varNamePtr check-in: f2a8e2d0fb user: andy tags: amg-array-enum-c-api
2016-11-21
18:25
[array size] should 0 if argument does not name an array. TODO: Distinguish between existence error... check-in: b0ceb88495 user: andy tags: amg-array-enum-c-api
13:12
Initial commit of new C API for array enumeration. TIP forthcoming. Work far from complete, only T... check-in: 405aba7ca5 user: andy tags: amg-array-enum-c-api
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclVar.c.

1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088


1089
1090
1091
1092
1093
1094
1095
1096
1097
1098

1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109



1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
....
3795
3796
3797
3798
3799
3800
3801
3802
3803











3804
3805
3806
3807
3808
3809
3810
int
Tcl_ArraySize(
    Tcl_Interp *interp,		/* Command interpreter in which part1Ptr is to
				 * be looked up. */
    Tcl_Obj *part1Ptr,		/* Name of array variable in interp. */
    int flags)			/* OR-ed combination of TCL_GLOBAL_ONLY,
				 * TCL_NAMESPACE_ONLY or TCL_LEAVE_ERR_MSG
				 * bits. */
{
    Interp *iPtr = (Interp *) interp;
    Var *varPtr, *arrayPtr;
    Tcl_HashSearch search;
    Var *varPtr2;
    int leaveErrMsg = flags & TCL_LEAVE_ERR_MSG ? 1 : 0;
    int size = 0;

    /*
     * Locate the array variable.
     */

    varPtr = TclObjLookupVarEx(interp, part1Ptr, NULL, /*flags*/ 0,
	    /*msg*/ 0, /*createPart1*/ 0, /*createPart2*/ 0, &arrayPtr);



    /*
     * Special array trace used to keep the env array in sync for array names,
     * array get, etc.
     */

    if (varPtr && (varPtr->flags & VAR_TRACED_ARRAY)
	    && (TclIsVarArray(varPtr) || TclIsVarUndefined(varPtr))) {
	if (TclObjCallVarTraces(iPtr, arrayPtr, varPtr, part1Ptr, NULL,
		flags|TCL_TRACE_ARRAY, leaveErrMsg, -1) == TCL_ERROR) {

	    return -1;
	}
    }

    /*
     * Verify that it is indeed an array variable. This test comes after the
     * traces - the variable may actually become an array as an effect of said
     * traces. We can only iterate over the array if it exists...
     */

    if (varPtr && TclIsVarArray(varPtr) && !TclIsVarUndefined(varPtr)) {



	/*
	 * Must iterate in order to get chance to check for present but
	 * "undefined" entries.
	 */

	for (varPtr2=VarHashFirstVar(varPtr->value.tablePtr, &search);
		varPtr2!=NULL ; varPtr2=VarHashNextVar(&search)) {
	    if (!TclIsVarUndefined(varPtr2)) {
		size++;
	    }
	}
    }

    return size;
}
 
/*
................................................................................
    int size;

    if (objc != 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "arrayName");
	return TCL_ERROR;
    }

    if ((size = Tcl_ArraySize(interp, objv[1], TCL_LEAVE_ERR_MSG)) < 0) {
	return TCL_ERROR;











    }

    Tcl_SetObjResult(interp, Tcl_NewIntObj(size));
    return TCL_OK;
}
 
/*






|






<
|





|
|
>
>






|

|
|
>










|
>
>
>
|
|
<
|

|
|
|
|
<







 







|
<
>
>
>
>
>
>
>
>
>
>
>







1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079

1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116

1117
1118
1119
1120
1121
1122

1123
1124
1125
1126
1127
1128
1129
....
3798
3799
3800
3801
3802
3803
3804
3805

3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
int
Tcl_ArraySize(
    Tcl_Interp *interp,		/* Command interpreter in which part1Ptr is to
				 * be looked up. */
    Tcl_Obj *part1Ptr,		/* Name of array variable in interp. */
    int flags)			/* OR-ed combination of TCL_GLOBAL_ONLY,
				 * TCL_NAMESPACE_ONLY and/or TCL_LEAVE_ERR_MSG
				 * bits. */
{
    Interp *iPtr = (Interp *) interp;
    Var *varPtr, *arrayPtr;
    Tcl_HashSearch search;
    Var *varPtr2;

    int size;

    /*
     * Locate the array variable.
     */

    if (!(varPtr = TclObjLookupVarEx(interp, part1Ptr, NULL, flags, "read",
	    /*createPart1*/ 0, /*createPart2*/ 0, &arrayPtr))) {
	return -1;
    }

    /*
     * Special array trace used to keep the env array in sync for array names,
     * array get, etc.
     */

    if ((varPtr->flags & VAR_TRACED_ARRAY)
	    && (TclIsVarArray(varPtr) || TclIsVarUndefined(varPtr))) {
	if (TclObjCallVarTraces(iPtr, arrayPtr, varPtr,
		part1Ptr, NULL, flags|TCL_TRACE_ARRAY,
		!!(flags & TCL_LEAVE_ERR_MSG, -1) == TCL_ERROR)) {
	    return -1;
	}
    }

    /*
     * Verify that it is indeed an array variable. This test comes after the
     * traces - the variable may actually become an array as an effect of said
     * traces. We can only iterate over the array if it exists...
     */

    if (TclIsVarArray(varPtr) && !TclIsVarUndefined(varPtr)) {
	return -1;
    }

    /*
     * Must iterate to get chance to check for present but "undefined" entries.

     */

    for (varPtr2=VarHashFirstVar(varPtr->value.tablePtr, &search);
	    varPtr2!=NULL ; varPtr2=VarHashNextVar(&search)) {
	if (!TclIsVarUndefined(varPtr2)) {
	    size++;

	}
    }

    return size;
}
 
/*
................................................................................
    int size;

    if (objc != 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "arrayName");
	return TCL_ERROR;
    }

    size = Tcl_ArraySize(interp, objv[1], 0);


    /*
     * The [array size] command reports nonexistent and non-array variables as
     * having zero size.
     *
     * XXX: Distinguish between existence errors and trace errors.  Hide the
     * former and report the latter for compatibility with [array size].
     */

    if (size < 0) {
	size = 0;
    }

    Tcl_SetObjResult(interp, Tcl_NewIntObj(size));
    return TCL_OK;
}
 
/*