Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch amg-array-enum-c-api Through [e098e8ef7f] Excluding Merge-Ins
This is equivalent to a diff from ad557c91a9 to e098e8ef7f
|
2016-11-25
| ||
| 07:02 | Add filtering options to [array size] command check-in: 3c19724381 user: andy tags: amg-array-enum-c-api | |
| 06:27 | Correct bug by splitting Tcl_ArrayNames() to high-level Tcl_ArrayNames() operating on a variable nam... check-in: e098e8ef7f user: andy tags: amg-array-enum-c-api | |
| 05:53 | Implement Tcl_ArrayNames(), still have a bug to fix though check-in: a7b63341ab user: andy tags: amg-array-enum-c-api | |
| 01:39 | Remove spurious article in comments check-in: 965949e559 user: andy tags: trunk | |
|
2016-11-24
| ||
| 20:55 | merge trunk check-in: c1735f1869 user: jan.nijtmans tags: package_files | |
| 20:31 | merge trunk check-in: 4115262f80 user: jan.nijtmans tags: novem | |
| 19:22 | Merge trunk check-in: a353ee5093 user: andy tags: amg-array-enum-c-api | |
| 19:21 | Partially backout [ef4da65408] because AppendPrintfToObjVA() (used indirectly by [tcl::unsupported::... check-in: ad557c91a9 user: andy tags: trunk | |
| 13:33 | Make compileEpoch "unsigned int", and start counting at 1. check-in: 83f0d245d8 user: jan.nijtmans tags: trunk | |
Changes to generic/tcl.decls.
| ︙ | |||
2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 | 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 | + + + + + + + + + + + + + + + + + + + + |
# TIP #400
declare 630 {
void Tcl_ZlibStreamSetCompressionDictionary(Tcl_ZlibStream zhandle,
Tcl_Obj *compressionDictionaryObj)
}
# ----- BASELINE -- FOR -- 8.6.0 ----- #
# TIP #XXX
declare 631 {
int Tcl_ArraySize(Tcl_Interp *interp, Tcl_Obj *part1Ptr,
Tcl_Obj *part2Ptr, int flags)
}
declare 632 {
Tcl_ArraySearch Tcl_ArraySearchStart(Tcl_Interp *interp,
Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, int flags)
}
declare 633 {
Tcl_Obj *Tcl_ArraySearchNext(Tcl_ArraySearch search)
}
declare 634 {
void Tcl_ArraySearchDone(Tcl_ArraySearch search)
}
declare 635 {
int Tcl_ArrayNames(Tcl_Interp *interp, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr,
Tcl_Obj *listPtr, int flags)
}
##############################################################################
# Define the platform specific public Tcl interface. These functions are only
# available on the designated platform.
interface tclPlat
|
| ︙ |
Changes to generic/tcl.h.
| ︙ | |||
528 529 530 531 532 533 534 535 536 537 538 539 540 541 | 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | + |
#else
int errorLineDontUse; /* Don't use in extensions! */
#endif
}
#endif /* TCL_NO_DEPRECATED */
Tcl_Interp;
typedef struct Tcl_ArraySearch_ *Tcl_ArraySearch;
typedef struct Tcl_AsyncHandler_ *Tcl_AsyncHandler;
typedef struct Tcl_Channel_ *Tcl_Channel;
typedef struct Tcl_ChannelTypeVersion_ *Tcl_ChannelTypeVersion;
typedef struct Tcl_Command_ *Tcl_Command;
typedef struct Tcl_Condition_ *Tcl_Condition;
typedef struct Tcl_Dict_ *Tcl_Dict;
typedef struct Tcl_EncodingState_ *Tcl_EncodingState;
|
| ︙ | |||
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 | 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 | + + + | /* * Flag values passed to variable-related functions. * WARNING: these bit choices must not conflict with the bit choice for * TCL_CANCEL_UNWIND, above. */ #define TCL_MATCH_EXACT 0 #define TCL_GLOBAL_ONLY 1 #define TCL_NAMESPACE_ONLY 2 #define TCL_APPEND_VALUE 4 #define TCL_LIST_ELEMENT 8 #define TCL_TRACE_READS 0x10 #define TCL_TRACE_WRITES 0x20 #define TCL_TRACE_UNSETS 0x40 #define TCL_TRACE_DESTROYED 0x80 #define TCL_INTERP_DESTROYED 0x100 #define TCL_LEAVE_ERR_MSG 0x200 #define TCL_MATCH_GLOB 0x400 #define TCL_TRACE_ARRAY 0x800 #ifndef TCL_REMOVE_OBSOLETE_TRACES /* Required to support old variable/vdelete/vinfo traces. */ #define TCL_TRACE_OLD_STYLE 0x1000 #endif #define TCL_MATCH_REGEXP 0x2000 /* Indicate the semantics of the result of a trace. */ #define TCL_TRACE_RESULT_DYNAMIC 0x8000 #define TCL_TRACE_RESULT_OBJECT 0x10000 /* * Flag values for ensemble commands. */ |
| ︙ |
Changes to generic/tclDecls.h.
| ︙ | |||
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 | 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 | + + + + + + + + + + + + + + + |
/* 629 */
EXTERN int Tcl_FSUnloadFile(Tcl_Interp *interp,
Tcl_LoadHandle handlePtr);
/* 630 */
EXTERN void Tcl_ZlibStreamSetCompressionDictionary(
Tcl_ZlibStream zhandle,
Tcl_Obj *compressionDictionaryObj);
/* 631 */
EXTERN int Tcl_ArraySize(Tcl_Interp *interp, Tcl_Obj *part1Ptr,
Tcl_Obj *part2Ptr, int flags);
/* 632 */
EXTERN Tcl_ArraySearch Tcl_ArraySearchStart(Tcl_Interp *interp,
Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr,
int flags);
/* 633 */
EXTERN Tcl_Obj * Tcl_ArraySearchNext(Tcl_ArraySearch search);
/* 634 */
EXTERN void Tcl_ArraySearchDone(Tcl_ArraySearch search);
/* 635 */
EXTERN int Tcl_ArrayNames(Tcl_Interp *interp, Tcl_Obj *part1Ptr,
Tcl_Obj *part2Ptr, Tcl_Obj *listPtr,
int flags);
typedef struct {
const struct TclPlatStubs *tclPlatStubs;
const struct TclIntStubs *tclIntStubs;
const struct TclIntPlatStubs *tclIntPlatStubs;
} TclStubHooks;
|
| ︙ | |||
2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 | 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 | + + + + + |
int (*tcl_CloseEx) (Tcl_Interp *interp, Tcl_Channel chan, int flags); /* 624 */
int (*tcl_NRExprObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, Tcl_Obj *resultPtr); /* 625 */
int (*tcl_NRSubstObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, int flags); /* 626 */
int (*tcl_LoadFile) (Tcl_Interp *interp, Tcl_Obj *pathPtr, const char *const symv[], int flags, void *procPtrs, Tcl_LoadHandle *handlePtr); /* 627 */
void * (*tcl_FindSymbol) (Tcl_Interp *interp, Tcl_LoadHandle handle, const char *symbol); /* 628 */
int (*tcl_FSUnloadFile) (Tcl_Interp *interp, Tcl_LoadHandle handlePtr); /* 629 */
void (*tcl_ZlibStreamSetCompressionDictionary) (Tcl_ZlibStream zhandle, Tcl_Obj *compressionDictionaryObj); /* 630 */
int (*tcl_ArraySize) (Tcl_Interp *interp, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, int flags); /* 631 */
Tcl_ArraySearch (*tcl_ArraySearchStart) (Tcl_Interp *interp, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, int flags); /* 632 */
Tcl_Obj * (*tcl_ArraySearchNext) (Tcl_ArraySearch search); /* 633 */
void (*tcl_ArraySearchDone) (Tcl_ArraySearch search); /* 634 */
int (*tcl_ArrayNames) (Tcl_Interp *interp, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, Tcl_Obj *listPtr, int flags); /* 635 */
} TclStubs;
extern const TclStubs *tclStubsPtr;
#ifdef __cplusplus
}
#endif
|
| ︙ | |||
3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 | 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 | + + + + + + + + + + | (tclStubsPtr->tcl_LoadFile) /* 627 */ #define Tcl_FindSymbol \ (tclStubsPtr->tcl_FindSymbol) /* 628 */ #define Tcl_FSUnloadFile \ (tclStubsPtr->tcl_FSUnloadFile) /* 629 */ #define Tcl_ZlibStreamSetCompressionDictionary \ (tclStubsPtr->tcl_ZlibStreamSetCompressionDictionary) /* 630 */ #define Tcl_ArraySize \ (tclStubsPtr->tcl_ArraySize) /* 631 */ #define Tcl_ArraySearchStart \ (tclStubsPtr->tcl_ArraySearchStart) /* 632 */ #define Tcl_ArraySearchNext \ (tclStubsPtr->tcl_ArraySearchNext) /* 633 */ #define Tcl_ArraySearchDone \ (tclStubsPtr->tcl_ArraySearchDone) /* 634 */ #define Tcl_ArrayNames \ (tclStubsPtr->tcl_ArrayNames) /* 635 */ #endif /* defined(USE_TCL_STUBS) */ /* !END!: Do not edit above this line. */ #if defined(USE_TCL_STUBS) # undef Tcl_CreateInterp |
| ︙ |
Changes to generic/tclStubInit.c.
| ︙ | |||
1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 | 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 | + + + + + |
Tcl_CloseEx, /* 624 */
Tcl_NRExprObj, /* 625 */
Tcl_NRSubstObj, /* 626 */
Tcl_LoadFile, /* 627 */
Tcl_FindSymbol, /* 628 */
Tcl_FSUnloadFile, /* 629 */
Tcl_ZlibStreamSetCompressionDictionary, /* 630 */
Tcl_ArraySize, /* 631 */
Tcl_ArraySearchStart, /* 632 */
Tcl_ArraySearchNext, /* 633 */
Tcl_ArraySearchDone, /* 634 */
Tcl_ArrayNames, /* 635 */
};
/* !END!: Do not edit above this line. */
|
Changes to generic/tclVar.c.
| ︙ | |||
44 45 46 47 48 49 50 | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | + + + + + + + + - + - + |
static inline Var * VarHashNextVar(Tcl_HashSearch *searchPtr);
static inline void CleanupVar(Var *varPtr, Var *arrayPtr);
#define VarHashGetValue(hPtr) \
((Var *) ((char *)hPtr - TclOffset(VarInHash, entry)))
/*
* Bit mask matching any of the bits used to select a match filter. AND this
* mask against a flags value to obtain a value which can be compared against
* each of the available match modes using the "==" equality operator.
*/
#define TCL_MATCH (TCL_MATCH_EXACT | TCL_MATCH_GLOB | TCL_MATCH_REGEXP)
/*
|
| ︙ | |||
141 142 143 144 145 146 147 | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | - + + + - + + + - + - - + + - - - + + - - + - + + + | * true if we are inside a procedure body. */ #define HasLocalVars(framePtr) ((framePtr)->isProcCallFrame & FRAME_IS_PROC) /* * The following structure describes an enumerative search in progress on an |
| ︙ | |||
185 186 187 188 189 190 191 | 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | - + + + + + + + + + | const char *otherP2, const int otherFlags, Tcl_Obj *myNamePtr, int myFlags, int index); static ArraySearch * ParseSearchId(Tcl_Interp *interp, const Var *varPtr, Tcl_Obj *varNamePtr, Tcl_Obj *handleObj); static void UnsetVarStruct(Var *varPtr, Var *arrayPtr, Interp *iPtr, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, int flags, int index); |
| ︙ | |||
226 227 228 229 230 231 232 | 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | - |
FreeLocalVarName, DupLocalVarName, NULL, NULL
};
static const Tcl_ObjType tclParsedVarNameType = {
"parsedVarName",
FreeParsedVarName, DupParsedVarName, NULL, NULL
};
|
| ︙ | |||
913 914 915 916 917 918 919 | 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 | - + | * TclLookupArrayElement -- * * This function is used to locate a variable which is in an array's * hashtable given a pointer to the array's Var structure and the * element's name. * * Results: |
| ︙ | |||
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 | 1059 1060 1061 1062 1063 1064 1065 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 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |
Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "ELEMENT",
TclGetString(elNamePtr), NULL);
}
}
}
return varPtr;
}
/*
*----------------------------------------------------------------------
*
* ArrayVar --
*
* This function looks up an existing array variable.
*
* Results:
* If successful, the requested variable is returned. On failure, NULL is
* returned, and error information is placed in the interpreter result. If
* the error occurred within an array trace and traceFailPtr is not NULL,
* *traceFailPtr is set to 1. Non-trace errors are inhibited if flags does
* not contain TCL_LEAVE_ERR_MSG.
*
* Side effects:
* Array traces, if any, are executed.
*
*----------------------------------------------------------------------
*/
static Var *
ArrayVar(
Tcl_Interp *interp, /* Command interpreter in which varNamePtr is to
* be looked up. */
Tcl_Obj *varNameObj, /* Name of array variable in interp. */
int *traceFailPtr, /* Unless NULL, set to 1 on trace failure. */
int flags) /* OR-ed combination of TCL_GLOBAL_ONLY,
* TCL_NAMESPACE_ONLY, and TCL_LEAVE_ERR_MSG. */
{
Var *varPtr, *arrayPtr;
const char *varName;
/*
* Locate the array variable.
*/
varPtr = TclObjLookupVarEx(interp, varNameObj, NULL,
flags & ~TCL_LEAVE_ERR_MSG, /*msg*/ NULL, /*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((Interp *)interp, arrayPtr, varPtr, varNameObj,
NULL, flags | TCL_LEAVE_ERR_MSG | TCL_TRACE_ARRAY,
/*leaveErrMsg*/ 1, -1) == TCL_ERROR) {
if (traceFailPtr) {
*traceFailPtr = 1;
}
return NULL;
}
}
/*
* 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.
*/
if (!varPtr || !TclIsVarArray(varPtr) || TclIsVarUndefined(varPtr)) {
varName = TclGetString(varNameObj);
if (flags & TCL_LEAVE_ERR_MSG) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"\"%s\" isn't an array", varName));
Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "ARRAY", varName, NULL);
}
return NULL;
}
/*
* On success, give the caller the address of the variable object.
*/
return varPtr;
}
/*
*----------------------------------------------------------------------
*
* ArrayFirst --
*
* Finds the first element of an array. If a filter is specified, only
* elements matching the filter are found.
*
* Preconditions:
* The interp, varPtr, filterObj, and filterType fields of *searchPtr must
* have been initialized.
*
* Results:
* The first array element is returned, or NULL if there are no matching
* elements or on error, in which case *failPtr is set to 1.
*
* Side effects:
* *searchPtr is updated to track the progress of the enumeration. On
* error, detailed error information is placed into the interpreter result.
*
*----------------------------------------------------------------------
*/
static Var *
ArrayFirst(
ArraySearch *searchPtr, /* Array enumeration state structure. */
int *failPtr) /* Set to 1 on error. */
{
TclVarHashTable *tablePtr = searchPtr->varPtr->value.tablePtr;
Var *varPtr;
/*
* Exact matches and trivial glob matches can be completed immediately since
* they will only ever match one or zero elements. No need to iterate, just
* do a direct lookup, then fast-forward to the end of the hash table.
*/
if (searchPtr->filterObj
&& (searchPtr->filterType == TCL_MATCH_EXACT
|| (searchPtr->filterType == TCL_MATCH_GLOB
&& TclMatchIsTrivial(TclGetString(searchPtr->filterObj))))) {
varPtr = VarHashFindVar(tablePtr, searchPtr->filterObj);
searchPtr->search.tablePtr = &tablePtr->table;
searchPtr->search.nextIndex = tablePtr->table.numBuckets;
searchPtr->search.nextEntryPtr = NULL;
searchPtr->nextEntry = NULL;
if (!varPtr || TclIsVarUndefined(varPtr)) {
return NULL;
} else {
return varPtr;
}
}
/*
* For all other match types, find the first item (which may or may not
* match the filter) then chain to ArrayNext() to get the real first item.
*/
searchPtr->nextEntry = VarHashFirstVar(tablePtr, &searchPtr->search);
return ArrayNext(searchPtr, failPtr);
}
/*
*----------------------------------------------------------------------
*
* ArrayNext --
*
* Finds the next element of an array for a given search query.
*
* Preconditions:
* ArrayFirst() must have been called on searchPtr.
*
* Results:
* The next array element is returned, or NULL if there are no matching
* elements remaining or on error, in which case *failPtr is set to 1 if
* failPtr is not NULL.
*
* Side effects:
* *searchPtr is updated to track the progress of the enumeration. On
* error, detailed error information is placed into the interpreter result.
*
*----------------------------------------------------------------------
*/
static Var *
ArrayNext(
ArraySearch *searchPtr, /* Array enumeration state structure. */
int *failPtr) /* Set to 1 on error. */
{
Var *varPtr;
Tcl_Obj *nameObj;
int matched;
/*
* Use the cached nextEntry left over from ArrayFirst() or [array anymore],
* or else get the next one from the hash table.
*/
if (searchPtr->nextEntry) {
varPtr = searchPtr->nextEntry;
searchPtr->nextEntry = NULL;
} else {
varPtr = VarHashNextVar(&searchPtr->search);
}
/*
* Iterate through the hash table until an element matches the filter or the
* end is reached.
*/
for (; varPtr; varPtr = VarHashNextVar(&searchPtr->search)) {
if (!TclIsVarUndefined(varPtr)) {
/*
* If no filter, accept each defined element regardless of name.
*/
if (!searchPtr->filterObj) {
return varPtr;
}
/*
* Conditionally accept elements whose names match the filter.
*/
nameObj = VarHashGetKey(varPtr);
if (searchPtr->filterType == TCL_MATCH_GLOB) {
if (Tcl_StringMatch(TclGetString(nameObj),
TclGetString(searchPtr->filterObj))) {
return varPtr;
}
} else if (searchPtr->filterType == TCL_MATCH_REGEXP) {
matched = Tcl_RegExpMatchObj(searchPtr->interp, nameObj,
searchPtr->filterObj);
if (matched < 0) {
if (failPtr) {
*failPtr = 1;
}
return NULL;
} else if (matched) {
return varPtr;
}
} else if (searchPtr->filterType == TCL_MATCH_EXACT) {
Tcl_Panic("exact matching shouldn't get here");
} else {
Tcl_Panic("invalid filter type: %u", searchPtr->filterType);
}
}
}
return NULL;
}
/*
*----------------------------------------------------------------------
*
* ArraySize --
*
* This function returns the number of elements in an array variable.
*
* Results:
* The return value is the integer count of array elements. The only
* possible error is a regular expression error, in which case -1 is
* returned and the error information is loaded into the interp result.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static int
ArraySize(
Tcl_Interp *interp, /* Interpreter, used to report regexp errors. */
Var *varPtr, /* Array variable. */
Tcl_Obj *filterObj, /* Element filter or NULL to accept all. */
int filterType) /* TCL_MATCH_EXACT, _GLOB, or _REGEXP. */
{
ArraySearch search;
int fail = 0, size = 0;
/*
* Count the number of times ArrayFirst() or ArrayNext() returns non-NULL.
*/
search.interp = interp;
search.varPtr = varPtr;
search.filterObj = filterObj;
search.filterType = filterType;
search.nextEntry = NULL;
varPtr = ArrayFirst(&search, &fail);
for (; varPtr; varPtr = ArrayNext(&search, &fail)) {
++size;
}
/*
* Return -1 on error or the number of matching elements on success.
*/
if (fail) {
return -1;
} else {
return size;
}
}
/*
*----------------------------------------------------------------------
*
* ArrayNames --
*
* Obtains a list of array element names, optionally limited by a filter.
*
* Results:
* Normally, TCL_OK is returned, and the list of matching array element
* names is appended to listObj. On error, TCL_ERROR is returned, and the
* error information is placed in the interpreter's result.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static int
ArrayNames(
Tcl_Interp *interp, /* Interpreter, used to report regexp errors. */
Var *varPtr, /* Array variable. */
Tcl_Obj *filterObj, /* Element filter or NULL to accept all. */
int filterType, /* TCL_MATCH_EXACT, _GLOB, or _REGEXP. */
Tcl_Obj *listObj) /* List to which array names are appended. */
{
ArraySearch search;
int fail = 0, oldLen, newLen;
/*
* Ensure output object is a list. Also get its length in case there is
* trouble and changes need to be rolled back. Such a failure should never
* occur because it requires a regular expression to initially succeed then
* return error on a subsequent evaluation, but handle it anyway because
* it's easy to do.
*/
if (Tcl_ListObjLength(interp, listObj, &oldLen) != TCL_OK) {
return TCL_ERROR;
}
/*
* Begin the search.
*/
search.interp = interp;
search.varPtr = varPtr;
search.filterObj = filterObj;
search.filterType = filterType;
search.nextEntry = NULL;
varPtr = ArrayFirst(&search, &fail);
/*
* Enumerate the array.
*/
for (; varPtr; varPtr = ArrayNext(&search, &fail)) {
Tcl_ListObjAppendElement(interp, listObj, VarHashGetKey(varPtr));
}
/*
* On failure, roll back changes to output list.
*/
if (fail) {
Tcl_ListObjLength(interp, listObj, &newLen);
Tcl_ListObjReplace(interp, listObj, oldLen, newLen - oldLen, 0, NULL);
return TCL_ERROR;
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* Tcl_ArraySize --
*
* This function returns the number of elements in an array variable. It
* provides C-level access to [array size] functionality, except this
* function does not treat scalar and nonexistent variable as if they were
* empty arrays. If part2Ptr is not NULL, only array elements whose names
* match part2Ptr are counted toward the return value. The interpretation
* of part2Ptr is controlled by TCL_MATCH_* being set within flags.
*
* Results:
* The return value is normally the integer count of array elements whose
* names match the given filter. If varNamePtr does not name an array, -1
* is returned and an error message is placed in interp's result.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
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. */
Tcl_Obj *part2Ptr, /* Element filter or NULL to accept all. */
int flags) /* OR-ed combination of TCL_GLOBAL_ONLY,
* TCL_NAMESPACE_ONLY, and TCL_LEAVE_ERR_MSG,
* also at most one of TCL_MATCH_EXACT, _GLOB,
* and _REGEXP. */
{
Var *varPtr = ArrayVar(interp, part1Ptr, NULL, flags);
return varPtr ? ArraySize(interp, varPtr, part2Ptr, flags & TCL_MATCH) : -1;
}
/*
*----------------------------------------------------------------------
*
* Tcl_ArraySearchStart --
*
* This function initiates an array search, i.e. step-by-step array element
* enumeration. It provides C-level access to [array startsearch]. The
* returned value is used to obtain one array element name at a time. If
* part2Ptr is not NULL, only array elements whose names match part2Ptr are
* returned by future calls to Tcl_ArraySearchNext(). The interpretation of
* part2Ptr is controlled by TCL_MATCH_* being set within flags.
*
* Results:
* A new array search is created, a pointer to which is returned. If the
* variable does not exist or is not an array, NULL is returned, and no
* search is created.
*
* Side effects:
* On success, the search is allocated on the heap and will need to be
* deallocated by a future call to Tcl_ArraySearchDone().
*
*----------------------------------------------------------------------
*/
Tcl_ArraySearch
Tcl_ArraySearchStart(
Tcl_Interp *interp, /* Command interpreter in which part1Ptr is to
* be looked up. */
Tcl_Obj *part1Ptr, /* Name of array variable in interp. */
Tcl_Obj *part2Ptr, /* Element filter or NULL to accept all. */
int flags) /* OR-ed combination of TCL_GLOBAL_ONLY,
* TCL_NAMESPACE_ONLY, and TCL_LEAVE_ERR_MSG,
* also at most one of TCL_MATCH_EXACT, _GLOB,
* and _REGEXP. */
{
Interp *iPtr = (Interp *)interp;
Var *varPtr = ArrayVar(interp, part1Ptr, NULL, flags);
Tcl_HashEntry *hPtr;
int isNew, fail = 0;
ArraySearch search, *searchPtr;
/*
* Handle the possible error cases before performing any allocations.
*/
if (!varPtr) {
return NULL;
}
search.interp = interp;
search.varPtr = varPtr;
search.filterObj = part2Ptr;
search.filterType = flags & TCL_MATCH;
search.nextEntry = ArrayFirst(&search, &fail);
if (!search.nextEntry && fail) {
return NULL;
}
/*
* Make a new array search with a free name.
*/
hPtr = Tcl_CreateHashEntry(&iPtr->varSearches, varPtr, &isNew);
if (isNew) {
search.id = 1;
varPtr->flags |= VAR_SEARCH_ACTIVE;
search.nextPtr = NULL;
} else {
search.id = ((ArraySearch *)Tcl_GetHashValue(hPtr))->id + 1;
search.nextPtr = Tcl_GetHashValue(hPtr);
}
search.name = Tcl_ObjPrintf("s-%d-%s", search.id, TclGetString(part1Ptr));
Tcl_IncrRefCount(search.name);
if (part2Ptr) {
Tcl_IncrRefCount(part2Ptr);
}
searchPtr = ckalloc(sizeof(*searchPtr));
*searchPtr = search;
Tcl_SetHashValue(hPtr, searchPtr);
return searchPtr;
}
/*
*----------------------------------------------------------------------
*
* Tcl_ArraySearchNext --
*
* Finds the next element of an array for a given search query.
*
* Preconditions:
* The search argument must be the return value of Tcl_ArraySearchStart()
* and must not have been passed to Tcl_ArraySearchDone().
*
* Results:
* The return value is the name of the next array element. If there are no
* more array elements, NULL is returned.
*
* Side effects:
* The search data structure is updated such that successive invocations of
* this function will return successive array element names.
*
* Limitations:
* It is not possible to distinguish between reaching the end of the array
* and experiencing a regular expression error. This is unlikely to be an
* actual problem because Tcl_ArraySearchStart() already checks for regular
* expression errors and returns NULL if found. If the regular expression
* engine has a bug whereby a given query can initially succeed yet return
* error depending on the string it is matched against, the caller of this
* function will perceive it as prematurely hitting the end of the array.
*
*----------------------------------------------------------------------
*/
Tcl_Obj *
Tcl_ArraySearchNext(
Tcl_ArraySearch search) /* Prior return from Tcl_ArraySearchStart(). */
{
Var *varPtr = ArrayNext(search, NULL);
return varPtr ? VarHashGetKey(varPtr) : NULL;
}
/*
*----------------------------------------------------------------------
*
* Tcl_ArraySearchDone --
*
* Terminates and cleans up an array search query.
*
* Preconditions:
* The search argument must be the return value of Tcl_ArraySearchStart()
* and must not have been passed to Tcl_ArraySearchDone().
*
* Results:
* The search query is completed.
*
* Side effects:
* Resources associated with the search are deallocated.
*
*----------------------------------------------------------------------
*/
void
Tcl_ArraySearchDone(
Tcl_ArraySearch search) /* Prior return from Tcl_ArraySearchStart(). */
{
Interp *iPtr = (Interp *)search->interp;
Var *varPtr = search->varPtr;
Tcl_HashEntry *hPtr = Tcl_FindHashEntry(&iPtr->varSearches, varPtr);
ArraySearch *prevPtr;
/*
* Unhook the search from the list of searches associated with the
* variable.
*/
if (search == Tcl_GetHashValue(hPtr)) {
if (search->nextPtr) {
Tcl_SetHashValue(hPtr, search->nextPtr);
} else {
varPtr->flags &= ~VAR_SEARCH_ACTIVE;
Tcl_DeleteHashEntry(hPtr);
}
} else {
for (prevPtr = Tcl_GetHashValue(hPtr);; prevPtr = prevPtr->nextPtr) {
if (prevPtr->nextPtr == search) {
prevPtr->nextPtr = search->nextPtr;
break;
}
}
}
Tcl_DecrRefCount(search->name);
if (search->filterObj) {
Tcl_DecrRefCount(search->filterObj);
}
ckfree(search);
}
/*
*----------------------------------------------------------------------
*
* Tcl_ArrayNames --
*
* Obtains a list of array element names, optionally limited by a filter.
*
* Results:
* Normally, TCL_OK is returned, and the list of matching array element
* names is appended to listObj. On error, TCL_ERROR is returned, and the
* error information is placed in the interpreter's result.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
Tcl_ArrayNames(
Tcl_Interp *interp, /* Command interpreter in which part1Ptr is to
* be looked up. */
Tcl_Obj *part1Ptr, /* Name of array variable in interp. */
Tcl_Obj *part2Ptr, /* Element filter or NULL to accept all. */
Tcl_Obj *listPtr, /* List to which array names are appended. */
int flags) /* OR-ed combination of TCL_GLOBAL_ONLY,
* TCL_NAMESPACE_ONLY, and TCL_LEAVE_ERR_MSG,
* also at most one of TCL_MATCH_EXACT, _GLOB,
* and _REGEXP. */
{
Var *varPtr = ArrayVar(interp, part1Ptr, NULL, flags);
if (varPtr) {
return ArrayNames(interp, varPtr, part2Ptr, flags & TCL_MATCH, listPtr);
} else {
return TCL_ERROR;
}
}
/*
*----------------------------------------------------------------------
*
* Tcl_GetVar --
*
* Return the value of a Tcl variable as a string.
|
| ︙ | |||
2843 2844 2845 2846 2847 2848 2849 | 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - | * Side effects: * See the user documentation. * *---------------------------------------------------------------------- */ /* ARGSUSED */ |
| ︙ | |||
2965 2966 2967 2968 2969 2970 2971 | 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 | - + - + - - - + + + - - + - - - - - + + + + - - - - + - - - + + |
Tcl_Interp *interp,
int objc,
Tcl_Obj *const objv[])
{
Interp *iPtr = (Interp *) interp;
Var *varPtr;
Tcl_Obj *varNameObj, *searchObj;
|
| ︙ | |||
3039 3040 3041 3042 3043 3044 3045 | 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 | - + - + - - + - - - - - + - - + - - - + - - - + - - - - + - - |
ArrayNextElementCmd(
ClientData clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *const objv[])
{
Var *varPtr;
|
| ︙ | |||
3115 3116 3117 3118 3119 3120 3121 | 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 | - - - + - + - - - - - - - - - - - - - - - - - - - + |
static int
ArrayDoneSearchCmd(
ClientData clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *const objv[])
{
|
| ︙ | |||
3194 3195 3196 3197 3198 3199 3200 | 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 | - + - + - + - - + - - - + - - + - - - - - - - + + + - - - - - - - + |
ArrayExistsCmd(
ClientData clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *const objv[])
{
Interp *iPtr = (Interp *) interp;
|
| ︙ | |||
3260 3261 3262 3263 3264 3265 3266 | 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 | - - + - + - + - - - + + - - - + + - - - + - - + - - - - - - + - - - |
static int
ArrayGetCmd(
ClientData clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *const objv[])
{
|
| ︙ | |||
3447 3448 3449 3450 3451 3452 3453 3454 | 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 | + + + - - - + - - - + + - - - - - - - - - - - - - - - - - - - - - - - + + - - + - - + + - - + - - - - - - - - - - - - - - - - - - - - - - + + + - - + + + - - - - - - + - - - - + - - - - - - - - - - - - + + + - - + - - - - - - - |
Tcl_Interp *interp,
int objc,
Tcl_Obj *const objv[])
{
static const char *const options[] = {
"-exact", "-glob", "-regexp", NULL
};
static const int flags[] = {
TCL_MATCH_EXACT, TCL_MATCH_GLOB, TCL_MATCH_REGEXP
};
enum options { OPT_EXACT, OPT_GLOB, OPT_REGEXP };
|
| ︙ | |||
3636 3637 3638 3639 3640 3641 3642 | 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 | - + - - - - - - - - - - - + - - - + - |
static int
ArraySetCmd(
ClientData clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *const objv[])
{
|
| ︙ | |||
3693 3694 3695 3696 3697 3698 3699 | 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 | - - - - - - + + - - - - + - - - + - - + - - - - - - - - - - + - - - - - - + - - - - - + - - - - - + + + - + |
static int
ArraySizeCmd(
ClientData clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *const objv[])
{
|
| ︙ | |||
3777 3778 3779 3780 3781 3782 3783 | 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 | - - + + - - - + - - - - - + - - - - - - - - - - - - - - - - - - - - - |
static int
ArrayStatsCmd(
ClientData clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *const objv[])
{
|
| ︙ | |||
3860 3861 3862 3863 3864 3865 3866 | 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 | - - + + - + - - - - + - - + - - - - - - + - - + - - - - - - + - - - |
static int
ArrayUnsetCmd(
ClientData clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *const objv[])
{
|
| ︙ |