Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch dkf-c11-features Excluding Merge-Ins
This is equivalent to a diff from 88f0807bb9 to 43e1c33e9e
|
2025-01-13
| ||
| 09:59 | More macros for measuring literals at compile time, and a shortcut for adding to error info Closed-Leaf check-in: 43e1c33e9e user: dkf tags: dkf-c11-features | |
|
2025-01-10
| ||
| 21:37 | Merge-mark check-in: 5145a78372 user: jan.nijtmans tags: trunk, main | |
| 16:25 | Clean up TEBC TRACE macro system check-in: 9dc5edae35 user: dkf tags: dkf-c11-features | |
| 14:02 | Rebase to 9.0 Closed-Leaf check-in: 7512a6295d user: jan.nijtmans tags: 70f3b23cad-docs-version-requirement | |
|
2025-01-08
| ||
| 16:09 | Rebase to 9.0 check-in: 16bd4182a9 user: jan.nijtmans tags: tip-709 | |
| 15:23 | Merge 9.0. registry -> 1.4a0 (breaking compilation on Windows XP) check-in: fd7b19dc30 user: jan.nijtmans tags: tip-710 | |
| 15:02 | Use C11 features, especially variadic macros. check-in: 38f3728d9a user: dkf tags: dkf-c11-features | |
| 14:07 | In --with-tcl8 mode, only typedef Tcl_Size when Tcl_Size is not #defined already check-in: 88f0807bb9 user: jan.nijtmans tags: trunk, main | |
| 13:57 | Only typedef Tcl_Size when Tcl_Size is not #defined. Spacing changes (backported from 8.7) check-in: 70a524360e user: jan.nijtmans tags: core-8-branch | |
|
2025-01-07
| ||
| 15:42 | Simplification for [d58e315172] check-in: 4e87493367 user: jan.nijtmans tags: trunk, main | |
Changes to generic/tclArithSeries.c.
| ︙ | ︙ | |||
693 694 695 696 697 698 699 |
}
if (isnan(dstart) || isnan(dend)) {
const char *description = "non-numeric floating-point value";
char tmp[TCL_DOUBLE_SPACE + 2];
tmp[0] = '\0';
Tcl_PrintDouble(NULL, isnan(dstart)?dstart:dend, tmp);
| | | | < | 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 |
}
if (isnan(dstart) || isnan(dend)) {
const char *description = "non-numeric floating-point value";
char tmp[TCL_DOUBLE_SPACE + 2];
tmp[0] = '\0';
Tcl_PrintDouble(NULL, isnan(dstart)?dstart:dend, tmp);
TclPrintfResult(interp,
"cannot use %s \"%s\" to estimate length of arith-series",
description, tmp);
TclSetErrorCode(interp, "ARITH", "DOMAIN", description);
return NULL;
}
precision = maxObjPrecision(startObj, endObj, stepObj);
len = ArithSeriesLenDbl(dstart, dend, dstep, precision);
} else {
len = ArithSeriesLenInt(start, end, step);
}
|
| ︙ | ︙ | |||
728 729 730 731 732 733 734 |
/*
* todo: check whether the boundary must be rather LIST_MAX, to be more
* similar to plain lists, otherwise it'd generare an error or panic later
* (0x0ffffffffffffffa instead of 0x7fffffffffffffff by 64bit)
*/
if (len > TCL_SIZE_MAX) {
exceeded:
| < | | | | 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 |
/*
* todo: check whether the boundary must be rather LIST_MAX, to be more
* similar to plain lists, otherwise it'd generare an error or panic later
* (0x0ffffffffffffffa instead of 0x7fffffffffffffff by 64bit)
*/
if (len > TCL_SIZE_MAX) {
exceeded:
TclPrintfResult(interp, "max length of a Tcl list exceeded");
TclSetErrorCode(interp, "TCL", "MEMORY");
return NULL;
}
if (useDoubles) {
/* ensure we'll not get NaN somewhere in the arith-series,
* so simply check the end of it and behave like [expr {Inf - Inf}] */
double d = dstart + (len - 1) * dstep;
if (isnan(d)) {
const char *s = "domain error: argument not in valid range";
Tcl_SetObjResult(interp, Tcl_NewStringObj(s, -1));
TclSetErrorCode(interp, "ARITH", "DOMAIN", s);
return NULL;
}
if (precision == (unsigned)-1) {
precision = maxObjPrecision(startObj, endObj, stepObj);
}
|
| ︙ | ︙ | |||
1008 1009 1010 1011 1012 1013 1014 |
/* If this exists, it has already been populated */
objv = arithSeriesRepPtr->elements;
} else {
/* Construct the elements array */
objv = (Tcl_Obj **) Tcl_Alloc(sizeof(Tcl_Obj*) * objc);
if (objv == NULL) {
if (interp) {
| | | < | | 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 |
/* If this exists, it has already been populated */
objv = arithSeriesRepPtr->elements;
} else {
/* Construct the elements array */
objv = (Tcl_Obj **) Tcl_Alloc(sizeof(Tcl_Obj*) * objc);
if (objv == NULL) {
if (interp) {
TclPrintfResult(interp,
"max length of a Tcl list exceeded");
TclSetErrorCode(interp, "TCL", "MEMORY");
}
return TCL_ERROR;
}
arithSeriesRepPtr->elements = objv;
Tcl_Size i;
for (i = 0; i < objc; i++) {
|
| ︙ | ︙ | |||
1034 1035 1036 1037 1038 1039 1040 |
} else {
objv = NULL;
}
*objvPtr = objv;
*objcPtr = objc;
} else {
if (interp != NULL) {
| < | | | 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 |
} else {
objv = NULL;
}
*objvPtr = objv;
*objcPtr = objc;
} else {
if (interp != NULL) {
TclPrintfResult(interp, "value is not an arithseries");
TclSetErrorCode(interp, "TCL", "VALUE", "UNKNOWN");
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
|
| ︙ | ︙ |
Changes to generic/tclAssembly.c.
| ︙ | ︙ | |||
788 789 790 791 792 793 794 |
TclNRAssembleObjCmd(
TCL_UNUSED(void *),
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
ByteCode *codePtr; /* Pointer to the bytecode to execute */
| < < | < < | < < | 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 |
TclNRAssembleObjCmd(
TCL_UNUSED(void *),
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
ByteCode *codePtr; /* Pointer to the bytecode to execute */
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "bytecodeList");
return TCL_ERROR;
}
/*
* Assemble the source to bytecode.
*/
codePtr = CompileAssembleObj(interp, objv[1]);
/*
* On failure, report error line.
*/
if (codePtr == NULL) {
TclPrintfErrorInfo(interp, "\n (\"%s\" body, line %d)",
TclGetString(objv[0]), Tcl_GetErrorLine(interp));
return TCL_ERROR;
}
/*
* Use NRE to evaluate the bytecode from the trampoline.
*/
|
| ︙ | ︙ | |||
977 978 979 980 981 982 983 |
/*
* Compile the code and convert any error from the compilation into
* bytecode reporting the error;
*/
if (TCL_ERROR == TclAssembleCode(envPtr, tokenPtr[1].start,
tokenPtr[1].size, TCL_EVAL_DIRECT)) {
| < | | | 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 |
/*
* Compile the code and convert any error from the compilation into
* bytecode reporting the error;
*/
if (TCL_ERROR == TclAssembleCode(envPtr, tokenPtr[1].start,
tokenPtr[1].size, TCL_EVAL_DIRECT)) {
TclPrintfErrorInfo(interp, "\n (\"%.*s\" body, line %d)",
(int)parsePtr->tokenPtr->size, parsePtr->tokenPtr->start,
Tcl_GetErrorLine(interp));
envPtr->numCommands = numCommands;
envPtr->codeNext = envPtr->codeStart + offset;
envPtr->currStackDepth = depth;
TclCompileSyntaxError(interp, envPtr);
}
return TCL_OK;
}
|
| ︙ | ︙ | |||
1373 1374 1375 1376 1377 1378 1379 |
Tcl_WrongNumArgs(interp, 1, &instNameObj, "imm8");
goto cleanup;
}
if (GetIntegerOperand(assemEnvPtr, &tokenPtr, &opnd) != TCL_OK) {
goto cleanup;
}
if (opnd < 0 || opnd > 3) {
| < | | | 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 |
Tcl_WrongNumArgs(interp, 1, &instNameObj, "imm8");
goto cleanup;
}
if (GetIntegerOperand(assemEnvPtr, &tokenPtr, &opnd) != TCL_OK) {
goto cleanup;
}
if (opnd < 0 || opnd > 3) {
TclPrintfResult(interp, "operand must be [0..3]");
TclSetErrorCode(interp, "TCL", "ASSEM", "OPERAND<0,>3");
goto cleanup;
}
BBEmitInstInt1(assemEnvPtr, tblIdx, opnd, opnd);
break;
case ASSEM_CONCAT1:
if (parsePtr->numWords != 2) {
|
| ︙ | ︙ | |||
1614 1615 1616 1617 1618 1619 1620 |
goto cleanup;
}
if (GetIntegerOperand(assemEnvPtr, &tokenPtr, &opnd) != TCL_OK) {
goto cleanup;
}
if (opnd < 2) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
| < | | | 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 |
goto cleanup;
}
if (GetIntegerOperand(assemEnvPtr, &tokenPtr, &opnd) != TCL_OK) {
goto cleanup;
}
if (opnd < 2) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
TclPrintfResult(interp, "operand must be >=2");
TclSetErrorCode(interp, "TCL", "ASSEM", "OPERAND>=2");
}
goto cleanup;
}
BBEmitInstInt4(assemEnvPtr, tblIdx, opnd, opnd);
break;
case ASSEM_LVT:
|
| ︙ | ︙ | |||
1979 1980 1981 1982 1983 1984 1985 |
Tcl_Size i;
if (TclListObjLength(interp, jumps, &objc) != TCL_OK) {
return TCL_ERROR;
}
if (objc % 2 != 0) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
| | | < | | 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 |
Tcl_Size i;
if (TclListObjLength(interp, jumps, &objc) != TCL_OK) {
return TCL_ERROR;
}
if (objc % 2 != 0) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
TclPrintfResult(interp,
"jump table must have an even number of list elements");
TclSetErrorCode(interp, "TCL", "ASSEM", "BADJUMPTABLE");
}
return TCL_ERROR;
}
if (TclListObjGetElements(interp, jumps, &objc, &objv) != TCL_OK) {
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
2010 2011 2012 2013 2014 2015 2016 |
for (i = 0; i < objc; i+=2) {
DEBUG_PRINT(" %s -> %s\n", TclGetString(objv[i]),
TclGetString(objv[i+1]));
hashEntry = Tcl_CreateHashEntry(jtHashPtr, TclGetString(objv[i]),
&isNew);
if (!isNew) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
| | | | | 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 |
for (i = 0; i < objc; i+=2) {
DEBUG_PRINT(" %s -> %s\n", TclGetString(objv[i]),
TclGetString(objv[i+1]));
hashEntry = Tcl_CreateHashEntry(jtHashPtr, TclGetString(objv[i]),
&isNew);
if (!isNew) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
TclPrintfResult(interp,
"duplicate entry in jump table for \"%s\"",
TclGetString(objv[i]));
TclSetErrorCode(interp, "TCL", "ASSEM", "DUPJUMPTABLEENTRY");
DeleteMirrorJumpTable(jtPtr);
return TCL_ERROR;
}
}
Tcl_SetHashValue(hashEntry, objv[i+1]);
Tcl_IncrRefCount(objv[i+1]);
}
|
| ︙ | ︙ | |||
2096 2097 2098 2099 2100 2101 2102 |
Tcl_Interp* interp = (Tcl_Interp*) assemEnvPtr->envPtr->iPtr;
Tcl_Obj* operandObj;
TclNewObj(operandObj);
if (!TclWordKnownAtCompileTime(*tokenPtrPtr, operandObj)) {
Tcl_DecrRefCount(operandObj);
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
| | | | | 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 |
Tcl_Interp* interp = (Tcl_Interp*) assemEnvPtr->envPtr->iPtr;
Tcl_Obj* operandObj;
TclNewObj(operandObj);
if (!TclWordKnownAtCompileTime(*tokenPtrPtr, operandObj)) {
Tcl_DecrRefCount(operandObj);
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
TclPrintfResult(interp,
"assembly code may not contain substitutions");
TclSetErrorCode(interp, "TCL", "ASSEM", "NOSUBST");
}
return TCL_ERROR;
}
*tokenPtrPtr = TokenAfter(*tokenPtrPtr);
Tcl_IncrRefCount(operandObj);
*operandObjPtr = operandObj;
return TCL_OK;
|
| ︙ | ︙ | |||
2318 2319 2320 2321 2322 2323 2324 |
Tcl_DecrRefCount(varNameObj);
return TCL_INDEX_NONE;
}
localVar = TclFindCompiledLocal(varNameStr, varNameLen, 1, envPtr);
Tcl_DecrRefCount(varNameObj);
if (localVar < 0) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
| | | | | 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 |
Tcl_DecrRefCount(varNameObj);
return TCL_INDEX_NONE;
}
localVar = TclFindCompiledLocal(varNameStr, varNameLen, 1, envPtr);
Tcl_DecrRefCount(varNameObj);
if (localVar < 0) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
TclPrintfResult(interp,
"cannot use this instruction to create a variable"
" in a non-proc context");
TclSetErrorCode(interp, "TCL", "ASSEM", "LVT");
}
return TCL_INDEX_NONE;
}
*tokenPtrPtr = TokenAfter(tokenPtr);
return localVar;
}
|
| ︙ | ︙ | |||
2354 2355 2356 2357 2358 2359 2360 |
const char* name, /* Variable name to check */
int nameLen) /* Length of the variable */
{
const char* p;
for (p = name; p+2 < name+nameLen; p++) {
if ((*p == ':') && (p[1] == ':')) {
| < | | | 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 |
const char* name, /* Variable name to check */
int nameLen) /* Length of the variable */
{
const char* p;
for (p = name; p+2 < name+nameLen; p++) {
if ((*p == ':') && (p[1] == ':')) {
TclPrintfResult(interp, "variable \"%s\" is not local", name);
TclSetErrorCode(interp, "TCL", "ASSEM", "NONLOCAL", name);
return TCL_ERROR;
}
}
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
2387 2388 2389 2390 2391 2392 2393 |
*/
static int
CheckOneByte(
Tcl_Interp* interp, /* Tcl interpreter for error reporting */
int value) /* Value to check */
{
| < < | < | | 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 |
*/
static int
CheckOneByte(
Tcl_Interp* interp, /* Tcl interpreter for error reporting */
int value) /* Value to check */
{
if (value < 0 || value > 0xFF) {
TclPrintfResult(interp, "operand does not fit in one byte");
TclSetErrorCode(interp, "TCL", "ASSEM", "1BYTE");
return TCL_ERROR;
}
return TCL_OK;
}
/*
*-----------------------------------------------------------------------------
|
| ︙ | ︙ | |||
2422 2423 2424 2425 2426 2427 2428 |
*/
static int
CheckSignedOneByte(
Tcl_Interp* interp, /* Tcl interpreter for error reporting */
int value) /* Value to check */
{
| < < | < | | 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 |
*/
static int
CheckSignedOneByte(
Tcl_Interp* interp, /* Tcl interpreter for error reporting */
int value) /* Value to check */
{
if (value > 0x7F || value < -0x80) {
TclPrintfResult(interp, "operand does not fit in one byte");
TclSetErrorCode(interp, "TCL", "ASSEM", "1BYTE");
return TCL_ERROR;
}
return TCL_OK;
}
/*
*-----------------------------------------------------------------------------
|
| ︙ | ︙ | |||
2455 2456 2457 2458 2459 2460 2461 |
*/
static int
CheckNonNegative(
Tcl_Interp* interp, /* Tcl interpreter for error reporting */
int value) /* Value to check */
{
| < < | < | | 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 |
*/
static int
CheckNonNegative(
Tcl_Interp* interp, /* Tcl interpreter for error reporting */
int value) /* Value to check */
{
if (value < 0) {
TclPrintfResult(interp, "operand must be nonnegative");
TclSetErrorCode(interp, "TCL", "ASSEM", "NONNEGATIVE");
return TCL_ERROR;
}
return TCL_OK;
}
/*
*-----------------------------------------------------------------------------
|
| ︙ | ︙ | |||
2488 2489 2490 2491 2492 2493 2494 |
*/
static int
CheckStrictlyPositive(
Tcl_Interp* interp, /* Tcl interpreter for error reporting */
int value) /* Value to check */
{
| < < | < | | 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 |
*/
static int
CheckStrictlyPositive(
Tcl_Interp* interp, /* Tcl interpreter for error reporting */
int value) /* Value to check */
{
if (value <= 0) {
TclPrintfResult(interp, "operand must be positive");
TclSetErrorCode(interp, "TCL", "ASSEM", "POSITIVE");
return TCL_ERROR;
}
return TCL_OK;
}
/*
*-----------------------------------------------------------------------------
|
| ︙ | ︙ | |||
2542 2543 2544 2545 2546 2547 2548 |
entry = Tcl_CreateHashEntry(&assemEnvPtr->labelHash, labelName, &isNew);
if (!isNew) {
/*
* This is a duplicate label.
*/
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
| | | | < | 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 |
entry = Tcl_CreateHashEntry(&assemEnvPtr->labelHash, labelName, &isNew);
if (!isNew) {
/*
* This is a duplicate label.
*/
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
TclPrintfResult(interp,
"duplicate definition of label \"%s\"", labelName);
TclSetErrorCode(interp, "TCL", "ASSEM", "DUPLABEL", labelName);
}
return TCL_ERROR;
}
/*
* This is the first appearance of the label in the code.
*/
|
| ︙ | ︙ | |||
2943 2944 2945 2946 2947 2948 2949 |
{
CompileEnv* envPtr = assemEnvPtr->envPtr;
/* Compilation environment */
Tcl_Interp* interp = (Tcl_Interp*) envPtr->iPtr;
/* Tcl interpreter */
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
| | | | | | 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 |
{
CompileEnv* envPtr = assemEnvPtr->envPtr;
/* Compilation environment */
Tcl_Interp* interp = (Tcl_Interp*) envPtr->iPtr;
/* Tcl interpreter */
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
TclPrintfResult(interp,
"undefined label \"%s\"", TclGetString(jumpTarget));
TclSetErrorCode(interp, "TCL", "ASSEM", "NOLABEL",
TclGetString(jumpTarget));
Tcl_SetErrorLine(interp, bbPtr->jumpLine);
}
}
/*
*-----------------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
3226 3227 3228 3229 3230 3231 3232 |
opcode = (envPtr->codeStart)[offset];
if (BytecodeMightThrow(opcode)) {
/*
* Report an error for a throw in the wrong context.
*/
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
| | | | | 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 |
opcode = (envPtr->codeStart)[offset];
if (BytecodeMightThrow(opcode)) {
/*
* Report an error for a throw in the wrong context.
*/
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
TclPrintfResult(interp,
"\"%s\" instruction may not appear in "
"a context where an exception has been "
"caught and not disposed of.",
tclInstructionTable[opcode].name);
TclSetErrorCode(interp, "TCL", "ASSEM", "BADTHROW");
AddBasicBlockRangeToErrorInfo(assemEnvPtr, blockPtr);
}
return TCL_ERROR;
}
offset += tclInstructionTable[opcode].numBytes;
}
return TCL_OK;
|
| ︙ | ︙ | |||
3403 3404 3405 3406 3407 3408 3409 |
* among the paths that reach it.
*/
if (blockPtr->initialStackDepth == initialStackDepth) {
return TCL_OK;
}
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
| | | | | 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 |
* among the paths that reach it.
*/
if (blockPtr->initialStackDepth == initialStackDepth) {
return TCL_OK;
}
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
TclPrintfResult(interp,
"inconsistent stack depths on two execution paths");
/*
* TODO - add execution trace of both paths
*/
Tcl_SetErrorLine(interp, blockPtr->startLine);
TclSetErrorCode(interp, "TCL", "ASSEM", "BADSTACK");
}
return TCL_ERROR;
}
/*
* If the block is not already visited, set the 'predecessor' link to
* indicate how control got to it. Set the initial stack depth to the
|
| ︙ | ︙ | |||
3433 3434 3435 3436 3437 3438 3439 |
/*
* Calculate minimum stack depth, and flag an error if the block
* underflows the stack.
*/
if (initialStackDepth + blockPtr->minStackDepth < 0) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
| | | | | | | 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 |
/*
* Calculate minimum stack depth, and flag an error if the block
* underflows the stack.
*/
if (initialStackDepth + blockPtr->minStackDepth < 0) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
TclPrintfResult(interp, "stack underflow");
TclSetErrorCode(interp, "TCL", "ASSEM", "BADSTACK");
AddBasicBlockRangeToErrorInfo(assemEnvPtr, blockPtr);
Tcl_SetErrorLine(interp, blockPtr->startLine);
}
return TCL_ERROR;
}
/*
* Make sure that the block doesn't try to pop below the stack level of an
* enclosing catch.
*/
if (blockPtr->enclosingCatch != 0 &&
initialStackDepth + blockPtr->minStackDepth
< (blockPtr->enclosingCatch->initialStackDepth
+ blockPtr->enclosingCatch->finalStackDepth)) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
TclPrintfResult(interp,
"code pops stack below level of enclosing catch");
TclSetErrorCode(interp, "TCL", "ASSEM", "BADSTACKINCATCH");
AddBasicBlockRangeToErrorInfo(assemEnvPtr, blockPtr);
Tcl_SetErrorLine(interp, blockPtr->startLine);
}
return TCL_ERROR;
}
/*
|
| ︙ | ︙ | |||
3578 3579 3580 3581 3582 3583 3584 |
/*
* Exit with unbalanced stack.
*/
if (depth != 1) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
| | | | | 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 |
/*
* Exit with unbalanced stack.
*/
if (depth != 1) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
TclPrintfResult(interp,
"stack is unbalanced on exit from the code (depth=%d)",
depth);
TclSetErrorCode(interp, "TCL", "ASSEM", "BADSTACK");
}
return TCL_ERROR;
}
/*
* Record stack usage.
*/
|
| ︙ | ︙ | |||
3722 3723 3724 3725 3726 3727 3728 |
* rechecked.
*/
if (bbPtr->catchState == BBCS_UNKNOWN) {
bbPtr->enclosingCatch = enclosing;
} else if (bbPtr->enclosingCatch != enclosing) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
| | | | | 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 |
* rechecked.
*/
if (bbPtr->catchState == BBCS_UNKNOWN) {
bbPtr->enclosingCatch = enclosing;
} else if (bbPtr->enclosingCatch != enclosing) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
TclPrintfResult(interp,
"execution reaches an instruction in inconsistent "
"exception contexts");
Tcl_SetErrorLine(interp, bbPtr->startLine);
TclSetErrorCode(interp, "TCL", "ASSEM", "BADCATCH");
}
return TCL_ERROR;
}
if (state > bbPtr->catchState) {
bbPtr->catchState = state;
changed = 1;
}
|
| ︙ | ︙ | |||
3782 3783 3784 3785 3786 3787 3788 |
/*
* If the block ends a catch, the state for the successor is whatever
* the state was on entry to the catch.
*/
if (enclosing == NULL) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
| | | | | 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 |
/*
* If the block ends a catch, the state for the successor is whatever
* the state was on entry to the catch.
*/
if (enclosing == NULL) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
TclPrintfResult(interp,
"endCatch without a corresponding beginCatch");
Tcl_SetErrorLine(interp, bbPtr->startLine);
TclSetErrorCode(interp, "TCL", "ASSEM", "BADENDCATCH");
}
return TCL_ERROR;
}
fallThruEnclosing = enclosing->enclosingCatch;
fallThruState = enclosing->catchState;
--catchDepth;
}
|
| ︙ | ︙ | |||
3857 3858 3859 3860 3861 3862 3863 |
CompileEnv* envPtr = assemEnvPtr->envPtr;
/* Compilation environment */
Tcl_Interp* interp = (Tcl_Interp*) envPtr->iPtr;
/* Tcl interpreter */
if (assemEnvPtr->curr_bb->catchState >= BBCS_INCATCH) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
| | | | | 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 |
CompileEnv* envPtr = assemEnvPtr->envPtr;
/* Compilation environment */
Tcl_Interp* interp = (Tcl_Interp*) envPtr->iPtr;
/* Tcl interpreter */
if (assemEnvPtr->curr_bb->catchState >= BBCS_INCATCH) {
if (assemEnvPtr->flags & TCL_EVAL_DIRECT) {
TclPrintfResult(interp,
"catch still active on exit from assembly code");
Tcl_SetErrorLine(interp,
assemEnvPtr->curr_bb->enclosingCatch->startLine);
TclSetErrorCode(interp, "TCL", "ASSEM", "UNCLOSEDCATCH");
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
4259 4260 4261 4262 4263 4264 4265 |
AssemblyEnv* assemEnvPtr, /* Assembly environment */
BasicBlock* bbPtr) /* Basic block in which the error is found */
{
CompileEnv* envPtr = assemEnvPtr->envPtr;
/* Compilation environment */
Tcl_Interp* interp = (Tcl_Interp*) envPtr->iPtr;
/* Tcl interpreter */
| < < < < < < > > | < | > > < | 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 |
AssemblyEnv* assemEnvPtr, /* Assembly environment */
BasicBlock* bbPtr) /* Basic block in which the error is found */
{
CompileEnv* envPtr = assemEnvPtr->envPtr;
/* Compilation environment */
Tcl_Interp* interp = (Tcl_Interp*) envPtr->iPtr;
/* Tcl interpreter */
if (bbPtr->successor1 != NULL) {
TclPrintfErrorInfo(interp,
"\n in assembly code between lines %d and %d",
bbPtr->startLine, bbPtr->successor1->startLine);
} else {
TclPrintfErrorInfo(interp,
"\n in assembly code between lines %d and end of assembly code",
bbPtr->startLine);
}
}
/*
*-----------------------------------------------------------------------------
*
* DupAssembleCodeInternalRep --
*
|
| ︙ | ︙ |
Changes to generic/tclBasic.c.
| ︙ | ︙ | |||
1519 1520 1521 1522 1523 1524 1525 |
void *clientData,
Tcl_Interp *interp,
TCL_UNUSED(int) /*objc*/,
TCL_UNUSED(Tcl_Obj *const *) /* objv */)
{
const UnsafeEnsembleInfo *infoPtr = (const UnsafeEnsembleInfo *)clientData;
| | | | | 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 |
void *clientData,
Tcl_Interp *interp,
TCL_UNUSED(int) /*objc*/,
TCL_UNUSED(Tcl_Obj *const *) /* objv */)
{
const UnsafeEnsembleInfo *infoPtr = (const UnsafeEnsembleInfo *)clientData;
TclPrintfResult(interp,
"not allowed to invoke subcommand %s of %s",
infoPtr->commandName, infoPtr->ensembleNsName);
TclSetErrorCode(interp, "TCL", "SAFE", "SUBCOMMAND");
return TCL_ERROR;
}
/*
*--------------------------------------------------------------
*
* Tcl_CallWhenDeleted --
|
| ︙ | ︙ | |||
2214 2215 2216 2217 2218 2219 2220 |
*
* But as we currently limit ourselves to the global namespace only for
* the source, in order to avoid potential confusion, lets prevent "::" in
* the token too. - dl
*/
if (strstr(hiddenCmdToken, "::") != NULL) {
| | | | | 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 |
*
* But as we currently limit ourselves to the global namespace only for
* the source, in order to avoid potential confusion, lets prevent "::" in
* the token too. - dl
*/
if (strstr(hiddenCmdToken, "::") != NULL) {
TclPrintfResult(interp,
"cannot use namespace qualifiers in hidden command"
" token (rename)");
TclSetErrorCode(interp, "TCL", "VALUE", "HIDDENTOKEN");
return TCL_ERROR;
}
/*
* Find the command to hide. An error is returned if cmdName can't be
* found. Look up the command only from the global namespace. Full path of
* the command must be given if using namespaces.
|
| ︙ | ︙ | |||
2239 2240 2241 2242 2243 2244 2245 |
cmdPtr = (Command *) cmd;
/*
* Check that the command is really in global namespace
*/
if (cmdPtr->nsPtr != iPtr->globalNsPtr) {
| | | < | | 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 |
cmdPtr = (Command *) cmd;
/*
* Check that the command is really in global namespace
*/
if (cmdPtr->nsPtr != iPtr->globalNsPtr) {
TclPrintfResult(interp,
"can only hide global namespace commands (use rename then hide)");
TclSetErrorCode(interp, "TCL", "HIDE", "NON_GLOBAL");
return TCL_ERROR;
}
/*
* Initialize the hidden command table if necessary.
*/
|
| ︙ | ︙ | |||
2265 2266 2267 2268 2269 2270 2271 |
* It is an error to move an exposed command to a hidden command with
* hiddenCmdToken if a hidden command with the name hiddenCmdToken already
* exists.
*/
hPtr = Tcl_CreateHashEntry(hiddenCmdTablePtr, hiddenCmdToken, &isNew);
if (!isNew) {
| | | | | 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 |
* It is an error to move an exposed command to a hidden command with
* hiddenCmdToken if a hidden command with the name hiddenCmdToken already
* exists.
*/
hPtr = Tcl_CreateHashEntry(hiddenCmdTablePtr, hiddenCmdToken, &isNew);
if (!isNew) {
TclPrintfResult(interp,
"hidden command named \"%s\" already exists",
hiddenCmdToken);
TclSetErrorCode(interp, "TCL", "HIDE", "ALREADY_HIDDEN");
return TCL_ERROR;
}
/*
* NB: This code is currently 'like' a rename to a special separate name
* table. Changes here and in TclRenameCommand must be kept in synch until
* the common parts are actually factorized out.
|
| ︙ | ︙ | |||
2369 2370 2371 2372 2373 2374 2375 |
/*
* Check that we have a regular name for the command (that the user is not
* trying to do an expose and a rename (to another namespace) at the same
* time).
*/
if (strstr(cmdName, "::") != NULL) {
| | | < | | | | < | | < | | | | 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 |
/*
* Check that we have a regular name for the command (that the user is not
* trying to do an expose and a rename (to another namespace) at the same
* time).
*/
if (strstr(cmdName, "::") != NULL) {
TclPrintfResult(interp,
"cannot expose to a namespace (use expose to toplevel, then rename)");
TclSetErrorCode(interp, "TCL", "EXPOSE", "NON_GLOBAL");
return TCL_ERROR;
}
/*
* Get the command from the hidden command table:
*/
hPtr = NULL;
hiddenCmdTablePtr = iPtr->hiddenCmdTablePtr;
if (hiddenCmdTablePtr != NULL) {
hPtr = Tcl_FindHashEntry(hiddenCmdTablePtr, hiddenCmdToken);
}
if (hPtr == NULL) {
TclPrintfResult(interp,
"unknown hidden command \"%s\"", hiddenCmdToken);
TclSetErrorCode(interp, "TCL", "LOOKUP", "HIDDENTOKEN", hiddenCmdToken);
return TCL_ERROR;
}
cmdPtr = (Command *)Tcl_GetHashValue(hPtr);
/*
* Check that we have a true global namespace command (enforced by
* Tcl_HideCommand but let's double check. (If it was not, we would not
* really know how to handle it).
*/
if (cmdPtr->nsPtr != iPtr->globalNsPtr) {
/*
* This case is theoretically impossible, we might rather Tcl_Panic
* than 'nicely' erroring out ?
*/
TclPrintfResult(interp,
"trying to expose a non-global command namespace command");
return TCL_ERROR;
}
/*
* This is the global table.
*/
nsPtr = cmdPtr->nsPtr;
/*
* It is an error to overwrite an existing exposed command as a result of
* exposing a previously hidden command.
*/
hPtr = Tcl_CreateHashEntry(&nsPtr->cmdTable, cmdName, &isNew);
if (!isNew) {
TclPrintfResult(interp,
"exposed command \"%s\" already exists", cmdName);
TclSetErrorCode(interp, "TCL", "EXPOSE", "COMMAND_EXISTS");
return TCL_ERROR;
}
/*
* Command resolvers (per-interp, per-namespace) might have resolved to a
* command for the given namespace scope with this command not being
* registered with the namespace's command table. During BC compilation,
|
| ︙ | ︙ | |||
3075 3076 3077 3078 3079 3080 3081 |
* Find the existing command. An error is returned if cmdName can't be
* found.
*/
cmd = Tcl_FindCommand(interp, oldName, NULL, /*flags*/ 0);
cmdPtr = (Command *) cmd;
if (cmdPtr == NULL) {
| | | | | 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 |
* Find the existing command. An error is returned if cmdName can't be
* found.
*/
cmd = Tcl_FindCommand(interp, oldName, NULL, /*flags*/ 0);
cmdPtr = (Command *) cmd;
if (cmdPtr == NULL) {
TclPrintfResult(interp,
"can't %s \"%s\": command doesn't exist",
((newName == NULL) || (*newName == '\0')) ? "delete" : "rename",
oldName);
TclSetErrorCode(interp, "TCL", "LOOKUP", "COMMAND", oldName);
return TCL_ERROR;
}
/*
* If the new command name is NULL or empty, delete the command. Do this
* with Tcl_DeleteCommandFromToken, since we already have the command.
*/
|
| ︙ | ︙ | |||
3108 3109 3110 3111 3112 3113 3114 |
* create the containing namespaces just like Tcl_CreateObjCommand would.
*/
TclGetNamespaceForQualName(interp, newName, NULL,
TCL_CREATE_NS_IF_UNKNOWN, &newNsPtr, &dummy1, &dummy2, &newTail);
if ((newNsPtr == NULL) || (newTail == NULL)) {
| | | | | | | < | 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 |
* create the containing namespaces just like Tcl_CreateObjCommand would.
*/
TclGetNamespaceForQualName(interp, newName, NULL,
TCL_CREATE_NS_IF_UNKNOWN, &newNsPtr, &dummy1, &dummy2, &newTail);
if ((newNsPtr == NULL) || (newTail == NULL)) {
TclPrintfResult(interp,
"can't rename to \"%s\": bad command name", newName);
TclSetErrorCode(interp, "TCL", "VALUE", "COMMAND");
result = TCL_ERROR;
goto done;
}
if (Tcl_FindHashEntry(&newNsPtr->cmdTable, newTail) != NULL) {
TclPrintfResult(interp,
"can't rename to \"%s\": command already exists", newName);
TclSetErrorCode(interp, "TCL", "OPERATION", "RENAME", "TARGET_EXISTS");
result = TCL_ERROR;
goto done;
}
/*
* Warning: any changes done in the code here are likely to be needed in
* Tcl_HideCommand code too (until the common parts are extracted out).
|
| ︙ | ︙ | |||
3559 3560 3561 3562 3563 3564 3565 |
/*
* Add the full name of the containing namespace, followed by the "::"
* separator, and the command name.
*/
if ((cmdPtr != NULL) && TclRoutineHasName(cmdPtr)) {
if (cmdPtr->nsPtr != NULL) {
| | | | | 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 |
/*
* Add the full name of the containing namespace, followed by the "::"
* separator, and the command name.
*/
if ((cmdPtr != NULL) && TclRoutineHasName(cmdPtr)) {
if (cmdPtr->nsPtr != NULL) {
Tcl_AppendToObj(objPtr, cmdPtr->nsPtr->fullName, TCL_AUTO_LENGTH);
if (cmdPtr->nsPtr != iPtr->globalNsPtr) {
TclAppendLiteralToObj(objPtr, "::");
}
}
if (cmdPtr->hPtr != NULL) {
name = (char *)Tcl_GetHashKey(cmdPtr->hPtr->tablePtr, cmdPtr->hPtr);
Tcl_AppendToObj(objPtr, name, TCL_AUTO_LENGTH);
}
}
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
4066 4067 4068 4069 4070 4071 4072 |
Tcl_ResetResult(interp);
/*
* If the interpreter has been deleted, return an error.
*/
if (iPtr->flags & DELETED) {
| < | | | | 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 |
Tcl_ResetResult(interp);
/*
* If the interpreter has been deleted, return an error.
*/
if (iPtr->flags & DELETED) {
TclPrintfResult(interp, "attempt to call eval in deleted interpreter");
TclSetErrorCode(interp, "TCL", "IDELETE",
"attempt to call eval in deleted interpreter");
return TCL_ERROR;
}
if (iPtr->execEnvPtr->rewind) {
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
4095 4096 4097 4098 4099 4100 4101 |
* probably because of an infinite loop somewhere.
*/
if ((iPtr->numLevels <= iPtr->maxNestingDepth)) {
return TCL_OK;
}
| < | | | 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 |
* probably because of an infinite loop somewhere.
*/
if ((iPtr->numLevels <= iPtr->maxNestingDepth)) {
return TCL_OK;
}
TclPrintfResult(interp, "too many nested evaluations (infinite loop?)");
TclSetErrorCode(interp, "TCL", "LIMIT", "STACK");
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* TclResetCancellation --
|
| ︙ | ︙ | |||
4231 4232 4233 4234 4235 4236 4237 |
id = "ICANCEL";
if (length == 0) {
message = "eval canceled";
}
}
Tcl_SetObjResult(interp, Tcl_NewStringObj(message, TCL_INDEX_NONE));
| | | 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 |
id = "ICANCEL";
if (length == 0) {
message = "eval canceled";
}
}
Tcl_SetObjResult(interp, Tcl_NewStringObj(message, TCL_INDEX_NONE));
TclSetErrorCode(interp, "TCL", "CANCEL", id, message);
}
/*
* Return TCL_ERROR to the caller (not necessarily just the Tcl core
* itself) that indicates further processing of the script or command in
* progress should halt gracefully and as soon as possible.
*/
|
| ︙ | ︙ | |||
4418 4419 4420 4421 4422 4423 4424 |
* this callback (that marks the end of the target command) and goes back
* to the end of the source command.
*/
if (iPtr->deferredCallbacks) {
iPtr->deferredCallbacks = NULL;
} else {
| | | 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 |
* this callback (that marks the end of the target command) and goes back
* to the end of the source command.
*/
if (iPtr->deferredCallbacks) {
iPtr->deferredCallbacks = NULL;
} else {
TclNRAddCallback(interp, NRCommand);
}
iPtr->numLevels++;
TclNRAddCallback(interp, EvalObjvCore, cmdPtr, INT2PTR(flags),
INT2PTR(objc), objv);
return TCL_OK;
}
|
| ︙ | ︙ | |||
4523 4524 4525 4526 4527 4528 4529 |
cmdPtr = preCmdPtr;
} else if (flags & TCL_EVAL_NORESOLVE) {
/*
* When it's been deleted, and we're told not to attempt resolving
* it ourselves, all we can do is raise an error.
*/
| | | | | 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 |
cmdPtr = preCmdPtr;
} else if (flags & TCL_EVAL_NORESOLVE) {
/*
* When it's been deleted, and we're told not to attempt resolving
* it ourselves, all we can do is raise an error.
*/
TclPrintfResult(interp,
"attempt to invoke a deleted command");
TclSetErrorCode(interp, "TCL", "EVAL", "DELETEDCOMMAND");
return TCL_ERROR;
}
}
if (cmdPtr == NULL) {
cmdPtr = TEOV_LookupCmdFromObj(interp, objv[0], lookupNsPtr);
if (!cmdPtr) {
return TEOV_NotFound(interp, objc, objv, lookupNsPtr);
|
| ︙ | ︙ | |||
4624 4625 4626 4627 4628 4629 4630 |
TclDTraceInfo(info, a, i);
TCL_DTRACE_CMD_INFO(a[0], a[1], a[2], a[3], i[0], i[1], a[4], a[5]);
TclDecrRefCount(info);
}
if ((TCL_DTRACE_CMD_RETURN_ENABLED() || TCL_DTRACE_CMD_RESULT_ENABLED())
&& objc) {
| | | 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 |
TclDTraceInfo(info, a, i);
TCL_DTRACE_CMD_INFO(a[0], a[1], a[2], a[3], i[0], i[1], a[4], a[5]);
TclDecrRefCount(info);
}
if ((TCL_DTRACE_CMD_RETURN_ENABLED() || TCL_DTRACE_CMD_RESULT_ENABLED())
&& objc) {
TclNRAddCallback(interp, DTraceCmdReturn, objv[0]);
}
if (TCL_DTRACE_CMD_ENTRY_ENABLED() && objc) {
TCL_DTRACE_CMD_ENTRY(TclGetString(objv[0]), objc - 1,
(Tcl_Obj **)(objv + 1));
}
#endif /* USE_DTRACE */
|
| ︙ | ︙ | |||
4674 4675 4676 4677 4678 4679 4680 |
* If there is a tailcall, schedule it next
*/
if (data[1] && (data[1] != INT2PTR(1))) {
listPtr = (Tcl_Obj *)data[1];
data[1] = NULL;
| | | 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 |
* If there is a tailcall, schedule it next
*/
if (data[1] && (data[1] != INT2PTR(1))) {
listPtr = (Tcl_Obj *)data[1];
data[1] = NULL;
TclNRAddCallback(interp, TclNRTailcallEval, listPtr);
}
/* OPT ??
* Do not interrupt a series of cleanups with async or limit checks:
* just check at the end?
*/
|
| ︙ | ︙ | |||
4729 4730 4731 4732 4733 4734 4735 |
*/
if (!(flags & TCL_EVAL_INVOKE)) {
/*
* Error messages
*/
| | < | < | < | 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 |
*/
if (!(flags & TCL_EVAL_INVOKE)) {
/*
* Error messages
*/
TclNRAddCallback(interp, TEOV_Error, INT2PTR(objc), objv);
}
if (iPtr->numLevels == 1) {
/*
* No CONTINUE or BREAK at level 0, manage RETURN
*/
TclNRAddCallback(interp, TEOV_Exception, INT2PTR(iPtr->evalFlags));
}
}
static void
TEOV_SwitchVarFrame(
Tcl_Interp *interp)
{
Interp *iPtr = (Interp *) interp;
/*
* Change the varFrame to be the rootVarFrame, and push a record to
* restore things at the end.
*/
TclNRAddCallback(interp, TEOV_RestoreVarFrame, iPtr->varFramePtr);
iPtr->varFramePtr = iPtr->rootFramePtr;
}
static int
TEOV_RestoreVarFrame(
void *data[],
Tcl_Interp *interp,
|
| ︙ | ︙ | |||
4897 4898 4899 4900 4901 4902 4903 |
*
* In this case we worry a bit less about recursion for now, and call the
* "blocking" interface.
*/
cmdPtr = TEOV_LookupCmdFromObj(interp, newObjv[0], lookupNsPtr);
if (cmdPtr == NULL) {
| | | | | | | 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 |
*
* In this case we worry a bit less about recursion for now, and call the
* "blocking" interface.
*/
cmdPtr = TEOV_LookupCmdFromObj(interp, newObjv[0], lookupNsPtr);
if (cmdPtr == NULL) {
TclPrintfResult(interp,
"invalid command name \"%s\"", TclGetString(objv[0]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "COMMAND",
TclGetString(objv[0]));
/*
* Release any resources we locked and allocated during the handler
* call.
*/
for (i = 0; i < handlerObjc; ++i) {
Tcl_DecrRefCount(newObjv[i]);
}
TclStackFree(interp, newObjv);
return TCL_ERROR;
}
if (lookupNsPtr) {
savedNsPtr = varFramePtr->nsPtr;
varFramePtr->nsPtr = lookupNsPtr;
}
TclSkipTailcall(interp);
TclNRAddCallback(interp, TEOV_NotFoundCallback, INT2PTR(handlerObjc),
newObjv, savedNsPtr);
return TclNREvalObjv(interp, newObjc, newObjv, TCL_EVAL_NOERR, NULL);
}
static int
TEOV_NotFoundCallback(
void *data[],
Tcl_Interp *interp,
|
| ︙ | ︙ | |||
4992 4993 4994 4995 4996 4997 4998 |
if (traceCode != TCL_OK) {
if (traceCode == TCL_ERROR) {
Tcl_Obj *info;
TclNewLiteralStringObj(info, "\n (enter trace on \"");
Tcl_AppendLimitedToObj(info, command, length, 55, "...");
| | | 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 |
if (traceCode != TCL_OK) {
if (traceCode == TCL_ERROR) {
Tcl_Obj *info;
TclNewLiteralStringObj(info, "\n (enter trace on \"");
Tcl_AppendLimitedToObj(info, command, length, 55, "...");
TclAppendLiteralToObj(info, "\")");
Tcl_AppendObjToErrorInfo(interp, info);
iPtr->flags |= ERR_ALREADY_LOGGED;
}
return traceCode;
}
if (cmdEpoch != newEpoch) {
*cmdPtrPtr = NULL;
|
| ︙ | ︙ | |||
5044 5045 5046 5047 5048 5049 5050 |
if (traceCode != TCL_OK) {
if (traceCode == TCL_ERROR) {
Tcl_Obj *info;
TclNewLiteralStringObj(info, "\n (leave trace on \"");
Tcl_AppendLimitedToObj(info, command, length, 55, "...");
| | | 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 |
if (traceCode != TCL_OK) {
if (traceCode == TCL_ERROR) {
Tcl_Obj *info;
TclNewLiteralStringObj(info, "\n (leave trace on \"");
Tcl_AppendLimitedToObj(info, command, length, 55, "...");
TclAppendLiteralToObj(info, "\")");
Tcl_AppendObjToErrorInfo(interp, info);
iPtr->flags |= ERR_ALREADY_LOGGED;
}
result = traceCode;
}
Tcl_DecrRefCount(commandPtr);
return result;
|
| ︙ | ︙ | |||
5387 5388 5389 5390 5391 5392 5393 |
code = TclListObjLength(interp, objv[objectsUsed],
&numElements);
if (code == TCL_ERROR) {
/*
* Attempt to expand a non-list.
*/
| | | > | 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 |
code = TclListObjLength(interp, objv[objectsUsed],
&numElements);
if (code == TCL_ERROR) {
/*
* Attempt to expand a non-list.
*/
TclPrintfErrorInfo(interp,
"\n (expanding word %" TCL_SIZE_MODIFIER "d)",
objectsUsed);
Tcl_DecrRefCount(objv[objectsUsed]);
break;
}
expandRequested = 1;
expand[objectsUsed] = 1;
additionalObjsCount = (numElements ? numElements : 1);
|
| ︙ | ︙ | |||
6201 6202 6203 6204 6205 6206 6207 | iPtr->cmdFramePtr = eoFramePtr; flags |= TCL_EVAL_SOURCE_IN_FRAME; } TclMarkTailcall(interp); TclNRAddCallback(interp, TEOEx_ListCallback, listPtr, eoFramePtr, | | | 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 |
iPtr->cmdFramePtr = eoFramePtr;
flags |= TCL_EVAL_SOURCE_IN_FRAME;
}
TclMarkTailcall(interp);
TclNRAddCallback(interp, TEOEx_ListCallback, listPtr, eoFramePtr,
objPtr);
TclListObjGetElements(NULL, listPtr, &objc, &objv);
return TclNREvalObjv(interp, objc, objv, flags, NULL);
}
if (!(flags & TCL_EVAL_DIRECT)) {
/*
|
| ︙ | ︙ | |||
6232 6233 6234 6235 6236 6237 6238 | savedVarFramePtr = iPtr->varFramePtr; iPtr->varFramePtr = iPtr->rootFramePtr; } Tcl_IncrRefCount(objPtr); codePtr = TclCompileObj(interp, objPtr, invoker, word); TclNRAddCallback(interp, TEOEx_ByteCodeCallback, savedVarFramePtr, | | | 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 |
savedVarFramePtr = iPtr->varFramePtr;
iPtr->varFramePtr = iPtr->rootFramePtr;
}
Tcl_IncrRefCount(objPtr);
codePtr = TclCompileObj(interp, objPtr, invoker, word);
TclNRAddCallback(interp, TEOEx_ByteCodeCallback, savedVarFramePtr,
objPtr, INT2PTR(allowExceptions));
return TclNRExecuteByteCode(interp, codePtr);
}
{
/*
* We're not supposed to use the compiler or byte-code
* interpreter. Let Tcl_EvalEx evaluate the command directly (and
|
| ︙ | ︙ | |||
6382 6383 6384 6385 6386 6387 6388 |
* result code was returned. */
int returnCode) /* The unexpected result code. */
{
char buf[TCL_INTEGER_SPACE];
Tcl_ResetResult(interp);
if (returnCode == TCL_BREAK) {
| < | < | < | | | 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 |
* result code was returned. */
int returnCode) /* The unexpected result code. */
{
char buf[TCL_INTEGER_SPACE];
Tcl_ResetResult(interp);
if (returnCode == TCL_BREAK) {
TclPrintfResult(interp, "invoked \"break\" outside of a loop");
} else if (returnCode == TCL_CONTINUE) {
TclPrintfResult(interp, "invoked \"continue\" outside of a loop");
} else {
TclPrintfResult(interp, "command returned bad code: %d", returnCode);
}
snprintf(buf, sizeof(buf), "%d", returnCode);
TclSetErrorCode(interp, "TCL", "UNEXPECTED_RESULT_CODE", buf);
}
/*
*---------------------------------------------------------------------------
*
* Tcl_ExprLong, Tcl_ExprDouble, Tcl_ExprBoolean --
*
|
| ︙ | ︙ | |||
6694 6695 6696 6697 6698 6699 6700 |
* TCL_INVOKE_HIDDEN, TCL_INVOKE_NO_UNKNOWN,
* or TCL_INVOKE_NO_TRACEBACK. */
{
if (interp == NULL) {
return TCL_ERROR;
}
if ((objc < 1) || (objv == NULL)) {
| < | | 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 |
* TCL_INVOKE_HIDDEN, TCL_INVOKE_NO_UNKNOWN,
* or TCL_INVOKE_NO_TRACEBACK. */
{
if (interp == NULL) {
return TCL_ERROR;
}
if ((objc < 1) || (objv == NULL)) {
TclPrintfResult(interp, "illegal argument vector");
return TCL_ERROR;
}
if ((flags & TCL_INVOKE_HIDDEN) == 0) {
Tcl_Panic("TclObjInvoke: called without TCL_INVOKE_HIDDEN");
}
return Tcl_NRCallObjProc(interp, TclNRInvoke, NULL, objc, objv);
}
|
| ︙ | ︙ | |||
6723 6724 6725 6726 6727 6728 6729 |
cmdName = TclGetString(objv[0]);
hTblPtr = iPtr->hiddenCmdTablePtr;
if (hTblPtr != NULL) {
hPtr = Tcl_FindHashEntry(hTblPtr, cmdName);
}
if (hPtr == NULL) {
| < | | < | | 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 |
cmdName = TclGetString(objv[0]);
hTblPtr = iPtr->hiddenCmdTablePtr;
if (hTblPtr != NULL) {
hPtr = Tcl_FindHashEntry(hTblPtr, cmdName);
}
if (hPtr == NULL) {
TclPrintfResult(interp, "invalid hidden command name \"%s\"", cmdName);
TclSetErrorCode(interp, "TCL", "LOOKUP", "HIDDENTOKEN", cmdName);
return TCL_ERROR;
}
cmdPtr = (Command *)Tcl_GetHashValue(hPtr);
/*
* Avoid the exception-handling brain damage when numLevels == 0
*/
iPtr->numLevels++;
TclNRAddCallback(interp, NRPostInvoke);
/*
* Normal command resolution of objv[0] isn't going to find cmdPtr.
* That's the whole point of **hidden** commands. So tell the Eval core
* machinery not to even try (and risk finding something wrong).
*/
|
| ︙ | ︙ | |||
6848 6849 6850 6851 6852 6853 6854 |
*/
iPtr->flags |= ERR_LEGACY_COPY;
if (iPtr->errorInfo == NULL) {
iPtr->errorInfo = iPtr->objResultPtr;
Tcl_IncrRefCount(iPtr->errorInfo);
if (!iPtr->errorCode) {
| | | 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 |
*/
iPtr->flags |= ERR_LEGACY_COPY;
if (iPtr->errorInfo == NULL) {
iPtr->errorInfo = iPtr->objResultPtr;
Tcl_IncrRefCount(iPtr->errorInfo);
if (!iPtr->errorCode) {
TclSetErrorCode(interp, "NONE");
}
}
/*
* Now append "message" to the end of errorInfo.
*/
|
| ︙ | ︙ | |||
7213 7214 7215 7216 7217 7218 7219 |
return TCL_ERROR;
}
Tcl_SetObjResult(interp, Tcl_NewBignumObj(&root));
}
return TCL_OK;
negarg:
| < | | | | 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 |
return TCL_ERROR;
}
Tcl_SetObjResult(interp, Tcl_NewBignumObj(&root));
}
return TCL_OK;
negarg:
TclPrintfResult(interp, "square root of negative argument");
TclSetErrorCode(interp, "ARITH", "DOMAIN",
"domain error: argument not in valid range");
return TCL_ERROR;
}
static int
ExprSqrtFunc(
TCL_UNUSED(void *),
Tcl_Interp *interp, /* The interpreter in which to execute the
|
| ︙ | ︙ | |||
8231 8232 8233 8234 8235 8236 8237 |
case FP_SUBNORMAL:
TclNewLiteralStringObj(objPtr, "subnormal");
break;
case FP_ZERO:
TclNewLiteralStringObj(objPtr, "zero");
break;
default:
| < | | 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 |
case FP_SUBNORMAL:
TclNewLiteralStringObj(objPtr, "subnormal");
break;
case FP_ZERO:
TclNewLiteralStringObj(objPtr, "zero");
break;
default:
TclPrintfResult(interp, "unable to classify number: %f", d);
return TCL_ERROR;
}
Tcl_SetObjResult(interp, objPtr);
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
8273 8274 8275 8276 8277 8278 8279 |
while (tail > name + 1) {
tail--;
if (*tail == ':' && tail[-1] == ':') {
name = tail + 1;
break;
}
}
| | | | | 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 |
while (tail > name + 1) {
tail--;
if (*tail == ':' && tail[-1] == ':') {
name = tail + 1;
break;
}
}
TclPrintfResult(interp,
"%s arguments for math function \"%s\"",
(found < expected ? "not enough" : "too many"), name);
TclSetErrorCode(interp, "TCL", "WRONGARGS");
}
#ifdef USE_DTRACE
/*
*----------------------------------------------------------------------
*
* DTraceObjCmd --
|
| ︙ | ︙ | |||
8692 8693 8694 8695 8696 8697 8698 |
void
TclMarkTailcall(
Tcl_Interp *interp)
{
Interp *iPtr = (Interp *) interp;
if (iPtr->deferredCallbacks == NULL) {
| | < | | 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 |
void
TclMarkTailcall(
Tcl_Interp *interp)
{
Interp *iPtr = (Interp *) interp;
if (iPtr->deferredCallbacks == NULL) {
TclNRAddCallback(interp, NRCommand);
iPtr->deferredCallbacks = TOP_CB(interp);
}
}
void
TclSkipTailcall(
Tcl_Interp *interp)
{
Interp *iPtr = (Interp *) interp;
TclMarkTailcall(interp);
iPtr->deferredCallbacks->data[1] = INT2PTR(1);
}
void
TclPushTailcallPoint(
Tcl_Interp *interp)
{
TclNRAddCallback(interp, NRCommand);
((Interp *) interp)->numLevels++;
}
/*
*----------------------------------------------------------------------
*
* TclSetTailcall --
|
| ︙ | ︙ | |||
8782 8783 8784 8785 8786 8787 8788 |
if (objc < 1) {
Tcl_WrongNumArgs(interp, 1, objv, "?command? ?arg ...?");
return TCL_ERROR;
}
if (!(iPtr->varFramePtr->isProcCallFrame & 1)) {
| | | | | 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 |
if (objc < 1) {
Tcl_WrongNumArgs(interp, 1, objv, "?command? ?arg ...?");
return TCL_ERROR;
}
if (!(iPtr->varFramePtr->isProcCallFrame & 1)) {
TclPrintfResult(interp,
"tailcall can only be called from a proc, lambda or method");
TclSetErrorCode(interp, "TCL", "TAILCALL", "ILLEGAL");
return TCL_ERROR;
}
/*
* Invocation without args just clears a scheduled tailcall; invocation
* with an argument replaces any previously scheduled tailcall.
*/
|
| ︙ | ︙ | |||
8865 8866 8867 8868 8869 8870 8871 |
}
/*
* Perform the tailcall
*/
TclMarkTailcall(interp);
| | | 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 |
}
/*
* Perform the tailcall
*/
TclMarkTailcall(interp);
TclNRAddCallback(interp, TclNRReleaseValues, listPtr);
iPtr->lookupNsPtr = (Namespace *) nsPtr;
return TclNREvalObjv(interp, objc - 1, objv + 1, 0, NULL);
}
int
TclNRReleaseValues(
void *data[],
|
| ︙ | ︙ | |||
8943 8944 8945 8946 8947 8948 8949 |
if (objc > 2) {
Tcl_WrongNumArgs(interp, 1, objv, "?returnValue?");
return TCL_ERROR;
}
if (!corPtr) {
| < | | | < < | | < | | < | 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 |
if (objc > 2) {
Tcl_WrongNumArgs(interp, 1, objv, "?returnValue?");
return TCL_ERROR;
}
if (!corPtr) {
TclPrintfResult(interp, "yield can only be called in a coroutine");
TclSetErrorCode(interp, "TCL", "COROUTINE", "ILLEGAL_YIELD");
return TCL_ERROR;
}
if (objc == 2) {
Tcl_SetObjResult(interp, objv[1]);
}
NRE_ASSERT(!COR_IS_SUSPENDED(corPtr));
TclNRAddCallback(interp, TclNRCoroutineActivateCallback, corPtr, clientData);
return TCL_OK;
}
int
TclNRYieldToObjCmd(
TCL_UNUSED(void *),
Tcl_Interp *interp,
int objc,
Tcl_Obj *const objv[])
{
CoroutineData *corPtr = iPtr->execEnvPtr->corPtr;
Tcl_Namespace *nsPtr = TclGetCurrentNamespace(interp);
Tcl_Obj *listPtr;
if (objc < 2) {
Tcl_WrongNumArgs(interp, 1, objv, "command ?arg ...?");
return TCL_ERROR;
}
if (!corPtr) {
TclPrintfResult(interp, "yieldto can only be called in a coroutine");
TclSetErrorCode(interp, "TCL", "COROUTINE", "ILLEGAL_YIELD");
return TCL_ERROR;
}
if (((Namespace *) nsPtr)->flags & NS_DYING) {
TclPrintfResult(interp, "yieldto called in deleted namespace");
TclSetErrorCode(interp, "TCL", "COROUTINE", "YIELDTO_IN_DELETED");
return TCL_ERROR;
}
/*
* Add the tailcall in the caller env, then just yield.
*
* This is essentially code from TclNRTailcallObjCmd
|
| ︙ | ︙ | |||
9034 9035 9036 9037 9038 9039 9040 |
Tcl_InterpState state = Tcl_SaveInterpState(interp, result);
NRE_ASSERT(COR_IS_SUSPENDED(corPtr));
NRE_ASSERT(corPtr->eePtr != NULL);
NRE_ASSERT(corPtr->eePtr != iPtr->execEnvPtr);
corPtr->eePtr->rewind = 1;
| | < | 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 |
Tcl_InterpState state = Tcl_SaveInterpState(interp, result);
NRE_ASSERT(COR_IS_SUSPENDED(corPtr));
NRE_ASSERT(corPtr->eePtr != NULL);
NRE_ASSERT(corPtr->eePtr != iPtr->execEnvPtr);
corPtr->eePtr->rewind = 1;
TclNRAddCallback(interp, RewindCoroutineCallback, state);
return TclNRInterpCoroutine(corPtr, interp, 0, NULL);
}
static void
DeleteCoroutine(
void *clientData)
{
|
| ︙ | ︙ | |||
9179 9180 9181 9182 9183 9184 9185 |
if (!corPtr->stackLevel) {
/*
* -- Coroutine is suspended --
* Push the callback to restore the caller's context on yield or
* return.
*/
| | < | 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 |
if (!corPtr->stackLevel) {
/*
* -- Coroutine is suspended --
* Push the callback to restore the caller's context on yield or
* return.
*/
TclNRAddCallback(interp, NRCoroutineCallerCallback, corPtr);
/*
* Record the stackLevel at which the resume is happening, then swap
* the interp's environment to make it suitable to run this coroutine.
*/
corPtr->stackLevel = stackLevel;
|
| ︙ | ︙ | |||
9217 9218 9219 9220 9221 9222 9223 | corPtr->yieldPtr = NULL; break; } } } iPtr->execEnvPtr = corPtr->eePtr; | < | | < | 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 |
corPtr->yieldPtr = NULL;
break;
}
}
}
iPtr->execEnvPtr = corPtr->eePtr;
TclPrintfResult(interp, "cannot yield: C stack busy");
TclSetErrorCode(interp, "TCL", "COROUTINE", "CANT_YIELD");
return TCL_ERROR;
}
void *type = data[1];
if (type == CORO_ACTIVATE_YIELD) {
corPtr->nargs = COROUTINE_ARGUMENTS_SINGLE_OPTIONAL;
} else if (type == CORO_ACTIVATE_YIELDM) {
|
| ︙ | ︙ | |||
9277 9278 9279 9280 9281 9282 9283 |
/*
* Look up the coroutine.
*/
cmdPtr = (Command *) Tcl_GetCommandFromObj(interp, objv[1]);
if ((!cmdPtr) || (cmdPtr->nreProc != TclNRInterpCoroutine)) {
| < | | | | | | < | | | 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 |
/*
* Look up the coroutine.
*/
cmdPtr = (Command *) Tcl_GetCommandFromObj(interp, objv[1]);
if ((!cmdPtr) || (cmdPtr->nreProc != TclNRInterpCoroutine)) {
TclPrintfResult(interp, "can only get coroutine type of a coroutine");
TclSetErrorCode(interp, "TCL", "LOOKUP", "COROUTINE",
TclGetString(objv[1]));
return TCL_ERROR;
}
/*
* An active coroutine is "active". Can't tell what it might do in the
* future.
*/
corPtr = (CoroutineData *)cmdPtr->objClientData;
if (!COR_IS_SUSPENDED(corPtr)) {
Tcl_SetObjResult(interp, TclNewString("active"));
return TCL_OK;
}
/*
* Inactive coroutines are classified by the (effective) command used to
* suspend them, which matters when you're injecting a probe.
*/
switch (corPtr->nargs) {
case COROUTINE_ARGUMENTS_SINGLE_OPTIONAL:
Tcl_SetObjResult(interp, TclNewString("yield"));
return TCL_OK;
case COROUTINE_ARGUMENTS_ARBITRARY:
Tcl_SetObjResult(interp, TclNewString("yieldto"));
return TCL_OK;
default:
TclPrintfResult(interp, "unknown coroutine type");
TclSetErrorCode(interp, "TCL", "COROUTINE", "BAD_TYPE");
return TCL_ERROR;
}
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
9339 9340 9341 9342 9343 9344 9345 |
* How to get a coroutine from its handle.
*/
Command *cmdPtr = (Command *) Tcl_GetCommandFromObj(interp, objPtr);
if ((!cmdPtr) || (cmdPtr->nreProc != TclNRInterpCoroutine)) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(errMsg, TCL_INDEX_NONE));
| | | | 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 |
* How to get a coroutine from its handle.
*/
Command *cmdPtr = (Command *) Tcl_GetCommandFromObj(interp, objPtr);
if ((!cmdPtr) || (cmdPtr->nreProc != TclNRInterpCoroutine)) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(errMsg, TCL_INDEX_NONE));
TclSetErrorCode(interp, "TCL", "LOOKUP", "COROUTINE",
TclGetString(objPtr));
return NULL;
}
return (CoroutineData *)cmdPtr->objClientData;
}
static int
TclNRCoroInjectObjCmd(
|
| ︙ | ︙ | |||
9371 9372 9373 9374 9375 9376 9377 |
corPtr = GetCoroutineFromObj(interp, objv[1],
"can only inject a command into a coroutine");
if (!corPtr) {
return TCL_ERROR;
}
if (!COR_IS_SUSPENDED(corPtr)) {
| | | | | | 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 |
corPtr = GetCoroutineFromObj(interp, objv[1],
"can only inject a command into a coroutine");
if (!corPtr) {
return TCL_ERROR;
}
if (!COR_IS_SUSPENDED(corPtr)) {
TclPrintfResult(interp,
"can only inject a command into a suspended coroutine");
TclSetErrorCode(interp, "TCL", "COROUTINE", "ACTIVE");
return TCL_ERROR;
}
/*
* Add the callback to the coro's execEnv, so that it is the first thing
* to happen when the coro is resumed.
*/
ExecEnv *savedEEPtr = iPtr->execEnvPtr;
iPtr->execEnvPtr = corPtr->eePtr;
TclNRAddCallback(interp, InjectHandler, corPtr,
Tcl_NewListObj(objc - 2, objv + 2), INT2PTR(corPtr->nargs));
iPtr->execEnvPtr = savedEEPtr;
return TCL_OK;
}
static int
TclNRCoroProbeObjCmd(
|
| ︙ | ︙ | |||
9416 9417 9418 9419 9420 9421 9422 |
corPtr = GetCoroutineFromObj(interp, objv[1],
"can only inject a probe command into a coroutine");
if (!corPtr) {
return TCL_ERROR;
}
if (!COR_IS_SUSPENDED(corPtr)) {
| | | < | | 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 |
corPtr = GetCoroutineFromObj(interp, objv[1],
"can only inject a probe command into a coroutine");
if (!corPtr) {
return TCL_ERROR;
}
if (!COR_IS_SUSPENDED(corPtr)) {
TclPrintfResult(interp,
"can only inject a probe command into a suspended coroutine");
TclSetErrorCode(interp, "TCL", "COROUTINE", "ACTIVE");
return TCL_ERROR;
}
/*
* Add the callback to the coro's execEnv, so that it is the first thing
* to happen when the coro is resumed.
*/
|
| ︙ | ︙ | |||
9441 9442 9443 9444 9445 9446 9447 |
/*
* Now we immediately transfer control to the coroutine to run our probe.
* TRICKY STUFF copied from the [yield] implementation.
*
* Push the callback to restore the caller's context on yield back.
*/
| | < | 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 |
/*
* Now we immediately transfer control to the coroutine to run our probe.
* TRICKY STUFF copied from the [yield] implementation.
*
* Push the callback to restore the caller's context on yield back.
*/
TclNRAddCallback(interp, NRCoroutineCallerCallback, corPtr);
/*
* Record the stackLevel at which the resume is happening, then swap
* the interp's environment to make it suitable to run this coroutine.
*/
corPtr->stackLevel = &corPtr;
|
| ︙ | ︙ | |||
9505 9506 9507 9508 9509 9510 9511 |
if (!isProbe) {
/*
* If this is [coroinject], add the extra arguments now.
*/
if (nargs == COROUTINE_ARGUMENTS_SINGLE_OPTIONAL) {
| | < | < | 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 |
if (!isProbe) {
/*
* If this is [coroinject], add the extra arguments now.
*/
if (nargs == COROUTINE_ARGUMENTS_SINGLE_OPTIONAL) {
Tcl_ListObjAppendElement(NULL, listPtr, TclNewString("yield"));
} else if (nargs == COROUTINE_ARGUMENTS_ARBITRARY) {
Tcl_ListObjAppendElement(NULL, listPtr, TclNewString("yieldto"));
} else {
/*
* I don't think this is reachable...
*/
Tcl_Obj *nargsObj;
TclNewIndexObj(nargsObj, nargs);
Tcl_ListObjAppendElement(NULL, listPtr, nargsObj);
|
| ︙ | ︙ | |||
9582 9583 9584 9585 9586 9587 9588 |
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
CoroutineData *corPtr = (CoroutineData *)clientData;
if (!COR_IS_SUSPENDED(corPtr)) {
| | | < | < | | | | < | 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 |
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
CoroutineData *corPtr = (CoroutineData *)clientData;
if (!COR_IS_SUSPENDED(corPtr)) {
TclPrintfResult(interp,
"coroutine \"%s\" is already running", TclGetString(objv[0]));
TclSetErrorCode(interp, "TCL", "COROUTINE", "BUSY");
return TCL_ERROR;
}
/*
* Parse all the arguments to work out what to feed as the result of the
* [yield]. TRICKY POINT: objc==0 happens here! It occurs when a coroutine
* is deleted!
*/
switch (corPtr->nargs) {
case COROUTINE_ARGUMENTS_SINGLE_OPTIONAL:
if (objc == 2) {
Tcl_SetObjResult(interp, objv[1]);
} else if (objc > 2) {
Tcl_WrongNumArgs(interp, 1, objv, "?arg?");
return TCL_ERROR;
}
break;
default:
if (corPtr->nargs + 1 != objc) {
TclPrintfResult(interp, "wrong coro nargs; how did we get here? "
"not implemented!");
TclSetErrorCode(interp, "TCL", "WRONGARGS");
return TCL_ERROR;
}
/* fallthrough */
case COROUTINE_ARGUMENTS_ARBITRARY:
if (objc > 1) {
Tcl_SetObjResult(interp, Tcl_NewListObj(objc - 1, objv + 1));
}
break;
}
TclNRAddCallback(interp, TclNRCoroutineActivateCallback, corPtr);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* TclNRCoroutineObjCmd --
|
| ︙ | ︙ | |||
9660 9661 9662 9663 9664 9665 9666 |
}
procName = TclGetString(objv[1]);
TclGetNamespaceForQualName(interp, procName, inNsPtr, 0,
&nsPtr, &altNsPtr, &cxtNsPtr, &simpleName);
if (nsPtr == NULL) {
| | | | | | | | 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 |
}
procName = TclGetString(objv[1]);
TclGetNamespaceForQualName(interp, procName, inNsPtr, 0,
&nsPtr, &altNsPtr, &cxtNsPtr, &simpleName);
if (nsPtr == NULL) {
TclPrintfResult(interp,
"can't create procedure \"%s\": unknown namespace",
procName);
TclSetErrorCode(interp, "TCL", "LOOKUP", "NAMESPACE");
return TCL_ERROR;
}
if (simpleName == NULL) {
TclPrintfResult(interp,
"can't create procedure \"%s\": bad procedure name",
procName);
TclSetErrorCode(interp, "TCL", "VALUE", "COMMAND", procName);
return TCL_ERROR;
}
/*
* We ARE creating the coroutine command: allocate the corresponding
* struct and create the corresponding command.
*/
|
| ︙ | ︙ | |||
9742 9743 9744 9745 9746 9747 9748 |
corPtr->eePtr->corPtr = corPtr;
SAVE_CONTEXT(corPtr->caller);
corPtr->callerEEPtr = iPtr->execEnvPtr;
RESTORE_CONTEXT(corPtr->running);
iPtr->execEnvPtr = corPtr->eePtr;
| | < | < | 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 |
corPtr->eePtr->corPtr = corPtr;
SAVE_CONTEXT(corPtr->caller);
corPtr->callerEEPtr = iPtr->execEnvPtr;
RESTORE_CONTEXT(corPtr->running);
iPtr->execEnvPtr = corPtr->eePtr;
TclNRAddCallback(interp, NRCoroutineExitCallback, corPtr);
/*
* Ensure that the command is looked up in the correct namespace.
*/
iPtr->lookupNsPtr = lookupNsPtr;
Tcl_NREvalObj(interp, Tcl_NewListObj(objc - 2, objv + 2), 0);
iPtr->numLevels--;
SAVE_CONTEXT(corPtr->running);
RESTORE_CONTEXT(corPtr->caller);
iPtr->execEnvPtr = corPtr->callerEEPtr;
/*
* Now just resume the coroutine.
*/
TclNRAddCallback(interp, TclNRCoroutineActivateCallback, corPtr);
return TCL_OK;
}
/*
* This is used in the [info] ensemble
*/
|
| ︙ | ︙ |
Changes to generic/tclBinary.c.
| ︙ | ︙ | |||
397 398 399 400 401 402 403 |
if (bytes && numBytesPtr) {
if (numBytes > INT_MAX) {
/* Caller asked for numBytes to be written to an int, but the
* value is outside the int range. */
if (interp) {
| < | | | 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
if (bytes && numBytesPtr) {
if (numBytes > INT_MAX) {
/* Caller asked for numBytes to be written to an int, but the
* value is outside the int range. */
if (interp) {
TclPrintfResult(interp, "byte sequence length exceeds INT_MAX");
TclSetErrorCode(interp, "TCL", "API", "OUTDATED");
}
return NULL;
} else {
*(int *)numBytesPtr = (int) numBytes;
}
}
return bytes;
|
| ︙ | ︙ | |||
514 515 516 517 518 519 520 |
int ch;
int count = TclUtfToUniChar(src, &ch);
if (ch > 255) {
proper = 0;
if (demandProper) {
if (interp) {
| | | | | 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 |
int ch;
int count = TclUtfToUniChar(src, &ch);
if (ch > 255) {
proper = 0;
if (demandProper) {
if (interp) {
TclPrintfResult(interp,
"expected byte sequence but character %"
TCL_Z_MODIFIER "u was '%1s' (U+%06X)",
dst - byteArrayPtr->bytes, src, ch);
TclSetErrorCode(interp, "TCL", "VALUE", "BYTES");
}
Tcl_Free(byteArrayPtr);
*byteArrayPtrPtr = NULL;
return proper;
}
}
src += count;
|
| ︙ | ︙ | |||
963 964 965 966 967 968 969 |
if (TclListObjLength(interp, objv[arg], &listc) != TCL_OK) {
return TCL_ERROR;
}
if (count == BINARY_ALL) {
count = listc;
} else if (count > listc) {
| | | < | | | 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 |
if (TclListObjLength(interp, objv[arg], &listc) != TCL_OK) {
return TCL_ERROR;
}
if (count == BINARY_ALL) {
count = listc;
} else if (count > listc) {
TclPrintfResult(interp,
"number of elements in list does not match count");
return TCL_ERROR;
}
if (TclListObjGetElements(interp, objv[arg], &listc,
&listv) != TCL_OK) {
return TCL_ERROR;
}
arg++;
}
offset += count*size;
break;
case 'x':
if (count == BINARY_ALL) {
TclPrintfResult(interp,
"cannot use \"*\" in format string with \"x\"");
return TCL_ERROR;
} else if (count == BINARY_NOCOUNT) {
count = 1;
}
offset += count;
break;
case 'X':
|
| ︙ | ︙ | |||
1294 1295 1296 1297 1298 1299 1300 |
}
}
Tcl_SetObjResult(interp, resultPtr);
return TCL_OK;
badValue:
Tcl_ResetResult(interp);
| | | < | | 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 |
}
}
Tcl_SetObjResult(interp, resultPtr);
return TCL_OK;
badValue:
Tcl_ResetResult(interp);
TclPrintfResult(interp,
"expected %s string but got \"%s\" instead",
errorString, errorValue);
return TCL_ERROR;
badCount:
errorString = "missing count for \"@\" field specifier";
goto error;
badIndex:
errorString = "not enough arguments for all format specifiers";
goto error;
badField:
{
Tcl_UniChar ch = 0;
char buf[5] = "";
TclUtfToUniChar(errorString, &ch);
buf[Tcl_UniCharToUtf(ch, buf)] = '\0';
TclPrintfResult(interp, "bad field specifier \"%s\"", buf);
return TCL_ERROR;
}
error:
Tcl_SetObjResult(interp, Tcl_NewStringObj(errorString, -1));
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
1695 1696 1697 1698 1699 1700 1701 |
badField:
{
Tcl_UniChar ch = 0;
char buf[5] = "";
TclUtfToUniChar(errorString, &ch);
buf[Tcl_UniCharToUtf(ch, buf)] = '\0';
| < | | 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 |
badField:
{
Tcl_UniChar ch = 0;
char buf[5] = "";
TclUtfToUniChar(errorString, &ch);
buf[Tcl_UniCharToUtf(ch, buf)] = '\0';
TclPrintfResult(interp, "bad field specifier \"%s\"", buf);
return TCL_ERROR;
}
error:
Tcl_SetObjResult(interp, Tcl_NewStringObj(errorString, -1));
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
2561 2562 2563 2564 2565 2566 2567 |
badChar:
if (pure) {
ucs4 = c;
} else {
TclUtfToUniChar((const char *)(data - 1), &ucs4);
}
TclDecrRefCount(resultObj);
| | | | | 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 |
badChar:
if (pure) {
ucs4 = c;
} else {
TclUtfToUniChar((const char *)(data - 1), &ucs4);
}
TclDecrRefCount(resultObj);
TclPrintfResult(interp,
"invalid hexadecimal digit \"%c\" (U+%06X) at position %"
TCL_Z_MODIFIER "u", ucs4, ucs4, data - datastart - 1);
TclSetErrorCode(interp, "TCL", "BINARY", "DECODE", "INVALID");
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* BinaryEncode64 --
|
| ︙ | ︙ | |||
2630 2631 2632 2633 2634 2635 2636 |
}
switch (index) {
case OPT_MAXLEN:
if (TclGetWideIntFromObj(interp, objv[i + 1], &maxlen) != TCL_OK) {
return TCL_ERROR;
}
if (maxlen < 0) {
| < | | | | 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 |
}
switch (index) {
case OPT_MAXLEN:
if (TclGetWideIntFromObj(interp, objv[i + 1], &maxlen) != TCL_OK) {
return TCL_ERROR;
}
if (maxlen < 0) {
TclPrintfResult(interp, "line length out of range");
TclSetErrorCode(interp, "TCL", "BINARY", "ENCODE",
"LINE_LENGTH");
return TCL_ERROR;
}
break;
case OPT_WRAPCHAR:
wrapchar = (const char *)Tcl_GetBytesFromObj(NULL,
objv[i + 1], &wrapcharlen);
if (wrapchar == NULL) {
|
| ︙ | ︙ | |||
2758 2759 2760 2761 2762 2763 2764 |
switch (index) {
case OPT_MAXLEN:
if (Tcl_GetIntFromObj(interp, objv[i + 1],
&lineLength) != TCL_OK) {
return TCL_ERROR;
}
if (lineLength < 5 || lineLength > 85) {
| < | | | | < | | | | | | | | > | | | | | | | | | < | | | < > | 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 |
switch (index) {
case OPT_MAXLEN:
if (Tcl_GetIntFromObj(interp, objv[i + 1],
&lineLength) != TCL_OK) {
return TCL_ERROR;
}
if (lineLength < 5 || lineLength > 85) {
TclPrintfResult(interp, "line length out of range");
TclSetErrorCode(interp, "TCL", "BINARY", "ENCODE",
"LINE_LENGTH");
return TCL_ERROR;
}
lineLength = ((lineLength - 1) & -4) + 1; /* 5, 9, 13 ... */
break;
case OPT_WRAPCHAR: {
wrapchar = (const unsigned char *)TclGetStringFromObj(
objv[i + 1], &wrapcharlen);
const unsigned char *p = wrapchar;
Tcl_Size numBytes = wrapcharlen;
while (numBytes) {
switch (*p) {
case '\t':
case '\v':
case '\f':
case '\r':
p++;
numBytes--;
continue;
case '\n':
numBytes--;
break;
default:
badwrap:
TclPrintfResult(interp,
"invalid wrapchar; will defeat decoding");
TclSetErrorCode(interp, "TCL", "BINARY",
"ENCODE", "WRAPCHAR");
return TCL_ERROR;
}
}
if (numBytes) {
goto badwrap;
}
break;
}
}
}
/*
* Allocate the buffer. This is a little bit too long, but is "good
* enough".
*/
|
| ︙ | ︙ | |||
3014 3015 3016 3017 3018 3019 3020 |
goto shortUu;
}
Tcl_SetByteArrayLength(resultObj, cursor - begin);
Tcl_SetObjResult(interp, resultObj);
return TCL_OK;
shortUu:
| | | | | | | 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 |
goto shortUu;
}
Tcl_SetByteArrayLength(resultObj, cursor - begin);
Tcl_SetObjResult(interp, resultObj);
return TCL_OK;
shortUu:
TclPrintfResult(interp, "short uuencode data");
TclSetErrorCode(interp, "TCL", "BINARY", "DECODE", "SHORT");
TclDecrRefCount(resultObj);
return TCL_ERROR;
badUu:
if (pure) {
ucs4 = c;
} else {
TclUtfToUniChar((const char *)(data - 1), &ucs4);
}
TclPrintfResult(interp,
"invalid uuencode character \"%c\" (U+%06X) at position %"
TCL_Z_MODIFIER "u", ucs4, ucs4, data - datastart - 1);
TclSetErrorCode(interp, "TCL", "BINARY", "DECODE", "INVALID");
TclDecrRefCount(resultObj);
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
3201 3202 3203 3204 3205 3206 3207 |
* valid member of the base64 alphabet, it could be the lead byte
* of a multi-byte character. */
/* Safe because we know data is NUL-terminated */
TclUtfToUniChar((const char *)(data - 1), &ucs4);
}
| | | | | 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 |
* valid member of the base64 alphabet, it could be the lead byte
* of a multi-byte character. */
/* Safe because we know data is NUL-terminated */
TclUtfToUniChar((const char *)(data - 1), &ucs4);
}
TclPrintfResult(interp,
"invalid base64 character \"%c\" (U+%06X) at position %"
TCL_Z_MODIFIER "u", ucs4, ucs4, data - datastart - 1);
TclSetErrorCode(interp, "TCL", "BINARY", "DECODE", "INVALID");
TclDecrRefCount(resultObj);
return TCL_ERROR;
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 4
* fill-column: 78
* End:
*/
|
Changes to generic/tclCkalloc.c.
| ︙ | ︙ | |||
186 187 188 189 190 191 192 |
current_bytes_malloced,
maximum_malloc_packets,
maximum_bytes_malloced);
if (flags == 0) {
fprintf((FILE *)clientData, "%s", buf);
} else {
/* Assume objPtr to append to */
| | | 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
current_bytes_malloced,
maximum_malloc_packets,
maximum_bytes_malloced);
if (flags == 0) {
fprintf((FILE *)clientData, "%s", buf);
} else {
/* Assume objPtr to append to */
Tcl_AppendToObj((Tcl_Obj *) clientData, buf, TCL_AUTO_LENGTH);
}
return 1;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
821 822 823 824 825 826 827 |
fileName = Tcl_TranslateFileName(interp, TclGetString(objv[2]), &buffer);
if (fileName == NULL) {
return TCL_ERROR;
}
result = Tcl_DumpActiveMemory(fileName);
Tcl_DStringFree(&buffer);
if (result != TCL_OK) {
| | | | | | | < | 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 |
fileName = Tcl_TranslateFileName(interp, TclGetString(objv[2]), &buffer);
if (fileName == NULL) {
return TCL_ERROR;
}
result = Tcl_DumpActiveMemory(fileName);
Tcl_DStringFree(&buffer);
if (result != TCL_OK) {
TclPrintfResult(interp, "error accessing %s: %s",
TclGetString(objv[2]), Tcl_PosixError(interp));
return TCL_ERROR;
}
return TCL_OK;
}
if (strcmp(TclGetString(objv[1]),"break_on_malloc") == 0) {
Tcl_WideInt value;
if (objc != 3) {
goto argError;
}
if (TclGetWideIntFromObj(interp, objv[2], &value) != TCL_OK) {
return TCL_ERROR;
}
break_on_malloc = value;
return TCL_OK;
}
if (strcmp(TclGetString(objv[1]),"info") == 0) {
TclPrintfResult(interp,
"%-25s %10" TCL_Z_MODIFIER "u\n%-25s %10" TCL_Z_MODIFIER "u\n%-25s %10" TCL_Z_MODIFIER "u\n%-25s %10" TCL_Z_MODIFIER "u\n%-25s %10" TCL_Z_MODIFIER "u\n%-25s %10" TCL_Z_MODIFIER "u\n",
"total mallocs", total_mallocs, "total frees", total_frees,
"current packets allocated", current_malloc_packets,
"current bytes allocated", current_bytes_malloced,
"maximum packets allocated", maximum_malloc_packets,
"maximum bytes allocated", maximum_bytes_malloced);
return TCL_OK;
}
if (strcmp(TclGetString(objv[1]), "init") == 0) {
if (objc != 3) {
goto bad_suboption;
}
init_malloced_bodies = (strcmp(TclGetString(objv[2]),"on") == 0);
return TCL_OK;
}
if (strcmp(TclGetString(objv[1]), "objs") == 0) {
if (objc != 3) {
Tcl_WrongNumArgs(interp, 2, objv, "file");
return TCL_ERROR;
}
fileName = Tcl_TranslateFileName(interp, TclGetString(objv[2]), &buffer);
if (fileName == NULL) {
return TCL_ERROR;
}
fileP = fopen(fileName, "w");
if (fileP == NULL) {
TclPrintfResult(interp,
"cannot open output file: %s", Tcl_PosixError(interp));
return TCL_ERROR;
}
TclDbDumpActiveObjects(fileP);
fclose(fileP);
Tcl_DStringFree(&buffer);
return TCL_OK;
}
|
| ︙ | ︙ | |||
931 932 933 934 935 936 937 |
if (objc != 3) {
goto bad_suboption;
}
validate_memory = (strcmp(TclGetString(objv[2]),"on") == 0);
return TCL_OK;
}
| | | | 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 |
if (objc != 3) {
goto bad_suboption;
}
validate_memory = (strcmp(TclGetString(objv[2]),"on") == 0);
return TCL_OK;
}
TclPrintfResult(interp,
"bad option \"%s\": should be active, break_on_malloc, info, "
"init, objs, onexit, tag, trace, trace_on_at_malloc, or validate",
TclGetString(objv[1]));
return TCL_ERROR;
argError:
Tcl_WrongNumArgs(interp, 2, objv, "count");
return TCL_ERROR;
bad_suboption:
|
| ︙ | ︙ |
Changes to generic/tclClock.c.
| ︙ | ︙ | |||
698 699 700 701 702 703 704 |
/* if locale was not yet used */
if (!(opts->flags & CLF_LOCALE_USED)) {
opts->localeObj = NormLocaleObj(dataPtr, opts->interp,
opts->localeObj, &opts->mcDictObj);
if (opts->localeObj == NULL) {
| | | < | | 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 |
/* if locale was not yet used */
if (!(opts->flags & CLF_LOCALE_USED)) {
opts->localeObj = NormLocaleObj(dataPtr, opts->interp,
opts->localeObj, &opts->mcDictObj);
if (opts->localeObj == NULL) {
TclPrintfResult(opts->interp,
"locale not specified and no default locale set");
TclSetErrorCode(opts->interp, "CLOCK", "badOption");
return NULL;
}
opts->flags |= CLF_LOCALE_USED;
/* check locale literals already available (on demand creation) */
if (dataPtr->mcLiterals == NULL) {
int i;
|
| ︙ | ︙ | |||
969 970 971 972 973 974 975 |
};
int optionIndex; /* Index of an option. */
Tcl_Size i;
for (i = 1; i < objc; i++) {
if (Tcl_GetIndexFromObj(interp, objv[i++], options,
"option", 0, &optionIndex) != TCL_OK) {
| | | | 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 |
};
int optionIndex; /* Index of an option. */
Tcl_Size i;
for (i = 1; i < objc; i++) {
if (Tcl_GetIndexFromObj(interp, objv[i++], options,
"option", 0, &optionIndex) != TCL_OK) {
TclSetErrorCode(interp, "CLOCK", "badOption",
TclGetString(objv[i - 1]));
return TCL_ERROR;
}
switch (optionIndex) {
case CLOCK_SYSTEM_TZ: {
/* validate current tz-epoch */
size_t lastTZEpoch = TzsetIfNecessary();
|
| ︙ | ︙ | |||
1423 1424 1425 1426 1427 1428 1429 |
}
dict = objv[1];
if (Tcl_DictObjGet(interp, dict, dataPtr->literals[LIT_LOCALSECONDS],
&secondsObj)!= TCL_OK) {
return TCL_ERROR;
}
if (secondsObj == NULL) {
| | | | 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 |
}
dict = objv[1];
if (Tcl_DictObjGet(interp, dict, dataPtr->literals[LIT_LOCALSECONDS],
&secondsObj)!= TCL_OK) {
return TCL_ERROR;
}
if (secondsObj == NULL) {
TclPrintfResult(interp,
"key \"localseconds\" not found in dictionary");
return TCL_ERROR;
}
if ((TclGetWideIntFromObj(interp, secondsObj, &fields.localSeconds) != TCL_OK)
|| (TclGetIntFromObj(interp, objv[3], &changeover) != TCL_OK)
|| ConvertLocalToUTC(dataPtr, interp, &fields, objv[2], changeover)) {
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
1650 1651 1652 1653 1654 1655 1656 |
{
Tcl_Obj *value = NULL;
if (Tcl_DictObjGet(interp, dict, key, &value) != TCL_OK) {
return TCL_ERROR;
}
if (value == NULL) {
| < | < | | 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 |
{
Tcl_Obj *value = NULL;
if (Tcl_DictObjGet(interp, dict, key, &value) != TCL_OK) {
return TCL_ERROR;
}
if (value == NULL) {
TclPrintfResult(interp, "expected key(s) not found in dictionary");
return TCL_ERROR;
}
return Tcl_GetIndexFromObj(interp, value, eras, "era", TCL_EXACT, storePtr);
}
static int
FetchIntField(
Tcl_Interp *interp,
Tcl_Obj *dict,
Tcl_Obj *key,
int *storePtr)
{
Tcl_Obj *value = NULL;
if (Tcl_DictObjGet(interp, dict, key, &value) != TCL_OK) {
return TCL_ERROR;
}
if (value == NULL) {
TclPrintfResult(interp, "expected key(s) not found in dictionary");
return TCL_ERROR;
}
return TclGetIntFromObj(interp, value, storePtr);
}
static int
ClockGetjuliandayfromerayearmonthdayObjCmd(
|
| ︙ | ︙ | |||
2114 2115 2116 2117 2118 2119 2120 |
/*
* If conversion fails, report an error.
*/
if (localErrno != 0
|| (fields->seconds == -1 && timeVal.tm_yday == -1)) {
| < | | 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 |
/*
* If conversion fails, report an error.
*/
if (localErrno != 0
|| (fields->seconds == -1 && timeVal.tm_yday == -1)) {
TclPrintfResult(interp, "time value too large/small to represent");
return TCL_ERROR;
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
|
| ︙ | ︙ | |||
2336 2337 2338 2339 2340 2341 2342 |
/*
* Use 'localtime' to determine local year, month, day, time of day.
*/
tock = (time_t) fields->seconds;
if ((Tcl_WideInt) tock != fields->seconds) {
| | | | | | | | 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 |
/*
* Use 'localtime' to determine local year, month, day, time of day.
*/
tock = (time_t) fields->seconds;
if ((Tcl_WideInt) tock != fields->seconds) {
TclPrintfResult(interp,
"number too large to represent as a Posix time");
TclSetErrorCode(interp, "CLOCK", "argTooLarge");
return TCL_ERROR;
}
TzsetIfNecessary();
timeVal = ThreadSafeLocalTime(&tock);
if (timeVal == NULL) {
TclPrintfResult(interp,
"localtime failed (clock value may be too "
"large/small to represent)");
TclSetErrorCode(interp, "CLOCK", "localtimeFailed");
return TCL_ERROR;
}
/*
* Fill in the date in 'fields' and use it to derive Julian Day.
*/
|
| ︙ | ︙ | |||
3324 3325 3326 3327 3328 3329 3330 |
goto badOptionMsg;
}
/* if already specified */
if (saw & (1 << optionIndex)) {
if (operation != CLC_OP_SCN && optionIndex == CLC_ARGS_BASE) {
goto badOptionMsg;
}
| | | < | 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 |
goto badOptionMsg;
}
/* if already specified */
if (saw & (1 << optionIndex)) {
if (operation != CLC_OP_SCN && optionIndex == CLC_ARGS_BASE) {
goto badOptionMsg;
}
TclPrintfResult(interp,
"bad option \"%s\": doubly present", TclGetString(objv[i]));
goto badOption;
}
switch (optionIndex) {
case CLC_ARGS_FORMAT:
if (operation == CLC_OP_ADD) {
goto badOptionMsg;
}
|
| ︙ | ︙ | |||
3376 3377 3378 3379 3380 3381 3382 |
/*
* Check options.
*/
if ((saw & (1 << CLC_ARGS_GMT))
&& (saw & (1 << CLC_ARGS_TIMEZONE))) {
| | | | | 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 |
/*
* Check options.
*/
if ((saw & (1 << CLC_ARGS_GMT))
&& (saw & (1 << CLC_ARGS_TIMEZONE))) {
TclPrintfResult(interp,
"cannot use -gmt and -timezone in same call");
TclSetErrorCode(interp, "CLOCK", "gmtWithTimezone");
return TCL_ERROR;
}
if (gmtFlag) {
opts->timezoneObj = dataPtr->literals[LIT_GMT];
} else if (opts->timezoneObj == NULL
|| TclGetString(opts->timezoneObj) == NULL
|| opts->timezoneObj->length == 0) {
|
| ︙ | ︙ | |||
3425 3426 3427 3428 3429 3430 3431 |
goto baseNow;
}
if (TclHasInternalRep(baseObj, &tclBignumType)) {
goto baseOverflow;
}
| | | | | 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 |
goto baseNow;
}
if (TclHasInternalRep(baseObj, &tclBignumType)) {
goto baseOverflow;
}
TclPrintfResult(interp,
"bad seconds \"%s\": must be now or integer",
TclGetString(baseObj));
i = baseIdx;
goto badOption;
}
/*
* Seconds could be an unsigned number that overflowed. Make sure
* that it isn't. Additionally it may be too complex to calculate
* julianday etc (forwards/backwards) by too large/small values, thus
|
| ︙ | ︙ | |||
3481 3482 3483 3484 3485 3486 3487 |
memcpy(&dataPtr->lastBase.date, date, ClockCacheableDateFieldsSize);
TclSetObjRef(dataPtr->lastBase.timezoneObj, opts->timezoneObj);
}
return TCL_OK;
badOptionMsg:
| | | < | | | 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 |
memcpy(&dataPtr->lastBase.date, date, ClockCacheableDateFieldsSize);
TclSetObjRef(dataPtr->lastBase.timezoneObj, opts->timezoneObj);
}
return TCL_OK;
badOptionMsg:
TclPrintfResult(interp,
"bad option \"%s\": must be %s", TclGetString(objv[i]), syntax);
badOption:
TclSetErrorCode(interp, "CLOCK", "badOption",
(i < objc) ? TclGetString(objv[i]) : (char *)NULL);
return TCL_ERROR;
}
/*----------------------------------------------------------------------
*
* ClockFormatObjCmd -- , clock format --
*
|
| ︙ | ︙ | |||
3530 3531 3532 3533 3534 3535 3536 |
int ret;
ClockFmtScnCmdArgs opts; /* Format, locale, timezone and base */
DateFormat dateFmt; /* Common structure used for formatting */
/* even number of arguments */
if ((objc & 1) == 1) {
Tcl_WrongNumArgs(interp, 0, objv, syntax);
| | | 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 |
int ret;
ClockFmtScnCmdArgs opts; /* Format, locale, timezone and base */
DateFormat dateFmt; /* Common structure used for formatting */
/* even number of arguments */
if ((objc & 1) == 1) {
Tcl_WrongNumArgs(interp, 0, objv, syntax);
TclSetErrorCode(interp, "CLOCK", "wrongNumArgs");
return TCL_ERROR;
}
memset(&dateFmt, 0, sizeof(dateFmt));
/*
* Extract values for the keywords.
|
| ︙ | ︙ | |||
3601 3602 3603 3604 3605 3606 3607 |
ClockFmtScnCmdArgs opts; /* Format, locale, timezone and base */
DateInfo yy; /* Common structure used for parsing */
DateInfo *info = &yy;
/* even number of arguments */
if ((objc & 1) == 1) {
Tcl_WrongNumArgs(interp, 0, objv, syntax);
| | | 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 |
ClockFmtScnCmdArgs opts; /* Format, locale, timezone and base */
DateInfo yy; /* Common structure used for parsing */
DateInfo *info = &yy;
/* even number of arguments */
if ((objc & 1) == 1) {
Tcl_WrongNumArgs(interp, 0, objv, syntax);
TclSetErrorCode(interp, "CLOCK", "wrongNumArgs");
return TCL_ERROR;
}
ClockInitDateInfo(&yy);
/*
* Extract values for the keywords.
|
| ︙ | ︙ | |||
3628 3629 3630 3631 3632 3633 3634 |
/* If free scan */
if (opts.formatObj == NULL) {
/* Use compiled version of FreeScan - */
/* [SB] TODO: Perhaps someday we'll localize the legacy code. Right now,
* it's not localized. */
if (opts.localeObj != NULL) {
| | | | | 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 |
/* If free scan */
if (opts.formatObj == NULL) {
/* Use compiled version of FreeScan - */
/* [SB] TODO: Perhaps someday we'll localize the legacy code. Right now,
* it's not localized. */
if (opts.localeObj != NULL) {
TclPrintfResult(interp,
"legacy [clock scan] does not support -locale");
TclSetErrorCode(interp, "CLOCK", "flagWithLegacyFormat");
ret = TCL_ERROR;
goto done;
}
ret = ClockFreeScan(&yy, objv[1], &opts);
} else {
/* Use compiled version of Scan - */
|
| ︙ | ︙ | |||
3722 3723 3724 3725 3726 3727 3728 |
}
/* some overflow checks */
if (info->flags & CLF_JULIANDAY) {
double curJDN = (double)yydate.julianDay
+ ((double)yySecondOfDay - SECONDS_PER_DAY/2) / SECONDS_PER_DAY;
if (curJDN > opts->dataPtr->maxJDN) {
| | | | | 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 |
}
/* some overflow checks */
if (info->flags & CLF_JULIANDAY) {
double curJDN = (double)yydate.julianDay
+ ((double)yySecondOfDay - SECONDS_PER_DAY/2) / SECONDS_PER_DAY;
if (curJDN > opts->dataPtr->maxJDN) {
TclPrintfResult(opts->interp,
"requested date too large to represent");
TclSetErrorCode(opts->interp, "CLOCK", "dateTooLarge");
return TCL_ERROR;
}
}
/* If seconds overflows the day (not valide case, or 24:00), increase days */
if (yySecondOfDay >= SECONDS_PER_DAY) {
yydate.julianDay += (yySecondOfDay / SECONDS_PER_DAY);
|
| ︙ | ︙ | |||
3955 3956 3957 3958 3959 3960 3961 |
goto error;
}
}
return TCL_OK;
error:
| < | | | 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 |
goto error;
}
}
return TCL_OK;
error:
TclPrintfResult(opts->interp, "unable to convert input string: %s", errMsg);
TclSetErrorCode(opts->interp, "CLOCK", "invInpStr", errCode);
return TCL_ERROR;
}
/*----------------------------------------------------------------------
*
* ClockFreeScan --
*
|
| ︙ | ︙ | |||
3999 4000 4001 4002 4003 4004 4005 |
* Notice that many yy-defines point to values in the "info" or "date"
* structure, e. g. yySecondOfDay -> info->date.secondOfDay or
* yyMonth -> info->date.month (same as yydate.month)
*/
yyInput = TclGetString(strObj);
if (TclClockFreeScan(interp, info) != TCL_OK) {
| | | | 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 |
* Notice that many yy-defines point to values in the "info" or "date"
* structure, e. g. yySecondOfDay -> info->date.secondOfDay or
* yyMonth -> info->date.month (same as yydate.month)
*/
yyInput = TclGetString(strObj);
if (TclClockFreeScan(interp, info) != TCL_OK) {
TclPrintfResult(interp,
"unable to convert date-time string \"%s\": %s",
TclGetString(strObj), Tcl_GetStringResult(interp));
goto done;
}
/*
* If the caller supplied a date in the string, update the date with
* the value. If the caller didn't specify a time with the date, default to
* midnight.
|
| ︙ | ︙ | |||
4396 4397 4398 4399 4400 4401 4402 |
int unitIndex; /* Index of an option. */
Tcl_Size i;
Tcl_WideInt offs;
/* even number of arguments */
if ((objc & 1) == 1) {
Tcl_WrongNumArgs(interp, 0, objv, syntax);
| | | 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 |
int unitIndex; /* Index of an option. */
Tcl_Size i;
Tcl_WideInt offs;
/* even number of arguments */
if ((objc & 1) == 1) {
Tcl_WrongNumArgs(interp, 0, objv, syntax);
TclSetErrorCode(interp, "CLOCK", "wrongNumArgs");
return TCL_ERROR;
}
ClockInitDateInfo(&yy);
/*
* Extract values for the keywords.
|
| ︙ | ︙ |
Changes to generic/tclClockFmt.c.
| ︙ | ︙ | |||
856 857 858 859 860 861 862 |
fss->objRefCount++;
ObjClockFmtScn(objPtr) = fss;
}
Tcl_MutexUnlock(&ClockFmtMutex);
if (fss == NULL && interp != NULL) {
| > | | | | 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 |
fss->objRefCount++;
ObjClockFmtScn(objPtr) = fss;
}
Tcl_MutexUnlock(&ClockFmtMutex);
if (fss == NULL && interp != NULL) {
TclPrintfResult(interp,
"retrieve clock format failed \"%s\"",
strFmt ? strFmt : "");
TclSetErrorCode(interp, "TCL", "EINVAL");
}
return fss;
}
/*
*----------------------------------------------------------------------
|
| ︙ | ︙ | |||
1603 1604 1605 1606 1607 1608 1609 |
return TCL_RETURN;
}
if (val == 0) {
val = 7;
}
if (val > 7) {
| < | | | 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 |
return TCL_RETURN;
}
if (val == 0) {
val = 7;
}
if (val > 7) {
TclPrintfResult(opts->interp, "day of week is greater than 7");
TclSetErrorCode(opts->interp, "CLOCK", "badDayOfWeek");
return TCL_ERROR;
}
info->date.dayOfWeek = val;
yyInput++;
return TCL_OK;
}
|
| ︙ | ︙ | |||
2698 2699 2700 2701 2702 2703 2704 |
ret = TCL_OK;
done:
return ret;
/* Error case reporting. */
overflow:
| | | | | | | | | | 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 |
ret = TCL_OK;
done:
return ret;
/* Error case reporting. */
overflow:
TclPrintfResult(opts->interp,
"integer value too large to represent");
TclSetErrorCode(opts->interp, "CLOCK", "dateTooLarge");
goto done;
not_match:
#if 1
TclPrintfResult(opts->interp,
"input string does not match supplied format");
#else
/* to debug where exactly scan breaks */
TclPrintfResult(opts->interp,
"input string \"%s\" does not match supplied format \"%s\","
" locale \"%s\" - token \"%s\"",
info->dateStart, HashEntry4FmtScn(fss)->key.string,
TclGetString(opts->localeObj),
tok && tok->tokWord.start ? tok->tokWord.start : "NULL");
#endif
TclSetErrorCode(opts->interp, "CLOCK", "badInputString");
goto done;
}
#define FrmResultIsAllocated(dateFmt) \
(dateFmt->resEnd - dateFmt->resMem > MIN_FMT_RESULT_BLOCK_ALLOC)
static inline int
|
| ︙ | ︙ |
Changes to generic/tclCmdAH.c.
| ︙ | ︙ | |||
182 183 184 185 186 187 188 |
varNamePtr = objv[2];
}
if (objc == 4) {
optionVarNamePtr = objv[3];
}
TclNRAddCallback(interp, CatchObjCmdCallback, INT2PTR(objc),
| | | 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
varNamePtr = objv[2];
}
if (objc == 4) {
optionVarNamePtr = objv[3];
}
TclNRAddCallback(interp, CatchObjCmdCallback, INT2PTR(objc),
varNamePtr, optionVarNamePtr);
/*
* TIP #280. Make invoking context available to caught script.
*/
return TclNREvalObjEx(interp, objv[1], 0, iPtr->cmdFramePtr, 1);
}
|
| ︙ | ︙ | |||
208 209 210 211 212 213 214 |
int rewind = iPtr->execEnvPtr->rewind;
/*
* We disable catch in interpreters where the limit has been exceeded.
*/
if (rewind || Tcl_LimitExceeded(interp)) {
| | | | 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
int rewind = iPtr->execEnvPtr->rewind;
/*
* We disable catch in interpreters where the limit has been exceeded.
*/
if (rewind || Tcl_LimitExceeded(interp)) {
TclPrintfErrorInfo(interp, "\n (\"catch\" body line %d)",
Tcl_GetErrorLine(interp));
return TCL_ERROR;
}
if (objc >= 3) {
if (NULL == Tcl_ObjSetVar2(interp, varNamePtr, NULL,
Tcl_GetObjResult(interp), TCL_LEAVE_ERR_MSG)) {
return TCL_ERROR;
|
| ︙ | ︙ | |||
286 287 288 289 290 291 292 |
Tcl_DString ds;
result = Tcl_UtfToExternalDStringEx(NULL, TCLFSENCODING, TclGetString(dir), -1, 0, &ds, NULL);
Tcl_DStringFree(&ds);
if (result == TCL_OK) {
result = Tcl_FSChdir(dir);
}
if (result != TCL_OK) {
| | | | 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
Tcl_DString ds;
result = Tcl_UtfToExternalDStringEx(NULL, TCLFSENCODING, TclGetString(dir), -1, 0, &ds, NULL);
Tcl_DStringFree(&ds);
if (result == TCL_OK) {
result = Tcl_FSChdir(dir);
}
if (result != TCL_OK) {
TclPrintfResult(interp,
"couldn't change working directory to \"%s\": %s",
TclGetString(dir), Tcl_PosixError(interp));
result = TCL_ERROR;
}
}
if (objc != 2) {
Tcl_DecrRefCount(dir);
}
return result;
|
| ︙ | ︙ | |||
721 722 723 724 725 726 727 |
if (objc == 1) {
Tcl_SetObjResult(interp, Tcl_GetEncodingSearchPath());
return TCL_OK;
}
dirListObj = objv[1];
if (Tcl_SetEncodingSearchPath(dirListObj) == TCL_ERROR) {
| | | | < | 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 |
if (objc == 1) {
Tcl_SetObjResult(interp, Tcl_GetEncodingSearchPath());
return TCL_OK;
}
dirListObj = objv[1];
if (Tcl_SetEncodingSearchPath(dirListObj) == TCL_ERROR) {
TclPrintfResult(interp,
"expected directory list but got \"%s\"",
TclGetString(dirListObj));
TclSetErrorCode(interp, "TCL", "OPERATION", "ENCODING", "BADPATH");
return TCL_ERROR;
}
Tcl_SetObjResult(interp, dirListObj);
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
897 898 899 900 901 902 903 |
static int
EvalCmdErrMsg(
TCL_UNUSED(void **),
Tcl_Interp *interp,
int result)
{
if (result == TCL_ERROR) {
| | | | 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 |
static int
EvalCmdErrMsg(
TCL_UNUSED(void **),
Tcl_Interp *interp,
int result)
{
if (result == TCL_ERROR) {
TclPrintfErrorInfo(interp, "\n (\"eval\" body line %d)",
Tcl_GetErrorLine(interp));
}
return result;
}
int
Tcl_EvalObjCmd(
void *clientData,
|
| ︙ | ︙ | |||
951 952 953 954 955 956 957 |
*
* TIP #280. Make invoking context available to eval'd script, done
* with the default values.
*/
objPtr = Tcl_ConcatObj(objc-1, objv+1);
}
| | | 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 |
*
* TIP #280. Make invoking context available to eval'd script, done
* with the default values.
*/
objPtr = Tcl_ConcatObj(objc-1, objv+1);
}
TclNRAddCallback(interp, EvalCmdErrMsg);
return TclNREvalObjEx(interp, objPtr, 0, invoker, word);
}
/*
*----------------------------------------------------------------------
*
* Tcl_ExitObjCmd --
|
| ︙ | ︙ | |||
1047 1048 1049 1050 1051 1052 1053 |
return TCL_ERROR;
}
TclNewObj(resultPtr);
Tcl_IncrRefCount(resultPtr);
if (objc == 2) {
objPtr = objv[1];
| | | | 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 |
return TCL_ERROR;
}
TclNewObj(resultPtr);
Tcl_IncrRefCount(resultPtr);
if (objc == 2) {
objPtr = objv[1];
TclNRAddCallback(interp, ExprCallback, resultPtr);
} else {
objPtr = Tcl_ConcatObj(objc-1, objv+1);
TclNRAddCallback(interp, ExprCallback, resultPtr, objPtr);
}
return Tcl_NRExprObj(interp, objPtr, resultPtr);
}
static int
ExprCallback(
|
| ︙ | ︙ | |||
1187 1188 1189 1190 1191 1192 1193 |
}
if (GetStatBuf(interp, objv[1], Tcl_FSStat, &buf) != TCL_OK) {
return TCL_ERROR;
}
#if defined(_WIN32)
/* We use a value of 0 to indicate the access time not available */
if (Tcl_GetAccessTimeFromStat(&buf) == 0) {
| | | | | | 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 |
}
if (GetStatBuf(interp, objv[1], Tcl_FSStat, &buf) != TCL_OK) {
return TCL_ERROR;
}
#if defined(_WIN32)
/* We use a value of 0 to indicate the access time not available */
if (Tcl_GetAccessTimeFromStat(&buf) == 0) {
TclPrintfResult(interp,
"could not get access time for file \"%s\"",
TclGetString(objv[1]));
return TCL_ERROR;
}
#endif
if (objc == 3) {
/*
* Need separate variable for reading longs from an object on 64-bit
* platforms. [Bug 698146]
*/
Tcl_WideInt newTime;
if (TclGetWideIntFromObj(interp, objv[2], &newTime) != TCL_OK) {
return TCL_ERROR;
}
tval.actime = newTime;
tval.modtime = Tcl_GetModificationTimeFromStat(&buf);
if (Tcl_FSUtime(objv[1], &tval) != 0) {
TclPrintfResult(interp,
"could not set access time for file \"%s\": %s",
TclGetString(objv[1]), Tcl_PosixError(interp));
return TCL_ERROR;
}
/*
* Do another stat to ensure that the we return the new recognized
* atime - hopefully the same as the one we sent in. However, fs's
* like FAT don't even know what atime is.
|
| ︙ | ︙ | |||
1269 1270 1271 1272 1273 1274 1275 |
}
if (GetStatBuf(interp, objv[1], Tcl_FSStat, &buf) != TCL_OK) {
return TCL_ERROR;
}
#if defined(_WIN32)
/* We use a value of 0 to indicate the modification time not available */
if (Tcl_GetModificationTimeFromStat(&buf) == 0) {
| | | | | | 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 |
}
if (GetStatBuf(interp, objv[1], Tcl_FSStat, &buf) != TCL_OK) {
return TCL_ERROR;
}
#if defined(_WIN32)
/* We use a value of 0 to indicate the modification time not available */
if (Tcl_GetModificationTimeFromStat(&buf) == 0) {
TclPrintfResult(interp,
"could not get modification time for file \"%s\"",
TclGetString(objv[1]));
return TCL_ERROR;
}
#endif
if (objc == 3) {
/*
* Need separate variable for reading longs from an object on 64-bit
* platforms. [Bug 698146]
*/
Tcl_WideInt newTime;
if (TclGetWideIntFromObj(interp, objv[2], &newTime) != TCL_OK) {
return TCL_ERROR;
}
tval.actime = Tcl_GetAccessTimeFromStat(&buf);
tval.modtime = newTime;
if (Tcl_FSUtime(objv[1], &tval) != 0) {
TclPrintfResult(interp,
"could not set modification time for file \"%s\": %s",
TclGetString(objv[1]), Tcl_PosixError(interp));
return TCL_ERROR;
}
/*
* Do another stat to ensure that the we return the new recognized
* mtime - hopefully the same as the one we sent in.
*/
|
| ︙ | ︙ | |||
1916 1917 1918 1919 1920 1921 1922 |
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "name");
return TCL_ERROR;
}
fsInfo = Tcl_FSFileSystemInfo(objv[1]);
if (fsInfo == NULL) {
| | | | | 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 |
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "name");
return TCL_ERROR;
}
fsInfo = Tcl_FSFileSystemInfo(objv[1]);
if (fsInfo == NULL) {
TclPrintfResult(interp, "unrecognised path");
TclSetErrorCode(interp, "TCL", "LOOKUP", "FILESYSTEM",
TclGetString(objv[1]));
return TCL_ERROR;
}
Tcl_SetObjResult(interp, fsInfo);
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
2064 2065 2066 2067 2068 2069 2070 |
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "name");
return TCL_ERROR;
}
res = Tcl_FSSplitPath(objv[1], (Tcl_Size *)NULL);
if (res == NULL) {
| | | | < | 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 |
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "name");
return TCL_ERROR;
}
res = Tcl_FSSplitPath(objv[1], (Tcl_Size *)NULL);
if (res == NULL) {
TclPrintfResult(interp,
"could not read \"%s\": no such file or directory",
TclGetString(objv[1]));
TclSetErrorCode(interp, "TCL", "OPERATION", "PATHSPLIT", "NONESUCH");
return TCL_ERROR;
}
Tcl_SetObjResult(interp, res);
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
2167 2168 2169 2170 2171 2172 2173 |
break;
}
Tcl_SetObjResult(interp, Tcl_NewStringObj(separator, 1));
} else {
Tcl_Obj *separatorObj = Tcl_FSPathSeparator(objv[1]);
if (separatorObj == NULL) {
| < | | | | 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 |
break;
}
Tcl_SetObjResult(interp, Tcl_NewStringObj(separator, 1));
} else {
Tcl_Obj *separatorObj = Tcl_FSPathSeparator(objv[1]);
if (separatorObj == NULL) {
TclPrintfResult(interp, "unrecognised path");
TclSetErrorCode(interp, "TCL", "LOOKUP", "FILESYSTEM",
TclGetString(objv[1]));
return TCL_ERROR;
}
Tcl_SetObjResult(interp, separatorObj);
}
return TCL_OK;
}
|
| ︙ | ︙ | |||
2300 2301 2302 2303 2304 2305 2306 |
} else {
status = statProc(pathPtr, statPtr);
}
Tcl_DStringFree(&ds);
if (status < 0) {
if (interp != NULL) {
| < | | | 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 |
} else {
status = statProc(pathPtr, statPtr);
}
Tcl_DStringFree(&ds);
if (status < 0) {
if (interp != NULL) {
TclPrintfResult(interp, "could not read \"%s\": %s",
TclGetString(pathPtr), Tcl_PosixError(interp));
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
2342 2343 2344 2345 2346 2347 2348 |
{
Tcl_Obj *field, *value, *result;
unsigned short mode;
if (varName == NULL) {
TclNewObj(result);
Tcl_IncrRefCount(result);
| | | < < | 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 |
{
Tcl_Obj *field, *value, *result;
unsigned short mode;
if (varName == NULL) {
TclNewObj(result);
Tcl_IncrRefCount(result);
#define DOBJPUT(key, objValue) \
Tcl_DictObjPut(NULL, result, TclNewString(key), (objValue))
DOBJPUT("dev", Tcl_NewWideIntObj((long)statPtr->st_dev));
DOBJPUT("ino", Tcl_NewWideIntObj((Tcl_WideInt)statPtr->st_ino));
DOBJPUT("nlink", Tcl_NewWideIntObj((long)statPtr->st_nlink));
DOBJPUT("uid", Tcl_NewWideIntObj((long)statPtr->st_uid));
DOBJPUT("gid", Tcl_NewWideIntObj((long)statPtr->st_gid));
DOBJPUT("size", Tcl_NewWideIntObj((Tcl_WideInt)statPtr->st_size));
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
|
| ︙ | ︙ | |||
2535 2536 2537 2538 2539 2540 2541 |
TclSmallAllocEx(interp, sizeof(ForIterData), iterPtr);
iterPtr->cond = objv[2];
iterPtr->body = objv[4];
iterPtr->next = objv[3];
iterPtr->msg = "\n (\"for\" body line %d)";
iterPtr->word = 4;
| | | 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 |
TclSmallAllocEx(interp, sizeof(ForIterData), iterPtr);
iterPtr->cond = objv[2];
iterPtr->body = objv[4];
iterPtr->next = objv[3];
iterPtr->msg = "\n (\"for\" body line %d)";
iterPtr->word = 4;
TclNRAddCallback(interp, ForSetupCallback, iterPtr);
/*
* TIP #280. Make invoking context available to initial script.
*/
return TclNREvalObjEx(interp, objv[1], 0, iPtr->cmdFramePtr, 1);
}
|
| ︙ | ︙ | |||
2559 2560 2561 2562 2563 2564 2565 |
if (result != TCL_OK) {
if (result == TCL_ERROR) {
Tcl_AddErrorInfo(interp, "\n (\"for\" initial command)");
}
TclSmallFreeEx(interp, iterPtr);
return result;
}
| | | 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 |
if (result != TCL_OK) {
if (result == TCL_ERROR) {
Tcl_AddErrorInfo(interp, "\n (\"for\" initial command)");
}
TclSmallFreeEx(interp, iterPtr);
return result;
}
TclNRAddCallback(interp, TclNRForIterCallback, iterPtr);
return TCL_OK;
}
int
TclNRForIterCallback(
void *data[],
Tcl_Interp *interp,
|
| ︙ | ︙ | |||
2583 2584 2585 2586 2587 2588 2589 | * We need to reset the result before evaluating the expression. * Otherwise, any error message will be appended to the result of the * last evaluation. */ Tcl_ResetResult(interp); TclNewObj(boolObj); | | < < | | 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 |
* We need to reset the result before evaluating the expression.
* Otherwise, any error message will be appended to the result of the
* last evaluation.
*/
Tcl_ResetResult(interp);
TclNewObj(boolObj);
TclNRAddCallback(interp, ForCondCallback, iterPtr, boolObj);
return Tcl_NRExprObj(interp, iterPtr->cond, boolObj);
case TCL_BREAK:
result = TCL_OK;
Tcl_ResetResult(interp);
break;
case TCL_ERROR:
TclPrintfErrorInfo(interp, iterPtr->msg, Tcl_GetErrorLine(interp));
}
TclSmallFreeEx(interp, iterPtr);
return result;
}
static int
ForCondCallback(
|
| ︙ | ︙ | |||
2623 2624 2625 2626 2627 2628 2629 |
return TCL_ERROR;
}
Tcl_DecrRefCount(boolObj);
if (value) {
/* TIP #280. */
if (iterPtr->next) {
| | < | < | < | | | 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 |
return TCL_ERROR;
}
Tcl_DecrRefCount(boolObj);
if (value) {
/* TIP #280. */
if (iterPtr->next) {
TclNRAddCallback(interp, ForNextCallback, iterPtr);
} else {
TclNRAddCallback(interp, TclNRForIterCallback, iterPtr);
}
return TclNREvalObjEx(interp, iterPtr->body, 0, iPtr->cmdFramePtr,
iterPtr->word);
}
TclSmallFreeEx(interp, iterPtr);
return result;
}
static int
ForNextCallback(
void *data[],
Tcl_Interp *interp,
int result)
{
Interp *iPtr = (Interp *) interp;
ForIterData *iterPtr = (ForIterData *)data[0];
Tcl_Obj *next = iterPtr->next;
if ((result == TCL_OK) || (result == TCL_CONTINUE)) {
TclNRAddCallback(interp, ForPostNextCallback, iterPtr);
/*
* TIP #280. Make invoking context available to next script.
*/
return TclNREvalObjEx(interp, next, 0, iPtr->cmdFramePtr, 3);
}
TclNRAddCallback(interp, TclNRForIterCallback, iterPtr);
return result;
}
static int
ForPostNextCallback(
void *data[],
Tcl_Interp *interp,
int result)
{
ForIterData *iterPtr = (ForIterData *)data[0];
if ((result != TCL_BREAK) && (result != TCL_OK)) {
if (result == TCL_ERROR) {
Tcl_AddErrorInfo(interp, "\n (\"for\" loop-end command)");
TclSmallFreeEx(interp, iterPtr);
}
return result;
}
TclNRAddCallback(interp, TclNRForIterCallback, iterPtr);
return result;
}
/*
*----------------------------------------------------------------------
*
* Tcl_ForeachObjCmd, TclNRForeachCmd, EachloopCmd --
|
| ︙ | ︙ | |||
2809 2810 2811 2812 2813 2814 2815 |
/* Variables */
statePtr->vCopyList[i] = TclListObjCopy(interp, objv[1+i*2]);
if (statePtr->vCopyList[i] == NULL) {
result = TCL_ERROR;
goto done;
}
result = TclListObjLength(interp, statePtr->vCopyList[i],
| | | | | | | | | | 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 |
/* Variables */
statePtr->vCopyList[i] = TclListObjCopy(interp, objv[1+i*2]);
if (statePtr->vCopyList[i] == NULL) {
result = TCL_ERROR;
goto done;
}
result = TclListObjLength(interp, statePtr->vCopyList[i],
&statePtr->varcList[i]);
if (result != TCL_OK) {
result = TCL_ERROR;
goto done;
}
if (statePtr->varcList[i] < 1) {
TclPrintfResult(interp,
"%s varlist is empty",
(statePtr->resultList != NULL ? "lmap" : "foreach"));
TclSetErrorCode(interp, "TCL", "OPERATION",
(statePtr->resultList != NULL ? "LMAP" : "FOREACH"),
"NEEDVARS");
result = TCL_ERROR;
goto done;
}
TclListObjGetElements(NULL, statePtr->vCopyList[i],
&statePtr->varcList[i], &statePtr->varvList[i]);
/* Values */
if (TclObjTypeHasProc(objv[2+i*2],indexProc)) {
/* Special case for AbstractList */
statePtr->aCopyList[i] = Tcl_DuplicateObj(objv[2+i*2]);
if (statePtr->aCopyList[i] == NULL) {
result = TCL_ERROR;
|
| ︙ | ︙ | |||
2871 2872 2873 2874 2875 2876 2877 |
if (statePtr->maxj > 0) {
result = ForeachAssignments(interp, statePtr);
if (result == TCL_ERROR) {
goto done;
}
| | | 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 |
if (statePtr->maxj > 0) {
result = ForeachAssignments(interp, statePtr);
if (result == TCL_ERROR) {
goto done;
}
TclNRAddCallback(interp, ForeachLoopStep, statePtr);
return TclNREvalObjEx(interp, objv[objc-1], 0,
((Interp *) interp)->cmdFramePtr, objc-1);
}
/*
* This cleanup stage is only used when an error occurs during setup or if
* there is no work to do.
|
| ︙ | ︙ | |||
2922 2923 2924 2925 2926 2927 2928 |
}
}
break;
case TCL_BREAK:
result = TCL_OK;
goto finish;
case TCL_ERROR:
| < | | | | 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 |
}
}
break;
case TCL_BREAK:
result = TCL_OK;
goto finish;
case TCL_ERROR:
TclPrintfErrorInfo(interp, "\n (\"%s\" body line %d)",
(statePtr->resultList != NULL ? "lmap" : "foreach"),
Tcl_GetErrorLine(interp));
default:
goto done;
}
/*
* Test if there is work still to be done. If so, do the next round of
* variable assignments, reschedule ourselves and run the body again.
*/
if (statePtr->maxj > ++statePtr->j) {
result = ForeachAssignments(interp, statePtr);
if (result == TCL_ERROR) {
goto done;
}
TclNRAddCallback(interp, ForeachLoopStep, statePtr);
return TclNREvalObjEx(interp, statePtr->bodyPtr, 0,
((Interp *) interp)->cmdFramePtr, statePtr->bodyIdx);
}
/*
* We're done. Tidy up our work space and finish off.
*/
|
| ︙ | ︙ | |||
2985 2986 2987 2988 2989 2990 2991 |
TclObjTypeHasProc(statePtr->aCopyList[i],indexProc) != NULL;
for (v=0 ; v<statePtr->varcList[i] ; v++) {
k = statePtr->index[i]++;
if (k < statePtr->argcList[i]) {
if (isAbstractList) {
if (TclObjTypeIndex(interp, statePtr->aCopyList[i], k, &valuePtr) != TCL_OK) {
| | | | | | 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 |
TclObjTypeHasProc(statePtr->aCopyList[i],indexProc) != NULL;
for (v=0 ; v<statePtr->varcList[i] ; v++) {
k = statePtr->index[i]++;
if (k < statePtr->argcList[i]) {
if (isAbstractList) {
if (TclObjTypeIndex(interp, statePtr->aCopyList[i], k, &valuePtr) != TCL_OK) {
TclPrintfErrorInfo(interp,
"\n (setting %s loop variable \"%s\")",
(statePtr->resultList != NULL ? "lmap" : "foreach"),
TclGetString(statePtr->varvList[i][v]));
return TCL_ERROR;
}
} else {
valuePtr = statePtr->argvList[i][k];
}
} else {
TclNewObj(valuePtr); /* Empty string */
}
varValuePtr = Tcl_ObjSetVar2(interp, statePtr->varvList[i][v],
NULL, valuePtr, TCL_LEAVE_ERR_MSG);
if (varValuePtr == NULL) {
TclPrintfErrorInfo(interp,
"\n (setting %s loop variable \"%s\")",
(statePtr->resultList != NULL ? "lmap" : "foreach"),
TclGetString(statePtr->varvList[i][v]));
return TCL_ERROR;
}
}
}
return TCL_OK;
}
|
| ︙ | ︙ |
Changes to generic/tclCmdIL.c.
| ︙ | ︙ | |||
217 218 219 220 221 222 223 |
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
Tcl_Obj *boolObj;
if (objc <= 1) {
| | | | | | | 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
Tcl_Obj *boolObj;
if (objc <= 1) {
TclPrintfResult(interp,
"wrong # args: no expression after \"%s\" argument",
TclGetString(objv[0]));
TclSetErrorCode(interp, "TCL", "WRONGARGS");
return TCL_ERROR;
}
/*
* At this point, objv[1] refers to the main expression to test. The
* arguments after the expression must be "then" (optional) and a script
* to execute if the expression is true.
*/
TclNewObj(boolObj);
TclNRAddCallback(interp, IfConditionCallback, INT2PTR(objc), objv,
INT2PTR(1), boolObj);
return Tcl_NRExprObj(interp, objv[1], boolObj);
}
static int
IfConditionCallback(
void *data[],
Tcl_Interp *interp,
|
| ︙ | ︙ | |||
308 309 310 311 312 313 314 |
* At this point in the loop, objv and objc refer to an expression to
* test, either for the main expression or an expression following an
* "elseif". The arguments after the expression must be "then"
* (optional) and a script to execute if the expression is true.
*/
if (i >= objc) {
| | | | | | | < | | | | | 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
* At this point in the loop, objv and objc refer to an expression to
* test, either for the main expression or an expression following an
* "elseif". The arguments after the expression must be "then"
* (optional) and a script to execute if the expression is true.
*/
if (i >= objc) {
TclPrintfResult(interp,
"wrong # args: no expression after \"%s\" argument",
clause);
TclSetErrorCode(interp, "TCL", "WRONGARGS");
return TCL_ERROR;
}
if (!thenScriptIndex) {
TclNewObj(boolObj);
TclNRAddCallback(interp, IfConditionCallback, data[0], data[1],
INT2PTR(i), boolObj);
return Tcl_NRExprObj(interp, objv[i], boolObj);
}
}
/*
* Couldn't find a "then" or "elseif" clause to execute. Check now for an
* "else" clause. We know that there's at least one more argument when we
* get here.
*/
if (strcmp(clause, "else") == 0) {
i++;
if (i >= objc) {
goto missingScript;
}
}
if (i < objc - 1) {
TclPrintfResult(interp,
"wrong # args: extra words after \"else\" clause in \"if\" command");
TclSetErrorCode(interp, "TCL", "WRONGARGS");
return TCL_ERROR;
}
if (thenScriptIndex) {
/*
* TIP #280. Make invoking context available to branch/else.
*/
return TclNREvalObjEx(interp, objv[thenScriptIndex], 0,
iPtr->cmdFramePtr, thenScriptIndex);
}
return TclNREvalObjEx(interp, objv[i], 0, iPtr->cmdFramePtr, i);
missingScript:
TclPrintfResult(interp,
"wrong # args: no script following \"%s\" argument",
TclGetString(objv[i - 1]));
TclSetErrorCode(interp, "TCL", "WRONGARGS");
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* Tcl_IncrObjCmd --
|
| ︙ | ︙ | |||
482 483 484 485 486 487 488 |
Tcl_WrongNumArgs(interp, 1, objv, "procname");
return TCL_ERROR;
}
name = TclGetString(objv[1]);
procPtr = TclFindProc(iPtr, name);
if (procPtr == NULL) {
| < | | | 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
Tcl_WrongNumArgs(interp, 1, objv, "procname");
return TCL_ERROR;
}
name = TclGetString(objv[1]);
procPtr = TclFindProc(iPtr, name);
if (procPtr == NULL) {
TclPrintfResult(interp, "\"%s\" isn't a procedure", name);
TclSetErrorCode(interp, "TCL", "LOOKUP", "PROCEDURE", name);
return TCL_ERROR;
}
/*
* Build a return list containing the arguments.
*/
|
| ︙ | ︙ | |||
544 545 546 547 548 549 550 |
Tcl_WrongNumArgs(interp, 1, objv, "procname");
return TCL_ERROR;
}
name = TclGetString(objv[1]);
procPtr = TclFindProc(iPtr, name);
if (procPtr == NULL) {
| < | | | 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 |
Tcl_WrongNumArgs(interp, 1, objv, "procname");
return TCL_ERROR;
}
name = TclGetString(objv[1]);
procPtr = TclFindProc(iPtr, name);
if (procPtr == NULL) {
TclPrintfResult(interp, "\"%s\" isn't a procedure", name);
TclSetErrorCode(interp, "TCL", "LOOKUP", "PROCEDURE", name);
return TCL_ERROR;
}
/*
* Here we used to return procPtr->bodyPtr, except when the body was
* bytecompiled - in that case, the return was a copy of the body's string
* rep. In order to better isolate the implementation details of the
|
| ︙ | ︙ | |||
964 965 966 967 968 969 970 |
}
procName = TclGetString(objv[1]);
argName = TclGetString(objv[2]);
procPtr = TclFindProc(iPtr, procName);
if (procPtr == NULL) {
| < | | < | 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 |
}
procName = TclGetString(objv[1]);
argName = TclGetString(objv[2]);
procPtr = TclFindProc(iPtr, procName);
if (procPtr == NULL) {
TclPrintfResult(interp, "\"%s\" isn't a procedure", procName);
TclSetErrorCode(interp, "TCL", "LOOKUP", "PROCEDURE", procName);
return TCL_ERROR;
}
for (localPtr = procPtr->firstLocalPtr; localPtr != NULL;
localPtr = localPtr->nextPtr) {
if (TclIsVarArgument(localPtr)
&& (strcmp(argName, localPtr->name) == 0)) {
|
| ︙ | ︙ | |||
997 998 999 1000 1001 1002 1003 |
}
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(0));
}
return TCL_OK;
}
}
| | | | | 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 |
}
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(0));
}
return TCL_OK;
}
}
TclPrintfResult(interp,
"procedure \"%s\" doesn't have an argument \"%s\"",
procName, argName);
TclSetErrorCode(interp, "TCL", "LOOKUP", "ARGUMENT", argName);
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* InfoErrorStackCmd --
|
| ︙ | ︙ | |||
1180 1181 1182 1183 1184 1185 1186 |
if (TclGetIntFromObj(interp, objv[1], &level) != TCL_OK) {
code = TCL_ERROR;
goto done;
}
if ((level > topLevel) || (level <= - topLevel)) {
levelError:
| < | | < | 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 |
if (TclGetIntFromObj(interp, objv[1], &level) != TCL_OK) {
code = TCL_ERROR;
goto done;
}
if ((level > topLevel) || (level <= - topLevel)) {
levelError:
TclPrintfResult(interp, "bad level \"%s\"", TclGetString(objv[1]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "LEVEL", TclGetString(objv[1]));
code = TCL_ERROR;
goto done;
}
/*
* Let us convert to relative so that we know how many levels to go back
*/
|
| ︙ | ︙ | |||
1478 1479 1480 1481 1482 1483 1484 |
int code;
if (objc > 2) {
Tcl_WrongNumArgs(interp, 1, objv, "?pattern?");
return TCL_ERROR;
}
| | | | 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 |
int code;
if (objc > 2) {
Tcl_WrongNumArgs(interp, 1, objv, "?pattern?");
return TCL_ERROR;
}
script = TclNewString(
" ::apply [::list {{pattern *}} {\n"
" ::set cmds {}\n"
" ::foreach cmd [::info commands ::tcl::mathfunc::$pattern] {\n"
" ::lappend cmds [::namespace tail $cmd]\n"
" }\n"
" ::foreach cmd [::info commands tcl::mathfunc::$pattern] {\n"
" ::set cmd [::namespace tail $cmd]\n"
" ::if {$cmd ni $cmds} {\n"
" ::lappend cmds $cmd\n"
" }\n"
" }\n"
" ::return $cmds\n"
" } [::namespace current]] ");
if (objc == 2) {
Tcl_Obj *arg = Tcl_NewListObj(1, &(objv[1]));
Tcl_AppendObjToObj(script, arg);
Tcl_DecrRefCount(arg);
}
|
| ︙ | ︙ | |||
1548 1549 1550 1551 1552 1553 1554 |
name = Tcl_GetHostName();
if (name) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(name, -1));
return TCL_OK;
}
| < | | | 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 |
name = Tcl_GetHostName();
if (name) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(name, -1));
return TCL_OK;
}
TclPrintfResult(interp, "unable to determine name of host");
TclSetErrorCode(interp, "TCL", "OPERATION", "HOSTNAME", "UNKNOWN");
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* InfoLevelCmd --
|
| ︙ | ︙ | |||
1620 1621 1622 1623 1624 1625 1626 |
return TCL_OK;
}
Tcl_WrongNumArgs(interp, 1, objv, "?number?");
return TCL_ERROR;
levelError:
| < | | < | 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 |
return TCL_OK;
}
Tcl_WrongNumArgs(interp, 1, objv, "?number?");
return TCL_ERROR;
levelError:
TclPrintfResult(interp, "bad level \"%s\"", TclGetString(objv[1]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "LEVEL", TclGetString(objv[1]));
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* InfoLibraryCmd --
|
| ︙ | ︙ | |||
1668 1669 1670 1671 1672 1673 1674 |
libDirName = Tcl_GetVar2(interp, "tcl_library", NULL, TCL_GLOBAL_ONLY);
if (libDirName != NULL) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(libDirName, -1));
return TCL_OK;
}
| < | | | 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 |
libDirName = Tcl_GetVar2(interp, "tcl_library", NULL, TCL_GLOBAL_ONLY);
if (libDirName != NULL) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(libDirName, -1));
return TCL_OK;
}
TclPrintfResult(interp, "no library has been specified for Tcl");
TclSetErrorCode(interp, "TCL", "LOOKUP", "VARIABLE", "tcl_library");
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* InfoLoadedCmd --
|
| ︙ | ︙ | |||
2122 2123 2124 2125 2126 2127 2128 |
/*
* There's one special case: safe child interpreters can't see aliases as
* aliases as they're part of the security mechanisms.
*/
if (Tcl_IsSafe(interp)
&& (((Command *) command)->objProc == TclAliasObjCmd)) {
| | | | | 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 |
/*
* There's one special case: safe child interpreters can't see aliases as
* aliases as they're part of the security mechanisms.
*/
if (Tcl_IsSafe(interp)
&& (((Command *) command)->objProc == TclAliasObjCmd)) {
Tcl_SetObjResult(interp, TclNewString("native"));
} else {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
TclGetCommandTypeName(command), TCL_AUTO_LENGTH));
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
2199 2200 2201 2202 2203 2204 2205 |
return TCL_ERROR;
}
Tcl_SetObjResult(interp, elemObj);
}
return TCL_OK;
}
| | | 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 |
return TCL_ERROR;
}
Tcl_SetObjResult(interp, elemObj);
}
return TCL_OK;
}
joinObjPtr = (objc == 2) ? TclNewString(" ") : objv[2];
Tcl_IncrRefCount(joinObjPtr);
(void)TclGetStringFromObj(joinObjPtr, &length);
if (length == 0) {
resObjPtr = TclStringCat(interp, listLen, elemPtrs, 0);
} else {
Tcl_Size i;
|
| ︙ | ︙ | |||
2633 2634 2635 2636 2637 2638 2639 |
* First, extract the element to be returned.
* TclLindexFlat adds a ref count which is handled.
*/
if (objc == 2) {
if (!listLen) {
/* empty list, throw the same error as with index "end" */
| < | | | | 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 |
* First, extract the element to be returned.
* TclLindexFlat adds a ref count which is handled.
*/
if (objc == 2) {
if (!listLen) {
/* empty list, throw the same error as with index "end" */
TclPrintfResult(interp, "index \"end\" out of range");
TclSetErrorCode(interp, "TCL", "VALUE", "INDEX", "OUTOFRANGE");
return TCL_ERROR;
}
result = Tcl_ListObjIndex(interp, listPtr, (listLen - 1), &elemPtr);
if (result != TCL_OK) {
return result;
}
Tcl_IncrRefCount(elemPtr);
} else {
elemPtr = TclLindexFlat(interp, listPtr, objc-2, objv+2);
|
| ︙ | ︙ | |||
2954 2955 2956 2957 2958 2959 2960 |
Tcl_WrongNumArgs(interp, 1, objv, "count ?value ...?");
return TCL_ERROR;
}
if (TCL_OK != TclGetWideIntFromObj(interp, objv[1], &elementCount)) {
return TCL_ERROR;
}
if (elementCount < 0) {
| | | > | < | | > | | 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 |
Tcl_WrongNumArgs(interp, 1, objv, "count ?value ...?");
return TCL_ERROR;
}
if (TCL_OK != TclGetWideIntFromObj(interp, objv[1], &elementCount)) {
return TCL_ERROR;
}
if (elementCount < 0) {
TclPrintfResult(interp,
"bad count \"%" TCL_LL_MODIFIER "d\": must be integer >= 0",
elementCount);
TclSetErrorCode(interp, "TCL", "OPERATION", "LREPEAT", "NEGARG");
return TCL_ERROR;
}
/*
* Skip forward to the interesting arguments now we've finished parsing.
*/
objc -= 2;
objv += 2;
/* Final sanity check. Do not exceed limits on max list length. */
if (elementCount && objc > LIST_MAX/elementCount) {
TclPrintfResult(interp,
"max length of a Tcl list (%" TCL_SIZE_MODIFIER "d elements) exceeded",
LIST_MAX);
TclSetErrorCode(interp, "TCL", "MEMORY");
return TCL_ERROR;
}
totalElems = objc * elementCount;
/*
* Get an empty list object that is allocated large enough to hold each
* init value elementCount times.
|
| ︙ | ︙ | |||
3389 3390 3391 3392 3393 3394 3395 |
*/
if (startPtr != NULL) {
Tcl_DecrRefCount(startPtr);
startPtr = NULL;
}
if (i > objc-4) {
| < | | | | < | < | | | | | < | | 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 |
*/
if (startPtr != NULL) {
Tcl_DecrRefCount(startPtr);
startPtr = NULL;
}
if (i > objc-4) {
TclPrintfResult(interp, "missing starting index");
TclSetErrorCode(interp, "TCL", "ARGUMENT", "MISSING");
result = TCL_ERROR;
goto done;
}
i++;
if (objv[i] == objv[objc - 2]) {
/*
* Take copy to prevent shimmering problems. Note that it does
* not matter if the index obj is also a component of the list
* being searched. We only need to copy where the list and the
* index are one-and-the-same.
*/
startPtr = Tcl_DuplicateObj(objv[i]);
} else {
startPtr = objv[i];
}
Tcl_IncrRefCount(startPtr);
break;
case LSEARCH_STRIDE: /* -stride */
if (i > objc-4) {
TclPrintfResult(interp,
"\"-stride\" option must be followed by stride length");
TclSetErrorCode(interp, "TCL", "ARGUMENT", "MISSING");
result = TCL_ERROR;
goto done;
}
if (TclGetWideIntFromObj(interp, objv[i+1], &wide) != TCL_OK) {
result = TCL_ERROR;
goto done;
}
if (wide < 1) {
TclPrintfResult(interp, "stride length must be at least 1");
TclSetErrorCode(interp, "TCL", "OPERATION", "LSEARCH",
"BADSTRIDE");
result = TCL_ERROR;
goto done;
}
groupSize = wide;
i++;
break;
case LSEARCH_INDEX: { /* -index */
Tcl_Obj **indices;
Tcl_Size j;
if (allocatedIndexVector) {
TclStackFree(interp, sortInfo.indexv);
allocatedIndexVector = 0;
}
if (i > objc-4) {
TclPrintfResult(interp,
"\"-index\" option must be followed by list index");
TclSetErrorCode(interp, "TCL", "ARGUMENT", "MISSING");
result = TCL_ERROR;
goto done;
}
/*
* Store the extracted indices for processing by sublist
* extraction. Note that we don't do this using objects because
|
| ︙ | ︙ | |||
3490 3491 3492 3493 3494 3495 3496 |
for (j=0 ; j<sortInfo.indexc ; j++) {
int encoded = 0;
if (TclIndexEncode(interp, indices[j], TCL_INDEX_NONE,
TCL_INDEX_NONE, &encoded) != TCL_OK) {
result = TCL_ERROR;
}
if (encoded == (int)TCL_INDEX_NONE) {
| | | | | | | | | < < | | < | 3475 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 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 |
for (j=0 ; j<sortInfo.indexc ; j++) {
int encoded = 0;
if (TclIndexEncode(interp, indices[j], TCL_INDEX_NONE,
TCL_INDEX_NONE, &encoded) != TCL_OK) {
result = TCL_ERROR;
}
if (encoded == (int)TCL_INDEX_NONE) {
TclPrintfResult(interp,
"index \"%s\" out of range",
TclGetString(indices[j]));
TclSetErrorCode(interp, "TCL", "VALUE", "INDEX", "OUTOFRANGE");
result = TCL_ERROR;
}
if (result == TCL_ERROR) {
TclPrintfErrorInfo(interp,
"\n (-index option item number %" TCL_Z_MODIFIER "u)", j);
goto done;
}
sortInfo.indexv[j] = encoded;
}
break;
}
}
}
/*
* Subindices only make sense if asked for with -index option set.
*/
if (returnSubindices && sortInfo.indexc==0) {
TclPrintfResult(interp,
"-subindices cannot be used without -index option");
TclSetErrorCode(interp, "TCL", "OPERATION", "LSEARCH", "BAD_OPTION_MIX");
result = TCL_ERROR;
goto done;
}
if (bisect && (allMatches || negatedMatch)) {
TclPrintfResult(interp, "-bisect is not compatible with -all or -not");
TclSetErrorCode(interp, "TCL", "OPERATION", "LSEARCH", "BAD_OPTION_MIX");
result = TCL_ERROR;
goto done;
}
if (mode == REGEXP) {
/*
* We can shimmer regexp/list if listv[i] == pattern, so get the
|
| ︙ | ︙ | |||
3575 3576 3577 3578 3579 3580 3581 |
/*
* Check for sanity when grouping elements of the overall list together
* because of the -stride option. [TIP #351]
*/
if (groupSize > 1) {
if (listc % groupSize) {
| | | < | < | | | | | 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 |
/*
* Check for sanity when grouping elements of the overall list together
* because of the -stride option. [TIP #351]
*/
if (groupSize > 1) {
if (listc % groupSize) {
TclPrintfResult(interp,
"list size must be a multiple of the stride length");
TclSetErrorCode(interp, "TCL", "OPERATION", "LSEARCH", "BADSTRIDE");
result = TCL_ERROR;
goto done;
}
if (sortInfo.indexc > 0) {
/*
* Use the first value in the list supplied to -index as the
* offset of the element within each group by which to sort.
*/
groupOffset = TclIndexDecode(sortInfo.indexv[0], groupSize - 1);
if (groupOffset < 0 || groupOffset >= groupSize) {
TclPrintfResult(interp,
"when used with \"-stride\", the leading \"-index\""
" value must be within the group");
TclSetErrorCode(interp, "TCL", "OPERATION", "LSEARCH",
"BADINDEX");
result = TCL_ERROR;
goto done;
}
if (sortInfo.indexc == 1) {
sortInfo.indexc = 0;
sortInfo.indexv = NULL;
} else {
|
| ︙ | ︙ | |||
4057 4058 4059 4060 4061 4062 4063 |
*numValuePtr = argPtr;
Tcl_IncrRefCount(argPtr);
return NumericArg;
}
}
if (allowedArgs & RangeKeywordArg) {
result = Tcl_GetIndexFromObj(NULL, argPtr, seq_operations,
| | | | | < | 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 |
*numValuePtr = argPtr;
Tcl_IncrRefCount(argPtr);
return NumericArg;
}
}
if (allowedArgs & RangeKeywordArg) {
result = Tcl_GetIndexFromObj(NULL, argPtr, seq_operations,
"range operation", 0, &opmode);
}
if (result == TCL_OK) {
if (allowedArgs & LastArg) {
/* keyword found, but no followed number */
TclPrintfResult(interp,
"missing \"%s\" value.", TclGetString(argPtr));
return ErrArg;
}
*keywordIndexPtr = opmode;
return RangeKeywordArg;
} else {
Tcl_Obj *exprValueObj;
if (!(allowedArgs & NumericArg)) {
return NoneArg;
}
doExpr:
/* Check for an index expression */
if (Tcl_ExprObj(interp, argPtr, &exprValueObj) != TCL_OK) {
return ErrArg;
}
int keyword;
/* Determine if result of expression is double or int */
if (Tcl_GetNumberFromObj(interp, exprValueObj, &internalPtr,
&keyword) != TCL_OK) {
return ErrArg;
}
*numValuePtr = exprValueObj; /* incremented in Tcl_ExprObj */
*keywordIndexPtr = keyword; /* type of expression result */
return NumericArg;
}
}
|
| ︙ | ︙ | |||
4577 4578 4579 4580 4581 4582 4583 |
}
switch (index) {
case LSORT_ASCII:
sortInfo.sortMode = SORTMODE_ASCII;
break;
case LSORT_COMMAND:
if (i == objc-2) {
| | | | | 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 |
}
switch (index) {
case LSORT_ASCII:
sortInfo.sortMode = SORTMODE_ASCII;
break;
case LSORT_COMMAND:
if (i == objc-2) {
TclPrintfResult(interp,
"\"-command\" option must be followed "
"by comparison command");
TclSetErrorCode(interp, "TCL", "ARGUMENT", "MISSING");
sortInfo.resultCode = TCL_ERROR;
goto done;
}
sortInfo.sortMode = SORTMODE_COMMAND;
cmdPtr = objv[i+1];
i++;
break;
|
| ︙ | ︙ | |||
4602 4603 4604 4605 4606 4607 4608 |
sortInfo.isIncreasing = 1;
break;
case LSORT_INDEX: {
Tcl_Size sortindex;
Tcl_Obj **indexv;
if (i == objc-2) {
| | | < | | 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 |
sortInfo.isIncreasing = 1;
break;
case LSORT_INDEX: {
Tcl_Size sortindex;
Tcl_Obj **indexv;
if (i == objc-2) {
TclPrintfResult(interp,
"\"-index\" option must be followed by list index");
TclSetErrorCode(interp, "TCL", "ARGUMENT", "MISSING");
sortInfo.resultCode = TCL_ERROR;
goto done;
}
if (TclListObjGetElements(interp, objv[i+1], &sortindex,
&indexv) != TCL_OK) {
sortInfo.resultCode = TCL_ERROR;
goto done;
|
| ︙ | ︙ | |||
4629 4630 4631 4632 4633 4634 4635 |
for (j=0 ; j<sortindex ; j++) {
int encoded = 0;
int result = TclIndexEncode(interp, indexv[j],
TCL_INDEX_NONE, TCL_INDEX_NONE, &encoded);
if ((result == TCL_OK) && (encoded == (int)TCL_INDEX_NONE)) {
| | | | | | | 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 |
for (j=0 ; j<sortindex ; j++) {
int encoded = 0;
int result = TclIndexEncode(interp, indexv[j],
TCL_INDEX_NONE, TCL_INDEX_NONE, &encoded);
if ((result == TCL_OK) && (encoded == (int)TCL_INDEX_NONE)) {
TclPrintfResult(interp,
"index \"%s\" out of range",
TclGetString(indexv[j]));
TclSetErrorCode(interp, "TCL", "VALUE", "INDEX", "OUTOFRANGE");
result = TCL_ERROR;
}
if (result == TCL_ERROR) {
TclPrintfErrorInfo(interp,
"\n (-index option item number %" TCL_Z_MODIFIER "u)", j);
sortInfo.resultCode = TCL_ERROR;
goto done;
}
}
indexPtr = objv[i+1];
i++;
break;
|
| ︙ | ︙ | |||
4663 4664 4665 4666 4667 4668 4669 |
sortInfo.unique = 1;
break;
case LSORT_INDICES:
indices = 1;
break;
case LSORT_STRIDE:
if (i == objc-2) {
| | | < | < | | < | 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 |
sortInfo.unique = 1;
break;
case LSORT_INDICES:
indices = 1;
break;
case LSORT_STRIDE:
if (i == objc-2) {
TclPrintfResult(interp,
"\"-stride\" option must be followed by stride length");
TclSetErrorCode(interp, "TCL", "ARGUMENT", "MISSING");
sortInfo.resultCode = TCL_ERROR;
goto done;
}
if (TclGetWideIntFromObj(interp, objv[i+1], &wide) != TCL_OK) {
sortInfo.resultCode = TCL_ERROR;
goto done;
}
if (wide < 2) {
TclPrintfResult(interp, "stride length must be at least 2");
TclSetErrorCode(interp, "TCL", "OPERATION", "LSORT", "BADSTRIDE");
sortInfo.resultCode = TCL_ERROR;
goto done;
}
groupSize = wide;
group = 1;
i++;
break;
|
| ︙ | ︙ | |||
4777 4778 4779 4780 4781 4782 4783 |
/*
* Check for sanity when grouping elements of the overall list together
* because of the -stride option. [TIP #326]
*/
if (group) {
if (length % groupSize) {
| | | < | < | | | < | 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 |
/*
* Check for sanity when grouping elements of the overall list together
* because of the -stride option. [TIP #326]
*/
if (group) {
if (length % groupSize) {
TclPrintfResult(interp,
"list size must be a multiple of the stride length");
TclSetErrorCode(interp, "TCL", "OPERATION", "LSORT", "BADSTRIDE");
sortInfo.resultCode = TCL_ERROR;
goto done;
}
length = length / groupSize;
if (sortInfo.indexc > 0) {
/*
* Use the first value in the list supplied to -index as the
* offset of the element within each group by which to sort.
*/
groupOffset = TclIndexDecode(sortInfo.indexv[0], groupSize - 1);
if (groupOffset < 0 || groupOffset >= groupSize) {
TclPrintfResult(interp,
"when used with \"-stride\", the leading \"-index\""
" value must be within the group");
TclSetErrorCode(interp, "TCL", "OPERATION", "LSORT", "BADINDEX");
sortInfo.resultCode = TCL_ERROR;
goto done;
}
if (sortInfo.indexc == 1) {
sortInfo.indexc = 0;
sortInfo.indexv = NULL;
} else {
|
| ︙ | ︙ | |||
4858 4859 4860 4861 4862 4863 4864 |
elmArrSize = length * sizeof(SortElement);
if (elmArrSize <= MAXCALLOC) {
elementArray = (SortElement *)Tcl_Alloc(elmArrSize);
} else {
elementArray = (SortElement *)malloc(elmArrSize);
}
if (!elementArray) {
| | | > | | 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 |
elmArrSize = length * sizeof(SortElement);
if (elmArrSize <= MAXCALLOC) {
elementArray = (SortElement *)Tcl_Alloc(elmArrSize);
} else {
elementArray = (SortElement *)malloc(elmArrSize);
}
if (!elementArray) {
TclPrintfResult(interp,
"no enough memory to proccess sort of %" TCL_Z_MODIFIER "u items",
length);
TclSetErrorCode(interp, "TCL", "MEMORY");
sortInfo.resultCode = TCL_ERROR;
goto done;
}
for (i=0; i < length; i++) {
idx = groupSize * i + groupOffset;
if (indexc) {
|
| ︙ | ︙ | |||
5311 5312 5313 5314 5315 5316 5317 |
/*
* Parse the result of the command.
*/
if (TclGetIntFromObj(infoPtr->interp,
Tcl_GetObjResult(infoPtr->interp), &order) != TCL_OK) {
| | | | | | 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 |
/*
* Parse the result of the command.
*/
if (TclGetIntFromObj(infoPtr->interp,
Tcl_GetObjResult(infoPtr->interp), &order) != TCL_OK) {
TclPrintfResult(infoPtr->interp,
"-compare command returned non-integer result");
TclSetErrorCode(infoPtr->interp, "TCL", "OPERATION", "LSORT",
"COMPARISONFAILED");
infoPtr->resultCode = TCL_ERROR;
return 0;
}
}
if (!infoPtr->isIncreasing) {
order = -order;
}
|
| ︙ | ︙ | |||
5521 5522 5523 5524 5525 5526 5527 |
¤tObj) != TCL_OK) {
infoPtr->resultCode = TCL_ERROR;
return NULL;
}
if (currentObj == NULL) {
if (index == TCL_INDEX_NONE) {
index = TCL_INDEX_END - infoPtr->indexv[i];
| | | | | | | | 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 |
¤tObj) != TCL_OK) {
infoPtr->resultCode = TCL_ERROR;
return NULL;
}
if (currentObj == NULL) {
if (index == TCL_INDEX_NONE) {
index = TCL_INDEX_END - infoPtr->indexv[i];
TclPrintfResult(infoPtr->interp,
"element end-%d missing from sublist \"%s\"",
index, TclGetString(objPtr));
} else {
TclPrintfResult(infoPtr->interp,
"element %d missing from sublist \"%s\"",
index, TclGetString(objPtr));
}
TclSetErrorCode(infoPtr->interp, "TCL", "OPERATION", "LSORT",
"INDEXFAILED");
infoPtr->resultCode = TCL_ERROR;
return NULL;
}
objPtr = currentObj;
Tcl_BounceRefCount(lastObj);
lastObj = currentObj;
}
|
| ︙ | ︙ |
Changes to generic/tclCmdMZ.c.
| ︙ | ︙ | |||
225 226 227 228 229 230 231 |
/*
* Check if the user requested -inline, but specified match variables; a
* no-no.
*/
if (doinline && ((objc - 2) != 0)) {
| | | | < | 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
/*
* Check if the user requested -inline, but specified match variables; a
* no-no.
*/
if (doinline && ((objc - 2) != 0)) {
TclPrintfResult(interp,
"regexp match variables not allowed when using -inline");
TclSetErrorCode(interp, "TCL", "OPERATION", "REGEXP", "MIX_VAR_INLINE");
goto optionError;
}
/*
* Handle the odd about case separately.
*/
|
| ︙ | ︙ | |||
677 678 679 680 681 682 683 |
* object. (If they aren't, that's cheap to do.)
*/
if (TclListObjLength(interp, objv[2], &numParts) != TCL_OK) {
return TCL_ERROR;
}
if (numParts < 1) {
| | | < | < | 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
* object. (If they aren't, that's cheap to do.)
*/
if (TclListObjLength(interp, objv[2], &numParts) != TCL_OK) {
return TCL_ERROR;
}
if (numParts < 1) {
TclPrintfResult(interp,
"command prefix must be a list of at least one element");
TclSetErrorCode(interp, "TCL", "OPERATION", "REGSUB", "CMDEMPTY");
return TCL_ERROR;
}
regExpr = Tcl_GetRegExpFromObj(interp, objv[0], cflags);
}
/*
* Make sure to avoid problems where the objects are shared. This can
|
| ︙ | ︙ | |||
810 811 812 813 814 815 816 |
result = Tcl_EvalObjv(interp, numArgs, args, 0);
for (idx = 0 ; idx <= info.nsubs ; idx++) {
TclDecrRefCount(args[idx + numParts]);
}
Tcl_Free(args);
if (result != TCL_OK) {
if (result == TCL_ERROR) {
| | | | 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 |
result = Tcl_EvalObjv(interp, numArgs, args, 0);
for (idx = 0 ; idx <= info.nsubs ; idx++) {
TclDecrRefCount(args[idx + numParts]);
}
Tcl_Free(args);
if (result != TCL_OK) {
if (result == TCL_ERROR) {
TclPrintfErrorInfo(interp,
"\n (%s substitution computation script)",
options[REGSUB_COMMAND]);
}
goto done;
}
Tcl_AppendObjToObj(resultPtr, Tcl_GetObjResult(interp));
Tcl_ResetResult(interp);
|
| ︙ | ︙ | |||
1968 1969 1970 1971 1972 1973 1974 |
if (objc == 4) {
const char *string = TclGetStringFromObj(objv[1], &length2);
if ((length2 > 1) &&
strncmp(string, "-nocase", length2) == 0) {
nocase = 1;
} else {
| | | | < | 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 |
if (objc == 4) {
const char *string = TclGetStringFromObj(objv[1], &length2);
if ((length2 > 1) &&
strncmp(string, "-nocase", length2) == 0) {
nocase = 1;
} else {
TclPrintfResult(interp,
"bad option \"%s\": must be -nocase", string);
TclSetErrorCode(interp, "TCL", "LOOKUP", "INDEX", "option", string);
return TCL_ERROR;
}
}
/*
* This test is tricky, but has to be that way or you get other strange
* inconsistencies (see test string-10.20.1 for illustration why!)
|
| ︙ | ︙ | |||
2036 2037 2038 2039 2040 2041 2042 |
Tcl_SetObjResult(interp, objv[objc-1]);
return TCL_OK;
} else if (mapElemc & 1) {
/*
* The charMap must be an even number of key/value items.
*/
| < | | < | 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 |
Tcl_SetObjResult(interp, objv[objc-1]);
return TCL_OK;
} else if (mapElemc & 1) {
/*
* The charMap must be an even number of key/value items.
*/
TclPrintfResult(interp, "char map list unbalanced");
TclSetErrorCode(interp, "TCL", "OPERATION", "MAP", "UNBALANCED");
return TCL_ERROR;
}
}
/*
* Take a copy of the source string object if it is the same as the map
* string to cut out nasty sharing crashes. [Bug 1018562]
|
| ︙ | ︙ | |||
2240 2241 2242 2243 2244 2245 2246 |
if (objc == 4) {
Tcl_Size length;
const char *string = TclGetStringFromObj(objv[1], &length);
if ((length > 1) && strncmp(string, "-nocase", length) == 0) {
nocase = TCL_MATCH_NOCASE;
} else {
| | | | < | 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 |
if (objc == 4) {
Tcl_Size length;
const char *string = TclGetStringFromObj(objv[1], &length);
if ((length > 1) && strncmp(string, "-nocase", length) == 0) {
nocase = TCL_MATCH_NOCASE;
} else {
TclPrintfResult(interp,
"bad option \"%s\": must be -nocase", string);
TclSetErrorCode(interp, "TCL", "LOOKUP", "INDEX", "option", string);
return TCL_ERROR;
}
}
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(
TclStringMatchObj(objv[objc-1], objv[objc-2], nocase)));
return TCL_OK;
}
|
| ︙ | ︙ | |||
2661 2662 2663 2664 2665 2666 2667 |
if (TclGetWideIntFromObj(interp, objv[i], &reqlength) != TCL_OK) {
return TCL_ERROR;
}
if ((Tcl_WideUInt)reqlength > TCL_SIZE_MAX) {
reqlength = -1;
}
} else {
| | | < | | | 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 |
if (TclGetWideIntFromObj(interp, objv[i], &reqlength) != TCL_OK) {
return TCL_ERROR;
}
if ((Tcl_WideUInt)reqlength > TCL_SIZE_MAX) {
reqlength = -1;
}
} else {
TclPrintfResult(interp,
"bad option \"%s\": must be -nocase or -length", string2);
TclSetErrorCode(interp, "TCL", "LOOKUP", "INDEX", "option",
string2);
return TCL_ERROR;
}
}
/*
* From now on, we only access the two objects at the end of the argument
* array.
|
| ︙ | ︙ | |||
2766 2767 2768 2769 2770 2771 2772 |
}
if ((Tcl_WideUInt)wreqlength > TCL_SIZE_MAX) {
*reqlength = -1;
} else {
*reqlength = wreqlength;
}
} else {
| | | < | | | 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 |
}
if ((Tcl_WideUInt)wreqlength > TCL_SIZE_MAX) {
*reqlength = -1;
} else {
*reqlength = wreqlength;
}
} else {
TclPrintfResult(interp,
"bad option \"%s\": must be -nocase or -length", string);
TclSetErrorCode(interp, "TCL", "LOOKUP", "INDEX", "option",
string);
return TCL_ERROR;
}
}
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
2933 2934 2935 2936 2937 2938 2939 | end = Tcl_UtfAtIndex(start, last - first + 1); resultPtr = Tcl_NewStringObj(string1, end - string1); string2 = TclGetString(resultPtr) + (start - string1); length2 = Tcl_UtfToLower(string2); Tcl_SetObjLength(resultPtr, length2 + (start - string1)); | | | 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 |
end = Tcl_UtfAtIndex(start, last - first + 1);
resultPtr = Tcl_NewStringObj(string1, end - string1);
string2 = TclGetString(resultPtr) + (start - string1);
length2 = Tcl_UtfToLower(string2);
Tcl_SetObjLength(resultPtr, length2 + (start - string1));
Tcl_AppendToObj(resultPtr, end, TCL_AUTO_LENGTH);
Tcl_SetObjResult(interp, resultPtr);
}
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
3018 3019 3020 3021 3022 3023 3024 | end = Tcl_UtfAtIndex(start, last - first + 1); resultPtr = Tcl_NewStringObj(string1, end - string1); string2 = TclGetString(resultPtr) + (start - string1); length2 = Tcl_UtfToUpper(string2); Tcl_SetObjLength(resultPtr, length2 + (start - string1)); | | | 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 |
end = Tcl_UtfAtIndex(start, last - first + 1);
resultPtr = Tcl_NewStringObj(string1, end - string1);
string2 = TclGetString(resultPtr) + (start - string1);
length2 = Tcl_UtfToUpper(string2);
Tcl_SetObjLength(resultPtr, length2 + (start - string1));
Tcl_AppendToObj(resultPtr, end, TCL_AUTO_LENGTH);
Tcl_SetObjResult(interp, resultPtr);
}
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
3103 3104 3105 3106 3107 3108 3109 | end = Tcl_UtfAtIndex(start, last - first + 1); resultPtr = Tcl_NewStringObj(string1, end - string1); string2 = TclGetString(resultPtr) + (start - string1); length2 = Tcl_UtfToTitle(string2); Tcl_SetObjLength(resultPtr, length2 + (start - string1)); | | | 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 |
end = Tcl_UtfAtIndex(start, last - first + 1);
resultPtr = Tcl_NewStringObj(string1, end - string1);
string2 = TclGetString(resultPtr) + (start - string1);
length2 = Tcl_UtfToTitle(string2);
Tcl_SetObjLength(resultPtr, length2 + (start - string1));
Tcl_AppendToObj(resultPtr, end, TCL_AUTO_LENGTH);
Tcl_SetObjResult(interp, resultPtr);
}
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
3496 3497 3498 3499 3500 3501 3502 |
default:
if (foundmode) {
/*
* Mode already set via -exact, -glob, or -regexp.
*/
| | | | | | | | < | | | < | | | < | | | < | 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 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 |
default:
if (foundmode) {
/*
* Mode already set via -exact, -glob, or -regexp.
*/
TclPrintfResult(interp,
"bad option \"%s\": %s option already found",
TclGetString(objv[i]), options[mode]);
TclSetErrorCode(interp, "TCL", "OPERATION", "SWITCH",
"DOUBLEOPT");
return TCL_ERROR;
}
foundmode = 1;
mode = index;
break;
/*
* Check for TIP#75 options specifying the variables to write
* regexp information into.
*/
case OPT_INDEXV:
i++;
if (i >= objc-2) {
TclPrintfResult(interp,
"missing variable name argument to %s option",
"-indexvar");
TclSetErrorCode(interp, "TCL", "OPERATION", "SWITCH", "NOVAR");
return TCL_ERROR;
}
indexVarObj = objv[i];
numMatchesSaved = -1;
break;
case OPT_MATCHV:
i++;
if (i >= objc-2) {
TclPrintfResult(interp,
"missing variable name argument to %s option",
"-matchvar");
TclSetErrorCode(interp, "TCL", "OPERATION", "SWITCH", "NOVAR");
return TCL_ERROR;
}
matchVarObj = objv[i];
numMatchesSaved = -1;
break;
}
}
finishedOptions:
if (objc - i < 2) {
Tcl_WrongNumArgs(interp, 1, objv,
"?-option ...? string ?pattern body ...? ?default body?");
return TCL_ERROR;
}
if (indexVarObj != NULL && mode != OPT_REGEXP) {
TclPrintfResult(interp,
"%s option requires -regexp option", "-indexvar");
TclSetErrorCode(interp, "TCL", "OPERATION", "SWITCH", "MODERESTRICTION");
return TCL_ERROR;
}
if (matchVarObj != NULL && mode != OPT_REGEXP) {
TclPrintfResult(interp,
"%s option requires -regexp option", "-matchvar");
TclSetErrorCode(interp, "TCL", "OPERATION", "SWITCH", "MODERESTRICTION");
return TCL_ERROR;
}
stringObj = objv[i];
objc -= i + 1;
objv += i + 1;
bidx = i + 1; /* First after the match string. */
|
| ︙ | ︙ | |||
3610 3611 3612 3613 3614 3615 3616 |
/*
* Complain if there is an odd number of words in the list of patterns and
* bodies.
*/
if (objc % 2) {
Tcl_ResetResult(interp);
| < | | < | | | | | | | | | 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 3642 3643 3644 3645 3646 3647 3648 3649 |
/*
* Complain if there is an odd number of words in the list of patterns and
* bodies.
*/
if (objc % 2) {
Tcl_ResetResult(interp);
TclPrintfResult(interp, "extra switch pattern with no body");
TclSetErrorCode(interp, "TCL", "OPERATION", "SWITCH", "BADARM");
/*
* Check if this can be due to a badly placed comment in the switch
* block.
*
* The following is an heuristic to detect the infamous "comment in
* switch" error: just check if a pattern begins with '#'.
*/
if (splitObjs) {
for (i=0 ; i<objc ; i+=2) {
if (TclGetString(objv[i])[0] == '#') {
TclAppendLiteralToObj(Tcl_GetObjResult(interp),
", this may be due to a comment incorrectly"
" placed outside of a switch body - see the"
" \"switch\" documentation");
TclSetErrorCode(interp, "TCL", "OPERATION", "SWITCH",
"BADARM", "COMMENT?");
break;
}
}
}
return TCL_ERROR;
}
/*
* Complain if the last body is a continuation. Note that this check
* assumes that the list is non-empty!
*/
if (strcmp(TclGetString(objv[objc-1]), "-") == 0) {
TclPrintfResult(interp,
"no body specified for pattern \"%s\"",
TclGetString(objv[objc - 2]));
TclSetErrorCode(interp, "TCL", "OPERATION", "SWITCH", "BADARM",
"FALLTHROUGH");
return TCL_ERROR;
}
for (i = 0; i < objc; i += 2) {
/*
* See if the pattern matches the string.
*/
|
| ︙ | ︙ | |||
3888 3889 3890 3891 3892 3893 3894 |
}
}
/*
* TIP #280: Make invoking context available to switch branch.
*/
| | | | | 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 |
}
}
/*
* TIP #280: Make invoking context available to switch branch.
*/
TclNRAddCallback(interp, SwitchPostProc, INT2PTR(splitObjs), ctxPtr,
INT2PTR(pc), pattern);
return TclNREvalObjEx(interp, objv[j], 0, ctxPtr, splitObjs ? j : bidx+j);
}
static int
SwitchPostProc(
void *data[], /* Data passed from TclNRAddCallback above */
Tcl_Interp *interp, /* Tcl interpreter */
int result) /* Result to return*/
{
/* Unpack the preserved data */
int splitObjs = PTR2INT(data[0]);
CmdFrame *ctxPtr = (CmdFrame *)data[1];
|
| ︙ | ︙ | |||
3930 3931 3932 3933 3934 3935 3936 |
* Generate an error message if necessary.
*/
if (result == TCL_ERROR) {
int limit = 50;
int overflow = (patternLength > limit);
| < | | | 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 |
* Generate an error message if necessary.
*/
if (result == TCL_ERROR) {
int limit = 50;
int overflow = (patternLength > limit);
TclPrintfErrorInfo(interp, "\n (\"%.*s%s\" arm line %d)",
(int) (overflow ? limit : patternLength), pattern,
(overflow ? "..." : ""), Tcl_GetErrorLine(interp));
}
TclStackFree(interp, ctxPtr);
return result;
}
/*
*----------------------------------------------------------------------
|
| ︙ | ︙ | |||
3978 3979 3980 3981 3982 3983 3984 |
/*
* The type must be a list of at least length 1.
*/
if (TclListObjLength(interp, objv[1], &len) != TCL_OK) {
return TCL_ERROR;
} else if (len < 1) {
| < | | < | 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 |
/*
* The type must be a list of at least length 1.
*/
if (TclListObjLength(interp, objv[1], &len) != TCL_OK) {
return TCL_ERROR;
} else if (len < 1) {
TclPrintfResult(interp, "type must be non-empty list");
TclSetErrorCode(interp, "TCL", "OPERATION", "THROW", "BADEXCEPTION");
return TCL_ERROR;
}
/*
* Now prepare the result options dictionary. We use the list API as it is
* slightly more convenient.
*/
|
| ︙ | ︙ | |||
4717 4718 4719 4720 4721 4722 4723 |
0, &type) != TCL_OK) {
Tcl_DecrRefCount(handlersObj);
return TCL_ERROR;
}
switch (type) {
case TryFinally: /* finally script */
if (i < objc-2) {
| < | | | | | | | | | | | | | < | | | | | | | | 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 |
0, &type) != TCL_OK) {
Tcl_DecrRefCount(handlersObj);
return TCL_ERROR;
}
switch (type) {
case TryFinally: /* finally script */
if (i < objc-2) {
TclPrintfResult(interp, "finally clause must be last");
Tcl_DecrRefCount(handlersObj);
TclSetErrorCode(interp, "TCL", "OPERATION", "TRY", "FINALLY",
"NONTERMINAL");
return TCL_ERROR;
} else if (i == objc-1) {
TclPrintfResult(interp,
"wrong # args to finally clause: must be"
" \"... finally script\"");
Tcl_DecrRefCount(handlersObj);
TclSetErrorCode(interp, "TCL", "OPERATION", "TRY", "FINALLY",
"ARGUMENT");
return TCL_ERROR;
}
finallyObj = objv[++i];
break;
case TryOn: /* on code variableList script */
if (i > objc-4) {
TclPrintfResult(interp,
"wrong # args to on clause: must be \"... on code"
" variableList script\"");
Tcl_DecrRefCount(handlersObj);
TclSetErrorCode(interp, "TCL", "OPERATION", "TRY", "ON",
"ARGUMENT");
return TCL_ERROR;
}
if (TclGetCompletionCodeFromObj(interp, objv[i+1],
&code) != TCL_OK) {
Tcl_DecrRefCount(handlersObj);
return TCL_ERROR;
}
info[2] = NULL;
goto commonHandler;
case TryTrap: /* trap pattern variableList script */
if (i > objc-4) {
TclPrintfResult(interp,
"wrong # args to trap clause: "
"must be \"... trap pattern variableList script\"");
Tcl_DecrRefCount(handlersObj);
TclSetErrorCode(interp, "TCL", "OPERATION", "TRY", "TRAP",
"ARGUMENT");
return TCL_ERROR;
}
code = 1;
if (TclListObjLength(NULL, objv[i + 1], &dummy) != TCL_OK) {
TclPrintfResult(interp,
"bad prefix '%s': must be a list",
TclGetString(objv[i + 1]));
Tcl_DecrRefCount(handlersObj);
TclSetErrorCode(interp, "TCL", "OPERATION", "TRY", "TRAP",
"EXNFORMAT");
return TCL_ERROR;
}
info[2] = objv[i+1];
commonHandler:
if (TclListObjLength(interp, objv[i+2], &dummy) != TCL_OK) {
Tcl_DecrRefCount(handlersObj);
|
| ︙ | ︙ | |||
4799 4800 4801 4802 4803 4804 4805 |
Tcl_NewListObj(5, info));
haveHandlers = 1;
i += 3;
break;
}
}
if (bodyShared) {
| | | | < | | | 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 |
Tcl_NewListObj(5, info));
haveHandlers = 1;
i += 3;
break;
}
}
if (bodyShared) {
TclPrintfResult(interp,
"last non-finally clause must not have a body of \"-\"");
Tcl_DecrRefCount(handlersObj);
TclSetErrorCode(interp, "TCL", "OPERATION", "TRY", "BADFALLTHROUGH");
return TCL_ERROR;
}
if (!haveHandlers) {
Tcl_DecrRefCount(handlersObj);
handlersObj = NULL;
}
/*
* Execute the body.
*/
TclNRAddCallback(interp, TryPostBody, handlersObj, finallyObj,
objv, INT2PTR(objc));
return TclNREvalObjEx(interp, bodyObj, 0,
((Interp *) interp)->cmdFramePtr, 1);
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
4891 4892 4893 4894 4895 4896 4897 |
cmdObj = objv[0];
/*
* Check for limits/rewinding, which override normal trapping behaviour.
*/
if (((Interp*) interp)->execEnvPtr->rewind || Tcl_LimitExceeded(interp)) {
| < | | < | | | 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 |
cmdObj = objv[0];
/*
* Check for limits/rewinding, which override normal trapping behaviour.
*/
if (((Interp*) interp)->execEnvPtr->rewind || Tcl_LimitExceeded(interp)) {
TclPrintfErrorInfo(interp, "\n (\"%s\" body line %d)",
TclGetString(cmdObj), Tcl_GetErrorLine(interp));
if (handlersObj != NULL) {
Tcl_DecrRefCount(handlersObj);
}
return TCL_ERROR;
}
/*
* Basic processing of the outcome of the script, including adding of
* errorinfo trace.
*/
if (result == TCL_ERROR) {
TclPrintfErrorInfo(interp, "\n (\"%s\" body line %d)",
TclGetString(cmdObj), Tcl_GetErrorLine(interp));
}
resultObj = Tcl_GetObjResult(interp);
Tcl_IncrRefCount(resultObj);
options = Tcl_GetReturnOptions(interp, result);
Tcl_IncrRefCount(options);
Tcl_ResetResult(interp);
|
| ︙ | ︙ | |||
5026 5027 5028 5029 5030 5031 5032 | * now because the info[] array is about to become invalid. There * is very little refcount handling here however, since we know * that the objects that we still want to refer to now were input * arguments to [try] and so are still on the Tcl value stack. */ handlerBodyObj = info[4]; | | | 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 | * now because the info[] array is about to become invalid. There * is very little refcount handling here however, since we know * that the objects that we still want to refer to now were input * arguments to [try] and so are still on the Tcl value stack. */ handlerBodyObj = info[4]; TclNRAddCallback(interp, TryPostHandler, objv, options, info[0], INT2PTR((finallyObj == NULL) ? 0 : objc - 1)); Tcl_DecrRefCount(handlersObj); return TclNREvalObjEx(interp, handlerBodyObj, 0, ((Interp *) interp)->cmdFramePtr, 4*i + 5); handlerFailed: resultObj = Tcl_GetObjResult(interp); |
| ︙ | ︙ | |||
5054 5055 5056 5057 5058 5059 5060 |
}
/*
* Process the finally clause.
*/
if (finallyObj != NULL) {
| | < | 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 |
}
/*
* Process the finally clause.
*/
if (finallyObj != NULL) {
TclNRAddCallback(interp, TryPostFinal, resultObj, options, cmdObj);
return TclNREvalObjEx(interp, finallyObj, 0,
((Interp *) interp)->cmdFramePtr, objc - 1);
}
/*
* Install the correct result/options into the interpreter and clean up
* any temporary storage.
|
| ︙ | ︙ | |||
5138 5139 5140 5141 5142 5143 5144 |
/*
* Process the finally clause if it is present.
*/
if (finallyObj != NULL) {
Interp *iPtr = (Interp *) interp;
| | < | 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 |
/*
* Process the finally clause if it is present.
*/
if (finallyObj != NULL) {
Interp *iPtr = (Interp *) interp;
TclNRAddCallback(interp, TryPostFinal, resultObj, options, cmdObj);
/* The 'finally' script is always the last argument word. */
return TclNREvalObjEx(interp, finallyObj, 0, iPtr->cmdFramePtr,
finallyIndex);
}
/*
|
| ︙ | ︙ | |||
5271 5272 5273 5274 5275 5276 5277 |
TclSmallAllocEx(interp, sizeof(ForIterData), iterPtr);
iterPtr->cond = objv[1];
iterPtr->body = objv[2];
iterPtr->next = NULL;
iterPtr->msg = "\n (\"while\" body line %d)";
iterPtr->word = 2;
| | < | 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 |
TclSmallAllocEx(interp, sizeof(ForIterData), iterPtr);
iterPtr->cond = objv[1];
iterPtr->body = objv[2];
iterPtr->next = NULL;
iterPtr->msg = "\n (\"while\" body line %d)";
iterPtr->word = 2;
TclNRAddCallback(interp, TclNRForIterCallback, iterPtr);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* TclListLines --
|
| ︙ | ︙ |
Changes to generic/tclCompCmds.c.
| ︙ | ︙ | |||
2371 2372 2373 2374 2375 2376 2377 |
TCL_UNUSED(size_t))
{
DictUpdateInfo *duiPtr = (DictUpdateInfo *)clientData;
Tcl_Size i;
for (i=0 ; i<duiPtr->length ; i++) {
if (i) {
| | | 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 |
TCL_UNUSED(size_t))
{
DictUpdateInfo *duiPtr = (DictUpdateInfo *)clientData;
Tcl_Size i;
for (i=0 ; i<duiPtr->length ; i++) {
if (i) {
TclAppendLiteralToObj(appendObj, ", ");
}
Tcl_AppendPrintfToObj(appendObj, "%%v%" TCL_Z_MODIFIER "u", duiPtr->varIndices[i]);
}
}
static void
DisassembleDictUpdateInfo(
|
| ︙ | ︙ | |||
3051 3052 3053 3054 3055 3056 3057 |
TCL_UNUSED(ByteCode *),
TCL_UNUSED(size_t))
{
ForeachInfo *infoPtr = (ForeachInfo *)clientData;
ForeachVarList *varsPtr;
Tcl_Size i, j;
| | | | | | | | | | | 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 |
TCL_UNUSED(ByteCode *),
TCL_UNUSED(size_t))
{
ForeachInfo *infoPtr = (ForeachInfo *)clientData;
ForeachVarList *varsPtr;
Tcl_Size i, j;
TclAppendLiteralToObj(appendObj, "data=[");
for (i=0 ; i<infoPtr->numLists ; i++) {
if (i) {
TclAppendLiteralToObj(appendObj, ", ");
}
Tcl_AppendPrintfToObj(appendObj, "%%v%" TCL_Z_MODIFIER "u",
(infoPtr->firstValueTemp + i));
}
Tcl_AppendPrintfToObj(appendObj, "], loop=%%v%" TCL_Z_MODIFIER "u",
infoPtr->loopCtTemp);
for (i=0 ; i<infoPtr->numLists ; i++) {
if (i) {
TclAppendLiteralToObj(appendObj, ",");
}
Tcl_AppendPrintfToObj(appendObj, "\n\t\t it%%v%" TCL_Z_MODIFIER "u\t[",
(infoPtr->firstValueTemp + i));
varsPtr = infoPtr->varLists[i];
for (j=0 ; j<varsPtr->numVars ; j++) {
if (j) {
TclAppendLiteralToObj(appendObj, ", ");
}
Tcl_AppendPrintfToObj(appendObj, "%%v%" TCL_Z_MODIFIER "u",
varsPtr->varIndexes[j]);
}
TclAppendLiteralToObj(appendObj, "]");
}
}
static void
PrintNewForeachInfo(
void *clientData,
Tcl_Obj *appendObj,
TCL_UNUSED(ByteCode *),
TCL_UNUSED(size_t))
{
ForeachInfo *infoPtr = (ForeachInfo *)clientData;
ForeachVarList *varsPtr;
Tcl_Size i, j;
Tcl_AppendPrintfToObj(appendObj, "jumpOffset=%+" TCL_Z_MODIFIER "d, vars=",
infoPtr->loopCtTemp);
for (i=0 ; i<infoPtr->numLists ; i++) {
if (i) {
TclAppendLiteralToObj(appendObj, ",");
}
TclAppendLiteralToObj(appendObj, "[");
varsPtr = infoPtr->varLists[i];
for (j=0 ; j<varsPtr->numVars ; j++) {
if (j) {
TclAppendLiteralToObj(appendObj, ",");
}
Tcl_AppendPrintfToObj(appendObj, "%%v%" TCL_Z_MODIFIER "u",
varsPtr->varIndexes[j]);
}
TclAppendLiteralToObj(appendObj, "]");
}
}
static void
DisassembleForeachInfo(
void *clientData,
Tcl_Obj *dictObj,
|
| ︙ | ︙ | |||
3348 3349 3350 3351 3352 3353 3354 |
* in the format string. */
TclNewObj(tmpObj); /* The buffer used to accumulate the literal
* being built. */
for (bytes = start ; *bytes ; bytes++) {
if (*bytes == '%') {
Tcl_AppendToObj(tmpObj, start, bytes - start);
if (*++bytes == '%') {
| | | 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 |
* in the format string. */
TclNewObj(tmpObj); /* The buffer used to accumulate the literal
* being built. */
for (bytes = start ; *bytes ; bytes++) {
if (*bytes == '%') {
Tcl_AppendToObj(tmpObj, start, bytes - start);
if (*++bytes == '%') {
TclAppendLiteralToObj(tmpObj, "%");
} else {
const char *b = TclGetStringFromObj(tmpObj, &len);
/*
* If there is a non-empty literal from the format string,
* push it and reset.
*/
|
| ︙ | ︙ |
Changes to generic/tclCompCmdsSZ.c.
| ︙ | ︙ | |||
2595 2596 2597 2598 2599 2600 2601 |
hPtr = Tcl_FirstHashEntry(&jtPtr->hashTable, &search);
for (; hPtr ; hPtr = Tcl_NextHashEntry(&search)) {
keyPtr = (const char *)Tcl_GetHashKey(&jtPtr->hashTable, hPtr);
offset = PTR2INT(Tcl_GetHashValue(hPtr));
if (i++) {
| | | | 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 |
hPtr = Tcl_FirstHashEntry(&jtPtr->hashTable, &search);
for (; hPtr ; hPtr = Tcl_NextHashEntry(&search)) {
keyPtr = (const char *)Tcl_GetHashKey(&jtPtr->hashTable, hPtr);
offset = PTR2INT(Tcl_GetHashValue(hPtr));
if (i++) {
TclAppendLiteralToObj(appendObj, ", ");
if (i%4==0) {
TclAppendLiteralToObj(appendObj, "\n\t\t");
}
}
Tcl_AppendPrintfToObj(appendObj, "\"%s\"->pc %" TCL_Z_MODIFIER "u",
keyPtr, pcOffset + offset);
}
}
|
| ︙ | ︙ |
Changes to generic/tclCompExpr.c.
| ︙ | ︙ | |||
780 781 782 783 784 785 786 |
const char *stop;
TclParseNumber(NULL, NULL, NULL, start, scanned,
&stop, TCL_PARSE_NO_WHITESPACE);
if (isdigit(UCHAR(*stop)) || (stop == start + 1)) {
switch (start[1]) {
case 'b':
| | | | | | | | 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 |
const char *stop;
TclParseNumber(NULL, NULL, NULL, start, scanned,
&stop, TCL_PARSE_NO_WHITESPACE);
if (isdigit(UCHAR(*stop)) || (stop == start + 1)) {
switch (start[1]) {
case 'b':
TclAppendLiteralToObj(post,
" (invalid binary number?)");
parsePtr->errorType = TCL_PARSE_BAD_NUMBER;
errCode = "BADNUMBER";
subErrCode = "BINARY";
break;
case 'o':
TclAppendLiteralToObj(post,
" (invalid octal number?)");
parsePtr->errorType = TCL_PARSE_BAD_NUMBER;
errCode = "BADNUMBER";
subErrCode = "OCTAL";
break;
default:
if (isdigit(UCHAR(start[1]))) {
TclAppendLiteralToObj(post,
" (invalid octal number?)");
parsePtr->errorType = TCL_PARSE_BAD_NUMBER;
errCode = "BADNUMBER";
subErrCode = "OCTAL";
}
break;
}
}
|
| ︙ | ︙ | |||
1445 1446 1447 1448 1449 1450 1451 |
(start + scanned + limit > parsePtr->end) ? "" : "...");
/*
* Next, append any postscript message.
*/
if (post != NULL) {
| | < | | | < | 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 |
(start + scanned + limit > parsePtr->end) ? "" : "...");
/*
* Next, append any postscript message.
*/
if (post != NULL) {
TclAppendLiteralToObj(msg, ";\n");
Tcl_AppendObjToObj(msg, post);
Tcl_DecrRefCount(post);
}
Tcl_SetObjResult(interp, msg);
/*
* Finally, place context information in the errorInfo.
*/
numBytes = parsePtr->end - parsePtr->string;
TclPrintfErrorInfo(interp, "\n (parsing expression \"%.*s%s\")",
(numBytes < limit) ? (int)numBytes : (int)limit - 3,
parsePtr->string, (numBytes < limit) ? "" : "...");
if (errCode) {
TclSetErrorCode(interp, "TCL", "PARSE", "EXPR", errCode, subErrCode);
}
}
return TCL_ERROR;
}
/*
|
| ︙ | ︙ |
Changes to generic/tclCompile.c.
| ︙ | ︙ | |||
2167 2168 2169 2170 2171 2172 2173 |
* Check depth to avoid overflow of the C execution stack by too many
* nested calls of TclCompileScript, considering interp recursionlimit.
* Use factor 5/4 (1.25) to avoid being too mistaken when recognizing the
* limit during "mixed" evaluation and compilation process (nested
* eval+compile) and is good enough for default recursionlimit (1000).
*/
if (iPtr->numLevels / 5 > iPtr->maxNestingDepth / 4) {
| | | | | | | | 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 |
* Check depth to avoid overflow of the C execution stack by too many
* nested calls of TclCompileScript, considering interp recursionlimit.
* Use factor 5/4 (1.25) to avoid being too mistaken when recognizing the
* limit during "mixed" evaluation and compilation process (nested
* eval+compile) and is good enough for default recursionlimit (1000).
*/
if (iPtr->numLevels / 5 > iPtr->maxNestingDepth / 4) {
TclPrintfResult(interp,
"too many nested compilations (infinite loop?)");
TclSetErrorCode(interp, "TCL", "LIMIT", "STACK");
TclCompileSyntaxError(interp, envPtr);
return;
}
if (numBytes < 0) {
numBytes = strlen(script);
}
/* Each iteration compiles one command from the script. */
if (numBytes > 0) {
if (numBytes >= INT_MAX) {
/*
* Note this gets -errorline as 1. Not worth figuring out which line
* crosses the limit to get -errorline for this error case.
*/
TclPrintfResult(interp,
"Script length %" TCL_SIZE_MODIFIER
"d exceeds max permitted length %d.",
numBytes, INT_MAX-1);
TclSetErrorCode(interp, "TCL", "LIMIT", "SCRIPTLENGTH");
TclCompileSyntaxError(interp, envPtr);
return;
}
/*
* Don't use system stack (size of Tcl_Parse is ca. 400 bytes), so
* many nested compilations (body enclosed in body) can cause abnormal
* program termination with a stack overflow exception, bug [fec0c17d39].
|
| ︙ | ︙ |
Changes to generic/tclConfig.c.
| ︙ | ︙ | |||
223 224 225 226 227 228 229 |
if (Tcl_DictObjGet(interp, pDB, pkgName, &pkgDict) != TCL_OK
|| pkgDict == NULL) {
/*
* Maybe a Tcl_Panic is better, because the package data has to be
* present.
*/
| | | | | | | | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
if (Tcl_DictObjGet(interp, pDB, pkgName, &pkgDict) != TCL_OK
|| pkgDict == NULL) {
/*
* Maybe a Tcl_Panic is better, because the package data has to be
* present.
*/
TclPrintfResult(interp, "package not known");
TclSetErrorCode(interp, "TCL", "FATAL", "PKGCFG_BASE",
TclGetString(pkgName));
return TCL_ERROR;
}
switch (index) {
case CFG_GET:
if (objc != 3) {
Tcl_WrongNumArgs(interp, 2, objv, "key");
return TCL_ERROR;
}
if (Tcl_DictObjGet(interp, pkgDict, objv[2], &val) != TCL_OK
|| val == NULL) {
TclPrintfResult(interp, "key not known");
TclSetErrorCode(interp, "TCL", "LOOKUP", "CONFIG",
TclGetString(objv[2]));
return TCL_ERROR;
}
if (cdPtr->encoding) {
venc = Tcl_GetEncoding(interp, cdPtr->encoding);
if (!venc) {
return TCL_ERROR;
|
| ︙ | ︙ | |||
274 275 276 277 278 279 280 |
return TCL_ERROR;
}
Tcl_DictObjSize(interp, pkgDict, &m);
listPtr = Tcl_NewListObj(m, NULL);
if (!listPtr) {
| < | | | 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
return TCL_ERROR;
}
Tcl_DictObjSize(interp, pkgDict, &m);
listPtr = Tcl_NewListObj(m, NULL);
if (!listPtr) {
TclPrintfResult(interp, "insufficient memory to create list");
TclSetErrorCode(interp, "TCL", "MEMORY");
return TCL_ERROR;
}
if (m) {
Tcl_DictSearch s;
Tcl_Obj *key;
int done;
|
| ︙ | ︙ |
Changes to generic/tclDictObj.c.
| ︙ | ︙ | |||
712 713 714 715 716 717 718 |
dict->chain = NULL;
dict->refCount = 1;
DictSetInternalRep(objPtr, dict);
return TCL_OK;
missingValue:
if (interp != NULL) {
| < | | | 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 |
dict->chain = NULL;
dict->refCount = 1;
DictSetInternalRep(objPtr, dict);
return TCL_OK;
missingValue:
if (interp != NULL) {
TclPrintfResult(interp, "missing value to go with key");
TclSetErrorCode(interp, "TCL", "VALUE", "DICTIONARY");
}
errorInFindDictElement:
DeleteChainTable(dict);
Tcl_Free(dict);
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
805 806 807 808 809 810 811 |
int isNew; /* Dummy */
if (flags & DICT_PATH_EXISTS) {
return DICT_PATH_NON_EXISTENT;
}
if ((flags & DICT_PATH_CREATE) != DICT_PATH_CREATE) {
if (interp != NULL) {
| | | | | | 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 |
int isNew; /* Dummy */
if (flags & DICT_PATH_EXISTS) {
return DICT_PATH_NON_EXISTENT;
}
if ((flags & DICT_PATH_CREATE) != DICT_PATH_CREATE) {
if (interp != NULL) {
TclPrintfResult(interp,
"key \"%s\" not known in dictionary",
TclGetString(keyv[i]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "DICT",
TclGetString(keyv[i]));
}
return NULL;
}
/*
* The next line should always set isNew to 1.
*/
|
| ︙ | ︙ | |||
1765 1766 1767 1768 1769 1770 1771 |
return TCL_ERROR;
}
result = Tcl_DictObjGet(interp, dictPtr, objv[objc-1], &valuePtr);
if (result != TCL_OK) {
return result;
}
if (valuePtr == NULL) {
| | | | | | 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 |
return TCL_ERROR;
}
result = Tcl_DictObjGet(interp, dictPtr, objv[objc-1], &valuePtr);
if (result != TCL_OK) {
return result;
}
if (valuePtr == NULL) {
TclPrintfResult(interp,
"key \"%s\" not known in dictionary",
TclGetString(objv[objc - 1]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "DICT",
TclGetString(objv[objc - 1]));
return TCL_ERROR;
}
Tcl_SetObjResult(interp, valuePtr);
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
2698 2699 2700 2701 2702 2703 2704 |
* Parse arguments.
*/
if (TclListObjGetElements(interp, objv[1], &varc, &varv) != TCL_OK) {
return TCL_ERROR;
}
if (varc != 2) {
| < | | | 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 |
* Parse arguments.
*/
if (TclListObjGetElements(interp, objv[1], &varc, &varv) != TCL_OK) {
return TCL_ERROR;
}
if (varc != 2) {
TclPrintfResult(interp, "must have exactly two variable names");
TclSetErrorCode(interp, "TCL", "SYNTAX", "dict", "for");
return TCL_ERROR;
}
searchPtr = (Tcl_DictSearch *)TclStackAlloc(interp, sizeof(Tcl_DictSearch));
if (Tcl_DictObjFirst(interp, objv[2], searchPtr, &keyObj, &valueObj,
&done) != TCL_OK) {
TclStackFree(interp, searchPtr);
return TCL_ERROR;
|
| ︙ | ︙ | |||
2791 2792 2793 2794 2795 2796 2797 |
if (result == TCL_CONTINUE) {
result = TCL_OK;
} else if (result != TCL_OK) {
if (result == TCL_BREAK) {
Tcl_ResetResult(interp);
result = TCL_OK;
} else if (result == TCL_ERROR) {
| < | | | 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 |
if (result == TCL_CONTINUE) {
result = TCL_OK;
} else if (result != TCL_OK) {
if (result == TCL_BREAK) {
Tcl_ResetResult(interp);
result = TCL_OK;
} else if (result == TCL_ERROR) {
TclPrintfErrorInfo(interp, "\n (\"dict for\" body line %d)",
Tcl_GetErrorLine(interp));
}
goto done;
}
/*
* Get the next mapping from the dictionary.
*/
|
| ︙ | ︙ | |||
2893 2894 2895 2896 2897 2898 2899 |
* Parse arguments.
*/
if (TclListObjGetElements(interp, objv[1], &varc, &varv) != TCL_OK) {
return TCL_ERROR;
}
if (varc != 2) {
| | | | | 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 |
* Parse arguments.
*/
if (TclListObjGetElements(interp, objv[1], &varc, &varv) != TCL_OK) {
return TCL_ERROR;
}
if (varc != 2) {
TclPrintfResult(interp,
"must have exactly two variable names");
TclSetErrorCode(interp, "TCL", "SYNTAX", "dict", "map");
return TCL_ERROR;
}
storagePtr = (DictMapStorage *)TclStackAlloc(interp, sizeof(DictMapStorage));
if (Tcl_DictObjFirst(interp, objv[2], &storagePtr->search, &keyObj,
&valueObj, &done) != TCL_OK) {
TclStackFree(interp, storagePtr);
return TCL_ERROR;
|
| ︙ | ︙ | |||
2953 2954 2955 2956 2957 2958 2959 |
}
TclDecrRefCount(valueObj);
/*
* Run the script.
*/
| | | 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 |
}
TclDecrRefCount(valueObj);
/*
* Run the script.
*/
TclNRAddCallback(interp, DictMapLoopCallback, storagePtr);
return TclNREvalObjEx(interp, storagePtr->scriptObj, 0,
iPtr->cmdFramePtr, 3);
/*
* For unwinding everything on error.
*/
|
| ︙ | ︙ | |||
2993 2994 2995 2996 2997 2998 2999 |
if (result == TCL_CONTINUE) {
result = TCL_OK;
} else if (result != TCL_OK) {
if (result == TCL_BREAK) {
Tcl_ResetResult(interp);
result = TCL_OK;
} else if (result == TCL_ERROR) {
| < | | | 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 |
if (result == TCL_CONTINUE) {
result = TCL_OK;
} else if (result != TCL_OK) {
if (result == TCL_BREAK) {
Tcl_ResetResult(interp);
result = TCL_OK;
} else if (result == TCL_ERROR) {
TclPrintfErrorInfo(interp, "\n (\"dict map\" body line %d)",
Tcl_GetErrorLine(interp));
}
goto done;
} else {
keyObj = Tcl_ObjGetVar2(interp, storagePtr->keyVarObj, NULL,
TCL_LEAVE_ERR_MSG);
if (keyObj == NULL) {
result = TCL_ERROR;
|
| ︙ | ︙ | |||
3043 3044 3045 3046 3047 3048 3049 |
}
TclDecrRefCount(valueObj);
/*
* Run the script.
*/
| | | 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 |
}
TclDecrRefCount(valueObj);
/*
* Run the script.
*/
TclNRAddCallback(interp, DictMapLoopCallback, storagePtr);
return TclNREvalObjEx(interp, storagePtr->scriptObj, 0,
iPtr->cmdFramePtr, 3);
/*
* For unwinding everything once the iterating is done.
*/
|
| ︙ | ︙ | |||
3333 3334 3335 3336 3337 3338 3339 |
* copying from the "dict for" implementation has occurred!
*/
if (TclListObjGetElements(interp, objv[3], &varc, &varv) != TCL_OK) {
return TCL_ERROR;
}
if (varc != 2) {
| < | | | 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 |
* copying from the "dict for" implementation has occurred!
*/
if (TclListObjGetElements(interp, objv[3], &varc, &varv) != TCL_OK) {
return TCL_ERROR;
}
if (varc != 2) {
TclPrintfResult(interp, "must have exactly two variable names");
TclSetErrorCode(interp, "TCL", "SYNTAX", "dict", "filter");
return TCL_ERROR;
}
keyVarObj = varv[0];
valueVarObj = varv[1];
scriptObj = objv[4];
/*
|
| ︙ | ︙ | |||
3422 3423 3424 3425 3426 3427 3428 | Tcl_ResetResult(interp); Tcl_DictObjDone(&search); /* FALLTHRU */ case TCL_CONTINUE: result = TCL_OK; break; case TCL_ERROR: | | | | 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 | Tcl_ResetResult(interp); Tcl_DictObjDone(&search); /* FALLTHRU */ case TCL_CONTINUE: result = TCL_OK; break; case TCL_ERROR: TclPrintfErrorInfo(interp, "\n (\"dict filter\" script line %d)", Tcl_GetErrorLine(interp)); default: goto abnormalResult; } TclDecrRefCount(keyObj); TclDecrRefCount(valueObj); |
| ︙ | ︙ | |||
3534 3535 3536 3537 3538 3539 3540 |
* Execute the body after setting up the NRE handler to process the
* results.
*/
objPtr = Tcl_NewListObj(objc-3, objv+2);
Tcl_IncrRefCount(objPtr);
Tcl_IncrRefCount(objv[1]);
| | | 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 |
* Execute the body after setting up the NRE handler to process the
* results.
*/
objPtr = Tcl_NewListObj(objc-3, objv+2);
Tcl_IncrRefCount(objPtr);
Tcl_IncrRefCount(objv[1]);
TclNRAddCallback(interp, FinalizeDictUpdate, objv[1], objPtr);
return TclNREvalObjEx(interp, objv[objc-1], 0, iPtr->cmdFramePtr, objc-1);
}
static int
FinalizeDictUpdate(
void *data[],
|
| ︙ | ︙ | |||
3684 3685 3686 3687 3688 3689 3690 |
pathPtr = NULL;
if (objc > 3) {
pathPtr = Tcl_NewListObj(objc-3, objv+2);
Tcl_IncrRefCount(pathPtr);
}
Tcl_IncrRefCount(objv[1]);
| | < | 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 |
pathPtr = NULL;
if (objc > 3) {
pathPtr = Tcl_NewListObj(objc-3, objv+2);
Tcl_IncrRefCount(pathPtr);
}
Tcl_IncrRefCount(objv[1]);
TclNRAddCallback(interp, FinalizeDictWith, objv[1], keysPtr, pathPtr);
return TclNREvalObjEx(interp, objv[objc-1], 0, iPtr->cmdFramePtr, objc-1);
}
static int
FinalizeDictWith(
void *data[],
|
| ︙ | ︙ |
Changes to generic/tclDisassemble.c.
| ︙ | ︙ | |||
193 194 195 196 197 198 199 |
void
TclPrintObject(
FILE *outFile, /* The file to print the source to. */
Tcl_Obj *objPtr, /* Points to the Tcl object whose string
* representation should be printed. */
Tcl_Size maxChars) /* Maximum number of chars to print. */
{
| | > | > > > > | 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
void
TclPrintObject(
FILE *outFile, /* The file to print the source to. */
Tcl_Obj *objPtr, /* Points to the Tcl object whose string
* representation should be printed. */
Tcl_Size maxChars) /* Maximum number of chars to print. */
{
const char *bytes;
Tcl_Size length;
if (objPtr) {
bytes = TclGetStringFromObj(objPtr, &length);
} else {
bytes = "";
length = 0;
}
TclPrintSource(outFile, bytes, TclMin(length, maxChars));
}
/*
*----------------------------------------------------------------------
*
* TclPrintSource --
|
| ︙ | ︙ | |||
278 279 280 281 282 283 284 |
/*
* Print header lines describing the ByteCode.
*/
Tcl_AppendPrintfToObj(bufferObj,
"ByteCode %p, refCt %" TCL_SIZE_MODIFIER "d, epoch %" TCL_SIZE_MODIFIER "d, interp %p (epoch %" TCL_SIZE_MODIFIER "d)\n",
codePtr, codePtr->refCount, codePtr->compileEpoch, iPtr, iPtr->compileEpoch);
| | | 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
/*
* Print header lines describing the ByteCode.
*/
Tcl_AppendPrintfToObj(bufferObj,
"ByteCode %p, refCt %" TCL_SIZE_MODIFIER "d, epoch %" TCL_SIZE_MODIFIER "d, interp %p (epoch %" TCL_SIZE_MODIFIER "d)\n",
codePtr, codePtr->refCount, codePtr->compileEpoch, iPtr, iPtr->compileEpoch);
TclAppendLiteralToObj(bufferObj, " Source ");
PrintSourceToObj(bufferObj, codePtr->source,
TclMin(codePtr->numSrcBytes, 55));
GetLocationInformation(codePtr->procPtr, &fileObj, &line);
if (line >= 0 && fileObj != NULL) {
Tcl_AppendPrintfToObj(bufferObj, "\n File \"%s\" Line %d",
TclGetString(fileObj), line);
}
|
| ︙ | ︙ | |||
337 338 339 340 341 342 343 |
(localPtr->flags & (VAR_ARRAY|VAR_LINK)) ? "" : ", scalar",
(localPtr->flags & VAR_ARRAY) ? ", array" : "",
(localPtr->flags & VAR_LINK) ? ", link" : "",
(localPtr->flags & VAR_ARGUMENT) ? ", arg" : "",
(localPtr->flags & VAR_TEMPORARY) ? ", temp" : "",
(localPtr->flags & VAR_RESOLVED) ? ", resolved" : "");
if (TclIsVarTemporary(localPtr)) {
| | | 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
(localPtr->flags & (VAR_ARRAY|VAR_LINK)) ? "" : ", scalar",
(localPtr->flags & VAR_ARRAY) ? ", array" : "",
(localPtr->flags & VAR_LINK) ? ", link" : "",
(localPtr->flags & VAR_ARGUMENT) ? ", arg" : "",
(localPtr->flags & VAR_TEMPORARY) ? ", temp" : "",
(localPtr->flags & VAR_RESOLVED) ? ", resolved" : "");
if (TclIsVarTemporary(localPtr)) {
TclAppendLiteralToObj(bufferObj, "\n");
} else {
Tcl_AppendPrintfToObj(bufferObj, ", \"%s\"\n",
localPtr->name);
}
localPtr = localPtr->nextPtr;
}
}
|
| ︙ | ︙ | |||
387 388 389 390 391 392 393 |
* If there were no commands (e.g., an expression or an empty string was
* compiled), just print all instructions and return.
*/
if (numCmds == 0) {
pc = codeStart;
while (pc < codeLimit) {
| | | 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
* If there were no commands (e.g., an expression or an empty string was
* compiled), just print all instructions and return.
*/
if (numCmds == 0) {
pc = codeStart;
while (pc < codeLimit) {
TclAppendLiteralToObj(bufferObj, " ");
pc += FormatInstruction(codePtr, pc, bufferObj);
}
return bufferObj;
}
/*
* Print table showing the code offset, source offset, and source length
|
| ︙ | ︙ | |||
449 450 451 452 453 454 455 |
Tcl_AppendPrintfToObj(bufferObj, "%s%4" TCL_SIZE_MODIFIER "d: pc %d-%d, src %d-%d",
((i % 2)? " " : "\n "),
(i+1), codeOffset, (codeOffset + codeLen - 1),
srcOffset, (srcOffset + srcLen - 1));
}
if (numCmds > 0) {
| | | 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
Tcl_AppendPrintfToObj(bufferObj, "%s%4" TCL_SIZE_MODIFIER "d: pc %d-%d, src %d-%d",
((i % 2)? " " : "\n "),
(i+1), codeOffset, (codeOffset + codeLen - 1),
srcOffset, (srcOffset + srcLen - 1));
}
if (numCmds > 0) {
TclAppendLiteralToObj(bufferObj, "\n");
}
/*
* Print each instruction. If the instruction corresponds to the start of
* a command, print the command's source. Note that we don't need the code
* length here.
*/
|
| ︙ | ︙ | |||
498 499 500 501 502 503 504 |
}
/*
* Print instructions before command i.
*/
while ((pc-codeStart) < codeOffset) {
| | | | | 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
}
/*
* Print instructions before command i.
*/
while ((pc-codeStart) < codeOffset) {
TclAppendLiteralToObj(bufferObj, " ");
pc += FormatInstruction(codePtr, pc, bufferObj);
}
Tcl_AppendPrintfToObj(bufferObj, " Command %" TCL_SIZE_MODIFIER "d: ", i+1);
PrintSourceToObj(bufferObj, (codePtr->source + srcOffset),
TclMin(srcLen, 55));
TclAppendLiteralToObj(bufferObj, "\n");
}
if (pc < codeLimit) {
/*
* Print instructions after the last command.
*/
while (pc < codeLimit) {
TclAppendLiteralToObj(bufferObj, " ");
pc += FormatInstruction(codePtr, pc, bufferObj);
}
}
return bufferObj;
}
/*
|
| ︙ | ︙ | |||
652 653 654 655 656 657 658 |
break;
}
}
if (suffixObj) {
const char *bytes;
Tcl_Size length;
| | | | | | 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 |
break;
}
}
if (suffixObj) {
const char *bytes;
Tcl_Size length;
TclAppendLiteralToObj(bufferObj, "\t# ");
bytes = TclGetStringFromObj(codePtr->objArrayPtr[opnd], &length);
PrintSourceToObj(bufferObj, bytes, TclMin(length, 40));
} else if (suffixBuffer[0]) {
Tcl_AppendPrintfToObj(bufferObj, "\t# %s", suffixBuffer);
if (suffixSrc) {
PrintSourceToObj(bufferObj, suffixSrc, 40);
}
}
TclAppendLiteralToObj(bufferObj, "\n");
if (auxPtr && auxPtr->type->printProc) {
TclAppendLiteralToObj(bufferObj, "\t\t[");
auxPtr->type->printProc(auxPtr->clientData, bufferObj, codePtr,
pcOffset);
TclAppendLiteralToObj(bufferObj, "]\n");
}
return numBytes;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
864 865 866 867 868 869 870 |
const char *stringPtr, /* The string to print. */
Tcl_Size maxChars) /* Maximum number of chars to print. */
{
const char *p;
Tcl_Size i = 0, len;
if (stringPtr == NULL) {
| | | | | | | | | | | | 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 |
const char *stringPtr, /* The string to print. */
Tcl_Size maxChars) /* Maximum number of chars to print. */
{
const char *p;
Tcl_Size i = 0, len;
if (stringPtr == NULL) {
TclAppendLiteralToObj(appendObj, "\"\"");
return;
}
TclAppendLiteralToObj(appendObj, "\"");
p = stringPtr;
for (; (*p != '\0') && (i < maxChars); p+=len) {
int ucs4;
len = TclUtfToUniChar(p, &ucs4);
switch (ucs4) {
case '"':
TclAppendLiteralToObj(appendObj, "\\\"");
i += 2;
continue;
case '\f':
TclAppendLiteralToObj(appendObj, "\\f");
i += 2;
continue;
case '\n':
TclAppendLiteralToObj(appendObj, "\\n");
i += 2;
continue;
case '\r':
TclAppendLiteralToObj(appendObj, "\\r");
i += 2;
continue;
case '\t':
TclAppendLiteralToObj(appendObj, "\\t");
i += 2;
continue;
case '\v':
TclAppendLiteralToObj(appendObj, "\\v");
i += 2;
continue;
default:
if (ucs4 > 0xFFFF) {
Tcl_AppendPrintfToObj(appendObj, "\\U%08x", ucs4);
i += 10;
} else if (ucs4 < 0x20 || ucs4 >= 0x7F) {
Tcl_AppendPrintfToObj(appendObj, "\\u%04x", ucs4);
i += 6;
} else {
Tcl_AppendPrintfToObj(appendObj, "%c", ucs4);
i++;
}
continue;
}
}
if (*p != '\0') {
TclAppendLiteralToObj(appendObj, "...");
}
TclAppendLiteralToObj(appendObj, "\"");
}
/*
*----------------------------------------------------------------------
*
* DisassembleByteCodeAsDicts --
*
|
| ︙ | ︙ | |||
970 971 972 973 974 975 976 |
for (i=0 ; i<localCount ; i++,localPtr=localPtr->nextPtr) {
Tcl_Obj *descriptor[2];
TclNewObj(descriptor[0]);
if (!(localPtr->flags & (VAR_ARRAY|VAR_LINK))) {
Tcl_ListObjAppendElement(NULL, descriptor[0],
| | | | | | | | 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 |
for (i=0 ; i<localCount ; i++,localPtr=localPtr->nextPtr) {
Tcl_Obj *descriptor[2];
TclNewObj(descriptor[0]);
if (!(localPtr->flags & (VAR_ARRAY|VAR_LINK))) {
Tcl_ListObjAppendElement(NULL, descriptor[0],
TclNewString("scalar"));
}
if (localPtr->flags & VAR_ARRAY) {
Tcl_ListObjAppendElement(NULL, descriptor[0],
TclNewString("array"));
}
if (localPtr->flags & VAR_LINK) {
Tcl_ListObjAppendElement(NULL, descriptor[0],
TclNewString("link"));
}
if (localPtr->flags & VAR_ARGUMENT) {
Tcl_ListObjAppendElement(NULL, descriptor[0],
TclNewString("arg"));
}
if (localPtr->flags & VAR_TEMPORARY) {
Tcl_ListObjAppendElement(NULL, descriptor[0],
TclNewString("temp"));
}
if (localPtr->flags & VAR_RESOLVED) {
Tcl_ListObjAppendElement(NULL, descriptor[0],
TclNewString("resolved"));
}
if (localPtr->flags & VAR_TEMPORARY) {
Tcl_ListObjAppendElement(NULL, variables,
Tcl_NewListObj(1, descriptor));
} else {
descriptor[1] = Tcl_NewStringObj(localPtr->name, -1);
Tcl_ListObjAppendElement(NULL, variables,
|
| ︙ | ︙ | |||
1079 1080 1081 1082 1083 1084 1085 |
case OPERAND_IDX4:
val = TclGetInt4AtPtr(opnd);
opnd += 4;
if (val >= -1) {
Tcl_ListObjAppendElement(NULL, inst, Tcl_ObjPrintf(
".%d", val));
} else if (val == -2) {
| | < | 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 |
case OPERAND_IDX4:
val = TclGetInt4AtPtr(opnd);
opnd += 4;
if (val >= -1) {
Tcl_ListObjAppendElement(NULL, inst, Tcl_ObjPrintf(
".%d", val));
} else if (val == -2) {
Tcl_ListObjAppendElement(NULL, inst, TclNewString(".end"));
} else {
Tcl_ListObjAppendElement(NULL, inst, Tcl_ObjPrintf(
".end-%d", -2-val));
}
break;
case OPERAND_AUX4:
val = TclGetInt4AtPtr(opnd);
|
| ︙ | ︙ | |||
1330 1331 1332 1333 1334 1335 1336 |
if (objc != 3) {
Tcl_WrongNumArgs(interp, 2, objv, "procName");
return TCL_ERROR;
}
procPtr = TclFindProc((Interp *) interp, TclGetString(objv[2]));
if (procPtr == NULL) {
| | | | | | 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 |
if (objc != 3) {
Tcl_WrongNumArgs(interp, 2, objv, "procName");
return TCL_ERROR;
}
procPtr = TclFindProc((Interp *) interp, TclGetString(objv[2]));
if (procPtr == NULL) {
TclPrintfResult(interp,
"\"%s\" isn't a procedure", TclGetString(objv[2]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "PROC",
TclGetString(objv[2]));
return TCL_ERROR;
}
/*
* Compile (if uncompiled) and disassemble a procedure.
*/
|
| ︙ | ︙ | |||
1380 1381 1382 1383 1384 1385 1386 |
*/
oPtr = (Object *) Tcl_GetObjectFromObj(interp, objv[2]);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (oPtr->classPtr == NULL) {
| | | | | | | < | | | | | | | 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 |
*/
oPtr = (Object *) Tcl_GetObjectFromObj(interp, objv[2]);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (oPtr->classPtr == NULL) {
TclPrintfResult(interp,
"\"%s\" is not a class", TclGetString(objv[2]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "CLASS",
TclGetString(objv[2]));
return TCL_ERROR;
}
methodPtr = oPtr->classPtr->constructorPtr;
if (methodPtr == NULL) {
TclPrintfResult(interp,
"\"%s\" has no defined constructor", TclGetString(objv[2]));
TclSetErrorCode(interp, "TCL", "OPERATION", "DISASSEMBLE",
"CONSRUCTOR");
return TCL_ERROR;
}
procPtr = TclOOGetProcFromMethod(methodPtr);
if (procPtr == NULL) {
TclPrintfResult(interp,
"body not available for this kind of constructor");
TclSetErrorCode(interp, "TCL", "OPERATION", "DISASSEMBLE",
"METHODTYPE");
return TCL_ERROR;
}
/*
* Compile if necessary.
*/
|
| ︙ | ︙ | |||
1445 1446 1447 1448 1449 1450 1451 |
*/
oPtr = (Object *) Tcl_GetObjectFromObj(interp, objv[2]);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (oPtr->classPtr == NULL) {
| | | | | | | < | | | | | | | 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 |
*/
oPtr = (Object *) Tcl_GetObjectFromObj(interp, objv[2]);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (oPtr->classPtr == NULL) {
TclPrintfResult(interp,
"\"%s\" is not a class", TclGetString(objv[2]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "CLASS",
TclGetString(objv[2]));
return TCL_ERROR;
}
methodPtr = oPtr->classPtr->destructorPtr;
if (methodPtr == NULL) {
TclPrintfResult(interp,
"\"%s\" has no defined destructor", TclGetString(objv[2]));
TclSetErrorCode(interp, "TCL", "OPERATION", "DISASSEMBLE",
"DESRUCTOR");
return TCL_ERROR;
}
procPtr = TclOOGetProcFromMethod(methodPtr);
if (procPtr == NULL) {
TclPrintfResult(interp,
"body not available for this kind of destructor");
TclSetErrorCode(interp, "TCL", "OPERATION", "DISASSEMBLE",
"METHODTYPE");
return TCL_ERROR;
}
/*
* Compile if necessary.
*/
|
| ︙ | ︙ | |||
1510 1511 1512 1513 1514 1515 1516 |
*/
oPtr = (Object *) Tcl_GetObjectFromObj(interp, objv[2]);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (oPtr->classPtr == NULL) {
| | | | | | 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 |
*/
oPtr = (Object *) Tcl_GetObjectFromObj(interp, objv[2]);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (oPtr->classPtr == NULL) {
TclPrintfResult(interp,
"\"%s\" is not a class", TclGetString(objv[2]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "CLASS",
TclGetString(objv[2]));
return TCL_ERROR;
}
hPtr = Tcl_FindHashEntry(&oPtr->classPtr->classMethods,
objv[3]);
goto methodBody;
case DISAS_OBJECT_METHOD:
if (objc != 4) {
|
| ︙ | ︙ | |||
1545 1546 1547 1548 1549 1550 1551 |
/*
* Compile (if necessary) and disassemble a method body.
*/
methodBody:
if (hPtr == NULL) {
unknownMethod:
| | | | | | | | | | 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 |
/*
* Compile (if necessary) and disassemble a method body.
*/
methodBody:
if (hPtr == NULL) {
unknownMethod:
TclPrintfResult(interp,
"unknown method \"%s\"", TclGetString(objv[3]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD",
TclGetString(objv[3]));
return TCL_ERROR;
}
procPtr = TclOOGetProcFromMethod((Method *)Tcl_GetHashValue(hPtr));
if (procPtr == NULL) {
TclPrintfResult(interp,
"body not available for this kind of method");
TclSetErrorCode(interp, "TCL", "OPERATION", "DISASSEMBLE",
"METHODTYPE");
return TCL_ERROR;
}
if (!TclHasInternalRep(procPtr->bodyPtr, &tclByteCodeType)) {
Command cmd;
/*
* Yes, this is ugly, but we need to pass the namespace in to the
|
| ︙ | ︙ | |||
1590 1591 1592 1593 1594 1595 1596 |
/*
* Do the actual disassembly.
*/
ByteCodeGetInternalRep(codeObjPtr, &tclByteCodeType, codePtr);
if (codePtr->flags & TCL_BYTECODE_PRECOMPILED) {
| < | | < | 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 |
/*
* Do the actual disassembly.
*/
ByteCodeGetInternalRep(codeObjPtr, &tclByteCodeType, codePtr);
if (codePtr->flags & TCL_BYTECODE_PRECOMPILED) {
TclPrintfResult(interp, "may not disassemble prebuilt bytecode");
TclSetErrorCode(interp, "TCL", "OPERATION", "DISASSEMBLE", "BYTECODE");
return TCL_ERROR;
}
if (clientData) {
Tcl_SetObjResult(interp,
DisassembleByteCodeAsDicts(codeObjPtr));
} else {
Tcl_SetObjResult(interp,
|
| ︙ | ︙ |
Changes to generic/tclEncoding.c.
| ︙ | ︙ | |||
1241 1242 1243 1244 1245 1246 1247 |
? TCL_INDEX_NONE : nBytesProcessed;
} else {
/* Caller wants error message on failure */
if (result != TCL_OK && interp != NULL) {
char buf[TCL_INTEGER_SPACE];
snprintf(buf, sizeof(buf), "%" TCL_SIZE_MODIFIER "d",
nBytesProcessed);
| | | | | < | 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 |
? TCL_INDEX_NONE : nBytesProcessed;
} else {
/* Caller wants error message on failure */
if (result != TCL_OK && interp != NULL) {
char buf[TCL_INTEGER_SPACE];
snprintf(buf, sizeof(buf), "%" TCL_SIZE_MODIFIER "d",
nBytesProcessed);
TclPrintfResult(interp,
"unexpected byte sequence starting at index %"
TCL_SIZE_MODIFIER "d: '\\x%02X'",
nBytesProcessed, UCHAR(srcStart[nBytesProcessed]));
TclSetErrorCode(interp,
"TCL", "ENCODING", "ILLEGALSEQUENCE", buf);
}
}
if (result != TCL_OK) {
errno = (result == TCL_CONVERT_NOSPACE) ? ENOMEM : EILSEQ;
}
return result;
}
|
| ︙ | ︙ | |||
1564 1565 1566 1567 1568 1569 1570 | Tcl_Size pos = Tcl_NumUtfChars(srcStart, nBytesProcessed); int ucs4; char buf[TCL_INTEGER_SPACE]; TclUtfToUniChar(&srcStart[nBytesProcessed], &ucs4); snprintf(buf, sizeof(buf), "%" TCL_SIZE_MODIFIER "d", nBytesProcessed); | | | > | < | 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 |
Tcl_Size pos = Tcl_NumUtfChars(srcStart, nBytesProcessed);
int ucs4;
char buf[TCL_INTEGER_SPACE];
TclUtfToUniChar(&srcStart[nBytesProcessed], &ucs4);
snprintf(buf, sizeof(buf), "%" TCL_SIZE_MODIFIER "d",
nBytesProcessed);
TclPrintfResult(interp,
"unexpected character at index %" TCL_SIZE_MODIFIER
"u: 'U+%06X'",
pos, ucs4);
TclSetErrorCode(interp,
"TCL", "ENCODING", "ILLEGALSEQUENCE", buf);
}
}
if (result != TCL_OK) {
errno = (result == TCL_CONVERT_NOSPACE) ? ENOMEM : EILSEQ;
}
return result;
}
|
| ︙ | ︙ | |||
1821 1822 1823 1824 1825 1826 1827 |
map = Tcl_DuplicateObj(TclGetProcessGlobalValue(&encodingFileMap));
TclDictPut(NULL, map, name, dir[i]);
TclSetProcessGlobalValue(&encodingFileMap, map);
}
}
if ((NULL == chan) && (interp != NULL)) {
| < | | | 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 |
map = Tcl_DuplicateObj(TclGetProcessGlobalValue(&encodingFileMap));
TclDictPut(NULL, map, name, dir[i]);
TclSetProcessGlobalValue(&encodingFileMap, map);
}
}
if ((NULL == chan) && (interp != NULL)) {
TclPrintfResult(interp, "unknown encoding \"%s\"", name);
TclSetErrorCode(interp, "TCL", "LOOKUP", "ENCODING", name);
}
Tcl_DecrRefCount(fileNameObj);
Tcl_DecrRefCount(searchPath);
return chan;
}
|
| ︙ | ︙ | |||
1895 1896 1897 1898 1899 1900 1901 |
encoding = LoadTableEncoding(name, ENCODING_MULTIBYTE, chan);
break;
case 'E':
encoding = LoadEscapeEncoding(name, chan);
break;
}
if ((encoding == NULL) && (interp != NULL)) {
| < | | | 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 |
encoding = LoadTableEncoding(name, ENCODING_MULTIBYTE, chan);
break;
case 'E':
encoding = LoadEscapeEncoding(name, chan);
break;
}
if ((encoding == NULL) && (interp != NULL)) {
TclPrintfResult(interp, "invalid encoding file \"%s\"", name);
TclSetErrorCode(interp, "TCL", "LOOKUP", "ENCODING", name);
}
Tcl_CloseEx(NULL, chan, 0);
return encoding;
}
/*
|
| ︙ | ︙ | |||
4530 4531 4532 4533 4534 4535 4536 |
}
}
if (interp) {
/* This code assumes at least two profiles :-) */
Tcl_Obj *errorObj = Tcl_ObjPrintf("bad profile name \"%s\": must be",
profileName);
for (i = 0; i < (numProfiles - 1); ++i) {
| < | | | < | | 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 |
}
}
if (interp) {
/* This code assumes at least two profiles :-) */
Tcl_Obj *errorObj = Tcl_ObjPrintf("bad profile name \"%s\": must be",
profileName);
for (i = 0; i < (numProfiles - 1); ++i) {
TclAppendStringsToObj(errorObj, " ", encodingProfiles[i].name, ",");
}
TclAppendStringsToObj(errorObj,
" or ", encodingProfiles[numProfiles-1].name);
Tcl_SetObjResult(interp, errorObj);
TclSetErrorCode(interp, "TCL", "ENCODING", "PROFILE", profileName);
}
return TCL_ERROR;
}
/*
*------------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
4571 4572 4573 4574 4575 4576 4577 |
for (i = 0; i < sizeof(encodingProfiles) / sizeof(encodingProfiles[0]); ++i) {
if (profileValue == encodingProfiles[i].value) {
return encodingProfiles[i].name;
}
}
if (interp) {
| | | < | | 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 |
for (i = 0; i < sizeof(encodingProfiles) / sizeof(encodingProfiles[0]); ++i) {
if (profileValue == encodingProfiles[i].value) {
return encodingProfiles[i].name;
}
}
if (interp) {
TclPrintfResult(interp,
"Internal error. Bad profile id \"%d\".", profileValue);
TclSetErrorCode(interp, "TCL", "ENCODING", "PROFILEID");
}
return NULL;
}
/*
*------------------------------------------------------------------------
*
|
| ︙ | ︙ |
Changes to generic/tclEnsemble.c.
| ︙ | ︙ | |||
156 157 158 159 160 161 162 |
{
Namespace *nsPtr = (Namespace *) TclGetCurrentNamespace(interp);
Tcl_Command token; /* The ensemble command. */
enum EnsSubcmds index;
if (nsPtr == NULL || nsPtr->flags & NS_DEAD) {
if (!Tcl_InterpDeleted(interp)) {
| | | < | | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
{
Namespace *nsPtr = (Namespace *) TclGetCurrentNamespace(interp);
Tcl_Command token; /* The ensemble command. */
enum EnsSubcmds index;
if (nsPtr == NULL || nsPtr->flags & NS_DEAD) {
if (!Tcl_InterpDeleted(interp)) {
TclPrintfResult(interp,
"tried to manipulate ensemble of deleted namespace");
TclSetErrorCode(interp, "TCL", "ENSEMBLE", "DEAD");
}
return TCL_ERROR;
}
if (objc < 2) {
Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?arg ...?");
return TCL_ERROR;
|
| ︙ | ︙ | |||
330 331 332 333 334 335 336 |
const char *cmd;
if (TclListObjGetElements(interp, listObj, &len,
&listv) != TCL_OK) {
goto mapError;
}
if (len < 1) {
| | | | < | | 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
const char *cmd;
if (TclListObjGetElements(interp, listObj, &len,
&listv) != TCL_OK) {
goto mapError;
}
if (len < 1) {
TclPrintfResult(interp,
"ensemble subcommand implementations "
"must be non-empty lists");
TclSetErrorCode(interp, "TCL", "ENSEMBLE", "EMPTY_TARGET");
goto mapError;
}
cmd = TclGetString(listv[0]);
if (!(cmd[0] == ':' && cmd[1] == ':')) {
Tcl_Obj *newList = Tcl_NewListObj(len, listv);
Tcl_Obj *newCmd = TclNewNamespaceObj(
(Tcl_Namespace *) nsPtr);
if (nsPtr->parentPtr) {
TclAppendLiteralToObj(newCmd, "::");
}
Tcl_AppendObjToObj(newCmd, listv[0]);
Tcl_ListObjReplace(NULL, newList, 0, 1, 1, &newCmd);
if (patchedDict == NULL) {
patchedDict = Tcl_DuplicateObj(objv[1]);
}
Tcl_DictObjPut(NULL, patchedDict, subcmdWordsObj, newList);
|
| ︙ | ︙ | |||
648 649 650 651 652 653 654 |
}
do {
if (TclListObjLength(interp, listObj, &len) != TCL_OK) {
goto finishSearchAndError;
}
if (len < 1) {
| | | | < | | 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 |
}
do {
if (TclListObjLength(interp, listObj, &len) != TCL_OK) {
goto finishSearchAndError;
}
if (len < 1) {
TclPrintfResult(interp,
"ensemble subcommand implementations "
"must be non-empty lists");
TclSetErrorCode(interp, "TCL", "ENSEMBLE", "EMPTY_TARGET");
goto finishSearchAndError;
}
if (TclListObjGetElements(interp, listObj, &len,
&listv) != TCL_OK) {
goto finishSearchAndError;
}
cmd = TclGetString(listv[0]);
if (!(cmd[0] == ':' && cmd[1] == ':')) {
Tcl_Obj *newList = Tcl_DuplicateObj(listObj);
Tcl_Obj *newCmd = TclNewNamespaceObj(
(Tcl_Namespace*) nsPtr);
if (nsPtr->parentPtr) {
TclAppendLiteralToObj(newCmd, "::");
}
Tcl_AppendObjToObj(newCmd, listv[0]);
Tcl_ListObjReplace(NULL, newList, 0, 1, 1, &newCmd);
if (patchedDict == NULL) {
patchedDict = Tcl_DuplicateObj(objv[1]);
}
Tcl_DictObjPut(NULL, patchedDict, subcmdWordsObj, newList);
|
| ︙ | ︙ | |||
694 695 696 697 698 699 700 |
Tcl_DictObjDone(&search);
if (patchedDict) {
Tcl_DecrRefCount(patchedDict);
}
goto freeMapAndError;
}
case CONF_NAMESPACE:
| < | | < | 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
Tcl_DictObjDone(&search);
if (patchedDict) {
Tcl_DecrRefCount(patchedDict);
}
goto freeMapAndError;
}
case CONF_NAMESPACE:
TclPrintfResult(interp, "option -namespace is read-only");
TclSetErrorCode(interp, "TCL", "ENSEMBLE", "READ_ONLY");
goto freeMapAndError;
case CONF_PREFIX:
if (Tcl_GetBooleanFromObj(interp, objv[1],
&permitPrefix) != TCL_OK) {
goto freeMapAndError;
}
continue;
|
| ︙ | ︙ | |||
866 867 868 869 870 871 872 |
Tcl_Interp *interp, /* Where to report an error. May be NULL. */
Tcl_Command token) /* What to check for ensemble-ness. */
{
Command *cmdPtr = (Command *) token;
if (cmdPtr->objProc != TclEnsembleImplementationCmd) {
if (interp != NULL) {
| < | < | | 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 |
Tcl_Interp *interp, /* Where to report an error. May be NULL. */
Tcl_Command token) /* What to check for ensemble-ness. */
{
Command *cmdPtr = (Command *) token;
if (cmdPtr->objProc != TclEnsembleImplementationCmd) {
if (interp != NULL) {
TclPrintfResult(interp, "command is not an ensemble");
TclSetErrorCode(interp, "TCL", "ENSEMBLE", "NOT_ENSEMBLE");
}
return NULL;
}
return (EnsembleConfig *) cmdPtr->objClientData;
}
/*
|
| ︙ | ︙ | |||
1081 1082 1083 1084 1085 1086 1087 |
if (Tcl_ListObjIndex(interp, valuePtr, 0, &cmdObjPtr) != TCL_OK) {
Tcl_DictObjDone(&search);
return TCL_ERROR;
}
bytes = TclGetString(cmdObjPtr);
if (bytes[0] != ':' || bytes[1] != ':') {
| | | < | < | 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 |
if (Tcl_ListObjIndex(interp, valuePtr, 0, &cmdObjPtr) != TCL_OK) {
Tcl_DictObjDone(&search);
return TCL_ERROR;
}
bytes = TclGetString(cmdObjPtr);
if (bytes[0] != ':' || bytes[1] != ':') {
TclPrintfResult(interp,
"ensemble target is not a fully-qualified command");
TclSetErrorCode(interp, "TCL", "ENSEMBLE", "UNQUALIFIED_TARGET");
Tcl_DictObjDone(&search);
return TCL_ERROR;
}
}
if (size < 1) {
mapDict = NULL;
|
| ︙ | ︙ | |||
1487 1488 1489 1490 1491 1492 1493 |
*/
token = TclGetOriginalCommand(token);
if (token == NULL ||
((Command *) token)->objProc != TclEnsembleImplementationCmd) {
if (flags & TCL_LEAVE_ERR_MSG) {
| | | | | | 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 |
*/
token = TclGetOriginalCommand(token);
if (token == NULL ||
((Command *) token)->objProc != TclEnsembleImplementationCmd) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclPrintfResult(interp,
"\"%s\" is not an ensemble command",
TclGetString(cmdNameObj));
TclSetErrorCode(interp, "TCL", "LOOKUP", "ENSEMBLE",
TclGetString(cmdNameObj));
}
return NULL;
}
}
return token;
}
|
| ︙ | ︙ | |||
1788 1789 1790 1791 1792 1793 1794 |
if (ensemblePtr->nsPtr->flags & NS_DEAD) {
/*
* Don't know how we got here, but make things give up quickly.
*/
if (!Tcl_InterpDeleted(interp)) {
| < | < | | 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 |
if (ensemblePtr->nsPtr->flags & NS_DEAD) {
/*
* Don't know how we got here, but make things give up quickly.
*/
if (!Tcl_InterpDeleted(interp)) {
TclPrintfResult(interp, "ensemble activated for deleted namespace");
TclSetErrorCode(interp, "TCL", "ENSEMBLE", "DEAD");
}
return TCL_ERROR;
}
/*
* If the table of subcommands is valid just lookup up the command there
* and go to dispatch.
|
| ︙ | ︙ | |||
1949 1950 1951 1952 1953 1954 1955 | Tcl_ListObjReplace(NULL, copyPtr, LIST_MAX, 0, ensemblePtr->numParameters, objv + 1); Tcl_ListObjReplace(NULL, copyPtr, LIST_MAX, 0, objc - 2 - ensemblePtr->numParameters, objv + 2 + ensemblePtr->numParameters); } Tcl_IncrRefCount(copyPtr); | | | < | 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 |
Tcl_ListObjReplace(NULL, copyPtr, LIST_MAX, 0,
ensemblePtr->numParameters, objv + 1);
Tcl_ListObjReplace(NULL, copyPtr, LIST_MAX, 0,
objc - 2 - ensemblePtr->numParameters,
objv + 2 + ensemblePtr->numParameters);
}
Tcl_IncrRefCount(copyPtr);
TclNRAddCallback(interp, TclNRReleaseValues, copyPtr);
TclDecrRefCount(prefixObj);
/*
* Record the words of the command as given so that routines like
* Tcl_WrongNumArgs can produce the correct error message. Parameters
* count both as inserted and removed arguments.
*/
if (TclInitRewriteEnsemble(interp, 2 + ensemblePtr->numParameters,
prefixObjc + ensemblePtr->numParameters, objv)) {
TclNRAddCallback(interp, TclClearRootEnsemble);
}
/*
* Hand off to the target command.
*/
TclSkipTailcall(interp);
|
| ︙ | ︙ | |||
2001 2002 2003 2004 2005 2006 2007 |
* Could not find a routine for the named subcommand so generate a standard
* failure message. The one odd case compared with a standard
* ensemble-like command is where a namespace has no exported commands at
* all...
*/
Tcl_ResetResult(interp);
| | < | | | | 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 |
* Could not find a routine for the named subcommand so generate a standard
* failure message. The one odd case compared with a standard
* ensemble-like command is where a namespace has no exported commands at
* all...
*/
Tcl_ResetResult(interp);
TclSetErrorCode(interp, "TCL", "LOOKUP", "SUBCOMMAND", TclGetString(subObj));
if (ensemblePtr->subcommandTable.numEntries == 0) {
TclPrintfResult(interp,
"unknown subcommand \"%s\": namespace %s does not"
" export any commands", TclGetString(subObj),
ensemblePtr->nsPtr->fullName);
return TCL_ERROR;
}
errorObj = Tcl_ObjPrintf("unknown%s subcommand \"%s\": must be ",
(ensemblePtr->flags & TCL_ENSEMBLE_PREFIX ? " or ambiguous" : ""),
TclGetString(subObj));
if (ensemblePtr->subcommandTable.numEntries == 1) {
Tcl_AppendToObj(errorObj, ensemblePtr->subcommandArrayPtr[0],
TCL_AUTO_LENGTH);
} else {
Tcl_Size i;
for (i=0 ; i<ensemblePtr->subcommandTable.numEntries-1 ; i++) {
Tcl_AppendToObj(errorObj, ensemblePtr->subcommandArrayPtr[i],
TCL_AUTO_LENGTH);
TclAppendLiteralToObj(errorObj, ", ");
}
Tcl_AppendPrintfToObj(errorObj, "or %s",
ensemblePtr->subcommandArrayPtr[i]);
}
Tcl_SetObjResult(interp, errorObj);
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
2239 2240 2241 2242 2243 2244 2245 | */ tmp[0] = NULL; tmp[1] = (Tcl_Obj *) iPtr->ensembleRewrite.sourceObjs; tmp[2] = (Tcl_Obj *) store; iPtr->ensembleRewrite.sourceObjs = (Tcl_Obj *const *) tmp; | | | | 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 |
*/
tmp[0] = NULL;
tmp[1] = (Tcl_Obj *) iPtr->ensembleRewrite.sourceObjs;
tmp[2] = (Tcl_Obj *) store;
iPtr->ensembleRewrite.sourceObjs = (Tcl_Obj *const *) tmp;
TclNRAddCallback(interp, FreeER, tmp, store);
}
store[idx] = fix;
Tcl_IncrRefCount(fix);
TclNRAddCallback(interp, TclNRReleaseValues, fix);
}
/*
*----------------------------------------------------------------------
*
* TclEnsembleGetRewriteValues --
*
|
| ︙ | ︙ | |||
2373 2374 2375 2376 2377 2378 2379 |
*/
Tcl_Preserve(ensemblePtr);
TclSkipTailcall(interp);
result = Tcl_EvalObjv(interp, paramc, paramv, 0);
if ((result == TCL_OK) && (ensemblePtr->flags & ENSEMBLE_DEAD)) {
if (!Tcl_InterpDeleted(interp)) {
| | | < | < | 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 |
*/
Tcl_Preserve(ensemblePtr);
TclSkipTailcall(interp);
result = Tcl_EvalObjv(interp, paramc, paramv, 0);
if ((result == TCL_OK) && (ensemblePtr->flags & ENSEMBLE_DEAD)) {
if (!Tcl_InterpDeleted(interp)) {
TclPrintfResult(interp,
"unknown subcommand handler deleted its ensemble");
TclSetErrorCode(interp, "TCL", "ENSEMBLE", "UNKNOWN_DELETED");
}
result = TCL_ERROR;
}
Tcl_Release(ensemblePtr);
/*
* On success the result is a list of words that form the command to be
|
| ︙ | ︙ | |||
2422 2423 2424 2425 2426 2427 2428 |
/*
* Convert exceptional result to an error.
*/
if (!Tcl_InterpDeleted(interp)) {
if (result != TCL_ERROR) {
Tcl_ResetResult(interp);
| | | < | < | < | < | < | 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 |
/*
* Convert exceptional result to an error.
*/
if (!Tcl_InterpDeleted(interp)) {
if (result != TCL_ERROR) {
Tcl_ResetResult(interp);
TclPrintfResult(interp,
"unknown subcommand handler returned bad code: ");
switch (result) {
case TCL_RETURN:
TclAppendLiteralToObj(Tcl_GetObjResult(interp), "return");
break;
case TCL_BREAK:
TclAppendLiteralToObj(Tcl_GetObjResult(interp), "break");
break;
case TCL_CONTINUE:
TclAppendLiteralToObj(Tcl_GetObjResult(interp), "continue");
break;
default:
Tcl_AppendPrintfToObj(Tcl_GetObjResult(interp), "%d", result);
}
Tcl_AddErrorInfo(interp, "\n result of "
"ensemble unknown subcommand handler: ");
Tcl_AppendObjToErrorInfo(interp, unknownCmd);
TclSetErrorCode(interp, "TCL", "ENSEMBLE", "UNKNOWN_RESULT");
} else {
Tcl_AddErrorInfo(interp,
"\n (ensemble unknown subcommand handler)");
}
}
TclDecrRefCount(unknownCmd);
return TCL_ERROR;
|
| ︙ | ︙ | |||
2777 2778 2779 2780 2781 2782 2783 |
* content!
*/
if (isNew) {
Tcl_Obj *cmdObj, *cmdPrefixObj;
TclNewObj(cmdObj);
| | | | 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 |
* content!
*/
if (isNew) {
Tcl_Obj *cmdObj, *cmdPrefixObj;
TclNewObj(cmdObj);
TclAppendStringsToObj(cmdObj,
ensemblePtr->nsPtr->fullName,
(ensemblePtr->nsPtr->parentPtr ? "::" : ""),
nsCmdName);
cmdPrefixObj = Tcl_NewListObj(1, &cmdObj);
Tcl_SetHashValue(hPtr, cmdPrefixObj);
Tcl_IncrRefCount(cmdPrefixObj);
}
break;
}
}
|
| ︙ | ︙ |
Changes to generic/tclEvent.c.
| ︙ | ︙ | |||
340 341 342 343 344 345 346 |
/*
* Check for a valid return options dictionary.
*/
result = TclDictGet(NULL, objv[2], "-level", &valuePtr);
if (result != TCL_OK || valuePtr == NULL) {
| < | | < | | | 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
/*
* Check for a valid return options dictionary.
*/
result = TclDictGet(NULL, objv[2], "-level", &valuePtr);
if (result != TCL_OK || valuePtr == NULL) {
TclPrintfResult(interp, "missing return option \"-level\"");
TclSetErrorCode(interp, "TCL", "ARGUMENT", "MISSING");
return TCL_ERROR;
}
if (Tcl_GetIntFromObj(interp, valuePtr, &level) == TCL_ERROR) {
return TCL_ERROR;
}
result = TclDictGet(NULL, objv[2], "-code", &valuePtr);
if (result != TCL_OK || valuePtr == NULL) {
TclPrintfResult(interp, "missing return option \"-code\"");
TclSetErrorCode(interp, "TCL", "ARGUMENT", "MISSING");
return TCL_ERROR;
}
if (Tcl_GetIntFromObj(interp, valuePtr, &code) == TCL_ERROR) {
return TCL_ERROR;
}
if (level != 0) {
|
| ︙ | ︙ | |||
1560 1561 1562 1563 1564 1565 1566 |
case OPT_NO_WEVTS:
mask &= ~TCL_WINDOW_EVENTS;
break;
case OPT_TIMEOUT:
if (++i >= objc) {
needArg:
Tcl_ResetResult(interp);
| | | | < | | | 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 |
case OPT_NO_WEVTS:
mask &= ~TCL_WINDOW_EVENTS;
break;
case OPT_TIMEOUT:
if (++i >= objc) {
needArg:
Tcl_ResetResult(interp);
TclPrintfResult(interp,
"argument required for \"%s\"", vWaitOptionStrings[index]);
TclSetErrorCode(interp, "TCL", "EVENT", "ARGUMENT");
result = TCL_ERROR;
goto done;
}
if (Tcl_GetIntFromObj(interp, objv[i], &timeout) != TCL_OK) {
result = TCL_ERROR;
goto done;
}
if (timeout < 0) {
Tcl_ResetResult(interp);
TclPrintfResult(interp, "timeout must be positive");
TclSetErrorCode(interp, "TCL", "EVENT", "NEGTIME");
result = TCL_ERROR;
goto done;
}
break;
case OPT_LAST:
i++;
goto endOfOptionLoop;
|
| ︙ | ︙ | |||
1608 1609 1610 1611 1612 1613 1614 |
}
if (TclGetChannelFromObj(interp, objv[i], &chan, &mode, 0)
!= TCL_OK) {
result = TCL_ERROR;
goto done;
}
if (!(mode & TCL_READABLE)) {
| | | | 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 |
}
if (TclGetChannelFromObj(interp, objv[i], &chan, &mode, 0)
!= TCL_OK) {
result = TCL_ERROR;
goto done;
}
if (!(mode & TCL_READABLE)) {
TclPrintfResult(interp,
"channel \"%s\" wasn't open for reading",
TclGetString(objv[i]));
result = TCL_ERROR;
goto done;
}
Tcl_CreateChannelHandler(chan, TCL_READABLE,
VwaitChannelReadProc, &vwaitItems[numItems]);
vwaitItems[numItems].donePtr = &done;
vwaitItems[numItems].sequence = -1;
|
| ︙ | ︙ | |||
1632 1633 1634 1635 1636 1637 1638 |
}
if (TclGetChannelFromObj(interp, objv[i], &chan, &mode, 0)
!= TCL_OK) {
result = TCL_ERROR;
goto done;
}
if (!(mode & TCL_WRITABLE)) {
| | | < | | < | | | 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 |
}
if (TclGetChannelFromObj(interp, objv[i], &chan, &mode, 0)
!= TCL_OK) {
result = TCL_ERROR;
goto done;
}
if (!(mode & TCL_WRITABLE)) {
TclPrintfResult(interp,
"channel \"%s\" wasn't open for writing",
TclGetString(objv[i]));
result = TCL_ERROR;
goto done;
}
Tcl_CreateChannelHandler(chan, TCL_WRITABLE,
VwaitChannelWriteProc, &vwaitItems[numItems]);
vwaitItems[numItems].donePtr = &done;
vwaitItems[numItems].sequence = -1;
vwaitItems[numItems].mask = TCL_WRITABLE;
vwaitItems[numItems].sourceObj = objv[i];
numItems++;
break;
}
}
endOfOptionLoop:
if ((mask & (TCL_FILE_EVENTS | TCL_IDLE_EVENTS |
TCL_TIMER_EVENTS | TCL_WINDOW_EVENTS)) == 0) {
TclPrintfResult(interp, "can't wait: would block forever");
TclSetErrorCode(interp, "TCL", "EVENT", "NO_SOURCES");
result = TCL_ERROR;
goto done;
}
if ((timeout > 0) && ((mask & TCL_TIMER_EVENTS) == 0)) {
TclPrintfResult(interp, "timer events disabled with timeout specified");
TclSetErrorCode(interp, "TCL", "EVENT", "NO_TIME");
result = TCL_ERROR;
goto done;
}
for (result = TCL_OK; i < objc; i++) {
result = Tcl_TraceVar2(interp, TclGetString(objv[i]), NULL,
TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
|
| ︙ | ︙ | |||
1688 1689 1690 1691 1692 1693 1694 |
result = TCL_ERROR;
goto done;
}
if (!(mask & TCL_FILE_EVENTS)) {
for (i = 0; i < numItems; i++) {
if (vwaitItems[i].mask) {
| | | | | 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 |
result = TCL_ERROR;
goto done;
}
if (!(mask & TCL_FILE_EVENTS)) {
for (i = 0; i < numItems; i++) {
if (vwaitItems[i].mask) {
TclPrintfResult(interp,
"file events disabled with channel(s) specified");
TclSetErrorCode(interp, "TCL", "EVENT", "NO_FILE_EVENT");
result = TCL_ERROR;
goto done;
}
}
}
if (timeout > 0) {
|
| ︙ | ︙ | |||
1728 1729 1730 1731 1732 1733 1734 |
((!any && (done < numItems)) || (any && !done))) {
foundEvent = Tcl_DoOneEvent(mask);
if (Tcl_Canceled(interp, TCL_LEAVE_ERR_MSG) == TCL_ERROR) {
break;
}
if (Tcl_LimitExceeded(interp)) {
Tcl_ResetResult(interp);
| | | < | | < | | 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 |
((!any && (done < numItems)) || (any && !done))) {
foundEvent = Tcl_DoOneEvent(mask);
if (Tcl_Canceled(interp, TCL_LEAVE_ERR_MSG) == TCL_ERROR) {
break;
}
if (Tcl_LimitExceeded(interp)) {
Tcl_ResetResult(interp);
TclPrintfResult(interp, "limit exceeded");
TclSetErrorCode(interp, "TCL", "EVENT", "LIMIT");
break;
}
if ((numItems == 0) && (timeout == 0)) {
/*
* Behavior like "update": clear interpreter's result because
* event handlers could have executed commands.
*/
Tcl_ResetResult(interp);
result = TCL_OK;
goto done;
}
}
if (!foundEvent) {
Tcl_ResetResult(interp);
TclPrintfResult(interp, "can't wait%s: would wait forever",
(numItems == 0) ? "" : " for variable(s)/channel(s)");
TclSetErrorCode(interp, "TCL", "EVENT", "NO_SOURCES");
result = TCL_ERROR;
goto done;
}
if (!done && !timedOut) {
/*
* The interpreter's result was already set to the right error message
|
| ︙ | ︙ | |||
1976 1977 1978 1979 1980 1981 1982 |
while (Tcl_DoOneEvent(flags) != 0) {
if (Tcl_Canceled(interp, TCL_LEAVE_ERR_MSG) == TCL_ERROR) {
return TCL_ERROR;
}
if (Tcl_LimitExceeded(interp)) {
Tcl_ResetResult(interp);
| | | 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 |
while (Tcl_DoOneEvent(flags) != 0) {
if (Tcl_Canceled(interp, TCL_LEAVE_ERR_MSG) == TCL_ERROR) {
return TCL_ERROR;
}
if (Tcl_LimitExceeded(interp)) {
Tcl_ResetResult(interp);
TclPrintfResult(interp, "limit exceeded");
return TCL_ERROR;
}
}
/*
* Must clear the interpreter's result because event handlers could have
* executed commands.
|
| ︙ | ︙ |
Changes to generic/tclExecute.c.
| ︙ | ︙ | |||
116 117 118 119 120 121 122 |
CmdFrame cmdFrame; /* codePtr was received for NR execution. */
Tcl_Obj *stack[1]; /* Start of the actual combined catch and obj
* stacks; the struct will be expanded as
* necessary */
} TEBCdata;
#define TEBC_YIELD() \
| | | | < | 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
CmdFrame cmdFrame; /* codePtr was received for NR execution. */
Tcl_Obj *stack[1]; /* Start of the actual combined catch and obj
* stacks; the struct will be expanded as
* necessary */
} TEBCdata;
#define TEBC_YIELD() \
do { \
esPtr->tosPtr = tosPtr; \
TclNRAddCallback(interp, TEBCresume, TD, pc, INT2PTR(cleanup)); \
} while (0)
#define TEBC_DATA_DIG() \
do { \
tosPtr = esPtr->tosPtr; \
} while (0)
|
| ︙ | ︙ | |||
366 367 368 369 370 371 372 | #define OBJ_AT_DEPTH(n) tosPtr[-(n)] #define CURR_DEPTH (tosPtr - initTosPtr) #define STACK_BASE(esPtr) ((esPtr)->stackWords - 1) /* | | | | > | < | > > | > | | | | | | < < < < < < | | | | > > | 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
#define OBJ_AT_DEPTH(n) tosPtr[-(n)]
#define CURR_DEPTH (tosPtr - initTosPtr)
#define STACK_BASE(esPtr) ((esPtr)->stackWords - 1)
/*
* Macros used to trace instruction execution. The macros TRACE, TRACE_APPEND,
* TRACE_ERROR, TRACE_RESULT, and O2S are only used inside
* TclNRExecuteByteCode. O2S is only used in TRACE* calls to get a string from
* an object. TRACE_INST is part of the implementation of these macros.
*/
#ifdef TCL_COMPILE_DEBUG
# define TRACE_INST() \
fprintf(stdout, "%2" TCL_SIZE_MODIFIER "d: %2" TCL_T_MODIFIER \
"d (%" TCL_T_MODIFIER "d) %s ", iPtr->numLevels, \
CURR_DEPTH, \
(pc - codePtr->codeStart), \
GetOpcodeName(pc))
# define TRACE(format, ...) \
while (traceInstructions) { \
TRACE_INST(); \
printf(format __VA_OPT__(,) __VA_ARGS__); \
break; \
}
# define TRACE_APPEND(format, ...) \
while (traceInstructions) { \
printf(format __VA_OPT__(,) __VA_ARGS__); \
break; \
}
# define TRACE_ERROR(interp) \
TRACE_APPEND("ERROR: %.30s\n", O2S(Tcl_GetObjResult(interp)));
# define TRACE_RESULT(objPtr) \
while (traceInstructions) { \
TclPrintObject(stdout, objPtr, 30); \
fprintf(stdout, "\n"); \
break; \
}
# define O2S(objPtr) \
(objPtr ? TclGetString(objPtr) : "")
#else /* !TCL_COMPILE_DEBUG */
# define TRACE(format, ...)
# define TRACE_APPEND(format, ...)
# define TRACE_ERROR(interp)
# define TRACE_RESULT(objPtr)
# define O2S(objPtr)
#endif /* TCL_COMPILE_DEBUG */
/*
* DTrace instruction probe macros. If USE_DTRACE isn't defined, we hard
* disable these; dtracing is very very expensive.
*/
#ifdef USE_DTRACE
#define TCL_DTRACE_INST_NEXT() \
do { \
if (TCL_DTRACE_INST_DONE_ENABLED()) { \
if (curInstName) { \
TCL_DTRACE_INST_DONE(curInstName, (int) CURR_DEPTH, \
tosPtr); \
} \
|
| ︙ | ︙ | |||
438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
} while (0)
#define TCL_DTRACE_INST_LAST() \
do { \
if (TCL_DTRACE_INST_DONE_ENABLED() && curInstName) { \
TCL_DTRACE_INST_DONE(curInstName, (int) CURR_DEPTH, tosPtr);\
} \
} while (0)
/*
* Macro used in this file to save a function call for common uses of
* Tcl_GetNumberFromObj(). The ANSI C "prototype" is:
*
* MODULE_SCOPE int GetNumberFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
* void **ptrPtr, int *tPtr);
| > > > > | 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
} while (0)
#define TCL_DTRACE_INST_LAST() \
do { \
if (TCL_DTRACE_INST_DONE_ENABLED() && curInstName) { \
TCL_DTRACE_INST_DONE(curInstName, (int) CURR_DEPTH, tosPtr);\
} \
} while (0)
#else
#define TCL_DTRACE_INST_NEXT()
#define TCL_DTRACE_INST_LAST()
#endif
/*
* Macro used in this file to save a function call for common uses of
* Tcl_GetNumberFromObj(). The ANSI C "prototype" is:
*
* MODULE_SCOPE int GetNumberFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
* void **ptrPtr, int *tPtr);
|
| ︙ | ︙ | |||
1297 1298 1299 1300 1301 1302 1303 |
Tcl_Obj **resultPtrPtr) /* Where the Tcl_Obj* that is the expression
* result is stored if no errors occur. */
{
NRE_callback *rootPtr = TOP_CB(interp);
Tcl_Obj *resultPtr;
TclNewObj(resultPtr);
| | < | 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 |
Tcl_Obj **resultPtrPtr) /* Where the Tcl_Obj* that is the expression
* result is stored if no errors occur. */
{
NRE_callback *rootPtr = TOP_CB(interp);
Tcl_Obj *resultPtr;
TclNewObj(resultPtr);
TclNRAddCallback(interp, CopyCallback, resultPtrPtr, resultPtr);
Tcl_NRExprObj(interp, objPtr, resultPtr);
return TclNRRunCallbacks(interp, TCL_OK, rootPtr);
}
static int
CopyCallback(
void *data[],
|
| ︙ | ︙ | |||
1356 1357 1358 1359 1360 1361 1362 |
{
ByteCode *codePtr;
Tcl_InterpState state = Tcl_SaveInterpState(interp, TCL_OK);
Tcl_ResetResult(interp);
codePtr = CompileExprObj(interp, objPtr);
| | < | 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 |
{
ByteCode *codePtr;
Tcl_InterpState state = Tcl_SaveInterpState(interp, TCL_OK);
Tcl_ResetResult(interp);
codePtr = CompileExprObj(interp, objPtr);
TclNRAddCallback(interp, ExprObjCallback, state, resultPtr);
return TclNRExecuteByteCode(interp, codePtr);
}
static int
ExprObjCallback(
void *data[],
Tcl_Interp *interp,
|
| ︙ | ︙ | |||
1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 |
/* Counter that is used to work out when to
* call Tcl_AsyncReady(). This must be 1
* initially so that we call the async-check
* stanza early, otherwise there are command
* sequences that can make the interpreter
* busy-loop without an opportunity to
* recognise an interrupt. */
const char *curInstName;
#ifdef TCL_COMPILE_DEBUG
int traceInstructions; /* Whether we are doing instruction-level
* tracing or not. */
#endif
Var *compiledLocals = iPtr->varFramePtr->compiledLocals;
Tcl_Obj **constants = &iPtr->execEnvPtr->constants[0];
| > > | 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 |
/* Counter that is used to work out when to
* call Tcl_AsyncReady(). This must be 1
* initially so that we call the async-check
* stanza early, otherwise there are command
* sequences that can make the interpreter
* busy-loop without an opportunity to
* recognise an interrupt. */
#ifdef USE_DTRACE
const char *curInstName;
#endif
#ifdef TCL_COMPILE_DEBUG
int traceInstructions; /* Whether we are doing instruction-level
* tracing or not. */
#endif
Var *compiledLocals = iPtr->varFramePtr->compiledLocals;
Tcl_Obj **constants = &iPtr->execEnvPtr->constants[0];
|
| ︙ | ︙ | |||
2116 2117 2118 2119 2120 2121 2122 | } /* * Push the call's object result and continue execution with the next * instruction. */ | | | > | 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 |
}
/*
* Push the call's object result and continue execution with the next
* instruction.
*/
TRACE("%" TCL_SIZE_MODIFIER "d => ... after \"%.20s\": TCL_OK, result=",
objc, cmdNameBuf);
TRACE_RESULT(Tcl_GetObjResult(interp));
/*
* Obtain and reset interp's result to avoid possible duplications of
* objects [Bug 781585]. We do not call Tcl_ResetResult to avoid any
* side effects caused by the resetting of errorInfo and errorCode
* [Bug 804681], which are not needed here. We chose instead to
* manipulate the interp's object result directly.
|
| ︙ | ︙ | |||
2272 2273 2274 2275 2276 2277 2278 2279 |
#endif /* TCL_COMPILE_DEBUG */
TCL_DTRACE_INST_NEXT();
if (inst == INST_LOAD_SCALAR1) {
goto instLoadScalar1;
} else if (inst == INST_PUSH1) {
PUSH_OBJECT(codePtr->objArrayPtr[TclGetUInt1AtPtr(pc+1)]);
| > | | 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 |
#endif /* TCL_COMPILE_DEBUG */
TCL_DTRACE_INST_NEXT();
if (inst == INST_LOAD_SCALAR1) {
goto instLoadScalar1;
} else if (inst == INST_PUSH1) {
TRACE("%u => ", TclGetUInt1AtPtr(pc + 1));
PUSH_OBJECT(codePtr->objArrayPtr[TclGetUInt1AtPtr(pc+1)]);
TRACE_RESULT(OBJ_AT_TOS);
inst = *(pc += 2);
goto peepholeStart;
} else if (inst == INST_START_CMD) {
/*
* Peephole: do not run INST_START_CMD, just skip it
*/
|
| ︙ | ︙ | |||
2312 2313 2314 2315 2316 2317 2318 | int code = TclGetInt4AtPtr(pc+1); int level = TclGetUInt4AtPtr(pc+5); /* * OBJ_AT_TOS is returnOpts, OBJ_UNDER_TOS is resultObjPtr. */ | | | | | | | | | | | < | | < | > | | | < | | < | < < | | < | | 2316 2317 2318 2319 2320 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 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 |
int code = TclGetInt4AtPtr(pc+1);
int level = TclGetUInt4AtPtr(pc+5);
/*
* OBJ_AT_TOS is returnOpts, OBJ_UNDER_TOS is resultObjPtr.
*/
TRACE("%u %u => ", code, level);
result = TclProcessReturn(interp, code, level, OBJ_AT_TOS);
if (result == TCL_OK) {
TRACE_APPEND("continuing to next instruction (result=\"%.30s\")\n",
O2S(objResultPtr));
NEXT_INST_F(9, 1, 0);
}
Tcl_SetObjResult(interp, OBJ_UNDER_TOS);
if (*pc == INST_SYNTAX) {
iPtr->flags &= ~ERR_ALREADY_LOGGED;
}
cleanup = 2;
TRACE_APPEND("\n");
goto processExceptionReturn;
}
case INST_RETURN_STK:
TRACE("=> ");
objResultPtr = POP_OBJECT();
result = Tcl_SetReturnOptions(interp, OBJ_AT_TOS);
if (result == TCL_OK) {
Tcl_DecrRefCount(OBJ_AT_TOS);
OBJ_AT_TOS = objResultPtr;
TRACE_APPEND("continuing to next instruction (result=\"%.30s\")\n",
O2S(objResultPtr));
NEXT_INST_F(1, 0, 0);
} else if (result == TCL_ERROR) {
/*
* BEWARE! Must do this in this order, because an error in the
* option dictionary overrides the result (and can be verified by
* test).
*/
Tcl_SetObjResult(interp, objResultPtr);
Tcl_SetReturnOptions(interp, OBJ_AT_TOS);
Tcl_DecrRefCount(OBJ_AT_TOS);
OBJ_AT_TOS = objResultPtr;
} else {
Tcl_DecrRefCount(OBJ_AT_TOS);
OBJ_AT_TOS = objResultPtr;
Tcl_SetObjResult(interp, objResultPtr);
}
cleanup = 1;
TRACE_APPEND("\n");
goto processExceptionReturn;
{
CoroutineData *corPtr;
void *yieldParameter;
case INST_YIELD:
corPtr = iPtr->execEnvPtr->corPtr;
TRACE("%.30s => ", O2S(OBJ_AT_TOS));
if (!corPtr) {
TRACE_APPEND("ERROR: yield outside coroutine\n");
TclPrintfResult(interp, "yield can only be called in a coroutine");
DECACHE_STACK_INFO();
TclSetErrorCode(interp, "TCL", "COROUTINE", "ILLEGAL_YIELD");
CACHE_STACK_INFO();
goto gotError;
}
#ifdef TCL_COMPILE_DEBUG
if (tclTraceExec >= 2) {
if (traceInstructions) {
TRACE_APPEND("YIELD...\n");
} else {
fprintf(stdout,
"%" TCL_SIZE_MODIFIER "d: (%" TCL_T_MODIFIER "d) yielding value \"%.30s\"\n",
iPtr->numLevels, (pc - codePtr->codeStart),
Tcl_GetString(OBJ_AT_TOS));
}
fflush(stdout);
}
#endif
yieldParameter = NULL; /*==CORO_ACTIVATE_YIELD*/
Tcl_SetObjResult(interp, OBJ_AT_TOS);
goto doYield;
case INST_YIELD_TO_INVOKE:
corPtr = iPtr->execEnvPtr->corPtr;
valuePtr = OBJ_AT_TOS;
if (!corPtr) {
TRACE("[%.30s] => ERROR: yield outside coroutine\n",
O2S(valuePtr));
TclPrintfResult(interp, "yieldto can only be called in a coroutine");
DECACHE_STACK_INFO();
TclSetErrorCode(interp, "TCL", "COROUTINE", "ILLEGAL_YIELD");
CACHE_STACK_INFO();
goto gotError;
}
if (((Namespace *)TclGetCurrentNamespace(interp))->flags & NS_DYING) {
TRACE("[%.30s] => ERROR: yield in deleted\n", O2S(valuePtr));
TclPrintfResult(interp, "yieldto called in deleted namespace");
DECACHE_STACK_INFO();
TclSetErrorCode(interp, "TCL", "COROUTINE", "YIELDTO_IN_DELETED");
CACHE_STACK_INFO();
goto gotError;
}
#ifdef TCL_COMPILE_DEBUG
if (tclTraceExec >= 2) {
if (traceInstructions) {
TRACE("[%.30s] => YIELD...\n", O2S(valuePtr));
} else {
/* FIXME: What is the right thing to trace? */
fprintf(stdout, "%" TCL_SIZE_MODIFIER "d: (%" TCL_T_MODIFIER "d) yielding to [%.30s]\n",
iPtr->numLevels, (pc - codePtr->codeStart),
TclGetString(valuePtr));
}
fflush(stdout);
|
| ︙ | ︙ | |||
2461 2462 2463 2464 2465 2466 2467 | ArgumentBCEnter(interp, codePtr, TD, pc, objc, objv); } pc++; cleanup = 1; TEBC_YIELD(); TclNRAddCallback(interp, TclNRCoroutineActivateCallback, corPtr, | | | | | | | | | | | 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 |
ArgumentBCEnter(interp, codePtr, TD, pc, objc, objv);
}
pc++;
cleanup = 1;
TEBC_YIELD();
TclNRAddCallback(interp, TclNRCoroutineActivateCallback, corPtr,
yieldParameter);
return TCL_OK;
}
case INST_TAILCALL: {
Tcl_Obj *listPtr;
opnd = TclGetUInt1AtPtr(pc+1);
if (!(iPtr->varFramePtr->isProcCallFrame & 1)) {
TRACE("%d => ERROR: tailcall in non-proc context\n", opnd);
TclPrintfResult(interp,
"tailcall can only be called from a proc or lambda");
DECACHE_STACK_INFO();
TclSetErrorCode(interp, "TCL", "TAILCALL", "ILLEGAL");
CACHE_STACK_INFO();
goto gotError;
}
#ifdef TCL_COMPILE_DEBUG
/* FIXME: What is the right thing to trace? */
{
int i;
TRACE("%d [", opnd);
for (i=opnd-1 ; i>=0 ; i--) {
TRACE_APPEND("\"%.30s\"", O2S(OBJ_AT_DEPTH(i)));
if (i > 0) {
TRACE_APPEND(" ");
}
}
TRACE_APPEND("] => RETURN...");
}
#endif
/*
* Push the evaluation of the called command into the NR callback
* stack.
*/
|
| ︙ | ︙ | |||
2516 2517 2518 2519 2520 2521 2522 |
result = TCL_RETURN;
cleanup = opnd;
goto processExceptionReturn;
}
case INST_DONE:
if (tosPtr > initTosPtr) {
| < | > | | > | | > > | > | | < > | < > | | 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 |
result = TCL_RETURN;
cleanup = opnd;
goto processExceptionReturn;
}
case INST_DONE:
if (tosPtr > initTosPtr) {
if ((curEvalFlags & TCL_EVAL_DISCARD_RESULT) && (result == TCL_OK)) {
/* simulate pop & fast done (like it does continue in loop) */
TRACE("=> discarding ");
TRACE_RESULT(OBJ_AT_TOS);
objPtr = POP_OBJECT();
TclDecrRefCount(objPtr);
goto abnormalReturn;
}
/*
* Set the interpreter's object result to point to the topmost
* object from the stack, and check for a possible [catch]. The
* stackTop's level and refCount will be handled by "processCatch"
* or "abnormalReturn".
*/
Tcl_SetObjResult(interp, OBJ_AT_TOS);
#ifdef TCL_COMPILE_DEBUG
TRACE("=> return code=%d, result=", result);
TRACE_RESULT(iPtr->objResultPtr);
if (traceInstructions) {
fprintf(stdout, "\n");
}
#endif
goto checkForCatch;
}
(void) POP_OBJECT();
goto abnormalReturn;
case INST_PUSH4:
TRACE("%u => ", TclGetUInt4AtPtr(pc+1));
objResultPtr = codePtr->objArrayPtr[TclGetUInt4AtPtr(pc+1)];
TRACE_RESULT(objResultPtr);
NEXT_INST_F(5, 0, 1);
break;
case INST_POP:
TRACE("=> discarding ");
TRACE_RESULT(OBJ_AT_TOS);
objPtr = POP_OBJECT();
TclDecrRefCount(objPtr);
NEXT_INST_F(1, 0, 0);
break;
case INST_DUP:
TRACE("=> ");
objResultPtr = OBJ_AT_TOS;
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 0, 1);
break;
case INST_OVER:
opnd = TclGetUInt4AtPtr(pc+1);
TRACE("%u => ", opnd);
objResultPtr = OBJ_AT_DEPTH(opnd);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(5, 0, 1);
break;
case INST_REVERSE: {
Tcl_Obj **a, **b;
opnd = TclGetUInt4AtPtr(pc + 1);
a = tosPtr - (opnd - 1);
b = tosPtr;
while (a < b) {
tmpPtr = *a;
*a = *b;
*b = tmpPtr;
a++;
b--;
}
TRACE("%u => OK\n", opnd);
NEXT_INST_F(5, 0, 0);
}
break;
case INST_STR_CONCAT1:
opnd = TclGetUInt1AtPtr(pc+1);
TRACE("%u => ", opnd);
DECACHE_STACK_INFO();
objResultPtr = TclStringCat(interp, opnd, &OBJ_AT_DEPTH(opnd-1),
TCL_STRING_IN_PLACE);
if (objResultPtr == NULL) {
CACHE_STACK_INFO();
TRACE_ERROR(interp);
goto gotError;
}
CACHE_STACK_INFO();
TRACE_RESULT(objResultPtr);
NEXT_INST_V(2, opnd, 1);
case INST_CONCAT_STK:
/*
* Pop the opnd (objc) top stack elements, run through Tcl_ConcatObj,
* and then decrement their ref counts.
*/
opnd = TclGetUInt4AtPtr(pc+1);
TRACE("%u => ", opnd);
objResultPtr = Tcl_ConcatObj(opnd, &OBJ_AT_DEPTH(opnd - 1));
TRACE_RESULT(objResultPtr);
NEXT_INST_V(5, opnd, 1);
break;
case INST_EXPAND_START:
/*
* Push an element to the auxObjList. This records the current
* stack depth - i.e., the point in the stack where the expanded
|
| ︙ | ︙ | |||
2635 2636 2637 2638 2639 2640 2641 | * error, also in INST_EXPAND_STKTOP). */ TclNewObj(objPtr); objPtr->internalRep.twoPtrValue.ptr2 = INT2PTR(CURR_DEPTH); objPtr->length = 0; PUSH_TAUX_OBJ(objPtr); | | | | | 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 |
* error, also in INST_EXPAND_STKTOP).
*/
TclNewObj(objPtr);
objPtr->internalRep.twoPtrValue.ptr2 = INT2PTR(CURR_DEPTH);
objPtr->length = 0;
PUSH_TAUX_OBJ(objPtr);
TRACE("=> mark depth as %" TCL_T_MODIFIER "d\n", CURR_DEPTH);
NEXT_INST_F(1, 0, 0);
break;
case INST_EXPAND_DROP:
/*
* Drops an element of the auxObjList, popping stack elements to
* restore the stack to the state before the point where the aux
* element was created.
*/
CLANG_ASSERT(auxObjList);
objc = CURR_DEPTH - PTR2INT(auxObjList->internalRep.twoPtrValue.ptr2);
POP_TAUX_OBJ();
#ifdef TCL_COMPILE_DEBUG
/* Ugly abuse! */
starting = 1;
#endif
TRACE("=> drop %" TCL_SIZE_MODIFIER "d items\n", objc);
NEXT_INST_V(1, objc, 0);
case INST_EXPAND_STKTOP: {
Tcl_Size i;
TEBCdata *newTD;
Tcl_Size oldCatchTopOff, oldTosPtrOff;
/*
* Make sure that the element at stackTop is a list; if not, just
* leave with an error. Note that the element from the expand list
* will be removed at checkForCatch.
*/
objPtr = OBJ_AT_TOS;
TRACE("\"%.30s\" => ", O2S(objPtr));
if (TclListObjGetElements(interp, objPtr, &objc, &objv) != TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
}
(void) POP_OBJECT();
/*
|
| ︙ | ︙ | |||
2715 2716 2717 2718 2719 2720 2721 |
* that it has a freeIntRepProc we use Tcl_DecrRefCount().
*/
for (i = 0; i < objc; i++) {
PUSH_OBJECT(objv[i]);
}
| | | 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 |
* that it has a freeIntRepProc we use Tcl_DecrRefCount().
*/
for (i = 0; i < objc; i++) {
PUSH_OBJECT(objv[i]);
}
TRACE_APPEND("OK\n");
Tcl_DecrRefCount(objPtr);
NEXT_INST_F(5, 0, 0);
}
break;
case INST_EXPR_STK: {
ByteCode *newCodePtr;
|
| ︙ | ︙ | |||
2788 2789 2790 2791 2792 2793 2794 |
#ifdef TCL_COMPILE_DEBUG
if (tclTraceExec >= 2) {
Tcl_Size i;
if (traceInstructions) {
strncpy(cmdNameBuf, TclGetString(objv[0]), 20);
| | | 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 |
#ifdef TCL_COMPILE_DEBUG
if (tclTraceExec >= 2) {
Tcl_Size i;
if (traceInstructions) {
strncpy(cmdNameBuf, TclGetString(objv[0]), 20);
TRACE("%" TCL_SIZE_MODIFIER "d => call ", objc);
} else {
fprintf(stdout, "%" TCL_SIZE_MODIFIER "d: (%" TCL_T_MODIFIER "d) invoking ", iPtr->numLevels,
(pc - codePtr->codeStart));
}
for (i = 0; i < objc; i++) {
TclPrintObject(stdout, objv[i], 15);
fprintf(stdout, " ");
|
| ︙ | ︙ | |||
2839 2840 2841 2842 2843 2844 2845 |
cleanup = objc;
#ifdef TCL_COMPILE_DEBUG
if (tclTraceExec >= 2) {
Tcl_Size i;
if (traceInstructions) {
strncpy(cmdNameBuf, TclGetString(objv[0]), 20);
| | > | 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 |
cleanup = objc;
#ifdef TCL_COMPILE_DEBUG
if (tclTraceExec >= 2) {
Tcl_Size i;
if (traceInstructions) {
strncpy(cmdNameBuf, TclGetString(objv[0]), 20);
TRACE("%" TCL_Z_MODIFIER "u => call (implementation %s) ",
objc, O2S(objPtr));
} else {
fprintf(stdout,
"%" TCL_Z_MODIFIER "d: (%" TCL_T_MODIFIER "u) invoking (using implementation %s) ",
iPtr->numLevels, (pc - codePtr->codeStart),
O2S(objPtr));
}
for (i = 0; i < objc; i++) {
|
| ︙ | ︙ | |||
2884 2885 2886 2887 2888 2889 2890 | } DECACHE_STACK_INFO(); pc += 6; TEBC_YIELD(); TclMarkTailcall(interp); | | | | | | | | 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 |
}
DECACHE_STACK_INFO();
pc += 6;
TEBC_YIELD();
TclMarkTailcall(interp);
TclNRAddCallback(interp, TclClearRootEnsemble);
TclListObjGetElements(NULL, objPtr, &objc, &objv);
TclNRAddCallback(interp, TclNRReleaseValues, objPtr);
return TclNREvalObjv(interp, objc, objv, TCL_EVAL_INVOKE, NULL);
/*
* -----------------------------------------------------------------
* Start of INST_LOAD instructions.
*
* WARNING: more 'goto' here than your doctor recommended! The different
* instructions set the value of some variables and then jump to some
* common execution code.
*/
case INST_LOAD_SCALAR1:
instLoadScalar1:
opnd = TclGetUInt1AtPtr(pc+1);
varPtr = LOCAL(opnd);
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
TRACE("%u => ", opnd);
if (TclIsVarDirectReadable(varPtr)) {
/*
* No errors, no traces: just get the value.
*/
objResultPtr = varPtr->value.objPtr;
TRACE_RESULT(objResultPtr);
NEXT_INST_F(2, 0, 1);
}
pcAdjustment = 2;
cleanup = 0;
arrayPtr = NULL;
part1Ptr = part2Ptr = NULL;
goto doCallPtrGetVar;
case INST_LOAD_SCALAR4:
opnd = TclGetUInt4AtPtr(pc+1);
varPtr = LOCAL(opnd);
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
TRACE("%u => ", opnd);
if (TclIsVarDirectReadable(varPtr)) {
/*
* No errors, no traces: just get the value.
*/
objResultPtr = varPtr->value.objPtr;
TRACE_RESULT(objResultPtr);
NEXT_INST_F(5, 0, 1);
}
pcAdjustment = 5;
cleanup = 0;
arrayPtr = NULL;
part1Ptr = part2Ptr = NULL;
goto doCallPtrGetVar;
|
| ︙ | ︙ | |||
2959 2960 2961 2962 2963 2964 2965 |
doLoadArray:
part1Ptr = NULL;
part2Ptr = OBJ_AT_TOS;
arrayPtr = LOCAL(opnd);
while (TclIsVarLink(arrayPtr)) {
arrayPtr = arrayPtr->value.linkPtr;
}
| | | | | | | | 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 |
doLoadArray:
part1Ptr = NULL;
part2Ptr = OBJ_AT_TOS;
arrayPtr = LOCAL(opnd);
while (TclIsVarLink(arrayPtr)) {
arrayPtr = arrayPtr->value.linkPtr;
}
TRACE("%u \"%.30s\" => ", opnd, O2S(part2Ptr));
if (TclIsVarArray(arrayPtr) && !ReadTraced(arrayPtr)) {
varPtr = VarHashFindVar(arrayPtr->value.tablePtr, part2Ptr);
if (varPtr && TclIsVarDirectReadable(varPtr)) {
/*
* No errors, no traces: just get the value.
*/
objResultPtr = varPtr->value.objPtr;
TRACE_RESULT(objResultPtr);
NEXT_INST_F(pcAdjustment, 1, 1);
}
}
varPtr = TclLookupArrayElement(interp, part1Ptr, part2Ptr,
TCL_LEAVE_ERR_MSG, "read", 0, 1, arrayPtr, opnd);
if (varPtr == NULL) {
TRACE_ERROR(interp);
goto gotError;
}
cleanup = 1;
goto doCallPtrGetVar;
case INST_LOAD_ARRAY_STK:
cleanup = 2;
part2Ptr = OBJ_AT_TOS; /* element name */
objPtr = OBJ_UNDER_TOS; /* array name */
TRACE("\"%.30s(%.30s)\" => ", O2S(objPtr), O2S(part2Ptr));
goto doLoadStk;
case INST_LOAD_STK:
case INST_LOAD_SCALAR_STK:
cleanup = 1;
part2Ptr = NULL;
objPtr = OBJ_AT_TOS; /* variable name */
TRACE("\"%.30s\" => ", O2S(objPtr));
doLoadStk:
part1Ptr = objPtr;
varPtr = TclObjLookupVarEx(interp, part1Ptr, part2Ptr,
TCL_LEAVE_ERR_MSG, "read", /*createPart1*/0, /*createPart2*/1,
&arrayPtr);
if (!varPtr) {
TRACE_ERROR(interp);
goto gotError;
}
if (TclIsVarDirectReadable2(varPtr, arrayPtr)) {
/*
* No errors, no traces: just get the value.
*/
objResultPtr = varPtr->value.objPtr;
TRACE_RESULT(objResultPtr);
NEXT_INST_V(1, cleanup, 1);
}
pcAdjustment = 1;
opnd = -1;
doCallPtrGetVar:
/*
* There are either errors or the variable is traced: call
* TclPtrGetVar to process fully.
*/
DECACHE_STACK_INFO();
objResultPtr = TclPtrGetVarIdx(interp, varPtr, arrayPtr,
part1Ptr, part2Ptr, TCL_LEAVE_ERR_MSG, opnd);
CACHE_STACK_INFO();
if (!objResultPtr) {
TRACE_ERROR(interp);
goto gotError;
}
TRACE_RESULT(objResultPtr);
NEXT_INST_V(pcAdjustment, cleanup, 1);
/*
* End of INST_LOAD instructions.
* -----------------------------------------------------------------
* Start of INST_STORE and related instructions.
*
|
| ︙ | ︙ | |||
3061 3062 3063 3064 3065 3066 3067 |
opnd = TclGetUInt1AtPtr(pc+1);
pcAdjustment = 2;
doStoreArrayDirect:
valuePtr = OBJ_AT_TOS;
part2Ptr = OBJ_UNDER_TOS;
arrayPtr = LOCAL(opnd);
| | | | 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 |
opnd = TclGetUInt1AtPtr(pc+1);
pcAdjustment = 2;
doStoreArrayDirect:
valuePtr = OBJ_AT_TOS;
part2Ptr = OBJ_UNDER_TOS;
arrayPtr = LOCAL(opnd);
TRACE("%u \"%.30s\" <- \"%.30s\" => ", opnd, O2S(part2Ptr),
O2S(valuePtr));
while (TclIsVarLink(arrayPtr)) {
arrayPtr = arrayPtr->value.linkPtr;
}
if (TclIsVarArray(arrayPtr) && !WriteTraced(arrayPtr)) {
varPtr = VarHashFindVar(arrayPtr->value.tablePtr, part2Ptr);
if (varPtr && TclIsVarDirectWritable(varPtr)) {
tosPtr--;
|
| ︙ | ︙ | |||
3092 3093 3094 3095 3096 3097 3098 |
case INST_STORE_SCALAR1:
opnd = TclGetUInt1AtPtr(pc+1);
pcAdjustment = 2;
doStoreScalarDirect:
valuePtr = OBJ_AT_TOS;
varPtr = LOCAL(opnd);
| | | 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 |
case INST_STORE_SCALAR1:
opnd = TclGetUInt1AtPtr(pc+1);
pcAdjustment = 2;
doStoreScalarDirect:
valuePtr = OBJ_AT_TOS;
varPtr = LOCAL(opnd);
TRACE("%u <- \"%.30s\" => ", opnd, O2S(valuePtr));
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
if (!TclIsVarDirectWritable(varPtr)) {
storeFlags = TCL_LEAVE_ERR_MSG;
part1Ptr = NULL;
goto doStoreScalar;
|
| ︙ | ︙ | |||
3118 3119 3120 3121 3122 3123 3124 |
TclDecrRefCount(valuePtr);
}
objResultPtr = OBJ_AT_TOS;
varPtr->value.objPtr = objResultPtr;
#ifndef TCL_COMPILE_DEBUG
if (pc[pcAdjustment] == INST_POP) {
tosPtr--;
| | | | 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 |
TclDecrRefCount(valuePtr);
}
objResultPtr = OBJ_AT_TOS;
varPtr->value.objPtr = objResultPtr;
#ifndef TCL_COMPILE_DEBUG
if (pc[pcAdjustment] == INST_POP) {
tosPtr--;
NEXT_INST_F(pcAdjustment+1, 0, 0);
}
#else
TRACE_RESULT(objResultPtr);
#endif
Tcl_IncrRefCount(objResultPtr);
NEXT_INST_F(pcAdjustment, 0, 0);
case INST_LAPPEND_STK:
valuePtr = OBJ_AT_TOS; /* value to append */
part2Ptr = NULL;
|
| ︙ | ︙ | |||
3169 3170 3171 3172 3173 3174 3175 |
storeFlags = TCL_LEAVE_ERR_MSG;
doStoreStk:
objPtr = OBJ_AT_DEPTH(1 + (part2Ptr != NULL)); /* variable name */
part1Ptr = objPtr;
#ifdef TCL_COMPILE_DEBUG
if (part2Ptr == NULL) {
| | | | | 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 |
storeFlags = TCL_LEAVE_ERR_MSG;
doStoreStk:
objPtr = OBJ_AT_DEPTH(1 + (part2Ptr != NULL)); /* variable name */
part1Ptr = objPtr;
#ifdef TCL_COMPILE_DEBUG
if (part2Ptr == NULL) {
TRACE("\"%.30s\" <- \"%.30s\" =>", O2S(part1Ptr),O2S(valuePtr));
} else {
TRACE("\"%.30s(%.30s)\" <- \"%.30s\" => ",
O2S(part1Ptr), O2S(part2Ptr), O2S(valuePtr));
}
#endif
varPtr = TclObjLookupVarEx(interp, objPtr, part2Ptr, TCL_LEAVE_ERR_MSG,
"set", /*createPart1*/ 1, /*createPart2*/ 1, &arrayPtr);
if (!varPtr) {
TRACE_ERROR(interp);
goto gotError;
|
| ︙ | ︙ | |||
3216 3217 3218 3219 3220 3221 3222 |
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE);
goto doStoreArray;
doStoreArray:
valuePtr = OBJ_AT_TOS;
part2Ptr = OBJ_UNDER_TOS;
arrayPtr = LOCAL(opnd);
| | | | 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 |
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE);
goto doStoreArray;
doStoreArray:
valuePtr = OBJ_AT_TOS;
part2Ptr = OBJ_UNDER_TOS;
arrayPtr = LOCAL(opnd);
TRACE("%u \"%.30s\" <- \"%.30s\" => ", opnd, O2S(part2Ptr),
O2S(valuePtr));
while (TclIsVarLink(arrayPtr)) {
arrayPtr = arrayPtr->value.linkPtr;
}
cleanup = 2;
part1Ptr = NULL;
doStoreArrayDirectFailed:
|
| ︙ | ︙ | |||
3262 3263 3264 3265 3266 3267 3268 |
pcAdjustment = 2;
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE);
goto doStoreScalar;
doStoreScalar:
valuePtr = OBJ_AT_TOS;
varPtr = LOCAL(opnd);
| | | | | | 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 |
pcAdjustment = 2;
storeFlags = (TCL_LEAVE_ERR_MSG | TCL_APPEND_VALUE);
goto doStoreScalar;
doStoreScalar:
valuePtr = OBJ_AT_TOS;
varPtr = LOCAL(opnd);
TRACE("%u <- \"%.30s\" => ", opnd, O2S(valuePtr));
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
cleanup = 1;
arrayPtr = NULL;
part1Ptr = part2Ptr = NULL;
doCallPtrSetVar:
DECACHE_STACK_INFO();
objResultPtr = TclPtrSetVarIdx(interp, varPtr, arrayPtr,
part1Ptr, part2Ptr, valuePtr, storeFlags, opnd);
CACHE_STACK_INFO();
if (!objResultPtr) {
TRACE_ERROR(interp);
goto gotError;
}
#ifndef TCL_COMPILE_DEBUG
if (pc[pcAdjustment] == INST_POP) {
NEXT_INST_V(pcAdjustment+1, cleanup, 0);
}
#endif
TRACE_RESULT(objResultPtr);
NEXT_INST_V(pcAdjustment, cleanup, 1);
case INST_LAPPEND_LIST:
opnd = TclGetUInt4AtPtr(pc+1);
valuePtr = OBJ_AT_TOS;
varPtr = LOCAL(opnd);
cleanup = 1;
pcAdjustment = 5;
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
TRACE("%u <- \"%.30s\" => ", opnd, O2S(valuePtr));
if (TclListObjGetElements(interp, valuePtr, &objc, &objv)
!= TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
}
if (TclIsVarDirectReadable(varPtr)
&& TclIsVarDirectWritable(varPtr)) {
|
| ︙ | ︙ | |||
3321 3322 3323 3324 3325 3326 3327 |
part2Ptr = OBJ_UNDER_TOS;
arrayPtr = LOCAL(opnd);
cleanup = 2;
pcAdjustment = 5;
while (TclIsVarLink(arrayPtr)) {
arrayPtr = arrayPtr->value.linkPtr;
}
| | | | 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 |
part2Ptr = OBJ_UNDER_TOS;
arrayPtr = LOCAL(opnd);
cleanup = 2;
pcAdjustment = 5;
while (TclIsVarLink(arrayPtr)) {
arrayPtr = arrayPtr->value.linkPtr;
}
TRACE("%u \"%.30s\" \"%.30s\" => ",
opnd, O2S(part2Ptr), O2S(valuePtr));
if (TclListObjGetElements(interp, valuePtr, &objc, &objv)
!= TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
}
if (TclIsVarArray(arrayPtr) && !ReadTraced(arrayPtr)
&& !WriteTraced(arrayPtr)) {
|
| ︙ | ︙ | |||
3350 3351 3352 3353 3354 3355 3356 |
case INST_LAPPEND_LIST_ARRAY_STK:
pcAdjustment = 1;
cleanup = 3;
valuePtr = OBJ_AT_TOS;
part2Ptr = OBJ_UNDER_TOS; /* element name */
part1Ptr = OBJ_AT_DEPTH(2); /* array name */
| | | | | | 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 |
case INST_LAPPEND_LIST_ARRAY_STK:
pcAdjustment = 1;
cleanup = 3;
valuePtr = OBJ_AT_TOS;
part2Ptr = OBJ_UNDER_TOS; /* element name */
part1Ptr = OBJ_AT_DEPTH(2); /* array name */
TRACE("\"%.30s(%.30s)\" \"%.30s\" => ",
O2S(part1Ptr), O2S(part2Ptr), O2S(valuePtr));
goto lappendList;
case INST_LAPPEND_LIST_STK:
pcAdjustment = 1;
cleanup = 2;
valuePtr = OBJ_AT_TOS;
part2Ptr = NULL;
part1Ptr = OBJ_UNDER_TOS; /* variable name */
TRACE("\"%.30s\" \"%.30s\" => ", O2S(part1Ptr), O2S(valuePtr));
goto lappendList;
lappendListDirect:
objResultPtr = varPtr->value.objPtr;
if (TclListObjLength(interp, objResultPtr, &len) != TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
}
if (Tcl_IsShared(objResultPtr)) {
Tcl_Obj *newValue = Tcl_DuplicateObj(objResultPtr);
TclDecrRefCount(objResultPtr);
varPtr->value.objPtr = objResultPtr = newValue;
Tcl_IncrRefCount(newValue);
}
if (TclListObjAppendElements(interp, objResultPtr, objc, objv)
!= TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
}
TRACE_RESULT(objResultPtr);
NEXT_INST_V(pcAdjustment, cleanup, 1);
lappendList:
opnd = -1;
if (TclListObjGetElements(interp, valuePtr, &objc, &objv)
!= TCL_OK) {
TRACE_ERROR(interp);
|
| ︙ | ︙ | |||
3452 3453 3454 3455 3456 3457 3458 |
CACHE_STACK_INFO();
if (!objResultPtr) {
errorInLappendListPtr:
TRACE_ERROR(interp);
goto gotError;
}
}
| | | 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 |
CACHE_STACK_INFO();
if (!objResultPtr) {
errorInLappendListPtr:
TRACE_ERROR(interp);
goto gotError;
}
}
TRACE_RESULT(objResultPtr);
NEXT_INST_V(pcAdjustment, cleanup, 1);
}
/*
* End of INST_STORE and related instructions.
* -----------------------------------------------------------------
* Start of INST_INCR instructions.
|
| ︙ | ︙ | |||
3505 3506 3507 3508 3509 3510 3511 |
pcAdjustment = 2;
doIncrStk:
if ((*pc == INST_INCR_ARRAY_STK_IMM)
|| (*pc == INST_INCR_ARRAY_STK)) {
part2Ptr = OBJ_AT_TOS;
objPtr = OBJ_UNDER_TOS;
| | | | | 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 |
pcAdjustment = 2;
doIncrStk:
if ((*pc == INST_INCR_ARRAY_STK_IMM)
|| (*pc == INST_INCR_ARRAY_STK)) {
part2Ptr = OBJ_AT_TOS;
objPtr = OBJ_UNDER_TOS;
TRACE("\"%.30s(%.30s)\" (by %ld) => ",
O2S(objPtr), O2S(part2Ptr), increment);
} else {
part2Ptr = NULL;
objPtr = OBJ_AT_TOS;
TRACE("\"%.30s\" (by %ld) => ", O2S(objPtr), increment);
}
part1Ptr = objPtr;
opnd = -1;
varPtr = TclObjLookupVarEx(interp, objPtr, part2Ptr,
TCL_LEAVE_ERR_MSG, "read", 1, 1, &arrayPtr);
if (!varPtr) {
DECACHE_STACK_INFO();
|
| ︙ | ︙ | |||
3543 3544 3545 3546 3547 3548 3549 |
part1Ptr = NULL;
part2Ptr = OBJ_AT_TOS;
arrayPtr = LOCAL(opnd);
cleanup = 1;
while (TclIsVarLink(arrayPtr)) {
arrayPtr = arrayPtr->value.linkPtr;
}
| | | 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 |
part1Ptr = NULL;
part2Ptr = OBJ_AT_TOS;
arrayPtr = LOCAL(opnd);
cleanup = 1;
while (TclIsVarLink(arrayPtr)) {
arrayPtr = arrayPtr->value.linkPtr;
}
TRACE("%u \"%.30s\" (by %ld) => ", opnd, O2S(part2Ptr), increment);
varPtr = TclLookupArrayElement(interp, part1Ptr, part2Ptr,
TCL_LEAVE_ERR_MSG, "read", 1, 1, arrayPtr, opnd);
if (!varPtr) {
TRACE_ERROR(interp);
Tcl_DecrRefCount(incrPtr);
goto gotError;
}
|
| ︙ | ︙ | |||
3580 3581 3582 3583 3584 3585 3586 |
/*
* Overflow when (augend and sum have different sign) and
* (augend and increment have the same sign). This is
* encapsulated in the Overflowing macro.
*/
if (!Overflowing(augend, increment, sum)) {
| | | | 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 |
/*
* Overflow when (augend and sum have different sign) and
* (augend and increment have the same sign). This is
* encapsulated in the Overflowing macro.
*/
if (!Overflowing(augend, increment, sum)) {
TRACE("%u %ld => ", opnd, increment);
if (Tcl_IsShared(objPtr)) {
objPtr->refCount--; /* We know it's shared. */
TclNewIntObj(objResultPtr, sum);
Tcl_IncrRefCount(objResultPtr);
varPtr->value.objPtr = objResultPtr;
} else {
objResultPtr = objPtr;
TclSetIntObj(objPtr, sum);
}
goto doneIncr;
}
w = (Tcl_WideInt)augend;
TRACE("%u %ld => ", opnd, increment);
if (Tcl_IsShared(objPtr)) {
objPtr->refCount--; /* We know it's shared. */
TclNewIntObj(objResultPtr, w + increment);
Tcl_IncrRefCount(objResultPtr);
varPtr->value.objPtr = objResultPtr;
} else {
objResultPtr = objPtr;
|
| ︙ | ︙ | |||
3646 3647 3648 3649 3650 3651 3652 |
varPtr = LOCAL(opnd);
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
arrayPtr = NULL;
part1Ptr = part2Ptr = NULL;
cleanup = 0;
| | | 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 |
varPtr = LOCAL(opnd);
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
arrayPtr = NULL;
part1Ptr = part2Ptr = NULL;
cleanup = 0;
TRACE("%u %s => ", opnd, TclGetString(incrPtr));
doIncrVar:
if (TclIsVarDirectModifyable2(varPtr, arrayPtr)) {
objPtr = varPtr->value.objPtr;
if (Tcl_IsShared(objPtr)) {
objPtr->refCount--; /* We know it's shared */
objResultPtr = Tcl_DuplicateObj(objPtr);
|
| ︙ | ︙ | |||
3677 3678 3679 3680 3681 3682 3683 |
Tcl_DecrRefCount(incrPtr);
if (objResultPtr == NULL) {
TRACE_ERROR(interp);
goto gotError;
}
}
doneIncr:
| | | | | 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 |
Tcl_DecrRefCount(incrPtr);
if (objResultPtr == NULL) {
TRACE_ERROR(interp);
goto gotError;
}
}
doneIncr:
TRACE_RESULT(objResultPtr);
#ifndef TCL_COMPILE_DEBUG
if (pc[pcAdjustment] == INST_POP) {
NEXT_INST_V(pcAdjustment+1, cleanup, 0);
}
#endif
NEXT_INST_V(pcAdjustment, cleanup, 1);
}
/*
* End of INST_INCR instructions.
* -----------------------------------------------------------------
* Start of INST_EXIST instructions.
*/
case INST_EXIST_SCALAR:
cleanup = 0;
pcAdjustment = 5;
opnd = TclGetUInt4AtPtr(pc+1);
varPtr = LOCAL(opnd);
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
TRACE("%u => ", opnd);
if (ReadTraced(varPtr)) {
DECACHE_STACK_INFO();
TclObjCallVarTraces(iPtr, NULL, varPtr, NULL, NULL,
TCL_TRACE_READS, 0, opnd);
CACHE_STACK_INFO();
if (TclIsVarUndefined(varPtr)) {
TclCleanupVar(varPtr, NULL);
|
| ︙ | ︙ | |||
3722 3723 3724 3725 3726 3727 3728 |
pcAdjustment = 5;
opnd = TclGetUInt4AtPtr(pc+1);
part2Ptr = OBJ_AT_TOS;
arrayPtr = LOCAL(opnd);
while (TclIsVarLink(arrayPtr)) {
arrayPtr = arrayPtr->value.linkPtr;
}
| | | 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 |
pcAdjustment = 5;
opnd = TclGetUInt4AtPtr(pc+1);
part2Ptr = OBJ_AT_TOS;
arrayPtr = LOCAL(opnd);
while (TclIsVarLink(arrayPtr)) {
arrayPtr = arrayPtr->value.linkPtr;
}
TRACE("%u \"%.30s\" => ", opnd, O2S(part2Ptr));
if (TclIsVarArray(arrayPtr) && !ReadTraced(arrayPtr)) {
varPtr = VarHashFindVar(arrayPtr->value.tablePtr, part2Ptr);
if (!varPtr || !ReadTraced(varPtr)) {
goto afterExistsPeephole;
}
}
varPtr = TclLookupArrayElement(interp, NULL, part2Ptr, 0, "access",
|
| ︙ | ︙ | |||
3750 3751 3752 3753 3754 3755 3756 |
goto afterExistsPeephole;
case INST_EXIST_ARRAY_STK:
cleanup = 2;
pcAdjustment = 1;
part2Ptr = OBJ_AT_TOS; /* element name */
part1Ptr = OBJ_UNDER_TOS; /* array name */
| | | | 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 |
goto afterExistsPeephole;
case INST_EXIST_ARRAY_STK:
cleanup = 2;
pcAdjustment = 1;
part2Ptr = OBJ_AT_TOS; /* element name */
part1Ptr = OBJ_UNDER_TOS; /* array name */
TRACE("\"%.30s(%.30s)\" => ", O2S(part1Ptr), O2S(part2Ptr));
goto doExistStk;
case INST_EXIST_STK:
cleanup = 1;
pcAdjustment = 1;
part2Ptr = NULL;
part1Ptr = OBJ_AT_TOS; /* variable name */
TRACE("\"%.30s\" => ", O2S(part1Ptr));
doExistStk:
varPtr = TclObjLookupVarEx(interp, part1Ptr, part2Ptr, 0, "access",
/*createPart1*/0, /*createPart2*/1, &arrayPtr);
if (varPtr) {
if (ReadTraced(varPtr) || (arrayPtr && ReadTraced(arrayPtr))) {
DECACHE_STACK_INFO();
|
| ︙ | ︙ | |||
3783 3784 3785 3786 3787 3788 3789 |
/*
* Peep-hole optimisation: if you're about to jump, do jump from here.
*/
afterExistsPeephole: {
int found = (varPtr && !TclIsVarUndefined(varPtr));
| | | | | | | | | 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 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 |
/*
* Peep-hole optimisation: if you're about to jump, do jump from here.
*/
afterExistsPeephole: {
int found = (varPtr && !TclIsVarUndefined(varPtr));
TRACE_APPEND("%d\n", found ? 1 : 0);
JUMP_PEEPHOLE_V(found, pcAdjustment, cleanup);
}
/*
* End of INST_EXIST instructions.
* -----------------------------------------------------------------
* Start of INST_UNSET instructions.
*/
{
int flags;
case INST_UNSET_SCALAR:
flags = TclGetUInt1AtPtr(pc+1) ? TCL_LEAVE_ERR_MSG : 0;
opnd = TclGetUInt4AtPtr(pc+2);
varPtr = LOCAL(opnd);
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
TRACE("%s %u => ", (flags ? "normal" : "noerr"), opnd);
if (TclIsVarDirectUnsettable(varPtr) && !TclIsVarInHash(varPtr)) {
/*
* No errors, no traces, no searches: just make the variable cease
* to exist.
*/
if (!TclIsVarUndefined(varPtr)) {
TclDecrRefCount(varPtr->value.objPtr);
} else if (flags & TCL_LEAVE_ERR_MSG) {
goto slowUnsetScalar;
}
varPtr->value.objPtr = NULL;
TRACE_APPEND("OK\n");
NEXT_INST_F(6, 0, 0);
}
slowUnsetScalar:
DECACHE_STACK_INFO();
if (TclPtrUnsetVarIdx(interp, varPtr, NULL, NULL, NULL, flags,
opnd) != TCL_OK && flags) {
goto errorInUnset;
}
CACHE_STACK_INFO();
NEXT_INST_F(6, 0, 0);
case INST_UNSET_ARRAY:
flags = TclGetUInt1AtPtr(pc+1) ? TCL_LEAVE_ERR_MSG : 0;
opnd = TclGetUInt4AtPtr(pc+2);
part2Ptr = OBJ_AT_TOS;
arrayPtr = LOCAL(opnd);
while (TclIsVarLink(arrayPtr)) {
arrayPtr = arrayPtr->value.linkPtr;
}
TRACE("%s %u \"%.30s\" => ",
(flags ? "normal" : "noerr"), opnd, O2S(part2Ptr));
if (TclIsVarArray(arrayPtr) && !UnsetTraced(arrayPtr)
&& !(arrayPtr->flags & VAR_SEARCH_ACTIVE)) {
varPtr = VarHashFindVar(arrayPtr->value.tablePtr, part2Ptr);
if (varPtr && TclIsVarDirectUnsettable(varPtr)) {
/*
* No nasty traces and element exists, so we can proceed to
* unset it. Might still not exist though...
*/
if (!TclIsVarUndefined(varPtr)) {
TclDecrRefCount(varPtr->value.objPtr);
TclSetVarUndefined(varPtr);
TclClearVarNamespaceVar(varPtr);
TclCleanupVar(varPtr, arrayPtr);
} else if (flags & TCL_LEAVE_ERR_MSG) {
goto slowUnsetArray;
}
TRACE_APPEND("OK\n");
NEXT_INST_F(6, 1, 0);
} else if (!varPtr && !(flags & TCL_LEAVE_ERR_MSG)) {
/*
* Don't need to do anything here.
*/
TRACE_APPEND("OK\n");
NEXT_INST_F(6, 1, 0);
}
}
slowUnsetArray:
DECACHE_STACK_INFO();
varPtr = TclLookupArrayElement(interp, NULL, part2Ptr, flags, "unset",
0, 0, arrayPtr, opnd);
|
| ︙ | ︙ | |||
3887 3888 3889 3890 3891 3892 3893 |
NEXT_INST_F(6, 1, 0);
case INST_UNSET_ARRAY_STK:
flags = TclGetUInt1AtPtr(pc+1) ? TCL_LEAVE_ERR_MSG : 0;
cleanup = 2;
part2Ptr = OBJ_AT_TOS; /* element name */
part1Ptr = OBJ_UNDER_TOS; /* array name */
| | | | | | | 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 |
NEXT_INST_F(6, 1, 0);
case INST_UNSET_ARRAY_STK:
flags = TclGetUInt1AtPtr(pc+1) ? TCL_LEAVE_ERR_MSG : 0;
cleanup = 2;
part2Ptr = OBJ_AT_TOS; /* element name */
part1Ptr = OBJ_UNDER_TOS; /* array name */
TRACE("%s \"%.30s(%.30s)\" => ", (flags ? "normal" : "noerr"),
O2S(part1Ptr), O2S(part2Ptr));
goto doUnsetStk;
case INST_UNSET_STK:
flags = TclGetUInt1AtPtr(pc+1) ? TCL_LEAVE_ERR_MSG : 0;
cleanup = 1;
part2Ptr = NULL;
part1Ptr = OBJ_AT_TOS; /* variable name */
TRACE("%s \"%.30s\" => ", (flags ? "normal" : "noerr"),
O2S(part1Ptr));
doUnsetStk:
DECACHE_STACK_INFO();
if (TclObjUnsetVar2(interp, part1Ptr, part2Ptr, flags) != TCL_OK
&& (flags & TCL_LEAVE_ERR_MSG)) {
goto errorInUnset;
}
CACHE_STACK_INFO();
TRACE_APPEND("OK\n");
NEXT_INST_V(2, cleanup, 0);
errorInUnset:
CACHE_STACK_INFO();
TRACE_ERROR(interp);
goto gotError;
}
|
| ︙ | ︙ | |||
3930 3931 3932 3933 3934 3935 3936 |
case INST_CONST_IMM:
opnd = TclGetUInt4AtPtr(pc+1);
pcAdjustment = 5;
cleanup = 1;
part1Ptr = NULL;
objPtr = OBJ_AT_TOS;
| | | | | 3933 3934 3935 3936 3937 3938 3939 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 |
case INST_CONST_IMM:
opnd = TclGetUInt4AtPtr(pc+1);
pcAdjustment = 5;
cleanup = 1;
part1Ptr = NULL;
objPtr = OBJ_AT_TOS;
TRACE("%u \"%.30s\" => \n", opnd, O2S(objPtr));
varPtr = LOCAL(opnd);
arrayPtr = NULL;
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
goto doConst;
case INST_CONST_STK:
opnd = -1;
pcAdjustment = 1;
cleanup = 2;
part1Ptr = OBJ_UNDER_TOS;
objPtr = OBJ_AT_TOS;
TRACE("\"%.30s\" \"%.30s\" => ", O2S(part1Ptr), O2S(objPtr));
varPtr = TclObjLookupVarEx(interp, part1Ptr, NULL, 0, NULL,
/*createPart1*/1, /*createPart2*/0, &arrayPtr);
doConst:
if (TclIsVarConstant(varPtr)) {
TRACE_APPEND("\n");
NEXT_INST_V(pcAdjustment, cleanup, 0);
}
if (TclIsVarArray(varPtr)) {
msgPart = "variable is array";
goto constError;
} else if (TclIsVarArrayElement(varPtr)) {
msgPart = "name refers to an element in an array";
|
| ︙ | ︙ | |||
3977 3978 3979 3980 3981 3982 3983 |
CACHE_STACK_INFO();
if (resPtr == NULL) {
TRACE_ERROR(interp);
goto gotError;
}
}
TclSetVarConstant(varPtr);
| | | | | | | | | | | | | | 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 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 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 |
CACHE_STACK_INFO();
if (resPtr == NULL) {
TRACE_ERROR(interp);
goto gotError;
}
}
TclSetVarConstant(varPtr);
TRACE_APPEND("\n");
NEXT_INST_V(pcAdjustment, cleanup, 0);
constError:
TclObjVarErrMsg(interp, part1Ptr, NULL, "make constant", msgPart, opnd);
TclSetErrorCode(interp, "TCL", "LOOKUP", "CONST");
TRACE_ERROR(interp);
goto gotError;
}
/*
* End of INST_CONST instructions.
* -----------------------------------------------------------------
* Start of INST_ARRAY instructions.
*/
case INST_ARRAY_EXISTS_IMM:
opnd = TclGetUInt4AtPtr(pc+1);
pcAdjustment = 5;
cleanup = 0;
part1Ptr = NULL;
arrayPtr = NULL;
TRACE("%u => ", opnd);
varPtr = LOCAL(opnd);
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
goto doArrayExists;
case INST_ARRAY_EXISTS_STK:
opnd = -1;
pcAdjustment = 1;
cleanup = 1;
part1Ptr = OBJ_AT_TOS;
TRACE("\"%.30s\" => ", O2S(part1Ptr));
varPtr = TclObjLookupVarEx(interp, part1Ptr, NULL, 0, NULL,
/*createPart1*/0, /*createPart2*/0, &arrayPtr);
doArrayExists:
DECACHE_STACK_INFO();
result = TclCheckArrayTraces(interp, varPtr, arrayPtr, part1Ptr, opnd);
CACHE_STACK_INFO();
if (result == TCL_ERROR) {
TRACE_ERROR(interp);
goto gotError;
}
if (varPtr && TclIsVarArray(varPtr) && !TclIsVarUndefined(varPtr)) {
objResultPtr = TCONST(1);
} else {
objResultPtr = TCONST(0);
}
TRACE_RESULT(objResultPtr);
NEXT_INST_V(pcAdjustment, cleanup, 1);
case INST_ARRAY_MAKE_IMM:
opnd = TclGetUInt4AtPtr(pc+1);
pcAdjustment = 5;
cleanup = 0;
part1Ptr = NULL;
arrayPtr = NULL;
TRACE("%u => ", opnd);
varPtr = LOCAL(opnd);
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
goto doArrayMake;
case INST_ARRAY_MAKE_STK:
opnd = -1;
pcAdjustment = 1;
cleanup = 1;
part1Ptr = OBJ_AT_TOS;
TRACE("\"%.30s\" => ", O2S(part1Ptr));
varPtr = TclObjLookupVarEx(interp, part1Ptr, NULL, TCL_LEAVE_ERR_MSG,
"set", /*createPart1*/1, /*createPart2*/0, &arrayPtr);
if (varPtr == NULL) {
TRACE_ERROR(interp);
goto gotError;
}
doArrayMake:
if (varPtr && !TclIsVarArray(varPtr)) {
if (TclIsVarArrayElement(varPtr) || !TclIsVarUndefined(varPtr)) {
/*
* Either an array element, or a scalar: lose!
*/
TclObjVarErrMsg(interp, part1Ptr, NULL, "array set",
"variable isn't array", opnd);
DECACHE_STACK_INFO();
TclSetErrorCode(interp, "TCL", "WRITE", "ARRAY");
CACHE_STACK_INFO();
TRACE_ERROR(interp);
goto gotError;
}
TclInitArrayVar(varPtr);
#ifdef TCL_COMPILE_DEBUG
TRACE_APPEND("done\n");
} else {
TRACE_APPEND("nothing to do\n");
#endif
}
NEXT_INST_V(pcAdjustment, cleanup, 0);
/*
* End of INST_ARRAY instructions.
* -----------------------------------------------------------------
* Start of variable linking instructions.
*/
{
Var *otherPtr;
CallFrame *framePtr, *savedFramePtr;
Tcl_Namespace *nsPtr;
Namespace *savedNsPtr;
case INST_UPVAR:
TRACE("%d %.30s %.30s => ", TclGetInt4AtPtr(pc+1),
O2S(OBJ_UNDER_TOS), O2S(OBJ_AT_TOS));
if (TclObjGetFrame(interp, OBJ_UNDER_TOS, &framePtr) == -1) {
TRACE_ERROR(interp);
goto gotError;
}
/*
|
| ︙ | ︙ | |||
4115 4116 4117 4118 4119 4120 4121 |
if (!otherPtr) {
TRACE_ERROR(interp);
goto gotError;
}
goto doLinkVars;
case INST_NSUPVAR:
| | | | 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 |
if (!otherPtr) {
TRACE_ERROR(interp);
goto gotError;
}
goto doLinkVars;
case INST_NSUPVAR:
TRACE("%d %.30s %.30s => ", TclGetInt4AtPtr(pc+1),
O2S(OBJ_UNDER_TOS), O2S(OBJ_AT_TOS));
if (TclGetNamespaceFromObj(interp, OBJ_UNDER_TOS, &nsPtr) != TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
}
/*
* Locate the other variable.
|
| ︙ | ︙ | |||
4139 4140 4141 4142 4143 4144 4145 |
if (!otherPtr) {
TRACE_ERROR(interp);
goto gotError;
}
goto doLinkVars;
case INST_VARIABLE:
| | | 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 |
if (!otherPtr) {
TRACE_ERROR(interp);
goto gotError;
}
goto doLinkVars;
case INST_VARIABLE:
TRACE("%d, %.30s => ", TclGetInt4AtPtr(pc+1), O2S(OBJ_AT_TOS));
otherPtr = TclObjLookupVarEx(interp, OBJ_AT_TOS, NULL,
(TCL_NAMESPACE_ONLY | TCL_LEAVE_ERR_MSG), "access",
/*createPart1*/ 1, /*createPart2*/ 1, &varPtr);
if (!otherPtr) {
TRACE_ERROR(interp);
goto gotError;
}
|
| ︙ | ︙ | |||
4174 4175 4176 4177 4178 4179 4180 |
/*
* Then it is a defined link.
*/
Var *linkPtr = varPtr->value.linkPtr;
if (linkPtr == otherPtr) {
| | | 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 |
/*
* Then it is a defined link.
*/
Var *linkPtr = varPtr->value.linkPtr;
if (linkPtr == otherPtr) {
TRACE_APPEND("already linked\n");
NEXT_INST_F(5, 1, 0);
}
if (TclIsVarInHash(linkPtr)) {
VarHashRefCount(linkPtr)--;
if (TclIsVarUndefined(linkPtr)) {
TclCleanupVar(linkPtr, NULL);
}
|
| ︙ | ︙ | |||
4200 4201 4202 4203 4204 4205 4206 | } /* * Do not pop the namespace or frame index, it may be needed for other * variables - and [variable] did not push it at all. */ | | | | | | | 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 |
}
/*
* Do not pop the namespace or frame index, it may be needed for other
* variables - and [variable] did not push it at all.
*/
TRACE_APPEND("link made\n");
NEXT_INST_F(5, 1, 0);
}
break;
/*
* End of variable linking instructions.
* -----------------------------------------------------------------
*/
case INST_JUMP1:
opnd = TclGetInt1AtPtr(pc+1);
TRACE("%d => new pc %" TCL_Z_MODIFIER "u\n", opnd,
(size_t)(pc + opnd - codePtr->codeStart));
NEXT_INST_F(opnd, 0, 0);
break;
case INST_JUMP4:
opnd = TclGetInt4AtPtr(pc+1);
TRACE("%d => new pc %" TCL_Z_MODIFIER "u\n", opnd,
(size_t)(pc + opnd - codePtr->codeStart));
NEXT_INST_F(opnd, 0, 0);
{
int jmpOffset[2], b;
/* TODO: consider rewrite so we don't compute the offset we're not
* going to take. */
|
| ︙ | ︙ | |||
4249 4250 4251 4252 4253 4254 4255 |
case INST_JUMP_TRUE1:
jmpOffset[0] = 2;
jmpOffset[1] = TclGetInt1AtPtr(pc+1);
doCondJump:
valuePtr = OBJ_AT_TOS;
| | | | | | | | | | | | | > | | > | < | > > | | | | | | | | > | | | | | | | | | > | | | < | | | | | < | | | | | 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 |
case INST_JUMP_TRUE1:
jmpOffset[0] = 2;
jmpOffset[1] = TclGetInt1AtPtr(pc+1);
doCondJump:
valuePtr = OBJ_AT_TOS;
TRACE("%d => ", jmpOffset[
(*pc==INST_JUMP_FALSE1 || *pc==INST_JUMP_FALSE4) ? 0 : 1]);
/* TODO - check claim that taking address of b harms performance */
/* TODO - consider optimization search for constants */
if (TclGetBooleanFromObj(interp, valuePtr, &b) != TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
}
#ifdef TCL_COMPILE_DEBUG
if (b) {
if ((*pc == INST_JUMP_TRUE1) || (*pc == INST_JUMP_TRUE4)) {
TRACE_APPEND("%.20s true, new pc %" TCL_Z_MODIFIER "u\n", O2S(valuePtr),
(size_t)(pc + jmpOffset[1] - codePtr->codeStart));
} else {
TRACE_APPEND("%.20s true\n", O2S(valuePtr));
}
} else {
if ((*pc == INST_JUMP_TRUE1) || (*pc == INST_JUMP_TRUE4)) {
TRACE_APPEND("%.20s false\n", O2S(valuePtr));
} else {
TRACE_APPEND("%.20s false, new pc %" TCL_Z_MODIFIER "u\n", O2S(valuePtr),
(size_t)(pc + jmpOffset[0] - codePtr->codeStart));
}
}
#endif
NEXT_INST_F(jmpOffset[b], 1, 0);
}
break;
case INST_JUMP_TABLE: {
Tcl_HashEntry *hPtr;
JumptableInfo *jtPtr;
/*
* Jump to location looked up in a hashtable; fall through to next
* instr if lookup fails.
*/
opnd = TclGetInt4AtPtr(pc+1);
jtPtr = (JumptableInfo *) codePtr->auxDataArrayPtr[opnd].clientData;
TRACE("%d \"%.20s\" => ", opnd, O2S(OBJ_AT_TOS));
hPtr = Tcl_FindHashEntry(&jtPtr->hashTable, TclGetString(OBJ_AT_TOS));
if (hPtr != NULL) {
int jumpOffset = PTR2INT(Tcl_GetHashValue(hPtr));
TRACE_APPEND("found in table, new pc %" TCL_Z_MODIFIER "u\n",
(size_t)(pc - codePtr->codeStart + jumpOffset));
NEXT_INST_F(jumpOffset, 1, 0);
} else {
TRACE_APPEND("not found in table\n");
NEXT_INST_F(5, 1, 0);
}
}
break;
/*
* -----------------------------------------------------------------
* Start of general introspector instructions.
*/
case INST_NS_CURRENT:
TRACE("=> ");
objResultPtr = TclNewNamespaceObj(TclGetCurrentNamespace(interp));
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 0, 1);
break;
case INST_COROUTINE_NAME: {
CoroutineData *corPtr = iPtr->execEnvPtr->corPtr;
TRACE("=> ");
TclNewObj(objResultPtr);
if (corPtr && !(corPtr->cmdPtr->flags & CMD_DYING)) {
Tcl_GetCommandFullName(interp, (Tcl_Command) corPtr->cmdPtr,
objResultPtr);
}
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 0, 1);
break;
}
case INST_INFO_LEVEL_NUM:
TRACE("=> ");
TclNewIntObj(objResultPtr, (int)iPtr->varFramePtr->level);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 0, 1);
break;
case INST_INFO_LEVEL_ARGS: {
int level;
CallFrame *framePtr = iPtr->varFramePtr;
CallFrame *rootFramePtr = iPtr->rootFramePtr;
TRACE("\"%.30s\" => ", O2S(OBJ_AT_TOS));
if (TclGetIntFromObj(interp, OBJ_AT_TOS, &level) != TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
}
if (level <= 0) {
level += framePtr->level;
}
for (; ((int)framePtr->level!=level) && (framePtr!=rootFramePtr) ;
framePtr = framePtr->callerVarPtr) {
/* Empty loop body */
}
if (framePtr == rootFramePtr) {
TclPrintfResult(interp,
"bad level \"%s\"", TclGetString(OBJ_AT_TOS));
TRACE_ERROR(interp);
DECACHE_STACK_INFO();
TclSetErrorCode(interp, "TCL", "LOOKUP", "STACK_LEVEL",
TclGetString(OBJ_AT_TOS));
CACHE_STACK_INFO();
goto gotError;
}
objResultPtr = Tcl_NewListObj(framePtr->objc, framePtr->objv);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 1, 1);
}
{
Tcl_Command cmd, origCmd;
case INST_RESOLVE_COMMAND:
TRACE("\"%.20s\" => ", O2S(OBJ_AT_TOS));
cmd = Tcl_GetCommandFromObj(interp, OBJ_AT_TOS);
TclNewObj(objResultPtr);
if (cmd != NULL) {
Tcl_GetCommandFullName(interp, cmd, objResultPtr);
}
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 1, 1);
case INST_ORIGIN_COMMAND:
TRACE("\"%.30s\" => ", O2S(OBJ_AT_TOS));
cmd = Tcl_GetCommandFromObj(interp, OBJ_AT_TOS);
if (cmd == NULL) {
goto instOriginError;
}
origCmd = TclGetOriginalCommand(cmd);
if (origCmd == NULL) {
origCmd = cmd;
}
TclNewObj(objResultPtr);
Tcl_GetCommandFullName(interp, origCmd, objResultPtr);
if (TclCheckEmptyString(objResultPtr) == TCL_EMPTYSTRING_YES ) {
Tcl_DecrRefCount(objResultPtr);
instOriginError:
TclPrintfResult(interp,
"invalid command name \"%s\"", TclGetString(OBJ_AT_TOS));
DECACHE_STACK_INFO();
TclSetErrorCode(interp, "TCL", "LOOKUP", "COMMAND",
TclGetString(OBJ_AT_TOS));
CACHE_STACK_INFO();
TRACE_APPEND("ERROR: not command\n");
goto gotError;
}
TRACE_RESULT(OBJ_AT_TOS);
NEXT_INST_F(1, 1, 1);
}
/*
* -----------------------------------------------------------------
* Start of TclOO support instructions.
*/
{
Object *oPtr;
CallFrame *framePtr;
CallContext *contextPtr;
Tcl_Size skip, newDepth;
case INST_TCLOO_SELF:
TRACE("=> ");
framePtr = iPtr->varFramePtr;
if (framePtr == NULL ||
!(framePtr->isProcCallFrame & FRAME_IS_METHOD)) {
TRACE("=> ERROR: no TclOO call context\n");
TclPrintfResult(interp,
"self may only be called from inside a method");
DECACHE_STACK_INFO();
OO_ERROR(interp, CONTEXT_REQUIRED);
CACHE_STACK_INFO();
goto gotError;
}
contextPtr = (CallContext *)framePtr->clientData;
/*
* Call out to get the name; it's expensive to compute but cached.
*/
objResultPtr = TclOOObjectName(interp, contextPtr->oPtr);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 0, 1);
case INST_TCLOO_NEXT_CLASS:
opnd = TclGetUInt1AtPtr(pc+1);
framePtr = iPtr->varFramePtr;
valuePtr = OBJ_AT_DEPTH(opnd - 2);
objv = &OBJ_AT_DEPTH(opnd - 1);
skip = 2;
TRACE("%d => ", opnd);
if (framePtr == NULL ||
!(framePtr->isProcCallFrame & FRAME_IS_METHOD)) {
TRACE_APPEND("ERROR: no TclOO call context\n");
TclPrintfResult(interp,
"nextto may only be called from inside a method");
DECACHE_STACK_INFO();
OO_ERROR(interp, CONTEXT_REQUIRED);
CACHE_STACK_INFO();
goto gotError;
}
contextPtr = (CallContext *)framePtr->clientData;
oPtr = (Object *) Tcl_GetObjectFromObj(interp, valuePtr);
if (oPtr == NULL) {
TRACE_APPEND("ERROR: \"%.30s\" not object\n", O2S(valuePtr));
goto gotError;
} else {
Class *classPtr = oPtr->classPtr;
struct MInvoke *miPtr;
Tcl_Size i;
const char *methodType;
if (classPtr == NULL) {
TRACE_APPEND("ERROR: \"%.30s\" not class\n", O2S(valuePtr));
TclPrintfResult(interp,
"\"%s\" is not a class", TclGetString(valuePtr));
DECACHE_STACK_INFO();
OO_ERROR(interp, CLASS_REQUIRED);
CACHE_STACK_INFO();
goto gotError;
}
for (i=contextPtr->index+1 ; i<contextPtr->callPtr->numChain ; i++) {
|
| ︙ | ︙ | |||
4513 4514 4515 4516 4517 4518 4519 |
methodType = "constructor";
} else if (contextPtr->callPtr->flags & DESTRUCTOR) {
methodType = "destructor";
} else {
methodType = "method";
}
| | | | | | | | | | | < | 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 |
methodType = "constructor";
} else if (contextPtr->callPtr->flags & DESTRUCTOR) {
methodType = "destructor";
} else {
methodType = "method";
}
TRACE_APPEND("ERROR: \"%.30s\" not on reachable chain\n",
O2S(valuePtr));
for (i = contextPtr->index ; i != TCL_INDEX_NONE ; i--) {
miPtr = contextPtr->callPtr->chain + i;
if (miPtr->isFilter
|| miPtr->mPtr->declaringClassPtr != classPtr) {
continue;
}
TclPrintfResult(interp,
"%s implementation by \"%s\" not reachable from here",
methodType, TclGetString(valuePtr));
DECACHE_STACK_INFO();
OO_ERROR(interp, CLASS_NOT_REACHABLE);
CACHE_STACK_INFO();
goto gotError;
}
TclPrintfResult(interp,
"%s has no non-filter implementation by \"%s\"",
methodType, TclGetString(valuePtr));
DECACHE_STACK_INFO();
OO_ERROR(interp, CLASS_NOT_THERE);
CACHE_STACK_INFO();
goto gotError;
}
case INST_TCLOO_NEXT:
opnd = TclGetUInt1AtPtr(pc+1);
objv = &OBJ_AT_DEPTH(opnd - 1);
framePtr = iPtr->varFramePtr;
skip = 1;
TRACE("%d => ", opnd);
if (framePtr == NULL ||
!(framePtr->isProcCallFrame & FRAME_IS_METHOD)) {
TRACE_APPEND("ERROR: no TclOO call context\n");
TclPrintfResult(interp,
"next may only be called from inside a method");
DECACHE_STACK_INFO();
OO_ERROR(interp, CONTEXT_REQUIRED);
CACHE_STACK_INFO();
goto gotError;
}
contextPtr = (CallContext *)framePtr->clientData;
|
| ︙ | ︙ | |||
4576 4577 4578 4579 4580 4581 4582 |
methodType = "constructor";
} else if (contextPtr->callPtr->flags & DESTRUCTOR) {
methodType = "destructor";
} else {
methodType = "method";
}
| | < | | 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 |
methodType = "constructor";
} else if (contextPtr->callPtr->flags & DESTRUCTOR) {
methodType = "destructor";
} else {
methodType = "method";
}
TRACE_APPEND("ERROR: no TclOO next impl\n");
TclPrintfResult(interp, "no next %s implementation", methodType);
DECACHE_STACK_INFO();
OO_ERROR(interp, NOTHING_NEXT);
CACHE_STACK_INFO();
goto gotError;
#ifdef TCL_COMPILE_DEBUG
} else if (tclTraceExec >= 2) {
int i;
|
| ︙ | ︙ | |||
4650 4651 4652 4653 4654 4655 4656 4657 4658 |
(Tcl_ObjectContext) contextPtr, opnd, objv);
}
return ((Tcl_MethodCallProc2 *)(void *)(mPtr->typePtr->callProc))(mPtr->clientData, interp,
(Tcl_ObjectContext) contextPtr, opnd, objv);
}
case INST_TCLOO_IS_OBJECT:
oPtr = (Object *) Tcl_GetObjectFromObj(interp, OBJ_AT_TOS);
objResultPtr = TCONST(oPtr != NULL ? 1 : 0);
| > | > | | > | < | | 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 |
(Tcl_ObjectContext) contextPtr, opnd, objv);
}
return ((Tcl_MethodCallProc2 *)(void *)(mPtr->typePtr->callProc))(mPtr->clientData, interp,
(Tcl_ObjectContext) contextPtr, opnd, objv);
}
case INST_TCLOO_IS_OBJECT:
TRACE("%.30s => ", O2S(OBJ_AT_TOS));
oPtr = (Object *) Tcl_GetObjectFromObj(interp, OBJ_AT_TOS);
objResultPtr = TCONST(oPtr != NULL ? 1 : 0);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 1, 1);
case INST_TCLOO_CLASS:
TRACE("%.30s => ", O2S(OBJ_AT_TOS));
oPtr = (Object *) Tcl_GetObjectFromObj(interp, OBJ_AT_TOS);
if (oPtr == NULL) {
TRACE_APPEND("ERROR: not object\n");
goto gotError;
}
objResultPtr = TclOOObjectName(interp, oPtr->selfCls->thisPtr);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 1, 1);
case INST_TCLOO_NS:
TRACE("%.30s => ", O2S(OBJ_AT_TOS));
oPtr = (Object *) Tcl_GetObjectFromObj(interp, OBJ_AT_TOS);
if (oPtr == NULL) {
TRACE_APPEND("ERROR: not object\n");
goto gotError;
}
objResultPtr = TclNewNamespaceObj(oPtr->namespacePtr);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 1, 1);
}
/*
* End of TclOO support instructions.
* -----------------------------------------------------------------
* Start of INST_LIST and related instructions.
|
| ︙ | ︙ | |||
4693 4694 4695 4696 4697 4698 4699 4700 |
case INST_LIST:
/*
* Pop the opnd (objc) top stack elements into a new list obj and then
* decrement their ref counts.
*/
opnd = TclGetUInt4AtPtr(pc+1);
objResultPtr = Tcl_NewListObj(opnd, &OBJ_AT_DEPTH(opnd-1));
| > | | | | | 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 |
case INST_LIST:
/*
* Pop the opnd (objc) top stack elements into a new list obj and then
* decrement their ref counts.
*/
opnd = TclGetUInt4AtPtr(pc+1);
TRACE("%u => ", opnd);
objResultPtr = Tcl_NewListObj(opnd, &OBJ_AT_DEPTH(opnd-1));
TRACE_RESULT(objResultPtr);
NEXT_INST_V(5, opnd, 1);
case INST_LIST_LENGTH:
TRACE("\"%.30s\" => ", O2S(OBJ_AT_TOS));
if (TclListObjLength(interp, OBJ_AT_TOS, &length) != TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
}
TclNewIntObj(objResultPtr, length);
TRACE_APPEND("%" TCL_SIZE_MODIFIER "d\n", length);
NEXT_INST_F(1, 1, 1);
case INST_LIST_INDEX: /* lindex with objc == 3 */
value2Ptr = OBJ_AT_TOS;
valuePtr = OBJ_UNDER_TOS;
TRACE("\"%.30s\" \"%.30s\" => ", O2S(valuePtr), O2S(value2Ptr));
/* special case for AbstractList */
if (TclObjTypeHasProc(valuePtr, indexProc)) {
DECACHE_STACK_INFO();
length = TclObjTypeLength(valuePtr);
if (TclGetIntForIndexM(interp, value2Ptr, length-1, &index)!=TCL_OK) {
CACHE_STACK_INFO();
|
| ︙ | ︙ | |||
4784 4785 4786 4787 4788 4789 4790 | goto gotError; } /* * Stash the list element on the stack. */ | | | | 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 |
goto gotError;
}
/*
* Stash the list element on the stack.
*/
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 2, -1); /* Already has the correct refCount */
case INST_LIST_INDEX_IMM: /* lindex with objc==3 and index in bytecode
* stream */
/*
* Pop the list and get the index.
*/
valuePtr = OBJ_AT_TOS;
opnd = TclGetInt4AtPtr(pc+1);
TRACE("\"%.30s\" %d => ", O2S(valuePtr), opnd);
/*
* Get the contents of the list, making sure that it really is a list
* in the process.
*/
/* special case for AbstractList */
|
| ︙ | ︙ | |||
4847 4848 4849 4850 4851 4852 4853 |
objResultPtr = objv[index];
} else {
TclNewObj(objResultPtr);
}
lindexFastPath2:
| | | | | | 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 |
objResultPtr = objv[index];
} else {
TclNewObj(objResultPtr);
}
lindexFastPath2:
TRACE_RESULT(objResultPtr);
NEXT_INST_F(pcAdjustment, 1, 1);
case INST_LIST_INDEX_MULTI: /* 'lindex' with multiple index args */
/*
* Determine the count of index args.
*/
opnd = TclGetUInt4AtPtr(pc+1);
numIndices = opnd-1;
/*
* Do the 'lindex' operation.
*/
TRACE("%d => ", opnd);
objResultPtr = TclLindexFlat(interp, OBJ_AT_DEPTH(numIndices),
numIndices, &OBJ_AT_DEPTH(numIndices - 1));
if (!objResultPtr) {
TRACE_ERROR(interp);
goto gotError;
}
/*
* Set result.
*/
TRACE_RESULT(objResultPtr);
NEXT_INST_V(5, opnd, -1);
case INST_LSET_FLAT:
/*
* Lset with 3, 5, or more args. Get the number of index args.
*/
opnd = TclGetUInt4AtPtr(pc + 1);
numIndices = opnd - 2;
TRACE("%d => ", opnd);
/*
* Get the old value of variable, and remove the stack ref. This is
* safe because the variable still references the object; the ref
* count will never go zero here - we can use the smaller macro
* Tcl_DecrRefCount.
*/
|
| ︙ | ︙ | |||
4919 4920 4921 4922 4923 4924 4925 | goto gotError; } /* * Set result. */ CACHE_STACK_INFO(); | | | | | | | | 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 |
goto gotError;
}
/*
* Set result.
*/
CACHE_STACK_INFO();
TRACE_RESULT(objResultPtr);
NEXT_INST_V(5, numIndices+1, -1);
case INST_LSET_LIST: /* 'lset' with 4 args */
/*
* Get the old value of variable, and remove the stack ref. This is
* safe because the variable still references the object; the ref
* count will never go zero here - we can use the smaller macro
* Tcl_DecrRefCount.
*/
objPtr = POP_OBJECT();
Tcl_DecrRefCount(objPtr); /* This one should be done here. */
/*
* Get the new element value, and the index list.
*/
valuePtr = OBJ_AT_TOS;
value2Ptr = OBJ_UNDER_TOS;
TRACE("\"%.30s\" \"%.30s\" \"%.30s\" => ",
O2S(value2Ptr), O2S(valuePtr), O2S(objPtr));
/*
* Compute the new variable value.
*/
objResultPtr = TclLsetList(interp, objPtr, value2Ptr, valuePtr);
if (!objResultPtr) {
TRACE_ERROR(interp);
goto gotError;
}
/*
* Set result.
*/
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 2, -1);
case INST_LIST_RANGE_IMM: /* lrange with objc==4 and both indices in
* bytecode stream */
/*
* Pop the list and get the indices.
*/
valuePtr = OBJ_AT_TOS;
fromIdx = TclGetInt4AtPtr(pc+1);
toIdx = TclGetInt4AtPtr(pc+5);
TRACE("\"%.30s\" %d %d => ", O2S(valuePtr), TclGetInt4AtPtr(pc+1),
TclGetInt4AtPtr(pc+5));
/*
* Get the length of the list, making sure that it really is a list
* in the process.
*/
if (TclListObjLength(interp, valuePtr, &objc) != TCL_OK) {
|
| ︙ | ︙ | |||
4997 4998 4999 5000 5001 5002 5003 |
}
#endif
/* Every range of an empty list is an empty list */
if (objc == 0) {
/* avoid return of not canonical list (e. g. spaces in string repr.) */
if (!valuePtr->bytes || !valuePtr->length) {
| | | | 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 |
}
#endif
/* Every range of an empty list is an empty list */
if (objc == 0) {
/* avoid return of not canonical list (e. g. spaces in string repr.) */
if (!valuePtr->bytes || !valuePtr->length) {
TRACE_APPEND("\n");
NEXT_INST_F(9, 0, 0);
}
goto emptyList;
}
/* Decode index value operands. */
if (toIdx == TCL_INDEX_NONE) {
emptyList:
TclNewObj(objResultPtr);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(9, 1, 1);
}
toIdx = TclIndexDecode(toIdx, objc - 1);
if (toIdx == TCL_INDEX_NONE) {
goto emptyList;
} else if (toIdx >= objc) {
toIdx = objc - 1;
|
| ︙ | ︙ | |||
5045 5046 5047 5048 5049 5050 5051 |
if (objResultPtr == NULL) {
CACHE_STACK_INFO();
TRACE_ERROR(interp);
goto gotError;
}
CACHE_STACK_INFO();
| | | | 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 |
if (objResultPtr == NULL) {
CACHE_STACK_INFO();
TRACE_ERROR(interp);
goto gotError;
}
CACHE_STACK_INFO();
TRACE_RESULT(objResultPtr);
NEXT_INST_F(9, 1, 1);
case INST_LIST_IN:
case INST_LIST_NOT_IN: /* Basic list containment operators. */
value2Ptr = OBJ_AT_TOS;
valuePtr = OBJ_UNDER_TOS;
s1 = TclGetStringFromObj(valuePtr, &s1len);
TRACE("\"%.30s\" \"%.30s\" => ", O2S(valuePtr), O2S(value2Ptr));
if (TclObjTypeHasProc(value2Ptr, inOperProc) != NULL) {
int status = TclObjTypeInOperator(interp, valuePtr, value2Ptr, &match);
if (status != TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
}
|
| ︙ | ︙ | |||
5112 5113 5114 5115 5116 5117 5118 |
}
}
if (*pc == INST_LIST_NOT_IN) {
match = !match;
}
| | | | | | 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 |
}
}
if (*pc == INST_LIST_NOT_IN) {
match = !match;
}
TRACE_APPEND("%d\n", match);
/*
* Peep-hole optimisation: if you're about to jump, do jump from here.
* We're saving the effort of pushing a boolean value only to pop it
* for branching.
*/
JUMP_PEEPHOLE_F(match, 1, 2);
case INST_LIST_CONCAT:
value2Ptr = OBJ_AT_TOS;
valuePtr = OBJ_UNDER_TOS;
TRACE("\"%.30s\" \"%.30s\" => ", O2S(valuePtr), O2S(value2Ptr));
if (Tcl_IsShared(valuePtr)) {
objResultPtr = Tcl_DuplicateObj(valuePtr);
if (Tcl_ListObjAppendList(interp, objResultPtr,
value2Ptr) != TCL_OK) {
TRACE_ERROR(interp);
TclDecrRefCount(objResultPtr);
goto gotError;
}
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 2, 1);
} else {
if (Tcl_ListObjAppendList(interp, valuePtr, value2Ptr) != TCL_OK){
TRACE_ERROR(interp);
goto gotError;
}
TRACE_RESULT(valuePtr);
NEXT_INST_F(1, 1, 0);
}
case INST_LREPLACE4: {
size_t numToDelete, numNewElems;
int end_indicator;
int haveSecondIndex, flags;
|
| ︙ | ︙ | |||
5210 5211 5212 5213 5214 5215 5216 |
objResultPtr = Tcl_DuplicateObj(valuePtr);
if (Tcl_ListObjReplace(interp, objResultPtr, fromIdx, numToDelete,
numNewElems, &OBJ_AT_DEPTH(numNewElems - 1)) != TCL_OK) {
TRACE_ERROR(interp);
Tcl_DecrRefCount(objResultPtr);
goto gotError;
}
| | | | 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 |
objResultPtr = Tcl_DuplicateObj(valuePtr);
if (Tcl_ListObjReplace(interp, objResultPtr, fromIdx, numToDelete,
numNewElems, &OBJ_AT_DEPTH(numNewElems - 1)) != TCL_OK) {
TRACE_ERROR(interp);
Tcl_DecrRefCount(objResultPtr);
goto gotError;
}
TRACE_RESULT(objResultPtr);
NEXT_INST_V(6, opnd, 1);
} else {
if (Tcl_ListObjReplace(interp, valuePtr, fromIdx, numToDelete,
numNewElems, &OBJ_AT_DEPTH(numNewElems - 1)) != TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
}
TRACE_RESULT(valuePtr);
NEXT_INST_V(6, opnd - 1, 0);
}
}
/*
* End of INST_LIST and related instructions.
* -----------------------------------------------------------------
|
| ︙ | ︙ | |||
5284 5285 5286 5287 5288 5289 5290 | case INST_GE: case INST_STR_GE: match = (match >= 0); break; } } | | | | | | | | | | | | | | | 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 |
case INST_GE:
case INST_STR_GE:
match = (match >= 0);
break;
}
}
TRACE("\"%.20s\" \"%.20s\" => %d\n", O2S(valuePtr), O2S(value2Ptr),
(match < 0 ? -1 : match > 0 ? 1 : 0));
JUMP_PEEPHOLE_F(match, 1, 2);
case INST_STR_LEN:
valuePtr = OBJ_AT_TOS;
slength = Tcl_GetCharLength(valuePtr);
TclNewIntObj(objResultPtr, slength);
TRACE("\"%.20s\" => %" TCL_Z_MODIFIER "u\n", O2S(valuePtr), slength);
NEXT_INST_F(1, 1, 1);
case INST_STR_UPPER:
valuePtr = OBJ_AT_TOS;
TRACE("\"%.20s\" => ", O2S(valuePtr));
if (Tcl_IsShared(valuePtr)) {
s1 = TclGetStringFromObj(valuePtr, &slength);
TclNewStringObj(objResultPtr, s1, slength);
slength = Tcl_UtfToUpper(TclGetString(objResultPtr));
Tcl_SetObjLength(objResultPtr, slength);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 1, 1);
} else {
slength = Tcl_UtfToUpper(TclGetString(valuePtr));
Tcl_SetObjLength(valuePtr, slength);
TclFreeInternalRep(valuePtr);
TRACE_RESULT(valuePtr);
NEXT_INST_F(1, 0, 0);
}
case INST_STR_LOWER:
valuePtr = OBJ_AT_TOS;
TRACE("\"%.20s\" => ", O2S(valuePtr));
if (Tcl_IsShared(valuePtr)) {
s1 = TclGetStringFromObj(valuePtr, &slength);
TclNewStringObj(objResultPtr, s1, slength);
slength = Tcl_UtfToLower(TclGetString(objResultPtr));
Tcl_SetObjLength(objResultPtr, slength);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 1, 1);
} else {
slength = Tcl_UtfToLower(TclGetString(valuePtr));
Tcl_SetObjLength(valuePtr, slength);
TclFreeInternalRep(valuePtr);
TRACE_RESULT(valuePtr);
NEXT_INST_F(1, 0, 0);
}
case INST_STR_TITLE:
valuePtr = OBJ_AT_TOS;
TRACE("\"%.20s\" => ", O2S(valuePtr));
if (Tcl_IsShared(valuePtr)) {
s1 = TclGetStringFromObj(valuePtr, &slength);
TclNewStringObj(objResultPtr, s1, slength);
slength = Tcl_UtfToTitle(TclGetString(objResultPtr));
Tcl_SetObjLength(objResultPtr, slength);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 1, 1);
} else {
slength = Tcl_UtfToTitle(TclGetString(valuePtr));
Tcl_SetObjLength(valuePtr, slength);
TclFreeInternalRep(valuePtr);
TRACE_RESULT(valuePtr);
NEXT_INST_F(1, 0, 0);
}
case INST_STR_INDEX:
value2Ptr = OBJ_AT_TOS;
valuePtr = OBJ_UNDER_TOS;
TRACE("\"%.20s\" %.20s => ", O2S(valuePtr), O2S(value2Ptr));
/*
* Get char length to calculate what 'end' means.
*/
slength = Tcl_GetCharLength(valuePtr);
DECACHE_STACK_INFO();
|
| ︙ | ︙ | |||
5390 5391 5392 5393 5394 5395 5396 |
TclNewObj(objResultPtr);
} else {
slength = Tcl_UniCharToUtf(ch, buf);
objResultPtr = Tcl_NewStringObj(buf, slength);
}
}
| | | | | | | | | | | | | | > > | 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 |
TclNewObj(objResultPtr);
} else {
slength = Tcl_UniCharToUtf(ch, buf);
objResultPtr = Tcl_NewStringObj(buf, slength);
}
}
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 2, 1);
case INST_STR_RANGE:
TRACE("\"%.20s\" %.20s %.20s =>",
O2S(OBJ_AT_DEPTH(2)), O2S(OBJ_UNDER_TOS), O2S(OBJ_AT_TOS));
slength = Tcl_GetCharLength(OBJ_AT_DEPTH(2)) - 1;
DECACHE_STACK_INFO();
if (TclGetIntForIndexM(interp, OBJ_UNDER_TOS, slength, &fromIdx) != TCL_OK) {
CACHE_STACK_INFO();
TRACE_ERROR(interp);
goto gotError;
}
if (TclGetIntForIndexM(interp, OBJ_AT_TOS, slength, &toIdx) != TCL_OK) {
CACHE_STACK_INFO();
TRACE_ERROR(interp);
goto gotError;
}
CACHE_STACK_INFO();
if (toIdx == TCL_INDEX_NONE) {
TclNewObj(objResultPtr);
} else {
objResultPtr = Tcl_GetRange(OBJ_AT_DEPTH(2), fromIdx, toIdx);
}
TRACE_RESULT(objResultPtr);
NEXT_INST_V(1, 3, 1);
case INST_STR_RANGE_IMM:
valuePtr = OBJ_AT_TOS;
fromIdx = TclGetInt4AtPtr(pc+1);
toIdx = TclGetInt4AtPtr(pc+5);
slength = Tcl_GetCharLength(valuePtr);
TRACE("\"%.20s\" %d %d => ", O2S(valuePtr), (int)(fromIdx), (int)(toIdx));
/* Every range of an empty value is an empty value */
if (slength == 0) {
TRACE_APPEND("\n");
NEXT_INST_F(9, 0, 0);
}
/* Decode index operands. */
toIdx = TclIndexDecode(toIdx, slength - 1);
fromIdx = TclIndexDecode(fromIdx, slength - 1);
if (toIdx == TCL_INDEX_NONE) {
TclNewObj(objResultPtr);
} else {
objResultPtr = Tcl_GetRange(valuePtr, fromIdx, toIdx);
}
TRACE_RESULT(objResultPtr);
NEXT_INST_F(9, 1, 1);
{
Tcl_UniChar *ustring1, *ustring2, *ustring3, *end, *p;
Tcl_Size length3;
Tcl_Obj *value3Ptr;
case INST_STR_REPLACE:
value3Ptr = POP_OBJECT();
valuePtr = OBJ_AT_DEPTH(2);
slength = Tcl_GetCharLength(valuePtr) - 1;
TRACE("\"%.20s\" %s %s \"%.20s\" => ", O2S(valuePtr),
O2S(OBJ_UNDER_TOS), O2S(OBJ_AT_TOS), O2S(value3Ptr));
DECACHE_STACK_INFO();
if (TclGetIntForIndexM(interp, OBJ_UNDER_TOS, slength, &fromIdx) != TCL_OK
|| TclGetIntForIndexM(interp, OBJ_AT_TOS, slength, &toIdx) != TCL_OK) {
CACHE_STACK_INFO();
TclDecrRefCount(value3Ptr);
TRACE_ERROR(interp);
goto gotError;
}
CACHE_STACK_INFO();
TclDecrRefCount(OBJ_AT_TOS);
(void) POP_OBJECT();
TclDecrRefCount(OBJ_AT_TOS);
(void) POP_OBJECT();
if ((toIdx < 0) || (fromIdx > slength) || (toIdx < fromIdx)) {
TRACE_RESULT(valuePtr);
TclDecrRefCount(value3Ptr);
NEXT_INST_F(1, 0, 0);
}
if (fromIdx < 0) {
fromIdx = 0;
}
if (toIdx > slength) {
toIdx = slength;
}
if ((fromIdx == 0) && (toIdx == slength)) {
TclDecrRefCount(OBJ_AT_TOS);
OBJ_AT_TOS = value3Ptr;
TRACE_RESULT(value3Ptr);
NEXT_INST_F(1, 0, 0);
}
objResultPtr = TclStringReplace(interp, valuePtr, fromIdx,
toIdx - fromIdx + 1, value3Ptr, TCL_STRING_IN_PLACE);
if (objResultPtr == value3Ptr) {
/* See [Bug 82e7f67325] */
TclDecrRefCount(OBJ_AT_TOS);
OBJ_AT_TOS = value3Ptr;
TRACE_RESULT(value3Ptr);
NEXT_INST_F(1, 0, 0);
}
TclDecrRefCount(value3Ptr);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 1, 1);
case INST_STR_MAP:
valuePtr = OBJ_AT_TOS; /* "Main" string. */
value3Ptr = OBJ_UNDER_TOS; /* "Target" string. */
value2Ptr = OBJ_AT_DEPTH(2); /* "Source" string. */
TRACE("%.20s %.20s %.20s => ",
O2S(value2Ptr), O2S(value3Ptr), O2S(valuePtr));
if (value3Ptr == value2Ptr) {
objResultPtr = valuePtr;
goto doneStringMap;
} else if (valuePtr == value2Ptr) {
objResultPtr = value3Ptr;
goto doneStringMap;
}
|
| ︙ | ︙ | |||
5562 5563 5564 5565 5566 5567 5568 |
/*
* Put the rest of the unmapped chars onto result.
*/
Tcl_AppendUnicodeToObj(objResultPtr, p, ustring1 - p);
}
doneStringMap:
| < | | | | | | < | | 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 |
/*
* Put the rest of the unmapped chars onto result.
*/
Tcl_AppendUnicodeToObj(objResultPtr, p, ustring1 - p);
}
doneStringMap:
TRACE_RESULT(objResultPtr);
NEXT_INST_V(1, 3, 1);
case INST_STR_FIND:
objResultPtr = TclStringFirst(OBJ_UNDER_TOS, OBJ_AT_TOS, 0);
TRACE("%.20s %.20s => %s\n",
O2S(OBJ_UNDER_TOS), O2S(OBJ_AT_TOS), O2S(objResultPtr));
NEXT_INST_F(1, 2, 1);
case INST_STR_FIND_LAST:
objResultPtr = TclStringLast(OBJ_UNDER_TOS, OBJ_AT_TOS, TCL_SIZE_MAX - 1);
TRACE("%.20s %.20s => %s\n",
O2S(OBJ_UNDER_TOS), O2S(OBJ_AT_TOS), O2S(objResultPtr));
NEXT_INST_F(1, 2, 1);
case INST_STR_CLASS:
opnd = TclGetInt1AtPtr(pc+1);
valuePtr = OBJ_AT_TOS;
TRACE("%s \"%.30s\" => ", tclStringClassTable[opnd].name, O2S(valuePtr));
ustring1 = Tcl_GetUnicodeFromObj(valuePtr, &slength);
match = 1;
if (slength > 0) {
int ch;
end = ustring1 + slength;
for (p=ustring1 ; p<end ; ) {
ch = *p++;
if (!tclStringClassTable[opnd].comparator(ch)) {
match = 0;
break;
}
}
}
TRACE_APPEND("%d\n", match);
JUMP_PEEPHOLE_F(match, 2, 1);
}
case INST_STR_MATCH:
nocase = TclGetInt1AtPtr(pc+1);
valuePtr = OBJ_AT_TOS; /* String */
value2Ptr = OBJ_UNDER_TOS; /* Pattern */
|
| ︙ | ︙ | |||
5637 5638 5639 5640 5641 5642 5643 | } /* * Reuse value2Ptr object already on stack if possible. Adjustment is * 2 due to the nocase byte */ | | | 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 |
}
/*
* Reuse value2Ptr object already on stack if possible. Adjustment is
* 2 due to the nocase byte
*/
TRACE("%.20s %.20s => %d\n", O2S(valuePtr), O2S(value2Ptr), match);
/*
* Peep-hole optimisation: if you're about to jump, do jump from here.
*/
JUMP_PEEPHOLE_F(match, 2, 2);
|
| ︙ | ︙ | |||
5679 5680 5681 5682 5683 5684 5685 |
/*
* Careful here; trim set often contains non-ASCII characters so we
* take care when printing. [Bug 971cb4f1db]
*/
#ifdef TCL_COMPILE_DEBUG
if (traceInstructions) {
| | | 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 |
/*
* Careful here; trim set often contains non-ASCII characters so we
* take care when printing. [Bug 971cb4f1db]
*/
#ifdef TCL_COMPILE_DEBUG
if (traceInstructions) {
TRACE("\"%.30s\" ", O2S(valuePtr));
TclPrintObject(stdout, value2Ptr, 30);
printf(" => ");
}
#endif
if (trim1 == 0 && trim2 == 0) {
#ifdef TCL_COMPILE_DEBUG
if (traceInstructions) {
|
| ︙ | ︙ | |||
5708 5709 5710 5711 5712 5713 5714 |
}
}
case INST_REGEXP:
cflags = TclGetInt1AtPtr(pc+1); /* RE compile flages like NOCASE */
valuePtr = OBJ_AT_TOS; /* String */
value2Ptr = OBJ_UNDER_TOS; /* Pattern */
| | | | 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 |
}
}
case INST_REGEXP:
cflags = TclGetInt1AtPtr(pc+1); /* RE compile flages like NOCASE */
valuePtr = OBJ_AT_TOS; /* String */
value2Ptr = OBJ_UNDER_TOS; /* Pattern */
TRACE("\"%.30s\" \"%.30s\" => ", O2S(valuePtr), O2S(value2Ptr));
/*
* Compile and match the regular expression.
*/
{
Tcl_RegExp regExpr =
Tcl_GetRegExpFromObj(interp, value2Ptr, cflags);
if (regExpr == NULL) {
TRACE_ERROR(interp);
goto gotError;
}
match = Tcl_RegExpExecObj(interp, regExpr, valuePtr, 0, 0, 0);
if (match < 0) {
TRACE_ERROR(interp);
goto gotError;
}
}
TRACE_APPEND("%d\n", match);
/*
* Peep-hole optimisation: if you're about to jump, do jump from here.
* Adjustment is 2 due to the nocase byte.
*/
JUMP_PEEPHOLE_F(match, 2, 2);
|
| ︙ | ︙ | |||
5755 5756 5757 5758 5759 5760 5761 |
Tcl_WideInt w1, w2, wResult;
case INST_NUM_TYPE:
if (GetNumberFromObj(NULL, OBJ_AT_TOS, &ptr1, &type1) != TCL_OK) {
type1 = 0;
}
TclNewIntObj(objResultPtr, type1);
| | | 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 |
Tcl_WideInt w1, w2, wResult;
case INST_NUM_TYPE:
if (GetNumberFromObj(NULL, OBJ_AT_TOS, &ptr1, &type1) != TCL_OK) {
type1 = 0;
}
TclNewIntObj(objResultPtr, type1);
TRACE("\"%.20s\" => %d\n", O2S(OBJ_AT_TOS), type1);
NEXT_INST_F(1, 1, 1);
case INST_EQ:
case INST_NEQ:
case INST_LT:
case INST_GT:
case INST_LE:
|
| ︙ | ︙ | |||
5836 5837 5838 5839 5840 5841 5842 |
}
/*
* Peep-hole optimisation: if you're about to jump, do jump from here.
*/
foundResult:
| | | | | | | | | | | | | | 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 |
}
/*
* Peep-hole optimisation: if you're about to jump, do jump from here.
*/
foundResult:
TRACE("\"%.20s\" \"%.20s\" => %d\n", O2S(valuePtr), O2S(value2Ptr),
iResult);
JUMP_PEEPHOLE_F(iResult, 1, 2);
}
case INST_MOD:
case INST_LSHIFT:
case INST_RSHIFT:
case INST_BITOR:
case INST_BITXOR:
case INST_BITAND:
value2Ptr = OBJ_AT_TOS;
valuePtr = OBJ_UNDER_TOS;
if ((GetNumberFromObj(NULL, valuePtr, &ptr1, &type1) != TCL_OK)
|| (type1==TCL_NUMBER_DOUBLE) || (type1==TCL_NUMBER_NAN)) {
TRACE("%.20s %.20s => ILLEGAL 1st TYPE %s\n", O2S(valuePtr),
O2S(value2Ptr), (valuePtr->typePtr?
valuePtr->typePtr->name : "null"));
DECACHE_STACK_INFO();
IllegalExprOperandType(interp, "left ", pc, valuePtr);
CACHE_STACK_INFO();
goto gotError;
}
if ((GetNumberFromObj(NULL, value2Ptr, &ptr2, &type2) != TCL_OK)
|| (type2==TCL_NUMBER_DOUBLE) || (type2==TCL_NUMBER_NAN)) {
TRACE("%.20s %.20s => ILLEGAL 2nd TYPE %s\n", O2S(valuePtr),
O2S(value2Ptr), (value2Ptr->typePtr?
value2Ptr->typePtr->name : "null"));
DECACHE_STACK_INFO();
IllegalExprOperandType(interp, "right ", pc, value2Ptr);
CACHE_STACK_INFO();
goto gotError;
}
/*
* Check for common, simple case.
*/
if ((type1 == TCL_NUMBER_INT) && (type2 == TCL_NUMBER_INT)) {
w1 = *((const Tcl_WideInt *)ptr1);
w2 = *((const Tcl_WideInt *)ptr2);
switch (*pc) {
case INST_MOD:
if (w2 == 0) {
TRACE("%s %s => DIVIDE BY ZERO\n", O2S(valuePtr),
O2S(value2Ptr));
goto divideByZero;
} else if ((w2 == 1) || (w2 == -1)) {
/*
* Div. by |1| always yields remainder of 0.
*/
TRACE("%s %s => ", O2S(valuePtr), O2S(value2Ptr));
objResultPtr = TCONST(0);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 2, 1);
} else if (w1 == 0) {
/*
* 0 % (non-zero) always yields remainder of 0.
*/
TRACE("%s %s => ", O2S(valuePtr), O2S(value2Ptr));
objResultPtr = TCONST(0);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 2, 1);
} else {
wResult = w1 / w2;
/*
* Force Tcl's integer division rules.
* TODO: examine for logic simplification
|
| ︙ | ︙ | |||
5925 5926 5927 5928 5929 5930 5931 |
(Tcl_WideUInt)w2*(Tcl_WideUInt)wResult);
goto wideResultOfArithmetic;
}
break;
case INST_RSHIFT:
if (w2 < 0) {
| < | | | < | | | | < | | | < | | | | | | | 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 |
(Tcl_WideUInt)w2*(Tcl_WideUInt)wResult);
goto wideResultOfArithmetic;
}
break;
case INST_RSHIFT:
if (w2 < 0) {
TclPrintfResult(interp, "negative shift argument");
#ifdef ERROR_CODE_FOR_EARLY_DETECTED_ARITH_ERROR
DECACHE_STACK_INFO();
TclSetErrorCode(interp, "ARITH", "DOMAIN",
"domain error: argument not in valid range");
CACHE_STACK_INFO();
#endif /* ERROR_CODE_FOR_EARLY_DETECTED_ARITH_ERROR */
goto gotError;
} else if (w1 == 0) {
TRACE("%s %s => ", O2S(valuePtr), O2S(value2Ptr));
objResultPtr = TCONST(0);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 2, 1);
} else {
/*
* Quickly force large right shifts to 0 or -1.
*/
if (w2 >= (Tcl_WideInt)(CHAR_BIT*sizeof(w1))) {
/*
* We assume that INT_MAX is much larger than the
* number of bits in a Tcl_WideInt. This is a pretty safe
* assumption, given that the former is usually around
* 4e9 and the latter 64...
*/
TRACE("%s %s => ", O2S(valuePtr), O2S(value2Ptr));
if (w1 > 0L) {
objResultPtr = TCONST(0);
} else {
TclNewIntObj(objResultPtr, -1);
}
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 2, 1);
}
/*
* Handle shifts within the native Tcl_WideInt range.
*/
wResult = w1 >> ((int) w2);
goto wideResultOfArithmetic;
}
break;
case INST_LSHIFT:
if (w2 < 0) {
TclPrintfResult(interp, "negative shift argument");
#ifdef ERROR_CODE_FOR_EARLY_DETECTED_ARITH_ERROR
DECACHE_STACK_INFO();
TclSetErrorCode(interp, "ARITH", "DOMAIN",
"domain error: argument not in valid range");
CACHE_STACK_INFO();
#endif /* ERROR_CODE_FOR_EARLY_DETECTED_ARITH_ERROR */
goto gotError;
} else if (w1 == 0) {
TRACE("%s %s => ", O2S(valuePtr), O2S(value2Ptr));
objResultPtr = TCONST(0);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 2, 1);
} else if (w2 > INT_MAX) {
/*
* Technically, we could hold the value (1 << (INT_MAX+1))
* in an mp_int, but since we're using mp_mul_2d() to do
* the work, and it takes only an int argument, that's a
* good place to draw the line.
*/
TclPrintfResult(interp,
"integer value too large to represent");
#ifdef ERROR_CODE_FOR_EARLY_DETECTED_ARITH_ERROR
DECACHE_STACK_INFO();
TclSetErrorCode(interp, "ARITH", "IOVERFLOW",
"integer value too large to represent");
CACHE_STACK_INFO();
#endif /* ERROR_CODE_FOR_EARLY_DETECTED_ARITH_ERROR */
goto gotError;
} else {
int shift = (int) w2;
/*
|
| ︙ | ︙ | |||
6025 6026 6027 6028 6029 6030 6031 | } } /* * Too large; need to use the broken-out function. */ | | | | | | | | | | | 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 |
}
}
/*
* Too large; need to use the broken-out function.
*/
TRACE("%s %s => ", O2S(valuePtr), O2S(value2Ptr));
break;
case INST_BITAND:
wResult = w1 & w2;
goto wideResultOfArithmetic;
case INST_BITOR:
wResult = w1 | w2;
goto wideResultOfArithmetic;
case INST_BITXOR:
wResult = w1 ^ w2;
goto wideResultOfArithmetic;
}
}
/*
* DO NOT MERGE THIS WITH THE EQUIVALENT SECTION LATER! That would
* encourage the compiler to inline ExecuteExtendedBinaryMathOp, which
* is highly undesirable due to the overall impact on size.
*/
TRACE("%s %s => ", O2S(valuePtr), O2S(value2Ptr));
objResultPtr = ExecuteExtendedBinaryMathOp(interp, *pc, &TCONST(0),
valuePtr, value2Ptr);
if (objResultPtr == DIVIDED_BY_ZERO) {
TRACE_APPEND("DIVIDE BY ZERO\n");
goto divideByZero;
} else if (objResultPtr == GENERAL_ARITHMETIC_ERROR) {
TRACE_ERROR(interp);
goto gotError;
} else if (objResultPtr == NULL) {
TRACE_RESULT(valuePtr);
NEXT_INST_F(1, 1, 0);
} else {
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 2, 1);
}
case INST_EXPON:
case INST_ADD:
case INST_SUB:
case INST_DIV:
case INST_MULT:
value2Ptr = OBJ_AT_TOS;
valuePtr = OBJ_UNDER_TOS;
if ((GetNumberFromObj(NULL, valuePtr, &ptr1, &type1) != TCL_OK)
|| IsErroringNaNType(type1)) {
TRACE("%.20s %.20s => ILLEGAL 1st TYPE %s\n",
O2S(value2Ptr), O2S(valuePtr),
(valuePtr->typePtr ? valuePtr->typePtr->name : "null"));
DECACHE_STACK_INFO();
IllegalExprOperandType(interp, "left ", pc, valuePtr);
CACHE_STACK_INFO();
goto gotError;
}
#ifdef ACCEPT_NAN
if (type1 == TCL_NUMBER_NAN) {
/*
* NaN first argument -> result is also NaN.
*/
NEXT_INST_F(1, 1, 0);
}
#endif
if ((GetNumberFromObj(NULL, value2Ptr, &ptr2, &type2) != TCL_OK)
|| IsErroringNaNType(type2)) {
TRACE("%.20s %.20s => ILLEGAL 2nd TYPE %s\n",
O2S(value2Ptr), O2S(valuePtr),
(value2Ptr->typePtr ? value2Ptr->typePtr->name : "null"));
DECACHE_STACK_INFO();
IllegalExprOperandType(interp, "right ", pc, value2Ptr);
CACHE_STACK_INFO();
goto gotError;
}
#ifdef ACCEPT_NAN
|
| ︙ | ︙ | |||
6151 6152 6153 6154 6155 6156 6157 |
* wResult have the same sign and there is no overflow anyway.
*/
if (Overflowing(w1, ~w2, wResult)) {
goto overflow;
}
wideResultOfArithmetic:
| | | | | | | 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 |
* wResult have the same sign and there is no overflow anyway.
*/
if (Overflowing(w1, ~w2, wResult)) {
goto overflow;
}
wideResultOfArithmetic:
TRACE("%s %s => ", O2S(valuePtr), O2S(value2Ptr));
if (Tcl_IsShared(valuePtr)) {
TclNewIntObj(objResultPtr, wResult);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 2, 1);
}
TclSetIntObj(valuePtr, wResult);
TRACE_RESULT(valuePtr);
NEXT_INST_F(1, 1, 0);
break;
case INST_DIV:
if (w2 == 0) {
TRACE("%s %s => DIVIDE BY ZERO\n",
O2S(valuePtr), O2S(value2Ptr));
goto divideByZero;
} else if ((w1 == WIDE_MIN) && (w2 == -1)) {
/*
* Can't represent (-WIDE_MIN) as a Tcl_WideInt.
*/
goto overflow;
|
| ︙ | ︙ | |||
6206 6207 6208 6209 6210 6211 6212 |
/*
* Fall through with INST_EXPON, INST_DIV and large multiplies.
*/
}
overflow:
| | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 |
/*
* Fall through with INST_EXPON, INST_DIV and large multiplies.
*/
}
overflow:
TRACE("%s %s => ", O2S(valuePtr), O2S(value2Ptr));
objResultPtr = ExecuteExtendedBinaryMathOp(interp, *pc, &TCONST(0),
valuePtr, value2Ptr);
if (objResultPtr == DIVIDED_BY_ZERO) {
TRACE_APPEND("DIVIDE BY ZERO\n");
goto divideByZero;
} else if (objResultPtr == EXPONENT_OF_ZERO) {
TRACE_APPEND("EXPONENT OF ZERO\n");
goto exponOfZero;
} else if (objResultPtr == GENERAL_ARITHMETIC_ERROR) {
TRACE_ERROR(interp);
goto gotError;
} else if (objResultPtr == OUT_OF_MEMORY) {
TRACE_APPEND("OUT OF MEMORY\n");
goto outOfMemory;
} else if (objResultPtr == NULL) {
TRACE_RESULT(valuePtr);
NEXT_INST_F(1, 1, 0);
} else {
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 2, 1);
}
case INST_LNOT: {
int b;
valuePtr = OBJ_AT_TOS;
TRACE("%s => ", O2S(valuePtr));
/* TODO - check claim that taking address of b harms performance */
/* TODO - consider optimization search for constants */
if (TclGetBooleanFromObj(NULL, valuePtr, &b) != TCL_OK) {
TRACE("\"%.20s\" => ERROR: illegal type %s\n", O2S(valuePtr),
(valuePtr->typePtr ? valuePtr->typePtr->name : "null"));
DECACHE_STACK_INFO();
IllegalExprOperandType(interp, "", pc, valuePtr);
CACHE_STACK_INFO();
goto gotError;
}
/* TODO: Consider peephole opt. */
objResultPtr = TCONST(!b);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 1, 1);
}
case INST_BITNOT:
valuePtr = OBJ_AT_TOS;
TRACE("\"%.20s\" => ", O2S(valuePtr));
if ((GetNumberFromObj(NULL, valuePtr, &ptr1, &type1) != TCL_OK)
|| (type1==TCL_NUMBER_NAN) || (type1==TCL_NUMBER_DOUBLE)) {
/*
* ... ~$NonInteger => raise an error.
*/
TRACE_APPEND("ERROR: illegal type %s\n",
(valuePtr->typePtr? valuePtr->typePtr->name : "null"));
DECACHE_STACK_INFO();
IllegalExprOperandType(interp, "", pc, valuePtr);
CACHE_STACK_INFO();
goto gotError;
}
if (type1 == TCL_NUMBER_INT) {
w1 = *((const Tcl_WideInt *) ptr1);
if (Tcl_IsShared(valuePtr)) {
TclNewIntObj(objResultPtr, ~w1);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 1, 1);
}
TclSetIntObj(valuePtr, ~w1);
TRACE_RESULT(valuePtr);
NEXT_INST_F(1, 0, 0);
}
objResultPtr = ExecuteExtendedUnaryMathOp(*pc, valuePtr);
if (objResultPtr != NULL) {
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 1, 1);
} else {
TRACE_RESULT(valuePtr);
NEXT_INST_F(1, 0, 0);
}
case INST_UMINUS:
valuePtr = OBJ_AT_TOS;
TRACE("\"%.20s\" => ", O2S(valuePtr));
if ((GetNumberFromObj(NULL, valuePtr, &ptr1, &type1) != TCL_OK)
|| IsErroringNaNType(type1)) {
TRACE_APPEND("ERROR: illegal type %s \n",
(valuePtr->typePtr? valuePtr->typePtr->name : "null"));
DECACHE_STACK_INFO();
IllegalExprOperandType(interp, "", pc, valuePtr);
CACHE_STACK_INFO();
goto gotError;
}
switch (type1) {
case TCL_NUMBER_NAN:
/* -NaN => NaN */
TRACE_RESULT(valuePtr);
NEXT_INST_F(1, 0, 0);
break;
case TCL_NUMBER_INT:
w1 = *((const Tcl_WideInt *) ptr1);
if (w1 != WIDE_MIN) {
if (Tcl_IsShared(valuePtr)) {
TclNewIntObj(objResultPtr, -w1);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 1, 1);
}
TclSetIntObj(valuePtr, -w1);
TRACE_RESULT(valuePtr);
NEXT_INST_F(1, 0, 0);
}
/* FALLTHROUGH */
}
objResultPtr = ExecuteExtendedUnaryMathOp(*pc, valuePtr);
if (objResultPtr != NULL) {
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 1, 1);
} else {
TRACE_RESULT(valuePtr);
NEXT_INST_F(1, 0, 0);
}
case INST_UPLUS:
case INST_TRY_CVT_TO_NUMERIC:
/*
* Try to convert the topmost stack object to numeric object. This is
* done in order to support [expr]'s policy of interpreting operands
* if at all possible as numbers first, then strings.
*/
valuePtr = OBJ_AT_TOS;
TRACE("\"%.20s\" => ", O2S(valuePtr));
if (GetNumberFromObj(NULL, valuePtr, &ptr1, &type1) != TCL_OK) {
if (*pc == INST_UPLUS) {
/*
* ... +$NonNumeric => raise an error.
*/
TRACE_APPEND("ERROR: illegal type %s\n",
(valuePtr->typePtr ? valuePtr->typePtr->name : "null"));
DECACHE_STACK_INFO();
IllegalExprOperandType(interp, "", pc, valuePtr);
CACHE_STACK_INFO();
goto gotError;
}
/* ... TryConvertToNumeric($NonNumeric) is acceptable */
TRACE_APPEND("not numeric\n");
NEXT_INST_F(1, 0, 0);
}
if (IsErroringNaNType(type1)) {
if (*pc == INST_UPLUS) {
/*
* ... +$NonNumeric => raise an error.
*/
TRACE_APPEND("ERROR: illegal type %s\n",
(valuePtr->typePtr ? valuePtr->typePtr->name : "null"));
DECACHE_STACK_INFO();
IllegalExprOperandType(interp, "", pc, valuePtr);
CACHE_STACK_INFO();
} else {
/*
* Numeric conversion of NaN -> error.
*/
TRACE_APPEND("ERROR: IEEE floating pt error\n");
DECACHE_STACK_INFO();
TclExprFloatError(interp, *((const double *) ptr1));
CACHE_STACK_INFO();
}
goto gotError;
}
/*
* Ensure that the numeric value has a string rep the same as the
* formatted version of its internal rep. This is used, e.g., to make
* sure that "expr {0001}" yields "1", not "0001". We implement this
* by _discarding_ the string rep since we know it will be
* regenerated, if needed later, by formatting the internal rep's
* value.
*/
if (valuePtr->bytes == NULL) {
TRACE_APPEND("numeric, same Tcl_Obj\n");
NEXT_INST_F(1, 0, 0);
}
if (Tcl_IsShared(valuePtr)) {
/*
* Here we do some surgery within the Tcl_Obj internals. We want
* to copy the internalrep, but not the string, so we temporarily hide
* the string so we do not copy it.
*/
char *savedString = valuePtr->bytes;
valuePtr->bytes = NULL;
objResultPtr = Tcl_DuplicateObj(valuePtr);
valuePtr->bytes = savedString;
TRACE_APPEND("numeric, new Tcl_Obj\n");
NEXT_INST_F(1, 1, 1);
}
TclInvalidateStringRep(valuePtr);
TRACE_APPEND("numeric, same Tcl_Obj\n");
NEXT_INST_F(1, 0, 0);
}
break;
/*
* End of numeric operator instructions.
* -----------------------------------------------------------------
*/
case INST_TRY_CVT_TO_BOOLEAN:
valuePtr = OBJ_AT_TOS;
TRACE("\"%.30s\" => ", O2S(valuePtr));
if (TclHasInternalRep(valuePtr, &tclBooleanType)) {
objResultPtr = TCONST(1);
} else {
int res = (TclSetBooleanFromAny(NULL, valuePtr) == TCL_OK);
objResultPtr = TCONST(res);
}
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 0, 1);
break;
case INST_BREAK:
/*
DECACHE_STACK_INFO();
Tcl_ResetResult(interp);
CACHE_STACK_INFO();
*/
result = TCL_BREAK;
cleanup = 0;
TRACE("=> BREAK!\n");
goto processExceptionReturn;
case INST_CONTINUE:
/*
DECACHE_STACK_INFO();
Tcl_ResetResult(interp);
CACHE_STACK_INFO();
*/
result = TCL_CONTINUE;
cleanup = 0;
TRACE("=> CONTINUE!\n");
goto processExceptionReturn;
{
ForeachInfo *infoPtr;
Tcl_Obj *listPtr, **elements;
ForeachVarList *varListPtr;
Tcl_Size numLists, listLen, numVars, listTmpDepth;
Tcl_Size iterNum, iterMax, iterTmp;
Tcl_Size varIndex, valIndex, i, j;
case INST_FOREACH_START:
/*
* Initialize the data for the looping construct, pushing the
* corresponding Tcl_Objs to the stack.
*/
opnd = TclGetUInt4AtPtr(pc+1);
infoPtr = (ForeachInfo *)codePtr->auxDataArrayPtr[opnd].clientData;
numLists = infoPtr->numLists;
TRACE("%u => ", opnd);
/*
* Compute the number of iterations that will be run: iterMax
*/
iterMax = 0;
listTmpDepth = numLists-1;
for (i = 0; i < numLists; i++) {
varListPtr = infoPtr->varLists[i];
numVars = varListPtr->numVars;
listPtr = OBJ_AT_DEPTH(listTmpDepth);
DECACHE_STACK_INFO();
if (TclListObjLength(interp, listPtr, &listLen) != TCL_OK) {
CACHE_STACK_INFO();
TRACE_APPEND("ERROR converting list %" TCL_Z_MODIFIER "d, \"%s\": %s",
i, O2S(listPtr), O2S(Tcl_GetObjResult(interp)));
goto gotError;
}
if (Tcl_IsShared(listPtr)) {
objPtr = TclListObjCopy(NULL, listPtr);
Tcl_IncrRefCount(objPtr);
Tcl_DecrRefCount(listPtr);
OBJ_AT_DEPTH(listTmpDepth) = objPtr;
|
| ︙ | ︙ | |||
6522 6523 6524 6525 6526 6527 6528 | * Store a pointer to the ForeachInfo struct; same dirty trick * as above */ TclNewObj(tmpPtr); tmpPtr->internalRep.twoPtrValue.ptr1 = infoPtr; PUSH_OBJECT(tmpPtr); /* infoPtr object */ | | | | 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 |
* Store a pointer to the ForeachInfo struct; same dirty trick
* as above
*/
TclNewObj(tmpPtr);
tmpPtr->internalRep.twoPtrValue.ptr1 = infoPtr;
PUSH_OBJECT(tmpPtr); /* infoPtr object */
TRACE_APPEND("jump to loop step\n");
/*
* Jump directly to the INST_FOREACH_STEP instruction; the C code just
* falls through.
*/
pc += 5 - infoPtr->loopCtTemp;
case INST_FOREACH_STEP: /* TODO: address abstract list indexing here! */
/*
* "Step" a foreach loop (i.e., begin its next iteration) by assigning
* the next value list element to each loop var.
*/
tmpPtr = OBJ_AT_TOS;
infoPtr = (ForeachInfo *)tmpPtr->internalRep.twoPtrValue.ptr1;
numLists = infoPtr->numLists;
TRACE("=> ");
tmpPtr = OBJ_AT_DEPTH(1);
iterNum = (size_t)tmpPtr->internalRep.twoPtrValue.ptr1;
iterMax = (size_t)tmpPtr->internalRep.twoPtrValue.ptr2;
/*
* If some list still has a remaining list element iterate one more
|
| ︙ | ︙ | |||
6625 6626 6627 6628 6629 6630 6631 |
Tcl_IncrRefCount(valuePtr);
}
} else {
DECACHE_STACK_INFO();
if (TclPtrSetVarIdx(interp, varPtr, NULL, NULL, NULL,
valuePtr, TCL_LEAVE_ERR_MSG, varIndex)==NULL){
CACHE_STACK_INFO();
| | | | | | | > | | | > | | > | | | | > | | | | | | | | | | | | | < | | | | | | | | | | | < | | | | | 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 |
Tcl_IncrRefCount(valuePtr);
}
} else {
DECACHE_STACK_INFO();
if (TclPtrSetVarIdx(interp, varPtr, NULL, NULL, NULL,
valuePtr, TCL_LEAVE_ERR_MSG, varIndex)==NULL){
CACHE_STACK_INFO();
TRACE_APPEND("ERROR init. index temp %" TCL_SIZE_MODIFIER "d: %.30s",
varIndex, O2S(Tcl_GetObjResult(interp)));
goto gotError;
}
CACHE_STACK_INFO();
}
valIndex++;
}
listTmpDepth--;
}
TRACE_APPEND("jump to loop start\n");
/* loopCtTemp being 'misused' for storing the jump size */
NEXT_INST_F(infoPtr->loopCtTemp, 0, 0);
}
TRACE_APPEND("loop has no more iterations\n");
#ifdef TCL_COMPILE_DEBUG
NEXT_INST_F(1, 0, 0);
#else
/*
* FALL THROUGH
*/
pc++;
#endif
case INST_FOREACH_END:
/* THIS INSTRUCTION IS ONLY CALLED AS A BREAK TARGET */
tmpPtr = OBJ_AT_TOS;
infoPtr = (ForeachInfo *)tmpPtr->internalRep.twoPtrValue.ptr1;
numLists = infoPtr->numLists;
TRACE("=> loop terminated\n");
NEXT_INST_V(1, numLists+2, 0);
case INST_LMAP_COLLECT:
/*
* This instruction is only issued by lmap. The stack is:
* - result
* - infoPtr
* - loop counters
* - valLists
* - collecting obj (unshared)
* The instruction lappends the result to the collecting obj.
*/
tmpPtr = OBJ_AT_DEPTH(1);
infoPtr = (ForeachInfo *)tmpPtr->internalRep.twoPtrValue.ptr1;
numLists = infoPtr->numLists;
TRACE_APPEND("=> appending to list at depth %" TCL_SIZE_MODIFIER "d\n",
3 + numLists);
objPtr = OBJ_AT_DEPTH(3 + numLists);
Tcl_ListObjAppendElement(NULL, objPtr, OBJ_AT_TOS);
NEXT_INST_F(1, 1, 0);
}
break;
case INST_BEGIN_CATCH4:
/*
* Record start of the catch command with exception range index equal
* to the operand. Push the current stack depth onto the special catch
* stack.
*/
*(++catchTop) = (Tcl_Obj *)INT2PTR(CURR_DEPTH);
TRACE("%u => catchTop=%" TCL_T_MODIFIER "d, stackTop=%" TCL_T_MODIFIER "d\n",
TclGetUInt4AtPtr(pc+1), (catchTop - initCatchTop - 1),
CURR_DEPTH);
NEXT_INST_F(5, 0, 0);
break;
case INST_END_CATCH:
catchTop--;
DECACHE_STACK_INFO();
Tcl_ResetResult(interp);
CACHE_STACK_INFO();
result = TCL_OK;
TRACE("=> catchTop=%" TCL_Z_MODIFIER "u\n",
(size_t)(catchTop - initCatchTop - 1));
NEXT_INST_F(1, 0, 0);
break;
case INST_PUSH_RESULT:
TRACE("=> ");
objResultPtr = Tcl_GetObjResult(interp);
TRACE_RESULT(objResultPtr);
/*
* See the comments at INST_INVOKE_STK
*/
TclNewObj(objPtr);
Tcl_IncrRefCount(objPtr);
iPtr->objResultPtr = objPtr;
NEXT_INST_F(1, 0, -1);
break;
case INST_PUSH_RETURN_CODE:
TclNewIntObj(objResultPtr, result);
TRACE("=> %u\n", result);
NEXT_INST_F(1, 0, 1);
break;
case INST_PUSH_RETURN_OPTIONS:
TRACE("=> ");
DECACHE_STACK_INFO();
objResultPtr = Tcl_GetReturnOptions(interp, result);
CACHE_STACK_INFO();
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 0, 1);
break;
case INST_RETURN_CODE_BRANCH: {
int code;
if (TclGetIntFromObj(NULL, OBJ_AT_TOS, &code) != TCL_OK) {
Tcl_Panic("INST_RETURN_CODE_BRANCH: TOS not a return code!");
}
if (code == TCL_OK) {
Tcl_Panic("INST_RETURN_CODE_BRANCH: TOS is TCL_OK!");
}
if (code < TCL_ERROR || code > TCL_CONTINUE) {
code = TCL_CONTINUE + 1;
}
TRACE("\"%s\" => jump offset %d\n", O2S(OBJ_AT_TOS), 2*code-1);
NEXT_INST_F(2*code-1, 1, 0);
}
/*
* -----------------------------------------------------------------
* Start of dictionary-related instructions.
*/
{
int opnd2, allocateDict, done, allocdict;
Tcl_Size i;
Tcl_Obj *dictPtr, *statePtr, *keyPtr, *listPtr, *varNamePtr, *keysPtr;
Tcl_Obj *emptyPtr, **keyPtrPtr;
Tcl_DictSearch *searchPtr;
DictUpdateInfo *duiPtr;
case INST_DICT_VERIFY: {
Tcl_Size size;
dictPtr = OBJ_AT_TOS;
TRACE("\"%.30s\" => ", O2S(dictPtr));
if (Tcl_DictObjSize(interp, dictPtr, &size) != TCL_OK) {
TRACE_APPEND("ERROR verifying dictionary nature of \"%.30s\": %s\n",
O2S(dictPtr), O2S(Tcl_GetObjResult(interp)));
goto gotError;
}
TRACE_APPEND("OK\n");
NEXT_INST_F(1, 1, 0);
}
break;
case INST_DICT_EXISTS: {
int found;
opnd = TclGetUInt4AtPtr(pc+1);
TRACE("%u => ", opnd);
dictPtr = OBJ_AT_DEPTH(opnd);
if (opnd > 1) {
dictPtr = TclTraceDictPath(NULL, dictPtr, opnd-1,
&OBJ_AT_DEPTH(opnd-1), DICT_PATH_EXISTS);
if (dictPtr == NULL || dictPtr == DICT_PATH_NON_EXISTENT) {
found = 0;
goto afterDictExists;
}
}
if (Tcl_DictObjGet(NULL, dictPtr, OBJ_AT_TOS,
&objResultPtr) == TCL_OK) {
found = (objResultPtr ? 1 : 0);
} else {
found = 0;
}
afterDictExists:
TRACE_APPEND("%d\n", found);
/*
* The INST_DICT_EXISTS instruction is usually followed by a
* conditional jump, so we can take advantage of this to do some
* peephole optimization (note that we're careful to not close out
* someone doing something else).
*/
JUMP_PEEPHOLE_V(found, 5, opnd+1);
}
case INST_DICT_GET:
opnd = TclGetUInt4AtPtr(pc+1);
TRACE("%u => ", opnd);
dictPtr = OBJ_AT_DEPTH(opnd);
if (opnd > 1) {
dictPtr = TclTraceDictPath(interp, dictPtr, opnd-1,
&OBJ_AT_DEPTH(opnd-1), DICT_PATH_READ);
if (dictPtr == NULL) {
TRACE_APPEND(
"ERROR tracing dictionary path into \"%.30s\": %s\n",
O2S(OBJ_AT_DEPTH(opnd)), Tcl_GetStringResult(interp));
goto gotError;
}
}
if (Tcl_DictObjGet(interp, dictPtr, OBJ_AT_TOS,
&objResultPtr) != TCL_OK) {
TRACE_APPEND("ERROR reading leaf dictionary key \"%.30s\": %s\n",
O2S(dictPtr), Tcl_GetStringResult(interp));
goto gotError;
}
if (!objResultPtr) {
TclPrintfResult(interp,
"key \"%s\" not known in dictionary",
TclGetString(OBJ_AT_TOS));
DECACHE_STACK_INFO();
TclSetErrorCode(interp, "TCL", "LOOKUP", "DICT",
TclGetString(OBJ_AT_TOS));
CACHE_STACK_INFO();
TRACE_ERROR(interp);
goto gotError;
}
TRACE_RESULT(objResultPtr);
NEXT_INST_V(5, opnd+1, 1);
case INST_DICT_GET_DEF:
opnd = TclGetUInt4AtPtr(pc+1);
TRACE("%u => ", opnd);
dictPtr = OBJ_AT_DEPTH(opnd+1);
if (opnd > 1) {
dictPtr = TclTraceDictPath(interp, dictPtr, opnd-1,
&OBJ_AT_DEPTH(opnd), DICT_PATH_EXISTS);
if (dictPtr == NULL) {
TRACE_APPEND(
"ERROR tracing dictionary path into \"%.30s\": %s\n",
O2S(OBJ_AT_DEPTH(opnd+1)), Tcl_GetStringResult(interp));
goto gotError;
} else if (dictPtr == DICT_PATH_NON_EXISTENT) {
goto dictGetDefUseDefault;
}
}
if (Tcl_DictObjGet(interp, dictPtr, OBJ_UNDER_TOS,
&objResultPtr) != TCL_OK) {
TRACE_APPEND("ERROR reading leaf dictionary key \"%.30s\": %s\n",
O2S(dictPtr), Tcl_GetStringResult(interp));
goto gotError;
} else if (!objResultPtr) {
dictGetDefUseDefault:
objResultPtr = OBJ_AT_TOS;
}
TRACE_RESULT(objResultPtr);
NEXT_INST_V(5, opnd+2, 1);
case INST_DICT_SET:
case INST_DICT_UNSET:
case INST_DICT_INCR_IMM:
opnd = TclGetUInt4AtPtr(pc+1);
opnd2 = TclGetUInt4AtPtr(pc+5);
varPtr = LOCAL(opnd2);
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
TRACE("%u %u => ", opnd, opnd2);
if (TclIsVarDirectReadable(varPtr)) {
dictPtr = varPtr->value.objPtr;
} else {
DECACHE_STACK_INFO();
dictPtr = TclPtrGetVarIdx(interp, varPtr, NULL, NULL, NULL, 0,
opnd2);
CACHE_STACK_INFO();
|
| ︙ | ︙ | |||
6942 6943 6944 6945 6946 6947 6948 |
Tcl_Panic("Should not happen!");
}
if (result != TCL_OK) {
if (allocateDict) {
TclDecrRefCount(dictPtr);
}
| | | | 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 |
Tcl_Panic("Should not happen!");
}
if (result != TCL_OK) {
if (allocateDict) {
TclDecrRefCount(dictPtr);
}
TRACE_APPEND("ERROR updating dictionary: %s\n",
O2S(Tcl_GetObjResult(interp)));
goto checkForCatch;
}
if (TclIsVarDirectWritable(varPtr)) {
if (allocateDict) {
value2Ptr = varPtr->value.objPtr;
Tcl_IncrRefCount(dictPtr);
|
| ︙ | ︙ | |||
6974 6975 6976 6977 6978 6979 6980 |
}
}
#ifndef TCL_COMPILE_DEBUG
if (pc[9] == INST_POP) {
NEXT_INST_V(10, cleanup, 0);
}
#endif
| | | | 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 |
}
}
#ifndef TCL_COMPILE_DEBUG
if (pc[9] == INST_POP) {
NEXT_INST_V(10, cleanup, 0);
}
#endif
TRACE_RESULT(objResultPtr);
NEXT_INST_V(9, cleanup, 1);
case INST_DICT_APPEND:
case INST_DICT_LAPPEND:
opnd = TclGetUInt4AtPtr(pc+1);
varPtr = LOCAL(opnd);
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
TRACE("%u => ", opnd);
if (TclIsVarDirectReadable(varPtr)) {
dictPtr = varPtr->value.objPtr;
} else {
DECACHE_STACK_INFO();
dictPtr = TclPtrGetVarIdx(interp, varPtr, NULL, NULL, NULL, 0,
opnd);
CACHE_STACK_INFO();
|
| ︙ | ︙ | |||
7113 7114 7115 7116 7117 7118 7119 |
}
}
#ifndef TCL_COMPILE_DEBUG
if (pc[5] == INST_POP) {
NEXT_INST_F(6, 2, 0);
}
#endif
| | | | 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 |
}
}
#ifndef TCL_COMPILE_DEBUG
if (pc[5] == INST_POP) {
NEXT_INST_F(6, 2, 0);
}
#endif
TRACE_RESULT(objResultPtr);
NEXT_INST_F(5, 2, 1);
case INST_DICT_FIRST:
opnd = TclGetUInt4AtPtr(pc+1);
TRACE("%u => ", opnd);
dictPtr = POP_OBJECT();
searchPtr = (Tcl_DictSearch *)Tcl_Alloc(sizeof(Tcl_DictSearch));
if (Tcl_DictObjFirst(interp, dictPtr, searchPtr, &keyPtr,
&valuePtr, &done) != TCL_OK) {
/*
* dictPtr is no longer on the stack, and we're not
* moving it into the internalrep of an iterator. We need
|
| ︙ | ︙ | |||
7154 7155 7156 7157 7158 7159 7160 |
}
varPtr->value.objPtr = statePtr;
Tcl_IncrRefCount(statePtr);
goto pushDictIteratorResult;
case INST_DICT_NEXT:
opnd = TclGetUInt4AtPtr(pc+1);
| | | 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 |
}
varPtr->value.objPtr = statePtr;
Tcl_IncrRefCount(statePtr);
goto pushDictIteratorResult;
case INST_DICT_NEXT:
opnd = TclGetUInt4AtPtr(pc+1);
TRACE("%u => ", opnd);
statePtr = (*LOCAL(opnd)).value.objPtr;
{
const Tcl_ObjInternalRep *irPtr;
if (statePtr &&
(irPtr = TclFetchInternalRep(statePtr, &dictIteratorType))) {
searchPtr = (Tcl_DictSearch *)irPtr->twoPtrValue.ptr1;
|
| ︙ | ︙ | |||
7176 7177 7178 7179 7180 7181 7182 |
TclNewObj(emptyPtr);
PUSH_OBJECT(emptyPtr);
PUSH_OBJECT(emptyPtr);
} else {
PUSH_OBJECT(valuePtr);
PUSH_OBJECT(keyPtr);
}
| | | | | 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 |
TclNewObj(emptyPtr);
PUSH_OBJECT(emptyPtr);
PUSH_OBJECT(emptyPtr);
} else {
PUSH_OBJECT(valuePtr);
PUSH_OBJECT(keyPtr);
}
TRACE_APPEND("\"%.30s\" \"%.30s\" %d\n",
O2S(OBJ_UNDER_TOS), O2S(OBJ_AT_TOS), done);
/*
* The INST_DICT_FIRST and INST_DICT_NEXT instructions are always
* followed by a conditional jump, so we can take advantage of this to
* do some peephole optimization (note that we're careful to not close
* out someone doing something else).
*/
JUMP_PEEPHOLE_F(done, 5, 0);
case INST_DICT_UPDATE_START:
opnd = TclGetUInt4AtPtr(pc+1);
opnd2 = TclGetUInt4AtPtr(pc+5);
TRACE("%u => ", opnd);
varPtr = LOCAL(opnd);
duiPtr = (DictUpdateInfo *)codePtr->auxDataArrayPtr[opnd2].clientData;
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
if (TclIsVarDirectReadable(varPtr)) {
dictPtr = varPtr->value.objPtr;
|
| ︙ | ︙ | |||
7245 7246 7247 7248 7249 7250 7251 | TRACE_ERROR(interp); Tcl_DecrRefCount(dictPtr); goto gotError; } CACHE_STACK_INFO(); } TclDecrRefCount(dictPtr); | | | | | 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 |
TRACE_ERROR(interp);
Tcl_DecrRefCount(dictPtr);
goto gotError;
}
CACHE_STACK_INFO();
}
TclDecrRefCount(dictPtr);
TRACE_APPEND("OK\n");
NEXT_INST_F(9, 0, 0);
case INST_DICT_UPDATE_END:
opnd = TclGetUInt4AtPtr(pc+1);
opnd2 = TclGetUInt4AtPtr(pc+5);
TRACE("%u => ", opnd);
varPtr = LOCAL(opnd);
duiPtr = (DictUpdateInfo *)codePtr->auxDataArrayPtr[opnd2].clientData;
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
if (TclIsVarDirectReadable(varPtr)) {
dictPtr = varPtr->value.objPtr;
} else {
DECACHE_STACK_INFO();
dictPtr = TclPtrGetVarIdx(interp, varPtr, NULL, NULL, NULL, 0,
opnd);
CACHE_STACK_INFO();
}
if (dictPtr == NULL) {
TRACE_APPEND("storage was unset\n");
NEXT_INST_F(9, 1, 0);
}
if (Tcl_DictObjSize(interp, dictPtr, &length) != TCL_OK
|| TclListObjGetElements(interp, OBJ_AT_TOS, &length,
&keyPtrPtr) != TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
|
| ︙ | ︙ | |||
7322 7323 7324 7325 7326 7327 7328 |
if (allocdict) {
TclDecrRefCount(dictPtr);
}
TRACE_ERROR(interp);
goto gotError;
}
}
| | | | | | | 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 |
if (allocdict) {
TclDecrRefCount(dictPtr);
}
TRACE_ERROR(interp);
goto gotError;
}
}
TRACE_APPEND("written back\n");
NEXT_INST_F(9, 1, 0);
case INST_DICT_EXPAND:
dictPtr = OBJ_UNDER_TOS;
listPtr = OBJ_AT_TOS;
TRACE("\"%.30s\" \"%.30s\" =>", O2S(dictPtr), O2S(listPtr));
if (TclListObjGetElements(interp, listPtr, &objc, &objv) != TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
}
objResultPtr = TclDictWithInit(interp, dictPtr, objc, objv);
if (objResultPtr == NULL) {
TRACE_ERROR(interp);
goto gotError;
}
TRACE_RESULT(objResultPtr);
NEXT_INST_F(1, 2, 1);
case INST_DICT_RECOMBINE_STK:
keysPtr = POP_OBJECT();
varNamePtr = OBJ_UNDER_TOS;
listPtr = OBJ_AT_TOS;
TRACE("\"%.30s\" \"%.30s\" \"%.30s\" => ",
O2S(varNamePtr), O2S(valuePtr), O2S(keysPtr));
if (TclListObjGetElements(interp, listPtr, &objc, &objv) != TCL_OK) {
TRACE_ERROR(interp);
TclDecrRefCount(keysPtr);
goto gotError;
}
varPtr = TclObjLookupVarEx(interp, varNamePtr, NULL,
TCL_LEAVE_ERR_MSG, "set", 1, 1, &arrayPtr);
|
| ︙ | ︙ | |||
7368 7369 7370 7371 7372 7373 7374 |
objc, objv, keysPtr);
CACHE_STACK_INFO();
TclDecrRefCount(keysPtr);
if (result != TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
}
| | | | | > > > > > | > > | 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 |
objc, objv, keysPtr);
CACHE_STACK_INFO();
TclDecrRefCount(keysPtr);
if (result != TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
}
TRACE_APPEND("OK\n");
NEXT_INST_F(1, 2, 0);
case INST_DICT_RECOMBINE_IMM:
opnd = TclGetUInt4AtPtr(pc+1);
listPtr = OBJ_UNDER_TOS;
keysPtr = OBJ_AT_TOS;
varPtr = LOCAL(opnd);
TRACE("%u <- \"%.30s\" \"%.30s\" => ", opnd, O2S(valuePtr),
O2S(keysPtr));
if (TclListObjGetElements(interp, listPtr, &objc, &objv) != TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
}
while (TclIsVarLink(varPtr)) {
varPtr = varPtr->value.linkPtr;
}
DECACHE_STACK_INFO();
result = TclDictWithFinish(interp, varPtr, NULL, NULL, NULL, opnd,
objc, objv, keysPtr);
CACHE_STACK_INFO();
if (result != TCL_OK) {
TRACE_ERROR(interp);
goto gotError;
}
TRACE_APPEND("OK\n");
NEXT_INST_F(5, 2, 0);
}
break;
/*
* End of dictionary-related instructions.
* -----------------------------------------------------------------
*/
case INST_CLOCK_READ: { /* Read the wall clock */
#ifdef TCL_COMPILE_DEBUG
static const char *clockTypes[] = {
"clicks", "micros", "millis", "secs"
};
#endif
Tcl_WideInt wval;
Tcl_Time now;
opnd = TclGetUInt1AtPtr(pc+1);
TRACE("%s => ", clockTypes[opnd]);
switch (opnd) {
case 0: /* clicks */
#ifdef TCL_WIDE_CLICKS
wval = TclpGetWideClicks();
#else
wval = (Tcl_WideInt)TclpGetClicks();
#endif
break;
|
| ︙ | ︙ | |||
7431 7432 7433 7434 7435 7436 7437 |
wval = (Tcl_WideInt)now.sec;
break;
default:
Tcl_Panic("clockRead instruction with unknown clock#");
break;
}
TclNewIntObj(objResultPtr, wval);
| | | 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 |
wval = (Tcl_WideInt)now.sec;
break;
default:
Tcl_Panic("clockRead instruction with unknown clock#");
break;
}
TclNewIntObj(objResultPtr, wval);
TRACE_RESULT(objResultPtr);
NEXT_INST_F(2, 0, 1);
}
break;
default:
Tcl_Panic("TclNRExecuteByteCode: unrecognized opCode %u", *pc);
} /* end of switch on opCode */
|
| ︙ | ︙ | |||
7463 7464 7465 7466 7467 7468 7469 |
*/
processExceptionReturn:
#ifdef TCL_COMPILE_DEBUG
switch (*pc) {
case INST_INVOKE_STK1:
opnd = TclGetUInt1AtPtr(pc+1);
| | | | | | | | | | | | | | | | | | | | | | < | | | | 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 |
*/
processExceptionReturn:
#ifdef TCL_COMPILE_DEBUG
switch (*pc) {
case INST_INVOKE_STK1:
opnd = TclGetUInt1AtPtr(pc+1);
TRACE("%u => ... after \"%.20s\": ", opnd, cmdNameBuf);
break;
case INST_INVOKE_STK4:
opnd = TclGetUInt4AtPtr(pc+1);
TRACE("%u => ... after \"%.20s\": ", opnd, cmdNameBuf);
break;
case INST_EVAL_STK:
/*
* Note that the object at stacktop has to be used before doing
* the cleanup.
*/
TRACE("\"%.30s\" => ", O2S(OBJ_AT_TOS));
break;
default:
TRACE("=> ");
}
#endif
if ((result == TCL_CONTINUE) || (result == TCL_BREAK)) {
rangePtr = GetExceptRangeForPc(pc, result, codePtr);
if (rangePtr == NULL) {
TRACE_APPEND("no encl. loop or catch, returning %s\n",
StringForResultCode(result));
goto abnormalReturn;
}
if (rangePtr->type == CATCH_EXCEPTION_RANGE) {
TRACE_APPEND("%s ...\n", StringForResultCode(result));
goto processCatch;
}
while (cleanup--) {
valuePtr = POP_OBJECT();
TclDecrRefCount(valuePtr);
}
if (result == TCL_BREAK) {
result = TCL_OK;
pc = (codePtr->codeStart + rangePtr->breakOffset);
TRACE_APPEND("%s, range at %" TCL_SIZE_MODIFIER "d, new pc %" TCL_SIZE_MODIFIER "d\n",
StringForResultCode(result),
rangePtr->codeOffset, rangePtr->breakOffset);
NEXT_INST_F(0, 0, 0);
}
if (rangePtr->continueOffset == TCL_INDEX_NONE) {
TRACE_APPEND("%s, loop w/o continue, checking for catch\n",
StringForResultCode(result));
goto checkForCatch;
}
result = TCL_OK;
pc = (codePtr->codeStart + rangePtr->continueOffset);
TRACE_APPEND("%s, range at %" TCL_SIZE_MODIFIER "d, new pc %" TCL_SIZE_MODIFIER "d\n",
StringForResultCode(result),
rangePtr->codeOffset, rangePtr->continueOffset);
NEXT_INST_F(0, 0, 0);
}
#ifdef TCL_COMPILE_DEBUG
if (traceInstructions) {
objPtr = Tcl_GetObjResult(interp);
if ((result != TCL_ERROR) && (result != TCL_RETURN)) {
TRACE_APPEND("OTHER RETURN CODE %d, result=\"%.30s\"\n ",
result, O2S(objPtr));
} else {
TRACE_APPEND("%s, result=\"%.30s\"\n",
StringForResultCode(result), O2S(objPtr));
}
}
#endif
goto checkForCatch;
/*
* Division by zero in an expression. Control only reaches this point
* by "goto divideByZero".
*/
divideByZero:
TclPrintfResult(interp, "divide by zero");
DECACHE_STACK_INFO();
TclSetErrorCode(interp, "ARITH", "DIVZERO", "divide by zero");
CACHE_STACK_INFO();
goto gotError;
outOfMemory:
TclPrintfResult(interp, "out of memory");
DECACHE_STACK_INFO();
TclSetErrorCode(interp, "ARITH", "OUTOFMEMORY", "out of memory");
CACHE_STACK_INFO();
goto gotError;
/*
* Exponentiation of zero by negative number in an expression. Control
* only reaches this point by "goto exponOfZero".
*/
exponOfZero:
TclPrintfResult(interp, "exponentiation of zero by negative power");
DECACHE_STACK_INFO();
TclSetErrorCode(interp, "ARITH", "DOMAIN",
"exponentiation of zero by negative power");
CACHE_STACK_INFO();
/*
* Almost all error paths feed through here rather than assigning to
* result themselves (for a small but consistent saving).
*/
|
| ︙ | ︙ | |||
8118 8119 8120 8121 8122 8123 8124 |
mp_clear(&big2);
break;
default:
/* Unused, here to silence compiler warning */
invalid = 0;
}
if (invalid) {
| < | | 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 |
mp_clear(&big2);
break;
default:
/* Unused, here to silence compiler warning */
invalid = 0;
}
if (invalid) {
TclPrintfResult(interp, "negative shift argument");
return GENERAL_ARITHMETIC_ERROR;
}
/*
* Zero shifted any number of bits is still zero.
*/
|
| ︙ | ︙ | |||
8149 8150 8151 8152 8153 8154 8155 | /* * Technically, we could hold the value (1 << (INT_MAX+1)) in * an mp_int, but since we're using mp_mul_2d() to do the * work, and it takes only an int argument, that's a good * place to draw the line. */ | < | | 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 | /* * Technically, we could hold the value (1 << (INT_MAX+1)) in * an mp_int, but since we're using mp_mul_2d() to do the * work, and it takes only an int argument, that's a good * place to draw the line. */ TclPrintfResult(interp, "integer value too large to represent"); return GENERAL_ARITHMETIC_ERROR; } shift = (int)(*((const Tcl_WideInt *)ptr2)); /* * Handle shifts within the native wide range. */ |
| ︙ | ︙ | |||
8396 8397 8398 8399 8400 8401 8402 |
* 268435455, which fits into a signed 32 bit int which is within the
* range of the Tcl_WideInt type. This means any numeric Tcl_Obj value
* not using TCL_NUMBER_INT type must hold a value larger than we
* accept.
*/
if (type2 != TCL_NUMBER_INT) {
| < | | 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 |
* 268435455, which fits into a signed 32 bit int which is within the
* range of the Tcl_WideInt type. This means any numeric Tcl_Obj value
* not using TCL_NUMBER_INT type must hold a value larger than we
* accept.
*/
if (type2 != TCL_NUMBER_INT) {
TclPrintfResult(interp, "exponent too large");
return GENERAL_ARITHMETIC_ERROR;
}
/* From here (up to overflowExpon) w1 and exponent w2 are wide-int's. */
assert(type1 == TCL_NUMBER_INT && type2 == TCL_NUMBER_INT);
if (w1 == 2) {
|
| ︙ | ︙ | |||
8472 8473 8474 8475 8476 8477 8478 |
wResult = oddExponent ? -Exp64Value[base] : Exp64Value[base];
WIDE_RESULT(wResult);
}
}
overflowExpon:
| < < | | 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 |
wResult = oddExponent ? -Exp64Value[base] : Exp64Value[base];
WIDE_RESULT(wResult);
}
}
overflowExpon:
if ((TclGetWideIntFromObj(NULL, value2Ptr, &w2) != TCL_OK)
|| !TclHasInternalRep(value2Ptr, &tclIntType)
|| (Tcl_WideUInt)w2 >= (1<<28)) {
TclPrintfResult(interp, "exponent too large");
return GENERAL_ARITHMETIC_ERROR;
}
Tcl_TakeBignumFromObj(NULL, valuePtr, &big1);
err = mp_init(&bigResult);
if (err == MP_OKAY) {
/* Don't use "mp_expt_n" directly here, it doesn't exist in libtommath 1.2 */
err = TclBN_mp_expt_n(&big1, (int)w2, &bigResult);
|
| ︙ | ︙ | |||
9109 9110 9111 9112 9113 9114 9115 |
if (GetNumberFromObj(NULL, opndPtr, &ptr, &type) != TCL_OK) {
Tcl_Size length;
if (TclHasInternalRep(opndPtr, &tclDictType)) {
Tcl_DictObjSize(NULL, opndPtr, &length);
if (length > 0) {
listRep:
| | | | | 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 |
if (GetNumberFromObj(NULL, opndPtr, &ptr, &type) != TCL_OK) {
Tcl_Size length;
if (TclHasInternalRep(opndPtr, &tclDictType)) {
Tcl_DictObjSize(NULL, opndPtr, &length);
if (length > 0) {
listRep:
TclPrintfResult(interp,
"cannot use a list as %soperand of \"%s\"", ord, op);
TclSetErrorCode(interp, "ARITH", "DOMAIN", "list");
return;
}
}
Tcl_ObjTypeLengthProc *lengthProc = TclObjTypeHasProc(opndPtr, lengthProc);
Tcl_Size objcPtr;
Tcl_Obj **objvPtr;
if ((lengthProc && lengthProc(opndPtr) > 1)
|
| ︙ | ︙ | |||
9133 9134 9135 9136 9137 9138 9139 |
} else if (type == TCL_NUMBER_DOUBLE) {
description = "floating-point value";
} else {
/* TODO: No caller needs this. Eliminate? */
description = "(big) integer";
}
| | | | | 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 |
} else if (type == TCL_NUMBER_DOUBLE) {
description = "floating-point value";
} else {
/* TODO: No caller needs this. Eliminate? */
description = "(big) integer";
}
TclPrintfResult(interp,
"cannot use %s \"%s\" as %soperand of \"%s\"", description,
TclGetString(opndPtr), ord, op);
TclSetErrorCode(interp, "ARITH", "DOMAIN", description);
}
/*
*----------------------------------------------------------------------
*
* TclGetSrcInfoForPc, GetSrcInfoForPc, TclGetSourceFromFrame --
*
|
| ︙ | ︙ | |||
9461 9462 9463 9464 9465 9466 9467 | } /* *---------------------------------------------------------------------- * * GetOpcodeName -- * | | | 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 | } /* *---------------------------------------------------------------------- * * GetOpcodeName -- * * This procedure is called by the TRACE_INST macro (and hence TRACE) used * in TclNRExecuteByteCode when debugging. It returns the name of the * bytecode instruction at a specified instruction pc. * * Results: * A character string for the instruction. * * Side effects: |
| ︙ | ︙ | |||
9514 9515 9516 9517 9518 9519 9520 |
* distinguish underflows from overflows. */
{
const char *s;
if ((errno == EDOM) || isnan(value)) {
s = "domain error: argument not in valid range";
Tcl_SetObjResult(interp, Tcl_NewStringObj(s, -1));
| | | | | < | 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 |
* distinguish underflows from overflows. */
{
const char *s;
if ((errno == EDOM) || isnan(value)) {
s = "domain error: argument not in valid range";
Tcl_SetObjResult(interp, Tcl_NewStringObj(s, -1));
TclSetErrorCode(interp, "ARITH", "DOMAIN", s);
} else if ((errno == ERANGE) || isinf(value)) {
if (value == 0.0) {
s = "floating-point value too small to represent";
Tcl_SetObjResult(interp, Tcl_NewStringObj(s, -1));
TclSetErrorCode(interp, "ARITH", "UNDERFLOW", s);
} else {
s = "floating-point value too large to represent";
Tcl_SetObjResult(interp, Tcl_NewStringObj(s, -1));
TclSetErrorCode(interp, "ARITH", "OVERFLOW", s);
}
} else {
Tcl_Obj *objPtr = Tcl_ObjPrintf(
"unknown floating-point error, errno = %d", errno);
TclSetErrorCode(interp, "ARITH", "UNKNOWN", TclGetString(objPtr));
Tcl_SetObjResult(interp, objPtr);
}
}
#ifdef TCL_COMPILE_STATS
/*
*----------------------------------------------------------------------
|
| ︙ | ︙ |
Changes to generic/tclFCmd.c.
| ︙ | ︙ | |||
150 151 152 153 154 155 156 |
* overwriting the symlink.
*/
if ((Tcl_FSStat(target, &statBuf) != 0) || !S_ISDIR(statBuf.st_mode)) {
if ((objc - i) > 2) {
errno = ENOTDIR;
Tcl_PosixError(interp);
| | | | 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
* overwriting the symlink.
*/
if ((Tcl_FSStat(target, &statBuf) != 0) || !S_ISDIR(statBuf.st_mode)) {
if ((objc - i) > 2) {
errno = ENOTDIR;
Tcl_PosixError(interp);
TclPrintfResult(interp,
"error %s: target \"%s\" is not a directory",
(copyFlag ? "copying" : "renaming"), TclGetString(target));
result = TCL_ERROR;
} else {
/*
* Even though already have target == translated(objv[i+1]), pass
* the original argument down, so if there's an error, the error
* message will reflect the original arguments.
*/
|
| ︙ | ︙ | |||
317 318 319 320 321 322 323 |
}
Tcl_DecrRefCount(split);
split = NULL;
}
done:
if (errfile != NULL) {
| | | | 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
}
Tcl_DecrRefCount(split);
split = NULL;
}
done:
if (errfile != NULL) {
TclPrintfResult(interp,
"can't create directory \"%s\": %s",
TclGetString(errfile), Tcl_PosixError(interp));
result = TCL_ERROR;
}
if (split != NULL) {
Tcl_DecrRefCount(split);
}
if (target != NULL) {
Tcl_DecrRefCount(target);
|
| ︙ | ︙ | |||
399 400 401 402 403 404 405 |
* We own a reference count on errorBuffer, if it was set as a
* result of this call.
*/
result = Tcl_FSRemoveDirectory(objv[i], force, &errorBuffer);
if (result != TCL_OK) {
if ((force == 0) && (errno == EEXIST)) {
| | | | 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
* We own a reference count on errorBuffer, if it was set as a
* result of this call.
*/
result = Tcl_FSRemoveDirectory(objv[i], force, &errorBuffer);
if (result != TCL_OK) {
if ((force == 0) && (errno == EEXIST)) {
TclPrintfResult(interp,
"error deleting \"%s\": directory not empty",
TclGetString(objv[i]));
Tcl_PosixError(interp);
goto done;
}
/*
* If possible, use the untranslated name for the file.
*/
|
| ︙ | ︙ | |||
448 449 450 451 452 453 454 |
}
if (result != TCL_OK) {
if (errfile == NULL) {
/*
* We try to accommodate poor error results from our Tcl_FS calls.
*/
| | | | | | 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
}
if (result != TCL_OK) {
if (errfile == NULL) {
/*
* We try to accommodate poor error results from our Tcl_FS calls.
*/
TclPrintfResult(interp,
"error deleting unknown file: %s",
Tcl_PosixError(interp));
} else {
TclPrintfResult(interp,
"error deleting \"%s\": %s",
TclGetString(errfile), Tcl_PosixError(interp));
}
}
done:
if (errorBuffer != NULL) {
Tcl_DecrRefCount(errorBuffer);
}
|
| ︙ | ︙ | |||
576 577 578 579 580 581 582 |
* implementations of copy and rename on all platforms also prevent
* this.
*/
if (S_ISDIR(sourceStatBuf.st_mode)
&& !S_ISDIR(targetStatBuf.st_mode)) {
errno = EISDIR;
| | | | | | 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 |
* implementations of copy and rename on all platforms also prevent
* this.
*/
if (S_ISDIR(sourceStatBuf.st_mode)
&& !S_ISDIR(targetStatBuf.st_mode)) {
errno = EISDIR;
TclPrintfResult(interp,
"can't overwrite file \"%s\" with directory \"%s\"",
TclGetString(target), TclGetString(source));
goto done;
}
if (!S_ISDIR(sourceStatBuf.st_mode)
&& S_ISDIR(targetStatBuf.st_mode)) {
errno = EISDIR;
TclPrintfResult(interp,
"can't overwrite directory \"%s\" with file \"%s\"",
TclGetString(target), TclGetString(source));
goto done;
}
/*
* The destination exists, but appears to be ok to over-write, and
* -force is given. We now try to adjust permissions to ensure the
* operation succeeds. If we can't adjust permissions, we'll let the
|
| ︙ | ︙ | |||
617 618 619 620 621 622 623 |
if (copyFlag == 0) {
result = Tcl_FSRenameFile(source, target);
if (result == TCL_OK) {
goto done;
}
if (errno == EINVAL) {
| | | | 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
if (copyFlag == 0) {
result = Tcl_FSRenameFile(source, target);
if (result == TCL_OK) {
goto done;
}
if (errno == EINVAL) {
TclPrintfResult(interp,
"error renaming \"%s\" to \"%s\": trying to rename a"
" volume or move a directory into itself",
TclGetString(source), TclGetString(target));
goto done;
} else if (errno != EXDEV) {
errfile = target;
goto done;
}
/*
|
| ︙ | ︙ | |||
664 665 666 667 668 669 670 |
*/
if (Tcl_FSStat(source, &sourceStatBuf) != 0) {
/*
* Actual file doesn't exist.
*/
| | | | 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
*/
if (Tcl_FSStat(source, &sourceStatBuf) != 0) {
/*
* Actual file doesn't exist.
*/
TclPrintfResult(interp,
"error copying \"%s\": the target of this link doesn't"
" exist", TclGetString(source));
goto done;
} else {
int counter = 0;
while (1) {
Tcl_Obj *path = Tcl_FSLink(actualSource, NULL, 0);
if (path == NULL) {
|
| ︙ | ︙ | |||
798 799 800 801 802 803 804 |
} else {
result = Tcl_FSDeleteFile(source);
if (result != TCL_OK) {
errfile = source;
}
}
if (result != TCL_OK) {
| | | | 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 |
} else {
result = Tcl_FSDeleteFile(source);
if (result != TCL_OK) {
errfile = source;
}
}
if (result != TCL_OK) {
TclPrintfResult(interp, "can't unlink \"%s\": %s",
TclGetString(errfile), Tcl_PosixError(interp));
errfile = NULL;
}
}
done:
if (errfile != NULL) {
Tcl_Obj *errorMsg = Tcl_ObjPrintf("error %s \"%s\"",
|
| ︙ | ︙ | |||
1020 1021 1022 1023 1024 1025 1026 |
if (objStrings == NULL) {
if (Tcl_GetErrno() != 0) {
/*
* There was an error, probably that the filePtr is not
* accepted by any filesystem
*/
| | | | 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 |
if (objStrings == NULL) {
if (Tcl_GetErrno() != 0) {
/*
* There was an error, probably that the filePtr is not
* accepted by any filesystem
*/
TclPrintfResult(interp,
"could not read \"%s\": %s",
TclGetString(filePtr), Tcl_PosixError(interp));
}
return TCL_ERROR;
}
/*
* We own the object now.
*/
|
| ︙ | ︙ | |||
1108 1109 1110 1111 1112 1113 1114 |
* Get one attribute.
*/
int index;
Tcl_Obj *objPtr = NULL;
if (numObjStrings == 0) {
| | | | | | | | | | < | 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 |
* Get one attribute.
*/
int index;
Tcl_Obj *objPtr = NULL;
if (numObjStrings == 0) {
TclPrintfResult(interp,
"bad option \"%s\", there are no file attributes in this"
" filesystem", TclGetString(objv[0]));
TclSetErrorCode(interp, "TCL", "OPERATION", "FATTR", "NONE");
goto end;
}
if (Tcl_GetIndexFromObj(interp, objv[0], attributeStrings,
"option", TCL_INDEX_TEMP_TABLE, &index) != TCL_OK) {
goto end;
}
if (Tcl_FSFileAttrsGet(interp, index, filePtr,
&objPtr) != TCL_OK) {
goto end;
}
Tcl_SetObjResult(interp, objPtr);
} else {
/*
* Set option/value pairs.
*/
int i, index;
if (numObjStrings == 0) {
TclPrintfResult(interp,
"bad option \"%s\", there are no file attributes in this"
" filesystem", TclGetString(objv[0]));
TclSetErrorCode(interp, "TCL", "OPERATION", "FATTR", "NONE");
goto end;
}
for (i = 0; i < objc ; i += 2) {
if (Tcl_GetIndexFromObj(interp, objv[i], attributeStrings,
"option", TCL_INDEX_TEMP_TABLE, &index) != TCL_OK) {
goto end;
}
if (i + 1 == objc) {
TclPrintfResult(interp,
"value for \"%s\" missing", TclGetString(objv[i]));
TclSetErrorCode(interp, "TCL", "OPERATION", "FATTR", "NOVALUE");
goto end;
}
if (Tcl_FSFileAttrsSet(interp, index, filePtr,
objv[i + 1]) != TCL_OK) {
goto end;
}
}
|
| ︙ | ︙ | |||
1262 1263 1264 1265 1266 1267 1268 |
if (contents == NULL) {
/*
* We handle three common error cases specially, and for all other
* errors, we use the standard Posix error message.
*/
if (errno == EEXIST) {
| | | | | | | | | | | | | 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 |
if (contents == NULL) {
/*
* We handle three common error cases specially, and for all other
* errors, we use the standard Posix error message.
*/
if (errno == EEXIST) {
TclPrintfResult(interp,
"could not create new link \"%s\": that path already"
" exists", TclGetString(objv[index]));
Tcl_PosixError(interp);
} else if (errno == ENOENT) {
/*
* There are two cases here: either the target doesn't exist,
* or the directory of the src doesn't exist.
*/
int access;
Tcl_Obj *dirPtr = TclPathPart(interp, objv[index],
TCL_PATH_DIRNAME);
if (dirPtr == NULL) {
return TCL_ERROR;
}
access = Tcl_FSAccess(dirPtr, F_OK);
Tcl_DecrRefCount(dirPtr);
if (access != 0) {
TclPrintfResult(interp,
"could not create new link \"%s\": no such file"
" or directory", TclGetString(objv[index]));
Tcl_PosixError(interp);
} else {
TclPrintfResult(interp,
"could not create new link \"%s\": target \"%s\" "
"doesn't exist", TclGetString(objv[index]),
TclGetString(objv[index+1]));
errno = ENOENT;
Tcl_PosixError(interp);
}
} else {
TclPrintfResult(interp,
"could not create new link \"%s\" pointing to \"%s\": %s",
TclGetString(objv[index]), TclGetString(objv[index+1]),
Tcl_PosixError(interp));
}
return TCL_ERROR;
}
} else {
if (Tcl_FSConvertToPathType(interp, objv[index]) != TCL_OK) {
return TCL_ERROR;
}
if (Tcl_UtfToExternalDStringEx(interp, TCLFSENCODING, TclGetString(objv[index]),
TCL_INDEX_NONE, 0, &ds, NULL) != TCL_OK) {
Tcl_DStringFree(&ds);
return TCL_ERROR;
}
Tcl_DStringFree(&ds);
/*
* Read link
*/
contents = Tcl_FSLink(objv[index], NULL, 0);
if (contents == NULL) {
TclPrintfResult(interp,
"could not read link \"%s\": %s",
TclGetString(objv[index]), Tcl_PosixError(interp));
return TCL_ERROR;
}
}
Tcl_SetObjResult(interp, contents);
if (objc == 2) {
/*
* If we are reading a link, we need to free this result refCount. If
|
| ︙ | ︙ | |||
1383 1384 1385 1386 1387 1388 1389 |
return TCL_ERROR;
}
Tcl_DStringFree(&ds);
contents = Tcl_FSLink(objv[1], NULL, 0);
if (contents == NULL) {
| | | | 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 |
return TCL_ERROR;
}
Tcl_DStringFree(&ds);
contents = Tcl_FSLink(objv[1], NULL, 0);
if (contents == NULL) {
TclPrintfResult(interp,
"could not read link \"%s\": %s",
TclGetString(objv[1]), Tcl_PosixError(interp));
return TCL_ERROR;
}
Tcl_SetObjResult(interp, contents);
Tcl_DecrRefCount(contents);
return TCL_OK;
}
|
| ︙ | ︙ | |||
1539 1540 1541 1542 1543 1544 1545 |
* Deal with results.
*/
if (chan == NULL) {
if (nameVarObj) {
TclDecrRefCount(nameObj);
}
| | | | 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 |
* Deal with results.
*/
if (chan == NULL) {
if (nameVarObj) {
TclDecrRefCount(nameObj);
}
TclPrintfResult(interp,
"can't create temporary file: %s", Tcl_PosixError(interp));
return TCL_ERROR;
}
Tcl_RegisterChannel(interp, chan);
if (nameVarObj != NULL) {
if (Tcl_ObjSetVar2(interp, nameVarObj, NULL, nameObj,
TCL_LEAVE_ERR_MSG) == NULL) {
Tcl_UnregisterChannel(interp, chan);
|
| ︙ | ︙ | |||
1691 1692 1693 1694 1695 1696 1697 |
}
/*
* Deal with results.
*/
if (dirNameObj == NULL) {
| | | | 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 |
}
/*
* Deal with results.
*/
if (dirNameObj == NULL) {
TclPrintfResult(interp,
"can't create temporary directory: %s",
Tcl_PosixError(interp));
return TCL_ERROR;
}
Tcl_SetObjResult(interp, dirNameObj);
return TCL_OK;
}
/*
|
| ︙ | ︙ |
Changes to generic/tclFileName.c.
| ︙ | ︙ | |||
835 836 837 838 839 840 841 |
switch (tclPlatform) {
case TCL_PLATFORM_UNIX:
/*
* Append a separator if needed.
*/
if (length > 0 && (start[length-1] != '/')) {
| | | 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 |
switch (tclPlatform) {
case TCL_PLATFORM_UNIX:
/*
* Append a separator if needed.
*/
if (length > 0 && (start[length-1] != '/')) {
TclAppendLiteralToObj(prefix, "/");
(void)TclGetStringFromObj(prefix, &length);
}
needsSep = 0;
/*
* Append the element, eliminating duplicate and trailing slashes.
*/
|
| ︙ | ︙ | |||
871 872 873 874 875 876 877 |
case TCL_PLATFORM_WINDOWS:
/*
* Check to see if we need to append a separator.
*/
if ((length > 0) &&
(start[length-1] != '/') && (start[length-1] != ':')) {
| | | 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 |
case TCL_PLATFORM_WINDOWS:
/*
* Check to see if we need to append a separator.
*/
if ((length > 0) &&
(start[length-1] != '/') && (start[length-1] != ':')) {
TclAppendLiteralToObj(prefix, "/");
(void)TclGetStringFromObj(prefix, &length);
}
needsSep = 0;
/*
* Append the element, eliminating duplicate and trailing slashes.
*/
|
| ︙ | ︙ | |||
927 928 929 930 931 932 933 |
char *
Tcl_JoinPath(
Tcl_Size argc,
const char *const *argv,
Tcl_DString *resultPtr) /* Pointer to previously initialized DString */
{
| | < | 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 |
char *
Tcl_JoinPath(
Tcl_Size argc,
const char *const *argv,
Tcl_DString *resultPtr) /* Pointer to previously initialized DString */
{
Tcl_Size i;
Tcl_Obj *listObj;
Tcl_Obj *resultObj;
/*
* Build the list of paths.
*/
TclNewObj(listObj);
for (i = 0; i < argc; i++) {
|
| ︙ | ︙ | |||
955 956 957 958 959 960 961 |
Tcl_IncrRefCount(resultObj);
Tcl_DecrRefCount(listObj);
/*
* Store the result.
*/
| < | | 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 |
Tcl_IncrRefCount(resultObj);
Tcl_DecrRefCount(listObj);
/*
* Store the result.
*/
TclDStringAppendObj(resultPtr, resultObj);
Tcl_DecrRefCount(resultObj);
/*
* Return a pointer to the result.
*/
return Tcl_DStringValue(resultPtr);
|
| ︙ | ︙ | |||
1166 1167 1168 1169 1170 1171 1172 |
/*
* Do nothing; This is normal operations in Tcl 9.
* Keep accepting as a no-op option to accommodate old scripts.
*/
break;
case GLOB_DIR: /* -dir */
if (i == (objc-1)) {
| < | | | | < | | | < | | | | < | | < | | | | | | | 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 |
/*
* Do nothing; This is normal operations in Tcl 9.
* Keep accepting as a no-op option to accommodate old scripts.
*/
break;
case GLOB_DIR: /* -dir */
if (i == (objc-1)) {
TclPrintfResult(interp, "missing argument to \"-directory\"");
TclSetErrorCode(interp, "TCL", "ARGUMENT", "MISSING");
return TCL_ERROR;
}
if (dir != PATH_NONE) {
TclPrintfResult(interp,
dir == PATH_DIR
? "\"-directory\" may only be used once"
: "\"-directory\" cannot be used with \"-path\"");
TclSetErrorCode(interp, "TCL", "OPERATION", "GLOB",
"BADOPTIONCOMBINATION");
return TCL_ERROR;
}
dir = PATH_DIR;
globFlags |= TCL_GLOBMODE_DIR;
pathOrDir = objv[i+1];
i++;
break;
case GLOB_JOIN: /* -join */
join = 1;
break;
case GLOB_TAILS: /* -tails */
globFlags |= TCL_GLOBMODE_TAILS;
break;
case GLOB_PATH: /* -path */
if (i == (objc-1)) {
TclPrintfResult(interp, "missing argument to \"-path\"");
TclSetErrorCode(interp, "TCL", "ARGUMENT", "MISSING");
return TCL_ERROR;
}
if (dir != PATH_NONE) {
TclPrintfResult(interp,
dir == PATH_GENERAL
? "\"-path\" may only be used once"
: "\"-path\" cannot be used with \"-dictionary\"");
TclSetErrorCode(interp, "TCL", "OPERATION", "GLOB",
"BADOPTIONCOMBINATION");
return TCL_ERROR;
}
dir = PATH_GENERAL;
pathOrDir = objv[i+1];
i++;
break;
case GLOB_TYPE: /* -types */
if (i == (objc-1)) {
TclPrintfResult(interp, "missing argument to \"-types\"");
TclSetErrorCode(interp, "TCL", "ARGUMENT", "MISSING");
return TCL_ERROR;
}
typePtr = objv[i+1];
if (TclListObjLength(interp, typePtr, &length) != TCL_OK) {
return TCL_ERROR;
}
i++;
break;
case GLOB_LAST: /* -- */
i++;
goto endOfForLoop;
}
}
endOfForLoop:
if ((globFlags & TCL_GLOBMODE_TAILS) && (pathOrDir == NULL)) {
TclPrintfResult(interp,
"\"-tails\" must be used with either "
"\"-directory\" or \"-path\"");
TclSetErrorCode(interp, "TCL", "OPERATION", "GLOB",
"BADOPTIONCOMBINATION");
return TCL_ERROR;
}
separators = NULL;
switch (tclPlatform) {
case TCL_PLATFORM_UNIX:
separators = "/";
|
| ︙ | ︙ | |||
1308 1309 1310 1311 1312 1313 1314 |
* '' or 'C:'. The way we do this is to add a separator if
* there are none presently in the prefix. Similar treatment
* for the zipfs volume.
*/
const char *temp = TclGetString(pathOrDir);
if (strpbrk(temp, "\\/") == NULL) {
| | | | 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 |
* '' or 'C:'. The way we do this is to add a separator if
* there are none presently in the prefix. Similar treatment
* for the zipfs volume.
*/
const char *temp = TclGetString(pathOrDir);
if (strpbrk(temp, "\\/") == NULL) {
Tcl_AppendToObj(pathOrDir, last - 1, 1);
} else if (!strcmp(temp, "//zipfs:")) {
TclAppendLiteralToObj(pathOrDir, "/");
}
}
/*
* Need to quote 'prefix'.
*/
|
| ︙ | ︙ | |||
1449 1450 1451 1452 1453 1454 1455 | /* * Error cases. We reset the 'join' flag to zero, since we * haven't yet made use of it. */ badTypesArg: | | | | | | | | 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 |
/*
* Error cases. We reset the 'join' flag to zero, since we
* haven't yet made use of it.
*/
badTypesArg:
TclPrintfResult(interp,
"bad argument to \"-types\": %s",
TclGetString(look));
TclSetErrorCode(interp, "TCL", "ARGUMENT", "BAD");
result = TCL_ERROR;
join = 0;
goto endOfGlob;
badMacTypesArg:
TclPrintfResult(interp,
"only one MacOS type or creator argument"
" to \"-types\" allowed");
result = TCL_ERROR;
TclSetErrorCode(interp, "TCL", "ARGUMENT", "BAD");
join = 0;
goto endOfGlob;
}
}
}
skipTypes:
|
| ︙ | ︙ | |||
2030 2031 2032 2033 2034 2035 2036 | /* * Balanced braces. */ closeBrace = p; break; } | < | | < < | | < | 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 |
/*
* Balanced braces.
*/
closeBrace = p;
break;
}
TclPrintfResult(interp, "unmatched open-brace in file name");
TclSetErrorCode(interp, "TCL", "OPERATION", "GLOB", "BALANCE");
return TCL_ERROR;
} else if (*p == '}') {
TclPrintfResult(interp, "unmatched close-brace in file name");
TclSetErrorCode(interp, "TCL", "OPERATION", "GLOB", "BALANCE");
return TCL_ERROR;
}
}
/*
* Substitute the alternate patterns from the braces and recurse.
*/
|
| ︙ | ︙ | |||
2254 2255 2256 2257 2258 2259 2260 |
* The current prefix must end in a separator.
*/
Tcl_Size len;
const char *joined = TclGetStringFromObj(joinedPtr,&len);
if ((len > 0) && (strchr(separators, joined[len-1]) == NULL)) {
| | | 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 |
* The current prefix must end in a separator.
*/
Tcl_Size len;
const char *joined = TclGetStringFromObj(joinedPtr,&len);
if ((len > 0) && (strchr(separators, joined[len-1]) == NULL)) {
TclAppendLiteralToObj(joinedPtr, "/");
}
}
Tcl_AppendToObj(joinedPtr, Tcl_DStringValue(&append),
Tcl_DStringLength(&append));
}
Tcl_IncrRefCount(joinedPtr);
Tcl_DStringFree(&append);
|
| ︙ | ︙ | |||
2292 2293 2294 2295 2296 2297 2298 |
*/
Tcl_Size len;
const char *joined = TclGetStringFromObj(joinedPtr,&len);
if ((len > 0) && (strchr(separators, joined[len-1]) == NULL)) {
if (Tcl_FSGetPathType(pathPtr) != TCL_PATH_VOLUME_RELATIVE) {
| | | 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 |
*/
Tcl_Size len;
const char *joined = TclGetStringFromObj(joinedPtr,&len);
if ((len > 0) && (strchr(separators, joined[len-1]) == NULL)) {
if (Tcl_FSGetPathType(pathPtr) != TCL_PATH_VOLUME_RELATIVE) {
TclAppendLiteralToObj(joinedPtr, "/");
}
}
}
Tcl_AppendToObj(joinedPtr, pattern, p-pattern);
}
Tcl_IncrRefCount(joinedPtr);
|
| ︙ | ︙ |
Changes to generic/tclIO.c.
| ︙ | ︙ | |||
1231 1232 1233 1234 1235 1236 1237 |
{
ChannelState *statePtr; /* State of the real channel. */
statePtr = ((Channel *) chan)->state->bottomChanPtr->state;
if (GotFlag(statePtr, CHANNEL_INCLOSE)) {
if (interp != NULL) {
| | | | 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 |
{
ChannelState *statePtr; /* State of the real channel. */
statePtr = ((Channel *) chan)->state->bottomChanPtr->state;
if (GotFlag(statePtr, CHANNEL_INCLOSE)) {
if (interp != NULL) {
TclPrintfResult(interp,
"illegal recursive call to close through close-handler"
" of channel");
}
return TCL_ERROR;
}
if (DetachChannel(interp, chan) != TCL_OK) {
return TCL_OK;
}
|
| ︙ | ︙ | |||
1459 1460 1461 1462 1463 1464 1465 |
name = chanPtr->state->channelName;
}
}
hTblPtr = GetChannelTable(interp);
hPtr = Tcl_FindHashEntry(hTblPtr, name);
if (hPtr == NULL) {
| | | | | 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 |
name = chanPtr->state->channelName;
}
}
hTblPtr = GetChannelTable(interp);
hPtr = Tcl_FindHashEntry(hTblPtr, name);
if (hPtr == NULL) {
TclPrintfResult(interp,
"can not find channel named \"%s\"", chanName);
TclSetErrorCode(interp, "TCL", "LOOKUP", "CHANNEL", chanName);
return NULL;
}
/*
* Always return bottom-most channel in the stack. This one lives the
* longest - other channels may go away unnoticed. The other APIs
* compensate where necessary to retrieve the topmost channel again.
|
| ︙ | ︙ | |||
1822 1823 1824 1825 1826 1827 1828 |
while ((statePtr != NULL) && (statePtr->topChanPtr != prevChanPtr)) {
statePtr = statePtr->nextCSPtr;
}
if (statePtr == NULL) {
if (interp) {
| | | | | | 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 |
while ((statePtr != NULL) && (statePtr->topChanPtr != prevChanPtr)) {
statePtr = statePtr->nextCSPtr;
}
if (statePtr == NULL) {
if (interp) {
TclPrintfResult(interp,
"couldn't find state for channel \"%s\"",
Tcl_GetChannelName(prevChan));
}
return NULL;
}
/*
* Here we check if the given "mask" matches the "flags" of the already
* existing channel.
*
* | - | R | W | RW |
* --+---+---+---+----+ <=> 0 != (chan->mask & prevChan->mask)
* - | | | | |
* R | | + | | + | The superceding channel is allowed to restrict
* W | | | + | + | the capabilities of the superceded one!
* RW| | + | + | + |
* --+---+---+---+----+
*/
if ((mask & GotFlag(statePtr, TCL_READABLE|TCL_WRITABLE)) == 0) {
if (interp) {
TclPrintfResult(interp,
"reading and writing both disallowed for channel \"%s\"",
Tcl_GetChannelName(prevChan));
}
return NULL;
}
/*
* Flush the buffers. This ensures that any data still in them at this
* time is not handled by the new transformation. Restrict this to
|
| ︙ | ︙ | |||
1873 1874 1875 1876 1877 1878 1879 |
* TODO: Examine what can go wrong if Tcl_Flush() call disturbs
* the stacking state of this channel during its operations.
*/
if (Tcl_Flush((Tcl_Channel) prevChanPtr) != TCL_OK) {
statePtr->csPtrR = csPtrR;
statePtr->csPtrW = csPtrW;
if (interp) {
| | | | 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 |
* TODO: Examine what can go wrong if Tcl_Flush() call disturbs
* the stacking state of this channel during its operations.
*/
if (Tcl_Flush((Tcl_Channel) prevChanPtr) != TCL_OK) {
statePtr->csPtrR = csPtrR;
statePtr->csPtrW = csPtrW;
if (interp) {
TclPrintfResult(interp,
"could not flush channel \"%s\"",
Tcl_GetChannelName(prevChan));
}
return NULL;
}
statePtr->csPtrR = csPtrR;
statePtr->csPtrW = csPtrW;
}
|
| ︙ | ︙ | |||
2068 2069 2070 2071 2072 2073 2074 |
* Move error messages put by the driver into the chan/ip
* bypass area into the regular interpreter result. Fall back
* to the regular message if nothing was found in the
* bypasses.
*/
if (!TclChanCaughtErrorBypass(interp, chan) && interp) {
| | | | 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 |
* Move error messages put by the driver into the chan/ip
* bypass area into the regular interpreter result. Fall back
* to the regular message if nothing was found in the
* bypasses.
*/
if (!TclChanCaughtErrorBypass(interp, chan) && interp) {
TclPrintfResult(interp,
"could not flush channel \"%s\"",
Tcl_GetChannelName((Tcl_Channel) chanPtr));
}
return TCL_ERROR;
}
statePtr->csPtrR = csPtrR;
statePtr->csPtrW = csPtrW;
}
|
| ︙ | ︙ | |||
2456 2457 2458 2459 2460 2461 2462 |
}
ResetFlag(statePtr, mode);
return TCL_OK;
error:
if (interp != NULL) {
| | | | 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 |
}
ResetFlag(statePtr, mode);
return TCL_OK;
error:
if (interp != NULL) {
TclPrintfResult(interp,
"Tcl_RemoveChannelMode error: %s. Channel: \"%s\"",
emsg, Tcl_GetChannelName((Tcl_Channel) chan));
}
return TCL_ERROR;
}
/*
*---------------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
2684 2685 2686 2687 2688 2689 2690 |
{
if (!GotFlag(statePtr, CHANNEL_DEAD)) {
return 0;
}
Tcl_SetErrno(EINVAL);
if (interp) {
| < | | 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 |
{
if (!GotFlag(statePtr, CHANNEL_DEAD)) {
return 0;
}
Tcl_SetErrno(EINVAL);
if (interp) {
TclPrintfResult(interp, "unable to access channel: invalid channel");
}
return 1;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
3472 3473 3474 3475 3476 3477 3478 |
if (statePtr->refCount > 0) {
Tcl_Panic("called Tcl_Close on channel with refCount > 0");
}
if (GotFlag(statePtr, CHANNEL_INCLOSE)) {
if (interp) {
| | | | 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 |
if (statePtr->refCount > 0) {
Tcl_Panic("called Tcl_Close on channel with refCount > 0");
}
if (GotFlag(statePtr, CHANNEL_INCLOSE)) {
if (interp) {
TclPrintfResult(interp,
"illegal recursive call to close through close-handler"
" of channel");
}
return TCL_ERROR;
}
SetFlag(statePtr, CHANNEL_INCLOSE);
/*
* When the channel has an escape sequence driven encoding such as
|
| ︙ | ︙ | |||
3640 3641 3642 3643 3644 3645 3646 |
chanPtr = (Channel *) chan;
statePtr = chanPtr->state;
if ((flags & (TCL_READABLE | TCL_WRITABLE)) == 0) {
return TclClose(interp, chan);
}
if ((flags & (TCL_READABLE | TCL_WRITABLE)) == (TCL_READABLE | TCL_WRITABLE)) {
| | | | | | | | | | | | 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 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 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 |
chanPtr = (Channel *) chan;
statePtr = chanPtr->state;
if ((flags & (TCL_READABLE | TCL_WRITABLE)) == 0) {
return TclClose(interp, chan);
}
if ((flags & (TCL_READABLE | TCL_WRITABLE)) == (TCL_READABLE | TCL_WRITABLE)) {
TclPrintfResult(interp,
"double-close of channels not supported by %ss",
chanPtr->typePtr->typeName);
return TCL_ERROR;
}
/*
* Does the channel support half-close anyway? Error if not.
*/
if (!chanPtr->typePtr->close2Proc) {
TclPrintfResult(interp,
"half-close of channels not supported by %ss",
chanPtr->typePtr->typeName);
return TCL_ERROR;
}
/*
* Is the channel unstacked ? If not we fail.
*/
if (chanPtr != statePtr->topChanPtr) {
TclPrintfResult(interp,
"half-close not applicable to stack of transformations");
return TCL_ERROR;
}
/*
* Check direction against channel mode. It is an error if we try to close
* a direction not supported by the channel (already closed, or never
* opened for that direction).
*/
if (!(GotFlag(statePtr, TCL_READABLE|TCL_WRITABLE) & flags)) {
const char *msg;
if (flags & TCL_CLOSE_READ) {
msg = "read";
} else {
msg = "write";
}
TclPrintfResult(interp,
"Half-close of %s-side not possible, side not opened or"
" already closed", msg);
return TCL_ERROR;
}
/*
* A user may try to call half-close from within a channel close handler.
* That won't do.
*/
if (GotFlag(statePtr, CHANNEL_INCLOSE)) {
if (interp) {
TclPrintfResult(interp,
"illegal recursive call to close through close-handler"
" of channel");
}
return TCL_ERROR;
}
if (flags & TCL_CLOSE_READ) {
/*
* Call the finalization code directly. There are no events to handle,
|
| ︙ | ︙ | |||
7883 7884 7885 7886 7887 7888 7889 |
Tcl_Interp *interp, /* Current interpreter (can be NULL).*/
const char *optionName, /* 'bad option' name */
const char *optionList) /* Specific options list to append to the
* standard generic options. Can be NULL for
* generic options only. */
{
if (interp != NULL) {
| < < | > > | 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 |
Tcl_Interp *interp, /* Current interpreter (can be NULL).*/
const char *optionName, /* 'bad option' name */
const char *optionList) /* Specific options list to append to the
* standard generic options. Can be NULL for
* generic options only. */
{
if (interp != NULL) {
const char **argv;
Tcl_Size argc, i;
Tcl_DString ds;
Tcl_Obj *errObj;
Tcl_DStringInit(&ds);
TclDStringAppendLiteral(&ds,
"blocking buffering buffersize encoding eofchar profile "
"translation");
if (optionList && (*optionList)) {
TclDStringAppendLiteral(&ds, " ");
Tcl_DStringAppend(&ds, optionList, -1);
}
if (Tcl_SplitList(interp, Tcl_DStringValue(&ds),
&argc, &argv) != TCL_OK) {
Tcl_Panic("malformed option list in channel driver");
|
| ︙ | ︙ | |||
8030 8031 8032 8033 8034 8035 8036 |
}
}
if (len == 0 || HaveOpt(2, "-encoding")) {
if (len == 0) {
Tcl_DStringAppendElement(dsPtr, "-encoding");
}
Tcl_DStringAppendElement(dsPtr,
| | | | 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 |
}
}
if (len == 0 || HaveOpt(2, "-encoding")) {
if (len == 0) {
Tcl_DStringAppendElement(dsPtr, "-encoding");
}
Tcl_DStringAppendElement(dsPtr,
Tcl_GetEncodingName(statePtr->encoding));
if (len > 0) {
return TCL_OK;
}
}
if (len == 0 || HaveOpt(2, "-eofchar")) {
char buf[4] = "";
if (len == 0) {
Tcl_DStringAppendElement(dsPtr, "-eofchar");
}
if ((flags & TCL_READABLE) && (statePtr->inEofChar != 0)) {
snprintf(buf, sizeof(buf), "%c", statePtr->inEofChar);
}
if (len > 0) {
Tcl_DStringAppend(dsPtr, buf, -1);
return TCL_OK;
}
Tcl_DStringAppendElement(dsPtr, buf);
}
if (len == 0 || HaveOpt(1, "-profile")) {
int profile;
const char *profileName;
|
| ︙ | ︙ | |||
8170 8171 8172 8173 8174 8175 8176 |
/*
* If the channel is in the middle of a background copy, fail.
*/
if (statePtr->csPtrR || statePtr->csPtrW) {
if (interp) {
| | | | 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 |
/*
* If the channel is in the middle of a background copy, fail.
*/
if (statePtr->csPtrR || statePtr->csPtrW) {
if (interp) {
TclPrintfResult(interp,
"unable to set channel options: background copy in"
" progress");
}
return TCL_ERROR;
}
/*
* Disallow options on dead channels -- channels that have been closed but
* not yet been deallocated. Such channels can be found if the exit
|
| ︙ | ︙ | |||
8221 8222 8223 8224 8225 8226 8227 |
ResetFlag(statePtr, CHANNEL_UNBUFFERED);
SetFlag(statePtr, CHANNEL_LINEBUFFERED);
} else if ((newValue[0] == 'n') &&
(strncmp(newValue, "none", len) == 0)) {
ResetFlag(statePtr, CHANNEL_LINEBUFFERED);
SetFlag(statePtr, CHANNEL_UNBUFFERED);
} else if (interp) {
| | | | 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 |
ResetFlag(statePtr, CHANNEL_UNBUFFERED);
SetFlag(statePtr, CHANNEL_LINEBUFFERED);
} else if ((newValue[0] == 'n') &&
(strncmp(newValue, "none", len) == 0)) {
ResetFlag(statePtr, CHANNEL_LINEBUFFERED);
SetFlag(statePtr, CHANNEL_UNBUFFERED);
} else if (interp) {
TclPrintfResult(interp,
"bad value for -buffering: must be one of"
" full, line, or none");
return TCL_ERROR;
}
return TCL_OK;
} else if (HaveOpt(7, "-buffersize")) {
Tcl_WideInt newBufferSize;
Tcl_Obj obj;
int code;
|
| ︙ | ︙ | |||
8251 8252 8253 8254 8255 8256 8257 |
return TCL_OK;
} else if (HaveOpt(2, "-encoding")) {
Tcl_Encoding encoding;
int profile;
if ((newValue[0] == '\0') || !strcmp(newValue, "binary")) {
if (interp) {
| | | | 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 |
return TCL_OK;
} else if (HaveOpt(2, "-encoding")) {
Tcl_Encoding encoding;
int profile;
if ((newValue[0] == '\0') || !strcmp(newValue, "binary")) {
if (interp) {
TclPrintfResult(interp,
"unknown encoding \"%s\": No longer supported.\n"
"\tplease use either \"-translation binary\" "
"or \"-encoding iso8859-1\"", newValue);
}
return TCL_ERROR;
} else {
encoding = Tcl_GetEncoding(interp, newValue);
if (encoding == NULL) {
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
8298 8299 8300 8301 8302 8303 8304 |
#endif
))) {
if (GotFlag(statePtr, TCL_READABLE)) {
statePtr->inEofChar = newValue[0];
}
} else {
if (interp) {
| | | | 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 |
#endif
))) {
if (GotFlag(statePtr, TCL_READABLE)) {
statePtr->inEofChar = newValue[0];
}
} else {
if (interp) {
TclPrintfResult(interp,
"bad value for -eofchar: must be non-NUL ASCII"
" character");
}
Tcl_Free((void *)argv);
return TCL_ERROR;
}
if (argv != NULL) {
Tcl_Free((void *)argv);
}
|
| ︙ | ︙ | |||
8345 8346 8347 8348 8349 8350 8351 |
readMode = GotFlag(statePtr, TCL_READABLE) ? argv[0] : NULL;
writeMode = GotFlag(statePtr, TCL_WRITABLE) ? argv[0] : NULL;
} else if (argc == 2) {
readMode = GotFlag(statePtr, TCL_READABLE) ? argv[0] : NULL;
writeMode = GotFlag(statePtr, TCL_WRITABLE) ? argv[1] : NULL;
} else {
if (interp) {
| | | | 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 |
readMode = GotFlag(statePtr, TCL_READABLE) ? argv[0] : NULL;
writeMode = GotFlag(statePtr, TCL_WRITABLE) ? argv[0] : NULL;
} else if (argc == 2) {
readMode = GotFlag(statePtr, TCL_READABLE) ? argv[0] : NULL;
writeMode = GotFlag(statePtr, TCL_WRITABLE) ? argv[1] : NULL;
} else {
if (interp) {
TclPrintfResult(interp,
"bad value for -translation: must be a one or two"
" element list");
}
Tcl_Free((void *)argv);
return TCL_ERROR;
}
if (readMode) {
TclEolTranslation translation;
|
| ︙ | ︙ | |||
8375 8376 8377 8378 8379 8380 8381 |
translation = TCL_TRANSLATE_CR;
} else if (strcmp(readMode, "crlf") == 0) {
translation = TCL_TRANSLATE_CRLF;
} else if (strcmp(readMode, "platform") == 0) {
translation = TCL_PLATFORM_TRANSLATION;
} else {
if (interp) {
| | | | 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 |
translation = TCL_TRANSLATE_CR;
} else if (strcmp(readMode, "crlf") == 0) {
translation = TCL_TRANSLATE_CRLF;
} else if (strcmp(readMode, "platform") == 0) {
translation = TCL_PLATFORM_TRANSLATION;
} else {
if (interp) {
TclPrintfResult(interp,
"bad value for -translation: must be one of "
"auto, binary, cr, lf, crlf, or platform");
}
Tcl_Free((void *)argv);
return TCL_ERROR;
}
/*
* Reset the EOL flags since we need to look at any buffered data
|
| ︙ | ︙ | |||
8424 8425 8426 8427 8428 8429 8430 |
statePtr->outputTranslation = TCL_TRANSLATE_CR;
} else if (strcmp(writeMode, "crlf") == 0) {
statePtr->outputTranslation = TCL_TRANSLATE_CRLF;
} else if (strcmp(writeMode, "platform") == 0) {
statePtr->outputTranslation = TCL_PLATFORM_TRANSLATION;
} else {
if (interp) {
| | | | 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 |
statePtr->outputTranslation = TCL_TRANSLATE_CR;
} else if (strcmp(writeMode, "crlf") == 0) {
statePtr->outputTranslation = TCL_TRANSLATE_CRLF;
} else if (strcmp(writeMode, "platform") == 0) {
statePtr->outputTranslation = TCL_PLATFORM_TRANSLATION;
} else {
if (interp) {
TclPrintfResult(interp,
"bad value for -translation: must be one of "
"auto, binary, cr, lf, crlf, or platform");
}
Tcl_Free((void *)argv);
return TCL_ERROR;
}
}
Tcl_Free((void *)argv);
return TCL_OK;
|
| ︙ | ︙ | |||
9233 9234 9235 9236 9237 9238 9239 |
chan = Tcl_GetChannel(interp, chanName, NULL);
if (chan == NULL) {
return TCL_ERROR;
}
chanPtr = (Channel *) chan;
statePtr = chanPtr->state;
if (GotFlag(statePtr, mask) == 0) {
| | | | 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 |
chan = Tcl_GetChannel(interp, chanName, NULL);
if (chan == NULL) {
return TCL_ERROR;
}
chanPtr = (Channel *) chan;
statePtr = chanPtr->state;
if (GotFlag(statePtr, mask) == 0) {
TclPrintfResult(interp, "channel is not %s",
(mask == TCL_READABLE) ? "readable" : "writable");
return TCL_ERROR;
}
/*
* If we are supposed to return the script, do so.
*/
|
| ︙ | ︙ | |||
9344 9345 9346 9347 9348 9349 9350 |
int moveBytes;
inStatePtr = inPtr->state;
outStatePtr = outPtr->state;
if (BUSY_STATE(inStatePtr, TCL_READABLE)) {
if (interp) {
| | | | | | 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 |
int moveBytes;
inStatePtr = inPtr->state;
outStatePtr = outPtr->state;
if (BUSY_STATE(inStatePtr, TCL_READABLE)) {
if (interp) {
TclPrintfResult(interp,
"channel \"%s\" is busy", Tcl_GetChannelName(inChan));
}
return TCL_ERROR;
}
if (BUSY_STATE(outStatePtr, TCL_WRITABLE)) {
if (interp) {
TclPrintfResult(interp,
"channel \"%s\" is busy", Tcl_GetChannelName(outChan));
}
return TCL_ERROR;
}
readFlags = inStatePtr->flags;
writeFlags = outStatePtr->flags;
|
| ︙ | ︙ | |||
9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 |
if (code == TCL_ERROR) {
return TCL_ERROR;
}
/* code == TCL_CONTINUE --> continue the loop */
}
return TCL_OK; /* Silence compiler warnings */
}
static int
CopyData(
CopyState *csPtr, /* State of copy operation. */
int mask) /* Current channel event flags. */
{
Tcl_Interp *interp;
| > > > > > > > > > > > > > > > > > > | 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 |
if (code == TCL_ERROR) {
return TCL_ERROR;
}
/* code == TCL_CONTINUE --> continue the loop */
}
return TCL_OK; /* Silence compiler warnings */
}
static inline Tcl_Obj *
ErrorCopying(
Tcl_Interp *interp,
Tcl_Channel chan,
const char *direction,
Tcl_Obj *msg)
{
const char *chanName = Tcl_GetChannelName(chan);
const char *details = (msg ? TclGetString(msg) : Tcl_PosixError(interp));
if (chanName) {
return Tcl_ObjPrintf("error %s \"%s\": %s",
direction, chanName, details);
} else {
return Tcl_ObjPrintf("error %s closed channel: %s", direction, details);
}
}
static int
CopyData(
CopyState *csPtr, /* State of copy operation. */
int mask) /* Current channel event flags. */
{
Tcl_Interp *interp;
|
| ︙ | ︙ | |||
9804 9805 9806 9807 9808 9809 9810 |
}
underflow = (size >= 0) && (size < sizeb); /* Input underflow */
}
if (size < 0) {
readError:
if (interp) {
| | < < < < < < < < | 9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 |
}
underflow = (size >= 0) && (size < sizeb); /* Input underflow */
}
if (size < 0) {
readError:
if (interp) {
errObj = ErrorCopying(interp, inChan, "reading", msg);
}
if (msg != NULL) {
Tcl_DecrRefCount(msg);
}
break;
} else if (underflow) {
/*
|
| ︙ | ︙ | |||
9880 9881 9882 9883 9884 9885 9886 |
* drive toRead below -1, causing infinite looping). Completely
* unsuitable for updating totals and toRead.
*/
if (sizeb < 0) {
writeError:
if (interp) {
| | < < < < < < < < | 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 9903 |
* drive toRead below -1, causing infinite looping). Completely
* unsuitable for updating totals and toRead.
*/
if (sizeb < 0) {
writeError:
if (interp) {
errObj = ErrorCopying(interp, outChan, "writing", msg);
}
if (msg != NULL) {
Tcl_DecrRefCount(msg);
}
break;
}
|
| ︙ | ︙ | |||
10507 10508 10509 10510 10511 10512 10513 |
*
* Note that we cannot have a message in the interpreter bypass
* area, StackSetBlockMode is restricted to the channel bypass.
* We still need the interp as the destination of the move.
*/
if (!TclChanCaughtErrorBypass(interp, (Tcl_Channel) chanPtr)) {
| | | | 10508 10509 10510 10511 10512 10513 10514 10515 10516 10517 10518 10519 10520 10521 10522 10523 10524 |
*
* Note that we cannot have a message in the interpreter bypass
* area, StackSetBlockMode is restricted to the channel bypass.
* We still need the interp as the destination of the move.
*/
if (!TclChanCaughtErrorBypass(interp, (Tcl_Channel) chanPtr)) {
TclPrintfResult(interp,
"error setting blocking mode: %s",
Tcl_PosixError(interp));
}
} else {
/*
* TIP #219.
* If we have no interpreter to put a bypass message into we have
* to clear it, to prevent its propagation and use in other places
* unrelated to the actual occurence of the problem.
|
| ︙ | ︙ |
Changes to generic/tclIOCmd.c.
| ︙ | ︙ | |||
153 154 155 156 157 158 159 |
}
chanObjPtr = tsdPtr->stdoutObjPtr;
}
if (TclGetChannelFromObj(interp, chanObjPtr, &chan, &mode, 0) != TCL_OK) {
return TCL_ERROR;
}
if (!(mode & TCL_WRITABLE)) {
| | | | 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
}
chanObjPtr = tsdPtr->stdoutObjPtr;
}
if (TclGetChannelFromObj(interp, chanObjPtr, &chan, &mode, 0) != TCL_OK) {
return TCL_ERROR;
}
if (!(mode & TCL_WRITABLE)) {
TclPrintfResult(interp,
"channel \"%s\" wasn't opened for writing",
TclGetString(chanObjPtr));
return TCL_ERROR;
}
TclChannelPreserve(chan);
result = Tcl_WriteObj(chan, string);
if (result == TCL_INDEX_NONE) {
goto error;
|
| ︙ | ︙ | |||
182 183 184 185 186 187 188 |
* Capture error messages put by the driver into the bypass area and put
* them into the regular interpreter result. Fall back to the regular
* message if nothing was found in the bypass.
*/
error:
if (!TclChanCaughtErrorBypass(interp, chan)) {
| | | | 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
* Capture error messages put by the driver into the bypass area and put
* them into the regular interpreter result. Fall back to the regular
* message if nothing was found in the bypass.
*/
error:
if (!TclChanCaughtErrorBypass(interp, chan)) {
TclPrintfResult(interp, "error writing \"%s\": %s",
TclGetString(chanObjPtr), Tcl_PosixError(interp));
}
TclChannelRelease(chan);
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
|
| ︙ | ︙ | |||
226 227 228 229 230 231 232 |
return TCL_ERROR;
}
chanObjPtr = objv[1];
if (TclGetChannelFromObj(interp, chanObjPtr, &chan, &mode, 0) != TCL_OK) {
return TCL_ERROR;
}
if (!(mode & TCL_WRITABLE)) {
| | | | | | 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
return TCL_ERROR;
}
chanObjPtr = objv[1];
if (TclGetChannelFromObj(interp, chanObjPtr, &chan, &mode, 0) != TCL_OK) {
return TCL_ERROR;
}
if (!(mode & TCL_WRITABLE)) {
TclPrintfResult(interp,
"channel \"%s\" wasn't opened for writing",
TclGetString(chanObjPtr));
return TCL_ERROR;
}
TclChannelPreserve(chan);
if (Tcl_Flush(chan) != TCL_OK) {
/*
* TIP #219.
* Capture error messages put by the driver into the bypass area and
* put them into the regular interpreter result. Fall back to the
* regular message if nothing was found in the bypass.
*/
if (!TclChanCaughtErrorBypass(interp, chan)) {
TclPrintfResult(interp,
"error flushing \"%s\": %s",
TclGetString(chanObjPtr), Tcl_PosixError(interp));
}
TclChannelRelease(chan);
return TCL_ERROR;
}
TclChannelRelease(chan);
return TCL_OK;
}
|
| ︙ | ︙ | |||
292 293 294 295 296 297 298 |
return TCL_ERROR;
}
chanObjPtr = objv[1];
if (TclGetChannelFromObj(interp, chanObjPtr, &chan, &mode, 0) != TCL_OK) {
return TCL_ERROR;
}
if (!(mode & TCL_READABLE)) {
| | | | | | 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
return TCL_ERROR;
}
chanObjPtr = objv[1];
if (TclGetChannelFromObj(interp, chanObjPtr, &chan, &mode, 0) != TCL_OK) {
return TCL_ERROR;
}
if (!(mode & TCL_READABLE)) {
TclPrintfResult(interp,
"channel \"%s\" wasn't opened for reading",
TclGetString(chanObjPtr));
return TCL_ERROR;
}
TclChannelPreserve(chan);
TclNewObj(linePtr);
lineLen = Tcl_GetsObj(chan, linePtr);
if (lineLen == TCL_IO_FAILURE) {
if (!Tcl_Eof(chan) && !Tcl_InputBlocked(chan)) {
Tcl_DecrRefCount(linePtr);
/*
* TIP #219.
* Capture error messages put by the driver into the bypass area
* and put them into the regular interpreter result. Fall back to
* the regular message if nothing was found in the bypass.
*/
if (!TclChanCaughtErrorBypass(interp, chan)) {
TclPrintfResult(interp,
"error reading \"%s\": %s",
TclGetString(chanObjPtr), Tcl_PosixError(interp));
}
code = TCL_ERROR;
goto done;
}
lineLen = TCL_IO_FAILURE;
}
if (objc == 3) {
|
| ︙ | ︙ | |||
403 404 405 406 407 408 409 |
}
chanObjPtr = objv[i];
if (TclGetChannelFromObj(interp, chanObjPtr, &chan, &mode, 0) != TCL_OK) {
return TCL_ERROR;
}
if (!(mode & TCL_READABLE)) {
| | | | | | | | | | 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
}
chanObjPtr = objv[i];
if (TclGetChannelFromObj(interp, chanObjPtr, &chan, &mode, 0) != TCL_OK) {
return TCL_ERROR;
}
if (!(mode & TCL_READABLE)) {
TclPrintfResult(interp,
"channel \"%s\" wasn't opened for reading",
TclGetString(chanObjPtr));
return TCL_ERROR;
}
i++; /* Consumed channel name. */
/*
* Compute how many bytes to read.
*/
toRead = -1;
if (i < objc) {
if ((TclGetWideIntFromObj(NULL, objv[i], &toRead) != TCL_OK)
|| (toRead < 0)) {
TclPrintfResult(interp,
"expected non-negative integer but got \"%s\"",
TclGetString(objv[i]));
TclSetErrorCode(interp, "TCL", "VALUE", "NUMBER");
return TCL_ERROR;
}
}
TclNewObj(resultPtr);
TclChannelPreserve(chan);
charactersRead = Tcl_ReadChars(chan, resultPtr, toRead, 0);
if (charactersRead == TCL_IO_FAILURE) {
Tcl_Obj *returnOptsPtr = NULL;
if (TclChannelGetBlockingMode(chan)) {
returnOptsPtr = Tcl_NewDictObj();
Tcl_DictObjPut(NULL, returnOptsPtr, TclNewString("-data"),
resultPtr);
} else {
Tcl_DecrRefCount(resultPtr);
}
/*
* TIP #219.
* Capture error messages put by the driver into the bypass area and
* put them into the regular interpreter result. Fall back to the
* regular message if nothing was found in the bypass.
*/
if (!TclChanCaughtErrorBypass(interp, chan)) {
TclPrintfResult(interp,
"error reading \"%s\": %s",
TclGetString(chanObjPtr), Tcl_PosixError(interp));
}
TclChannelRelease(chan);
if (returnOptsPtr) {
Tcl_SetReturnOptions(interp, returnOptsPtr);
}
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
540 541 542 543 544 545 546 |
* TIP #219.
* Capture error messages put by the driver into the bypass area and
* put them into the regular interpreter result. Fall back to the
* regular message if nothing was found in the bypass.
*/
if (!TclChanCaughtErrorBypass(interp, chan)) {
| | | | 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
* TIP #219.
* Capture error messages put by the driver into the bypass area and
* put them into the regular interpreter result. Fall back to the
* regular message if nothing was found in the bypass.
*/
if (!TclChanCaughtErrorBypass(interp, chan)) {
TclPrintfResult(interp,
"error during seek on \"%s\": %s",
TclGetString(objv[1]), Tcl_PosixError(interp));
}
TclChannelRelease(chan);
return TCL_ERROR;
}
TclChannelRelease(chan);
return TCL_OK;
}
|
| ︙ | ︙ | |||
671 672 673 674 675 676 677 |
/*
* Check direction against channel mode. It is an error if we try to
* close a direction not supported by the channel (already closed, or
* never opened for that direction).
*/
if (!(dir & Tcl_GetChannelMode(chan))) {
| | | | 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 |
/*
* Check direction against channel mode. It is an error if we try to
* close a direction not supported by the channel (already closed, or
* never opened for that direction).
*/
if (!(dir & Tcl_GetChannelMode(chan))) {
TclPrintfResult(interp,
"Half-close of %s-side not possible, side not opened"
" or already closed", dirOptions[index]);
return TCL_ERROR;
}
/*
* Special handling is needed if and only if the channel mode supports
* more than the direction to close. Because if the close the last
* direction supported we can and will go through the regular
|
| ︙ | ︙ | |||
1011 1012 1013 1014 1015 1016 1017 |
* TIP #219.
* Capture error messages put by the driver into the bypass area
* and put them into the regular interpreter result. Fall back to
* the regular message if nothing was found in the bypass.
*/
if (!TclChanCaughtErrorBypass(interp, chan)) {
| | | | 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 |
* TIP #219.
* Capture error messages put by the driver into the bypass area
* and put them into the regular interpreter result. Fall back to
* the regular message if nothing was found in the bypass.
*/
if (!TclChanCaughtErrorBypass(interp, chan)) {
TclPrintfResult(interp,
"error reading output from command: %s",
Tcl_PosixError(interp));
Tcl_DecrRefCount(resultPtr);
}
return TCL_ERROR;
}
}
/*
|
| ︙ | ︙ | |||
1082 1083 1084 1085 1086 1087 1088 |
return TCL_ERROR;
}
if (TclGetChannelFromObj(interp, objv[1], &chan, &mode, 0) != TCL_OK) {
return TCL_ERROR;
}
if (!(mode & TCL_READABLE)) {
| | | | 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 |
return TCL_ERROR;
}
if (TclGetChannelFromObj(interp, objv[1], &chan, &mode, 0) != TCL_OK) {
return TCL_ERROR;
}
if (!(mode & TCL_READABLE)) {
TclPrintfResult(interp,
"channel \"%s\" wasn't opened for reading",
TclGetString(objv[1]));
return TCL_ERROR;
}
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(Tcl_InputBlocked(chan)));
return TCL_OK;
}
|
| ︙ | ︙ | |||
1144 1145 1146 1147 1148 1149 1150 |
if ((permString[scanned] == '0')
&& (permString[scanned+1] >= '0')
&& (permString[scanned+1] <= '7')) {
Tcl_Obj *permObj;
TclNewLiteralStringObj(permObj, "0o");
| | | 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 |
if ((permString[scanned] == '0')
&& (permString[scanned+1] >= '0')
&& (permString[scanned+1] <= '7')) {
Tcl_Obj *permObj;
TclNewLiteralStringObj(permObj, "0o");
Tcl_AppendToObj(permObj, permString+scanned+1, TCL_AUTO_LENGTH);
code = TclGetIntFromObj(NULL, permObj, &prot);
Tcl_DecrRefCount(permObj);
}
if ((code == TCL_ERROR)
&& TclGetIntFromObj(interp, objv[3], &prot) != TCL_OK) {
return TCL_ERROR;
|
| ︙ | ︙ | |||
1522 1523 1524 1525 1526 1527 1528 |
if (Tcl_GetIndexFromObj(interp, objv[a], socketOptions, "option",
TCL_EXACT, &optionIndex) != TCL_OK) {
return TCL_ERROR;
}
switch (optionIndex) {
case SKT_ASYNC:
if (server == 1) {
| | | | | | | | | | | | | | | | | < | | | | 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 |
if (Tcl_GetIndexFromObj(interp, objv[a], socketOptions, "option",
TCL_EXACT, &optionIndex) != TCL_OK) {
return TCL_ERROR;
}
switch (optionIndex) {
case SKT_ASYNC:
if (server == 1) {
TclPrintfResult(interp,
"cannot set -async option for server sockets");
return TCL_ERROR;
}
async = 1;
break;
case SKT_MYADDR:
a++;
if (a >= objc) {
TclPrintfResult(interp,
"no argument given for -myaddr option");
return TCL_ERROR;
}
myaddr = TclGetString(objv[a]);
break;
case SKT_MYPORT: {
const char *myPortName;
a++;
if (a >= objc) {
TclPrintfResult(interp,
"no argument given for -myport option");
return TCL_ERROR;
}
myPortName = TclGetString(objv[a]);
if (TclSockGetPort(interp, myPortName, "tcp", &myport) != TCL_OK) {
return TCL_ERROR;
}
break;
}
case SKT_SERVER:
if (async == 1) {
TclPrintfResult(interp,
"cannot set -async option for server sockets");
return TCL_ERROR;
}
server = 1;
a++;
if (a >= objc) {
TclPrintfResult(interp,
"no argument given for -server option");
return TCL_ERROR;
}
script = objv[a];
break;
case SKT_REUSEADDR:
a++;
if (a >= objc) {
TclPrintfResult(interp,
"no argument given for -reuseaddr option");
return TCL_ERROR;
}
if (Tcl_GetBooleanFromObj(interp, objv[a], &reusea) != TCL_OK) {
return TCL_ERROR;
}
break;
case SKT_REUSEPORT:
a++;
if (a >= objc) {
TclPrintfResult(interp,
"no argument given for -reuseport option");
return TCL_ERROR;
}
if (Tcl_GetBooleanFromObj(interp, objv[a], &reusep) != TCL_OK) {
return TCL_ERROR;
}
break;
case SKT_BACKLOG:
a++;
if (a >= objc) {
TclPrintfResult(interp,
"no argument given for -backlog option");
return TCL_ERROR;
}
if (Tcl_GetIntFromObj(interp, objv[a], &backlog) != TCL_OK) {
return TCL_ERROR;
}
break;
default:
Tcl_Panic("Tcl_SocketObjCmd: bad option index to SocketOptions");
}
}
if (server) {
host = myaddr; /* NULL implies INADDR_ANY */
if (myport != 0) {
TclPrintfResult(interp, "option -myport is not valid for servers");
return TCL_ERROR;
}
} else if (a < objc) {
host = TclGetString(objv[a]);
a++;
} else {
Interp *iPtr;
wrongNumArgs:
iPtr = (Interp *) interp;
Tcl_WrongNumArgs(interp, 1, objv,
"?-async? ?-myaddr addr? ?-myport myport? host port");
iPtr->flags |= INTERP_ALTERNATE_WRONG_ARGS;
Tcl_WrongNumArgs(interp, 1, objv,
"-server command ?-backlog count? ?-myaddr addr? "
"?-reuseaddr boolean? ?-reuseport boolean? port");
return TCL_ERROR;
}
if (!server && (reusea != -1 || reusep != -1 || backlog != -1)) {
TclPrintfResult(interp,
"options -backlog, -reuseaddr, and -reuseport are only valid "
"for servers");
return TCL_ERROR;
}
/*
* Set the options to their default value if the user didn't override
* their value.
*/
|
| ︙ | ︙ | |||
1765 1766 1767 1768 1769 1770 1771 |
* writable, as appropriate.
*/
if (TclGetChannelFromObj(interp, objv[1], &inChan, &mode, 0) != TCL_OK) {
return TCL_ERROR;
}
if (!(mode & TCL_READABLE)) {
| | | | | | 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 |
* writable, as appropriate.
*/
if (TclGetChannelFromObj(interp, objv[1], &inChan, &mode, 0) != TCL_OK) {
return TCL_ERROR;
}
if (!(mode & TCL_READABLE)) {
TclPrintfResult(interp,
"channel \"%s\" wasn't opened for reading",
TclGetString(objv[1]));
return TCL_ERROR;
}
if (TclGetChannelFromObj(interp, objv[2], &outChan, &mode, 0) != TCL_OK) {
return TCL_ERROR;
}
if (!(mode & TCL_WRITABLE)) {
TclPrintfResult(interp,
"channel \"%s\" wasn't opened for writing",
TclGetString(objv[2]));
return TCL_ERROR;
}
toRead = -1;
cmdPtr = NULL;
for (i = 3; i < objc; i += 2) {
if (Tcl_GetIndexFromObj(interp, objv[i], switches, "option", 0,
|
| ︙ | ︙ | |||
1920 1921 1922 1923 1924 1925 1926 |
* User is supplying an explicit length.
*/
if (TclGetWideIntFromObj(interp, objv[2], &length) != TCL_OK) {
return TCL_ERROR;
}
if (length < 0) {
| | | | | | | | 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 |
* User is supplying an explicit length.
*/
if (TclGetWideIntFromObj(interp, objv[2], &length) != TCL_OK) {
return TCL_ERROR;
}
if (length < 0) {
TclPrintfResult(interp,
"cannot truncate to negative length of file");
return TCL_ERROR;
}
} else {
/*
* User wants to truncate to the current file position.
*/
length = Tcl_Tell(chan);
if (length == -1) {
TclPrintfResult(interp,
"could not determine current location in \"%s\": %s",
TclGetString(objv[1]), Tcl_PosixError(interp));
return TCL_ERROR;
}
}
if (Tcl_TruncateChannel(chan, length) != TCL_OK) {
TclPrintfResult(interp,
"error during truncate on \"%s\": %s",
TclGetString(objv[1]), Tcl_PosixError(interp));
return TCL_ERROR;
}
return TCL_OK;
}
/*
|
| ︙ | ︙ |
Changes to generic/tclIOGT.c.
| ︙ | ︙ | |||
263 264 265 266 267 268 269 |
Tcl_DString ds;
if (chan == NULL) {
return TCL_ERROR;
}
if (TCL_OK != TclListObjLength(interp, cmdObjPtr, &objc)) {
| < | | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
Tcl_DString ds;
if (chan == NULL) {
return TCL_ERROR;
}
if (TCL_OK != TclListObjLength(interp, cmdObjPtr, &objc)) {
TclPrintfResult(interp, "-command value is not a list");
return TCL_ERROR;
}
chanPtr = (Channel *) chan;
statePtr = chanPtr->state;
chanPtr = statePtr->topChanPtr;
chan = (Tcl_Channel) chanPtr;
|
| ︙ | ︙ | |||
468 469 470 471 472 473 474 |
case TRANSMIT_IBUF:
resObj = Tcl_GetObjResult(eval);
resBuf = Tcl_GetBytesFromObj(NULL, resObj, &resLen);
if (resBuf) {
ResultAdd(&dataPtr->result, resBuf, resLen);
break;
}
| | | < | 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
case TRANSMIT_IBUF:
resObj = Tcl_GetObjResult(eval);
resBuf = Tcl_GetBytesFromObj(NULL, resObj, &resLen);
if (resBuf) {
ResultAdd(&dataPtr->result, resBuf, resLen);
break;
}
nonBytes:
TclPrintfResult(interp, "chan transform callback received non-bytes");
Tcl_Release(eval);
return TCL_ERROR;
case TRANSMIT_NUM:
/*
* Interpret result as integer number.
*/
|
| ︙ | ︙ |
Changes to generic/tclIORChan.c.
| ︙ | ︙ | |||
504 505 506 507 508 509 510 |
Tcl_Size listc; /* Result of 'initialize', and of */
Tcl_Obj **listv; /* its sublist in the 2nd element */
int methIndex; /* Encoded method name */
int result; /* Result code for 'initialize' */
Tcl_Obj *resObj; /* Result data for 'initialize' */
int methods; /* Bitmask for supported methods. */
Channel *chanPtr; /* 'chan' resolved to internal struct. */
| < | 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
Tcl_Size listc; /* Result of 'initialize', and of */
Tcl_Obj **listv; /* its sublist in the 2nd element */
int methIndex; /* Encoded method name */
int result; /* Result code for 'initialize' */
Tcl_Obj *resObj; /* Result data for 'initialize' */
int methods; /* Bitmask for supported methods. */
Channel *chanPtr; /* 'chan' resolved to internal struct. */
ReflectedChannelMap *rcmPtr;
/* Map of reflected channels with handlers in
* this interp. */
Tcl_HashEntry *hPtr; /* Entry in the above map */
int isNew; /* Placeholder. */
/*
|
| ︙ | ︙ | |||
598 599 600 601 602 603 604 |
* Verify the result.
* - List, of method names. Convert to mask.
* Check for non-optionals through the mask.
* Compare open mode against optional r/w.
*/
if (TclListObjGetElements(NULL, resObj, &listc, &listv) != TCL_OK) {
| | | < | | < | | | | | | | | | | | | 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 |
* Verify the result.
* - List, of method names. Convert to mask.
* Check for non-optionals through the mask.
* Compare open mode against optional r/w.
*/
if (TclListObjGetElements(NULL, resObj, &listc, &listv) != TCL_OK) {
TclPrintfResult(interp,
"chan handler \"%s initialize\" returned non-list: %s",
TclGetString(cmdObj), TclGetString(resObj));
Tcl_DecrRefCount(resObj);
goto error;
}
methods = 0;
while (listc > 0) {
if (Tcl_GetIndexFromObj(interp, listv[listc-1], methodNames,
"method", TCL_EXACT, &methIndex) != TCL_OK) {
TclPrintfResult(interp,
"chan handler \"%s initialize\" returned %s",
Tcl_GetString(cmdObj), Tcl_GetStringResult(interp));
Tcl_DecrRefCount(resObj);
goto error;
}
methods |= FLAG(methIndex);
listc--;
}
Tcl_DecrRefCount(resObj);
if ((REQUIRED_METHODS & methods) != REQUIRED_METHODS) {
TclPrintfResult(interp,
"chan handler \"%s\" does not support all required methods",
TclGetString(cmdObj));
goto error;
}
if ((mode & TCL_READABLE) && !HAS(methods, METH_READ)) {
TclPrintfResult(interp,
"chan handler \"%s\" lacks a \"read\" method",
TclGetString(cmdObj));
goto error;
}
if ((mode & TCL_WRITABLE) && !HAS(methods, METH_WRITE)) {
TclPrintfResult(interp,
"chan handler \"%s\" lacks a \"write\" method",
TclGetString(cmdObj));
goto error;
}
if (!IMPLIES(HAS(methods, METH_CGET), HAS(methods, METH_CGETALL))) {
TclPrintfResult(interp,
"chan handler \"%s\" supports \"cget\" but not \"cgetall\"",
TclGetString(cmdObj));
goto error;
}
if (!IMPLIES(HAS(methods, METH_CGETALL), HAS(methods, METH_CGET))) {
TclPrintfResult(interp,
"chan handler \"%s\" supports \"cgetall\" but not \"cget\"",
TclGetString(cmdObj));
goto error;
}
Tcl_ResetResult(interp);
/*
* Everything is fine now.
|
| ︙ | ︙ | |||
855 856 857 858 859 860 861 |
chanId = TclGetString(objv[CHAN]);
rcmPtr = GetReflectedChannelMap(interp);
hPtr = Tcl_FindHashEntry(&rcmPtr->map, chanId);
if (hPtr == NULL) {
| | | | | 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 |
chanId = TclGetString(objv[CHAN]);
rcmPtr = GetReflectedChannelMap(interp);
hPtr = Tcl_FindHashEntry(&rcmPtr->map, chanId);
if (hPtr == NULL) {
TclPrintfResult(interp,
"can not find reflected channel named \"%s\"", chanId);
TclSetErrorCode(interp, "TCL", "LOOKUP", "CHANNEL", chanId);
return TCL_ERROR;
}
/*
* Note that the search above subsumes several of the older checks,
* namely:
*
|
| ︙ | ︙ | |||
909 910 911 912 913 914 915 |
* "write". Expect at least one list element. Abbreviations are ok.
*/
if (EncodeEventMask(interp, "event", objv[EVENT], &events) != TCL_OK) {
return TCL_ERROR;
}
if (events == 0) {
| < | | | | 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 |
* "write". Expect at least one list element. Abbreviations are ok.
*/
if (EncodeEventMask(interp, "event", objv[EVENT], &events) != TCL_OK) {
return TCL_ERROR;
}
if (events == 0) {
TclPrintfResult(interp, "bad event list: is empty");
return TCL_ERROR;
}
/*
* Check that the channel is actually interested in the provided events.
*/
if (events & ~rcPtr->interest) {
TclPrintfResult(interp,
"tried to post events channel \"%s\" is not interested in",
chanId);
return TCL_ERROR;
}
/*
* We have the channel and the events to post.
*/
|
| ︙ | ︙ | |||
1951 1952 1953 1954 1955 1956 1957 |
if ((listc % 2) == 1) {
/*
* Odd number of elements is wrong.
*/
Tcl_ResetResult(interp);
| | | | 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 |
if ((listc % 2) == 1) {
/*
* Odd number of elements is wrong.
*/
Tcl_ResetResult(interp);
TclPrintfResult(interp,
"Expected list with even number of "
"elements, got %" TCL_SIZE_MODIFIER "d element%s instead", listc,
(listc == 1 ? "" : "s"));
goto error;
} else {
Tcl_Size len;
const char *str = TclGetStringFromObj(resObj, &len);
if (len) {
TclDStringAppendLiteral(dsPtr, " ");
|
| ︙ | ︙ | |||
2409 2410 2411 2412 2413 2414 2415 |
if (result != TCL_ERROR) {
Tcl_Size cmdLen;
const char *cmdString = TclGetStringFromObj(cmd, &cmdLen);
Tcl_IncrRefCount(cmd);
Tcl_ResetResult(rcPtr->interp);
| | | | | | 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 |
if (result != TCL_ERROR) {
Tcl_Size cmdLen;
const char *cmdString = TclGetStringFromObj(cmd, &cmdLen);
Tcl_IncrRefCount(cmd);
Tcl_ResetResult(rcPtr->interp);
TclPrintfResult(rcPtr->interp,
"chan handler returned bad code: %d", result);
Tcl_LogCommandInfo(rcPtr->interp, cmdString, cmdString,
cmdLen);
Tcl_DecrRefCount(cmd);
result = TCL_ERROR;
}
TclPrintfErrorInfo(rcPtr->interp,
"\n (chan handler subcommand \"%s\")",
methodNames[method]);
resObj = MarshallError(rcPtr->interp);
}
Tcl_IncrRefCount(resObj);
}
Tcl_DecrRefCount(cmd);
Tcl_RestoreInterpState(rcPtr->interp, sr);
Tcl_Release(rcPtr->interp);
|
| ︙ | ︙ |
Changes to generic/tclIORTrans.c.
| ︙ | ︙ | |||
596 597 598 599 600 601 602 |
/*
* Verify the result.
* - List, of method names. Convert to mask. Check for non-optionals
* through the mask. Compare open mode against optional r/w.
*/
if (TclListObjGetElements(NULL, resObj, &listc, &listv) != TCL_OK) {
| | | | | < | | | | | | | | | 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 |
/*
* Verify the result.
* - List, of method names. Convert to mask. Check for non-optionals
* through the mask. Compare open mode against optional r/w.
*/
if (TclListObjGetElements(NULL, resObj, &listc, &listv) != TCL_OK) {
TclPrintfResult(interp,
"chan handler \"%s initialize\" returned non-list: %s",
TclGetString(cmdObj), TclGetString(resObj));
Tcl_DecrRefCount(resObj);
goto error;
}
methods = 0;
while (listc > 0) {
if (Tcl_GetIndexFromObj(interp, listv[listc-1], methodNames,
"method", TCL_EXACT, &methIndex) != TCL_OK) {
TclPrintfResult(interp,
"chan handler \"%s initialize\" returned %s",
TclGetString(cmdObj), Tcl_GetStringResult(interp));
Tcl_DecrRefCount(resObj);
goto error;
}
methods |= FLAG(methIndex);
listc--;
}
Tcl_DecrRefCount(resObj);
if ((REQUIRED_METHODS & methods) != REQUIRED_METHODS) {
TclPrintfResult(interp,
"chan handler \"%s\" does not support all required methods",
TclGetString(cmdObj));
goto error;
}
/*
* Mode tell us what the parent channel supports. The methods tell us what
* the handler supports. We remove the non-supported bits from the mode
* and check that the channel is not completely inaccessible. Afterward the
* mode tells us which methods are still required, and these methods will
* also be supported by the handler, by design of the check.
*/
if (!HAS(methods, METH_READ)) {
mode &= ~TCL_READABLE;
}
if (!HAS(methods, METH_WRITE)) {
mode &= ~TCL_WRITABLE;
}
if (!mode) {
TclPrintfResult(interp,
"chan handler \"%s\" makes the channel inaccessible",
TclGetString(cmdObj));
goto error;
}
/*
* The mode and support for it is ok, now check the internal constraints.
*/
if (!IMPLIES(HAS(methods, METH_DRAIN), HAS(methods, METH_READ))) {
TclPrintfResult(interp,
"chan handler \"%s\" supports \"drain\" but not \"read\"",
TclGetString(cmdObj));
goto error;
}
if (!IMPLIES(HAS(methods, METH_FLUSH), HAS(methods, METH_WRITE))) {
TclPrintfResult(interp,
"chan handler \"%s\" supports \"flush\" but not \"write\"",
TclGetString(cmdObj));
goto error;
}
Tcl_ResetResult(interp);
/*
* Everything is fine now.
|
| ︙ | ︙ | |||
1999 2000 2001 2002 2003 2004 2005 |
if (result != TCL_ERROR) {
Tcl_Obj *cmd = Tcl_NewListObj(cmdc, rtPtr->argv);
Tcl_Size cmdLen;
const char *cmdString = TclGetStringFromObj(cmd, &cmdLen);
Tcl_IncrRefCount(cmd);
Tcl_ResetResult(rtPtr->interp);
| | | | | | 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 |
if (result != TCL_ERROR) {
Tcl_Obj *cmd = Tcl_NewListObj(cmdc, rtPtr->argv);
Tcl_Size cmdLen;
const char *cmdString = TclGetStringFromObj(cmd, &cmdLen);
Tcl_IncrRefCount(cmd);
Tcl_ResetResult(rtPtr->interp);
TclPrintfResult(rtPtr->interp,
"chan handler returned bad code: %d", result);
Tcl_LogCommandInfo(rtPtr->interp, cmdString, cmdString, cmdLen);
Tcl_DecrRefCount(cmd);
result = TCL_ERROR;
}
TclPrintfErrorInfo(rtPtr->interp,
"\n (chan handler subcommand \"%s\")", method);
resObj = MarshallError(rtPtr->interp);
}
Tcl_IncrRefCount(resObj);
}
Tcl_RestoreInterpState(rtPtr->interp, sr);
Tcl_Release(rtPtr->interp);
Tcl_Release(rtPtr);
|
| ︙ | ︙ |
Changes to generic/tclIOSock.c.
| ︙ | ︙ | |||
88 89 90 91 92 93 94 |
return TCL_OK;
}
}
if (Tcl_GetInt(interp, string, portPtr) != TCL_OK) {
return TCL_ERROR;
}
if (*portPtr > 0xFFFF) {
| < | | 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
return TCL_OK;
}
}
if (Tcl_GetInt(interp, string, portPtr) != TCL_OK) {
return TCL_ERROR;
}
if (*portPtr > 0xFFFF) {
TclPrintfResult(interp, "couldn't open socket: port number too high");
return TCL_ERROR;
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
|
| ︙ | ︙ |
Changes to generic/tclIOUtil.c.
| ︙ | ︙ | |||
1048 1049 1050 1051 1052 1053 1054 |
* generic code because otherwise every filesystem implementation of
* Tcl_FSMatchInDirectory has to do it.
*/
cwd = Tcl_FSGetCwd(NULL);
if (cwd == NULL) {
if (interp != NULL) {
| | | < | 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 |
* generic code because otherwise every filesystem implementation of
* Tcl_FSMatchInDirectory has to do it.
*/
cwd = Tcl_FSGetCwd(NULL);
if (cwd == NULL) {
if (interp != NULL) {
TclPrintfResult(interp,
"glob couldn't determine the current working directory");
}
return TCL_ERROR;
}
fsPtr = Tcl_FSGetFileSystemForPath(cwd);
if (fsPtr != NULL && fsPtr->matchInDirectoryProc != NULL) {
TclNewObj(tmpResultPtr);
|
| ︙ | ︙ | |||
1510 1511 1512 1513 1514 1515 1516 |
goto error;
}
return mode;
error:
*modeFlagsPtr = 0;
if (interp != NULL) {
| < | | | | | < | | | | | 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 |
goto error;
}
return mode;
error:
*modeFlagsPtr = 0;
if (interp != NULL) {
TclPrintfResult(interp, "illegal access mode \"%s\"", modeString);
TclSetErrorCode(interp, "TCL", "OPENMODE", "INVALID");
}
return -1;
}
/*
* The access modes are specified as a list of POSIX modes like O_CREAT.
*
* Tcl_SplitList must work correctly when interp is NULL.
*/
if (Tcl_SplitList(interp, modeString, &modeArgc, &modeArgv) != TCL_OK) {
invAccessMode:
if (interp != NULL) {
TclPrintfErrorInfo(interp,
"\n while processing open access modes \"%s\"",
modeString);
TclSetErrorCode(interp, "TCL", "OPENMODE", "INVALID");
}
if (modeArgv) {
Tcl_Free((void *)modeArgv);
}
return -1;
}
gotRW = 0;
for (i = 0; i < modeArgc; i++) {
flag = modeArgv[i];
c = flag[0];
if ((c == 'R') && (strcmp(flag, "RDONLY") == 0)) {
if (gotRW) {
invRW:
if (interp != NULL) {
TclPrintfResult(interp,
"invalid access mode \"%s\": modes RDONLY, "
"RDWR, and WRONLY cannot be combined", flag);
}
goto invAccessMode;
}
mode = (mode & ~O_ACCMODE) | O_RDONLY;
gotRW = 1;
} else if ((c == 'W') && (strcmp(flag, "WRONLY") == 0)) {
if (gotRW) {
|
| ︙ | ︙ | |||
1570 1571 1572 1573 1574 1575 1576 |
}
mode = (mode & ~O_ACCMODE) | O_RDWR;
gotRW = 1;
} else if ((c == 'A') && (strcmp(flag, "APPEND") == 0)) {
if (mode & O_APPEND) {
accessFlagRepeated:
if (interp) {
| < | | | | | | | | | | < | 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 |
}
mode = (mode & ~O_ACCMODE) | O_RDWR;
gotRW = 1;
} else if ((c == 'A') && (strcmp(flag, "APPEND") == 0)) {
if (mode & O_APPEND) {
accessFlagRepeated:
if (interp) {
TclPrintfResult(interp, "access mode \"%s\" repeated", flag);
}
goto invAccessMode;
}
mode |= O_APPEND;
*modeFlagsPtr |= 1;
} else if ((c == 'C') && (strcmp(flag, "CREAT") == 0)) {
if (mode & O_CREAT) {
goto accessFlagRepeated;
}
mode |= O_CREAT;
} else if ((c == 'E') && (strcmp(flag, "EXCL") == 0)) {
if (mode & O_EXCL) {
goto accessFlagRepeated;
}
mode |= O_EXCL;
} else if ((c == 'N') && (strcmp(flag, "NOCTTY") == 0)) {
#ifdef O_NOCTTY
if (mode & O_NOCTTY) {
goto accessFlagRepeated;
}
mode |= O_NOCTTY;
#else
if (interp != NULL) {
TclPrintfResult(interp,
"access mode \"%s\" not supported by this system",
flag);
}
goto invAccessMode;
#endif
} else if ((c == 'N') && (strcmp(flag, "NONBLOCK") == 0)) {
#ifdef O_NONBLOCK
if (mode & O_NONBLOCK) {
goto accessFlagRepeated;
}
mode |= O_NONBLOCK;
#else
if (interp != NULL) {
TclPrintfResult(interp,
"access mode \"%s\" not supported by this system",
flag);
}
goto invAccessMode;
#endif
} else if ((c == 'T') && (strcmp(flag, "TRUNC") == 0)) {
if (mode & O_TRUNC) {
goto accessFlagRepeated;
}
mode |= O_TRUNC;
} else if ((c == 'B') && (strcmp(flag, "BINARY") == 0)) {
if (*modeFlagsPtr & CHANNEL_RAW_MODE) {
goto accessFlagRepeated;
}
*modeFlagsPtr |= CHANNEL_RAW_MODE;
} else {
if (interp != NULL) {
TclPrintfResult(interp,
"invalid access mode \"%s\": must be APPEND, BINARY, "
"CREAT, EXCL, NOCTTY, NONBLOCK, RDONLY, RDWR, "
"TRUNC, or WRONLY", flag);
}
goto invAccessMode;
}
}
Tcl_Free((void *)modeArgv);
if (!gotRW) {
if (interp != NULL) {
TclPrintfResult(interp,
"access mode must include either RDONLY, RDWR, or WRONLY");
}
return -1;
}
return mode;
}
/*
|
| ︙ | ︙ | |||
1707 1708 1709 1710 1711 1712 1713 |
if (Tcl_FSGetNormalizedPath(interp, pathPtr) == NULL) {
return result;
}
if (Tcl_FSStat(pathPtr, &statBuf) == -1) {
Tcl_SetErrno(errno);
| | | | | | 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 |
if (Tcl_FSGetNormalizedPath(interp, pathPtr) == NULL) {
return result;
}
if (Tcl_FSStat(pathPtr, &statBuf) == -1) {
Tcl_SetErrno(errno);
TclPrintfResult(interp,
"couldn't read file \"%s\": %s",
TclGetString(pathPtr), Tcl_PosixError(interp));
return result;
}
chan = Tcl_FSOpenFileChannel(interp, pathPtr, "r", 0644);
if (chan == NULL) {
TclPrintfResult(interp,
"couldn't read file \"%s\": %s",
TclGetString(pathPtr), Tcl_PosixError(interp));
return result;
}
/*
* The eof character is \x1A (^Z). Tcl uses it on every platform to allow
* for scripted documents. [Bug: 2040]
*/
|
| ︙ | ︙ | |||
1750 1751 1752 1753 1754 1755 1756 |
/*
* Read first character of stream to check for utf-8 BOM
*/
if (Tcl_ReadChars(chan, objPtr, 1, 0) == TCL_IO_FAILURE) {
Tcl_CloseEx(interp, chan, 0);
| | | | | | 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 |
/*
* Read first character of stream to check for utf-8 BOM
*/
if (Tcl_ReadChars(chan, objPtr, 1, 0) == TCL_IO_FAILURE) {
Tcl_CloseEx(interp, chan, 0);
TclPrintfResult(interp,
"couldn't read file \"%s\": %s",
TclGetString(pathPtr), Tcl_PosixError(interp));
goto end;
}
string = TclGetString(objPtr);
/*
* If first character is not a BOM, append the remaining characters.
* Otherwise, replace them. [Bug 3466099]
*/
if (Tcl_ReadChars(chan, objPtr, TCL_INDEX_NONE,
memcmp(string, "\xEF\xBB\xBF", 3)) == TCL_IO_FAILURE) {
Tcl_CloseEx(interp, chan, 0);
TclPrintfResult(interp,
"couldn't read file \"%s\": %s",
TclGetString(pathPtr), Tcl_PosixError(interp));
goto end;
}
if (Tcl_CloseEx(interp, chan, 0) != TCL_OK) {
goto end;
}
|
| ︙ | ︙ | |||
1810 1811 1812 1813 1814 1815 1816 | * Record information about where the error occurred. */ const char *pathString = TclGetStringFromObj(pathPtr, &length); int limit = 150; int overflow = (length > limit); | < | | | 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 |
* Record information about where the error occurred.
*/
const char *pathString = TclGetStringFromObj(pathPtr, &length);
int limit = 150;
int overflow = (length > limit);
TclPrintfErrorInfo(interp, "\n (file \"%.*s%s\" line %d)",
(overflow ? limit : (int)length), pathString,
(overflow ? "..." : ""), Tcl_GetErrorLine(interp));
}
end:
Tcl_DecrRefCount(objPtr);
return result;
}
|
| ︙ | ︙ | |||
1842 1843 1844 1845 1846 1847 1848 |
if (Tcl_FSGetNormalizedPath(interp, pathPtr) == NULL) {
return TCL_ERROR;
}
if (Tcl_FSStat(pathPtr, &statBuf) == -1) {
Tcl_SetErrno(errno);
| | | | | | 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 |
if (Tcl_FSGetNormalizedPath(interp, pathPtr) == NULL) {
return TCL_ERROR;
}
if (Tcl_FSStat(pathPtr, &statBuf) == -1) {
Tcl_SetErrno(errno);
TclPrintfResult(interp,
"couldn't read file \"%s\": %s",
TclGetString(pathPtr), Tcl_PosixError(interp));
return TCL_ERROR;
}
chan = Tcl_FSOpenFileChannel(interp, pathPtr, "r", 0644);
if (chan == NULL) {
TclPrintfResult(interp,
"couldn't read file \"%s\": %s",
TclGetString(pathPtr), Tcl_PosixError(interp));
return TCL_ERROR;
}
TclPkgFileSeen(interp, TclGetString(pathPtr));
/*
* The eof character is \x1A (^Z). Tcl uses it on every platform to allow
* for scripted documents. [Bug: 2040]
|
| ︙ | ︙ | |||
1886 1887 1888 1889 1890 1891 1892 |
/*
* Read first character of stream to check for utf-8 BOM
*/
if (Tcl_ReadChars(chan, objPtr, 1, 0) == TCL_IO_FAILURE) {
Tcl_CloseEx(interp, chan, 0);
| | | | | | < | 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 |
/*
* Read first character of stream to check for utf-8 BOM
*/
if (Tcl_ReadChars(chan, objPtr, 1, 0) == TCL_IO_FAILURE) {
Tcl_CloseEx(interp, chan, 0);
TclPrintfResult(interp,
"couldn't read file \"%s\": %s",
TclGetString(pathPtr), Tcl_PosixError(interp));
Tcl_DecrRefCount(objPtr);
return TCL_ERROR;
}
string = TclGetString(objPtr);
/*
* If first character is not a BOM, append the remaining characters.
* Otherwise, replace them. [Bug 3466099]
*/
if (Tcl_ReadChars(chan, objPtr, TCL_INDEX_NONE,
memcmp(string, "\xEF\xBB\xBF", 3)) == TCL_IO_FAILURE) {
Tcl_CloseEx(interp, chan, 0);
TclPrintfResult(interp,
"couldn't read file \"%s\": %s",
TclGetString(pathPtr), Tcl_PosixError(interp));
Tcl_DecrRefCount(objPtr);
return TCL_ERROR;
}
if (Tcl_CloseEx(interp, chan, 0) != TCL_OK) {
Tcl_DecrRefCount(objPtr);
return TCL_ERROR;
}
iPtr = (Interp *) interp;
oldScriptFile = iPtr->scriptFile;
iPtr->scriptFile = pathPtr;
Tcl_IncrRefCount(iPtr->scriptFile);
/*
* TIP #280: Open a frame for the evaluated script.
*/
iPtr->evalFlags |= TCL_EVAL_FILE;
TclNRAddCallback(interp, EvalFileCallback, oldScriptFile, pathPtr, objPtr);
return TclNREvalObjEx(interp, objPtr, 0, NULL, INT_MIN);
}
static int
EvalFileCallback(
void *data[],
Tcl_Interp *interp,
|
| ︙ | ︙ | |||
1963 1964 1965 1966 1967 1968 1969 | */ Tcl_Size length; const char *pathString = TclGetStringFromObj(pathPtr, &length); const int limit = 150; int overflow = (length > limit); | < | | | 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 |
*/
Tcl_Size length;
const char *pathString = TclGetStringFromObj(pathPtr, &length);
const int limit = 150;
int overflow = (length > limit);
TclPrintfErrorInfo(interp, "\n (file \"%.*s%s\" line %d)",
(overflow ? limit : (int)length), pathString,
(overflow ? "..." : ""), Tcl_GetErrorLine(interp));
}
Tcl_DecrRefCount(objPtr);
return result;
}
/*
|
| ︙ | ︙ | |||
2058 2059 2060 2061 2062 2063 2064 |
Tcl_Interp *interp) /* Interpreter to set the errorCode of */
{
const char *id, *msg;
msg = Tcl_ErrnoMsg(errno);
id = Tcl_ErrnoId();
if (interp) {
| | | 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 |
Tcl_Interp *interp) /* Interpreter to set the errorCode of */
{
const char *id, *msg;
msg = Tcl_ErrnoMsg(errno);
id = Tcl_ErrnoId();
if (interp) {
TclSetErrorCode(interp, "POSIX", id, msg);
}
return msg;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
2228 2229 2230 2231 2232 2233 2234 |
/*
* Seek and/or set binary mode as determined above.
*/
if ((modeFlags & 1) && Tcl_Seek(retVal, (Tcl_WideInt) 0, SEEK_END)
< (Tcl_WideInt) 0) {
if (interp != NULL) {
| | | | | | 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 |
/*
* Seek and/or set binary mode as determined above.
*/
if ((modeFlags & 1) && Tcl_Seek(retVal, (Tcl_WideInt) 0, SEEK_END)
< (Tcl_WideInt) 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"could not seek to end of file while opening \"%s\": %s",
TclGetString(pathPtr), Tcl_PosixError(interp));
}
Tcl_CloseEx(NULL, retVal, 0);
return NULL;
}
if (modeFlags & CHANNEL_RAW_MODE) {
Tcl_SetChannelOption(interp, retVal, "-translation", "binary");
}
return retVal;
}
/*
* File doesn't belong to any filesystem that can open it.
*/
Tcl_SetErrno(ENOENT);
if (interp != NULL) {
TclPrintfResult(interp,
"couldn't open \"%s\": %s",
TclGetString(pathPtr), Tcl_PosixError(interp));
}
return NULL;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
2672 2673 2674 2675 2676 2677 2678 |
fsRecPtr->fsPtr->freeInternalRepProc(retCd);
}
Tcl_DecrRefCount(retVal);
retVal = NULL;
Disclaim();
goto cdDidNotChange;
} else if (interp != NULL) {
| | | | 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 |
fsRecPtr->fsPtr->freeInternalRepProc(retCd);
}
Tcl_DecrRefCount(retVal);
retVal = NULL;
Disclaim();
goto cdDidNotChange;
} else if (interp != NULL) {
TclPrintfResult(interp,
"error getting working directory name: %s",
Tcl_PosixError(interp));
}
}
Disclaim();
if (retVal != NULL) {
/*
* On some platforms the pathname of the current directory might
|
| ︙ | ︙ | |||
2747 2748 2749 2750 2751 2752 2753 |
* New API.
*/
TclFSGetCwdProc2 *proc2 = (TclFSGetCwdProc2 *) fsPtr->getCwdProc;
retCd = proc2(tsdPtr->cwdClientData);
if (retCd == NULL && interp != NULL) {
| | | | 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 |
* New API.
*/
TclFSGetCwdProc2 *proc2 = (TclFSGetCwdProc2 *) fsPtr->getCwdProc;
retCd = proc2(tsdPtr->cwdClientData);
if (retCd == NULL && interp != NULL) {
TclPrintfResult(interp,
"error getting working directory name: %s",
Tcl_PosixError(interp));
}
if (retCd == tsdPtr->cwdClientData) {
goto cdDidNotChange;
}
/*
|
| ︙ | ︙ | |||
3211 3212 3213 3214 3215 3216 3217 |
/*
* Make sure the file is accessible.
*/
if (Tcl_FSAccess(pathPtr, R_OK) != 0) {
if (interp) {
| | | | 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 |
/*
* Make sure the file is accessible.
*/
if (Tcl_FSAccess(pathPtr, R_OK) != 0) {
if (interp) {
TclPrintfResult(interp,
"couldn't load library \"%s\": %s",
TclGetString(pathPtr), Tcl_PosixError(interp));
}
return TCL_ERROR;
}
#ifdef TCL_LOAD_FROM_MEMORY
/*
* The platform supports loading a dynamic shared object from memory.
|
| ︙ | ︙ | |||
3287 3288 3289 3290 3291 3292 3293 |
/*
* Try to delete the file we probably created and then exit.
*/
Tcl_FSDeleteFile(copyToPtr);
Tcl_DecrRefCount(copyToPtr);
if (interp) {
| < | | 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 |
/*
* Try to delete the file we probably created and then exit.
*/
Tcl_FSDeleteFile(copyToPtr);
Tcl_DecrRefCount(copyToPtr);
if (interp) {
TclPrintfResult(interp, "couldn't load from current filesystem");
}
return TCL_ERROR;
}
if (TclCrossFilesystemCopy(interp, pathPtr, copyToPtr) != TCL_OK) {
Tcl_FSDeleteFile(copyToPtr);
Tcl_DecrRefCount(copyToPtr);
|
| ︙ | ︙ | |||
3588 3589 3590 3591 3592 3593 3594 |
int
Tcl_FSUnloadFile(
Tcl_Interp *interp, /* The relevant interpreter. */
Tcl_LoadHandle handle) /* A handle for the object to unload. */
{
if (handle->unloadFileProcPtr == NULL) {
if (interp != NULL) {
| | | < | 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 |
int
Tcl_FSUnloadFile(
Tcl_Interp *interp, /* The relevant interpreter. */
Tcl_LoadHandle handle) /* A handle for the object to unload. */
{
if (handle->unloadFileProcPtr == NULL) {
if (interp != NULL) {
TclPrintfResult(interp,
"cannot unload: filesystem does not support unloading");
}
return TCL_ERROR;
}
if (handle->unloadFileProcPtr != NULL) {
handle->unloadFileProcPtr(handle);
}
return TCL_OK;
|
| ︙ | ︙ |
Changes to generic/tclIcu.c.
| ︙ | ︙ | |||
290 291 292 293 294 295 296 |
/* Error handlers. */
static int
FunctionNotAvailableError(
Tcl_Interp *interp)
{
if (interp) {
| < | | | | | | 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
/* Error handlers. */
static int
FunctionNotAvailableError(
Tcl_Interp *interp)
{
if (interp) {
TclPrintfResult(interp, "ICU function not available");
TclSetErrorCode(interp, "TCL", "ICU", "UNSUPPORTED_OP");
}
return TCL_ERROR;
}
static int
IcuError(
Tcl_Interp *interp,
const char *message,
UErrorCodex code)
{
if (interp) {
const char *codeMessage = NULL;
if (u_errorName) {
codeMessage = u_errorName(code);
}
TclPrintfResult(interp,
"%s%sICU error (%d): %s",
message ? message : "",
message ? ". " : "",
code,
codeMessage ? codeMessage : "");
TclSetErrorCode(interp, "TCL", "ICU", codeMessage);
}
return TCL_ERROR;
}
/*
* Detect the likely encoding of the string encoded in the given byte array.
*/
|
| ︙ | ︙ | |||
599 600 601 602 603 604 605 |
if (objc == 1) {
return DetectableEncodings(interp);
}
int all = 0;
if (objc == 3) {
if (strcmp("-all", Tcl_GetString(objv[2]))) {
| | | | 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
if (objc == 1) {
return DetectableEncodings(interp);
}
int all = 0;
if (objc == 3) {
if (strcmp("-all", Tcl_GetString(objv[2]))) {
TclPrintfResult(interp,
"Invalid option %s, must be \"-all\"",
Tcl_GetString(objv[2]));
return TCL_ERROR;
}
all = 1;
}
return DetectEncoding(interp, objv[1], all);
}
|
| ︙ | ︙ | |||
767 768 769 770 771 772 773 |
}
}
UCharx *utf16 = (UCharx *) Tcl_DStringValue(dsInPtr);
Tcl_Size utf16len = Tcl_DStringLength(dsInPtr) / sizeof(UCharx);
Tcl_Size dstLen, dstCapacity;
if (utf16len > INT_MAX) {
| < | | 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 |
}
}
UCharx *utf16 = (UCharx *) Tcl_DStringValue(dsInPtr);
Tcl_Size utf16len = Tcl_DStringLength(dsInPtr) / sizeof(UCharx);
Tcl_Size dstLen, dstCapacity;
if (utf16len > INT_MAX) {
TclPrintfResult(interp, "Max length supported by ICU exceeded.");
return TCL_ERROR;
}
dstCapacity = utf16len;
Tcl_DStringInit(dsOutPtr);
Tcl_DStringSetLength(dsOutPtr, dstCapacity);
dstLen = ucnv_fromUChars(ucnvPtr, Tcl_DStringValue(dsOutPtr), dstCapacity,
|
| ︙ | ︙ | |||
831 832 833 834 835 836 837 |
{
if (ucnv_open == NULL || ucnv_close == NULL ||
ucnv_toUChars == NULL || UCNV_TO_U_CALLBACK_STOP == NULL) {
return FunctionNotAvailableError(interp);
}
if (nbytes > INT_MAX) {
| < | | 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 |
{
if (ucnv_open == NULL || ucnv_close == NULL ||
ucnv_toUChars == NULL || UCNV_TO_U_CALLBACK_STOP == NULL) {
return FunctionNotAvailableError(interp);
}
if (nbytes > INT_MAX) {
TclPrintfResult(interp, "Max length supported by ICU exceeded.");
return TCL_ERROR;
}
UErrorCodex status = U_ZERO_ERRORZ;
UConverter *ucnvPtr = ucnv_open(icuEncName, &status);
if (ucnvPtr == NULL) {
return IcuError(interp, "Could not get encoding converter", status);
|
| ︙ | ︙ | |||
940 941 942 943 944 945 946 |
Tcl_Size utf16len;
UCharx *normPtr;
int32_t normLen;
utf16 = (UCharx *) Tcl_DStringValue(dsInPtr);
utf16len = Tcl_DStringLength(dsInPtr) / sizeof(UCharx);
if (utf16len > INT_MAX) {
| < | | 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 |
Tcl_Size utf16len;
UCharx *normPtr;
int32_t normLen;
utf16 = (UCharx *) Tcl_DStringValue(dsInPtr);
utf16len = Tcl_DStringLength(dsInPtr) / sizeof(UCharx);
if (utf16len > INT_MAX) {
TclPrintfResult(interp, "Max length supported by ICU exceeded.");
return TCL_ERROR;
}
Tcl_DStringInit(dsOutPtr);
Tcl_DStringSetLength(dsOutPtr, utf16len * sizeof(UCharx));
normPtr = (UCharx *) Tcl_DStringValue(dsOutPtr);
normLen = unorm2_normalize(
|
| ︙ | ︙ | |||
1005 1006 1007 1008 1009 1010 1011 |
for (i = 1; i < objc; ++i) {
if (Tcl_GetIndexFromObj(
interp, objv[i], optNames, "option", 0, &opt) != TCL_OK) {
return TCL_ERROR;
}
++i;
if (i == objc) {
| < | | < | | | | < | | 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 |
for (i = 1; i < objc; ++i) {
if (Tcl_GetIndexFromObj(
interp, objv[i], optNames, "option", 0, &opt) != TCL_OK) {
return TCL_ERROR;
}
++i;
if (i == objc) {
TclPrintfResult(interp, "Missing value for option %s.",
Tcl_GetString(objv[i - 1]));
return TCL_ERROR;
}
const char *s = Tcl_GetString(objv[i]);
switch (opt) {
case OPT_PROFILE:
if (!strcmp(s, "replace")) {
strict = 0;
} else if (strcmp(s, "strict")) {
TclPrintfResult(interp,
"Invalid value \"%s\" supplied for option"
" \"-profile\". Must be \"strict\" or \"replace\".",
s);
return TCL_ERROR;
}
break;
case OPT_FAILINDEX:
/* TBD */
TclPrintfResult(interp, "Option -failindex not implemented.");
return TCL_ERROR;
}
}
*strictPtr = strict;
*failindexVarPtr = NULL;
return TCL_OK;
}
|
| ︙ | ︙ | |||
1174 1175 1176 1177 1178 1179 1180 |
for (i = 1; i < objc - 1; ++i) {
if (Tcl_GetIndexFromObj(
interp, objv[i], optNames, "option", 0, &opt) != TCL_OK) {
return TCL_ERROR;
}
++i;
if (i == (objc-1)) {
| < | | < | | | | | > | 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 |
for (i = 1; i < objc - 1; ++i) {
if (Tcl_GetIndexFromObj(
interp, objv[i], optNames, "option", 0, &opt) != TCL_OK) {
return TCL_ERROR;
}
++i;
if (i == (objc-1)) {
TclPrintfResult(interp, "Missing value for option %s.",
Tcl_GetString(objv[i - 1]));
return TCL_ERROR;
}
const char *s = Tcl_GetString(objv[i]);
switch (opt) {
case OPT_PROFILE:
if (!strcmp(s, "replace")) {
strict = 0;
} else if (strcmp(s, "strict")) {
TclPrintfResult(interp,
"Invalid value \"%s\" supplied for option \"-profile\"."
" Must be \"strict\" or \"replace\".",
s);
return TCL_ERROR;
}
break;
case OPT_MODE:
if (Tcl_GetIndexFromObj(interp, objv[i], normalizationForms,
"normalization mode", 0, &mode) != TCL_OK) {
return TCL_ERROR;
}
break;
}
}
Tcl_DString dsIn;
|
| ︙ | ︙ | |||
1399 1400 1401 1402 1403 1404 1405 |
* On Windows, if no ICU install found, look for the system's
* (Win10 1703 or later). There are two cases. Newer systems
* have icu.dll containing all functions. Older systems have
* icucc.dll and icuin.dll
*/
if (icu_fns.libs[0] == NULL) {
Tcl_ResetResult(interp);
| | | | | 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 |
* On Windows, if no ICU install found, look for the system's
* (Win10 1703 or later). There are two cases. Newer systems
* have icu.dll containing all functions. Older systems have
* icucc.dll and icuin.dll
*/
if (icu_fns.libs[0] == NULL) {
Tcl_ResetResult(interp);
nameobj = TclNewString("icu.dll");
Tcl_IncrRefCount(nameobj);
if (Tcl_LoadFile(interp, nameobj, NULL, 0, NULL, &icu_fns.libs[0])
== TCL_OK) {
/* Reload same for second set of functions. */
(void) Tcl_LoadFile(interp, nameobj, NULL, 0, NULL,
&icu_fns.libs[1]);
/* Functions do NOT have version suffixes */
icuversion[0] = '\0';
}
Tcl_DecrRefCount(nameobj);
}
if (icu_fns.libs[0] == NULL) {
/* No icu.dll. Try last fallback */
Tcl_ResetResult(interp);
nameobj = TclNewString("icuuc.dll");
Tcl_IncrRefCount(nameobj);
if (Tcl_LoadFile(interp, nameobj, NULL, 0, NULL, &icu_fns.libs[0])
== TCL_OK) {
Tcl_DecrRefCount(nameobj);
nameobj = TclNewString("icuin.dll");
Tcl_IncrRefCount(nameobj);
(void) Tcl_LoadFile(interp, nameobj, NULL, 0, NULL,
&icu_fns.libs[1]);
/* Functions do NOT have version suffixes */
icuversion[0] = '\0';
}
Tcl_DecrRefCount(nameobj);
|
| ︙ | ︙ |
Changes to generic/tclIndexObj.c.
| ︙ | ︙ | |||
199 200 201 202 203 204 205 |
const char *const *entryPtr;
Tcl_Obj *resultPtr;
IndexRep *indexRep;
const Tcl_ObjInternalRep *irPtr;
if (offset < (Tcl_Size)sizeof(char *)) {
if (interp) {
| | | | 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
const char *const *entryPtr;
Tcl_Obj *resultPtr;
IndexRep *indexRep;
const Tcl_ObjInternalRep *irPtr;
if (offset < (Tcl_Size)sizeof(char *)) {
if (interp) {
TclPrintfResult(interp,
"Invalid %s value %" TCL_SIZE_MODIFIER "d.",
"struct offset", offset);
}
return TCL_ERROR;
}
/*
* See if there is a valid cached result from a previous lookup.
*/
|
| ︙ | ︙ | |||
329 330 331 332 333 334 335 |
int count = 0;
TclNewObj(resultPtr);
entryPtr = (const char *const *)tablePtr;
while ((*entryPtr != NULL) && !**entryPtr) {
entryPtr = NEXT_ENTRY(entryPtr, offset);
}
| | | | | < | | | | | | 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
int count = 0;
TclNewObj(resultPtr);
entryPtr = (const char *const *)tablePtr;
while ((*entryPtr != NULL) && !**entryPtr) {
entryPtr = NEXT_ENTRY(entryPtr, offset);
}
TclAppendStringsToObj(resultPtr,
(numAbbrev>1 && !(flags & TCL_EXACT) ? "ambiguous " : "bad "),
msg, " \"", key);
if (*entryPtr == NULL) {
TclAppendStringsToObj(resultPtr, "\": no valid options");
} else {
TclAppendStringsToObj(resultPtr, "\": must be ", *entryPtr);
entryPtr = NEXT_ENTRY(entryPtr, offset);
while (*entryPtr != NULL) {
if ((*NEXT_ENTRY(entryPtr, offset) == NULL) && !(flags & TCL_NULL_OK)) {
TclAppendStringsToObj(resultPtr, (count > 0 ? "," : ""),
" or ", *entryPtr);
} else if (**entryPtr) {
TclAppendStringsToObj(resultPtr, ", ", *entryPtr);
count++;
}
entryPtr = NEXT_ENTRY(entryPtr, offset);
}
if ((flags & TCL_NULL_OK)) {
TclAppendStringsToObj(resultPtr, ", or \"\"");
}
}
Tcl_SetObjResult(interp, resultPtr);
TclSetErrorCode(interp, "TCL", "LOOKUP", "INDEX", msg, key);
}
return TCL_ERROR;
}
/* #define again, needed below */
#define Tcl_GetIndexFromObjStruct(interp, objPtr, tablePtr, offset, msg, flags, indexPtr) \
((Tcl_GetIndexFromObjStruct)((interp), (objPtr), (tablePtr), (offset), (msg), (flags)|(int)(sizeof(*(indexPtr))<<1), (indexPtr)))
|
| ︙ | ︙ | |||
532 533 534 535 536 537 538 |
}
switch (index) {
case PRFMATCH_EXACT:
flags |= TCL_EXACT;
break;
case PRFMATCH_MESSAGE:
if (i > objc-4) {
| < | | < | | | | < | | 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
}
switch (index) {
case PRFMATCH_EXACT:
flags |= TCL_EXACT;
break;
case PRFMATCH_MESSAGE:
if (i > objc-4) {
TclPrintfResult(interp, "missing value for -message");
TclSetErrorCode(interp, "TCL", "OPERATION", "NOARG");
return TCL_ERROR;
}
i++;
message = TclGetString(objv[i]);
break;
case PRFMATCH_ERROR:
if (i > objc-4) {
TclPrintfResult(interp, "missing value for -error");
TclSetErrorCode(interp, "TCL", "OPERATION", "NOARG");
return TCL_ERROR;
}
i++;
result = TclListObjLength(interp, objv[i], &errorLength);
if (result != TCL_OK) {
return TCL_ERROR;
}
if ((errorLength % 2) != 0) {
TclPrintfResult(interp,
"error options must have an even number of elements");
TclSetErrorCode(interp, "TCL", "VALUE", "DICTIONARY");
return TCL_ERROR;
}
errorPtr = objv[i];
break;
}
}
|
| ︙ | ︙ | |||
590 591 592 593 594 595 596 |
} else if (errorPtr == NULL) {
return TCL_ERROR;
}
if (Tcl_IsShared(errorPtr)) {
errorPtr = Tcl_DuplicateObj(errorPtr);
}
| | < | 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 |
} else if (errorPtr == NULL) {
return TCL_ERROR;
}
if (Tcl_IsShared(errorPtr)) {
errorPtr = Tcl_DuplicateObj(errorPtr);
}
Tcl_ListObjAppendElement(interp, errorPtr, TclNewString("-code"));
Tcl_ListObjAppendElement(interp, errorPtr, Tcl_NewWideIntObj(result));
return Tcl_SetReturnOptions(interp, errorPtr);
}
result = Tcl_ListObjIndex(interp, tablePtr, i, &resultPtr);
if (result != TCL_OK) {
|
| ︙ | ︙ | |||
819 820 821 822 823 824 825 |
Interp *iPtr = (Interp *)interp;
const char *elementStr;
TclNewObj(objPtr);
if (iPtr->flags & INTERP_ALTERNATE_WRONG_ARGS) {
iPtr->flags &= ~INTERP_ALTERNATE_WRONG_ARGS;
Tcl_AppendObjToObj(objPtr, Tcl_GetObjResult(interp));
| | | | 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 |
Interp *iPtr = (Interp *)interp;
const char *elementStr;
TclNewObj(objPtr);
if (iPtr->flags & INTERP_ALTERNATE_WRONG_ARGS) {
iPtr->flags &= ~INTERP_ALTERNATE_WRONG_ARGS;
Tcl_AppendObjToObj(objPtr, Tcl_GetObjResult(interp));
TclAppendLiteralToObj(objPtr, " or \"");
} else {
TclAppendLiteralToObj(objPtr, "wrong # args: should be \"");
}
/*
* If processing an ensemble implementation, rewrite the results in
* terms of how the ensemble was invoked.
*/
|
| ︙ | ︙ | |||
890 891 892 893 894 895 896 |
/*
* Add a space if the word is not the last one (which has a
* moderately complex condition here).
*/
if (i + 1 < toPrint || objc!=0 || message!=NULL) {
| | | 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 |
/*
* Add a space if the word is not the last one (which has a
* moderately complex condition here).
*/
if (i + 1 < toPrint || objc!=0 || message!=NULL) {
TclAppendLiteralToObj(objPtr, " ");
}
}
}
/*
* Now add the arguments (other than those rewritten) that the caller took
* from its calling context.
|
| ︙ | ︙ | |||
912 913 914 915 916 917 918 |
* Otherwise, just use the string rep.
*/
const Tcl_ObjInternalRep *irPtr;
if ((irPtr = TclFetchInternalRep(objv[i], &tclIndexType))) {
IndexRep *indexRep = (IndexRep *)irPtr->twoPtrValue.ptr1;
| | | 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 |
* Otherwise, just use the string rep.
*/
const Tcl_ObjInternalRep *irPtr;
if ((irPtr = TclFetchInternalRep(objv[i], &tclIndexType))) {
IndexRep *indexRep = (IndexRep *)irPtr->twoPtrValue.ptr1;
TclAppendStringsToObj(objPtr, EXPAND_OF(indexRep));
} else {
/*
* Quote the argument if it contains spaces (Bug 942757).
*/
elementStr = TclGetStringFromObj(objv[i], &elemLen);
flags = 0;
|
| ︙ | ︙ | |||
940 941 942 943 944 945 946 |
/*
* Append a space character (" ") if there is more text to follow
* (either another element from objv, or the message string).
*/
if (i + 1 < objc || message!=NULL) {
| | | | | | 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 |
/*
* Append a space character (" ") if there is more text to follow
* (either another element from objv, or the message string).
*/
if (i + 1 < objc || message!=NULL) {
TclAppendLiteralToObj(objPtr, " ");
}
}
/*
* Add any trailing message bits and set the resulting string as the
* interpreter result. Caller is responsible for reporting this as an
* actual error.
*/
if (message != NULL) {
Tcl_AppendToObj(objPtr, message, TCL_AUTO_LENGTH);
}
TclAppendLiteralToObj(objPtr, "\"");
TclSetErrorCode(interp, "TCL", "WRONGARGS");
Tcl_SetObjResult(interp, objPtr);
}
/*
*----------------------------------------------------------------------
*
* Tcl_ParseArgsObjv --
|
| ︙ | ︙ | |||
1072 1073 1074 1075 1076 1077 1078 |
continue;
}
if (infoPtr->keyStr[length] == 0) {
matchPtr = infoPtr;
goto gotMatch;
}
if (matchPtr != NULL) {
| < | < | | 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 |
continue;
}
if (infoPtr->keyStr[length] == 0) {
matchPtr = infoPtr;
goto gotMatch;
}
if (matchPtr != NULL) {
TclPrintfResult(interp, "ambiguous option \"%s\"", str);
goto error;
}
matchPtr = infoPtr;
}
if (matchPtr == NULL) {
/*
* Unrecognized argument. Just copy it down, unless the caller
* prefers an error to be registered.
*/
if (remObjv == NULL) {
TclPrintfResult(interp, "unrecognized argument \"%s\"", str);
goto error;
}
dstIndex++; /* This argument is now handled */
leftovers[nrem++] = curArg;
continue;
}
|
| ︙ | ︙ | |||
1111 1112 1113 1114 1115 1116 1117 |
break;
case TCL_ARGV_INT:
if (objc == 0) {
goto missingArg;
}
if (Tcl_GetIntFromObj(interp, objv[srcIndex],
(int *) infoPtr->dstPtr) == TCL_ERROR) {
| | | | 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 |
break;
case TCL_ARGV_INT:
if (objc == 0) {
goto missingArg;
}
if (Tcl_GetIntFromObj(interp, objv[srcIndex],
(int *) infoPtr->dstPtr) == TCL_ERROR) {
TclPrintfResult(interp,
"expected integer argument for \"%s\" but got \"%s\"",
infoPtr->keyStr, TclGetString(objv[srcIndex]));
goto error;
}
srcIndex++;
objc--;
break;
case TCL_ARGV_STRING:
if (objc == 0) {
|
| ︙ | ︙ | |||
1144 1145 1146 1147 1148 1149 1150 |
goto argsDone;
case TCL_ARGV_FLOAT:
if (objc == 0) {
goto missingArg;
}
if (Tcl_GetDoubleFromObj(interp, objv[srcIndex],
(double *) infoPtr->dstPtr) == TCL_ERROR) {
| | | | 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 |
goto argsDone;
case TCL_ARGV_FLOAT:
if (objc == 0) {
goto missingArg;
}
if (Tcl_GetDoubleFromObj(interp, objv[srcIndex],
(double *) infoPtr->dstPtr) == TCL_ERROR) {
TclPrintfResult(interp,
"expected floating-point argument for \"%s\" but got \"%s\"",
infoPtr->keyStr, TclGetString(objv[srcIndex]));
goto error;
}
srcIndex++;
objc--;
break;
case TCL_ARGV_FUNC: {
Tcl_ArgvFuncProc *handlerProc = (Tcl_ArgvFuncProc *)
|
| ︙ | ︙ | |||
1169 1170 1171 1172 1173 1174 1175 |
if (handlerProc(infoPtr->clientData, argObj, infoPtr->dstPtr)) {
srcIndex++;
objc--;
}
break;
}
case TCL_ARGV_GENFUNC: {
| < | | > | | | 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 |
if (handlerProc(infoPtr->clientData, argObj, infoPtr->dstPtr)) {
srcIndex++;
objc--;
}
break;
}
case TCL_ARGV_GENFUNC: {
if (objc > INT_MAX) {
TclPrintfResult(interp,
"too many (%" TCL_SIZE_MODIFIER "d) arguments for TCL_ARGV_GENFUNC",
objc);
goto error;
}
Tcl_ArgvGenFuncProc *handlerProc = (Tcl_ArgvGenFuncProc *)
infoPtr->srcPtr;
gf_ret = handlerProc(infoPtr->clientData, interp, objc,
&objv[srcIndex], infoPtr->dstPtr);
if (gf_ret < 0) {
goto error;
} else {
srcIndex += gf_ret;
objc -= gf_ret;
}
break;
}
case TCL_ARGV_HELP:
PrintUsage(interp, argTable);
goto error;
default:
TclPrintfResult(interp,
"bad argument type %d in Tcl_ArgvInfo", infoPtr->type);
goto error;
}
}
/*
* If we broke out of the loop because of an OPT_REST argument, copy the
* remaining arguments down. Note that there is always at least one
|
| ︙ | ︙ | |||
1229 1230 1231 1232 1233 1234 1235 |
/*
* Make sure to handle freeing any temporary space we've allocated on the
* way to an error.
*/
missingArg:
| | | | 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 |
/*
* Make sure to handle freeing any temporary space we've allocated on the
* way to an error.
*/
missingArg:
TclPrintfResult(interp,
"\"%s\" option requires an additional argument", str);
error:
if (leftovers != NULL) {
Tcl_Free(leftovers);
}
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
1291 1292 1293 1294 1295 1296 1297 |
}
}
/*
* Now add the option information, with pretty-printing.
*/
| | | | 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 |
}
}
/*
* Now add the option information, with pretty-printing.
*/
msg = TclNewString("Command-specific options:");
for (infoPtr = argTable; infoPtr->type != TCL_ARGV_END; infoPtr++) {
if ((infoPtr->type == TCL_ARGV_HELP) && (infoPtr->keyStr == NULL)) {
Tcl_AppendPrintfToObj(msg, "\n%s", infoPtr->helpStr);
continue;
}
Tcl_AppendPrintfToObj(msg, "\n %s:", infoPtr->keyStr);
numSpaces = width + 1 - strlen(infoPtr->keyStr);
while (numSpaces > 0) {
if (numSpaces >= NUM_SPACES) {
Tcl_AppendToObj(msg, spaces, NUM_SPACES);
} else {
Tcl_AppendToObj(msg, spaces, numSpaces);
}
numSpaces -= NUM_SPACES;
}
Tcl_AppendToObj(msg, infoPtr->helpStr, TCL_AUTO_LENGTH);
switch (infoPtr->type) {
case TCL_ARGV_INT:
Tcl_AppendPrintfToObj(msg, "\n\t\tDefault value: %d",
*((int *) infoPtr->dstPtr));
break;
case TCL_ARGV_FLOAT:
Tcl_AppendPrintfToObj(msg, "\n\t\tDefault value: %g",
|
| ︙ | ︙ | |||
1375 1376 1377 1378 1379 1380 1381 |
}
/*
* Value is not a legal completion code.
*/
if (interp != NULL) {
| | | | | 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 |
}
/*
* Value is not a legal completion code.
*/
if (interp != NULL) {
TclPrintfResult(interp,
"bad completion code \"%s\": must be"
" ok, error, return, break, continue, or an integer",
TclGetString(value));
TclSetErrorCode(interp, "TCL", "RESULT", "ILLEGAL_CODE");
}
return TCL_ERROR;
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 4
* fill-column: 78
* End:
*/
|
Changes to generic/tclInt.h.
| ︙ | ︙ | |||
4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 |
*/
#define TclDStringAppendLiteral(dsPtr, sLiteral) \
Tcl_DStringAppend((dsPtr), (sLiteral), sizeof(sLiteral "") - 1)
#define TclDStringClear(dsPtr) \
Tcl_DStringSetLength((dsPtr), 0)
/*
*----------------------------------------------------------------
* Inline version of Tcl_GetCurrentNamespace and Tcl_GetGlobalNamespace.
*/
#define TclGetCurrentNamespace(interp) \
(Tcl_Namespace *) ((Interp *)(interp))->varFramePtr->nsPtr
| > > > > > > > > > > > > > > | 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 |
*/
#define TclDStringAppendLiteral(dsPtr, sLiteral) \
Tcl_DStringAppend((dsPtr), (sLiteral), sizeof(sLiteral "") - 1)
#define TclDStringClear(dsPtr) \
Tcl_DStringSetLength((dsPtr), 0)
/*
*----------------------------------------------------------------
* Convenience macro for Tcl_AppendToObj and Tcl_NewStringObj.
* The ANSI C "prototypes" for these macros are:
*
* MODULE_SCOPE void TclAppendLiteralToObj(Tcl_DString *dsPtr,
* const char *sLiteral);
* MODULE_SCOPE Tcl_Obj * TclNewString(const char *sLiteral);
*/
#define TclAppendLiteralToObj(objPtr, sLiteral) \
Tcl_AppendToObj((objPtr), (sLiteral), sizeof(sLiteral "") - 1)
#define TclNewString(sLiteral) \
Tcl_NewStringObj((sLiteral), sizeof(sLiteral "") - 1)
/*
*----------------------------------------------------------------
* Inline version of Tcl_GetCurrentNamespace and Tcl_GetGlobalNamespace.
*/
#define TclGetCurrentNamespace(interp) \
(Tcl_Namespace *) ((Interp *)(interp))->varFramePtr->nsPtr
|
| ︙ | ︙ | |||
5068 5069 5070 5071 5072 5073 5074 |
#define TOP_CB(iPtr) \
(((Interp *)(iPtr))->execEnvPtr->callbackPtr)
/*
* Inline version of Tcl_NRAddCallback.
*/
| | > > > > > > > > > > > > > > > > > > > > > > > > > > > | 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 |
#define TOP_CB(iPtr) \
(((Interp *)(iPtr))->execEnvPtr->callbackPtr)
/*
* Inline version of Tcl_NRAddCallback.
*/
#define TclNRAddCallback(interp, postProcPtr, ...) \
TclNRAddCallback_(interp, postProcPtr __VA_OPT__(,) __VA_ARGS__, \
NULL, NULL, NULL, NULL)
#define TclNRAddCallback_(interp,postProcPtr,data0,data1,data2,data3,...) \
do { \
NRE_callback *_callbackPtr; \
TCLNR_ALLOC((interp), (_callbackPtr)); \
_callbackPtr->procPtr = (postProcPtr); \
_callbackPtr->data[0] = (void *)(data0); \
_callbackPtr->data[1] = (void *)(data1); \
_callbackPtr->data[2] = (void *)(data2); \
_callbackPtr->data[3] = (void *)(data3); \
_callbackPtr->nextPtr = TOP_CB(interp); \
TOP_CB(interp) = _callbackPtr; \
} while (0)
/*
* Wrapper for Tcl_SetErrorCode that makes certain there's a trailing NULL.
*/
#define TclSetErrorCode(interp, ...) \
Tcl_SetErrorCode((interp), __VA_ARGS__, (char *) NULL)
/*
* Wrapper for Tcl_AppendStringsToObj that makes certain there's a trailing
* NULL.
*/
#define TclAppendStringsToObj(objPtr, ...) \
Tcl_AppendStringsToObj((objPtr), __VA_ARGS__, (char *)NULL)
/*
* Wrapper for writing to the interpreter result and error info.
*/
#define TclPrintfResult(interp, format, ...) \
Tcl_SetObjResult((interp), \
Tcl_ObjPrintf((format) __VA_OPT__(,) __VA_ARGS__))
#define TclPrintfErrorInfo(interp, format, ...) \
Tcl_AppendObjToErrorInfo((interp), \
Tcl_ObjPrintf((format) __VA_OPT__(,) __VA_ARGS__))
#if NRE_USE_SMALL_ALLOC
#define TCLNR_ALLOC(interp, ptr) \
TclSmallAllocEx(interp, sizeof(NRE_callback), (ptr))
#define TCLNR_FREE(interp, ptr) TclSmallFreeEx((interp), (ptr))
#else
#define TCLNR_ALLOC(interp, ptr) \
((ptr) = Tcl_Alloc(sizeof(NRE_callback)))
|
| ︙ | ︙ |
Changes to generic/tclInterp.c.
| ︙ | ︙ | |||
879 880 881 882 883 884 885 |
InterpInfo *iiPtr;
for (i = 2; i < objc; i++) {
childInterp = GetInterp(interp, objv[i]);
if (childInterp == NULL) {
return TCL_ERROR;
} else if (childInterp == interp) {
| | | | | | 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 |
InterpInfo *iiPtr;
for (i = 2; i < objc; i++) {
childInterp = GetInterp(interp, objv[i]);
if (childInterp == NULL) {
return TCL_ERROR;
} else if (childInterp == interp) {
TclPrintfResult(interp,
"cannot delete the current interpreter");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP",
"DELETESELF");
return TCL_ERROR;
}
iiPtr = INTERP_INFO(childInterp);
Tcl_DeleteCommandFromToken(iiPtr->child.parentInterp,
iiPtr->child.interpCmd);
}
return TCL_OK;
|
| ︙ | ︙ | |||
1124 1125 1126 1127 1128 1129 1130 |
}
aliasName = TclGetString(objv[3]);
iiPtr = INTERP_INFO(childInterp);
hPtr = Tcl_FindHashEntry(&iiPtr->child.aliasTable, aliasName);
if (hPtr == NULL) {
| | | | < | | | | | 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 |
}
aliasName = TclGetString(objv[3]);
iiPtr = INTERP_INFO(childInterp);
hPtr = Tcl_FindHashEntry(&iiPtr->child.aliasTable, aliasName);
if (hPtr == NULL) {
TclPrintfResult(interp,
"alias \"%s\" in path \"%s\" not found",
aliasName, TclGetString(objv[2]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "ALIAS", aliasName);
return TCL_ERROR;
}
aliasPtr = (Alias *) Tcl_GetHashValue(hPtr);
if (Tcl_GetInterpPath(interp, aliasPtr->targetInterp) != TCL_OK) {
TclPrintfResult(interp,
"target interpreter for alias \"%s\" in path \"%s\" is "
"not my descendant", aliasName, TclGetString(objv[2]));
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP",
"TARGETSHROUDED");
return TCL_ERROR;
}
return TCL_OK;
}
default:
Tcl_Panic("unreachable");
return TCL_ERROR;
|
| ︙ | ︙ | |||
1317 1318 1319 1320 1321 1322 1323 |
Tcl_HashEntry *hPtr;
Alias *aliasPtr;
Tcl_Size objc;
Tcl_Obj **objv;
hPtr = Tcl_FindHashEntry(&iiPtr->child.aliasTable, aliasName);
if (hPtr == NULL) {
| < | | < | 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 |
Tcl_HashEntry *hPtr;
Alias *aliasPtr;
Tcl_Size objc;
Tcl_Obj **objv;
hPtr = Tcl_FindHashEntry(&iiPtr->child.aliasTable, aliasName);
if (hPtr == NULL) {
TclPrintfResult(interp, "alias \"%s\" not found", aliasName);
TclSetErrorCode(interp, "TCL", "LOOKUP", "ALIAS", aliasName);
return TCL_ERROR;
}
aliasPtr = (Alias *) Tcl_GetHashValue(hPtr);
objc = aliasPtr->objc;
objv = &aliasPtr->objPtr;
if (targetInterpPtr != NULL) {
|
| ︙ | ︙ | |||
1408 1409 1410 1411 1412 1413 1414 |
if (Tcl_InterpDeleted(nextAliasPtr->targetInterp)) {
/*
* The child interpreter can be deleted while creating the alias.
* [Bug #641195]
*/
| | | | | | < | 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 |
if (Tcl_InterpDeleted(nextAliasPtr->targetInterp)) {
/*
* The child interpreter can be deleted while creating the alias.
* [Bug #641195]
*/
TclPrintfResult(interp,
"cannot define or rename alias \"%s\": interpreter deleted",
Tcl_GetCommandName(cmdInterp, cmd));
return TCL_ERROR;
}
cmdNamePtr = nextAliasPtr->objPtr;
aliasCmd = Tcl_FindCommand(nextAliasPtr->targetInterp,
TclGetString(cmdNamePtr),
Tcl_GetGlobalNamespace(nextAliasPtr->targetInterp),
/*flags*/ 0);
if (aliasCmd == NULL) {
return TCL_OK;
}
aliasCmdPtr = (Command *) aliasCmd;
if (aliasCmdPtr == cmdPtr) {
TclPrintfResult(interp,
"cannot define or rename alias \"%s\": would create a loop",
Tcl_GetCommandName(cmdInterp, cmd));
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP", "ALIASLOOP");
return TCL_ERROR;
}
/*
* Otherwise, follow the chain one step further. See if the target
* command is an alias - if so, follow the loop to its target command.
* Otherwise we do not have a loop.
|
| ︙ | ︙ | |||
1646 1647 1648 1649 1650 1651 1652 |
* the original name (with which it was created) to find the alias to
* delete it.
*/
childPtr = &INTERP_INFO(childInterp)->child;
hPtr = Tcl_FindHashEntry(&childPtr->aliasTable, TclGetString(namePtr));
if (hPtr == NULL) {
| | | | | | 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 |
* the original name (with which it was created) to find the alias to
* delete it.
*/
childPtr = &INTERP_INFO(childInterp)->child;
hPtr = Tcl_FindHashEntry(&childPtr->aliasTable, TclGetString(namePtr));
if (hPtr == NULL) {
TclPrintfResult(interp,
"alias \"%s\" not found", TclGetString(namePtr));
TclSetErrorCode(interp, "TCL", "LOOKUP", "ALIAS",
TclGetString(namePtr));
return TCL_ERROR;
}
aliasPtr = (Alias *) Tcl_GetHashValue(hPtr);
Tcl_DeleteCommandFromToken(childInterp, aliasPtr->childCmd);
return TCL_OK;
}
|
| ︙ | ︙ | |||
1816 1817 1818 1819 1820 1821 1822 |
/*
* Use the ensemble rewriting machinery to ensure correct error messages:
* only the source command should show, not the full target prefix.
*/
if (TclInitRewriteEnsemble(interp, 1, prefc, objv)) {
| | | 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 |
/*
* Use the ensemble rewriting machinery to ensure correct error messages:
* only the source command should show, not the full target prefix.
*/
if (TclInitRewriteEnsemble(interp, 1, prefc, objv)) {
TclNRAddCallback(interp, TclClearRootEnsemble);
}
TclSkipTailcall(interp);
return Tcl_NREvalObj(interp, listPtr, flags);
}
int
TclAliasObjCmd(
|
| ︙ | ︙ | |||
2298 2299 2300 2301 2302 2303 2304 |
childPtr = (Child *) Tcl_GetHashValue(hPtr);
searchInterp = childPtr->childInterp;
if (searchInterp == NULL) {
break;
}
}
if (searchInterp == NULL) {
| | | | | | 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 |
childPtr = (Child *) Tcl_GetHashValue(hPtr);
searchInterp = childPtr->childInterp;
if (searchInterp == NULL) {
break;
}
}
if (searchInterp == NULL) {
TclPrintfResult(interp,
"could not find interpreter \"%s\"", TclGetString(pathPtr));
TclSetErrorCode(interp, "TCL", "LOOKUP", "INTERP",
TclGetString(pathPtr));
}
return searchInterp;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
2336 2337 2338 2339 2340 2341 2342 |
Tcl_Obj *const objv[]) /* Argument strings. */
{
if (objc) {
Tcl_Size length;
if (TCL_ERROR == TclListObjLength(NULL, objv[0], &length)
|| (length < 1)) {
| < | | | | 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 |
Tcl_Obj *const objv[]) /* Argument strings. */
{
if (objc) {
Tcl_Size length;
if (TCL_ERROR == TclListObjLength(NULL, objv[0], &length)
|| (length < 1)) {
TclPrintfResult(interp, "cmdPrefix must be list of length >= 1");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP",
"BGERRORFORMAT");
return TCL_ERROR;
}
TclSetBgErrorHandler(childInterp, objv[0]);
}
Tcl_SetObjResult(interp, TclGetBgErrorHandler(childInterp));
return TCL_OK;
}
|
| ︙ | ︙ | |||
2407 2408 2409 2410 2411 2412 2413 |
safe = Tcl_IsSafe(parentInterp);
}
parentInfoPtr = INTERP_INFO(parentInterp);
hPtr = Tcl_CreateHashEntry(&parentInfoPtr->parent.childTable, path,
&isNew);
if (isNew == 0) {
| | | | 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 |
safe = Tcl_IsSafe(parentInterp);
}
parentInfoPtr = INTERP_INFO(parentInterp);
hPtr = Tcl_CreateHashEntry(&parentInfoPtr->parent.childTable, path,
&isNew);
if (isNew == 0) {
TclPrintfResult(interp,
"interpreter named \"%s\" already exists, cannot create",
path);
return NULL;
}
childInterp = Tcl_CreateInterp();
childPtr = &INTERP_INFO(childInterp)->child;
childPtr->parentInterp = parentInterp;
childPtr->childEntryPtr = hPtr;
|
| ︙ | ︙ | |||
2778 2779 2780 2781 2782 2783 2784 |
int debugType;
Interp *iPtr;
Tcl_Obj *resultPtr;
iPtr = (Interp *) childInterp;
if (objc == 0) {
TclNewObj(resultPtr);
| | < | 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 |
int debugType;
Interp *iPtr;
Tcl_Obj *resultPtr;
iPtr = (Interp *) childInterp;
if (objc == 0) {
TclNewObj(resultPtr);
Tcl_ListObjAppendElement(NULL, resultPtr, TclNewString("-frame"));
Tcl_ListObjAppendElement(NULL, resultPtr,
Tcl_NewBooleanObj(iPtr->flags & INTERP_DEBUG_FRAME));
Tcl_SetObjResult(interp, resultPtr);
} else {
if (Tcl_GetIndexFromObj(interp, objv[0], debugTypes, "debug option",
0, &debugType) != TCL_OK) {
return TCL_ERROR;
|
| ︙ | ︙ | |||
2902 2903 2904 2905 2906 2907 2908 |
Tcl_Interp *childInterp, /* Interp in which command will be exposed. */
Tcl_Size objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument strings. */
{
const char *name;
if (Tcl_IsSafe(interp)) {
| | | < | < | 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 |
Tcl_Interp *childInterp, /* Interp in which command will be exposed. */
Tcl_Size objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument strings. */
{
const char *name;
if (Tcl_IsSafe(interp)) {
TclPrintfResult(interp,
"permission denied: safe interpreter cannot expose commands");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP", "UNSAFE");
return TCL_ERROR;
}
name = TclGetString(objv[(objc == 1) ? 0 : 1]);
if (Tcl_ExposeCommand(childInterp, TclGetString(objv[0]),
name) != TCL_OK) {
Tcl_TransferResult(childInterp, TCL_ERROR, interp);
|
| ︙ | ︙ | |||
2948 2949 2950 2951 2952 2953 2954 |
Tcl_Obj *const objv[]) /* Argument strings. */
{
Interp *iPtr;
Tcl_WideInt limit;
if (objc) {
if (Tcl_IsSafe(interp)) {
| | | | < < | | < < | | | 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 |
Tcl_Obj *const objv[]) /* Argument strings. */
{
Interp *iPtr;
Tcl_WideInt limit;
if (objc) {
if (Tcl_IsSafe(interp)) {
TclPrintfResult(interp, "permission denied: "
"safe interpreters cannot change recursion limit");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP", "UNSAFE");
return TCL_ERROR;
}
if (TclGetWideIntFromObj(interp, objv[0], &limit) == TCL_ERROR) {
return TCL_ERROR;
}
if (limit <= 0) {
TclPrintfResult(interp, "recursion limit must be > 0");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP", "BADLIMIT");
return TCL_ERROR;
}
Tcl_SetRecursionLimit(childInterp, limit);
iPtr = (Interp *) childInterp;
if (interp == childInterp && iPtr->numLevels > limit) {
TclPrintfResult(interp, "falling back due to new recursion limit");
TclSetErrorCode(interp, "TCL", "RECURSION");
return TCL_ERROR;
}
Tcl_SetObjResult(interp, objv[0]);
return TCL_OK;
} else {
limit = Tcl_SetRecursionLimit(childInterp, 0);
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(limit));
|
| ︙ | ︙ | |||
3008 3009 3010 3011 3012 3013 3014 |
Tcl_Interp *childInterp, /* Interp in which command will be exposed. */
Tcl_Size objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument strings. */
{
const char *name;
if (Tcl_IsSafe(interp)) {
| | | < | < | 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 |
Tcl_Interp *childInterp, /* Interp in which command will be exposed. */
Tcl_Size objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument strings. */
{
const char *name;
if (Tcl_IsSafe(interp)) {
TclPrintfResult(interp,
"permission denied: safe interpreter cannot hide commands");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP", "UNSAFE");
return TCL_ERROR;
}
name = TclGetString(objv[(objc == 1) ? 0 : 1]);
if (Tcl_HideCommand(childInterp, TclGetString(objv[0]), name) != TCL_OK) {
Tcl_TransferResult(childInterp, TCL_ERROR, interp);
return TCL_ERROR;
|
| ︙ | ︙ | |||
3094 3095 3096 3097 3098 3099 3100 |
const char *namespaceName, /* The namespace to use, if any. */
Tcl_Size objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
int result;
if (Tcl_IsSafe(interp)) {
| | | < | < | < | 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 |
const char *namespaceName, /* The namespace to use, if any. */
Tcl_Size objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
int result;
if (Tcl_IsSafe(interp)) {
TclPrintfResult(interp,
"not allowed to invoke hidden commands from safe interpreter");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP", "UNSAFE");
return TCL_ERROR;
}
Tcl_Preserve(childInterp);
Tcl_AllowExceptions(childInterp);
if (namespaceName == NULL) {
NRE_callback *rootPtr = TOP_CB(childInterp);
TclNRAddCallback(interp, NRPostInvokeHidden, childInterp, rootPtr);
return TclNRInvoke(NULL, childInterp, objc, objv);
} else {
Namespace *nsPtr, *dummy1, *dummy2;
const char *tail;
result = TclGetNamespaceForQualName(childInterp, namespaceName, NULL,
TCL_FIND_ONLY_NS | TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG
|
| ︙ | ︙ | |||
3171 3172 3173 3174 3175 3176 3177 |
static int
ChildMarkTrusted(
Tcl_Interp *interp, /* Interp for error return. */
Tcl_Interp *childInterp) /* The child interpreter which will be marked
* trusted. */
{
if (Tcl_IsSafe(interp)) {
| | | < | < | 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 |
static int
ChildMarkTrusted(
Tcl_Interp *interp, /* Interp for error return. */
Tcl_Interp *childInterp) /* The child interpreter which will be marked
* trusted. */
{
if (Tcl_IsSafe(interp)) {
TclPrintfResult(interp,
"permission denied: safe interpreter cannot mark trusted");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP", "UNSAFE");
return TCL_ERROR;
}
((Interp *) childInterp)->flags &= ~SAFE_INTERP;
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
3426 3427 3428 3429 3430 3431 3432 |
(iPtr->limit.cmdCount < iPtr->cmdCount)) {
iPtr->limit.exceeded |= TCL_LIMIT_COMMANDS;
Tcl_Preserve(interp);
RunLimitHandlers(iPtr->limit.cmdHandlers, interp);
if (iPtr->limit.cmdCount >= iPtr->cmdCount) {
iPtr->limit.exceeded &= ~TCL_LIMIT_COMMANDS;
} else if (iPtr->limit.exceeded & TCL_LIMIT_COMMANDS) {
| < | | | 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 |
(iPtr->limit.cmdCount < iPtr->cmdCount)) {
iPtr->limit.exceeded |= TCL_LIMIT_COMMANDS;
Tcl_Preserve(interp);
RunLimitHandlers(iPtr->limit.cmdHandlers, interp);
if (iPtr->limit.cmdCount >= iPtr->cmdCount) {
iPtr->limit.exceeded &= ~TCL_LIMIT_COMMANDS;
} else if (iPtr->limit.exceeded & TCL_LIMIT_COMMANDS) {
TclPrintfResult(interp, "command count limit exceeded");
TclSetErrorCode(interp, "TCL", "LIMIT", "COMMANDS");
Tcl_Release(interp);
return TCL_ERROR;
}
Tcl_Release(interp);
}
if ((iPtr->limit.active & TCL_LIMIT_TIME) &&
|
| ︙ | ︙ | |||
3452 3453 3454 3455 3456 3457 3458 |
Tcl_Preserve(interp);
RunLimitHandlers(iPtr->limit.timeHandlers, interp);
if (iPtr->limit.time.sec > now.sec ||
(iPtr->limit.time.sec == now.sec &&
iPtr->limit.time.usec >= now.usec)) {
iPtr->limit.exceeded &= ~TCL_LIMIT_TIME;
} else if (iPtr->limit.exceeded & TCL_LIMIT_TIME) {
| < | | | 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 |
Tcl_Preserve(interp);
RunLimitHandlers(iPtr->limit.timeHandlers, interp);
if (iPtr->limit.time.sec > now.sec ||
(iPtr->limit.time.sec == now.sec &&
iPtr->limit.time.usec >= now.usec)) {
iPtr->limit.exceeded &= ~TCL_LIMIT_TIME;
} else if (iPtr->limit.exceeded & TCL_LIMIT_TIME) {
TclPrintfResult(interp, "time limit exceeded");
TclSetErrorCode(interp, "TCL", "LIMIT", "TIME");
Tcl_Release(interp);
return TCL_ERROR;
}
Tcl_Release(interp);
}
}
|
| ︙ | ︙ | |||
4456 4457 4458 4459 4460 4461 4462 |
* First, ensure that we are not reading or writing the calling
* interpreter's limits; it may only manipulate its children. Note that
* the low level API enforces this with Tcl_Panic, which we want to
* avoid. [Bug 3398794]
*/
if (interp == childInterp) {
| < | | < | 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 |
* First, ensure that we are not reading or writing the calling
* interpreter's limits; it may only manipulate its children. Note that
* the low level API enforces this with Tcl_Panic, which we want to
* avoid. [Bug 3398794]
*/
if (interp == childInterp) {
TclPrintfResult(interp, "limits on current interpreter inaccessible");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP", "SELF");
return TCL_ERROR;
}
if (objc == consumedObjc) {
Tcl_Obj *dictPtr;
TclNewObj(dictPtr);
|
| ︙ | ︙ | |||
4551 4552 4553 4554 4555 4556 4557 |
break;
case OPT_GRAN:
granObj = objv[i+1];
if (TclGetIntFromObj(interp, objv[i+1], &gran) != TCL_OK) {
return TCL_ERROR;
}
if (gran < 1) {
| < | | | | | | | | 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 |
break;
case OPT_GRAN:
granObj = objv[i+1];
if (TclGetIntFromObj(interp, objv[i+1], &gran) != TCL_OK) {
return TCL_ERROR;
}
if (gran < 1) {
TclPrintfResult(interp, "granularity must be at least 1");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP",
"BADVALUE");
return TCL_ERROR;
}
break;
case OPT_VAL:
limitObj = objv[i+1];
(void) TclGetStringFromObj(objv[i+1], &limitLen);
if (limitLen == 0) {
break;
}
if (TclGetIntFromObj(interp, objv[i+1], &limit) != TCL_OK) {
return TCL_ERROR;
}
if (limit < 0) {
TclPrintfResult(interp,
"command limit value must be at least 0");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP",
"BADVALUE");
return TCL_ERROR;
}
break;
}
}
if (scriptObj != NULL) {
SetScriptLimitCallback(interp, TCL_LIMIT_COMMANDS, childInterp,
|
| ︙ | ︙ | |||
4640 4641 4642 4643 4644 4645 4646 |
* First, ensure that we are not reading or writing the calling
* interpreter's limits; it may only manipulate its children. Note that
* the low level API enforces this with Tcl_Panic, which we want to
* avoid. [Bug 3398794]
*/
if (interp == childInterp) {
| < | | < | 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 |
* First, ensure that we are not reading or writing the calling
* interpreter's limits; it may only manipulate its children. Note that
* the low level API enforces this with Tcl_Panic, which we want to
* avoid. [Bug 3398794]
*/
if (interp == childInterp) {
TclPrintfResult(interp, "limits on current interpreter inaccessible");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP", "SELF");
return TCL_ERROR;
}
if (objc == consumedObjc) {
Tcl_Obj *dictPtr;
TclNewObj(dictPtr);
|
| ︙ | ︙ | |||
4755 4756 4757 4758 4759 4760 4761 |
break;
case OPT_GRAN:
granObj = objv[i+1];
if (TclGetIntFromObj(interp, objv[i+1], &gran) != TCL_OK) {
return TCL_ERROR;
}
if (gran < 1) {
| < | | | | | | | < | | | | | | | | | | | | 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 |
break;
case OPT_GRAN:
granObj = objv[i+1];
if (TclGetIntFromObj(interp, objv[i+1], &gran) != TCL_OK) {
return TCL_ERROR;
}
if (gran < 1) {
TclPrintfResult(interp, "granularity must be at least 1");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP",
"BADVALUE");
return TCL_ERROR;
}
break;
case OPT_MILLI:
milliObj = objv[i+1];
(void) TclGetStringFromObj(objv[i+1], &milliLen);
if (milliLen == 0) {
break;
}
if (TclGetWideIntFromObj(interp, objv[i+1], &tmp) != TCL_OK) {
return TCL_ERROR;
}
if (tmp < 0) {
TclPrintfResult(interp,
"milliseconds must be non-negative");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP",
"BADVALUE");
return TCL_ERROR;
}
limitMoment.usec = tmp*1000;
break;
case OPT_SEC:
secObj = objv[i+1];
(void) TclGetStringFromObj(objv[i+1], &secLen);
if (secLen == 0) {
break;
}
if (TclGetWideIntFromObj(interp, objv[i+1], &tmp) != TCL_OK) {
return TCL_ERROR;
}
if (tmp < 0) {
TclPrintfResult(interp, "seconds must be non-negative");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP",
"BADVALUE");
return TCL_ERROR;
}
limitMoment.sec = (long long) tmp;
break;
}
}
if (milliObj != NULL || secObj != NULL) {
if (milliObj != NULL) {
/*
* Setting -milliseconds but clearing -seconds, or resetting
* -milliseconds but not resetting -seconds? Bad voodoo!
*/
if (secObj != NULL && secLen == 0 && milliLen > 0) {
TclPrintfResult(interp,
"may only set -milliseconds if -seconds is not "
"also being reset");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP",
"BADUSAGE");
return TCL_ERROR;
}
if (milliLen == 0 && (secObj == NULL || secLen > 0)) {
TclPrintfResult(interp,
"may only reset -milliseconds if -seconds is "
"also being reset");
TclSetErrorCode(interp, "TCL", "OPERATION", "INTERP",
"BADUSAGE");
return TCL_ERROR;
}
}
if (milliLen > 0 || secLen > 0) {
/*
* Force usec to be in range [0..1000000), possibly
|
| ︙ | ︙ |
Changes to generic/tclLink.c.
| ︙ | ︙ | |||
163 164 165 166 167 168 169 |
Namespace *dummy;
const char *name;
int code;
linkPtr = (Link *) Tcl_VarTraceInfo2(interp, varName, NULL,
TCL_GLOBAL_ONLY, LinkTraceProc, NULL);
if (linkPtr != NULL) {
| < | | 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
Namespace *dummy;
const char *name;
int code;
linkPtr = (Link *) Tcl_VarTraceInfo2(interp, varName, NULL,
TCL_GLOBAL_ONLY, LinkTraceProc, NULL);
if (linkPtr != NULL) {
TclPrintfResult(interp, "variable '%s' is already linked", varName);
return TCL_ERROR;
}
linkPtr = (Link *)Tcl_Alloc(sizeof(Link));
linkPtr->interp = interp;
linkPtr->nsPtr = NULL;
linkPtr->varName = Tcl_NewStringObj(varName, -1);
|
| ︙ | ︙ | |||
243 244 245 246 247 248 249 |
Tcl_Obj *objPtr;
Link *linkPtr;
Namespace *dummy;
const char *name;
int code;
if (size < 1) {
| < | | 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
Tcl_Obj *objPtr;
Link *linkPtr;
Namespace *dummy;
const char *name;
int code;
if (size < 1) {
TclPrintfResult(interp, "wrong array size given");
return TCL_ERROR;
}
linkPtr = (Link *)Tcl_Alloc(sizeof(Link));
linkPtr->type = type & ~TCL_LINK_READ_ONLY;
linkPtr->numElems = size;
if (type & TCL_LINK_READ_ONLY) {
|
| ︙ | ︙ | |||
311 312 313 314 315 316 317 |
break;
case TCL_LINK_CHARS:
case TCL_LINK_BINARY:
linkPtr->bytes = size * sizeof(char);
break;
default:
LinkFree(linkPtr);
| < | | 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
break;
case TCL_LINK_CHARS:
case TCL_LINK_BINARY:
linkPtr->bytes = size * sizeof(char);
break;
default:
LinkFree(linkPtr);
TclPrintfResult(interp, "bad linked array variable type");
return TCL_ERROR;
}
/*
* Allocate C variable space in case no address is given
*/
|
| ︙ | ︙ |
Changes to generic/tclListObj.c.
| ︙ | ︙ | |||
465 466 467 468 469 470 471 |
*/
static int
MemoryAllocationError(
Tcl_Interp *interp, /* Interpreter for error message. May be NULL */
size_t size) /* Size of attempted allocation that failed */
{
if (interp != NULL) {
| | | | | 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
*/
static int
MemoryAllocationError(
Tcl_Interp *interp, /* Interpreter for error message. May be NULL */
size_t size) /* Size of attempted allocation that failed */
{
if (interp != NULL) {
TclPrintfResult(interp,
"list construction failed: unable to alloc %" TCL_Z_MODIFIER
"u bytes",
size);
TclSetErrorCode(interp, "TCL", "MEMORY");
}
return TCL_ERROR;
}
/*
*------------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
494 495 496 497 498 499 500 |
*------------------------------------------------------------------------
*/
static int
ListLimitExceededError(
Tcl_Interp *interp)
{
if (interp != NULL) {
| < | | | 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
*------------------------------------------------------------------------
*/
static int
ListLimitExceededError(
Tcl_Interp *interp)
{
if (interp != NULL) {
TclPrintfResult(interp, "max length of a Tcl list exceeded");
TclSetErrorCode(interp, "TCL", "MEMORY");
}
return TCL_ERROR;
}
/*
*------------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
672 673 674 675 676 677 678 |
#undef INVARIANT
return;
failure:
Tcl_Panic("List internal failure in %s line %d. Condition: %s",
| < < | | 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 |
#undef INVARIANT
return;
failure:
Tcl_Panic("List internal failure in %s line %d. Condition: %s",
file, lineNum, condition);
}
/*
*------------------------------------------------------------------------
*
* TclListObjValidate --
*
|
| ︙ | ︙ | |||
2982 2983 2984 2985 2986 2987 2988 |
if ((index == TCL_SIZE_MAX) && (elemCount == 0)) {
index = 0;
}
if (index < 0 || index > elemCount
|| (valueObj == NULL && index >= elemCount)) {
/* ...the index points outside the sublist. */
if (interp != NULL) {
| | | | | 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 |
if ((index == TCL_SIZE_MAX) && (elemCount == 0)) {
index = 0;
}
if (index < 0 || index > elemCount
|| (valueObj == NULL && index >= elemCount)) {
/* ...the index points outside the sublist. */
if (interp != NULL) {
TclPrintfResult(interp,
"index \"%s\" out of range", TclGetString(indexArray[-1]));
TclSetErrorCode(interp, "TCL", "VALUE", "INDEX", "OUTOFRANGE");
}
result = TCL_ERROR;
break;
}
/*
* No error conditions. As long as we're not yet on the last index,
|
| ︙ | ︙ | |||
3171 3172 3173 3174 3175 3176 3177 |
}
elemCount = ListRepLength(&listRep);
/* Ensure that the index is in bounds. */
if ((index < 0) || (index >= elemCount)) {
if (interp != NULL) {
| | | | | 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 |
}
elemCount = ListRepLength(&listRep);
/* Ensure that the index is in bounds. */
if ((index < 0) || (index >= elemCount)) {
if (interp != NULL) {
TclPrintfResult(interp,
"index \"%" TCL_SIZE_MODIFIER "d\" out of range", index);
TclSetErrorCode(interp, "TCL", "VALUE", "INDEX", "OUTOFRANGE");
}
return TCL_ERROR;
}
/*
* Note - garbage collect this only AFTER checking indices above.
* Do not want to modify listrep and then not store it back in listObj.
|
| ︙ | ︙ |
Changes to generic/tclLoad.c.
| ︙ | ︙ | |||
186 187 188 189 190 191 192 |
if (objc >= 3) {
prefix = TclGetString(objv[2]);
if (prefix[0] == '\0') {
prefix = NULL;
}
}
if ((fullFileName[0] == 0) && (prefix == NULL)) {
| < | | < | 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
if (objc >= 3) {
prefix = TclGetString(objv[2]);
if (prefix[0] == '\0') {
prefix = NULL;
}
}
if ((fullFileName[0] == 0) && (prefix == NULL)) {
TclPrintfResult(interp, "must specify either file name or prefix");
TclSetErrorCode(interp, "TCL", "OPERATION", "LOAD", "NOLIBRARY");
code = TCL_ERROR;
goto done;
}
/*
* Figure out which interpreter we're going to load the library into.
*/
|
| ︙ | ︙ | |||
251 252 253 254 255 256 257 |
defaultPtr = libraryPtr;
}
if (filesMatch && !namesMatch && (fullFileName[0] != 0)) {
/*
* Can't have two different libraries loaded from the same file.
*/
| | | | | | 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
defaultPtr = libraryPtr;
}
if (filesMatch && !namesMatch && (fullFileName[0] != 0)) {
/*
* Can't have two different libraries loaded from the same file.
*/
TclPrintfResult(interp,
"file \"%s\" is already loaded for prefix \"%s\"",
fullFileName, libraryPtr->prefix);
TclSetErrorCode(interp, "TCL", "OPERATION", "LOAD",
"SPLITPERSONALITY");
code = TCL_ERROR;
Tcl_MutexUnlock(&libraryMutex);
goto done;
}
}
Tcl_MutexUnlock(&libraryMutex);
if (libraryPtr == NULL) {
|
| ︙ | ︙ | |||
289 290 291 292 293 294 295 |
if (libraryPtr == NULL) {
/*
* The desired file isn't currently loaded, so load it. It's an error
* if the desired library is a static one.
*/
if (fullFileName[0] == 0) {
| | | | < | 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
if (libraryPtr == NULL) {
/*
* The desired file isn't currently loaded, so load it. It's an error
* if the desired library is a static one.
*/
if (fullFileName[0] == 0) {
TclPrintfResult(interp,
"no library with prefix \"%s\" is loaded statically", prefix);
TclSetErrorCode(interp, "TCL", "OPERATION", "LOAD", "NOTSTATIC");
code = TCL_ERROR;
goto done;
}
/*
* Figure out the prefix if it wasn't provided explicitly.
*/
|
| ︙ | ︙ | |||
350 351 352 353 354 355 356 |
if (!Tcl_UniCharIsWordChar(UCHAR(ch))
|| Tcl_UniCharIsDigit(UCHAR(ch))) {
break;
}
}
if (p == pkgGuess) {
Tcl_DecrRefCount(splitPtr);
| | | | | | 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
if (!Tcl_UniCharIsWordChar(UCHAR(ch))
|| Tcl_UniCharIsDigit(UCHAR(ch))) {
break;
}
}
if (p == pkgGuess) {
Tcl_DecrRefCount(splitPtr);
TclPrintfResult(interp,
"cannot figure out prefix for %s",
fullFileName);
TclSetErrorCode(interp, "TCL", "OPERATION", "LOAD",
"WHATLIBRARY");
code = TCL_ERROR;
goto done;
}
Tcl_DStringAppend(&pfx, pkgGuess, p - pkgGuess);
Tcl_DecrRefCount(splitPtr);
/*
|
| ︙ | ︙ | |||
447 448 449 450 451 452 453 |
/*
* Invoke the library's initialization function (either the normal one or
* the safe one, depending on whether or not the interpreter is safe).
*/
if (Tcl_IsSafe(target)) {
if (libraryPtr->safeInitProc == NULL) {
| | | | < | | | < | | 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
/*
* Invoke the library's initialization function (either the normal one or
* the safe one, depending on whether or not the interpreter is safe).
*/
if (Tcl_IsSafe(target)) {
if (libraryPtr->safeInitProc == NULL) {
TclPrintfResult(interp,
"cannot use library in a safe interpreter: no"
" %s_SafeInit procedure", libraryPtr->prefix);
TclSetErrorCode(interp, "TCL", "OPERATION", "LOAD", "UNSAFE");
code = TCL_ERROR;
goto done;
}
code = libraryPtr->safeInitProc(target);
} else {
if (libraryPtr->initProc == NULL) {
TclPrintfResult(interp,
"cannot attach library to interpreter: no %s_Init procedure",
libraryPtr->prefix);
TclSetErrorCode(interp, "TCL", "OPERATION", "LOAD", "ENTRYPOINT");
code = TCL_ERROR;
goto done;
}
code = libraryPtr->initProc(target);
}
/*
* Test for whether the initialization failed. If so, transfer the error
* from the target interpreter to the originating one.
*/
if (code != TCL_OK) {
Interp *iPtr = (Interp *) target;
if (iPtr->legacyResult && *(iPtr->legacyResult) && !iPtr->legacyFreeProc) {
/*
* A call to Tcl_InitStubs() determined the caller extension
* Stubs were introduced in Tcl 8.1, so there's only one possible reason.
*/
TclPrintfResult(target, "this extension is compiled for Tcl 8.x");
iPtr->legacyResult = NULL;
iPtr->legacyFreeProc = (void (*) (void))-1;
}
Tcl_TransferResult(target, code, interp);
goto done;
}
|
| ︙ | ︙ | |||
618 619 620 621 622 623 624 |
if (objc - i >= 2) {
prefix = TclGetString(objv[i+1]);
if (prefix[0] == '\0') {
prefix = NULL;
}
}
if ((fullFileName[0] == 0) && (prefix == NULL)) {
| < | | < | 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 |
if (objc - i >= 2) {
prefix = TclGetString(objv[i+1]);
if (prefix[0] == '\0') {
prefix = NULL;
}
}
if ((fullFileName[0] == 0) && (prefix == NULL)) {
TclPrintfResult(interp, "must specify either file name or prefix");
TclSetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "NOLIBRARY");
code = TCL_ERROR;
goto done;
}
/*
* Figure out which interpreter we're going to load the library into.
*/
|
| ︙ | ︙ | |||
685 686 687 688 689 690 691 |
}
Tcl_MutexUnlock(&libraryMutex);
if (fullFileName[0] == 0) {
/*
* It's an error to try unload a static library.
*/
| | | | < | | | < | 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
}
Tcl_MutexUnlock(&libraryMutex);
if (fullFileName[0] == 0) {
/*
* It's an error to try unload a static library.
*/
TclPrintfResult(interp,
"library with prefix \"%s\" is loaded statically and cannot be unloaded",
prefix);
TclSetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "STATIC");
code = TCL_ERROR;
goto done;
}
if (libraryPtr == NULL) {
/*
* The DLL pointed by the provided filename has never been loaded.
*/
TclPrintfResult(interp,
"file \"%s\" has never been loaded", fullFileName);
TclSetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "NEVERLOADED");
code = TCL_ERROR;
goto done;
}
/*
* Scan through the list of libraries already loaded in the target
* interpreter. If the library we want is already loaded there, then we
|
| ︙ | ︙ | |||
727 728 729 730 731 732 733 |
}
}
if (code != TCL_OK) {
/*
* The library has not been loaded in this interpreter.
*/
| | | | < | 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 |
}
}
if (code != TCL_OK) {
/*
* The library has not been loaded in this interpreter.
*/
TclPrintfResult(interp,
"file \"%s\" has never been loaded in this interpreter",
fullFileName);
TclSetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "NEVERLOADED");
code = TCL_ERROR;
goto done;
}
code = UnloadLibrary(interp, target, libraryPtr, keepLibrary, fullFileName, 0);
done:
|
| ︙ | ︙ | |||
788 789 790 791 792 793 794 |
* libraryPtr->unloadProc must not be NULL for the DLL to be unloadable. If
* the interpreter is a safe one, libraryPtr->safeUnloadProc must be non-NULL.
*/
if (Tcl_IsSafe(target)) {
if (libraryPtr->safeUnloadProc == NULL) {
if (!interpExiting) {
| | | | < | | | < | 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 |
* libraryPtr->unloadProc must not be NULL for the DLL to be unloadable. If
* the interpreter is a safe one, libraryPtr->safeUnloadProc must be non-NULL.
*/
if (Tcl_IsSafe(target)) {
if (libraryPtr->safeUnloadProc == NULL) {
if (!interpExiting) {
TclPrintfResult(interp,
"file \"%s\" cannot be unloaded under a safe interpreter",
fullFileName);
TclSetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "CANNOT");
code = TCL_ERROR;
goto done;
}
}
unloadProc = libraryPtr->safeUnloadProc;
} else {
if (libraryPtr->unloadProc == NULL) {
if (!interpExiting) {
TclPrintfResult(interp,
"file \"%s\" cannot be unloaded under a trusted interpreter",
fullFileName);
TclSetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "CANNOT");
code = TCL_ERROR;
goto done;
}
}
unloadProc = libraryPtr->unloadProc;
}
|
| ︙ | ︙ | |||
955 956 957 958 959 960 961 |
Tcl_Free(iterLibraryPtr);
Tcl_MutexUnlock(&libraryMutex);
} else {
code = TCL_ERROR;
}
}
#else
| | | | < | 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 |
Tcl_Free(iterLibraryPtr);
Tcl_MutexUnlock(&libraryMutex);
} else {
code = TCL_ERROR;
}
}
#else
TclPrintfResult(interp,
"file \"%s\" cannot be unloaded: unloading disabled",
fullFileName);
TclSetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "DISABLED");
code = TCL_ERROR;
#endif
}
done:
return code;
}
|
| ︙ | ︙ |
Changes to generic/tclLoadNone.c.
| ︙ | ︙ | |||
42 43 44 45 46 47 48 |
Tcl_FSUnloadFileProc **unloadProcPtr,
/* Filled with address of Tcl_FSUnloadFileProc
* function which should be used for this
* file. */
int flags)
{
if (interp) {
| | | < | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
Tcl_FSUnloadFileProc **unloadProcPtr,
/* Filled with address of Tcl_FSUnloadFileProc
* function which should be used for this
* file. */
int flags)
{
if (interp) {
TclPrintfResult(interp,
"dynamic loading is not currently available on this system");
}
return TCL_ERROR;
}
/*
* These functions are fallbacks if we somehow determine that the platform can
* do loading from memory but the user wishes to disable it. They just report
|
| ︙ | ︙ |
Changes to generic/tclMain.c.
| ︙ | ︙ | |||
338 339 340 341 342 343 344 |
path = Tcl_GetStartupScript(&encodingName);
if (path != NULL) {
appName = path;
} else if (argv[0]) {
appName = NewNativeObj(argv[0]);
} else {
| | | 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
path = Tcl_GetStartupScript(&encodingName);
if (path != NULL) {
appName = path;
} else if (argv[0]) {
appName = NewNativeObj(argv[0]);
} else {
appName = TclNewString("tclsh");
}
Tcl_SetVar2Ex(interp, "argv0", NULL, appName, TCL_GLOBAL_ONLY);
Tcl_SetVar2Ex(interp, "argc", NULL, Tcl_NewWideIntObj(argc), TCL_GLOBAL_ONLY);
argvPtr = Tcl_NewListObj(0, NULL);
while (argc--) {
|
| ︙ | ︙ | |||
497 498 499 500 501 502 503 |
*/
if (Tcl_IsShared(is.commandPtr)) {
Tcl_DecrRefCount(is.commandPtr);
is.commandPtr = Tcl_DuplicateObj(is.commandPtr);
Tcl_IncrRefCount(is.commandPtr);
}
| | | 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
*/
if (Tcl_IsShared(is.commandPtr)) {
Tcl_DecrRefCount(is.commandPtr);
is.commandPtr = Tcl_DuplicateObj(is.commandPtr);
Tcl_IncrRefCount(is.commandPtr);
}
TclAppendLiteralToObj(is.commandPtr, "\n");
if (!TclObjCommandComplete(is.commandPtr)) {
is.prompt = PROMPT_CONTINUE;
continue;
}
is.prompt = PROMPT_START;
|
| ︙ | ︙ | |||
769 770 771 772 773 774 775 |
}
if (Tcl_IsShared(commandPtr)) {
Tcl_DecrRefCount(commandPtr);
commandPtr = Tcl_DuplicateObj(commandPtr);
Tcl_IncrRefCount(commandPtr);
}
| | | 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 |
}
if (Tcl_IsShared(commandPtr)) {
Tcl_DecrRefCount(commandPtr);
commandPtr = Tcl_DuplicateObj(commandPtr);
Tcl_IncrRefCount(commandPtr);
}
TclAppendLiteralToObj(commandPtr, "\n");
if (!TclObjCommandComplete(commandPtr)) {
isPtr->prompt = PROMPT_CONTINUE;
goto prompt;
}
isPtr->prompt = PROMPT_START;
(void)Tcl_GetStringFromObj(commandPtr, &length);
Tcl_SetObjLength(commandPtr, --length);
|
| ︙ | ︙ | |||
880 881 882 883 884 885 886 |
Tcl_WriteChars(chan, DEFAULT_PRIMARY_PROMPT,
sizeof(DEFAULT_PRIMARY_PROMPT) - 1);
}
}
} else {
code = Tcl_EvalObjEx(interp, promptCmdPtr, TCL_EVAL_GLOBAL);
if (code != TCL_OK) {
| | < | 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 |
Tcl_WriteChars(chan, DEFAULT_PRIMARY_PROMPT,
sizeof(DEFAULT_PRIMARY_PROMPT) - 1);
}
}
} else {
code = Tcl_EvalObjEx(interp, promptCmdPtr, TCL_EVAL_GLOBAL);
if (code != TCL_OK) {
Tcl_AddErrorInfo(interp, "\n (script that generates prompt)");
chan = Tcl_GetStdChannel(TCL_STDERR);
if (chan != NULL) {
if (Tcl_WriteObj(chan, Tcl_GetObjResult(interp)) < 0) {
Tcl_WriteChars(chan, ENCODING_ERROR, -1);
}
Tcl_WriteChars(chan, "\n", 1);
}
|
| ︙ | ︙ |
Changes to generic/tclNamesp.c.
| ︙ | ︙ | |||
829 830 831 832 833 834 835 |
/*
* If we've ended up with an empty string now, we're attempting to create
* the global namespace despite the global namespace existing. That's
* naughty!
*/
if (*name == '\0') {
| | | | | | 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 |
/*
* If we've ended up with an empty string now, we're attempting to create
* the global namespace despite the global namespace existing. That's
* naughty!
*/
if (*name == '\0') {
TclPrintfResult(interp, "can't create namespace \"\": "
"only global namespace can have empty name");
TclSetErrorCode(interp, "TCL", "OPERATION", "NAMESPACE",
"CREATEGLOBAL");
Tcl_DStringFree(&tmpBuffer);
return NULL;
}
/*
* Find the parent for the new namespace.
*/
|
| ︙ | ︙ | |||
861 862 863 864 865 866 867 |
/*
* Check for a bad namespace name and make sure that the name does not
* already exist in the parent namespace.
*/
if (FindChildEntry(parentPtr, simpleName) != NULL) {
| | | | | | 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 |
/*
* Check for a bad namespace name and make sure that the name does not
* already exist in the parent namespace.
*/
if (FindChildEntry(parentPtr, simpleName) != NULL) {
TclPrintfResult(interp,
"can't create namespace \"%s\": already exists", name);
TclSetErrorCode(interp, "TCL", "OPERATION", "NAMESPACE",
"CREATEEXISTING");
Tcl_DStringFree(&tmpBuffer);
return NULL;
}
/*
* Create the new namespace and root it in its parent. Increment the count
* of namespaces created.
|
| ︙ | ︙ | |||
1504 1505 1506 1507 1508 1509 1510 |
* Check that the pattern doesn't have namespace qualifiers.
*/
TclGetNamespaceForQualName(interp, pattern, nsPtr, TCL_NAMESPACE_ONLY,
&exportNsPtr, &dummyPtr, &dummyPtr, &simplePattern);
if ((exportNsPtr != nsPtr) || (strcmp(pattern, simplePattern) != 0)) {
| | | | | 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 |
* Check that the pattern doesn't have namespace qualifiers.
*/
TclGetNamespaceForQualName(interp, pattern, nsPtr, TCL_NAMESPACE_ONLY,
&exportNsPtr, &dummyPtr, &dummyPtr, &simplePattern);
if ((exportNsPtr != nsPtr) || (strcmp(pattern, simplePattern) != 0)) {
TclPrintfResult(interp, "invalid export pattern"
" \"%s\": pattern can't specify a namespace", pattern);
TclSetErrorCode(interp, "TCL", "EXPORT", "INVALID");
return TCL_ERROR;
}
/*
* Make sure that we don't already have the pattern in the array
*/
|
| ︙ | ︙ | |||
1712 1713 1714 1715 1716 1717 1718 |
/*
* From the pattern, find the namespace from which we are importing and
* get the simple pattern (no namespace qualifiers or ::'s) at the end.
*/
if (strlen(pattern) == 0) {
| | | | | | | | | | | | | 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 |
/*
* From the pattern, find the namespace from which we are importing and
* get the simple pattern (no namespace qualifiers or ::'s) at the end.
*/
if (strlen(pattern) == 0) {
TclPrintfResult(interp, "empty import pattern");
TclSetErrorCode(interp, "TCL", "IMPORT", "EMPTY");
return TCL_ERROR;
}
TclGetNamespaceForQualName(interp, pattern, nsPtr, TCL_NAMESPACE_ONLY,
&importNsPtr, &dummyPtr, &dummyPtr, &simplePattern);
if (importNsPtr == NULL) {
TclPrintfResult(interp,
"unknown namespace in import pattern \"%s\"", pattern);
TclSetErrorCode(interp, "TCL", "LOOKUP", "NAMESPACE", pattern);
return TCL_ERROR;
}
if (importNsPtr == nsPtr) {
if (pattern == simplePattern) {
TclPrintfResult(interp,
"no namespace specified in import pattern \"%s\"",
pattern);
TclSetErrorCode(interp, "TCL", "IMPORT", "ORIGIN");
} else {
TclPrintfResult(interp,
"import pattern \"%s\" tries to import from namespace"
" \"%s\" into itself", pattern, importNsPtr->name);
TclSetErrorCode(interp, "TCL", "IMPORT", "SELF");
}
return TCL_ERROR;
}
/*
* Scan through the command table in the source namespace and look for
* exported commands that match the string pattern. Create an "imported
|
| ︙ | ︙ | |||
1852 1853 1854 1855 1856 1857 1858 |
Command *overwrite = (Command *) Tcl_GetHashValue(found);
Command *linkCmd = cmdPtr;
while (linkCmd->deleteProc == DeleteImportedCmd) {
dataPtr = (ImportedCmdData *) linkCmd->objClientData;
linkCmd = dataPtr->realCmdPtr;
if (overwrite == linkCmd) {
| | | | | 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 |
Command *overwrite = (Command *) Tcl_GetHashValue(found);
Command *linkCmd = cmdPtr;
while (linkCmd->deleteProc == DeleteImportedCmd) {
dataPtr = (ImportedCmdData *) linkCmd->objClientData;
linkCmd = dataPtr->realCmdPtr;
if (overwrite == linkCmd) {
TclPrintfResult(interp,
"import pattern \"%s\" would create a loop"
" containing command \"%s\"",
pattern, Tcl_DStringValue(&ds));
Tcl_DStringFree(&ds);
TclSetErrorCode(interp, "TCL", "IMPORT", "LOOP");
return TCL_ERROR;
}
}
}
dataPtr = (ImportedCmdData *) Tcl_Alloc(sizeof(ImportedCmdData));
importedCmd = Tcl_NRCreateCommand(interp, Tcl_DStringValue(&ds),
|
| ︙ | ︙ | |||
1898 1899 1900 1901 1902 1903 1904 | /* * Repeated import of same command is acceptable. */ return TCL_OK; } } | | | | | 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 |
/*
* Repeated import of same command is acceptable.
*/
return TCL_OK;
}
}
TclPrintfResult(interp,
"can't import command \"%s\": already exists", cmdName);
TclSetErrorCode(interp, "TCL", "IMPORT", "OVERWRITE");
return TCL_ERROR;
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
|
| ︙ | ︙ | |||
1967 1968 1969 1970 1971 1972 1973 |
* simple pattern.
*/
TclGetNamespaceForQualName(interp, pattern, nsPtr, TCL_NAMESPACE_ONLY,
&sourceNsPtr, &dummyPtr, &dummyPtr, &simplePattern);
if (sourceNsPtr == NULL) {
| | | | | 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 |
* simple pattern.
*/
TclGetNamespaceForQualName(interp, pattern, nsPtr, TCL_NAMESPACE_ONLY,
&sourceNsPtr, &dummyPtr, &dummyPtr, &simplePattern);
if (sourceNsPtr == NULL) {
TclPrintfResult(interp,
"unknown namespace in namespace forget pattern \"%s\"",
pattern);
TclSetErrorCode(interp, "TCL", "LOOKUP", "NAMESPACE", pattern);
return TCL_ERROR;
}
if (strcmp(pattern, simplePattern) == 0) {
/*
* The pattern is simple. Delete any imported commands that match it.
*/
|
| ︙ | ︙ | |||
2599 2600 2601 2602 2603 2604 2605 |
flags|TCL_FIND_ONLY_NS, &nsPtr, &dummy1Ptr, &dummy2Ptr, &dummy);
if (nsPtr != NULL) {
return (Tcl_Namespace *) nsPtr;
}
if (flags & TCL_LEAVE_ERR_MSG) {
| < | | | 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 |
flags|TCL_FIND_ONLY_NS, &nsPtr, &dummy1Ptr, &dummy2Ptr, &dummy);
if (nsPtr != NULL) {
return (Tcl_Namespace *) nsPtr;
}
if (flags & TCL_LEAVE_ERR_MSG) {
TclPrintfResult(interp, "unknown namespace \"%s\"", name);
TclSetErrorCode(interp, "TCL", "LOOKUP", "NAMESPACE", name);
}
return NULL;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
2789 2790 2791 2792 2793 2794 2795 |
if (cmdPtr != NULL) {
cmdPtr->flags &= ~CMD_VIA_RESOLVER;
return (Tcl_Command) cmdPtr;
}
if (flags & TCL_LEAVE_ERR_MSG) {
| < | | | 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 |
if (cmdPtr != NULL) {
cmdPtr->flags &= ~CMD_VIA_RESOLVER;
return (Tcl_Command) cmdPtr;
}
if (flags & TCL_LEAVE_ERR_MSG) {
TclPrintfResult(interp, "unknown command \"%s\"", name);
TclSetErrorCode(interp, "TCL", "LOOKUP", "COMMAND", name);
}
return NULL;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
2965 2966 2967 2968 2969 2970 2971 |
* namespace. */
Tcl_Namespace **nsPtrPtr) /* Result namespace pointer goes here. */
{
if (GetNamespaceFromObj(interp, objPtr, nsPtrPtr) == TCL_ERROR) {
const char *name = TclGetString(objPtr);
if ((name[0] == ':') && (name[1] == ':')) {
| < | | | | | 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 |
* namespace. */
Tcl_Namespace **nsPtrPtr) /* Result namespace pointer goes here. */
{
if (GetNamespaceFromObj(interp, objPtr, nsPtrPtr) == TCL_ERROR) {
const char *name = TclGetString(objPtr);
if ((name[0] == ':') && (name[1] == ':')) {
TclPrintfResult(interp, "namespace \"%s\" not found", name);
} else {
/*
* Get the current namespace name.
*/
NamespaceCurrentCmd(NULL, interp, 1, NULL);
TclPrintfResult(interp,
"namespace \"%s\" not found in \"%s\"", name,
Tcl_GetStringResult(interp));
}
TclSetErrorCode(interp, "TCL", "LOOKUP", "NAMESPACE", name);
return TCL_ERROR;
}
return TCL_OK;
}
static int
GetNamespaceFromObj(
|
| ︙ | ︙ | |||
3403 3404 3405 3406 3407 3408 3409 |
*/
for (i = 1; i < objc; i++) {
name = TclGetString(objv[i]);
namespacePtr = Tcl_FindNamespace(interp, name, NULL, /*flags*/ 0);
if ((namespacePtr == NULL)
|| (((Namespace *) namespacePtr)->flags & NS_TEARDOWN)) {
| | | | | | 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 |
*/
for (i = 1; i < objc; i++) {
name = TclGetString(objv[i]);
namespacePtr = Tcl_FindNamespace(interp, name, NULL, /*flags*/ 0);
if ((namespacePtr == NULL)
|| (((Namespace *) namespacePtr)->flags & NS_TEARDOWN)) {
TclPrintfResult(interp,
"unknown namespace \"%s\" in namespace delete command",
TclGetString(objv[i]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "NAMESPACE",
TclGetString(objv[i]));
return TCL_ERROR;
}
}
/*
* Okay, now delete each namespace.
*/
|
| ︙ | ︙ | |||
3541 3542 3543 3544 3545 3546 3547 |
word = 0;
}
/*
* TIP #280: Make invoking context available to eval'd script.
*/
| | < | | | 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 |
word = 0;
}
/*
* TIP #280: Make invoking context available to eval'd script.
*/
TclNRAddCallback(interp, NsEval_Callback, namespacePtr, "eval");
return TclNREvalObjEx(interp, objPtr, 0, invoker, word);
}
static int
NsEval_Callback(
void *data[],
Tcl_Interp *interp,
int result)
{
Tcl_Namespace *namespacePtr = (Tcl_Namespace *) data[0];
if (result == TCL_ERROR) {
size_t length = strlen(namespacePtr->fullName);
unsigned limit = 200;
int overflow = (length > limit);
char *cmd = (char *) data[1];
TclPrintfErrorInfo(interp,
"\n (in namespace %s \"%.*s%s\" script line %d)",
cmd,
(overflow ? limit : (unsigned)length), namespacePtr->fullName,
(overflow ? "..." : ""), Tcl_GetErrorLine(interp));
}
/*
* Restore the previous "current" namespace.
*/
TclPopStackFrame(interp);
|
| ︙ | ︙ | |||
3966 3967 3968 3969 3970 3971 3972 |
concatObjv[0] = objv[2];
concatObjv[1] = Tcl_NewListObj(objc - 3, objv + 3);
cmdObjPtr = Tcl_ConcatObj(2, concatObjv);
Tcl_DecrRefCount(concatObjv[1]); /* We're done with the list object. */
}
| | < | 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 |
concatObjv[0] = objv[2];
concatObjv[1] = Tcl_NewListObj(objc - 3, objv + 3);
cmdObjPtr = Tcl_ConcatObj(2, concatObjv);
Tcl_DecrRefCount(concatObjv[1]); /* We're done with the list object. */
}
TclNRAddCallback(interp, NsEval_Callback, namespacePtr, "inscope");
return TclNREvalObjEx(interp, cmdObjPtr, 0, NULL, 0);
}
/*
*----------------------------------------------------------------------
*
* NamespaceOriginCmd --
|
| ︙ | ︙ | |||
4033 4034 4035 4036 4037 4038 4039 |
Tcl_DecrRefCount(resultPtr);
goto namespaceOriginError;
}
Tcl_SetObjResult(interp, resultPtr);
return TCL_OK;
namespaceOriginError:
| | | | | | 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 |
Tcl_DecrRefCount(resultPtr);
goto namespaceOriginError;
}
Tcl_SetObjResult(interp, resultPtr);
return TCL_OK;
namespaceOriginError:
TclPrintfResult(interp,
"invalid command name \"%s\"", TclGetString(objv[1]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "COMMAND",
TclGetString(objv[1]));
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* NamespaceParentCmd --
|
| ︙ | ︙ | |||
5051 5052 5053 5054 5055 5056 5057 |
}
}
if (length < 0) {
length = strlen(command);
}
overflow = (length > limit);
| | | | | | 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 |
}
}
if (length < 0) {
length = strlen(command);
}
overflow = (length > limit);
TclPrintfErrorInfo(interp, "\n %s\n\"%.*s%s\"",
((iPtr->errorInfo == NULL)
? "while executing" : "invoked from within"),
(overflow ? limit : (int)length), command,
(overflow ? "..." : ""));
varPtr = TclObjLookupVarEx(interp, iPtr->eiVar, NULL, TCL_GLOBAL_ONLY,
NULL, 0, 0, &arrayPtr);
if ((varPtr == NULL) || !TclIsVarTraced(varPtr)) {
/*
* Should not happen.
*/
|
| ︙ | ︙ |
Changes to generic/tclOO.c.
| ︙ | ︙ | |||
1848 1849 1850 1851 1852 1853 1854 |
contextPtr->skip = skip;
/*
* Adjust the ensemble tracking record if necessary. [Bug 3514761]
*/
if (TclInitRewriteEnsemble(interp, skip, skip, objv)) {
| | | 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 |
contextPtr->skip = skip;
/*
* Adjust the ensemble tracking record if necessary. [Bug 3514761]
*/
if (TclInitRewriteEnsemble(interp, skip, skip, objv)) {
TclNRAddCallback(interp, TclClearRootEnsemble);
}
/*
* Fire off the constructors non-recursively.
*/
TclNRAddCallback(interp, FinalizeAlloc, contextPtr, oPtr, state,
|
| ︙ | ︙ | |||
1885 1886 1887 1888 1889 1890 1891 |
/*
* Disallow creation of an object over an existing command.
*/
hPtr = Tcl_FindHashEntry(&nsPtr->cmdTable, simpleName);
if (hPtr) {
| | | | 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 |
/*
* Disallow creation of an object over an existing command.
*/
hPtr = Tcl_FindHashEntry(&nsPtr->cmdTable, simpleName);
if (hPtr) {
TclPrintfResult(interp,
"can't create object \"%s\": command already exists with"
" that name", nameStr);
OO_ERROR(interp, OVERWRITE_OBJECT);
return NULL;
}
}
/*
* Create the object.
|
| ︙ | ︙ | |||
1943 1944 1945 1946 1947 1948 1949 |
/*
* Ensure an error if the object was deleted in the constructor. Don't
* want to lose errors by accident. [Bug 2903011]
*/
if (result != TCL_ERROR && Destructing(oPtr)) {
| < | | 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 |
/*
* Ensure an error if the object was deleted in the constructor. Don't
* want to lose errors by accident. [Bug 2903011]
*/
if (result != TCL_ERROR && Destructing(oPtr)) {
TclPrintfResult(interp, "object deleted in constructor");
OO_ERROR(interp, STILLBORN);
result = TCL_ERROR;
}
if (result != TCL_OK) {
Tcl_DiscardInterpState(state);
/*
|
| ︙ | ︙ | |||
2014 2015 2016 2017 2018 2019 2020 |
int result;
/*
* Sanity check.
*/
if (IsRootClass(oPtr)) {
| < | | 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 |
int result;
/*
* Sanity check.
*/
if (IsRootClass(oPtr)) {
TclPrintfResult(interp, "may not clone the class of classes");
OO_ERROR(interp, CLONING_CLASS);
return NULL;
}
/*
* Build the instance. Note that this does not run any constructors.
*/
|
| ︙ | ︙ | |||
2779 2780 2781 2782 2783 2784 2785 |
Tcl_IncrRefCount(mappedMethodName);
contextPtr = TclOOGetCallContext(oPtr, mappedMethodName,
flags | (oPtr->flags & FILTER_HANDLING), callerObjPtr,
callerClsPtr, methodNamePtr);
TclDecrRefCount(mappedMethodName);
if (contextPtr == NULL) {
| | | | | | | | | | 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 |
Tcl_IncrRefCount(mappedMethodName);
contextPtr = TclOOGetCallContext(oPtr, mappedMethodName,
flags | (oPtr->flags & FILTER_HANDLING), callerObjPtr,
callerClsPtr, methodNamePtr);
TclDecrRefCount(mappedMethodName);
if (contextPtr == NULL) {
TclPrintfResult(interp,
"impossible to invoke method \"%s\": no defined method or"
" unknown method", TclGetString(methodNamePtr));
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD_MAPPED",
TclGetString(methodNamePtr));
return TCL_ERROR;
}
} else {
/*
* Get the call chain.
*/
noMapping:
contextPtr = TclOOGetCallContext(oPtr, methodNamePtr,
flags | (oPtr->flags & FILTER_HANDLING), callerObjPtr,
callerClsPtr, NULL);
if (contextPtr == NULL) {
TclPrintfResult(interp,
"impossible to invoke method \"%s\": no defined method or"
" unknown method", TclGetString(methodNamePtr));
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD",
TclGetString(methodNamePtr));
return TCL_ERROR;
}
}
/*
* Check to see if we need to apply magical tricks to start part way
* through the call chain.
|
| ︙ | ︙ | |||
2823 2824 2825 2826 2827 2828 2829 |
continue;
}
if (miPtr->mPtr->declaringClassPtr == startCls) {
break;
}
}
if (contextPtr->index >= contextPtr->callPtr->numChain) {
| < | | | | | 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 |
continue;
}
if (miPtr->mPtr->declaringClassPtr == startCls) {
break;
}
}
if (contextPtr->index >= contextPtr->callPtr->numChain) {
TclPrintfResult(interp, "no valid method implementation");
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD",
TclGetString(methodNamePtr));
TclOODeleteContext(contextPtr);
return TCL_ERROR;
}
}
/*
* Invoke the call chain, locking the object structure against deletion
* for the duration.
*/
TclNRAddCallback(interp, FinalizeObjectCall, contextPtr);
return TclOOInvokeContext(contextPtr, interp, objc, objv);
}
static int
FinalizeObjectCall(
void *data[],
TCL_UNUSED(Tcl_Interp *),
|
| ︙ | ︙ | |||
2905 2906 2907 2908 2909 2910 2911 |
methodType = "constructor";
} else if (contextPtr->callPtr->flags & DESTRUCTOR) {
methodType = "destructor";
} else {
methodType = "method";
}
| < | | 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 |
methodType = "constructor";
} else if (contextPtr->callPtr->flags & DESTRUCTOR) {
methodType = "destructor";
} else {
methodType = "method";
}
TclPrintfResult(interp, "no next %s implementation", methodType);
OO_ERROR(interp, NOTHING_NEXT);
return TCL_ERROR;
}
/*
* Advance to the next method implementation in the chain in the method
* call context while we process the body. However, need to adjust the
|
| ︙ | ︙ | |||
2974 2975 2976 2977 2978 2979 2980 |
methodType = "constructor";
} else if (contextPtr->callPtr->flags & DESTRUCTOR) {
methodType = "destructor";
} else {
methodType = "method";
}
| < | | | 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 |
methodType = "constructor";
} else if (contextPtr->callPtr->flags & DESTRUCTOR) {
methodType = "destructor";
} else {
methodType = "method";
}
TclPrintfResult(interp, "no next %s implementation", methodType);
OO_ERROR(interp, NOTHING_NEXT);
return TCL_ERROR;
}
/*
* Advance to the next method implementation in the chain in the method
* call context while we process the body. However, need to adjust the
* argument-skip control because we're guaranteed to have a single prefix
* arg (i.e., 'next') and not the variable amount that can happen because
* method invocations (i.e., '$obj meth' and 'my meth'), constructors
* (i.e., '$cls new' and '$cls create obj') and destructors (no args at
* all) come through the same code.
*/
TclNRAddCallback(interp, FinalizeNext, contextPtr,
INT2PTR(contextPtr->index), INT2PTR(contextPtr->skip));
contextPtr->index++;
contextPtr->skip = skip;
/*
* Invoke the (advanced) method call context in the caller context.
*/
|
| ︙ | ︙ | |||
3052 3053 3054 3055 3056 3057 3058 |
if (cmdPtr == NULL || cmdPtr->objProc != TclOOPublicObjectCmd) {
goto notAnObject;
}
}
return (Tcl_Object) cmdPtr->objClientData;
notAnObject:
| | | | < | 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 |
if (cmdPtr == NULL || cmdPtr->objProc != TclOOPublicObjectCmd) {
goto notAnObject;
}
}
return (Tcl_Object) cmdPtr->objClientData;
notAnObject:
TclPrintfResult(interp,
"%s does not refer to an object", TclGetString(objPtr));
TclSetErrorCode(interp, "TCL", "LOOKUP", "OBJECT", TclGetString(objPtr));
return NULL;
}
/*
* ----------------------------------------------------------------------
*
* TclOOIsReachable --
|
| ︙ | ︙ |
Changes to generic/tclOOBasic.c.
| ︙ | ︙ | |||
42 43 44 45 46 47 48 |
* ----------------------------------------------------------------------
*/
static inline Tcl_Object *
AddConstructionFinalizer(
Tcl_Interp *interp)
{
| | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
* ----------------------------------------------------------------------
*/
static inline Tcl_Object *
AddConstructionFinalizer(
Tcl_Interp *interp)
{
TclNRAddCallback(interp, FinalizeConstruction);
return (Tcl_Object *) &(TOP_CB(interp)->data[0]);
}
static int
FinalizeConstruction(
void *data[],
Tcl_Interp *interp,
|
| ︙ | ︙ | |||
128 129 130 131 132 133 134 |
* Must add references or errors in configuration script will cause
* trouble.
*/
Tcl_IncrRefCount(invoke[0]);
Tcl_IncrRefCount(invoke[1]);
Tcl_IncrRefCount(invoke[2]);
| | < | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
* Must add references or errors in configuration script will cause
* trouble.
*/
Tcl_IncrRefCount(invoke[0]);
Tcl_IncrRefCount(invoke[1]);
Tcl_IncrRefCount(invoke[2]);
TclNRAddCallback(interp, DecrRefsPostClassConstructor, invoke, oPtr);
/*
* Tricky point: do not want the extra reported level in the Tcl stack
* trace, so use TCL_EVAL_NOERR.
*/
return TclNREvalObjv(interp, 3, invoke, TCL_EVAL_NOERR, NULL);
|
| ︙ | ︙ | |||
200 201 202 203 204 205 206 |
* Sanity check; should not be possible to invoke this method on a
* non-class.
*/
if (oPtr->classPtr == NULL) {
Tcl_Obj *cmdnameObj = TclOOObjectName(interp, oPtr);
| | | < | | 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
* Sanity check; should not be possible to invoke this method on a
* non-class.
*/
if (oPtr->classPtr == NULL) {
Tcl_Obj *cmdnameObj = TclOOObjectName(interp, oPtr);
TclPrintfResult(interp,
"object \"%s\" is not a class", TclGetString(cmdnameObj));
OO_ERROR(interp, INSTANTIATE_NONCLASS);
return TCL_ERROR;
}
/*
* Check we have the right number of (sensible) arguments.
*/
if (objc < 1 + Tcl_ObjectContextSkippedArgs(context)) {
Tcl_WrongNumArgs(interp, Tcl_ObjectContextSkippedArgs(context), objv,
"objectName ?arg ...?");
return TCL_ERROR;
}
objName = Tcl_GetStringFromObj(
objv[Tcl_ObjectContextSkippedArgs(context)], &len);
if (len == 0) {
TclPrintfResult(interp, "object name must not be empty");
OO_ERROR(interp, EMPTY_NAME);
return TCL_ERROR;
}
/*
* Make the object and return its name.
*/
|
| ︙ | ︙ | |||
265 266 267 268 269 270 271 |
* Sanity check; should not be possible to invoke this method on a
* non-class.
*/
if (oPtr->classPtr == NULL) {
Tcl_Obj *cmdnameObj = TclOOObjectName(interp, oPtr);
| | | < | < | | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
* Sanity check; should not be possible to invoke this method on a
* non-class.
*/
if (oPtr->classPtr == NULL) {
Tcl_Obj *cmdnameObj = TclOOObjectName(interp, oPtr);
TclPrintfResult(interp,
"object \"%s\" is not a class", TclGetString(cmdnameObj));
OO_ERROR(interp, INSTANTIATE_NONCLASS);
return TCL_ERROR;
}
/*
* Check we have the right number of (sensible) arguments.
*/
if (objc + 1 < Tcl_ObjectContextSkippedArgs(context) + 3) {
Tcl_WrongNumArgs(interp, Tcl_ObjectContextSkippedArgs(context), objv,
"objectName namespaceName ?arg ...?");
return TCL_ERROR;
}
objName = Tcl_GetStringFromObj(
objv[Tcl_ObjectContextSkippedArgs(context)], &len);
if (len == 0) {
TclPrintfResult(interp, "object name must not be empty");
OO_ERROR(interp, EMPTY_NAME);
return TCL_ERROR;
}
nsName = Tcl_GetStringFromObj(
objv[Tcl_ObjectContextSkippedArgs(context) + 1], &len);
if (len == 0) {
TclPrintfResult(interp, "namespace name must not be empty");
OO_ERROR(interp, EMPTY_NAME);
return TCL_ERROR;
}
/*
* Make the object and return its name.
*/
|
| ︙ | ︙ | |||
336 337 338 339 340 341 342 |
* Sanity check; should not be possible to invoke this method on a
* non-class.
*/
if (oPtr->classPtr == NULL) {
Tcl_Obj *cmdnameObj = TclOOObjectName(interp, oPtr);
| | | | 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
* Sanity check; should not be possible to invoke this method on a
* non-class.
*/
if (oPtr->classPtr == NULL) {
Tcl_Obj *cmdnameObj = TclOOObjectName(interp, oPtr);
TclPrintfResult(interp,
"object \"%s\" is not a class", TclGetString(cmdnameObj));
OO_ERROR(interp, INSTANTIATE_NONCLASS);
return TCL_ERROR;
}
/*
* Make the object and return its name.
*/
|
| ︙ | ︙ | |||
385 386 387 388 389 390 391 |
if (!(oPtr->flags & DESTRUCTOR_CALLED)) {
oPtr->flags |= DESTRUCTOR_CALLED;
contextPtr = TclOOGetCallContext(oPtr, NULL, DESTRUCTOR, NULL, NULL,
NULL);
if (contextPtr != NULL) {
contextPtr->callPtr->flags |= DESTRUCTOR;
contextPtr->skip = 0;
| | < | 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
if (!(oPtr->flags & DESTRUCTOR_CALLED)) {
oPtr->flags |= DESTRUCTOR_CALLED;
contextPtr = TclOOGetCallContext(oPtr, NULL, DESTRUCTOR, NULL, NULL,
NULL);
if (contextPtr != NULL) {
contextPtr->callPtr->flags |= DESTRUCTOR;
contextPtr->skip = 0;
TclNRAddCallback(interp, AfterNRDestructor, contextPtr);
TclPushTailcallPoint(interp);
return TclOOInvokeContext(contextPtr, interp, 0, NULL);
}
}
if (oPtr->command) {
Tcl_DeleteCommandFromToken(interp, oPtr->command);
}
|
| ︙ | ︙ | |||
480 481 482 483 484 485 486 |
}
/*
* Evaluate the script now, with FinalizeEval to do the processing after
* the script completes.
*/
| | < | | | 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
}
/*
* Evaluate the script now, with FinalizeEval to do the processing after
* the script completes.
*/
TclNRAddCallback(interp, FinalizeEval, object);
return TclNREvalObjEx(interp, scriptPtr, 0, invoker, skip);
}
static int
FinalizeEval(
void *data[],
Tcl_Interp *interp,
int result)
{
if (result == TCL_ERROR) {
Object *oPtr = (Object *) data[0];
const char *namePtr;
if (oPtr) {
namePtr = TclGetString(TclOOObjectName(interp, oPtr));
} else {
namePtr = "my";
}
TclPrintfErrorInfo(interp, "\n (in \"%s eval\" script line %d)",
namePtr, Tcl_GetErrorLine(interp));
}
/*
* Restore the previous "current" namespace.
*/
TclPopStackFrame(interp);
|
| ︙ | ︙ | |||
595 596 597 598 599 600 601 |
const char *piece;
if (contextPtr->callPtr->flags & PUBLIC_METHOD) {
piece = "visible methods";
} else {
piece = "methods";
}
| | | | | | | | < | 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 |
const char *piece;
if (contextPtr->callPtr->flags & PUBLIC_METHOD) {
piece = "visible methods";
} else {
piece = "methods";
}
TclPrintfResult(interp,
"object \"%s\" has no %s", TclGetString(tmpBuf), piece);
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD",
TclGetString(objv[skip]));
return TCL_ERROR;
}
errorMsg = Tcl_ObjPrintf("unknown method \"%s\": must be ",
TclGetString(objv[skip]));
for (i=0 ; i<numMethodNames-1 ; i++) {
if (i) {
TclAppendLiteralToObj(errorMsg, ", ");
}
Tcl_AppendToObj(errorMsg, methodNames[i], TCL_AUTO_LENGTH);
}
if (i) {
TclAppendLiteralToObj(errorMsg, " or ");
}
Tcl_AppendToObj(errorMsg, methodNames[i], TCL_AUTO_LENGTH);
Tcl_Free((void *)methodNames);
Tcl_SetObjResult(interp, errorMsg);
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD", TclGetString(objv[skip]));
return TCL_ERROR;
}
/*
* ----------------------------------------------------------------------
*
* TclOO_Object_LinkVar --
|
| ︙ | ︙ | |||
671 672 673 674 675 676 677 |
/*
* The variable name must not contain a '::' since that's illegal in
* local names.
*/
if (strstr(varName, "::") != NULL) {
| | | | | 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 |
/*
* The variable name must not contain a '::' since that's illegal in
* local names.
*/
if (strstr(varName, "::") != NULL) {
TclPrintfResult(interp,
"variable name \"%s\" illegal: must not contain namespace"
" separator", varName);
TclSetErrorCode(interp, "TCL", "UPVAR", "INVERTED");
return TCL_ERROR;
}
/*
* Switch to the object's namespace for the duration of this call.
* Like this, the variable is looked up in the namespace of the
* object, and not in the namespace of the caller. Otherwise this
|
| ︙ | ︙ | |||
703 704 705 706 707 708 709 | /* * Variable cannot be an element in an array. If aryPtr is not * NULL, it is an element, so throw up an error and return. */ TclVarErrMsg(interp, varName, NULL, "define", "name refers to an element in an array"); | | | 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 | /* * Variable cannot be an element in an array. If aryPtr is not * NULL, it is an element, so throw up an error and return. */ TclVarErrMsg(interp, varName, NULL, "define", "name refers to an element in an array"); TclSetErrorCode(interp, "TCL", "UPVAR", "LOCAL_ELEMENT"); return TCL_ERROR; } /* * Arrange for the lifetime of the variable to be correctly managed. * This is copied out of Tcl_VariableObjCmd... */ |
| ︙ | ︙ | |||
825 826 827 828 829 830 831 |
}
Tcl_IncrRefCount(varNamePtr);
Tcl_Var var = (Tcl_Var) TclObjLookupVar(interp, varNamePtr, NULL,
TCL_NAMESPACE_ONLY|TCL_LEAVE_ERR_MSG, "refer to", 1, 1,
(Var **) aryPtr);
Tcl_DecrRefCount(varNamePtr);
if (var == NULL) {
| | | 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 |
}
Tcl_IncrRefCount(varNamePtr);
Tcl_Var var = (Tcl_Var) TclObjLookupVar(interp, varNamePtr, NULL,
TCL_NAMESPACE_ONLY|TCL_LEAVE_ERR_MSG, "refer to", 1, 1,
(Var **) aryPtr);
Tcl_DecrRefCount(varNamePtr);
if (var == NULL) {
TclSetErrorCode(interp, "TCL", "LOOKUP", "VARIABLE", arg);
} else if (*aryPtr == NULL && TclIsVarArrayElement((Var *) var)) {
/*
* If the varPtr points to an element of an array but we don't already
* have the array, find it now. Note that this can't be easily
* backported; the arrayPtr field is new in Tcl 9.0. [Bug 2da1cb0c80]
*/
*aryPtr = (Tcl_Var) TclVarParentArray(var);
|
| ︙ | ︙ | |||
927 928 929 930 931 932 933 |
/*
* Start with sanity checks on the calling context to make sure that we
* are invoked from a suitable method context. If so, we can safely
* retrieve the handle to the object call context.
*/
if (framePtr == NULL || !(framePtr->isProcCallFrame & FRAME_IS_METHOD)) {
| | | | | 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 |
/*
* Start with sanity checks on the calling context to make sure that we
* are invoked from a suitable method context. If so, we can safely
* retrieve the handle to the object call context.
*/
if (framePtr == NULL || !(framePtr->isProcCallFrame & FRAME_IS_METHOD)) {
TclPrintfResult(interp,
"%s may only be called from inside a method",
TclGetString(objv[0]));
OO_ERROR(interp, CONTEXT_REQUIRED);
return TCL_ERROR;
}
context = (Tcl_ObjectContext) framePtr->clientData;
/*
* Invoke the (advanced) method call context in the caller context. Note
* that this is like [uplevel 1] and not [eval].
*/
TclNRAddCallback(interp, NextRestoreFrame, framePtr);
iPtr->varFramePtr = framePtr->callerVarPtr;
return TclNRObjectContextInvokeNext(interp, context, objc, objv, 1);
}
int
TclOONextToObjCmd(
TCL_UNUSED(void *),
|
| ︙ | ︙ | |||
967 968 969 970 971 972 973 |
/*
* Start with sanity checks on the calling context to make sure that we
* are invoked from a suitable method context. If so, we can safely
* retrieve the handle to the object call context.
*/
if (framePtr == NULL || !(framePtr->isProcCallFrame & FRAME_IS_METHOD)) {
| | | | | | | 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 |
/*
* Start with sanity checks on the calling context to make sure that we
* are invoked from a suitable method context. If so, we can safely
* retrieve the handle to the object call context.
*/
if (framePtr == NULL || !(framePtr->isProcCallFrame & FRAME_IS_METHOD)) {
TclPrintfResult(interp,
"%s may only be called from inside a method",
TclGetString(objv[0]));
OO_ERROR(interp, CONTEXT_REQUIRED);
return TCL_ERROR;
}
contextPtr = (CallContext *) framePtr->clientData;
/*
* Sanity check the arguments; we need the first one to refer to a class.
*/
if (objc < 2) {
Tcl_WrongNumArgs(interp, 1, objv, "class ?arg...?");
return TCL_ERROR;
}
object = Tcl_GetObjectFromObj(interp, objv[1]);
if (object == NULL) {
return TCL_ERROR;
}
classPtr = ((Object *) object)->classPtr;
if (classPtr == NULL) {
TclPrintfResult(interp,
"\"%s\" is not a class", TclGetString(objv[1]));
OO_ERROR(interp, CLASS_REQUIRED);
return TCL_ERROR;
}
/*
* Search for an implementation of a method associated with the current
* call on the call chain past the point where we currently are. Do not
* allow jumping backwards!
*/
for (i=contextPtr->index+1 ; i<contextPtr->callPtr->numChain ; i++) {
MInvoke *miPtr = &contextPtr->callPtr->chain[i];
if (!miPtr->isFilter && miPtr->mPtr->declaringClassPtr == classPtr) {
/*
* Invoke the (advanced) method call context in the caller
* context. Note that this is like [uplevel 1] and not [eval].
*/
TclNRAddCallback(interp, NextRestoreFrame, framePtr,
contextPtr, INT2PTR(contextPtr->index));
contextPtr->index = i - 1;
iPtr->varFramePtr = framePtr->callerVarPtr;
return TclNRObjectContextInvokeNext(interp,
(Tcl_ObjectContext) contextPtr, objc, objv, 2);
}
}
|
| ︙ | ︙ | |||
1036 1037 1038 1039 1040 1041 1042 |
methodType = "method";
}
for (i=contextPtr->index ; i != TCL_INDEX_NONE ; i--) {
MInvoke *miPtr = &contextPtr->callPtr->chain[i];
if (!miPtr->isFilter && miPtr->mPtr->declaringClassPtr == classPtr) {
| | | | | | 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 |
methodType = "method";
}
for (i=contextPtr->index ; i != TCL_INDEX_NONE ; i--) {
MInvoke *miPtr = &contextPtr->callPtr->chain[i];
if (!miPtr->isFilter && miPtr->mPtr->declaringClassPtr == classPtr) {
TclPrintfResult(interp,
"%s implementation by \"%s\" not reachable from here",
methodType, TclGetString(objv[1]));
OO_ERROR(interp, CLASS_NOT_REACHABLE);
return TCL_ERROR;
}
}
TclPrintfResult(interp,
"%s has no non-filter implementation by \"%s\"",
methodType, TclGetString(objv[1]));
OO_ERROR(interp, CLASS_NOT_THERE);
return TCL_ERROR;
}
static int
NextRestoreFrame(
void *data[],
|
| ︙ | ︙ | |||
1105 1106 1107 1108 1109 1110 1111 |
((contextPtr)->callPtr->chain[(contextPtr)->index])
/*
* Start with sanity checks on the calling context and the method context.
*/
if (framePtr == NULL || !(framePtr->isProcCallFrame & FRAME_IS_METHOD)) {
| | | | 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 |
((contextPtr)->callPtr->chain[(contextPtr)->index])
/*
* Start with sanity checks on the calling context and the method context.
*/
if (framePtr == NULL || !(framePtr->isProcCallFrame & FRAME_IS_METHOD)) {
TclPrintfResult(interp,
"%s may only be called from inside a method",
TclGetString(objv[0]));
OO_ERROR(interp, CONTEXT_REQUIRED);
return TCL_ERROR;
}
contextPtr = (CallContext *) framePtr->clientData;
/*
|
| ︙ | ︙ | |||
1141 1142 1143 1144 1145 1146 1147 |
Tcl_SetObjResult(interp,
TclNewNamespaceObj(contextPtr->oPtr->namespacePtr));
return TCL_OK;
case SELF_CLASS: {
Class *clsPtr = CurrentlyInvoked(contextPtr).mPtr->declaringClassPtr;
if (clsPtr == NULL) {
| < | < | | 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 |
Tcl_SetObjResult(interp,
TclNewNamespaceObj(contextPtr->oPtr->namespacePtr));
return TCL_OK;
case SELF_CLASS: {
Class *clsPtr = CurrentlyInvoked(contextPtr).mPtr->declaringClassPtr;
if (clsPtr == NULL) {
TclPrintfResult(interp, "method not defined by a class");
OO_ERROR(interp, UNMATCHED_CONTEXT);
return TCL_ERROR;
}
Tcl_SetObjResult(interp, TclOOObjectName(interp, clsPtr->thisPtr));
return TCL_OK;
}
case SELF_METHOD:
if (contextPtr->callPtr->flags & CONSTRUCTOR) {
Tcl_SetObjResult(interp, contextPtr->oPtr->fPtr->constructorName);
} else if (contextPtr->callPtr->flags & DESTRUCTOR) {
Tcl_SetObjResult(interp, contextPtr->oPtr->fPtr->destructorName);
} else {
Tcl_SetObjResult(interp,
CurrentlyInvoked(contextPtr).mPtr->namePtr);
}
return TCL_OK;
case SELF_FILTER:
if (!CurrentlyInvoked(contextPtr).isFilter) {
TclPrintfResult(interp, "not inside a filtering context");
OO_ERROR(interp, UNMATCHED_CONTEXT);
return TCL_ERROR;
} else {
MInvoke *miPtr = &CurrentlyInvoked(contextPtr);
Object *oPtr;
const char *type;
|
| ︙ | ︙ | |||
1188 1189 1190 1191 1192 1193 1194 |
result[2] = miPtr->mPtr->namePtr;
Tcl_SetObjResult(interp, Tcl_NewListObj(3, result));
return TCL_OK;
}
case SELF_CALLER:
if ((framePtr->callerVarPtr == NULL) ||
!(framePtr->callerVarPtr->isProcCallFrame & FRAME_IS_METHOD)){
| < | < | | 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 |
result[2] = miPtr->mPtr->namePtr;
Tcl_SetObjResult(interp, Tcl_NewListObj(3, result));
return TCL_OK;
}
case SELF_CALLER:
if ((framePtr->callerVarPtr == NULL) ||
!(framePtr->callerVarPtr->isProcCallFrame & FRAME_IS_METHOD)){
TclPrintfResult(interp, "caller is not an object");
OO_ERROR(interp, CONTEXT_REQUIRED);
return TCL_ERROR;
} else {
CallContext *callerPtr = (CallContext *)
framePtr->callerVarPtr->clientData;
Method *mPtr = callerPtr->callPtr->chain[callerPtr->index].mPtr;
Object *declarerPtr;
if (mPtr->declaringClassPtr != NULL) {
declarerPtr = mPtr->declaringClassPtr->thisPtr;
} else if (mPtr->declaringObjectPtr != NULL) {
declarerPtr = mPtr->declaringObjectPtr;
} else {
/*
* This should be unreachable code.
*/
TclPrintfResult(interp, "method without declarer!");
return TCL_ERROR;
}
result[0] = TclOOObjectName(interp, declarerPtr);
result[1] = TclOOObjectName(interp, callerPtr->oPtr);
if (callerPtr->callPtr->flags & CONSTRUCTOR) {
result[2] = declarerPtr->fPtr->constructorName;
|
| ︙ | ︙ | |||
1239 1240 1241 1242 1243 1244 1245 |
} else if (mPtr->declaringObjectPtr != NULL) {
declarerPtr = mPtr->declaringObjectPtr;
} else {
/*
* This should be unreachable code.
*/
| < | < | | 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 |
} else if (mPtr->declaringObjectPtr != NULL) {
declarerPtr = mPtr->declaringObjectPtr;
} else {
/*
* This should be unreachable code.
*/
TclPrintfResult(interp, "method without declarer!");
return TCL_ERROR;
}
result[0] = TclOOObjectName(interp, declarerPtr);
if (contextPtr->callPtr->flags & CONSTRUCTOR) {
result[1] = declarerPtr->fPtr->constructorName;
} else if (contextPtr->callPtr->flags & DESTRUCTOR) {
result[1] = declarerPtr->fPtr->destructorName;
} else {
result[1] = mPtr->namePtr;
}
Tcl_SetObjResult(interp, Tcl_NewListObj(2, result));
}
return TCL_OK;
case SELF_TARGET:
if (!CurrentlyInvoked(contextPtr).isFilter) {
TclPrintfResult(interp, "not inside a filtering context");
OO_ERROR(interp, UNMATCHED_CONTEXT);
return TCL_ERROR;
} else {
Method *mPtr;
Object *declarerPtr;
Tcl_Size i;
|
| ︙ | ︙ | |||
1284 1285 1286 1287 1288 1289 1290 |
} else if (mPtr->declaringObjectPtr != NULL) {
declarerPtr = mPtr->declaringObjectPtr;
} else {
/*
* This should be unreachable code.
*/
| < | | 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 |
} else if (mPtr->declaringObjectPtr != NULL) {
declarerPtr = mPtr->declaringObjectPtr;
} else {
/*
* This should be unreachable code.
*/
TclPrintfResult(interp, "method without declarer!");
return TCL_ERROR;
}
result[0] = TclOOObjectName(interp, declarerPtr);
result[1] = mPtr->namePtr;
Tcl_SetObjResult(interp, Tcl_NewListObj(2, result));
return TCL_OK;
}
|
| ︙ | ︙ | |||
1364 1365 1366 1367 1368 1369 1370 |
if (objc == 4) {
namespaceName = TclGetString(objv[3]);
if (namespaceName[0] == '\0') {
namespaceName = NULL;
} else if (Tcl_FindNamespace(interp, namespaceName, NULL,
0) != NULL) {
| | | | 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 |
if (objc == 4) {
namespaceName = TclGetString(objv[3]);
if (namespaceName[0] == '\0') {
namespaceName = NULL;
} else if (Tcl_FindNamespace(interp, namespaceName, NULL,
0) != NULL) {
TclPrintfResult(interp,
"%s refers to an existing namespace", namespaceName);
return TCL_ERROR;
}
}
o2Ptr = Tcl_CopyObjectInstance(interp, oPtr, name, namespaceName);
}
|
| ︙ | ︙ |
Changes to generic/tclOOCall.c.
| ︙ | ︙ | |||
353 354 355 356 357 358 359 | } /* * Add a callback to ensure that method references are dropped once * this call is finished. */ | | < | | | 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
}
/*
* Add a callback to ensure that method references are dropped once
* this call is finished.
*/
TclNRAddCallback(interp, FinalizeMethodRefs, contextPtr);
}
/*
* Save whether we were in a filter and set up whether we are now.
*/
if (contextPtr->oPtr->flags & FILTER_HANDLING) {
TclNRAddCallback(interp, SetFilterFlags, contextPtr);
} else {
TclNRAddCallback(interp, ResetFilterFlags, contextPtr);
}
if (isFilter || contextPtr->callPtr->flags & FILTER_HANDLING) {
contextPtr->oPtr->flags |= FILTER_HANDLING;
} else {
contextPtr->oPtr->flags &= ~FILTER_HANDLING;
}
|
| ︙ | ︙ |
Changes to generic/tclOODefineCmds.c.
| ︙ | ︙ | |||
698 699 700 701 702 703 704 |
Tcl_HashEntry *hPtr, *newHPtr = NULL;
Method *mPtr;
int isNew;
if (!useClass) {
if (!oPtr->methodsPtr) {
noSuchMethod:
| | | | | < | | | | 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 |
Tcl_HashEntry *hPtr, *newHPtr = NULL;
Method *mPtr;
int isNew;
if (!useClass) {
if (!oPtr->methodsPtr) {
noSuchMethod:
TclPrintfResult(interp,
"method %s does not exist", TclGetString(fromPtr));
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD",
TclGetString(fromPtr));
return TCL_ERROR;
}
hPtr = Tcl_FindHashEntry(oPtr->methodsPtr, fromPtr);
if (hPtr == NULL) {
goto noSuchMethod;
}
if (toPtr) {
newHPtr = Tcl_CreateHashEntry(oPtr->methodsPtr, toPtr,
&isNew);
if (hPtr == newHPtr) {
renameToSelf:
TclPrintfResult(interp, "cannot rename method to itself");
OO_ERROR(interp, RENAME_TO_SELF);
return TCL_ERROR;
} else if (!isNew) {
renameToExisting:
TclPrintfResult(interp,
"method called %s already exists",
TclGetString(toPtr));
OO_ERROR(interp, RENAME_OVER);
return TCL_ERROR;
}
}
} else {
hPtr = Tcl_FindHashEntry(&oPtr->classPtr->classMethods, fromPtr);
if (hPtr == NULL) {
|
| ︙ | ︙ | |||
788 789 790 791 792 793 794 |
{
Namespace *nsPtr = (Namespace *) Tcl_GetCurrentNamespace(interp);
FOREACH_HASH_DECLS;
Tcl_Size soughtLen;
const char *soughtStr, *nameStr, *matchedStr = NULL;
if (objc < 2) {
| < | | 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 |
{
Namespace *nsPtr = (Namespace *) Tcl_GetCurrentNamespace(interp);
FOREACH_HASH_DECLS;
Tcl_Size soughtLen;
const char *soughtStr, *nameStr, *matchedStr = NULL;
if (objc < 2) {
TclPrintfResult(interp, "bad call of unknown handler");
OO_ERROR(interp, BAD_UNKNOWN);
return TCL_ERROR;
}
if (TclOOGetDefineCmdContext(interp) == NULL) {
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
831 832 833 834 835 836 837 |
result = Tcl_EvalObjv(interp, objc - 1, newObjv, 0);
Tcl_DecrRefCount(newObjv[0]);
TclStackFree(interp, newObjv);
return result;
}
noMatch:
| < | | | 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 |
result = Tcl_EvalObjv(interp, objc - 1, newObjv, 0);
Tcl_DecrRefCount(newObjv[0]);
TclStackFree(interp, newObjv);
return result;
}
noMatch:
TclPrintfResult(interp, "invalid command name \"%s\"", soughtStr);
TclSetErrorCode(interp, "TCL", "LOOKUP", "COMMAND", soughtStr);
return TCL_ERROR;
}
/*
* ----------------------------------------------------------------------
*
* FindCommand --
|
| ︙ | ︙ | |||
921 922 923 924 925 926 927 |
Object *oPtr,
int objc,
Tcl_Obj *const objv[])
{
CallFrame *framePtr, **framePtrPtr = &framePtr;
if (namespacePtr == NULL) {
| < | | 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 |
Object *oPtr,
int objc,
Tcl_Obj *const objv[])
{
CallFrame *framePtr, **framePtrPtr = &framePtr;
if (namespacePtr == NULL) {
TclPrintfResult(interp, "no definition namespace available");
OO_ERROR(interp, MONKEY_BUSINESS);
return TCL_ERROR;
}
/*
* framePtrPtr is needed to satisfy GCC 3.3's strict aliasing rules.
*/
|
| ︙ | ︙ | |||
961 962 963 964 965 966 967 |
{
Interp *iPtr = (Interp *) interp;
Tcl_Object object;
if ((iPtr->varFramePtr == NULL)
|| (iPtr->varFramePtr->isProcCallFrame != FRAME_IS_OO_DEFINE
&& iPtr->varFramePtr->isProcCallFrame != PRIVATE_FRAME)) {
| | | < | | < | | 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 |
{
Interp *iPtr = (Interp *) interp;
Tcl_Object object;
if ((iPtr->varFramePtr == NULL)
|| (iPtr->varFramePtr->isProcCallFrame != FRAME_IS_OO_DEFINE
&& iPtr->varFramePtr->isProcCallFrame != PRIVATE_FRAME)) {
TclPrintfResult(interp,
"this command may only be called from within the context of"
" an ::oo::define or ::oo::objdefine command");
OO_ERROR(interp, MONKEY_BUSINESS);
return NULL;
}
object = (Tcl_Object) iPtr->varFramePtr->clientData;
if (Tcl_ObjectDeleted(object)) {
TclPrintfResult(interp,
"this command cannot be called when the object has been"
" deleted");
OO_ERROR(interp, MONKEY_BUSINESS);
return NULL;
}
return object;
}
Class *
TclOOGetClassDefineCmdContext(
Tcl_Interp *interp)
{
Object *oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return NULL;
}
if (!oPtr->classPtr) {
TclPrintfResult(interp, "attempt to misuse API");
OO_ERROR(interp, MONKEY_BUSINESS);
return NULL;
}
return oPtr->classPtr;
}
/*
|
| ︙ | ︙ | |||
1033 1034 1035 1036 1037 1038 1039 |
oPtr = (Object *) Tcl_GetObjectFromObj(interp, className);
iPtr->varFramePtr = savedFramePtr;
if (oPtr == NULL) {
return NULL;
}
if (oPtr->classPtr == NULL) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(errMsg, TCL_AUTO_LENGTH));
| | | | 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 |
oPtr = (Object *) Tcl_GetObjectFromObj(interp, className);
iPtr->varFramePtr = savedFramePtr;
if (oPtr == NULL) {
return NULL;
}
if (oPtr->classPtr == NULL) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(errMsg, TCL_AUTO_LENGTH));
TclSetErrorCode(interp, "TCL", "LOOKUP", "CLASS",
TclGetString(className));
return NULL;
}
return oPtr->classPtr;
}
static inline Tcl_Namespace *
GetNamespaceInOuterContext(
|
| ︙ | ︙ | |||
1098 1099 1100 1101 1102 1103 1104 |
Tcl_Size length;
Tcl_Obj *realNameObj = Tcl_ObjectDeleted((Tcl_Object) oPtr)
? savedNameObj : TclOOObjectName(interp, oPtr);
const char *objName = TclGetStringFromObj(realNameObj, &length);
int limit = OBJNAME_LENGTH_IN_ERRORINFO_LIMIT;
int overflow = (length > limit);
| | | | 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 |
Tcl_Size length;
Tcl_Obj *realNameObj = Tcl_ObjectDeleted((Tcl_Object) oPtr)
? savedNameObj : TclOOObjectName(interp, oPtr);
const char *objName = TclGetStringFromObj(realNameObj, &length);
int limit = OBJNAME_LENGTH_IN_ERRORINFO_LIMIT;
int overflow = (length > limit);
TclPrintfErrorInfo(interp,
"\n (in definition script for %s \"%.*s%s\" line %d)",
typeOfSubject, (overflow ? limit : (int) length), objName,
(overflow ? "..." : ""), Tcl_GetErrorLine(interp));
}
/*
* ----------------------------------------------------------------------
*
* MagicDefinitionInvoke --
*
|
| ︙ | ︙ | |||
1207 1208 1209 1210 1211 1212 1213 |
}
oPtr = (Object *) Tcl_GetObjectFromObj(interp, objv[1]);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (oPtr->classPtr == NULL) {
| | | | | | 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 |
}
oPtr = (Object *) Tcl_GetObjectFromObj(interp, objv[1]);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (oPtr->classPtr == NULL) {
TclPrintfResult(interp,
"%s does not refer to a class", TclGetString(objv[1]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "CLASS",
TclGetString(objv[1]));
return TCL_ERROR;
}
/*
* Make the oo::define namespace the current namespace and evaluate the
* command(s).
*/
|
| ︙ | ︙ | |||
1530 1531 1532 1533 1534 1535 1536 |
*/
oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (oPtr->flags & ROOT_OBJECT) {
| | | < | | < | | < | 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 |
*/
oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (oPtr->flags & ROOT_OBJECT) {
TclPrintfResult(interp,
"may not modify the class of the root object class");
OO_ERROR(interp, MONKEY_BUSINESS);
return TCL_ERROR;
}
if (oPtr->flags & ROOT_CLASS) {
TclPrintfResult(interp,
"may not modify the class of the class of classes");
OO_ERROR(interp, MONKEY_BUSINESS);
return TCL_ERROR;
}
/*
* Parse the argument to get the class to set the object's class to.
*/
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "className");
return TCL_ERROR;
}
clsPtr = GetClassInOuterContext(interp, objv[1],
"the class of an object must be a class");
if (clsPtr == NULL) {
return TCL_ERROR;
}
if (oPtr == clsPtr->thisPtr) {
TclPrintfResult(interp,
"may not change classes into an instance of themselves");
OO_ERROR(interp, MONKEY_BUSINESS);
return TCL_ERROR;
}
/*
* Set the object's class.
*/
|
| ︙ | ︙ | |||
1700 1701 1702 1703 1704 1705 1706 |
Class *clsPtr = TclOOGetClassDefineCmdContext(interp);
Tcl_Namespace *nsPtr;
Tcl_Obj *nsNamePtr, **storagePtr;
if (clsPtr == NULL) {
return TCL_ERROR;
} else if (clsPtr->thisPtr->flags & (ROOT_OBJECT | ROOT_CLASS)) {
| | | < | 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 |
Class *clsPtr = TclOOGetClassDefineCmdContext(interp);
Tcl_Namespace *nsPtr;
Tcl_Obj *nsNamePtr, **storagePtr;
if (clsPtr == NULL) {
return TCL_ERROR;
} else if (clsPtr->thisPtr->flags & (ROOT_OBJECT | ROOT_CLASS)) {
TclPrintfResult(interp,
"may not modify the definition namespace of the root classes");
OO_ERROR(interp, MONKEY_BUSINESS);
return TCL_ERROR;
}
/*
* Parse the arguments and work out what the user wants to do.
*/
|
| ︙ | ︙ | |||
1778 1779 1780 1781 1782 1783 1784 |
}
oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (!isInstanceDeleteMethod && !oPtr->classPtr) {
| < | | 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 |
}
oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (!isInstanceDeleteMethod && !oPtr->classPtr) {
TclPrintfResult(interp, "attempt to misuse API");
OO_ERROR(interp, MONKEY_BUSINESS);
return TCL_ERROR;
}
for (i = 1; i < objc; i++) {
/*
* Delete the method structure from the appropriate hash table.
|
| ︙ | ︙ | |||
1900 1901 1902 1903 1904 1905 1906 |
oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return TCL_ERROR;
}
clsPtr = oPtr->classPtr;
if (!isInstanceExport && !clsPtr) {
| < | | 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 |
oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return TCL_ERROR;
}
clsPtr = oPtr->classPtr;
if (!isInstanceExport && !clsPtr) {
TclPrintfResult(interp, "attempt to misuse API");
OO_ERROR(interp, MONKEY_BUSINESS);
return TCL_ERROR;
}
for (i = 1; i < objc; i++) {
/*
* Exporting is done by adding the PUBLIC_METHOD flag to the method
|
| ︙ | ︙ | |||
1995 1996 1997 1998 1999 2000 2001 |
}
oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (!isInstanceForward && !oPtr->classPtr) {
| < | | 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 |
}
oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (!isInstanceForward && !oPtr->classPtr) {
TclPrintfResult(interp, "attempt to misuse API");
OO_ERROR(interp, MONKEY_BUSINESS);
return TCL_ERROR;
}
isPublic = Tcl_StringMatch(TclGetString(objv[1]), PUBLIC_PATTERN)
? PUBLIC_METHOD : 0;
if (IsPrivateDefine(interp)) {
isPublic = TRUE_PRIVATE_METHOD;
|
| ︙ | ︙ | |||
2073 2074 2075 2076 2077 2078 2079 |
}
oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (!isInstanceMethod && !oPtr->classPtr) {
| < | | 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 |
}
oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (!isInstanceMethod && !oPtr->classPtr) {
TclPrintfResult(interp, "attempt to misuse API");
OO_ERROR(interp, MONKEY_BUSINESS);
return TCL_ERROR;
}
if (objc == 5) {
if (Tcl_GetIndexFromObj(interp, objv[2], exportModes, "export flag",
0, &exportMode) != TCL_OK) {
return TCL_ERROR;
|
| ︙ | ︙ | |||
2152 2153 2154 2155 2156 2157 2158 |
}
oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (!isInstanceRenameMethod && !oPtr->classPtr) {
| < | | 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 |
}
oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (!isInstanceRenameMethod && !oPtr->classPtr) {
TclPrintfResult(interp, "attempt to misuse API");
OO_ERROR(interp, MONKEY_BUSINESS);
return TCL_ERROR;
}
/*
* Delete the method entry from the appropriate hash table, and transfer
* the thing it points to to its new entry. To do this, we first need to
|
| ︙ | ︙ | |||
2214 2215 2216 2217 2218 2219 2220 |
oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return TCL_ERROR;
}
clsPtr = oPtr->classPtr;
if (!isInstanceUnexport && !clsPtr) {
| < | | 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 |
oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return TCL_ERROR;
}
clsPtr = oPtr->classPtr;
if (!isInstanceUnexport && !clsPtr) {
TclPrintfResult(interp, "attempt to misuse API");
OO_ERROR(interp, MONKEY_BUSINESS);
return TCL_ERROR;
}
for (i = 1; i < objc; i++) {
/*
* Unexporting is done by removing the PUBLIC_METHOD flag from the
|
| ︙ | ︙ | |||
2539 2540 2541 2542 2543 2544 2545 |
"may only mix in classes");
if (mixins[i] == NULL) {
i--;
goto freeAndError;
}
(void) Tcl_CreateHashEntry(&uniqueCheck, (void *) mixins[i], &isNew);
if (!isNew) {
| < | < < | | 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 |
"may only mix in classes");
if (mixins[i] == NULL) {
i--;
goto freeAndError;
}
(void) Tcl_CreateHashEntry(&uniqueCheck, (void *) mixins[i], &isNew);
if (!isNew) {
TclPrintfResult(interp, "class should only be a direct mixin once");
OO_ERROR(interp, REPETITIOUS);
goto freeAndError;
}
if (TclOOIsReachable(clsPtr, mixins[i])) {
TclPrintfResult(interp, "may not mix a class into itself");
OO_ERROR(interp, SELF_MIXIN);
goto freeAndError;
}
}
TclOOClassSetMixins(interp, clsPtr, mixinc, mixins);
Tcl_DeleteHashTable(&uniqueCheck);
|
| ︙ | ︙ | |||
2630 2631 2632 2633 2634 2635 2636 |
"superclassList");
return TCL_ERROR;
}
objv += Tcl_ObjectContextSkippedArgs(context);
Foundation *fPtr = clsPtr->thisPtr->fPtr;
if (clsPtr == fPtr->objectCls) {
| | | < | 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 |
"superclassList");
return TCL_ERROR;
}
objv += Tcl_ObjectContextSkippedArgs(context);
Foundation *fPtr = clsPtr->thisPtr->fPtr;
if (clsPtr == fPtr->objectCls) {
TclPrintfResult(interp,
"may not modify the superclass of the root object");
OO_ERROR(interp, MONKEY_BUSINESS);
return TCL_ERROR;
} else if (TclListObjGetElements(interp, objv[0], &superc,
&superv) != TCL_OK) {
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
2671 2672 2673 2674 2675 2676 2677 |
superclasses[i] = GetClassInOuterContext(interp, superv[i],
"only a class can be a superclass");
if (superclasses[i] == NULL) {
goto failedAfterAlloc;
}
for (j = 0; j < i; j++) {
if (superclasses[j] == superclasses[i]) {
| | | < | | < | 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 |
superclasses[i] = GetClassInOuterContext(interp, superv[i],
"only a class can be a superclass");
if (superclasses[i] == NULL) {
goto failedAfterAlloc;
}
for (j = 0; j < i; j++) {
if (superclasses[j] == superclasses[i]) {
TclPrintfResult(interp,
"class should only be a direct superclass once");
OO_ERROR(interp, REPETITIOUS);
goto failedAfterAlloc;
}
}
if (TclOOIsReachable(clsPtr, superclasses[i])) {
TclPrintfResult(interp,
"attempt to form circular dependency graph");
OO_ERROR(interp, CIRCULARITY);
failedAfterAlloc:
for (; i-- > 0 ;) {
TclOODecrRefCount(superclasses[i]->thisPtr);
}
Tcl_Free(superclasses);
return TCL_ERROR;
|
| ︙ | ︙ | |||
2803 2804 2805 2806 2807 2808 2809 |
return TCL_ERROR;
}
for (i = 0; i < varc; i++) {
const char *varName = TclGetString(varv[i]);
if (strstr(varName, "::") != NULL) {
| | | | | | 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 |
return TCL_ERROR;
}
for (i = 0; i < varc; i++) {
const char *varName = TclGetString(varv[i]);
if (strstr(varName, "::") != NULL) {
TclPrintfResult(interp,
"invalid declared variable name \"%s\": must not %s",
varName, "contain namespace separators");
OO_ERROR(interp, BAD_DECLVAR);
return TCL_ERROR;
}
if (Tcl_StringMatch(varName, "*(*)")) {
TclPrintfResult(interp,
"invalid declared variable name \"%s\": must not %s",
varName, "refer to an array element");
OO_ERROR(interp, BAD_DECLVAR);
return TCL_ERROR;
}
}
if (IsPrivateDefine(interp)) {
InstallPrivateVariableMapping(&clsPtr->privateVariables,
|
| ︙ | ︙ | |||
2978 2979 2980 2981 2982 2983 2984 |
mixins[i] = GetClassInOuterContext(interp, mixinv[i],
"may only mix in classes");
if (mixins[i] == NULL) {
goto freeAndError;
}
(void) Tcl_CreateHashEntry(&uniqueCheck, (void *) mixins[i], &isNew);
if (!isNew) {
| | | < | 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 |
mixins[i] = GetClassInOuterContext(interp, mixinv[i],
"may only mix in classes");
if (mixins[i] == NULL) {
goto freeAndError;
}
(void) Tcl_CreateHashEntry(&uniqueCheck, (void *) mixins[i], &isNew);
if (!isNew) {
TclPrintfResult(interp,
"class should only be a direct mixin once");
OO_ERROR(interp, REPETITIOUS);
goto freeAndError;
}
}
TclOOObjectSetMixins(oPtr, mixinc, mixins);
TclStackFree(interp, mixins);
|
| ︙ | ︙ | |||
3074 3075 3076 3077 3078 3079 3080 |
return TCL_ERROR;
}
for (i = 0; i < varc; i++) {
const char *varName = TclGetString(varv[i]);
if (strstr(varName, "::") != NULL) {
| | | | | | 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 |
return TCL_ERROR;
}
for (i = 0; i < varc; i++) {
const char *varName = TclGetString(varv[i]);
if (strstr(varName, "::") != NULL) {
TclPrintfResult(interp,
"invalid declared variable name \"%s\": must not %s",
varName, "contain namespace separators");
OO_ERROR(interp, BAD_DECLVAR);
return TCL_ERROR;
}
if (Tcl_StringMatch(varName, "*(*)")) {
TclPrintfResult(interp,
"invalid declared variable name \"%s\": must not %s",
varName, "refer to an array element");
OO_ERROR(interp, BAD_DECLVAR);
return TCL_ERROR;
}
}
if (IsPrivateDefine(interp)) {
InstallPrivateVariableMapping(&oPtr->privateVariables, varc, varv,
|
| ︙ | ︙ |
Changes to generic/tclOOInfo.c.
| ︙ | ︙ | |||
162 163 164 165 166 167 168 |
{
Object *oPtr = (Object *) Tcl_GetObjectFromObj(interp, objPtr);
if (oPtr == NULL) {
return NULL;
}
if (oPtr->classPtr == NULL) {
| | | | | | 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
{
Object *oPtr = (Object *) Tcl_GetObjectFromObj(interp, objPtr);
if (oPtr == NULL) {
return NULL;
}
if (oPtr->classPtr == NULL) {
TclPrintfResult(interp,
"\"%s\" is not a class", TclGetString(objPtr));
TclSetErrorCode(interp, "TCL", "LOOKUP", "CLASS",
TclGetString(objPtr));
return NULL;
}
return oPtr->classPtr;
}
/*
* ----------------------------------------------------------------------
|
| ︙ | ︙ | |||
300 301 302 303 304 305 306 |
return TCL_OK;
/*
* Errors...
*/
unknownMethod:
| < | | < | | < | < | 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
return TCL_OK;
/*
* Errors...
*/
unknownMethod:
TclPrintfResult(interp, "unknown method \"%s\"", TclGetString(objv[2]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD", TclGetString(objv[2]));
return TCL_ERROR;
wrongType:
TclPrintfResult(interp,
"definition not available for this kind of method");
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD", TclGetString(objv[2]));
return TCL_ERROR;
}
/*
* ----------------------------------------------------------------------
*
* InfoObjectFiltersCmd --
|
| ︙ | ︙ | |||
409 410 411 412 413 414 415 |
return TCL_OK;
/*
* Errors...
*/
unknownMethod:
| | | | < | | < | < | 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
return TCL_OK;
/*
* Errors...
*/
unknownMethod:
TclPrintfResult(interp,
"unknown method \"%s\"", TclGetString(objv[2]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD", TclGetString(objv[2]));
return TCL_ERROR;
wrongType:
TclPrintfResult(interp,
"prefix argument list not available for this kind of method");
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD", TclGetString(objv[2]));
return TCL_ERROR;
}
/*
* ----------------------------------------------------------------------
*
* InfoObjectIsACmd --
|
| ︙ | ︙ | |||
613 614 615 616 617 618 619 |
flag = PRIVATE_METHOD;
break;
case OPT_PRIVATE:
flag = 0;
break;
case OPT_SCOPE:
if (++i >= objc) {
| < | | < | 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
flag = PRIVATE_METHOD;
break;
case OPT_PRIVATE:
flag = 0;
break;
case OPT_SCOPE:
if (++i >= objc) {
TclPrintfResult(interp, "missing option for -scope");
TclSetErrorCode(interp, "TCL", "ARGUMENT", "MISSING");
return TCL_ERROR;
}
if (Tcl_GetIndexFromObj(interp, objv[i], scopes, "scope", 0,
&scope) != TCL_OK) {
return TCL_ERROR;
}
break;
|
| ︙ | ︙ | |||
739 740 741 742 743 744 745 |
}
Tcl_SetObjResult(interp,
Tcl_NewStringObj(mPtr->typePtr->name, TCL_AUTO_LENGTH));
return TCL_OK;
unknownMethod:
| < | | < | 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 |
}
Tcl_SetObjResult(interp,
Tcl_NewStringObj(mPtr->typePtr->name, TCL_AUTO_LENGTH));
return TCL_OK;
unknownMethod:
TclPrintfResult(interp, "unknown method \"%s\"", TclGetString(objv[2]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD", TclGetString(objv[2]));
return TCL_ERROR;
}
/*
* ----------------------------------------------------------------------
*
* InfoObjectMixinsCmd --
|
| ︙ | ︙ | |||
881 882 883 884 885 886 887 |
if (objc != 2 && objc != 3) {
Tcl_WrongNumArgs(interp, 1, objv, "objName ?-private?");
return TCL_ERROR;
}
if (objc == 3) {
if (strcmp("-private", TclGetString(objv[2])) != 0) {
| | | | 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 |
if (objc != 2 && objc != 3) {
Tcl_WrongNumArgs(interp, 1, objv, "objName ?-private?");
return TCL_ERROR;
}
if (objc == 3) {
if (strcmp("-private", TclGetString(objv[2])) != 0) {
TclPrintfResult(interp,
"option \"%s\" is not exactly \"-private\"",
TclGetString(objv[2]));
OO_ERROR(interp, BAD_ARG);
return TCL_ERROR;
}
isPrivate = 1;
}
oPtr = (Object *) Tcl_GetObjectFromObj(interp, objv[1]);
if (oPtr == NULL) {
|
| ︙ | ︙ | |||
1008 1009 1010 1011 1012 1013 1014 |
return TCL_ERROR;
}
if (clsPtr->constructorPtr == NULL) {
return TCL_OK;
}
procPtr = TclOOGetProcFromMethod(clsPtr->constructorPtr);
if (procPtr == NULL) {
| | | < | 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 |
return TCL_ERROR;
}
if (clsPtr->constructorPtr == NULL) {
return TCL_OK;
}
procPtr = TclOOGetProcFromMethod(clsPtr->constructorPtr);
if (procPtr == NULL) {
TclPrintfResult(interp,
"definition not available for this kind of method");
OO_ERROR(interp, METHOD_TYPE);
return TCL_ERROR;
}
TclNewObj(resultObjs[0]);
for (localPtr=procPtr->firstLocalPtr; localPtr!=NULL;
localPtr=localPtr->nextPtr) {
|
| ︙ | ︙ | |||
1067 1068 1069 1070 1071 1072 1073 |
}
clsPtr = TclOOGetClassFromObj(interp, objv[1]);
if (clsPtr == NULL) {
return TCL_ERROR;
}
hPtr = Tcl_FindHashEntry(&clsPtr->classMethods, objv[2]);
if (hPtr == NULL) {
| | | | < | | < | < | 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 |
}
clsPtr = TclOOGetClassFromObj(interp, objv[1]);
if (clsPtr == NULL) {
return TCL_ERROR;
}
hPtr = Tcl_FindHashEntry(&clsPtr->classMethods, objv[2]);
if (hPtr == NULL) {
TclPrintfResult(interp,
"unknown method \"%s\"", TclGetString(objv[2]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD", TclGetString(objv[2]));
return TCL_ERROR;
}
procPtr = TclOOGetProcFromMethod((Method *) Tcl_GetHashValue(hPtr));
if (procPtr == NULL) {
TclPrintfResult(interp,
"definition not available for this kind of method");
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD", TclGetString(objv[2]));
return TCL_ERROR;
}
TclNewObj(resultObjs[0]);
for (localPtr=procPtr->firstLocalPtr; localPtr!=NULL;
localPtr=localPtr->nextPtr) {
if (TclIsVarArgument(localPtr)) {
|
| ︙ | ︙ | |||
1186 1187 1188 1189 1190 1191 1192 |
}
if (clsPtr->destructorPtr == NULL) {
return TCL_OK;
}
procPtr = TclOOGetProcFromMethod(clsPtr->destructorPtr);
if (procPtr == NULL) {
| | | < | 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 |
}
if (clsPtr->destructorPtr == NULL) {
return TCL_OK;
}
procPtr = TclOOGetProcFromMethod(clsPtr->destructorPtr);
if (procPtr == NULL) {
TclPrintfResult(interp,
"definition not available for this kind of method");
OO_ERROR(interp, METHOD_TYPE);
return TCL_ERROR;
}
Tcl_SetObjResult(interp, TclOOGetMethodBody(clsPtr->destructorPtr));
return TCL_OK;
}
|
| ︙ | ︙ | |||
1266 1267 1268 1269 1270 1271 1272 |
}
clsPtr = TclOOGetClassFromObj(interp, objv[1]);
if (clsPtr == NULL) {
return TCL_ERROR;
}
hPtr = Tcl_FindHashEntry(&clsPtr->classMethods, objv[2]);
if (hPtr == NULL) {
| | | | < | | < | < | 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 |
}
clsPtr = TclOOGetClassFromObj(interp, objv[1]);
if (clsPtr == NULL) {
return TCL_ERROR;
}
hPtr = Tcl_FindHashEntry(&clsPtr->classMethods, objv[2]);
if (hPtr == NULL) {
TclPrintfResult(interp,
"unknown method \"%s\"", TclGetString(objv[2]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD", TclGetString(objv[2]));
return TCL_ERROR;
}
prefixObj = TclOOGetFwdFromMethod((Method *) Tcl_GetHashValue(hPtr));
if (prefixObj == NULL) {
TclPrintfResult(interp,
"prefix argument list not available for this kind of method");
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD", TclGetString(objv[2]));
return TCL_ERROR;
}
Tcl_SetObjResult(interp, prefixObj);
return TCL_OK;
}
|
| ︙ | ︙ | |||
1397 1398 1399 1400 1401 1402 1403 |
flag = PRIVATE_METHOD;
break;
case OPT_PRIVATE:
flag = 0;
break;
case OPT_SCOPE:
if (++i >= objc) {
| < | | < | 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 |
flag = PRIVATE_METHOD;
break;
case OPT_PRIVATE:
flag = 0;
break;
case OPT_SCOPE:
if (++i >= objc) {
TclPrintfResult(interp, "missing option for -scope");
TclSetErrorCode(interp, "TCL", "ARGUMENT", "MISSING");
return TCL_ERROR;
}
if (Tcl_GetIndexFromObj(interp, objv[i], scopes, "scope", 0,
&scope) != TCL_OK) {
return TCL_ERROR;
}
break;
|
| ︙ | ︙ | |||
1512 1513 1514 1515 1516 1517 1518 |
goto unknownMethod;
}
Tcl_SetObjResult(interp,
Tcl_NewStringObj(mPtr->typePtr->name, TCL_AUTO_LENGTH));
return TCL_OK;
unknownMethod:
| < | | < | 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 |
goto unknownMethod;
}
Tcl_SetObjResult(interp,
Tcl_NewStringObj(mPtr->typePtr->name, TCL_AUTO_LENGTH));
return TCL_OK;
unknownMethod:
TclPrintfResult(interp, "unknown method \"%s\"", TclGetString(objv[2]));
TclSetErrorCode(interp, "TCL", "LOOKUP", "METHOD", TclGetString(objv[2]));
return TCL_ERROR;
}
/*
* ----------------------------------------------------------------------
*
* InfoClassMixinsCmd --
|
| ︙ | ︙ | |||
1683 1684 1685 1686 1687 1688 1689 |
if (objc != 2 && objc != 3) {
Tcl_WrongNumArgs(interp, 1, objv, "className ?-private?");
return TCL_ERROR;
}
if (objc == 3) {
if (strcmp("-private", TclGetString(objv[2])) != 0) {
| | | | 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 |
if (objc != 2 && objc != 3) {
Tcl_WrongNumArgs(interp, 1, objv, "className ?-private?");
return TCL_ERROR;
}
if (objc == 3) {
if (strcmp("-private", TclGetString(objv[2])) != 0) {
TclPrintfResult(interp,
"option \"%s\" is not exactly \"-private\"",
TclGetString(objv[2]));
OO_ERROR(interp, BAD_ARG);
return TCL_ERROR;
}
isPrivate = 1;
}
clsPtr = TclOOGetClassFromObj(interp, objv[1]);
if (clsPtr == NULL) {
|
| ︙ | ︙ | |||
1750 1751 1752 1753 1754 1755 1756 |
/*
* Get the call context and render its call chain.
*/
contextPtr = TclOOGetCallContext(oPtr, objv[2], PUBLIC_METHOD, NULL, NULL,
NULL);
if (contextPtr == NULL) {
| < | | 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 |
/*
* Get the call context and render its call chain.
*/
contextPtr = TclOOGetCallContext(oPtr, objv[2], PUBLIC_METHOD, NULL, NULL,
NULL);
if (contextPtr == NULL) {
TclPrintfResult(interp, "cannot construct any call chain");
OO_ERROR(interp, BAD_CALL_CHAIN);
return TCL_ERROR;
}
Tcl_SetObjResult(interp,
TclOORenderCallChain(interp, contextPtr->callPtr));
TclOODeleteContext(contextPtr);
return TCL_OK;
|
| ︙ | ︙ | |||
1796 1797 1798 1799 1800 1801 1802 |
/*
* Get an render the stereotypical call chain.
*/
callPtr = TclOOGetStereotypeCallChain(clsPtr, objv[2], PUBLIC_METHOD);
if (callPtr == NULL) {
| < | | 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 |
/*
* Get an render the stereotypical call chain.
*/
callPtr = TclOOGetStereotypeCallChain(clsPtr, objv[2], PUBLIC_METHOD);
if (callPtr == NULL) {
TclPrintfResult(interp, "cannot construct any call chain");
OO_ERROR(interp, BAD_CALL_CHAIN);
return TCL_ERROR;
}
Tcl_SetObjResult(interp, TclOORenderCallChain(interp, callPtr));
TclOODeleteChain(callPtr);
return TCL_OK;
}
|
| ︙ | ︙ |
Changes to generic/tclOOInt.h.
| ︙ | ︙ | |||
710 711 712 713 714 715 716 |
} \
} while(0)
/*
* Convenience macro for generating error codes.
*/
#define OO_ERROR(interp, code) \
| | | 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 |
} \
} while(0)
/*
* Convenience macro for generating error codes.
*/
#define OO_ERROR(interp, code) \
TclSetErrorCode((interp), "TCL", "OO", #code)
#endif /* TCL_OO_INTERNAL_H */
/*
* Local Variables:
* mode: c
* c-basic-offset: 4
|
| ︙ | ︙ |
Changes to generic/tclOOMethod.c.
| ︙ | ︙ | |||
883 884 885 886 887 888 889 |
}
}
/*
* Now invoke the body of the method.
*/
| | | 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 |
}
}
/*
* Now invoke the body of the method.
*/
TclNRAddCallback(interp, FinalizePMCall, pmPtr, context, fdPtr);
return TclNRInterpProcCore(interp, fdPtr->nameObj,
Tcl_ObjectContextSkippedArgs(context), fdPtr->errProc);
}
static int
FinalizePMCall(
void *data[],
|
| ︙ | ︙ | |||
1323 1324 1325 1326 1327 1328 1329 |
} else {
objectName = "unknown or deleted";
objectNameLen = 18;
}
if (!special) {
Tcl_Size nameLen;
const char *methodName = TclGetStringFromObj(mPtr->namePtr, &nameLen);
| | | < | | | 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 |
} else {
objectName = "unknown or deleted";
objectNameLen = 18;
}
if (!special) {
Tcl_Size nameLen;
const char *methodName = TclGetStringFromObj(mPtr->namePtr, &nameLen);
TclPrintfErrorInfo(interp,
"\n (%s \"%.*s%s\" method \"%.*s%s\" line %d)",
kindName, ELLIPSIFY(objectName, objectNameLen),
ELLIPSIFY(methodName, nameLen), Tcl_GetErrorLine(interp));
} else {
TclPrintfErrorInfo(interp, "\n (%s \"%.*s%s\" %s line %d)",
kindName, ELLIPSIFY(objectName, objectNameLen), special,
Tcl_GetErrorLine(interp));
}
}
static void
MethodErrorHandler(
Tcl_Interp *interp,
TCL_UNUSED(Tcl_Obj *) /*methodNameObj*/)
|
| ︙ | ︙ | |||
1489 1490 1491 1492 1493 1494 1495 |
Tcl_Size prefixLen;
ForwardMethod *fmPtr;
if (TclListObjLength(interp, prefixObj, &prefixLen) != TCL_OK) {
return NULL;
}
if (prefixLen < 1) {
| < | | 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 |
Tcl_Size prefixLen;
ForwardMethod *fmPtr;
if (TclListObjLength(interp, prefixObj, &prefixLen) != TCL_OK) {
return NULL;
}
if (prefixLen < 1) {
TclPrintfResult(interp, "method forward prefix must be non-empty");
OO_ERROR(interp, BAD_FORWARD);
return NULL;
}
fmPtr = (ForwardMethod *) Tcl_Alloc(sizeof(ForwardMethod));
fmPtr->prefixObj = prefixObj;
Tcl_IncrRefCount(prefixObj);
|
| ︙ | ︙ | |||
1528 1529 1530 1531 1532 1533 1534 |
Tcl_Size prefixLen;
ForwardMethod *fmPtr;
if (TclListObjLength(interp, prefixObj, &prefixLen) != TCL_OK) {
return NULL;
}
if (prefixLen < 1) {
| < | | 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 |
Tcl_Size prefixLen;
ForwardMethod *fmPtr;
if (TclListObjLength(interp, prefixObj, &prefixLen) != TCL_OK) {
return NULL;
}
if (prefixLen < 1) {
TclPrintfResult(interp, "method forward prefix must be non-empty");
OO_ERROR(interp, BAD_FORWARD);
return NULL;
}
fmPtr = (ForwardMethod *) Tcl_Alloc(sizeof(ForwardMethod));
fmPtr->prefixObj = prefixObj;
Tcl_IncrRefCount(prefixObj);
|
| ︙ | ︙ | |||
1576 1577 1578 1579 1580 1581 1582 |
* non-empty list, so there's a whole class of failures ("not a list") we
* can ignore here.
*/
TclListObjGetElements(NULL, fmPtr->prefixObj, &numPrefixes, &prefixObjs);
argObjs = InitEnsembleRewrite(interp, objc, objv, skip,
numPrefixes, prefixObjs, &len);
| | | 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 |
* non-empty list, so there's a whole class of failures ("not a list") we
* can ignore here.
*/
TclListObjGetElements(NULL, fmPtr->prefixObj, &numPrefixes, &prefixObjs);
argObjs = InitEnsembleRewrite(interp, objc, objv, skip,
numPrefixes, prefixObjs, &len);
TclNRAddCallback(interp, FinalizeForwardCall, argObjs);
/*
* NOTE: The combination of direct set of iPtr->lookupNsPtr and the use
* of the TCL_EVAL_NOERR flag results in an evaluation configuration
* very much like TCL_EVAL_INVOKE.
*/
((Interp *) interp)->lookupNsPtr = (Namespace *)
contextPtr->oPtr->namespacePtr;
|
| ︙ | ︙ | |||
1734 1735 1736 1737 1738 1739 1740 |
* how to store the rewrite rules get complex solely because of the case
* where an ensemble rewrites itself out of the picture; when that
* happens, the quality of the error message rewrite falls drastically
* (and unavoidably).
*/
if (TclInitRewriteEnsemble(interp, toRewrite, rewriteLength, objv)) {
| | | 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 |
* how to store the rewrite rules get complex solely because of the case
* where an ensemble rewrites itself out of the picture; when that
* happens, the quality of the error message rewrite falls drastically
* (and unavoidably).
*/
if (TclInitRewriteEnsemble(interp, toRewrite, rewriteLength, objv)) {
TclNRAddCallback(interp, TclClearRootEnsemble);
}
*lengthPtr = len;
return argObjs;
}
/*
* ----------------------------------------------------------------------
|
| ︙ | ︙ |
Changes to generic/tclOOProp.c.
| ︙ | ︙ | |||
105 106 107 108 109 110 111 |
Tcl_IncrRefCount(args[0]);
Tcl_IncrRefCount(args[1]);
code = TclOOPrivateObjectCmd(oPtr, interp, 2, args);
Tcl_DecrRefCount(args[0]);
Tcl_DecrRefCount(args[1]);
switch (code) {
case TCL_BREAK:
| | | | | | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
Tcl_IncrRefCount(args[0]);
Tcl_IncrRefCount(args[1]);
code = TclOOPrivateObjectCmd(oPtr, interp, 2, args);
Tcl_DecrRefCount(args[0]);
Tcl_DecrRefCount(args[1]);
switch (code) {
case TCL_BREAK:
TclPrintfResult(interp,
"property getter for %s did a break", propName);
return TCL_ERROR;
case TCL_CONTINUE:
TclPrintfResult(interp,
"property getter for %s did a continue", propName);
return TCL_ERROR;
default:
return code;
}
}
static inline int
|
| ︙ | ︙ | |||
140 141 142 143 144 145 146 |
Tcl_IncrRefCount(args[2]);
code = TclOOPrivateObjectCmd(oPtr, interp, 3, args);
Tcl_DecrRefCount(args[0]);
Tcl_DecrRefCount(args[1]);
Tcl_DecrRefCount(args[2]);
switch (code) {
case TCL_BREAK:
| | | | | | 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
Tcl_IncrRefCount(args[2]);
code = TclOOPrivateObjectCmd(oPtr, interp, 3, args);
Tcl_DecrRefCount(args[0]);
Tcl_DecrRefCount(args[1]);
Tcl_DecrRefCount(args[2]);
switch (code) {
case TCL_BREAK:
TclPrintfResult(interp,
"property setter for %s did a break", propName);
return TCL_ERROR;
case TCL_CONTINUE:
TclPrintfResult(interp,
"property setter for %s did a continue", propName);
return TCL_ERROR;
default:
return code;
}
}
/* Look up a property full name. */
|
| ︙ | ︙ | |||
212 213 214 215 216 217 218 |
*/
Tcl_InterpState foo = Tcl_SaveInterpState(interp, result);
Tcl_Obj *otherName = GetPropertyName(interp, oPtr,
flags ^ (GPN_WRITABLE | GPN_FALLING_BACK), namePtr, NULL);
result = Tcl_RestoreInterpState(interp, foo);
if (otherName != NULL) {
| | | | 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
*/
Tcl_InterpState foo = Tcl_SaveInterpState(interp, result);
Tcl_Obj *otherName = GetPropertyName(interp, oPtr,
flags ^ (GPN_WRITABLE | GPN_FALLING_BACK), namePtr, NULL);
result = Tcl_RestoreInterpState(interp, foo);
if (otherName != NULL) {
TclPrintfResult(interp,
"property \"%s\" is %s only",
TclGetString(otherName),
(flags & GPN_WRITABLE) ? "read" : "write");
}
}
if (!cachePtr) {
TclStackFree(interp, tablePtr);
}
if (result != TCL_OK) {
return NULL;
|
| ︙ | ︙ | |||
1003 1004 1005 1006 1007 1008 1009 |
return TCL_ERROR;
}
ImplementClassProperty(cls, propName, readable, writable);
}
return TCL_OK;
badProp:
| < | | 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 |
return TCL_ERROR;
}
ImplementClassProperty(cls, propName, readable, writable);
}
return TCL_OK;
badProp:
TclPrintfResult(interp, "bad property name \"%s\": %s", name, reason);
OO_ERROR(interp, PROPERTY_FORMAT);
return TCL_ERROR;
}
/*
* ----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
1046 1047 1048 1049 1050 1051 1052 |
};
Object *oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (!useInstance && !oPtr->classPtr) {
| < | | 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 |
};
Object *oPtr = (Object *) TclOOGetDefineCmdContext(interp);
if (oPtr == NULL) {
return TCL_ERROR;
}
if (!useInstance && !oPtr->classPtr) {
TclPrintfResult(interp, "attempt to misuse API");
OO_ERROR(interp, MONKEY_BUSINESS);
return TCL_ERROR;
}
for (i = 1; i < objc; i++) {
Tcl_Obj *propObj = objv[i], *nextObj, *argObj, *hyphenated;
Tcl_Obj *getterScript = NULL, *setterScript = NULL;
|
| ︙ | ︙ | |||
1073 1074 1075 1076 1077 1078 1079 |
break;
}
if (Tcl_GetIndexFromObj(interp, nextObj, options, "option", 0,
&option) != TCL_OK) {
return TCL_ERROR;
}
if (i + 2 >= objc) {
| | | | | 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 |
break;
}
if (Tcl_GetIndexFromObj(interp, nextObj, options, "option", 0,
&option) != TCL_OK) {
return TCL_ERROR;
}
if (i + 2 >= objc) {
TclPrintfResult(interp,
"missing %s to go with %s option",
(option == OPT_KIND ? "kind value" : "body"),
options[option]);
TclSetErrorCode(interp, "TCL", "WRONGARGS");
return TCL_ERROR;
}
argObj = objv[i + 2];
i += 2;
switch (option) {
case OPT_GET:
getterScript = argObj;
|
| ︙ | ︙ |
Changes to generic/tclObj.c.
| ︙ | ︙ | |||
943 944 945 946 947 948 949 |
* Use the target type's Tcl_SetFromAnyProc to set "objPtr"s internal form
* as appropriate for the target type. This frees the old internal
* representation.
*/
if (typePtr->setFromAnyProc == NULL) {
if (interp) {
| | | | | 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 |
* Use the target type's Tcl_SetFromAnyProc to set "objPtr"s internal form
* as appropriate for the target type. This frees the old internal
* representation.
*/
if (typePtr->setFromAnyProc == NULL) {
if (interp) {
TclPrintfResult(interp,
"can't convert value to type %s", typePtr->name);
TclSetErrorCode(interp, "TCL", "API_ABUSE");
}
return TCL_ERROR;
}
return typePtr->setFromAnyProc(interp, objPtr);
}
|
| ︙ | ︙ | |||
2064 2065 2066 2067 2068 2069 2070 |
}
/* Handle dict separately, because it doesn't have a lengthProc */
if (TclHasInternalRep(objPtr, &tclDictType)) {
Tcl_DictObjSize(NULL, objPtr, &length);
if (length > 0) {
listRep:
if (interp) {
| > | | | 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 |
}
/* Handle dict separately, because it doesn't have a lengthProc */
if (TclHasInternalRep(objPtr, &tclDictType)) {
Tcl_DictObjSize(NULL, objPtr, &length);
if (length > 0) {
listRep:
if (interp) {
TclPrintfResult(interp,
"expected boolean value%s but got a list",
(flags & TCL_NULL_OK) ? " or \"\"" : "");
}
return TCL_ERROR;
}
}
Tcl_ObjTypeLengthProc *lengthProc = TclObjTypeHasProc(objPtr, lengthProc);
if (lengthProc && lengthProc(objPtr) != 1) {
goto listRep;
|
| ︙ | ︙ | |||
2150 2151 2152 2153 2154 2155 2156 |
if (interp != NULL) {
Tcl_Size length;
const char *str = Tcl_GetStringFromObj(objPtr, &length);
Tcl_Obj *msg;
TclNewLiteralStringObj(msg, "expected boolean value but got \"");
Tcl_AppendLimitedToObj(msg, str, length, 50, "");
| | | | 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 |
if (interp != NULL) {
Tcl_Size length;
const char *str = Tcl_GetStringFromObj(objPtr, &length);
Tcl_Obj *msg;
TclNewLiteralStringObj(msg, "expected boolean value but got \"");
Tcl_AppendLimitedToObj(msg, str, length, 50, "");
TclAppendLiteralToObj(msg, "\"");
Tcl_SetObjResult(interp, msg);
TclSetErrorCode(interp, "TCL", "VALUE", "BOOLEAN");
}
return TCL_ERROR;
}
static int
ParseBoolean(
Tcl_Obj *objPtr) /* The object to parse/convert. */
|
| ︙ | ︙ | |||
2439 2440 2441 2442 2443 2444 2445 |
double *dblPtr) /* Place to store resulting double. */
{
Tcl_Size length;
do {
if (TclHasInternalRep(objPtr, &tclDoubleType)) {
if (isnan(objPtr->internalRep.doubleValue)) {
if (interp != NULL) {
| | | | < | 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 |
double *dblPtr) /* Place to store resulting double. */
{
Tcl_Size length;
do {
if (TclHasInternalRep(objPtr, &tclDoubleType)) {
if (isnan(objPtr->internalRep.doubleValue)) {
if (interp != NULL) {
TclPrintfResult(interp,
"floating point value is Not a Number");
TclSetErrorCode(interp, "TCL", "VALUE", "DOUBLE", "NAN");
}
return TCL_ERROR;
}
*dblPtr = (double) objPtr->internalRep.doubleValue;
return TCL_OK;
}
if (TclHasInternalRep(objPtr, &tclIntType)) {
|
| ︙ | ︙ | |||
2466 2467 2468 2469 2470 2471 2472 |
}
/* Handle dict separately, because it doesn't have a lengthProc */
if (TclHasInternalRep(objPtr, &tclDictType)) {
Tcl_DictObjSize(NULL, objPtr, &length);
if (length > 0) {
listRep:
if (interp) {
| | | | 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 |
}
/* Handle dict separately, because it doesn't have a lengthProc */
if (TclHasInternalRep(objPtr, &tclDictType)) {
Tcl_DictObjSize(NULL, objPtr, &length);
if (length > 0) {
listRep:
if (interp) {
TclPrintfResult(interp,
"expected floating-point number but got a list");
}
return TCL_ERROR;
}
}
Tcl_ObjTypeLengthProc *lengthProc = TclObjTypeHasProc(objPtr, lengthProc);
if (lengthProc && lengthProc(objPtr) != 1) {
goto listRep;
|
| ︙ | ︙ | |||
2586 2587 2588 2589 2590 2591 2592 |
long l;
if (TclGetLongFromObj(interp, objPtr, &l) != TCL_OK) {
return TCL_ERROR;
}
if ((ULONG_MAX > UINT_MAX) && ((l > UINT_MAX) || (l < INT_MIN))) {
if (interp != NULL) {
| < | | | | 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 |
long l;
if (TclGetLongFromObj(interp, objPtr, &l) != TCL_OK) {
return TCL_ERROR;
}
if ((ULONG_MAX > UINT_MAX) && ((l > UINT_MAX) || (l < INT_MIN))) {
if (interp != NULL) {
const char *s = "integer value too large to represent";
TclPrintfResult(interp, s);
TclSetErrorCode(interp, "ARITH", "IOVERFLOW", s);
}
return TCL_ERROR;
}
*intPtr = (int) l;
return TCL_OK;
#endif
}
|
| ︙ | ︙ | |||
2709 2710 2711 2712 2713 2714 2715 |
return TCL_OK;
}
goto tooLarge;
}
#endif
if (TclHasInternalRep(objPtr, &tclDoubleType)) {
if (interp != NULL) {
| | | | | 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 |
return TCL_OK;
}
goto tooLarge;
}
#endif
if (TclHasInternalRep(objPtr, &tclDoubleType)) {
if (interp != NULL) {
TclPrintfResult(interp,
"expected integer but got \"%s\"",
TclGetString(objPtr));
TclSetErrorCode(interp, "TCL", "VALUE", "INTEGER");
}
return TCL_ERROR;
}
if (TclHasInternalRep(objPtr, &tclBignumType)) {
/*
* Must check for those bignum values that can fit in a long, even
* when auto-narrowing is enabled. Only those values in the signed
|
| ︙ | ︙ | |||
2753 2754 2755 2756 2757 2758 2759 |
}
}
#ifndef TCL_WIDE_INT_IS_LONG
tooLarge:
#endif
if (interp != NULL) {
const char *s = "integer value too large to represent";
| < | | | | 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 |
}
}
#ifndef TCL_WIDE_INT_IS_LONG
tooLarge:
#endif
if (interp != NULL) {
const char *s = "integer value too large to represent";
TclPrintfResult(interp, s);
TclSetErrorCode(interp, "ARITH", "IOVERFLOW", s);
}
return TCL_ERROR;
}
/* Handle dict separately, because it doesn't have a lengthProc */
if (TclHasInternalRep(objPtr, &tclDictType)) {
Tcl_DictObjSize(NULL, objPtr, &length);
if (length > 0) {
listRep:
if (interp) {
TclPrintfResult(interp, "expected integer but got a list");
}
return TCL_ERROR;
}
}
Tcl_ObjTypeLengthProc *lengthProc = TclObjTypeHasProc(objPtr, lengthProc);
if (lengthProc && lengthProc(objPtr) != 1) {
goto listRep;
|
| ︙ | ︙ | |||
3033 3034 3035 3036 3037 3038 3039 |
do {
if (TclHasInternalRep(objPtr, &tclIntType)) {
*wideIntPtr = objPtr->internalRep.wideValue;
return TCL_OK;
}
if (TclHasInternalRep(objPtr, &tclDoubleType)) {
if (interp != NULL) {
| | | | | 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 |
do {
if (TclHasInternalRep(objPtr, &tclIntType)) {
*wideIntPtr = objPtr->internalRep.wideValue;
return TCL_OK;
}
if (TclHasInternalRep(objPtr, &tclDoubleType)) {
if (interp != NULL) {
TclPrintfResult(interp,
"expected integer but got \"%s\"",
TclGetString(objPtr));
TclSetErrorCode(interp, "TCL", "VALUE", "INTEGER");
}
return TCL_ERROR;
}
if (TclHasInternalRep(objPtr, &tclBignumType)) {
/*
* Must check for those bignum values that can fit in a
* Tcl_WideInt, even when auto-narrowing is enabled.
|
| ︙ | ︙ | |||
3071 3072 3073 3074 3075 3076 3077 |
*wideIntPtr = (Tcl_WideInt)value;
return TCL_OK;
}
}
}
if (interp != NULL) {
const char *s = "integer value too large to represent";
| < | | | | 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 |
*wideIntPtr = (Tcl_WideInt)value;
return TCL_OK;
}
}
}
if (interp != NULL) {
const char *s = "integer value too large to represent";
TclPrintfResult(interp, s);
TclSetErrorCode(interp, "ARITH", "IOVERFLOW", s);
}
return TCL_ERROR;
}
/* Handle dict separately, because it doesn't have a lengthProc */
if (TclHasInternalRep(objPtr, &tclDictType)) {
Tcl_DictObjSize(NULL, objPtr, &length);
if (length > 0) {
listRep:
if (interp) {
TclPrintfResult(interp, "expected integer but got a list");
}
return TCL_ERROR;
}
}
Tcl_ObjTypeLengthProc *lengthProc = TclObjTypeHasProc(objPtr, lengthProc);
if (lengthProc && lengthProc(objPtr) != 1) {
goto listRep;
|
| ︙ | ︙ | |||
3131 3132 3133 3134 3135 3136 3137 |
/* Place to store resulting long. */
{
do {
if (TclHasInternalRep(objPtr, &tclIntType)) {
if (objPtr->internalRep.wideValue < 0) {
wideUIntOutOfRange:
if (interp != NULL) {
| | | | | 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 |
/* Place to store resulting long. */
{
do {
if (TclHasInternalRep(objPtr, &tclIntType)) {
if (objPtr->internalRep.wideValue < 0) {
wideUIntOutOfRange:
if (interp != NULL) {
TclPrintfResult(interp,
"expected unsigned integer but got \"%s\"",
TclGetString(objPtr));
TclSetErrorCode(interp, "TCL", "VALUE", "INTEGER");
}
return TCL_ERROR;
}
*wideUIntPtr = (Tcl_WideUInt)objPtr->internalRep.wideValue;
return TCL_OK;
}
if (TclHasInternalRep(objPtr, &tclDoubleType)) {
|
| ︙ | ︙ | |||
3170 3171 3172 3173 3174 3175 3176 |
}
*wideUIntPtr = (Tcl_WideUInt)value;
return TCL_OK;
}
if (interp != NULL) {
const char *s = "integer value too large to represent";
| < | | | 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 |
}
*wideUIntPtr = (Tcl_WideUInt)value;
return TCL_OK;
}
if (interp != NULL) {
const char *s = "integer value too large to represent";
TclPrintfResult(interp, s);
TclSetErrorCode(interp, "ARITH", "IOVERFLOW", s);
}
return TCL_ERROR;
}
} while (TclParseNumber(interp, objPtr, "integer", NULL, -1, NULL,
TCL_PARSE_INTEGER_ONLY)==TCL_OK);
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
3217 3218 3219 3220 3221 3222 3223 |
do {
if (TclHasInternalRep(objPtr, &tclIntType)) {
*wideIntPtr = objPtr->internalRep.wideValue;
return TCL_OK;
}
if (TclHasInternalRep(objPtr, &tclDoubleType)) {
if (interp != NULL) {
| | | | | 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 |
do {
if (TclHasInternalRep(objPtr, &tclIntType)) {
*wideIntPtr = objPtr->internalRep.wideValue;
return TCL_OK;
}
if (TclHasInternalRep(objPtr, &tclDoubleType)) {
if (interp != NULL) {
TclPrintfResult(interp,
"expected integer but got \"%s\"",
TclGetString(objPtr));
TclSetErrorCode(interp, "TCL", "VALUE", "INTEGER");
}
return TCL_ERROR;
}
if (TclHasInternalRep(objPtr, &tclBignumType)) {
mp_int big;
mp_err err;
|
| ︙ | ︙ | |||
3541 3542 3543 3544 3545 3546 3547 |
objPtr->internalRep.wideValue) != MP_OKAY) {
return TCL_ERROR;
}
return TCL_OK;
}
if (TclHasInternalRep(objPtr, &tclDoubleType)) {
if (interp != NULL) {
| | | | | 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 |
objPtr->internalRep.wideValue) != MP_OKAY) {
return TCL_ERROR;
}
return TCL_OK;
}
if (TclHasInternalRep(objPtr, &tclDoubleType)) {
if (interp != NULL) {
TclPrintfResult(interp,
"expected integer but got \"%s\"",
TclGetString(objPtr));
TclSetErrorCode(interp, "TCL", "VALUE", "INTEGER");
}
return TCL_ERROR;
}
} while (TclParseNumber(interp, objPtr, "integer", NULL, -1, NULL,
TCL_PARSE_INTEGER_ONLY)==TCL_OK);
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
3773 3774 3775 3776 3777 3778 3779 |
}
/* Handle dict separately, because it doesn't have a lengthProc */
if (TclHasInternalRep(objPtr, &tclDictType)) {
Tcl_DictObjSize(NULL, objPtr, &length);
if (length > 0) {
listRep:
if (interp) {
| | | 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 |
}
/* Handle dict separately, because it doesn't have a lengthProc */
if (TclHasInternalRep(objPtr, &tclDictType)) {
Tcl_DictObjSize(NULL, objPtr, &length);
if (length > 0) {
listRep:
if (interp) {
TclPrintfResult(interp, "expected number but got a list");
}
return TCL_ERROR;
}
}
Tcl_ObjTypeLengthProc *lengthProc = TclObjTypeHasProc(objPtr, lengthProc);
if (lengthProc && lengthProc(objPtr) != 1) {
goto listRep;
|
| ︙ | ︙ | |||
3810 3811 3812 3813 3814 3815 3816 |
numBytes = 0;
}
if (numBytes < 0) {
numBytes = strlen(bytes);
}
if (numBytes > INT_MAX) {
if (interp) {
| | | | | 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 |
numBytes = 0;
}
if (numBytes < 0) {
numBytes = strlen(bytes);
}
if (numBytes > INT_MAX) {
if (interp) {
TclPrintfResult(interp,
"max size for a Tcl value (%d bytes) exceeded", INT_MAX);
TclSetErrorCode(interp, "TCL", "MEMORY");
}
return TCL_ERROR;
}
objPtr->bytes = (char *) bytes;
objPtr->length = numBytes;
|
| ︙ | ︙ | |||
4746 4747 4748 4749 4750 4751 4752 |
Tcl_AppendPrintfToObj(descObj, ", internal representation %p:%p",
(void *) objv[1]->internalRep.twoPtrValue.ptr1,
(void *) objv[1]->internalRep.twoPtrValue.ptr2);
}
}
if (objv[1]->bytes) {
| | | | | 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 |
Tcl_AppendPrintfToObj(descObj, ", internal representation %p:%p",
(void *) objv[1]->internalRep.twoPtrValue.ptr1,
(void *) objv[1]->internalRep.twoPtrValue.ptr2);
}
}
if (objv[1]->bytes) {
TclAppendLiteralToObj(descObj, ", string representation \"");
Tcl_AppendLimitedToObj(descObj, objv[1]->bytes, objv[1]->length,
16, "...");
TclAppendLiteralToObj(descObj, "\"");
} else {
TclAppendLiteralToObj(descObj, ", no string representation");
}
Tcl_SetObjResult(interp, descObj);
return TCL_OK;
}
/*
|
| ︙ | ︙ |
Changes to generic/tclParse.c.
| ︙ | ︙ | |||
223 224 225 226 227 228 229 |
if (numBytes < 0 && start) {
numBytes = strlen(start);
}
TclParseInit(interp, start, numBytes, parsePtr);
if ((start == NULL) && (numBytes != 0)) {
if (interp != NULL) {
| < | | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
if (numBytes < 0 && start) {
numBytes = strlen(start);
}
TclParseInit(interp, start, numBytes, parsePtr);
if ((start == NULL) && (numBytes != 0)) {
if (interp != NULL) {
TclPrintfResult(interp, "can't parse a NULL pointer");
}
return TCL_ERROR;
}
parsePtr->commentStart = NULL;
parsePtr->commentSize = 0;
parsePtr->commandStart = NULL;
parsePtr->commandSize = 0;
|
| ︙ | ︙ | |||
277 278 279 280 281 282 283 |
}
/* Are we missing white space after previous word? */
if (scanned == 0) {
if (src[-1] == '"') {
if (interp != NULL) {
| | | | | | 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
}
/* Are we missing white space after previous word? */
if (scanned == 0) {
if (src[-1] == '"') {
if (interp != NULL) {
TclPrintfResult(interp,
"extra characters after close-quote");
}
parsePtr->errorType = TCL_PARSE_QUOTE_EXTRA;
} else {
if (interp != NULL) {
TclPrintfResult(interp,
"extra characters after close-brace");
}
parsePtr->errorType = TCL_PARSE_BRACE_EXTRA;
}
parsePtr->term = src;
error:
Tcl_FreeParse(parsePtr);
parsePtr->commandSize = parsePtr->end - parsePtr->commandStart;
|
| ︙ | ︙ | |||
1157 1158 1159 1160 1161 1162 1163 |
if ((nestedPtr->term < parsePtr->end)
&& (*(nestedPtr->term) == ']')
&& !(nestedPtr->incomplete)) {
break;
}
if (numBytes == 0) {
if (parsePtr->interp != NULL) {
| | | | 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 |
if ((nestedPtr->term < parsePtr->end)
&& (*(nestedPtr->term) == ']')
&& !(nestedPtr->incomplete)) {
break;
}
if (numBytes == 0) {
if (parsePtr->interp != NULL) {
TclPrintfResult(parsePtr->interp,
"missing close-bracket");
}
parsePtr->errorType = TCL_PARSE_MISSING_BRACKET;
parsePtr->term = tokenPtr->start;
parsePtr->incomplete = 1;
TclStackFree(parsePtr->interp, nestedPtr);
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
1403 1404 1405 1406 1407 1408 1409 |
}
numBytes--;
src++;
ch= *src;
}
if (numBytes == 0) {
if (parsePtr->interp != NULL) {
| | | | 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 |
}
numBytes--;
src++;
ch= *src;
}
if (numBytes == 0) {
if (parsePtr->interp != NULL) {
TclPrintfResult(parsePtr->interp,
"missing close-brace for variable name");
}
parsePtr->errorType = TCL_PARSE_MISSING_VAR_BRACE;
parsePtr->term = tokenPtr->start-1;
parsePtr->incomplete = 1;
goto error;
}
tokenPtr->size = src - tokenPtr->start;
|
| ︙ | ︙ | |||
1461 1462 1463 1464 1465 1466 1467 |
if (TCL_OK != ParseTokens(src+1, numBytes-1, TYPE_BAD_ARRAY_INDEX,
TCL_SUBST_ALL, parsePtr)) {
goto error;
}
if (parsePtr->term == src+numBytes){
if (parsePtr->interp != NULL) {
| | < | | | 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 |
if (TCL_OK != ParseTokens(src+1, numBytes-1, TYPE_BAD_ARRAY_INDEX,
TCL_SUBST_ALL, parsePtr)) {
goto error;
}
if (parsePtr->term == src+numBytes){
if (parsePtr->interp != NULL) {
TclPrintfResult(parsePtr->interp, "missing )");
}
parsePtr->errorType = TCL_PARSE_MISSING_PAREN;
parsePtr->term = src;
parsePtr->incomplete = 1;
goto error;
} else if ((*parsePtr->term != ')')){
if (parsePtr->interp != NULL) {
TclPrintfResult(parsePtr->interp,
"invalid character in array index");
}
parsePtr->errorType = TCL_PARSE_SYNTAX;
parsePtr->term = src;
goto error;
}
src = parsePtr->term + 1;
}
|
| ︙ | ︙ | |||
1742 1743 1744 1745 1746 1747 1748 |
* Skip straight to the exit code since we have no interpreter to put
* error message in.
*/
goto error;
}
| < | | 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 |
* Skip straight to the exit code since we have no interpreter to put
* error message in.
*/
goto error;
}
TclPrintfResult(parsePtr->interp, "missing close-brace");
/*
* Guess if the problem is due to comments by searching the source string
* for a possible open brace within the context of a comment. Since we
* aren't performing a full Tcl parse, just look for an open brace
* preceded by a '<whitespace>#' on the same line.
*/
|
| ︙ | ︙ | |||
1766 1767 1768 1769 1770 1771 1772 |
break;
case '\n':
openBrace = 0;
break;
case '#' :
if (openBrace && TclIsSpaceProcM(src[-1])) {
Tcl_AppendToObj(Tcl_GetObjResult(parsePtr->interp),
| | > | 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 |
break;
case '\n':
openBrace = 0;
break;
case '#' :
if (openBrace && TclIsSpaceProcM(src[-1])) {
Tcl_AppendToObj(Tcl_GetObjResult(parsePtr->interp),
": possible unbalanced brace in comment",
TCL_AUTO_LENGTH);
goto error;
}
break;
}
}
}
|
| ︙ | ︙ | |||
1844 1845 1846 1847 1848 1849 1850 |
if (TCL_OK != ParseTokens(start+1, numBytes-1, TYPE_QUOTE, TCL_SUBST_ALL,
parsePtr)) {
goto error;
}
if (*parsePtr->term != '"') {
if (parsePtr->interp != NULL) {
| | < | 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 |
if (TCL_OK != ParseTokens(start+1, numBytes-1, TYPE_QUOTE, TCL_SUBST_ALL,
parsePtr)) {
goto error;
}
if (*parsePtr->term != '"') {
if (parsePtr->interp != NULL) {
TclPrintfResult(parsePtr->interp, "missing \"");
}
parsePtr->errorType = TCL_PARSE_MISSING_QUOTE;
parsePtr->term = start;
parsePtr->incomplete = 1;
goto error;
}
if (termPtr != NULL) {
|
| ︙ | ︙ |
Changes to generic/tclPathObj.c.
| ︙ | ︙ | |||
415 416 417 418 419 420 421 |
}
if (needTrailingSlash) {
if (Tcl_IsShared(retVal)) {
TclDecrRefCount(retVal);
retVal = Tcl_DuplicateObj(retVal);
Tcl_IncrRefCount(retVal);
}
| | | 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
}
if (needTrailingSlash) {
if (Tcl_IsShared(retVal)) {
TclDecrRefCount(retVal);
retVal = Tcl_DuplicateObj(retVal);
Tcl_IncrRefCount(retVal);
}
TclAppendLiteralToObj(retVal, "/");
}
}
/*
* Now we have an absolute path, with no '..', '.' sequences, but it still
* may not be in 'unique' form, depending on the platform. For instance,
* Unix is case-sensitive, so the path is ok. Windows is case-insensitive,
|
| ︙ | ︙ | |||
1350 1351 1352 1353 1354 1355 1356 |
* of no evidence that such a foolish thing exists. This solution was
* chosen so that "JoinPath" operations that pass through either path
* internalrep produce the same results; that is, bugward compatibility. If
* we need to fix that bug here, it needs fixing in TclJoinPath() too.
*/
bytes = TclGetStringFromObj(tail, &length);
if (length == 0) {
| | | 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 |
* of no evidence that such a foolish thing exists. This solution was
* chosen so that "JoinPath" operations that pass through either path
* internalrep produce the same results; that is, bugward compatibility. If
* we need to fix that bug here, it needs fixing in TclJoinPath() too.
*/
bytes = TclGetStringFromObj(tail, &length);
if (length == 0) {
TclAppendLiteralToObj(copy, "/");
} else {
TclpNativeJoinPath(copy, bytes);
}
return copy;
}
/*
|
| ︙ | ︙ | |||
2483 2484 2485 2486 2487 2488 2489 |
if (user == NULL || user[0] == 0) {
/* No user name specified -> current user */
dir = TclGetEnv("HOME", &dirString);
if (dir == NULL) {
if (interp) {
| | | < | < < | | < | 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 |
if (user == NULL || user[0] == 0) {
/* No user name specified -> current user */
dir = TclGetEnv("HOME", &dirString);
if (dir == NULL) {
if (interp) {
TclPrintfResult(interp,
"couldn't find HOME environment variable to expand path");
TclSetErrorCode(interp, "TCL", "VALUE", "PATH", "HOMELESS");
}
return TCL_ERROR;
}
} else {
/* User name specified - ~user */
dir = TclpGetUserHome(user, &dirString);
if (dir == NULL) {
if (interp != NULL) {
TclPrintfResult(interp, "user \"%s\" doesn't exist", user);
TclSetErrorCode(interp, "TCL", "VALUE", "PATH", "NOUSER");
}
return TCL_ERROR;
}
}
if (subPath) {
const char *parts[2];
parts[0] = dir;
|
| ︙ | ︙ |
Changes to generic/tclPipe.c.
| ︙ | ︙ | |||
102 103 104 105 106 107 108 |
if (file == NULL) {
Tcl_Obj *msg;
Tcl_GetChannelError(chan, &msg);
if (msg) {
Tcl_SetObjResult(interp, msg);
} else {
| | | | < | 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
if (file == NULL) {
Tcl_Obj *msg;
Tcl_GetChannelError(chan, &msg);
if (msg) {
Tcl_SetObjResult(interp, msg);
} else {
TclPrintfResult(interp,
"channel \"%s\" wasn't opened for %s",
Tcl_GetChannelName(chan),
((writing) ? "writing" : "reading"));
TclSetErrorCode(interp, "TCL", "OPERATION", "EXEC", "BADCHAN");
}
return NULL;
}
*releasePtr = 1;
if (writing) {
/*
* Be sure to flush output to the file, so that anything written
|
| ︙ | ︙ | |||
138 139 140 141 142 143 144 |
name = Tcl_TranslateFileName(interp, spec, &nameString);
if (name == NULL) {
return NULL;
}
file = TclpOpenFile(name, flags);
Tcl_DStringFree(&nameString);
if (file == NULL) {
| | | | | | | 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
name = Tcl_TranslateFileName(interp, spec, &nameString);
if (name == NULL) {
return NULL;
}
file = TclpOpenFile(name, flags);
Tcl_DStringFree(&nameString);
if (file == NULL) {
TclPrintfResult(interp,
"couldn't %s file \"%s\": %s",
(writing ? "write" : "read"), spec,
Tcl_PosixError(interp));
return NULL;
}
*closePtr = 1;
}
return file;
badLastArg:
TclPrintfResult(interp,
"can't specify \"%s\" as last word in command", arg);
TclSetErrorCode(interp, "TCL", "OPERATION", "EXEC", "SYNTAX");
return NULL;
}
/*
*----------------------------------------------------------------------
*
* Tcl_DetachPids --
|
| ︙ | ︙ | |||
336 337 338 339 340 341 342 |
Tcl_Seek(errorChan, 0, SEEK_SET);
TclNewObj(objPtr);
count = Tcl_ReadChars(errorChan, objPtr, TCL_INDEX_NONE, 0);
if (count == -1) {
result = TCL_ERROR;
Tcl_DecrRefCount(objPtr);
Tcl_ResetResult(interp);
| | | < | | 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
Tcl_Seek(errorChan, 0, SEEK_SET);
TclNewObj(objPtr);
count = Tcl_ReadChars(errorChan, objPtr, TCL_INDEX_NONE, 0);
if (count == -1) {
result = TCL_ERROR;
Tcl_DecrRefCount(objPtr);
Tcl_ResetResult(interp);
TclPrintfResult(interp,
"error reading stderr output file: %s",
Tcl_PosixError(interp));
} else if (count > 0) {
anyErrorInfo = 1;
Tcl_SetObjResult(interp, objPtr);
result = TCL_ERROR;
} else {
Tcl_DecrRefCount(objPtr);
}
}
Tcl_CloseEx(NULL, errorChan, 0);
}
/*
* If a child exited abnormally but didn't output any error information at
* all, generate an error message here.
*/
if ((abnormalExit != 0) && (anyErrorInfo == 0) && (interp != NULL)) {
TclPrintfResult(interp, "child process exited abnormally");
}
return result;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
507 508 509 510 511 512 513 |
switch (*p++) {
case '|':
if (*p == '&') {
p++;
}
if (*p == '\0') {
if ((i == (lastBar + 1)) || (i == (argc - 1))) {
| | | | | | 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
switch (*p++) {
case '|':
if (*p == '&') {
p++;
}
if (*p == '\0') {
if ((i == (lastBar + 1)) || (i == (argc - 1))) {
TclPrintfResult(interp,
"illegal use of | or |& in command");
TclSetErrorCode(interp, "TCL", "OPERATION", "EXEC",
"PIPESYNTAX");
goto error;
}
}
lastBar = i;
cmdCount++;
needCmd = 1;
break;
|
| ︙ | ︙ | |||
535 536 537 538 539 540 541 |
if (*p == '<') {
inputFile = NULL;
inputLiteral = p + 1;
skip = 1;
if (*inputLiteral == '\0') {
inputLiteral = ((i + 1) == argc) ? NULL : argv[i + 1];
if (inputLiteral == NULL) {
| | | | | | 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
if (*p == '<') {
inputFile = NULL;
inputLiteral = p + 1;
skip = 1;
if (*inputLiteral == '\0') {
inputLiteral = ((i + 1) == argc) ? NULL : argv[i + 1];
if (inputLiteral == NULL) {
TclPrintfResult(interp,
"can't specify \"%s\" as last word in command",
argv[i]);
TclSetErrorCode(interp, "TCL", "OPERATION", "EXEC",
"PIPESYNTAX");
goto error;
}
skip = 2;
}
} else {
nextArg = ((i + 1) == argc) ? NULL : argv[i + 1];
inputLiteral = NULL;
|
| ︙ | ︙ | |||
652 653 654 655 656 657 658 |
/*
* Special case handling of 2>@1 to redirect stderr to the
* exec/open output pipe as well. This is meant for the end of
* the command string, otherwise use |& between commands.
*/
if (i != argc-1) {
| | | | | | 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 |
/*
* Special case handling of 2>@1 to redirect stderr to the
* exec/open output pipe as well. This is meant for the end of
* the command string, otherwise use |& between commands.
*/
if (i != argc-1) {
TclPrintfResult(interp,
"must specify \"%s\" as last word in command",
argv[i]);
TclSetErrorCode(interp, "TCL", "OPERATION", "EXEC",
"PIPESYNTAX");
goto error;
}
errorFile = outputFile;
errorToOutput = 2;
skip = 1;
} else {
nextArg = ((i + 1) == argc) ? NULL : argv[i + 1];
|
| ︙ | ︙ | |||
695 696 697 698 699 700 701 |
}
if (needCmd) {
/*
* We had a bar followed only by redirections.
*/
| < | | < | | | | | 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 |
}
if (needCmd) {
/*
* We had a bar followed only by redirections.
*/
TclPrintfResult(interp, "illegal use of | or |& in command");
TclSetErrorCode(interp, "TCL", "OPERATION", "EXEC", "PIPESYNTAX");
goto error;
}
if (inputFile == NULL) {
if (inputLiteral != NULL) {
/*
* The input for the first process is immediate data coming from
* Tcl. Create a temporary file for it and put the data into the
* file.
*/
inputFile = TclpCreateTempFile(inputLiteral);
if (inputFile == NULL) {
TclPrintfResult(interp,
"couldn't create input file for command: %s",
Tcl_PosixError(interp));
goto error;
}
inputClose = 1;
} else if (inPipePtr != NULL) {
/*
* The input for the first process in the pipeline is to come from
* a pipe that can be written from by the caller.
*/
if (TclpCreatePipe(&inputFile, inPipePtr) == 0) {
TclPrintfResult(interp,
"couldn't create input pipe for command: %s",
Tcl_PosixError(interp));
goto error;
}
inputClose = 1;
} else {
/*
* The input for the first process comes from stdin.
*/
|
| ︙ | ︙ | |||
754 755 756 757 758 759 760 |
if (outPipePtr != NULL) {
/*
* Output from the last process in the pipeline is to go to a pipe
* that can be read by the caller.
*/
if (TclpCreatePipe(outPipePtr, &outputFile) == 0) {
| | | | 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 |
if (outPipePtr != NULL) {
/*
* Output from the last process in the pipeline is to go to a pipe
* that can be read by the caller.
*/
if (TclpCreatePipe(outPipePtr, &outputFile) == 0) {
TclPrintfResult(interp,
"couldn't create output pipe for command: %s",
Tcl_PosixError(interp));
goto error;
}
outputClose = 1;
} else {
/*
* The output for the last process goes to stdout.
*/
|
| ︙ | ︙ | |||
794 795 796 797 798 799 800 |
* cause the pipeline to deadlock: we'd be waiting for processes
* to complete before reading stderr, and processes couldn't
* complete because stderr was backed up.
*/
errorFile = TclpCreateTempFile(NULL);
if (errorFile == NULL) {
| | | | 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 |
* cause the pipeline to deadlock: we'd be waiting for processes
* to complete before reading stderr, and processes couldn't
* complete because stderr was backed up.
*/
errorFile = TclpCreateTempFile(NULL);
if (errorFile == NULL) {
TclPrintfResult(interp,
"couldn't create error file for command: %s",
Tcl_PosixError(interp));
goto error;
}
*errFilePtr = errorFile;
} else {
/*
* Errors from the pipeline go to stderr.
*/
|
| ︙ | ︙ | |||
867 868 869 870 871 872 873 |
*/
if (lastArg == argc) {
curOutFile = outputFile;
} else {
argv[lastArg] = NULL;
if (TclpCreatePipe(&pipeIn, &curOutFile) == 0) {
| | | | 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 |
*/
if (lastArg == argc) {
curOutFile = outputFile;
} else {
argv[lastArg] = NULL;
if (TclpCreatePipe(&pipeIn, &curOutFile) == 0) {
TclPrintfResult(interp,
"couldn't create pipe: %s", Tcl_PosixError(interp));
goto error;
}
}
if (joinThisError != 0) {
curErrFile = curOutFile;
} else {
|
| ︙ | ︙ | |||
1048 1049 1050 1051 1052 1053 1054 |
/*
* Verify that the pipes that were created satisfy the readable/writable
* constraints.
*/
if (flags & TCL_ENFORCE_MODE) {
if ((flags & TCL_STDOUT) && (outPipe == NULL)) {
| | | | < | | | < | | | | 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 |
/*
* Verify that the pipes that were created satisfy the readable/writable
* constraints.
*/
if (flags & TCL_ENFORCE_MODE) {
if ((flags & TCL_STDOUT) && (outPipe == NULL)) {
TclPrintfResult(interp,
"can't read output from command:"
" standard output was redirected");
TclSetErrorCode(interp, "TCL", "OPERATION", "EXEC", "BADREDIRECT");
goto error;
}
if ((flags & TCL_STDIN) && (inPipe == NULL)) {
TclPrintfResult(interp,
"can't write input to command:"
" standard input was redirected");
TclSetErrorCode(interp, "TCL", "OPERATION", "EXEC", "BADREDIRECT");
goto error;
}
}
channel = TclpCreateCommandChannel(outPipe, inPipe, errFile,
numPids, pidPtr);
if (channel == NULL) {
TclPrintfResult(interp,
"pipe for command could not be created");
TclSetErrorCode(interp, "TCL", "OPERATION", "EXEC", "NOPIPE");
goto error;
}
return channel;
error:
if (pidPtr) {
Tcl_DetachPids(numPids, pidPtr);
|
| ︙ | ︙ |
Changes to generic/tclPkg.c.
| ︙ | ︙ | |||
185 186 187 188 189 190 191 |
if (res == 0) {
if (clientData != NULL) {
pkgPtr->clientData = clientData;
}
return TCL_OK;
}
| | | | | 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
if (res == 0) {
if (clientData != NULL) {
pkgPtr->clientData = clientData;
}
return TCL_OK;
}
TclPrintfResult(interp,
"conflicting versions provided for package \"%s\": %s, then %s",
name, Tcl_GetString(pkgPtr->version), version);
TclSetErrorCode(interp, "TCL", "PACKAGE", "VERSIONCONFLICT");
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* Tcl_PkgRequire / Tcl_PkgRequireEx / Tcl_PkgRequireProc --
|
| ︙ | ︙ | |||
382 383 384 385 386 387 388 | * * Trouble is that's going to be tricky. We're now using a Tcl library * that's not fully initialized. Functions in it may not work * reliably, so be very careful about adding any other calls here * without checking how they behave when initialization is incomplete. */ | | | | | | 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
*
* Trouble is that's going to be tricky. We're now using a Tcl library
* that's not fully initialized. Functions in it may not work
* reliably, so be very careful about adding any other calls here
* without checking how they behave when initialization is incomplete.
*/
TclPrintfResult(interp,
"Cannot load package \"%s\" in standalone executable:"
" This package is not compiled with stub support", name);
TclSetErrorCode(interp, "TCL", "PACKAGE", "UNSTUBBED");
return NULL;
}
/*
* Translate between old and new API, and defer to the new function.
*/
if (version == NULL) {
if (Tcl_PkgRequireProc(interp, name, 0, NULL, clientDataPtr) == TCL_OK) {
result = Tcl_GetStringResult(interp);
Tcl_ResetResult(interp);
}
} else {
if (exact && TCL_OK
!= CheckVersionAndConvert(interp, version, NULL, NULL)) {
return NULL;
}
ov = Tcl_NewStringObj(version, -1);
if (exact) {
TclAppendStringsToObj(ov, "-", version);
}
Tcl_IncrRefCount(ov);
if (Tcl_PkgRequireProc(interp, name, 1, &ov, clientDataPtr) == TCL_OK) {
result = Tcl_GetStringResult(interp);
Tcl_ResetResult(interp);
}
TclDecrRefCount(ov);
|
| ︙ | ︙ | |||
445 446 447 448 449 450 451 |
void *clientData,
Tcl_Interp *interp,
int reqc,
Tcl_Obj *const reqv[])
{
RequireProcArgs *args = (RequireProcArgs *)clientData;
| | | < | < | | | | | 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
void *clientData,
Tcl_Interp *interp,
int reqc,
Tcl_Obj *const reqv[])
{
RequireProcArgs *args = (RequireProcArgs *)clientData;
TclNRAddCallback(interp, PkgRequireCore,
args->name, INT2PTR(reqc), reqv, args->clientDataPtr);
return TCL_OK;
}
static int
PkgRequireCore(
void *data[],
Tcl_Interp *interp,
TCL_UNUSED(int))
{
const char *name = (const char *)data[0];
int reqc = (int)PTR2INT(data[1]);
Tcl_Obj **reqv = (Tcl_Obj **)data[2];
int code = CheckAllRequirements(interp, reqc, reqv);
Require *reqPtr;
if (code != TCL_OK) {
return code;
}
reqPtr = (Require *)Tcl_Alloc(sizeof(Require));
TclNRAddCallback(interp, PkgRequireCoreCleanup, reqPtr);
reqPtr->clientDataPtr = data[3];
reqPtr->name = name;
reqPtr->pkgPtr = FindPackage(interp, name);
if (reqPtr->pkgPtr->version == NULL) {
TclNRAddCallback(interp, SelectPackage, reqPtr, INT2PTR(reqc), reqv,
PkgRequireCoreStep1);
} else {
TclNRAddCallback(interp,
PkgRequireCoreFinal, reqPtr, INT2PTR(reqc), reqv);
}
return TCL_OK;
}
static int
PkgRequireCoreStep1(
void *data[],
|
| ︙ | ︙ | |||
501 502 503 504 505 506 507 |
/*
* If we've got the package in the DB already, go on to actually loading
* it.
*/
if (reqPtr->pkgPtr->version != NULL) {
| | | | | | | < | | | < | < | | | | | < | 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
/*
* If we've got the package in the DB already, go on to actually loading
* it.
*/
if (reqPtr->pkgPtr->version != NULL) {
TclNRAddCallback(interp,
PkgRequireCoreFinal, reqPtr, INT2PTR(reqc), reqv);
return TCL_OK;
}
/*
* The package is not in the database. If there is a "package unknown"
* command, invoke it.
*/
script = ((Interp *) interp)->packageUnknown;
if (script == NULL) {
/*
* No package unknown script. Move on to finalizing.
*/
TclNRAddCallback(interp,
PkgRequireCoreFinal, reqPtr, INT2PTR(reqc), reqv);
return TCL_OK;
}
/*
* Invoke the "package unknown" script synchronously.
*/
Tcl_DStringInit(&command);
Tcl_DStringAppend(&command, script, -1);
Tcl_DStringAppendElement(&command, name);
AddRequirementsToDString(&command, reqc, reqv);
TclNRAddCallback(interp,
PkgRequireCoreStep2, reqPtr, INT2PTR(reqc), reqv);
Tcl_NREvalObj(interp, Tcl_DStringToObj(&command), TCL_EVAL_GLOBAL);
return TCL_OK;
}
static int
PkgRequireCoreStep2(
void *data[],
Tcl_Interp *interp,
int result)
{
Require *reqPtr = (Require *)data[0];
int reqc = (int)PTR2INT(data[1]);
Tcl_Obj **const reqv = (Tcl_Obj **)data[2];
const char *name = reqPtr->name; /* Name of desired package. */
if ((result != TCL_OK) && (result != TCL_ERROR)) {
TclPrintfResult(interp, "bad return code: %d", result);
TclSetErrorCode(interp, "TCL", "PACKAGE", "BADRESULT");
result = TCL_ERROR;
}
if (result == TCL_ERROR) {
Tcl_AddErrorInfo(interp, "\n (\"package unknown\" script)");
return result;
}
Tcl_ResetResult(interp);
/*
* pkgPtr may now be invalid, so refresh it.
*/
reqPtr->pkgPtr = FindPackage(interp, name);
TclNRAddCallback(interp,
SelectPackage, reqPtr, INT2PTR(reqc), reqv,
(void *)PkgRequireCoreFinal);
return TCL_OK;
}
static int
PkgRequireCoreFinal(
void *data[],
Tcl_Interp *interp,
TCL_UNUSED(int))
{
Require *reqPtr = (Require *)data[0];
int reqc = (int)PTR2INT(data[1]), satisfies;
Tcl_Obj **const reqv = (Tcl_Obj **)data[2];
char *pkgVersionI;
void *clientDataPtr = reqPtr->clientDataPtr;
const char *name = reqPtr->name; /* Name of desired package. */
if (reqPtr->pkgPtr->version == NULL) {
TclPrintfResult(interp, "can't find package %s", name);
TclSetErrorCode(interp, "TCL", "PACKAGE", "UNFOUND");
AddRequirementsToResult(interp, reqc, reqv);
return TCL_ERROR;
}
/*
* Ensure that the provided version meets the current requirements.
*/
if (reqc != 0) {
CheckVersionAndConvert(interp, Tcl_GetString(reqPtr->pkgPtr->version),
&pkgVersionI, NULL);
satisfies = SomeRequirementSatisfied(pkgVersionI, reqc, reqv);
Tcl_Free(pkgVersionI);
if (!satisfies) {
TclPrintfResult(interp,
"version conflict for package \"%s\": have %s, need",
name, Tcl_GetString(reqPtr->pkgPtr->version));
TclSetErrorCode(interp, "TCL", "PACKAGE", "VERSIONCONFLICT");
AddRequirementsToResult(interp, reqc, reqv);
return TCL_ERROR;
}
}
if (clientDataPtr) {
const void **ptr = (const void **) clientDataPtr;
|
| ︙ | ︙ | |||
657 658 659 660 661 662 663 |
/*
* Check whether we're already attempting to load some version of this
* package (circular dependency detection).
*/
if (pkgPtr->clientData != NULL) {
| | | | | 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 |
/*
* Check whether we're already attempting to load some version of this
* package (circular dependency detection).
*/
if (pkgPtr->clientData != NULL) {
TclPrintfResult(interp,
"circular package dependency:"
" attempt to provide %s %s requires %s",
name, (char *) pkgPtr->clientData, name);
AddRequirementsToResult(interp, reqc, reqv);
TclSetErrorCode(interp, "TCL", "PACKAGE", "CIRCULARITY");
return TCL_ERROR;
}
/*
* The package isn't yet present. Search the list of available versions
* and invoke the script for the best available version. We are actually
* locating the best, and the best stable version. One of them is then
|
| ︙ | ︙ | |||
797 798 799 800 801 802 803 |
if ((iPtr->packagePrefer == PKG_PREFER_STABLE)
&& (bestStablePtr != NULL)) {
bestPtr = bestStablePtr;
}
if (bestPtr == NULL) {
| | | | 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 |
if ((iPtr->packagePrefer == PKG_PREFER_STABLE)
&& (bestStablePtr != NULL)) {
bestPtr = bestStablePtr;
}
if (bestPtr == NULL) {
TclNRAddCallback(interp,
(Tcl_NRPostProc *)data[3], reqPtr, INT2PTR(reqc), reqv);
} else {
/*
* We found an ifneeded script for the package. Be careful while
* executing it: this could cause reentrancy, so (a) protect the
* script itself from deletion and (b) don't assume that bestPtr will
* still exist when the script completes.
*/
|
| ︙ | ︙ | |||
828 829 830 831 832 833 834 |
pkgName->nextPtr = pkgFiles->names;
strcpy(pkgName->name, name);
pkgFiles->names = pkgName;
if (bestPtr->pkgIndex) {
TclPkgFileSeen(interp, bestPtr->pkgIndex);
}
reqPtr->versionToProvide = versionToProvide;
| | | | 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 |
pkgName->nextPtr = pkgFiles->names;
strcpy(pkgName->name, name);
pkgFiles->names = pkgName;
if (bestPtr->pkgIndex) {
TclPkgFileSeen(interp, bestPtr->pkgIndex);
}
reqPtr->versionToProvide = versionToProvide;
TclNRAddCallback(interp,
SelectPackageFinal, reqPtr, INT2PTR(reqc), reqv,
data[3]);
Tcl_NREvalObj(interp, Tcl_NewStringObj(bestPtr->script, -1),
TCL_EVAL_GLOBAL);
}
return TCL_OK;
}
|
| ︙ | ︙ | |||
863 864 865 866 867 868 869 |
Tcl_Free(pkgName);
reqPtr->pkgPtr = FindPackage(interp, name);
if (result == TCL_OK) {
Tcl_ResetResult(interp);
if (reqPtr->pkgPtr->version == NULL) {
result = TCL_ERROR;
| | | | < | | | < | | | < | | | 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 |
Tcl_Free(pkgName);
reqPtr->pkgPtr = FindPackage(interp, name);
if (result == TCL_OK) {
Tcl_ResetResult(interp);
if (reqPtr->pkgPtr->version == NULL) {
result = TCL_ERROR;
TclPrintfResult(interp,
"attempt to provide package %s %s failed:"
" no version of package %s provided",
name, versionToProvide, name);
TclSetErrorCode(interp, "TCL", "PACKAGE", "UNPROVIDED");
} else {
char *pvi, *vi;
if (TCL_OK != CheckVersionAndConvert(interp,
Tcl_GetString(reqPtr->pkgPtr->version), &pvi, NULL)) {
result = TCL_ERROR;
} else if (CheckVersionAndConvert(interp,
versionToProvide, &vi, NULL) != TCL_OK) {
Tcl_Free(pvi);
result = TCL_ERROR;
} else {
int res = CompareVersions(pvi, vi, NULL);
Tcl_Free(pvi);
Tcl_Free(vi);
if (res != 0) {
result = TCL_ERROR;
TclPrintfResult(interp,
"attempt to provide package %s %s failed:"
" package %s %s provided instead",
name, versionToProvide,
name, Tcl_GetString(reqPtr->pkgPtr->version));
TclSetErrorCode(interp, "TCL", "PACKAGE", "WRONGPROVIDE");
}
}
}
} else if (result != TCL_ERROR) {
Tcl_Obj *codePtr;
TclNewIntObj(codePtr, result);
TclPrintfResult(interp,
"attempt to provide package %s %s failed:"
" bad return code: %s",
name, versionToProvide, TclGetString(codePtr));
TclSetErrorCode(interp, "TCL", "PACKAGE", "BADRESULT");
TclDecrRefCount(codePtr);
result = TCL_ERROR;
}
if (result == TCL_ERROR) {
TclPrintfErrorInfo(interp, "\n (\"package ifneeded %s %s\" script)",
name, versionToProvide);
}
Tcl_Release(versionToProvide);
if (result != TCL_OK) {
/*
* Take a non-TCL_OK code from the script as an indication the package
* wasn't loaded properly, so the package system should not remember
|
| ︙ | ︙ | |||
935 936 937 938 939 940 941 |
Tcl_DecrRefCount(reqPtr->pkgPtr->version);
reqPtr->pkgPtr->version = NULL;
}
reqPtr->pkgPtr->clientData = NULL;
return result;
}
| | | | 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 |
Tcl_DecrRefCount(reqPtr->pkgPtr->version);
reqPtr->pkgPtr->version = NULL;
}
reqPtr->pkgPtr->clientData = NULL;
return result;
}
TclNRAddCallback(interp,
(Tcl_NRPostProc *)data[3], reqPtr, INT2PTR(reqc), reqv);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* Tcl_PkgPresent / Tcl_PkgPresentEx --
|
| ︙ | ︙ | |||
1009 1010 1011 1012 1013 1014 1015 |
* calling Tcl_PkgRequireEx() to check for us.
*/
const char *foundVersion = Tcl_PkgRequireEx(interp, name, version,
exact, clientDataPtr);
if (foundVersion == NULL) {
| | < < | < | | | 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 |
* calling Tcl_PkgRequireEx() to check for us.
*/
const char *foundVersion = Tcl_PkgRequireEx(interp, name, version,
exact, clientDataPtr);
if (foundVersion == NULL) {
TclSetErrorCode(interp, "TCL", "LOOKUP", "PACKAGE", name);
}
return foundVersion;
}
}
if (version != NULL) {
TclPrintfResult(interp, "package %s %s is not present", name, version);
} else {
TclPrintfResult(interp, "package %s is not present", name);
}
TclSetErrorCode(interp, "TCL", "LOOKUP", "PACKAGE", name);
return NULL;
}
/*
*----------------------------------------------------------------------
*
* Tcl_PackageObjCmd --
|
| ︙ | ︙ | |||
1346 1347 1348 1349 1350 1351 1352 | } /* * Create a new-style requirement for the exact version. */ ov = Tcl_NewStringObj(version, -1); | | | | | | | 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 |
}
/*
* Create a new-style requirement for the exact version.
*/
ov = Tcl_NewStringObj(version, -1);
TclAppendStringsToObj(ov, "-", version);
version = NULL;
argv3 = TclGetString(objv[3]);
Tcl_IncrRefCount(objv[3]);
objvListPtr = Tcl_NewListObj(0, NULL);
Tcl_IncrRefCount(objvListPtr);
Tcl_ListObjAppendElement(interp, objvListPtr, ov);
TclListObjGetElements(interp, objvListPtr, &newobjc, &newObjvPtr);
TclNRAddCallback(interp,
TclNRPackageObjCmdCleanup, objv[3], objvListPtr);
TclNRAddCallback(interp,
PkgRequireCore, (void *) argv3, INT2PTR(newobjc),
newObjvPtr);
return TCL_OK;
} else {
Tcl_Obj *const *newobjv = objv + 3;
newobjc = objc - 3;
if (CheckAllRequirements(interp, objc-3, objv+3) != TCL_OK) {
return TCL_ERROR;
|
| ︙ | ︙ | |||
1382 1383 1384 1385 1386 1387 1388 | * so duplicate them. */ Tcl_ListObjAppendElement(interp, objvListPtr, Tcl_DuplicateObj(newobjv[i])); } TclListObjGetElements(interp, objvListPtr, &newobjc, &newObjvPtr); | | | | | < | 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 |
* so duplicate them.
*/
Tcl_ListObjAppendElement(interp, objvListPtr,
Tcl_DuplicateObj(newobjv[i]));
}
TclListObjGetElements(interp, objvListPtr, &newobjc, &newObjvPtr);
TclNRAddCallback(interp,
TclNRPackageObjCmdCleanup, objv[2], objvListPtr);
TclNRAddCallback(interp,
PkgRequireCore, argv2, INT2PTR(newobjc), newObjvPtr);
return TCL_OK;
}
break;
case PKG_UNKNOWN: {
Tcl_Size length;
if (objc == 2) {
|
| ︙ | ︙ | |||
1746 1747 1748 1749 1750 1751 1752 |
*stable = !hasunstable;
}
return TCL_OK;
}
error:
Tcl_Free(ibuf);
| | | | | 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 |
*stable = !hasunstable;
}
return TCL_OK;
}
error:
Tcl_Free(ibuf);
TclPrintfResult(interp,
"expected version number but got \"%s\"", string);
TclSetErrorCode(interp, "TCL", "VALUE", "VERSION");
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* CompareVersions --
|
| ︙ | ︙ | |||
2009 2010 2011 2012 2013 2014 2015 |
}
if (strchr(dash+1, '-') != NULL) {
/*
* More dashes found after the first. This is wrong.
*/
| | | | | 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 |
}
if (strchr(dash+1, '-') != NULL) {
/*
* More dashes found after the first. This is wrong.
*/
TclPrintfResult(interp,
"expected versionMin-versionMax but got \"%s\"", string);
TclSetErrorCode(interp, "TCL", "VALUE", "VERSIONRANGE");
return TCL_ERROR;
}
/*
* Exactly one dash is present. Copy the string, split at the location of
* dash and check that both parts are versions. Note that the max part can
* be empty. Also note that the string allocated with strdup() must be
|
| ︙ | ︙ |
Changes to generic/tclProc.c.
| ︙ | ︙ | |||
181 182 183 184 185 186 187 |
*/
procName = TclGetString(objv[1]);
TclGetNamespaceForQualName(interp, procName, NULL, 0,
&nsPtr, &altNsPtr, &cxtNsPtr, &simpleName);
if (nsPtr == NULL) {
| | | | | | | | < < | | 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
*/
procName = TclGetString(objv[1]);
TclGetNamespaceForQualName(interp, procName, NULL, 0,
&nsPtr, &altNsPtr, &cxtNsPtr, &simpleName);
if (nsPtr == NULL) {
TclPrintfResult(interp,
"can't create procedure \"%s\": unknown namespace",
procName);
TclSetErrorCode(interp, "TCL", "VALUE", "COMMAND");
return TCL_ERROR;
}
if (simpleName == NULL) {
TclPrintfResult(interp,
"can't create procedure \"%s\": bad procedure name",
procName);
TclSetErrorCode(interp, "TCL", "VALUE", "COMMAND");
return TCL_ERROR;
}
/*
* Create the data structure to represent the procedure.
*/
if (TclCreateProc(interp, /*ignored nsPtr*/ NULL, simpleName, objv[2],
objv[3], &procPtr) != TCL_OK) {
TclPrintfErrorInfo(interp, "\n (creating proc \"%s\")", simpleName);
return TCL_ERROR;
}
cmd = TclNRCreateCommandInNs(interp, simpleName, (Tcl_Namespace *) nsPtr,
TclObjInterpProc, NRInterpProc, procPtr, TclProcDeleteProc);
/*
* Now initialize the new procedure's cmdPtr field. This will be used
* later when the procedure is called to determine what namespace the
* procedure will run in. This will be different than the current
* namespace if the proc was renamed into a different namespace.
*/
|
| ︙ | ︙ | |||
494 495 496 497 498 499 500 |
result = TclListObjGetElements(interp, argsPtr, &numArgs, &argArray);
if (result != TCL_OK) {
goto procError;
}
if (precompiled) {
if (numArgs > procPtr->numArgs) {
| | | | | < | 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
result = TclListObjGetElements(interp, argsPtr, &numArgs, &argArray);
if (result != TCL_OK) {
goto procError;
}
if (precompiled) {
if (numArgs > procPtr->numArgs) {
TclPrintfResult(interp,
"procedure \"%s\": arg list contains %" TCL_SIZE_MODIFIER "d entries, "
"precompiled header expects %" TCL_SIZE_MODIFIER "d",
procName, numArgs, procPtr->numArgs);
TclSetErrorCode(interp, "TCL", "OPERATION", "PROC", "BYTECODELIES");
goto procError;
}
localPtr = procPtr->firstLocalPtr;
} else {
procPtr->numArgs = numArgs;
procPtr->numCompiledLocals = numArgs;
}
|
| ︙ | ︙ | |||
523 524 525 526 527 528 529 |
result = TclListObjGetElements(interp, argArray[i], &fieldCount,
&fieldValues);
if (result != TCL_OK) {
goto procError;
}
if (fieldCount > 2) {
| | | | < < | | < | | | | | | | | | | < < | | | 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
result = TclListObjGetElements(interp, argArray[i], &fieldCount,
&fieldValues);
if (result != TCL_OK) {
goto procError;
}
if (fieldCount > 2) {
TclPrintfResult(interp,
"too many fields in argument specifier \"%s\"",
TclGetString(argArray[i]));
TclSetErrorCode(interp, "TCL", "OPERATION", "PROC",
"FORMALARGUMENTFORMAT");
goto procError;
}
if ((fieldCount == 0) || (Tcl_GetCharLength(fieldValues[0]) == 0)) {
TclPrintfResult(interp, "argument with no name");
TclSetErrorCode(interp, "TCL", "OPERATION", "PROC",
"FORMALARGUMENTFORMAT");
goto procError;
}
argname = TclGetStringFromObj(fieldValues[0], &nameLength);
/*
* Check that the formal parameter name is a scalar.
*/
argnamei = argname;
argnamelast = (nameLength > 0) ? (argname + nameLength - 1) : argname;
while (argnamei < argnamelast) {
if (*argnamei == '(') {
if (*argnamelast == ')') { /* We have an array element. */
TclPrintfResult(interp,
"formal parameter \"%s\" is an array element",
TclGetString(fieldValues[0]));
TclSetErrorCode(interp, "TCL", "OPERATION", "PROC",
"FORMALARGUMENTFORMAT");
goto procError;
}
} else if (argnamei[0] == ':' && argnamei[1] == ':') {
TclPrintfResult(interp,
"formal parameter \"%s\" is not a simple name",
TclGetString(fieldValues[0]));
TclSetErrorCode(interp, "TCL", "OPERATION", "PROC",
"FORMALARGUMENTFORMAT");
goto procError;
}
argnamei++;
}
if (precompiled) {
/*
|
| ︙ | ︙ | |||
589 590 591 592 593 594 595 |
if ((localPtr->nameLength != nameLength)
|| (memcmp(localPtr->name, argname, nameLength) != 0)
|| (localPtr->frameIndex != i)
|| !(localPtr->flags & VAR_ARGUMENT)
|| (localPtr->defValuePtr == NULL && fieldCount == 2)
|| (localPtr->defValuePtr != NULL && fieldCount != 2)) {
| | | | | | | < < | < > | | | 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 |
if ((localPtr->nameLength != nameLength)
|| (memcmp(localPtr->name, argname, nameLength) != 0)
|| (localPtr->frameIndex != i)
|| !(localPtr->flags & VAR_ARGUMENT)
|| (localPtr->defValuePtr == NULL && fieldCount == 2)
|| (localPtr->defValuePtr != NULL && fieldCount != 2)) {
TclPrintfResult(interp,
"procedure \"%s\": formal parameter %" TCL_SIZE_MODIFIER "d is "
"inconsistent with precompiled body", procName, i);
TclSetErrorCode(interp, "TCL", "OPERATION", "PROC",
"BYTECODELIES");
goto procError;
}
/*
* Compare the default value if any.
*/
if (localPtr->defValuePtr != NULL) {
Tcl_Size tmpLength, valueLength;
const char *tmpPtr = TclGetStringFromObj(localPtr->defValuePtr, &tmpLength);
const char *value = TclGetStringFromObj(fieldValues[1], &valueLength);
if ((valueLength != tmpLength)
|| memcmp(value, tmpPtr, tmpLength) != 0) {
TclPrintfResult(interp,
"procedure \"%s\": formal parameter \"%s\" has "
"default value inconsistent with precompiled body",
procName, TclGetString(fieldValues[0]));
TclSetErrorCode(interp, "TCL", "OPERATION", "PROC",
"BYTECODELIES");
goto procError;
}
}
if ((i == numArgs - 1)
&& (localPtr->nameLength == 4)
&& (localPtr->name[0] == 'a')
&& (strcmp(localPtr->name, "args") == 0)) {
|
| ︙ | ︙ | |||
842 843 844 845 846 847 848 |
}
}
}
badLevel:
if (name == NULL) {
name = objPtr ? TclGetString(objPtr) : "1" ;
}
| | | | 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 |
}
}
}
badLevel:
if (name == NULL) {
name = objPtr ? TclGetString(objPtr) : "1" ;
}
TclPrintfResult(interp, "bad level \"%s\"", name);
TclSetErrorCode(interp, "TCL", "LOOKUP", "LEVEL", name);
return -1;
}
/*
*----------------------------------------------------------------------
*
* Tcl_UplevelObjCmd --
|
| ︙ | ︙ | |||
873 874 875 876 877 878 879 |
void *data[],
Tcl_Interp *interp,
int result)
{
CallFrame *savedVarFramePtr = (CallFrame *)data[0];
if (result == TCL_ERROR) {
| | | | 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 |
void *data[],
Tcl_Interp *interp,
int result)
{
CallFrame *savedVarFramePtr = (CallFrame *)data[0];
if (result == TCL_ERROR) {
TclPrintfErrorInfo(interp, "\n (\"uplevel\" body line %d)",
Tcl_GetErrorLine(interp));
}
/*
* Restore the variable frame, and return.
*/
((Interp *)interp)->varFramePtr = savedVarFramePtr;
|
| ︙ | ︙ | |||
981 982 983 984 985 986 987 |
* between, then evaluate the result. Tcl_EvalObjEx will delete the
* object when it decrements its refcount after eval'ing it.
*/
objPtr = Tcl_ConcatObj(objc, objv);
}
| | < | 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 |
* between, then evaluate the result. Tcl_EvalObjEx will delete the
* object when it decrements its refcount after eval'ing it.
*/
objPtr = Tcl_ConcatObj(objc, objv);
}
TclNRAddCallback(interp, Uplevel_Callback, savedVarFramePtr);
return TclNREvalObjEx(interp, objPtr, 0, invoker, word);
}
/*
*----------------------------------------------------------------------
*
* TclFindProc --
|
| ︙ | ︙ | |||
1079 1080 1081 1082 1083 1084 1085 |
*/
numArgs = framePtr->procPtr->numArgs;
desiredObjs = (Tcl_Obj **)TclStackAlloc(interp,
sizeof(Tcl_Obj *) * (numArgs+1));
if (framePtr->isProcCallFrame & FRAME_IS_LAMBDA) {
| | | < | 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 |
*/
numArgs = framePtr->procPtr->numArgs;
desiredObjs = (Tcl_Obj **)TclStackAlloc(interp,
sizeof(Tcl_Obj *) * (numArgs+1));
if (framePtr->isProcCallFrame & FRAME_IS_LAMBDA) {
desiredObjs[0] = TclNewString("lambdaExpr");
} else {
desiredObjs[0] = framePtr->objv[skip-1];
}
Tcl_IncrRefCount(desiredObjs[0]);
if (localCt > 0) {
Var *defPtr = (Var *)(&framePtr->localCachePtr->varName0 + localCt);
for (i=1 ; i<=numArgs ; i++, defPtr++) {
Tcl_Obj *argObj;
Tcl_Obj *namePtr = localName(framePtr, i-1);
if (defPtr->value.objPtr != NULL) {
TclNewObj(argObj);
TclAppendStringsToObj(argObj, "?", TclGetString(namePtr), "?");
} else if (defPtr->flags & VAR_IS_ARGS) {
numArgs--;
final = "?arg ...?";
break;
} else {
argObj = namePtr;
Tcl_IncrRefCount(namePtr);
|
| ︙ | ︙ | |||
1476 1477 1478 1479 1480 1481 1482 |
/*
* Initialise all compiled locals to avoid problems at DeleteLocalVars.
*/
incorrectArgs:
if ((skip != 1) &&
TclInitRewriteEnsemble(interp, skip-1, 0, framePtr->objv)) {
| | | 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 |
/*
* Initialise all compiled locals to avoid problems at DeleteLocalVars.
*/
incorrectArgs:
if ((skip != 1) &&
TclInitRewriteEnsemble(interp, skip-1, 0, framePtr->objv)) {
TclNRAddCallback(interp, TclClearRootEnsemble);
}
memset(varPtr, 0,
((framePtr->compiledLocals + localCt)-varPtr) * sizeof(Var));
return ProcWrongNumArgs(interp, skip);
}
/*
|
| ︙ | ︙ | |||
1777 1778 1779 1780 1781 1782 1783 |
/*
* Invoke the commands in the procedure's body.
*/
procPtr->refCount++;
ByteCodeGetInternalRep(procPtr->bodyPtr, &tclByteCodeType, codePtr);
| | < | 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 |
/*
* Invoke the commands in the procedure's body.
*/
procPtr->refCount++;
ByteCodeGetInternalRep(procPtr->bodyPtr, &tclByteCodeType, codePtr);
TclNRAddCallback(interp, InterpProcNR2, procNameObj, errorProc);
return TclNRExecuteByteCode(interp, codePtr);
}
static int
InterpProcNR2(
void *data[],
Tcl_Interp *interp,
|
| ︙ | ︙ | |||
1854 1855 1856 1857 1858 1859 1860 |
case TCL_CONTINUE:
case TCL_BREAK:
/*
* It's an error to get to this point from a 'break' or 'continue', so
* transform to an error now.
*/
| | | | | 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 |
case TCL_CONTINUE:
case TCL_BREAK:
/*
* It's an error to get to this point from a 'break' or 'continue', so
* transform to an error now.
*/
TclPrintfResult(interp,
"invoked \"%s\" outside of a loop",
((result == TCL_BREAK) ? "break" : "continue"));
TclSetErrorCode(interp, "TCL", "RESULT", "UNEXPECTED");
result = TCL_ERROR;
/* FALLTHRU */
case TCL_ERROR:
/*
* Now it _must_ be an error, so we need to log it as such. This means
|
| ︙ | ︙ | |||
1937 1938 1939 1940 1941 1942 1943 |
&& (codePtr->nsEpoch == nsPtr->resolverEpoch)
&& ((codePtr->procPtr == procPtr) || !bodyPtr->bytes)) {
return TCL_OK;
}
if (codePtr->flags & TCL_BYTECODE_PRECOMPILED) {
if ((Interp *) *codePtr->interpHandle != iPtr) {
| | | | | | 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 |
&& (codePtr->nsEpoch == nsPtr->resolverEpoch)
&& ((codePtr->procPtr == procPtr) || !bodyPtr->bytes)) {
return TCL_OK;
}
if (codePtr->flags & TCL_BYTECODE_PRECOMPILED) {
if ((Interp *) *codePtr->interpHandle != iPtr) {
TclPrintfResult(interp,
"a precompiled script jumped interps");
TclSetErrorCode(interp, "TCL", "OPERATION", "PROC",
"CROSSINTERPBYTECODE");
return TCL_ERROR;
}
codePtr->compileEpoch = iPtr->compileEpoch;
codePtr->nsPtr = nsPtr;
} else {
Tcl_StoreInternalRep(bodyPtr, &tclByteCodeType, NULL);
codePtr = NULL;
|
| ︙ | ︙ | |||
1965 1966 1967 1968 1969 1970 1971 | * to compile. */ Tcl_Obj *message; TclNewLiteralStringObj(message, "Compiling "); Tcl_IncrRefCount(message); | | | 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 |
* to compile.
*/
Tcl_Obj *message;
TclNewLiteralStringObj(message, "Compiling ");
Tcl_IncrRefCount(message);
TclAppendStringsToObj(message, description, " \"");
Tcl_AppendLimitedToObj(message, procName, TCL_INDEX_NONE, 50, NULL);
fprintf(stdout, "%s\"\n", TclGetString(message));
Tcl_DecrRefCount(message);
}
#else
(void)description;
(void)procName;
|
| ︙ | ︙ | |||
2080 2081 2082 2083 2084 2085 2086 |
* messages and trace information. */
{
int overflow, limit = 60;
Tcl_Size nameLen;
const char *procName = TclGetStringFromObj(procNameObj, &nameLen);
overflow = (nameLen > (Tcl_Size)limit);
| < | | | 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 |
* messages and trace information. */
{
int overflow, limit = 60;
Tcl_Size nameLen;
const char *procName = TclGetStringFromObj(procNameObj, &nameLen);
overflow = (nameLen > (Tcl_Size)limit);
TclPrintfErrorInfo(interp, "\n (procedure \"%.*s%s\" line %d)",
(overflow ? limit : (int)nameLen), procName,
(overflow ? "..." : ""), Tcl_GetErrorLine(interp));
}
/*
*----------------------------------------------------------------------
*
* TclProcDeleteProc --
*
|
| ︙ | ︙ | |||
2455 2456 2457 2458 2459 2460 2461 |
/*
* Convert objPtr to list type first; if it cannot be converted, or if its
* length is not 2, then it cannot be converted to lambdaType.
*/
result = TclListObjLength(NULL, objPtr, &objc);
if ((result != TCL_OK) || ((objc != 2) && (objc != 3))) {
| | | | | | | < | > | 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 |
/*
* Convert objPtr to list type first; if it cannot be converted, or if its
* length is not 2, then it cannot be converted to lambdaType.
*/
result = TclListObjLength(NULL, objPtr, &objc);
if ((result != TCL_OK) || ((objc != 2) && (objc != 3))) {
TclPrintfResult(interp,
"can't interpret \"%s\" as a lambda expression",
Tcl_GetString(objPtr));
TclSetErrorCode(interp, "TCL", "VALUE", "LAMBDA");
return TCL_ERROR;
}
result = TclListObjGetElements(NULL, objPtr, &objc, &objv);
if ((result != TCL_OK) || ((objc != 2) && (objc != 3))) {
TclPrintfResult(interp,
"can't interpret \"%s\" as a lambda expression",
TclGetString(objPtr));
TclSetErrorCode(interp, "TCL", "VALUE", "LAMBDA");
return TCL_ERROR;
}
argsPtr = objv[0];
bodyPtr = objv[1];
/*
* Create and initialize the Proc struct. The cmdPtr field is set to NULL
* to signal that this is an anonymous function.
*/
name = TclGetString(objPtr);
if (TclCreateProc(interp, /*ignored nsPtr*/ NULL, name, argsPtr, bodyPtr,
&procPtr) != TCL_OK) {
TclPrintfErrorInfo(interp, "\n (parsing lambda expression \"%s\")",
name);
return TCL_ERROR;
}
/*
* CAREFUL: TclCreateProc returns refCount==1! [Bug 1578454]
* procPtr->refCount = 1;
*/
|
| ︙ | ︙ | |||
2726 2727 2728 2729 2730 2731 2732 |
extraPtr->efi.fields[0].name = "lambda";
extraPtr->efi.fields[0].proc = NULL;
extraPtr->efi.fields[0].clientData = lambdaPtr;
extraPtr->cmd.clientData = &extraPtr->efi;
result = TclPushProcCallFrame(procPtr, interp, objc, objv, 1);
if (result == TCL_OK) {
| | | 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 |
extraPtr->efi.fields[0].name = "lambda";
extraPtr->efi.fields[0].proc = NULL;
extraPtr->efi.fields[0].clientData = lambdaPtr;
extraPtr->cmd.clientData = &extraPtr->efi;
result = TclPushProcCallFrame(procPtr, interp, objc, objv, 1);
if (result == TCL_OK) {
TclNRAddCallback(interp, ApplyNR2, extraPtr);
result = TclNRInterpProcCore(interp, objv[1], 2, &MakeLambdaError);
}
return result;
}
static int
ApplyNR2(
|
| ︙ | ︙ | |||
2774 2775 2776 2777 2778 2779 2780 |
* messages and trace information. */
{
int overflow, limit = 60;
Tcl_Size nameLen;
const char *procName = TclGetStringFromObj(procNameObj, &nameLen);
overflow = (nameLen > (Tcl_Size)limit);
| < | | | 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 |
* messages and trace information. */
{
int overflow, limit = 60;
Tcl_Size nameLen;
const char *procName = TclGetStringFromObj(procNameObj, &nameLen);
overflow = (nameLen > (Tcl_Size)limit);
TclPrintfErrorInfo(interp, "\n (lambda term \"%.*s%s\" line %d)",
(overflow ? limit : (int)nameLen), procName,
(overflow ? "..." : ""), Tcl_GetErrorLine(interp));
}
/*
*----------------------------------------------------------------------
*
* TclGetCmdFrameForProcedure --
*
|
| ︙ | ︙ |
Changes to generic/tclProcess.c.
| ︙ | ︙ | |||
236 237 238 239 240 241 242 |
*codePtr = errno;
}
if (msgObjPtr) {
*msgObjPtr = Tcl_ObjPrintf(
"error waiting for process to exit: %s", msg);
}
if (errorObjPtr) {
| | | 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
*codePtr = errno;
}
if (msgObjPtr) {
*msgObjPtr = Tcl_ObjPrintf(
"error waiting for process to exit: %s", msg);
}
if (errorObjPtr) {
errorStrings[0] = TclNewString("POSIX");
errorStrings[1] = Tcl_NewStringObj(Tcl_ErrnoId(), -1);
errorStrings[2] = Tcl_NewStringObj(msg, -1);
*errorObjPtr = Tcl_NewListObj(3, errorStrings);
}
return TCL_PROCESS_ERROR;
} else if (WIFEXITED(waitStatus)) {
if (codePtr) {
|
| ︙ | ︙ | |||
265 266 267 268 269 270 271 |
/*
* CHILDSTATUS pid code
*
* Child exited with a non-zero exit status.
*/
if (msgObjPtr) {
| < | | | 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
/*
* CHILDSTATUS pid code
*
* Child exited with a non-zero exit status.
*/
if (msgObjPtr) {
*msgObjPtr = TclNewString("child process exited abnormally");
}
if (errorObjPtr) {
errorStrings[0] = TclNewString("CHILDSTATUS");
TclNewIntObj(errorStrings[1], resolvedPid);
TclNewIntObj(errorStrings[2], WEXITSTATUS(waitStatus));
*errorObjPtr = Tcl_NewListObj(3, errorStrings);
}
}
return TCL_PROCESS_EXITED;
} else if (WIFSIGNALED(waitStatus)) {
|
| ︙ | ︙ | |||
291 292 293 294 295 296 297 |
if (codePtr) {
*codePtr = WTERMSIG(waitStatus);
}
if (msgObjPtr) {
*msgObjPtr = Tcl_ObjPrintf("child killed: %s", msg);
}
if (errorObjPtr) {
| | | 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
if (codePtr) {
*codePtr = WTERMSIG(waitStatus);
}
if (msgObjPtr) {
*msgObjPtr = Tcl_ObjPrintf("child killed: %s", msg);
}
if (errorObjPtr) {
errorStrings[0] = TclNewString("CHILDKILLED");
TclNewIntObj(errorStrings[1], resolvedPid);
errorStrings[2] = Tcl_NewStringObj(Tcl_SignalId(WTERMSIG(waitStatus)), -1);
errorStrings[3] = Tcl_NewStringObj(msg, -1);
*errorObjPtr = Tcl_NewListObj(4, errorStrings);
}
return TCL_PROCESS_SIGNALED;
} else if (WIFSTOPPED(waitStatus)) {
|
| ︙ | ︙ | |||
313 314 315 316 317 318 319 |
if (codePtr) {
*codePtr = WSTOPSIG(waitStatus);
}
if (msgObjPtr) {
*msgObjPtr = Tcl_ObjPrintf("child suspended: %s", msg);
}
if (errorObjPtr) {
| | < | | | | | | 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
if (codePtr) {
*codePtr = WSTOPSIG(waitStatus);
}
if (msgObjPtr) {
*msgObjPtr = Tcl_ObjPrintf("child suspended: %s", msg);
}
if (errorObjPtr) {
errorStrings[0] = TclNewString("CHILDSUSP");
TclNewIntObj(errorStrings[1], resolvedPid);
errorStrings[2] = Tcl_NewStringObj(Tcl_SignalId(WSTOPSIG(waitStatus)), -1);
errorStrings[3] = Tcl_NewStringObj(msg, -1);
*errorObjPtr = Tcl_NewListObj(4, errorStrings);
}
return TCL_PROCESS_STOPPED;
} else {
/*
* TCL OPERATION EXEC ODDWAITRESULT
*
* Child wait status didn't make sense.
*/
if (codePtr) {
*codePtr = waitStatus;
}
if (msgObjPtr) {
*msgObjPtr = TclNewString("child wait status didn't make sense\n");
}
if (errorObjPtr) {
errorStrings[0] = TclNewString("TCL");
errorStrings[1] = TclNewString("OPERATION");
errorStrings[2] = TclNewString("EXEC");
errorStrings[3] = TclNewString("ODDWAITRESULT");
TclNewIntObj(errorStrings[4], resolvedPid);
*errorObjPtr = Tcl_NewListObj(5, errorStrings);
}
return TCL_PROCESS_UNKNOWN_STATUS;
}
}
|
| ︙ | ︙ |
Changes to generic/tclRegexp.c.
| ︙ | ︙ | |||
723 724 725 726 727 728 729 |
char cbuf[TCL_INTEGER_SPACE];
size_t n;
const char *p;
Tcl_ResetResult(interp);
n = TclReError(status, buf, sizeof(buf));
p = (n > sizeof(buf)) ? "..." : "";
| | | | 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 |
char cbuf[TCL_INTEGER_SPACE];
size_t n;
const char *p;
Tcl_ResetResult(interp);
n = TclReError(status, buf, sizeof(buf));
p = (n > sizeof(buf)) ? "..." : "";
TclPrintfResult(interp, "%s%s%s", msg, buf, p);
snprintf(cbuf, sizeof(cbuf), "%d", status);
(void) TclReError(REG_ITOA, cbuf, sizeof(cbuf));
TclSetErrorCode(interp, "REGEXP", cbuf, buf);
}
/*
*----------------------------------------------------------------------
*
* FreeRegexpInternalRep --
*
|
| ︙ | ︙ |
Changes to generic/tclResult.c.
| ︙ | ︙ | |||
310 311 312 313 314 315 316 |
}
while (1) {
const char *bytes = va_arg(argList, char *);
if (bytes == NULL) {
break;
}
| | | 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
}
while (1) {
const char *bytes = va_arg(argList, char *);
if (bytes == NULL) {
break;
}
Tcl_AppendToObj(objPtr, bytes, TCL_AUTO_LENGTH);
}
Tcl_SetObjResult(interp, objPtr);
va_end(argList);
}
/*
*----------------------------------------------------------------------
|
| ︙ | ︙ | |||
357 358 359 360 361 362 363 |
Tcl_Size length;
if (Tcl_IsShared(iPtr->objResultPtr)) {
Tcl_SetObjResult(interp, Tcl_DuplicateObj(iPtr->objResultPtr));
}
bytes = TclGetStringFromObj(iPtr->objResultPtr, &length);
if (TclNeedSpace(bytes, bytes + length)) {
| | | 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
Tcl_Size length;
if (Tcl_IsShared(iPtr->objResultPtr)) {
Tcl_SetObjResult(interp, Tcl_DuplicateObj(iPtr->objResultPtr));
}
bytes = TclGetStringFromObj(iPtr->objResultPtr, &length);
if (TclNeedSpace(bytes, bytes + length)) {
TclAppendLiteralToObj(iPtr->objResultPtr, " ");
}
Tcl_AppendObjToObj(iPtr->objResultPtr, listPtr);
Tcl_DecrRefCount(listPtr);
}
/*
*----------------------------------------------------------------------
|
| ︙ | ︙ | |||
762 763 764 765 766 767 768 |
valueObjv);
}
Tcl_DictObjGet(NULL, iPtr->returnOpts, keys[KEY_ERRORCODE],
&valuePtr);
if (valuePtr != NULL) {
Tcl_SetObjErrorCode(interp, valuePtr);
} else {
| | | 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 |
valueObjv);
}
Tcl_DictObjGet(NULL, iPtr->returnOpts, keys[KEY_ERRORCODE],
&valuePtr);
if (valuePtr != NULL) {
Tcl_SetObjErrorCode(interp, valuePtr);
} else {
TclSetErrorCode(interp, "NONE");
}
Tcl_DictObjGet(NULL, iPtr->returnOpts, keys[KEY_ERRORLINE],
&valuePtr);
if (valuePtr != NULL) {
TclGetIntFromObj(NULL, valuePtr, &iPtr->errorLine);
}
|
| ︙ | ︙ | |||
838 839 840 841 842 843 844 |
nestedOptions:
if (TCL_ERROR == Tcl_DictObjFirst(NULL, dict, &search,
&keyPtr, &valuePtr, &done)) {
/*
* Value is not a legal dictionary.
*/
| | | | < | 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 |
nestedOptions:
if (TCL_ERROR == Tcl_DictObjFirst(NULL, dict, &search,
&keyPtr, &valuePtr, &done)) {
/*
* Value is not a legal dictionary.
*/
TclPrintfResult(interp,
"bad %s value: expected dictionary but got \"%s\"",
compare, TclGetString(objv[1]));
TclSetErrorCode(interp, "TCL", "RESULT", "ILLEGAL_OPTIONS");
goto error;
}
while (!done) {
Tcl_DictObjPut(NULL, returnOpts, keyPtr, valuePtr);
Tcl_DictObjNext(&search, &keyPtr, &valuePtr, &done);
}
|
| ︙ | ︙ | |||
888 889 890 891 892 893 894 |
if (valuePtr != NULL) {
if ((TCL_ERROR == TclGetIntFromObj(NULL, valuePtr, &level))
|| (level < 0)) {
/*
* Value is not a legal level.
*/
| | | | | | | < | | | < | | | | | 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 |
if (valuePtr != NULL) {
if ((TCL_ERROR == TclGetIntFromObj(NULL, valuePtr, &level))
|| (level < 0)) {
/*
* Value is not a legal level.
*/
TclPrintfResult(interp,
"bad -level value: expected non-negative integer but got"
" \"%s\"", TclGetString(valuePtr));
TclSetErrorCode(interp, "TCL", "RESULT", "ILLEGAL_LEVEL");
goto error;
}
Tcl_DictObjRemove(NULL, returnOpts, keys[KEY_LEVEL]);
}
/*
* Check for bogus -errorcode value.
*/
Tcl_DictObjGet(NULL, returnOpts, keys[KEY_ERRORCODE], &valuePtr);
if (valuePtr != NULL) {
Tcl_Size length;
if (TCL_ERROR == TclListObjLength(NULL, valuePtr, &length )) {
/*
* Value is not a list, which is illegal for -errorcode.
*/
TclPrintfResult(interp,
"bad -errorcode value: expected a list but got \"%s\"",
TclGetString(valuePtr));
TclSetErrorCode(interp, "TCL", "RESULT", "ILLEGAL_ERRORCODE");
goto error;
}
}
/*
* Check for bogus -errorstack value.
*/
Tcl_DictObjGet(NULL, returnOpts, keys[KEY_ERRORSTACK], &valuePtr);
if (valuePtr != NULL) {
Tcl_Size length;
if (TCL_ERROR == TclListObjLength(NULL, valuePtr, &length)) {
/*
* Value is not a list, which is illegal for -errorstack.
*/
TclPrintfResult(interp,
"bad -errorstack value: expected a list but got \"%s\"",
TclGetString(valuePtr));
TclSetErrorCode(interp, "TCL", "RESULT", "NONLIST_ERRORSTACK");
goto error;
}
if (length % 2) {
/*
* Errorstack must always be an even-sized list
*/
TclPrintfResult(interp,
"forbidden odd-sized list for -errorstack: \"%s\"",
TclGetString(valuePtr));
TclSetErrorCode(interp, "TCL", "RESULT",
"ODDSIZEDLIST_ERRORSTACK");
goto error;
}
}
/*
* Convert [return -code return -level X] to [return -code ok -level X+1]
*/
|
| ︙ | ︙ | |||
1100 1101 1102 1103 1104 1105 1106 |
Tcl_Size objc;
int level, code;
Tcl_Obj **objv, *mergedOpts;
Tcl_IncrRefCount(options);
if (TCL_ERROR == TclListObjGetElements(interp, options, &objc, &objv)
|| (objc % 2)) {
| | | | | 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 |
Tcl_Size objc;
int level, code;
Tcl_Obj **objv, *mergedOpts;
Tcl_IncrRefCount(options);
if (TCL_ERROR == TclListObjGetElements(interp, options, &objc, &objv)
|| (objc % 2)) {
TclPrintfResult(interp,
"expected dict but got \"%s\"", TclGetString(options));
TclSetErrorCode(interp, "TCL", "RESULT", "ILLEGAL_OPTIONS");
code = TCL_ERROR;
} else if (TCL_ERROR == TclMergeReturnOptions(interp, objc, objv,
&mergedOpts, &code, &level)) {
code = TCL_ERROR;
} else {
code = TclProcessReturn(interp, code, level, mergedOpts);
}
|
| ︙ | ︙ |
Changes to generic/tclScan.c.
| ︙ | ︙ | |||
338 339 340 341 342 343 344 |
goto xpgCheckDone;
}
notXpg:
gotSequential = 1;
if (gotXpg) {
mixedXPG:
| | | < | | | < | | 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
goto xpgCheckDone;
}
notXpg:
gotSequential = 1;
if (gotXpg) {
mixedXPG:
Tcl_SetObjResult(interp, TclNewString(
"cannot mix \"%\" and \"%n$\" conversion specifiers"));
TclSetErrorCode(interp, "TCL", "FORMAT", "MIXEDSPECTYPES");
goto error;
}
xpgCheckDone:
/*
* Parse any width specifier.
*/
if ((ch < 0x80) && isdigit(UCHAR(ch))) { /* INTL: "C" locale. */
/* Note ull >= 0 because of isdigit check above */
unsigned long long ull;
ull = strtoull(
format - 1, (char **)&format, 10); /* INTL: "C" locale. */
/* Note >=, not >, to leave room for a nul */
if (ull >= TCL_SIZE_MAX) {
TclPrintfResult(interp,
"specified field width %" TCL_LL_MODIFIER
"u exceeds limit %" TCL_SIZE_MODIFIER "d.",
ull, (Tcl_Size)TCL_SIZE_MAX-1);
TclSetErrorCode(interp, "TCL", "FORMAT", "WIDTHLIMIT");
goto error;
}
flags |= SCAN_WIDTH;
format += TclUtfToUniChar(format, &ch);
}
/*
|
| ︙ | ︙ | |||
412 413 414 415 416 417 418 |
/*
* Handle the various field types.
*/
switch (ch) {
case 'c':
if (flags & SCAN_WIDTH) {
| | | < | | | | | | | 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
/*
* Handle the various field types.
*/
switch (ch) {
case 'c':
if (flags & SCAN_WIDTH) {
Tcl_SetObjResult(interp, TclNewString(
"field width may not be specified in %c conversion"));
TclSetErrorCode(interp, "TCL", "FORMAT", "BADWIDTH");
goto error;
}
/* FALLTHRU */
case 'n':
case 's':
if (flags & (SCAN_LONGER|SCAN_BIG)) {
invalidFieldSize:
buf[Tcl_UniCharToUtf(ch, buf)] = '\0';
errorMsg = TclNewString(
"field size modifier may not be specified in %");
Tcl_AppendToObj(errorMsg, buf, TCL_AUTO_LENGTH);
TclAppendLiteralToObj(errorMsg, " conversion");
Tcl_SetObjResult(interp, errorMsg);
TclSetErrorCode(interp, "TCL", "FORMAT", "BADSIZE");
goto error;
}
/*
* Fall through!
*/
case 'd':
case 'e':
|
| ︙ | ︙ | |||
479 480 481 482 483 484 485 |
if (*format == '\0') {
goto badSet;
}
format += TclUtfToUniChar(format, &ch);
}
break;
badSet:
| < | | < | | | | | 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
if (*format == '\0') {
goto badSet;
}
format += TclUtfToUniChar(format, &ch);
}
break;
badSet:
TclPrintfResult(interp, "unmatched [ in format string");
TclSetErrorCode(interp, "TCL", "FORMAT", "BRACKET");
goto error;
default:
buf[Tcl_UniCharToUtf(ch, buf)] = '\0';
errorMsg = TclNewString("bad scan conversion character \"");
Tcl_AppendToObj(errorMsg, buf, TCL_AUTO_LENGTH);
TclAppendLiteralToObj(errorMsg, "\"");
Tcl_SetObjResult(interp, errorMsg);
TclSetErrorCode(interp, "TCL", "FORMAT", "BADTYPE");
goto error;
}
if (!(flags & SCAN_SUPPRESS)) {
if (objIndex >= nspace) {
/*
* Expand the nassign buffer. If we are using XPG specifiers,
* make sure that we grow to a large enough size. xpgSize is
|
| ︙ | ︙ | |||
534 535 536 537 538 539 540 |
}
}
if (totalSubs) {
*totalSubs = numVars;
}
for (i = 0; i < numVars; i++) {
if (nassign[i] > 1) {
| | | < | | | < | | | | | | < | | 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
}
}
if (totalSubs) {
*totalSubs = numVars;
}
for (i = 0; i < numVars; i++) {
if (nassign[i] > 1) {
Tcl_SetObjResult(interp, TclNewString(
"variable is assigned by multiple \"%n$\" conversion specifiers"));
TclSetErrorCode(interp, "TCL", "FORMAT", "POLYASSIGNED");
goto error;
} else if (!xpgSize && (nassign[i] == 0)) {
/*
* If the space is empty, and xpgSize is 0 (means XPG wasn't used,
* and/or numVars != 0), then too many vars were given
*/
TclPrintfResult(interp,
"variable is not assigned by any conversion specifiers");
TclSetErrorCode(interp, "TCL", "FORMAT", "UNASSIGNED");
goto error;
}
}
TclStackFree(interp, nassign);
return TCL_OK;
badIndex:
if (gotXpg) {
Tcl_SetObjResult(interp, TclNewString(
"\"%n$\" argument index out of range"));
TclSetErrorCode(interp, "TCL", "FORMAT", "INDEXRANGE");
} else {
TclPrintfResult(interp,
"different numbers of variable names and field specifiers");
TclSetErrorCode(interp, "TCL", "FORMAT", "FIELDVARMISMATCH");
}
error:
TclStackFree(interp, nassign);
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
970 971 972 973 974 975 976 |
} else {
wideValue = WIDE_MAX;
}
}
if ((flags & SCAN_UNSIGNED) && (wideValue < 0)) {
mp_int big;
if (mp_init_u64(&big, (Tcl_WideUInt)wideValue) != MP_OKAY) {
| | | | | 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 |
} else {
wideValue = WIDE_MAX;
}
}
if ((flags & SCAN_UNSIGNED) && (wideValue < 0)) {
mp_int big;
if (mp_init_u64(&big, (Tcl_WideUInt)wideValue) != MP_OKAY) {
TclPrintfResult(interp,
"insufficient memory to create bignum");
TclSetErrorCode(interp, "TCL", "MEMORY");
return TCL_ERROR;
} else {
Tcl_SetBignumObj(objPtr, &big);
}
} else {
TclSetIntObj(objPtr, wideValue);
}
|
| ︙ | ︙ | |||
997 998 999 1000 1001 1002 1003 |
}
if (res == TCL_ERROR) {
if (objs != NULL) {
Tcl_Free(objs);
}
Tcl_DecrRefCount(objPtr);
| | | | < | | | | 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 |
}
if (res == TCL_ERROR) {
if (objs != NULL) {
Tcl_Free(objs);
}
Tcl_DecrRefCount(objPtr);
TclPrintfResult(interp,
"unsigned bignum scans are invalid");
TclSetErrorCode(interp, "TCL", "FORMAT", "BADUNSIGNED");
return TCL_ERROR;
}
}
} else {
if (TclGetIntFromObj(NULL, objPtr, &value) != TCL_OK) {
if (TclGetString(objPtr)[0] == '-') {
value = INT_MIN;
} else {
value = INT_MAX;
}
}
if ((flags & SCAN_UNSIGNED) && (value < 0)) {
#ifdef TCL_WIDE_INT_IS_LONG
mp_int big;
if (mp_init_u64(&big, (unsigned long)value) != MP_OKAY) {
TclPrintfResult(interp,
"insufficient memory to create bignum");
TclSetErrorCode(interp, "TCL", "MEMORY");
return TCL_ERROR;
} else {
Tcl_SetBignumObj(objPtr, &big);
}
#else
Tcl_SetWideIntObj(objPtr, (unsigned long)value);
#endif
|
| ︙ | ︙ |
Changes to generic/tclStrIdxTree.c.
| ︙ | ︙ | |||
465 466 467 468 469 470 471 |
Tcl_Interp *interp,
TclStrIdx *tree,
int offs)
{
Tcl_Obj *obj[2];
const char *s;
| | | 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
Tcl_Interp *interp,
TclStrIdx *tree,
int offs)
{
Tcl_Obj *obj[2];
const char *s;
TclInitObjRef(obj[0], TclNewString("::puts"));
while (tree != NULL) {
s = TclGetString(tree->key) + offs;
TclInitObjRef(obj[1], Tcl_ObjPrintf("%*s%.*s\t:%d",
offs, "", tree->length - offs, s, tree->value));
Tcl_PutsObjCmd(NULL, interp, 2, obj);
TclUnsetObjRef(obj[1]);
if (tree->childTree.firstPtr != NULL) {
|
| ︙ | ︙ | |||
500 501 502 503 504 505 506 |
if (objc < 2) {
Tcl_WrongNumArgs(interp, 1, objv, "");
return TCL_ERROR;
}
if (Tcl_GetIndexFromObj(interp, objv[1], options,
"option", 0, &optionIndex) != TCL_OK) {
| | < | 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
if (objc < 2) {
Tcl_WrongNumArgs(interp, 1, objv, "");
return TCL_ERROR;
}
if (Tcl_GetIndexFromObj(interp, objv[1], options,
"option", 0, &optionIndex) != TCL_OK) {
TclSetErrorCode(interp, "CLOCK", "badOption", TclGetString(objv[1]));
return TCL_ERROR;
}
switch (optionIndex) {
case O_FINDEQUAL:
if (objc < 4) {
Tcl_WrongNumArgs(interp, 1, objv, "");
|
| ︙ | ︙ |
Changes to generic/tclStrToD.c.
| ︙ | ︙ | |||
1528 1529 1530 1531 1532 1533 1534 |
Tcl_Obj *msg = Tcl_ObjPrintf("expected %s but got ",
expected);
Tcl_Size argc;
const char **argv;
if ((TclMaxListLength(bytes, TCL_INDEX_NONE, NULL) > 1)
&& Tcl_SplitList(NULL, bytes, &argc, &argv) == TCL_OK) {
Tcl_Free(argv);
| | | | | | 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 |
Tcl_Obj *msg = Tcl_ObjPrintf("expected %s but got ",
expected);
Tcl_Size argc;
const char **argv;
if ((TclMaxListLength(bytes, TCL_INDEX_NONE, NULL) > 1)
&& Tcl_SplitList(NULL, bytes, &argc, &argv) == TCL_OK) {
Tcl_Free(argv);
TclAppendLiteralToObj(msg, "a list");
} else {
TclAppendLiteralToObj(msg, "\"");
Tcl_AppendLimitedToObj(msg, bytes, numBytes, 50, "");
TclAppendLiteralToObj(msg, "\"");
}
Tcl_SetObjResult(interp, msg);
TclSetErrorCode(interp, "TCL", "VALUE", "NUMBER");
}
}
/*
* Free memory.
*/
|
| ︙ | ︙ | |||
4797 4798 4799 4800 4801 4802 4803 |
* Infinite values can't convert to bignum.
*/
if (isinf(d)) {
if (interp != NULL) {
const char *s = "integer value too large to represent";
| | | | 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 |
* Infinite values can't convert to bignum.
*/
if (isinf(d)) {
if (interp != NULL) {
const char *s = "integer value too large to represent";
TclPrintfResult(interp, s);
TclSetErrorCode(interp, "ARITH", "IOVERFLOW", s);
}
return TCL_ERROR;
}
fract = frexp(d, &expt);
if (expt <= 0) {
err = mp_init(b);
|
| ︙ | ︙ |
Changes to generic/tclStringObj.c.
| ︙ | ︙ | |||
1811 1812 1813 1814 1815 1816 1817 |
while (1) {
const char *bytes = va_arg(argList, char *);
if (bytes == NULL) {
break;
}
| | | 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 |
while (1) {
const char *bytes = va_arg(argList, char *);
if (bytes == NULL) {
break;
}
Tcl_AppendToObj(objPtr, bytes, TCL_AUTO_LENGTH);
}
va_end(argList);
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
2248 2249 2250 2251 2252 2253 2254 |
(isNegative ? "-" : gotPlus ? "+" : " "), 1);
segmentLimit -= 1;
}
if (gotHash || (ch == 'p')) {
switch (ch) {
case 'o':
| | | | | | 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 |
(isNegative ? "-" : gotPlus ? "+" : " "), 1);
segmentLimit -= 1;
}
if (gotHash || (ch == 'p')) {
switch (ch) {
case 'o':
TclAppendLiteralToObj(segment, "0o");
segmentLimit -= 2;
break;
case 'p':
case 'x':
case 'X':
TclAppendLiteralToObj(segment, "0x");
segmentLimit -= 2;
break;
case 'b':
TclAppendLiteralToObj(segment, "0b");
segmentLimit -= 2;
break;
case 'd':
TclAppendLiteralToObj(segment, "0d");
segmentLimit -= 2;
break;
}
}
switch (ch) {
case 'd': {
|
| ︙ | ︙ | |||
2307 2308 2309 2310 2311 2312 2313 |
*/
if (gotPrecision) {
if (length < precision) {
segmentLimit -= precision - length;
}
while (length < precision) {
| | | | 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 |
*/
if (gotPrecision) {
if (length < precision) {
segmentLimit -= precision - length;
}
while (length < precision) {
TclAppendLiteralToObj(segment, "0");
length++;
}
gotZero = 0;
}
if (gotZero) {
length += Tcl_GetCharLength(segment);
if (length < width) {
segmentLimit -= width - length;
}
while (length < width) {
TclAppendLiteralToObj(segment, "0");
length++;
}
}
if (toAppend > segmentLimit) {
msg = overflow;
errCode = "OVERFLOW";
goto errorMsg;
|
| ︙ | ︙ | |||
2437 2438 2439 2440 2441 2442 2443 |
mp_clear(&big);
}
if (gotPrecision) {
if (length < precision) {
segmentLimit -= precision - length;
}
while (length < precision) {
| | | | 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 |
mp_clear(&big);
}
if (gotPrecision) {
if (length < precision) {
segmentLimit -= precision - length;
}
while (length < precision) {
TclAppendLiteralToObj(segment, "0");
length++;
}
gotZero = 0;
}
if (gotZero) {
length += Tcl_GetCharLength(segment);
if (length < width) {
segmentLimit -= width - length;
}
while (length < width) {
TclAppendLiteralToObj(segment, "0");
length++;
}
}
if (toAppend > segmentLimit) {
msg = overflow;
errCode = "OVERFLOW";
goto errorMsg;
|
| ︙ | ︙ | |||
2554 2555 2556 2557 2558 2559 2560 |
*q = 'p';
}
}
break;
}
default:
if (interp != NULL) {
| < | | | 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 |
*q = 'p';
}
}
break;
}
default:
if (interp != NULL) {
TclPrintfResult(interp, "bad field specifier \"%c\"", ch);
TclSetErrorCode(interp, "TCL", "FORMAT", "BADTYPE");
}
goto error;
}
if (width>0 && numChars<0) {
numChars = Tcl_GetCharLength(segment);
}
|
| ︙ | ︙ | |||
2616 2617 2618 2619 2620 2621 2622 |
}
return TCL_OK;
errorMsg:
if (interp != NULL) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, -1));
| | | 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 |
}
return TCL_OK;
errorMsg:
if (interp != NULL) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, -1));
TclSetErrorCode(interp, "TCL", "FORMAT", errCode);
}
error:
Tcl_SetObjLength(appendObj, originalLength);
return TCL_ERROR;
}
/*
|
| ︙ | ︙ | |||
3035 3036 3037 3038 3039 3040 3041 |
/* Any repeats of empty is empty. */
return objPtr;
}
/* maxCount includes space for null */
if (count > (maxCount-1)) {
if (interp) {
| | | | | 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 |
/* Any repeats of empty is empty. */
return objPtr;
}
/* maxCount includes space for null */
if (count > (maxCount-1)) {
if (interp) {
TclPrintfResult(interp,
"max size for a Tcl value (%" TCL_SIZE_MODIFIER
"d bytes) exceeded", TCL_SIZE_MAX);
TclSetErrorCode(interp, "TCL", "MEMORY");
}
return NULL;
}
if (binary) {
/* Efficiently produce a pure byte array result */
objResultPtr = (!inPlace || Tcl_IsShared(objPtr)) ?
|
| ︙ | ︙ | |||
3073 3074 3075 3076 3077 3078 3079 |
TclInvalidateStringRep(objPtr);
objResultPtr = objPtr;
}
/* TODO - overflow check */
if (0 == Tcl_AttemptSetObjLength(objResultPtr, count*length)) {
if (interp) {
| | | | | 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 |
TclInvalidateStringRep(objPtr);
objResultPtr = objPtr;
}
/* TODO - overflow check */
if (0 == Tcl_AttemptSetObjLength(objResultPtr, count*length)) {
if (interp) {
TclPrintfResult(interp,
"string size overflow: unable to alloc %"
TCL_SIZE_MODIFIER "d bytes",
STRING_SIZE(count * length));
TclSetErrorCode(interp, "TCL", "MEMORY");
}
return NULL;
}
Tcl_SetObjLength(objResultPtr, length);
while (count - done > done) {
Tcl_AppendObjToObj(objResultPtr, objResultPtr);
done *= 2;
|
| ︙ | ︙ | |||
3102 3103 3104 3105 3106 3107 3108 |
} else {
TclFreeInternalRep(objPtr);
objResultPtr = objPtr;
}
/* TODO - overflow check */
if (0 == Tcl_AttemptSetObjLength(objResultPtr, count*length)) {
if (interp) {
| | | | | 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 |
} else {
TclFreeInternalRep(objPtr);
objResultPtr = objPtr;
}
/* TODO - overflow check */
if (0 == Tcl_AttemptSetObjLength(objResultPtr, count*length)) {
if (interp) {
TclPrintfResult(interp,
"string size overflow: unable to alloc %" TCL_SIZE_MODIFIER "d bytes",
count * length);
TclSetErrorCode(interp, "TCL", "MEMORY");
}
return NULL;
}
Tcl_SetObjLength(objResultPtr, length);
while (count - done > done) {
Tcl_AppendObjToObj(objResultPtr, objResultPtr);
done *= 2;
|
| ︙ | ︙ | |||
3400 3401 3402 3403 3404 3405 3406 |
objResultPtr = *objv++; objc--;
/* Ugly interface! Force resize of the unicode array. */
(void)Tcl_GetUnicodeFromObj(objResultPtr, &start);
Tcl_InvalidateStringRep(objResultPtr);
if (0 == Tcl_AttemptSetObjLength(objResultPtr, length)) {
if (interp) {
| | | | | | | | | | | | 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 |
objResultPtr = *objv++; objc--;
/* Ugly interface! Force resize of the unicode array. */
(void)Tcl_GetUnicodeFromObj(objResultPtr, &start);
Tcl_InvalidateStringRep(objResultPtr);
if (0 == Tcl_AttemptSetObjLength(objResultPtr, length)) {
if (interp) {
TclPrintfResult(interp,
"concatenation failed: unable to alloc %"
TCL_Z_MODIFIER "u bytes",
STRING_SIZE(length));
TclSetErrorCode(interp, "TCL", "MEMORY");
}
return NULL;
}
dst = Tcl_GetUnicode(objResultPtr) + start;
} else {
Tcl_UniChar ch = 0;
/* Ugly interface! No scheme to init array size. */
objResultPtr = Tcl_NewUnicodeObj(&ch, 0); /* PANIC? */
if (0 == Tcl_AttemptSetObjLength(objResultPtr, length)) {
Tcl_DecrRefCount(objResultPtr);
if (interp) {
TclPrintfResult(interp,
"concatenation failed: unable to alloc %"
TCL_Z_MODIFIER "u bytes",
STRING_SIZE(length));
TclSetErrorCode(interp, "TCL", "MEMORY");
}
return NULL;
}
dst = Tcl_GetUnicode(objResultPtr);
}
while (objc--) {
Tcl_Obj *objPtr = *objv++;
|
| ︙ | ︙ | |||
3449 3450 3451 3452 3453 3454 3455 |
Tcl_Size start;
objResultPtr = *objv++; objc--;
(void)TclGetStringFromObj(objResultPtr, &start);
if (0 == Tcl_AttemptSetObjLength(objResultPtr, length)) {
if (interp) {
| | | > | | | | > | | | 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 |
Tcl_Size start;
objResultPtr = *objv++; objc--;
(void)TclGetStringFromObj(objResultPtr, &start);
if (0 == Tcl_AttemptSetObjLength(objResultPtr, length)) {
if (interp) {
TclPrintfResult(interp,
"concatenation failed: unable to alloc %"
TCL_SIZE_MODIFIER "d bytes",
length);
TclSetErrorCode(interp, "TCL", "MEMORY");
}
return NULL;
}
dst = TclGetString(objResultPtr) + start;
TclFreeInternalRep(objResultPtr);
} else {
TclNewObj(objResultPtr); /* PANIC? */
if (0 == Tcl_AttemptSetObjLength(objResultPtr, length)) {
Tcl_DecrRefCount(objResultPtr);
if (interp) {
TclPrintfResult(interp,
"concatenation failed: unable to alloc %"
TCL_SIZE_MODIFIER "d bytes",
length);
TclSetErrorCode(interp, "TCL", "MEMORY");
}
return NULL;
}
dst = TclGetString(objResultPtr);
}
while (objc--) {
Tcl_Obj *objPtr = *objv++;
|
| ︙ | ︙ | |||
3491 3492 3493 3494 3495 3496 3497 |
/* Must NUL-terminate! */
*dst = '\0';
}
return objResultPtr;
overflow:
if (interp) {
| | | | | 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 |
/* Must NUL-terminate! */
*dst = '\0';
}
return objResultPtr;
overflow:
if (interp) {
TclPrintfResult(interp,
"max size for a Tcl value (%" TCL_SIZE_MODIFIER
"d bytes) exceeded", TCL_SIZE_MAX);
TclSetErrorCode(interp, "TCL", "MEMORY");
}
return NULL;
}
/*
*---------------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
4241 4242 4243 4244 4245 4246 4247 |
memcpy(bytes + first, iBytes, count);
Tcl_InvalidateStringRep(objPtr);
return objPtr;
}
if (newBytes > (TCL_SIZE_MAX - (numBytes - count))) {
if (interp) {
| | | > | | | 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 |
memcpy(bytes + first, iBytes, count);
Tcl_InvalidateStringRep(objPtr);
return objPtr;
}
if (newBytes > (TCL_SIZE_MAX - (numBytes - count))) {
if (interp) {
TclPrintfResult(interp,
"max size for a Tcl value (%" TCL_SIZE_MODIFIER
"d bytes) exceeded",
TCL_SIZE_MAX);
TclSetErrorCode(interp, "TCL", "MEMORY");
}
return NULL;
}
result = Tcl_NewByteArrayObj(NULL, numBytes - count + newBytes);
/* PANIC? */
Tcl_SetByteArrayLength(result, 0);
TclAppendBytesToByteArray(result, bytes, first);
|
| ︙ | ︙ |
Changes to generic/tclTimer.c.
| ︙ | ︙ | |||
818 819 820 821 822 823 824 |
*/
if (TclGetWideIntFromObj(NULL, objv[1], &ms) != TCL_OK) {
if (Tcl_GetIndexFromObj(NULL, objv[1], afterSubCmds, "", 0, &index)
!= TCL_OK) {
const char *arg = TclGetString(objv[1]);
| | | | < | 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 |
*/
if (TclGetWideIntFromObj(NULL, objv[1], &ms) != TCL_OK) {
if (Tcl_GetIndexFromObj(NULL, objv[1], afterSubCmds, "", 0, &index)
!= TCL_OK) {
const char *arg = TclGetString(objv[1]);
TclPrintfResult(interp,
"bad argument \"%s\": must be"
" cancel, idle, info, or an integer", arg);
TclSetErrorCode(interp, "TCL", "LOOKUP", "INDEX", "argument", arg);
return TCL_ERROR;
}
}
/*
* At this point, either index = -1 and ms contains the number of ms
* to wait, or else index is the index of a subcommand.
|
| ︙ | ︙ | |||
959 960 961 962 963 964 965 |
Tcl_WrongNumArgs(interp, 2, objv, "?id?");
return TCL_ERROR;
}
afterPtr = GetAfterEvent(assocPtr, objv[2]);
if (afterPtr == NULL) {
const char *eventStr = TclGetString(objv[2]);
| < | | | 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 |
Tcl_WrongNumArgs(interp, 2, objv, "?id?");
return TCL_ERROR;
}
afterPtr = GetAfterEvent(assocPtr, objv[2]);
if (afterPtr == NULL) {
const char *eventStr = TclGetString(objv[2]);
TclPrintfResult(interp, "event \"%s\" doesn't exist", eventStr);
TclSetErrorCode(interp, "TCL","LOOKUP","EVENT", eventStr);
return TCL_ERROR;
} else {
Tcl_Obj *resultListPtr;
TclNewObj(resultListPtr);
Tcl_ListObjAppendElement(interp, resultListPtr,
afterPtr->commandPtr);
|
| ︙ | ︙ |
Changes to generic/tclTrace.c.
| ︙ | ︙ | |||
311 312 313 314 315 316 317 |
*/
result = TclListObjLength(interp, objv[4], &listLen);
if (result != TCL_OK) {
return result;
}
if (listLen == 0) {
| | | | < | 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
*/
result = TclListObjLength(interp, objv[4], &listLen);
if (result != TCL_OK) {
return result;
}
if (listLen == 0) {
TclPrintfResult(interp,
"bad operation list \"\": must be one or more of"
" enter, leave, enterstep, or leavestep");
TclSetErrorCode(interp, "TCL", "OPERATION", "TRACE", "NOOPS");
return TCL_ERROR;
}
result = TclListObjGetElements(interp, objv[4], &listLen, &elemPtrs);
if (result != TCL_OK) {
return result;
}
for (i = 0; i < listLen; i++) {
|
| ︙ | ︙ | |||
553 554 555 556 557 558 559 |
*/
result = TclListObjLength(interp, objv[4], &listLen);
if (result != TCL_OK) {
return result;
}
if (listLen == 0) {
| | | | < | 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
*/
result = TclListObjLength(interp, objv[4], &listLen);
if (result != TCL_OK) {
return result;
}
if (listLen == 0) {
TclPrintfResult(interp,
"bad operation list \"\": must be one or more of"
" delete or rename");
TclSetErrorCode(interp, "TCL", "OPERATION", "TRACE", "NOOPS");
return TCL_ERROR;
}
result = TclListObjGetElements(interp, objv[4], &listLen, &elemPtrs);
if (result != TCL_OK) {
return result;
}
for (i = 0; i < listLen; i++) {
|
| ︙ | ︙ | |||
752 753 754 755 756 757 758 |
*/
result = TclListObjLength(interp, objv[4], &listLen);
if (result != TCL_OK) {
return result;
}
if (listLen == 0) {
| | | | < | 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 |
*/
result = TclListObjLength(interp, objv[4], &listLen);
if (result != TCL_OK) {
return result;
}
if (listLen == 0) {
TclPrintfResult(interp,
"bad operation list \"\": must be one or more of"
" array, read, unset, or write");
TclSetErrorCode(interp, "TCL", "OPERATION", "TRACE", "NOOPS");
return TCL_ERROR;
}
result = TclListObjGetElements(interp, objv[4], &listLen, &elemPtrs);
if (result != TCL_OK) {
return result;
}
for (i = 0; i < listLen ; i++) {
|
| ︙ | ︙ | |||
2670 2671 2672 2673 2674 2675 2676 |
if (disposeFlags & TCL_TRACE_RESULT_OBJECT) {
Tcl_SetObjResult((Tcl_Interp *)iPtr, (Tcl_Obj *) result);
} else {
Tcl_SetObjResult((Tcl_Interp *)iPtr,
Tcl_NewStringObj(result, -1));
}
| < | | | 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 |
if (disposeFlags & TCL_TRACE_RESULT_OBJECT) {
Tcl_SetObjResult((Tcl_Interp *)iPtr, (Tcl_Obj *) result);
} else {
Tcl_SetObjResult((Tcl_Interp *)iPtr,
Tcl_NewStringObj(result, -1));
}
TclPrintfErrorInfo((Tcl_Interp *)iPtr,
"\n (%s trace on \"%s%s%s%s\")", type, part1,
(element ? "(" : ""), (element ? element : ""),
(element ? ")" : "") );
if (disposeFlags & TCL_TRACE_RESULT_OBJECT) {
TclVarErrMsg((Tcl_Interp *) iPtr, part1, element, verb,
TclGetString((Tcl_Obj *) result));
} else {
TclVarErrMsg((Tcl_Interp *) iPtr, part1, element, verb, result);
}
iPtr->flags &= ~(ERR_ALREADY_LOGGED);
|
| ︙ | ︙ |
Changes to generic/tclUtil.c.
| ︙ | ︙ | |||
665 666 667 668 669 670 671 |
if (interp != NULL) {
p2 = p;
while ((p2 < limit) && (!TclIsSpaceProcM(*p2))
&& (p2 < p+20)) {
p2++;
}
| | | | < | 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 |
if (interp != NULL) {
p2 = p;
while ((p2 < limit) && (!TclIsSpaceProcM(*p2))
&& (p2 < p+20)) {
p2++;
}
TclPrintfResult(interp,
"%s element in braces followed by \"%.*s\" "
"instead of space", typeStr, (int) (p2-p), p);
TclSetErrorCode(interp, "TCL", "VALUE", typeCode, "JUNK");
}
return TCL_ERROR;
}
break;
/*
* Backslash: skip over everything up to the end of the backslash
|
| ︙ | ︙ | |||
717 718 719 720 721 722 723 |
if (interp != NULL) {
p2 = p;
while ((p2 < limit) && (!TclIsSpaceProcM(*p2))
&& (p2 < p+20)) {
p2++;
}
| | | | < | 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 |
if (interp != NULL) {
p2 = p;
while ((p2 < limit) && (!TclIsSpaceProcM(*p2))
&& (p2 < p+20)) {
p2++;
}
TclPrintfResult(interp,
"%s element in quotes followed by \"%.*s\" "
"instead of space", typeStr, (int) (p2-p), p);
TclSetErrorCode(interp, "TCL", "VALUE", typeCode, "JUNK");
}
return TCL_ERROR;
}
break;
default:
if (TclIsSpaceProcM(*p)) {
|
| ︙ | ︙ | |||
751 752 753 754 755 756 757 |
/*
* End of list/dict: terminate element.
*/
if (p == limit) {
if (openBraces != 0) {
if (interp != NULL) {
| < | | < < | | < | 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 |
/*
* End of list/dict: terminate element.
*/
if (p == limit) {
if (openBraces != 0) {
if (interp != NULL) {
TclPrintfResult(interp, "unmatched open brace in %s", typeStr);
TclSetErrorCode(interp, "TCL", "VALUE", typeCode, "BRACE");
}
return TCL_ERROR;
} else if (inQuotes) {
if (interp != NULL) {
TclPrintfResult(interp, "unmatched open quote in %s", typeStr);
TclSetErrorCode(interp, "TCL", "VALUE", typeCode, "QUOTE");
}
return TCL_ERROR;
}
size = (p - elemStart);
}
done:
|
| ︙ | ︙ | |||
910 911 912 913 914 915 916 |
}
if (*element == 0) {
break;
}
if (i >= size) {
Tcl_Free((void *)argv);
if (interp != NULL) {
| < | | < | 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 |
}
if (*element == 0) {
break;
}
if (i >= size) {
Tcl_Free((void *)argv);
if (interp != NULL) {
TclPrintfResult(interp, "internal error in Tcl_SplitList");
TclSetErrorCode(interp, "TCL", "INTERNAL", "Tcl_SplitList");
}
return TCL_ERROR;
}
argv[i] = p;
if (literal) {
memcpy(p, element, elSize);
p += elSize;
|
| ︙ | ︙ | |||
2083 2084 2085 2086 2087 2088 2089 |
}
/*
* Append to the result with space if needed.
*/
if (needSpace) {
| | | 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 |
}
/*
* Append to the result with space if needed.
*/
if (needSpace) {
TclAppendLiteralToObj(resPtr, " ");
}
Tcl_AppendToObj(resPtr, element, elemLength);
needSpace = 1;
}
return resPtr;
}
|
| ︙ | ︙ | |||
3732 3733 3734 3735 3736 3737 3738 |
}
return TCL_OK;
/* Report a parse error. */
parseError:
if (interp != NULL) {
char * bytes = TclGetString(objPtr);
| | | | | 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 |
}
return TCL_OK;
/* Report a parse error. */
parseError:
if (interp != NULL) {
char * bytes = TclGetString(objPtr);
TclPrintfResult(interp,
"bad index \"%s\": must be integer?[+-]integer? or"
" end?[+-]integer?", bytes);
if (!strncmp(bytes, "end-", 4)) {
bytes += 4;
}
TclSetErrorCode(interp, "TCL", "VALUE", "INDEX");
}
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
|
| ︙ | ︙ | |||
3928 3929 3930 3931 3932 3933 3934 |
}
}
*indexPtr = idx;
return TCL_OK;
rangeerror:
if (interp) {
| > | | | 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 |
}
}
*indexPtr = idx;
return TCL_OK;
rangeerror:
if (interp) {
TclPrintfResult(interp,
"index \"%s\" out of range", TclGetString(objPtr));
TclSetErrorCode(interp, "TCL", "VALUE", "INDEX", "OUTOFRANGE");
}
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
3986 3987 3988 3989 3990 3991 3992 |
int
TclCommandWordLimitError(
Tcl_Interp *interp, /* May be NULL */
Tcl_Size count) /* If <= 0, "unknown" */
{
if (interp) {
if (count > 0) {
| | | | | | 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 |
int
TclCommandWordLimitError(
Tcl_Interp *interp, /* May be NULL */
Tcl_Size count) /* If <= 0, "unknown" */
{
if (interp) {
if (count > 0) {
TclPrintfResult(interp,
"Number of words (%" TCL_SIZE_MODIFIER
"d) in command exceeds limit %" TCL_SIZE_MODIFIER "d.",
count, (Tcl_Size)INT_MAX);
} else {
TclPrintfResult(interp,
"Number of words in command exceeds limit %"
TCL_SIZE_MODIFIER "d.",
(Tcl_Size)INT_MAX);
}
}
return TCL_ERROR; /* Always */
}
/*
*----------------------------------------------------------------------
|
| ︙ | ︙ | |||
4600 4601 4602 4603 4604 4605 4606 |
}
return TCL_OK;
invalidGlob:
if (interp != NULL) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, -1));
| | | 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 |
}
return TCL_OK;
invalidGlob:
if (interp != NULL) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, -1));
TclSetErrorCode(interp, "TCL", "RE2GLOB", code);
}
Tcl_DStringFree(dsPtr);
return TCL_ERROR;
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 4
* fill-column: 78
* End:
*/
|
Changes to generic/tclVar.c.
| ︙ | ︙ | |||
340 341 342 343 344 345 346 |
static int
NotArrayError(
Tcl_Interp *interp,
Tcl_Obj *name)
{
const char *nameStr = TclGetString(name);
| < | | | 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
static int
NotArrayError(
Tcl_Interp *interp,
Tcl_Obj *name)
{
const char *nameStr = TclGetString(name);
TclPrintfResult(interp, "\"%s\" isn't an array", nameStr);
TclSetErrorCode(interp, "TCL", "LOOKUP", "ARRAY", nameStr);
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* TclCleanupVar --
|
| ︙ | ︙ | |||
646 647 648 649 650 651 652 |
* ERROR: part1Ptr is already an array element, cannot specify
* a part2.
*/
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, msg,
NOSUCHVAR, -1);
| | | 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 |
* ERROR: part1Ptr is already an array element, cannot specify
* a part2.
*/
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, msg,
NOSUCHVAR, -1);
TclSetErrorCode(interp, "TCL", "VALUE", "VARNAME");
}
return NULL;
}
part2Ptr = elem;
part1Ptr = arrayPtr;
goto restart;
}
|
| ︙ | ︙ | |||
671 672 673 674 675 676 677 |
const char *part2 = strchr(part1, '(');
if (part2) {
if (part2Ptr != NULL) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, msg,
NEEDARRAY, -1);
| | < | 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 |
const char *part2 = strchr(part1, '(');
if (part2) {
if (part2Ptr != NULL) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, msg,
NEEDARRAY, -1);
TclSetErrorCode(interp, "TCL", "VALUE", "VARNAME");
}
return NULL;
}
arrayPtr = Tcl_NewStringObj(part1, (part2 - part1));
part2Ptr = Tcl_NewStringObj(part2 + 1,
len - (part2 - part1) - 2);
|
| ︙ | ︙ | |||
699 700 701 702 703 704 705 |
*/
varPtr = TclLookupSimpleVar(interp, part1Ptr, flags, createPart1,
&errMsg, &index);
if (varPtr == NULL) {
if ((errMsg != NULL) && (flags & TCL_LEAVE_ERR_MSG)) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, msg, errMsg, -1);
| | | | 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 |
*/
varPtr = TclLookupSimpleVar(interp, part1Ptr, flags, createPart1,
&errMsg, &index);
if (varPtr == NULL) {
if ((errMsg != NULL) && (flags & TCL_LEAVE_ERR_MSG)) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, msg, errMsg, -1);
TclSetErrorCode(interp, "TCL", "LOOKUP", "VARNAME",
TclGetString(part1Ptr));
}
return NULL;
}
/*
* Cache the newly found variable if possible.
*/
|
| ︙ | ︙ | |||
1083 1084 1085 1086 1087 1088 1089 |
*/
if (TclIsVarUndefined(arrayPtr) && !TclIsVarArrayElement(arrayPtr)) {
if (!createArray) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, arrayNamePtr, elNamePtr, msg,
NOSUCHVAR, index);
| | | | | | | | | | 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 |
*/
if (TclIsVarUndefined(arrayPtr) && !TclIsVarArrayElement(arrayPtr)) {
if (!createArray) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, arrayNamePtr, elNamePtr, msg,
NOSUCHVAR, index);
TclSetErrorCode(interp, "TCL", "LOOKUP", "VARNAME",
arrayNamePtr ? TclGetString(arrayNamePtr) : NULL);
}
return NULL;
}
/*
* Make sure we are not resurrecting a namespace variable from a
* deleted namespace!
*/
if (TclIsVarDeadHash(arrayPtr)) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, arrayNamePtr, elNamePtr, msg,
DANGLINGVAR, index);
TclSetErrorCode(interp, "TCL", "LOOKUP", "VARNAME",
arrayNamePtr ? TclGetString(arrayNamePtr) : NULL);
}
return NULL;
}
TclInitArrayVar(arrayPtr);
} else if (!TclIsVarArray(arrayPtr)) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, arrayNamePtr, elNamePtr, msg, NEEDARRAY,
index);
TclSetErrorCode(interp, "TCL", "LOOKUP", "VARNAME",
arrayNamePtr ? TclGetString(arrayNamePtr) : NULL);
}
return NULL;
}
if (createElem) {
varPtr = VarHashCreateVar(arrayPtr->value.tablePtr, elNamePtr,
&isNew);
if (isNew) {
if (arrayPtr->flags & VAR_SEARCH_ACTIVE) {
DeleteSearches((Interp *) interp, arrayPtr);
}
TclSetVarArrayElement(varPtr);
}
} else {
varPtr = VarHashFindVar(arrayPtr->value.tablePtr, elNamePtr);
if (varPtr == NULL) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, arrayNamePtr, elNamePtr, msg,
NOSUCHELEMENT, index);
TclSetErrorCode(interp, "TCL", "LOOKUP", "ELEMENT",
TclGetString(elNamePtr));
}
}
}
return varPtr;
}
/*
|
| ︙ | ︙ | |||
1452 1453 1454 1455 1456 1457 1458 |
/*
* An error. If the variable doesn't exist anymore and no-one's using it,
* then free up the relevant structures and hash table entries.
*/
errorReturn:
| | | 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 |
/*
* An error. If the variable doesn't exist anymore and no-one's using it,
* then free up the relevant structures and hash table entries.
*/
errorReturn:
TclSetErrorCode(interp, "TCL", "READ", "VARNAME");
if (TclIsVarUndefined(varPtr)) {
TclCleanupVar(varPtr, arrayPtr);
}
return NULL;
}
/*
|
| ︙ | ︙ | |||
1930 1931 1932 1933 1934 1935 1936 |
*/
if (TclIsVarDeadHash(varPtr)) {
if (flags & TCL_LEAVE_ERR_MSG) {
if (TclIsVarArrayElement(varPtr)) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, "set",
DANGLINGELEMENT, index);
| | | | | | 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 |
*/
if (TclIsVarDeadHash(varPtr)) {
if (flags & TCL_LEAVE_ERR_MSG) {
if (TclIsVarArrayElement(varPtr)) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, "set",
DANGLINGELEMENT, index);
TclSetErrorCode(interp, "TCL", "LOOKUP", "ELEMENT");
} else {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, "set",
DANGLINGVAR, index);
TclSetErrorCode(interp, "TCL", "LOOKUP", "VARNAME");
}
}
goto earlyError;
}
/*
* It's an error to try to set a constant.
*/
if (TclIsVarConstant(varPtr)) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, "set", ISCONST,index);
TclSetErrorCode(interp, "TCL", "WRITE", "CONST");
}
goto earlyError;
}
/*
* It's an error to try to set an array variable itself.
*/
if (TclIsVarArray(varPtr)) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, "set", ISARRAY,index);
TclSetErrorCode(interp, "TCL", "WRITE", "ARRAY");
}
goto earlyError;
}
TclVarFindHiddenArray(varPtr, arrayPtr);
/*
|
| ︙ | ︙ | |||
2053 2054 2055 2056 2057 2058 2059 |
/*
* If the variable doesn't exist anymore and no-one's using it, then free
* up the relevant structures and hash table entries.
*/
cleanup:
if (resultPtr == NULL) {
| | | 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 |
/*
* If the variable doesn't exist anymore and no-one's using it, then free
* up the relevant structures and hash table entries.
*/
cleanup:
if (resultPtr == NULL) {
TclSetErrorCode(interp, "TCL", "WRITE", "VARNAME");
}
if (TclIsVarUndefined(varPtr)) {
TclCleanupVar(varPtr, arrayPtr);
}
return resultPtr;
earlyError:
|
| ︙ | ︙ | |||
2237 2238 2239 2240 2241 2242 2243 |
/*
* It's an error to try to increment a constant.
*/
if (TclIsVarConstant(varPtr)) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, "incr", ISCONST,index);
| | | 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 |
/*
* It's an error to try to increment a constant.
*/
if (TclIsVarConstant(varPtr)) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, "incr", ISCONST,index);
TclSetErrorCode(interp, "TCL", "WRITE", "CONST");
}
return NULL;
}
if (TclIsVarInHash(varPtr)) {
VarHashRefCount(varPtr)++;
}
|
| ︙ | ︙ | |||
2474 2475 2476 2477 2478 2479 2480 |
/*
* It's an error to try to unset a constant.
*/
if (TclIsVarConstant(varPtr)) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, "unset", ISCONST,index);
| | | 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 |
/*
* It's an error to try to unset a constant.
*/
if (TclIsVarConstant(varPtr)) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, "unset", ISCONST,index);
TclSetErrorCode(interp, "TCL", "UNSET", "CONST");
}
return TCL_ERROR;
}
/*
* Keep the variable alive until we're done with it. We used to
* increase/decrease the refCount for each operation, making it hard to
|
| ︙ | ︙ | |||
2502 2503 2504 2505 2506 2507 2508 |
* It's an error to unset an undefined variable.
*/
if (result != TCL_OK) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, "unset",
((initialArrayPtr == NULL) ? NOSUCHVAR : NOSUCHELEMENT), index);
| | | 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 |
* It's an error to unset an undefined variable.
*/
if (result != TCL_OK) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, "unset",
((initialArrayPtr == NULL) ? NOSUCHVAR : NOSUCHELEMENT), index);
TclSetErrorCode(interp, "TCL", "UNSET", "VARNAME");
}
}
/*
* Finally, if the variable is truly not in use then free up its Var
* structure and remove it from its hash table, if any. The ref count of
* its value object, if any, was decremented above.
|
| ︙ | ︙ | |||
3103 3104 3105 3106 3107 3108 3109 |
*/
if (TclListObjLength(interp, objv[1], &numVars) != TCL_OK) {
return TCL_ERROR;
}
if (numVars != 2) {
| < | | | 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 |
*/
if (TclListObjLength(interp, objv[1], &numVars) != TCL_OK) {
return TCL_ERROR;
}
if (numVars != 2) {
TclPrintfResult(interp, "must have two variable names");
TclSetErrorCode(interp, "TCL", "SYNTAX", "array", "for");
return TCL_ERROR;
}
arrayNameObj = objv[2];
if (TCL_ERROR == LocateArray(interp, arrayNameObj, &varPtr, &isArray)) {
return TCL_ERROR;
|
| ︙ | ︙ | |||
3178 3179 3180 3181 3182 3183 3184 |
if (result == TCL_CONTINUE) {
result = TCL_OK;
} else if (result != TCL_OK) {
if (result == TCL_BREAK) {
Tcl_ResetResult(interp);
result = TCL_OK;
} else if (result == TCL_ERROR) {
| < | | | 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 |
if (result == TCL_CONTINUE) {
result = TCL_OK;
} else if (result != TCL_OK) {
if (result == TCL_BREAK) {
Tcl_ResetResult(interp);
result = TCL_OK;
} else if (result == TCL_ERROR) {
TclPrintfErrorInfo(interp, "\n (\"array for\" body line %d)",
Tcl_GetErrorLine(interp));
}
goto arrayfordone;
}
/*
* Get the next mapping from the array.
*/
|
| ︙ | ︙ | |||
3204 3205 3206 3207 3208 3209 3210 |
&valueObj);
}
result = TCL_OK;
if (done != TCL_CONTINUE) {
Tcl_ResetResult(interp);
if (done == TCL_ERROR) {
| < | | | 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 |
&valueObj);
}
result = TCL_OK;
if (done != TCL_CONTINUE) {
Tcl_ResetResult(interp);
if (done == TCL_ERROR) {
TclPrintfResult(interp, "array changed during iteration");
TclSetErrorCode(interp, "TCL", "READ", "array", "for");
varPtr->flags |= TCL_LEAVE_ERR_MSG;
result = done;
}
goto arrayfordone;
}
result = TclListObjGetElements(NULL, varListObj, &varc, &varv);
|
| ︙ | ︙ | |||
4020 4021 4022 4023 4024 4025 4026 |
/*createPart2*/ 1, &arrayPtr);
if (varPtr == NULL) {
return TCL_ERROR;
}
if (arrayPtr) {
CleanupVar(varPtr, arrayPtr);
TclObjVarErrMsg(interp, arrayNameObj, NULL, "set", NEEDARRAY, -1);
| | | | 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 |
/*createPart2*/ 1, &arrayPtr);
if (varPtr == NULL) {
return TCL_ERROR;
}
if (arrayPtr) {
CleanupVar(varPtr, arrayPtr);
TclObjVarErrMsg(interp, arrayNameObj, NULL, "set", NEEDARRAY, -1);
TclSetErrorCode(interp, "TCL", "LOOKUP", "VARNAME",
TclGetString(arrayNameObj));
return TCL_ERROR;
}
/*
* Install the contents of the dictionary or list into the array.
*/
|
| ︙ | ︙ | |||
4087 4088 4089 4090 4091 4092 4093 |
Tcl_Size i;
result = TclListObjLength(interp, arrayElemObj, &elemLen);
if (result != TCL_OK) {
return result;
}
if (elemLen & 1) {
| | | | | 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 |
Tcl_Size i;
result = TclListObjLength(interp, arrayElemObj, &elemLen);
if (result != TCL_OK) {
return result;
}
if (elemLen & 1) {
TclPrintfResult(interp,
"list must have an even number of elements");
TclSetErrorCode(interp, "TCL", "ARGUMENT", "FORMAT");
return TCL_ERROR;
}
if (elemLen == 0) {
goto ensureArray;
}
result = TclListObjGetElements(interp, arrayElemObj,
&elemLen, &elemPtrs);
|
| ︙ | ︙ | |||
4148 4149 4150 4151 4152 4153 4154 |
if (TclIsVarArrayElement(varPtr) || !TclIsVarUndefined(varPtr)) {
/*
* Either an array element, or a scalar: lose!
*/
TclObjVarErrMsg(interp, arrayNameObj, NULL, "array set",
NEEDARRAY, -1);
| | | 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 |
if (TclIsVarArrayElement(varPtr) || !TclIsVarUndefined(varPtr)) {
/*
* Either an array element, or a scalar: lose!
*/
TclObjVarErrMsg(interp, arrayNameObj, NULL, "array set",
NEEDARRAY, -1);
TclSetErrorCode(interp, "TCL", "WRITE", "ARRAY");
return TCL_ERROR;
}
}
TclInitArrayVar(varPtr);
return TCL_OK;
}
|
| ︙ | ︙ | |||
4260 4261 4262 4263 4264 4265 4266 |
if (!isArray) {
return NotArrayError(interp, varNameObj);
}
stats = Tcl_HashStats((Tcl_HashTable *) varPtr->value.tablePtr);
if (stats == NULL) {
| < | | 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 |
if (!isArray) {
return NotArrayError(interp, varNameObj);
}
stats = Tcl_HashStats((Tcl_HashTable *) varPtr->value.tablePtr);
if (stats == NULL) {
TclPrintfResult(interp, "error reading array statistics");
return TCL_ERROR;
}
Tcl_SetObjResult(interp, Tcl_NewStringObj(stats, -1));
Tcl_Free(stats);
return TCL_OK;
}
|
| ︙ | ︙ | |||
4528 4529 4530 4531 4532 4533 4534 |
if (!(arrayPtr != NULL
? (TclIsVarInHash(arrayPtr) && TclGetVarNsPtr(arrayPtr))
: (TclIsVarInHash(otherPtr) && TclGetVarNsPtr(otherPtr)))
&& ((myFlags & (TCL_GLOBAL_ONLY | TCL_NAMESPACE_ONLY))
|| (varFramePtr == NULL)
|| !HasLocalVars(varFramePtr)
|| (strstr(TclGetString(myNamePtr), "::") != NULL))) {
| | | | | 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 |
if (!(arrayPtr != NULL
? (TclIsVarInHash(arrayPtr) && TclGetVarNsPtr(arrayPtr))
: (TclIsVarInHash(otherPtr) && TclGetVarNsPtr(otherPtr)))
&& ((myFlags & (TCL_GLOBAL_ONLY | TCL_NAMESPACE_ONLY))
|| (varFramePtr == NULL)
|| !HasLocalVars(varFramePtr)
|| (strstr(TclGetString(myNamePtr), "::") != NULL))) {
TclPrintfResult((Tcl_Interp *) iPtr,
"bad variable name \"%s\": can't create namespace "
"variable that refers to procedure variable",
TclGetString(myNamePtr));
TclSetErrorCode(interp, "TCL", "UPVAR", "INVERTED");
return TCL_ERROR;
}
}
return TclPtrObjMakeUpvarIdx(interp, otherPtr, myNamePtr, myFlags, index);
}
|
| ︙ | ︙ | |||
4644 4645 4646 4647 4648 4649 4650 |
if (p != NULL) {
p += strlen(p)-1;
if (*p == ')') {
/*
* myName looks like an array reference.
*/
| | | | < | | | | | | | | | | | | 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 |
if (p != NULL) {
p += strlen(p)-1;
if (*p == ')') {
/*
* myName looks like an array reference.
*/
TclPrintfResult((Tcl_Interp *) iPtr,
"bad variable name \"%s\": can't create a scalar "
"variable that looks like an array element", myName);
TclSetErrorCode(interp, "TCL", "UPVAR", "LOCAL_ELEMENT");
return TCL_ERROR;
}
}
/*
* Lookup and eventually create the new variable. Set the flag bit
* TCL_AVOID_RESOLVERS to indicate the special resolution rules for
* upvar purposes:
* - Bug #696893 - variable is either proc-local or in the current
* namespace; never follow the second (global) resolution path.
* - Bug #631741 - do not use special namespace or interp resolvers.
*/
varPtr = TclLookupSimpleVar(interp, myNamePtr,
myFlags|TCL_AVOID_RESOLVERS, /* create */ 1, &errMsg, &index);
if (varPtr == NULL) {
TclObjVarErrMsg(interp, myNamePtr, NULL, "create", errMsg, -1);
TclSetErrorCode(interp, "TCL", "LOOKUP", "VARNAME",
TclGetString(myNamePtr));
return TCL_ERROR;
}
}
if (varPtr == otherPtr) {
TclPrintfResult((Tcl_Interp *) iPtr,
"can't upvar from variable to itself");
TclSetErrorCode(interp, "TCL", "UPVAR", "SELF");
return TCL_ERROR;
}
if (TclIsVarTraced(varPtr)) {
TclPrintfResult((Tcl_Interp *) iPtr,
"variable \"%s\" has traces: can't use for upvar", myName);
TclSetErrorCode(interp, "TCL", "UPVAR", "TRACED");
return TCL_ERROR;
} else if (!TclIsVarUndefined(varPtr)) {
Var *linkPtr;
/*
* The variable already existed. Make sure this variable "varPtr"
* isn't the same as "otherPtr" (avoid circular links). Also, if it's
* not an upvar then it's an error. If it is an upvar, then just
* disconnect it from the thing it currently refers to.
*/
if (!TclIsVarLink(varPtr)) {
TclPrintfResult((Tcl_Interp *) iPtr,
"variable \"%s\" already exists", myName);
TclSetErrorCode(interp, "TCL", "UPVAR", "EXISTS");
return TCL_ERROR;
}
linkPtr = varPtr->value.linkPtr;
if (linkPtr == otherPtr) {
return TCL_OK;
}
|
| ︙ | ︙ | |||
4817 4818 4819 4820 4821 4822 4823 |
/*
* Add the full name of the containing namespace (if any), followed by the
* "::" separator, then the variable name.
*/
nsPtr = TclGetVarNsPtr(varPtr);
if (nsPtr) {
| | | | 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 |
/*
* Add the full name of the containing namespace (if any), followed by the
* "::" separator, then the variable name.
*/
nsPtr = TclGetVarNsPtr(varPtr);
if (nsPtr) {
Tcl_AppendToObj(objPtr, nsPtr->fullName, TCL_AUTO_LENGTH);
if (nsPtr != iPtr->globalNsPtr) {
TclAppendLiteralToObj(objPtr, "::");
}
}
if (TclIsVarInHash(varPtr)) {
if (!TclIsVarDeadHash(varPtr)) {
namePtr = VarHashGetKey(varPtr);
Tcl_AppendObjToObj(objPtr, namePtr);
}
|
| ︙ | ︙ | |||
4874 4875 4876 4877 4878 4879 4880 |
}
part1Ptr = objv[1];
varPtr = TclObjLookupVarEx(interp, part1Ptr, NULL, TCL_LEAVE_ERR_MSG,
"const", /*createPart1*/ 1, /*createPart2*/ 1, &arrayPtr);
if (TclIsVarArray(varPtr)) {
TclObjVarErrMsg(interp, part1Ptr, NULL, "make constant", ISARRAY, -1);
| | | | | 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 |
}
part1Ptr = objv[1];
varPtr = TclObjLookupVarEx(interp, part1Ptr, NULL, TCL_LEAVE_ERR_MSG,
"const", /*createPart1*/ 1, /*createPart2*/ 1, &arrayPtr);
if (TclIsVarArray(varPtr)) {
TclObjVarErrMsg(interp, part1Ptr, NULL, "make constant", ISARRAY, -1);
TclSetErrorCode(interp, "TCL", "LOOKUP", "CONST");
return TCL_ERROR;
}
if (TclIsVarArrayElement(varPtr)) {
if (TclIsVarUndefined(varPtr)) {
CleanupVar(varPtr, arrayPtr);
}
TclObjVarErrMsg(interp, part1Ptr, NULL, "make constant", ISARRAYELEMENT, -1);
TclSetErrorCode(interp, "TCL", "LOOKUP", "CONST");
return TCL_ERROR;
}
/*
* If already exists, either a constant (no problem) or an error.
*/
if (!TclIsVarUndefined(varPtr)) {
if (TclIsVarConstant(varPtr)) {
return TCL_OK;
}
TclObjVarErrMsg(interp, part1Ptr, NULL, "make constant", EXISTS, -1);
TclSetErrorCode(interp, "TCL", "LOOKUP", "CONST");
return TCL_ERROR;
}
/*
* Make the variable and flag it as a constant.
*/
if (TclPtrSetVar(interp, (Tcl_Var) varPtr, NULL, objv[1], NULL,
|
| ︙ | ︙ | |||
5067 5068 5069 5070 5071 5072 5073 | /* * Variable cannot be an element in an array. If arrayPtr is * non-NULL, it is, so throw up an error and return. */ TclObjVarErrMsg(interp, varNamePtr, NULL, "define", ISARRAYELEMENT, -1); | | | 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 |
/*
* Variable cannot be an element in an array. If arrayPtr is
* non-NULL, it is, so throw up an error and return.
*/
TclObjVarErrMsg(interp, varNamePtr, NULL, "define",
ISARRAYELEMENT, -1);
TclSetErrorCode(interp, "TCL", "UPVAR", "LOCAL_ELEMENT");
return TCL_ERROR;
}
if (varPtr == NULL) {
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
5215 5216 5217 5218 5219 5220 5221 |
}
if ((result == 0) && hasLevel) {
/*
* Synthesize an error message since TclObjGetFrame doesn't do this
* for this particular case.
*/
| < | | < | 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 |
}
if ((result == 0) && hasLevel) {
/*
* Synthesize an error message since TclObjGetFrame doesn't do this
* for this particular case.
*/
TclPrintfResult(interp, "bad level \"%s\"", TclGetString(levelObj));
TclSetErrorCode(interp, "TCL", "LOOKUP", "LEVEL", TclGetString(levelObj));
return TCL_ERROR;
}
/*
* We've now finished with parsing levels; skip to the variable names.
*/
|
| ︙ | ︙ | |||
5299 5300 5301 5302 5303 5304 5305 |
return searchPtr;
}
}
}
if ((handle[0] != 's') || (handle[1] != '-')
|| (strtoul(handle + 2, &end, 10), end == (handle + 2))
|| (*end != '-')) {
| < | | | < | | | 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 |
return searchPtr;
}
}
}
if ((handle[0] != 's') || (handle[1] != '-')
|| (strtoul(handle + 2, &end, 10), end == (handle + 2))
|| (*end != '-')) {
TclPrintfResult(interp, "illegal search identifier \"%s\"", handle);
} else if (strcmp(end + 1, TclGetString(varNamePtr)) != 0) {
TclPrintfResult(interp,
"search identifier \"%s\" isn't for variable \"%s\"",
handle, TclGetString(varNamePtr));
} else {
TclPrintfResult(interp, "couldn't find search \"%s\"", handle);
}
TclSetErrorCode(interp, "TCL", "LOOKUP", "ARRAYSEARCH", handle);
return NULL;
}
/*
*----------------------------------------------------------------------
*
* DeleteSearches --
|
| ︙ | ︙ | |||
5700 5701 5702 5703 5704 5705 5706 |
{
if (!part1Ptr) {
if (index == -1) {
Tcl_Panic("invalid part1Ptr and invalid index together");
}
part1Ptr = localName(((Interp *)interp)->varFramePtr, index);
}
| | | | 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 |
{
if (!part1Ptr) {
if (index == -1) {
Tcl_Panic("invalid part1Ptr and invalid index together");
}
part1Ptr = localName(((Interp *)interp)->varFramePtr, index);
}
TclPrintfResult(interp, "can't %s \"%s%s%s%s\": %s",
operation, TclGetString(part1Ptr), (part2Ptr ? "(" : ""),
(part2Ptr ? TclGetString(part2Ptr) : ""), (part2Ptr ? ")" : ""),
reason);
}
/*
*----------------------------------------------------------------------
*
* Internal functions for variable name object types --
*
|
| ︙ | ︙ | |||
5951 5952 5953 5954 5955 5956 5957 |
varPtr = VarHashFindVar(&nsPtr[search]->varTable, simpleNamePtr);
}
}
if (simpleName != name) {
Tcl_DecrRefCount(simpleNamePtr);
}
if ((varPtr == NULL) && (flags & TCL_LEAVE_ERR_MSG)) {
| < | | | 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 |
varPtr = VarHashFindVar(&nsPtr[search]->varTable, simpleNamePtr);
}
}
if (simpleName != name) {
Tcl_DecrRefCount(simpleNamePtr);
}
if ((varPtr == NULL) && (flags & TCL_LEAVE_ERR_MSG)) {
TclPrintfResult(interp, "unknown variable \"%s\"", name);
TclSetErrorCode(interp, "TCL", "LOOKUP", "VARIABLE", name);
}
return (Tcl_Var) varPtr;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
6857 6858 6859 6860 6861 6862 6863 |
if (!varPtr || TclIsVarUndefined(varPtr) || !isArray) {
return NotArrayError(interp, arrayNameObj);
}
defaultValueObj = TclGetArrayDefault(varPtr);
if (!defaultValueObj) {
/* Array default must exist. */
| < | | | 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 |
if (!varPtr || TclIsVarUndefined(varPtr) || !isArray) {
return NotArrayError(interp, arrayNameObj);
}
defaultValueObj = TclGetArrayDefault(varPtr);
if (!defaultValueObj) {
/* Array default must exist. */
TclPrintfResult(interp, "array has no default value");
TclSetErrorCode(interp, "TCL", "READ", "ARRAY", "DEFAULT");
return TCL_ERROR;
}
Tcl_SetObjResult(interp, defaultValueObj);
return TCL_OK;
case OPT_SET:
if (objc != 4) {
|
| ︙ | ︙ | |||
6888 6889 6890 6891 6892 6893 6894 | /* * Not a valid array name. */ CleanupVar(varPtr, arrayPtr); TclObjVarErrMsg(interp, arrayNameObj, NULL, "array default set", NEEDARRAY, -1); | | | | | 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 |
/*
* Not a valid array name.
*/
CleanupVar(varPtr, arrayPtr);
TclObjVarErrMsg(interp, arrayNameObj, NULL, "array default set",
NEEDARRAY, -1);
TclSetErrorCode(interp, "TCL", "LOOKUP", "VARNAME",
TclGetString(arrayNameObj));
return TCL_ERROR;
}
if (!TclIsVarArray(varPtr) && !TclIsVarUndefined(varPtr)) {
/*
* Not an array.
*/
TclObjVarErrMsg(interp, arrayNameObj, NULL, "array default set",
NEEDARRAY, -1);
TclSetErrorCode(interp, "TCL", "WRITE", "ARRAY");
return TCL_ERROR;
}
if (!TclIsVarArray(varPtr)) {
TclInitArrayVar(varPtr);
}
defaultValueObj = objv[3];
|
| ︙ | ︙ |
Changes to generic/tclZipfs.c.
| ︙ | ︙ | |||
50 51 52 53 54 55 56 |
if (interp) { \
Tcl_SetObjResult(interp, Tcl_NewStringObj(errstr, -1)); \
} \
} while (0)
#define ZIPFS_MEM_ERROR(interp) \
do { \
if (interp) { \
| < | | | | | < | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
if (interp) { \
Tcl_SetObjResult(interp, Tcl_NewStringObj(errstr, -1)); \
} \
} while (0)
#define ZIPFS_MEM_ERROR(interp) \
do { \
if (interp) { \
TclPrintfResult(interp, "out of memory"); \
TclSetErrorCode(interp, "TCL", "MALLOC"); \
} \
} while (0)
#define ZIPFS_POSIX_ERROR(interp,errstr) \
do { \
if (interp) { \
TclPrintfResult(interp, \
"%s: %s", errstr, Tcl_PosixError(interp)); \
} \
} while (0)
#define ZIPFS_ERROR_CODE(interp,errcode) \
do { \
if (interp) { \
TclSetErrorCode(interp, "TCL", "ZIPFS", errcode); \
} \
} while (0)
#include "zlib.h"
#include "crypt.h"
#include "zutil.h"
#include "crc32.h"
|
| ︙ | ︙ | |||
1116 1117 1118 1119 1120 1121 1122 |
Tcl_DStringFree(&dsJoin);
Tcl_DStringAppend(dsPtr, normalizedPath, normalizedLen);
Tcl_DecrRefCount(normalizedObj);
return TCL_OK;
invalidMountPath:
if (interp) {
| < | | 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 |
Tcl_DStringFree(&dsJoin);
Tcl_DStringAppend(dsPtr, normalizedPath, normalizedLen);
Tcl_DecrRefCount(normalizedObj);
return TCL_OK;
invalidMountPath:
if (interp) {
TclPrintfResult(interp, "Invalid mount path \"%s\"", mountPath);
ZIPFS_ERROR_CODE(interp, "MOUNT_PATH");
}
errorReturn:
Tcl_DStringFree(&dsJoin);
return TCL_ERROR;
}
|
| ︙ | ︙ | |||
1971 1972 1973 1974 1975 1976 1977 |
WriteLock();
hPtr = Tcl_CreateHashEntry(&ZipFS.zipHash, mountPoint, &isNew);
if (!isNew) {
if (interp) {
zf0 = (ZipFile *) Tcl_GetHashValue(hPtr);
| | | | 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 |
WriteLock();
hPtr = Tcl_CreateHashEntry(&ZipFS.zipHash, mountPoint, &isNew);
if (!isNew) {
if (interp) {
zf0 = (ZipFile *) Tcl_GetHashValue(hPtr);
TclPrintfResult(interp,
"%s is already mounted on %s", zf0->name, mountPoint);
ZIPFS_ERROR_CODE(interp, "MOUNTED");
}
Unlock();
ZipFSCloseArchive(interp, zf);
Tcl_DStringFree(&ds);
Tcl_Free(zf);
return TCL_ERROR;
|
| ︙ | ︙ | |||
2084 2085 2086 2087 2088 2089 2090 | * APK due to the leading dot in the file name component. This * trick should make the files AndroidManifest.xml, * resources.arsc, and classes.dex visible to Tcl. */ Tcl_DString ds2; Tcl_DStringInit(&ds2); | | | < | 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 |
* APK due to the leading dot in the file name component. This
* trick should make the files AndroidManifest.xml,
* resources.arsc, and classes.dex visible to Tcl.
*/
Tcl_DString ds2;
Tcl_DStringInit(&ds2);
TclDStringAppendLiteral(&ds2, "assets/.root/");
Tcl_DStringAppend(&ds2, path, -1);
if (ZipFSLookup(Tcl_DStringValue(&ds2))) {
/* should not happen but skip it anyway */
Tcl_DStringFree(&ds2);
goto nextent;
}
Tcl_DStringSetLength(&ds, 0);
TclDStringAppendDString(&ds, &ds2);
path = Tcl_DStringValue(&ds);
Tcl_DStringFree(&ds2);
#else /* !ANDROID */
/*
* Regular files skipped when mounting on root.
*/
goto nextent;
|
| ︙ | ︙ | |||
2436 2437 2438 2439 2440 2441 2442 |
Unlock();
zipPathObj = Tcl_NewStringObj(zipname, -1);
Tcl_IncrRefCount(zipPathObj);
normZipPathObj = Tcl_FSGetNormalizedPath(interp, zipPathObj);
if (normZipPathObj == NULL) {
| | | | | 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 |
Unlock();
zipPathObj = Tcl_NewStringObj(zipname, -1);
Tcl_IncrRefCount(zipPathObj);
normZipPathObj = Tcl_FSGetNormalizedPath(interp, zipPathObj);
if (normZipPathObj == NULL) {
TclPrintfResult(interp,
"could not normalize zip filename \"%s\"", zipname);
TclSetErrorCode(interp, "TCL", "OPERATION", "NORMALIZE");
ret = TCL_ERROR;
} else {
Tcl_IncrRefCount(normZipPathObj);
const char *normPath = Tcl_GetString(normZipPathObj);
if (passwd == NULL ||
(ret = IsPasswordValid(interp, passwd,
strlen(passwd))) == TCL_OK) {
|
| ︙ | ︙ | |||
2897 2898 2899 2900 2901 2902 2903 |
if (Tcl_GetDoubleFromObj(interp, ret, &r) != TCL_OK) {
goto failed;
}
*chPtr = (int) (r * 256);
return TCL_OK;
failed:
| | | < | 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 |
if (Tcl_GetDoubleFromObj(interp, ret, &r) != TCL_OK) {
goto failed;
}
*chPtr = (int) (r * 256);
return TCL_OK;
failed:
TclPrintfErrorInfo(interp,
"\n (evaluating PRNG step %d for password encoding)", step);
return TCL_ERROR;
}
/*
*-------------------------------------------------------------------------
*
* ZipAddFile --
|
| ︙ | ︙ | |||
2984 2985 2986 2987 2988 2989 2990 |
TCL_INDEX_NONE, 0, &zpathDs, NULL) != TCL_OK) {
Tcl_DStringFree(&zpathDs);
return TCL_ERROR;
}
zpathExt = Tcl_DStringValue(&zpathDs);
zpathlen = strlen(zpathExt);
if (zpathlen + ZIP_CENTRAL_HEADER_LEN > bufsize) {
| | | | 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 |
TCL_INDEX_NONE, 0, &zpathDs, NULL) != TCL_OK) {
Tcl_DStringFree(&zpathDs);
return TCL_ERROR;
}
zpathExt = Tcl_DStringValue(&zpathDs);
zpathlen = strlen(zpathExt);
if (zpathlen + ZIP_CENTRAL_HEADER_LEN > bufsize) {
TclPrintfResult(interp,
"path too long for \"%s\"", TclGetString(pathObj));
ZIPFS_ERROR_CODE(interp, "PATH_LEN");
Tcl_DStringFree(&zpathDs);
return TCL_ERROR;
}
in = Tcl_FSOpenFileChannel(interp, pathObj, "rb", 0);
if (!in) {
Tcl_DStringFree(&zpathDs);
|
| ︙ | ︙ | |||
3026 3027 3028 3029 3030 3031 3032 |
if (len < 0) {
Tcl_DStringFree(&zpathDs);
if (nbyte == 0 && errno == EISDIR) {
Tcl_Close(interp, in);
return TCL_OK;
}
readErrorWithChannelOpen:
| | | | | | 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 |
if (len < 0) {
Tcl_DStringFree(&zpathDs);
if (nbyte == 0 && errno == EISDIR) {
Tcl_Close(interp, in);
return TCL_OK;
}
readErrorWithChannelOpen:
TclPrintfResult(interp, "read error on \"%s\": %s",
TclGetString(pathObj), Tcl_PosixError(interp));
Tcl_Close(interp, in);
return TCL_ERROR;
}
if (len == 0) {
break;
}
crc = crc32(crc, (unsigned char *) buf, len);
nbyte += len;
}
if (Tcl_Seek(in, 0, SEEK_SET) == -1) {
TclPrintfResult(interp, "seek error on \"%s\": %s",
TclGetString(pathObj), Tcl_PosixError(interp));
Tcl_Close(interp, in);
Tcl_DStringFree(&zpathDs);
return TCL_ERROR;
}
/*
* Remember where we've got to so far so we can write the header (after
|
| ︙ | ︙ | |||
3062 3063 3064 3065 3066 3067 3068 |
*/
memset(buf, '\0', ZIP_LOCAL_HEADER_LEN);
memcpy(buf + ZIP_LOCAL_HEADER_LEN, zpathExt, zpathlen);
len = zpathlen + ZIP_LOCAL_HEADER_LEN;
if (Tcl_Write(out, buf, len) != len) {
writeErrorWithChannelOpen:
| | | | 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 |
*/
memset(buf, '\0', ZIP_LOCAL_HEADER_LEN);
memcpy(buf + ZIP_LOCAL_HEADER_LEN, zpathExt, zpathlen);
len = zpathlen + ZIP_LOCAL_HEADER_LEN;
if (Tcl_Write(out, buf, len) != len) {
writeErrorWithChannelOpen:
TclPrintfResult(interp,
"write error on \"%s\": %s",
TclGetString(pathObj), Tcl_PosixError(interp));
Tcl_Close(interp, in);
Tcl_DStringFree(&zpathDs);
return TCL_ERROR;
}
/*
* Align payload to next 4-byte boundary (if necessary) using a dummy
|
| ︙ | ︙ | |||
3140 3141 3142 3143 3144 3145 3146 |
compMeth = ZIP_COMPMETH_DEFLATED;
memset(&stream, 0, sizeof(z_stream));
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = Z_NULL;
if (deflateInit2(&stream, 9, Z_DEFLATED, -15, 8,
Z_DEFAULT_STRATEGY) != Z_OK) {
| | | | | | 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 |
compMeth = ZIP_COMPMETH_DEFLATED;
memset(&stream, 0, sizeof(z_stream));
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = Z_NULL;
if (deflateInit2(&stream, 9, Z_DEFLATED, -15, 8,
Z_DEFAULT_STRATEGY) != Z_OK) {
TclPrintfResult(interp,
"compression init error on \"%s\"", TclGetString(pathObj));
ZIPFS_ERROR_CODE(interp, "DEFLATE_INIT");
Tcl_Close(interp, in);
Tcl_DStringFree(&zpathDs);
return TCL_ERROR;
}
do {
len = Tcl_Read(in, buf, bufsize);
if (len < 0) {
deflateEnd(&stream);
goto readErrorWithChannelOpen;
}
stream.avail_in = len;
stream.next_in = (unsigned char *) buf;
flush = Tcl_Eof(in) ? Z_FINISH : Z_NO_FLUSH;
do {
stream.avail_out = sizeof(obuf);
stream.next_out = (unsigned char *) obuf;
len = deflate(&stream, flush);
if (len == Z_STREAM_ERROR) {
TclPrintfResult(interp,
"deflate error on \"%s\"", TclGetString(pathObj));
ZIPFS_ERROR_CODE(interp, "DEFLATE");
deflateEnd(&stream);
Tcl_Close(interp, in);
Tcl_DStringFree(&zpathDs);
return TCL_ERROR;
}
olen = sizeof(obuf) - stream.avail_out;
|
| ︙ | ︙ | |||
3205 3206 3207 3208 3209 3210 3211 |
*/
if (Tcl_Seek(in, 0, SEEK_SET) != 0) {
goto seekErr;
}
if (Tcl_Seek(out, dataStartOffset, SEEK_SET) != dataStartOffset) {
seekErr:
| < | | 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 |
*/
if (Tcl_Seek(in, 0, SEEK_SET) != 0) {
goto seekErr;
}
if (Tcl_Seek(out, dataStartOffset, SEEK_SET) != dataStartOffset) {
seekErr:
TclPrintfResult(interp, "seek error: %s", Tcl_PosixError(interp));
Tcl_Close(interp, in);
Tcl_DStringFree(&zpathDs);
return TCL_ERROR;
}
nbytecompr = (passwd ? ZIP_CRYPT_HDR_LEN : 0);
while (1) {
len = Tcl_Read(in, buf, bufsize);
|
| ︙ | ︙ | |||
3249 3250 3251 3252 3253 3254 3255 |
}
Tcl_Close(interp, in);
Tcl_DStringFree(&zpathDs);
zpathExt = NULL;
hPtr = Tcl_CreateHashEntry(fileHash, zpathTcl, &isNew);
if (!isNew) {
| | | | 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 |
}
Tcl_Close(interp, in);
Tcl_DStringFree(&zpathDs);
zpathExt = NULL;
hPtr = Tcl_CreateHashEntry(fileHash, zpathTcl, &isNew);
if (!isNew) {
TclPrintfResult(interp,
"non-unique path name \"%s\"", TclGetString(pathObj));
ZIPFS_ERROR_CODE(interp, "DUPLICATE_PATH");
return TCL_ERROR;
}
/*
* Remember that we've written the file (for central directory generation)
* and generate the local (per-file) header in the space that we reserved
|
| ︙ | ︙ | |||
3281 3282 3283 3284 3285 3286 3287 |
*/
SerializeLocalEntryHeader(start, end, (unsigned char *) buf, z,
zpathlen, align);
if (Tcl_Seek(out, headerStartOffset, SEEK_SET) != headerStartOffset) {
Tcl_DeleteHashEntry(hPtr);
Tcl_Free(z);
| < | < | < | | 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 |
*/
SerializeLocalEntryHeader(start, end, (unsigned char *) buf, z,
zpathlen, align);
if (Tcl_Seek(out, headerStartOffset, SEEK_SET) != headerStartOffset) {
Tcl_DeleteHashEntry(hPtr);
Tcl_Free(z);
TclPrintfResult(interp, "seek error: %s", Tcl_PosixError(interp));
return TCL_ERROR;
}
if (Tcl_Write(out, buf, ZIP_LOCAL_HEADER_LEN) != ZIP_LOCAL_HEADER_LEN) {
Tcl_DeleteHashEntry(hPtr);
Tcl_Free(z);
TclPrintfResult(interp, "write error: %s", Tcl_PosixError(interp));
return TCL_ERROR;
}
Tcl_Flush(out);
if (Tcl_Seek(out, dataEndOffset, SEEK_SET) != dataEndOffset) {
Tcl_DeleteHashEntry(hPtr);
Tcl_Free(z);
TclPrintfResult(interp, "seek error: %s", Tcl_PosixError(interp));
return TCL_ERROR;
}
return TCL_OK;
}
/*
*-------------------------------------------------------------------------
|
| ︙ | ︙ | |||
3322 3323 3324 3325 3326 3327 3328 |
ZipFSFind(
Tcl_Interp *interp,
Tcl_Obj *dirRoot)
{
Tcl_Obj *cmd[2];
int result;
| | | 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 |
ZipFSFind(
Tcl_Interp *interp,
Tcl_Obj *dirRoot)
{
Tcl_Obj *cmd[2];
int result;
cmd[0] = TclNewString("::tcl::zipfs::find");
cmd[1] = dirRoot;
Tcl_IncrRefCount(cmd[0]);
result = Tcl_EvalObjv(interp, 2, cmd, 0);
Tcl_DecrRefCount(cmd[0]);
if (result != TCL_OK) {
return NULL;
}
|
| ︙ | ︙ | |||
3559 3560 3561 3562 3563 3564 3565 |
* Copy everything up to the ZIP-related suffix.
*/
if ((size_t)Tcl_Write(out, (char *) zf->data,
zf->passOffset) != zf->passOffset) {
memset(passBuf, 0, sizeof(passBuf));
Tcl_DecrRefCount(list);
| | | | 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 |
* Copy everything up to the ZIP-related suffix.
*/
if ((size_t)Tcl_Write(out, (char *) zf->data,
zf->passOffset) != zf->passOffset) {
memset(passBuf, 0, sizeof(passBuf));
Tcl_DecrRefCount(list);
TclPrintfResult(interp,
"write error: %s", Tcl_PosixError(interp));
Tcl_Close(interp, out);
if (zf == &zf0) {
ZipFSCloseArchive(interp, zf);
} else {
WriteLock();
zf->numOpen--;
Unlock();
|
| ︙ | ︙ | |||
3601 3602 3603 3604 3605 3606 3607 |
*/
len = strlen(passBuf);
if (len > 0) {
i = Tcl_Write(out, passBuf, len);
if (i != len) {
Tcl_DecrRefCount(list);
| | | | 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 |
*/
len = strlen(passBuf);
if (len > 0) {
i = Tcl_Write(out, passBuf, len);
if (i != len) {
Tcl_DecrRefCount(list);
TclPrintfResult(interp,
"write error: %s", Tcl_PosixError(interp));
Tcl_Close(interp, out);
return TCL_ERROR;
}
}
memset(passBuf, 0, sizeof(passBuf));
Tcl_Flush(out);
dataStartOffset = Tcl_Tell(out);
|
| ︙ | ︙ | |||
3668 3669 3670 3671 3672 3673 3674 |
name = Tcl_DStringValue(&ds);
len = Tcl_DStringLength(&ds);
SerializeCentralDirectoryEntry(start, end, (unsigned char *) buf,
z, len, dataStartOffset);
if ((Tcl_Write(out, buf, ZIP_CENTRAL_HEADER_LEN)
!= ZIP_CENTRAL_HEADER_LEN)
|| (Tcl_Write(out, name, len) != len)) {
| < | < | | 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 |
name = Tcl_DStringValue(&ds);
len = Tcl_DStringLength(&ds);
SerializeCentralDirectoryEntry(start, end, (unsigned char *) buf,
z, len, dataStartOffset);
if ((Tcl_Write(out, buf, ZIP_CENTRAL_HEADER_LEN)
!= ZIP_CENTRAL_HEADER_LEN)
|| (Tcl_Write(out, name, len) != len)) {
TclPrintfResult(interp, "write error: %s", Tcl_PosixError(interp));
Tcl_DStringFree(&ds);
goto done;
}
Tcl_DStringFree(&ds);
count++;
}
/*
* Finalize the central directory.
*/
Tcl_Flush(out);
suffixStartOffset = Tcl_Tell(out);
SerializeCentralDirectorySuffix(start, end, (unsigned char *) buf,
count, dataStartOffset, directoryStartOffset, suffixStartOffset);
if (Tcl_Write(out, buf, ZIP_CENTRAL_END_LEN) != ZIP_CENTRAL_END_LEN) {
TclPrintfResult(interp, "write error: %s", Tcl_PosixError(interp));
goto done;
}
Tcl_Flush(out);
ret = TCL_OK;
done:
if (ret == TCL_OK) {
|
| ︙ | ︙ | |||
3784 3785 3786 3787 3788 3789 3790 |
goto copyError;
}
}
Tcl_Close(interp, in);
return TCL_OK;
copyError:
| < | | 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 |
goto copyError;
}
}
Tcl_Close(interp, in);
return TCL_OK;
copyError:
TclPrintfResult(interp, "%s: %s", errMsg, Tcl_PosixError(interp));
Tcl_Close(interp, in);
return TCL_ERROR;
}
/*
* ---------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
4185 4186 4187 4188 4189 4190 4191 |
Tcl_ListObjAppendElement(interp, result,
Tcl_NewWideIntObj(z->numCompressedBytes));
Tcl_ListObjAppendElement(interp, result, Tcl_NewWideIntObj(z->offset));
ret = TCL_OK;
} else {
Tcl_SetErrno(ENOENT);
if (interp) {
| | | < | 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 |
Tcl_ListObjAppendElement(interp, result,
Tcl_NewWideIntObj(z->numCompressedBytes));
Tcl_ListObjAppendElement(interp, result, Tcl_NewWideIntObj(z->offset));
ret = TCL_OK;
} else {
Tcl_SetErrno(ENOENT);
if (interp) {
TclPrintfResult(interp,
"path \"%s\" not found in any zipfs volume", filename);
}
ret = TCL_ERROR;
}
Unlock();
return ret;
}
|
| ︙ | ︙ | |||
4846 4847 4848 4849 4850 4851 4852 |
int wr = (mode & (O_WRONLY | O_RDWR)) != 0;
/* Check for unsupported modes. */
if ((ZipFS.wrmax <= 0) && wr) {
Tcl_SetErrno(EACCES);
if (interp) {
| | | | | | | | | < | 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 |
int wr = (mode & (O_WRONLY | O_RDWR)) != 0;
/* Check for unsupported modes. */
if ((ZipFS.wrmax <= 0) && wr) {
Tcl_SetErrno(EACCES);
if (interp) {
TclPrintfResult(interp,
"writes not permitted: %s",
Tcl_PosixError(interp));
}
return NULL;
}
if ((mode & (O_APPEND|O_TRUNC)) && !wr) {
Tcl_SetErrno(EINVAL);
if (interp) {
TclPrintfResult(interp,
"Invalid flags 0x%x. O_APPEND and "
"O_TRUNC require write access: %s",
mode, Tcl_PosixError(interp));
}
return NULL;
}
/*
* Is the file there?
*/
WriteLock();
z = ZipFSLookup(filename);
if (!z) {
Tcl_SetErrno(wr ? ENOTSUP : ENOENT);
if (interp) {
TclPrintfResult(interp,
"file \"%s\" not %s: %s",
filename, wr ? "created" : "found",
Tcl_PosixError(interp));
}
goto error;
}
if (z->numBytes < 0 || z->numCompressedBytes < 0 ||
z->offset >= z->zipFilePtr->length) {
/* Normally this should only happen for zip64. */
ZIPFS_ERROR(interp, "file size error (may be zip64)");
ZIPFS_ERROR_CODE(interp, "FILE_SIZE");
goto error;
}
/* Do we support opening the file that way? */
if (wr && z->isDirectory) {
Tcl_SetErrno(EISDIR);
if (interp) {
TclPrintfResult(interp,
"unsupported file type: %s", Tcl_PosixError(interp));
}
goto error;
}
if ((z->compressMethod != ZIP_COMPMETH_STORED)
&& (z->compressMethod != ZIP_COMPMETH_DEFLATED)) {
ZIPFS_ERROR(interp, "unsupported compression method");
ZIPFS_ERROR_CODE(interp, "COMP_METHOD");
|
| ︙ | ︙ | |||
4924 4925 4926 4927 4928 4929 4930 |
/* Read-only */
flags |= TCL_READABLE;
}
if (z->isEncrypted) {
if (z->numCompressedBytes < ZIP_CRYPT_HDR_LEN) {
ZIPFS_ERROR(interp,
| | | 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 |
/* Read-only */
flags |= TCL_READABLE;
}
if (z->isEncrypted) {
if (z->numCompressedBytes < ZIP_CRYPT_HDR_LEN) {
ZIPFS_ERROR(interp,
"decryption failed: truncated decryption header");
ZIPFS_ERROR_CODE(interp, "DECRYPT");
goto error;
}
if (z->zipFilePtr->passBuf[0] == 0) {
ZIPFS_ERROR(interp, "decryption failed - no password provided");
ZIPFS_ERROR_CODE(interp, "DECRYPT");
goto error;
|
| ︙ | ︙ | |||
5561 5562 5563 5564 5565 5566 5567 |
*-------------------------------------------------------------------------
*/
static Tcl_Obj *
ZipFSFilesystemSeparatorProc(
TCL_UNUSED(Tcl_Obj *) /*pathPtr*/)
{
| | | 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 |
*-------------------------------------------------------------------------
*/
static Tcl_Obj *
ZipFSFilesystemSeparatorProc(
TCL_UNUSED(Tcl_Obj *) /*pathPtr*/)
{
return TclNewString("/");
}
/*
*-------------------------------------------------------------------------
*
* AppendWithPrefix --
*
|
| ︙ | ︙ | |||
5679 5680 5681 5682 5683 5684 5685 | /* * We need to strip the normalized prefix of the filenames and replace * it with the official prefix that we were expecting to get. */ strip = len + 1; Tcl_DStringAppend(&dsPref, prefix, prefixLen); | | | 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 |
/*
* We need to strip the normalized prefix of the filenames and replace
* it with the official prefix that we were expecting to get.
*/
strip = len + 1;
Tcl_DStringAppend(&dsPref, prefix, prefixLen);
TclDStringAppendLiteral(&dsPref, "/");
prefix = Tcl_DStringValue(&dsPref);
prefixBuf = &dsPref;
}
ReadLock();
/*
|
| ︙ | ︙ | |||
6104 6105 6106 6107 6108 6109 6110 |
TclNewIntObj(*objPtrRef, z ? z->offset : 0);
break;
case ZIP_ATTR_MOUNT:
if (z) {
*objPtrRef = Tcl_NewStringObj(z->zipFilePtr->mountPoint,
z->zipFilePtr->mountPointLen);
} else {
| | | | 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 |
TclNewIntObj(*objPtrRef, z ? z->offset : 0);
break;
case ZIP_ATTR_MOUNT:
if (z) {
*objPtrRef = Tcl_NewStringObj(z->zipFilePtr->mountPoint,
z->zipFilePtr->mountPointLen);
} else {
*objPtrRef = TclNewString("");
}
break;
case ZIP_ATTR_ARCHIVE:
*objPtrRef = Tcl_NewStringObj(z ? z->zipFilePtr->name : "", -1);
break;
case ZIP_ATTR_PERMISSIONS:
*objPtrRef = TclNewString("0o555");
break;
case ZIP_ATTR_CRC:
TclNewIntObj(*objPtrRef, z ? z->crc32 : 0);
break;
default:
ZIPFS_ERROR(interp, "unknown attribute");
ZIPFS_ERROR_CODE(interp, "FILE_ATTR");
|
| ︙ | ︙ | |||
6172 6173 6174 6175 6176 6177 6178 |
*-------------------------------------------------------------------------
*/
static Tcl_Obj *
ZipFSFilesystemPathTypeProc(
TCL_UNUSED(Tcl_Obj *) /*pathPtr*/)
{
| | | 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 |
*-------------------------------------------------------------------------
*/
static Tcl_Obj *
ZipFSFilesystemPathTypeProc(
TCL_UNUSED(Tcl_Obj *) /*pathPtr*/)
{
return TclNewString("zip");
}
/*
*-------------------------------------------------------------------------
*
* ZipFSLoadFile --
*
|
| ︙ | ︙ |
Changes to generic/tclZlib.c.
| ︙ | ︙ | |||
338 339 340 341 342 343 344 |
Tcl_SetObjResult(interp, Tcl_NewStringObj(zError(code), TCL_AUTO_LENGTH));
/*
* Tricky point! We might pass NULL twice here (and will when the error
* type is known).
*/
| | | 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
Tcl_SetObjResult(interp, Tcl_NewStringObj(zError(code), TCL_AUTO_LENGTH));
/*
* Tricky point! We might pass NULL twice here (and will when the error
* type is known).
*/
TclSetErrorCode(interp, "TCL", "ZLIB", codeStr, codeStr2);
}
static Tcl_Obj *
ConvertErrorToList(
int code, /* The zlib error code. */
uLong adler) /* The checksum expected (for Z_NEED_DICT) */
{
|
| ︙ | ︙ | |||
447 448 449 450 451 452 453 |
result = Tcl_UtfToExternal(NULL, latin1enc, valueStr, length,
TCL_ENCODING_START|TCL_ENCODING_END|TCL_ENCODING_PROFILE_STRICT,
&state, headerPtr->nativeCommentBuf, MAX_COMMENT_LEN - 1, NULL,
&len, NULL);
if (result != TCL_OK) {
if (interp) {
if (result == TCL_CONVERT_UNKNOWN) {
| | | | < | 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
result = Tcl_UtfToExternal(NULL, latin1enc, valueStr, length,
TCL_ENCODING_START|TCL_ENCODING_END|TCL_ENCODING_PROFILE_STRICT,
&state, headerPtr->nativeCommentBuf, MAX_COMMENT_LEN - 1, NULL,
&len, NULL);
if (result != TCL_OK) {
if (interp) {
if (result == TCL_CONVERT_UNKNOWN) {
TclPrintfResult(interp,
"Comment contains characters > 0xFF");
} else {
TclPrintfResult(interp, "Comment too large for zip");
}
}
result = TCL_ERROR; /* TCL_CONVERT_* -> TCL_ERROR */
goto error;
}
headerPtr->nativeCommentBuf[len] = '\0';
headerPtr->header.comment = (Bytef *) headerPtr->nativeCommentBuf;
|
| ︙ | ︙ | |||
483 484 485 486 487 488 489 |
result = Tcl_UtfToExternal(NULL, latin1enc, valueStr, length,
TCL_ENCODING_START|TCL_ENCODING_END|TCL_ENCODING_PROFILE_STRICT,
&state, headerPtr->nativeFilenameBuf, MAXPATHLEN - 1, NULL,
&len, NULL);
if (result != TCL_OK) {
if (interp) {
if (result == TCL_CONVERT_UNKNOWN) {
| | | < | | 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
result = Tcl_UtfToExternal(NULL, latin1enc, valueStr, length,
TCL_ENCODING_START|TCL_ENCODING_END|TCL_ENCODING_PROFILE_STRICT,
&state, headerPtr->nativeFilenameBuf, MAXPATHLEN - 1, NULL,
&len, NULL);
if (result != TCL_OK) {
if (interp) {
if (result == TCL_CONVERT_UNKNOWN) {
TclPrintfResult(interp,
"Filename contains characters > 0xFF");
} else {
TclPrintfResult(interp, "Filename too large for zip");
}
}
result = TCL_ERROR; /* TCL_CONVERT_* -> TCL_ERROR */
goto error;
}
headerPtr->nativeFilenameBuf[len] = '\0';
headerPtr->header.name = (Bytef *) headerPtr->nativeFilenameBuf;
|
| ︙ | ︙ | |||
825 826 827 828 829 830 831 |
goto error;
}
Tcl_DStringInit(&cmdname);
TclDStringAppendLiteral(&cmdname, "::tcl::zlib::streamcmd_");
TclDStringAppendObj(&cmdname, Tcl_GetObjResult(interp));
if (Tcl_FindCommand(interp, Tcl_DStringValue(&cmdname),
NULL, 0) != NULL) {
| | | | | 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 |
goto error;
}
Tcl_DStringInit(&cmdname);
TclDStringAppendLiteral(&cmdname, "::tcl::zlib::streamcmd_");
TclDStringAppendObj(&cmdname, Tcl_GetObjResult(interp));
if (Tcl_FindCommand(interp, Tcl_DStringValue(&cmdname),
NULL, 0) != NULL) {
TclPrintfResult(interp,
"BUG: Stream command name already exists");
TclSetErrorCode(interp, "TCL", "BUG", "EXISTING_CMD");
Tcl_DStringFree(&cmdname);
goto error;
}
Tcl_ResetResult(interp);
/*
* Create the command.
|
| ︙ | ︙ | |||
1217 1218 1219 1220 1221 1222 1223 |
int e;
Tcl_Size size = 0;
size_t outSize, toStore;
unsigned char *bytes;
if (zshPtr->streamEnd) {
if (zshPtr->interp) {
| | | | | 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 |
int e;
Tcl_Size size = 0;
size_t outSize, toStore;
unsigned char *bytes;
if (zshPtr->streamEnd) {
if (zshPtr->interp) {
TclPrintfResult(zshPtr->interp,
"already past compressed stream end");
TclSetErrorCode(zshPtr->interp, "TCL", "ZIP", "CLOSED");
}
return TCL_ERROR;
}
bytes = Tcl_GetBytesFromObj(zshPtr->interp, data, &size);
if (bytes == NULL) {
return TCL_ERROR;
|
| ︙ | ︙ | |||
1447 1448 1449 1450 1451 1452 1453 |
/*
* State: We have not satisfied the request yet and there may be
* more to inflate.
*/
if (zshPtr->stream.avail_in > 0) {
if (zshPtr->interp) {
| | | | < | 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 |
/*
* State: We have not satisfied the request yet and there may be
* more to inflate.
*/
if (zshPtr->stream.avail_in > 0) {
if (zshPtr->interp) {
TclPrintfResult(zshPtr->interp,
"unexpected zlib internal state during"
" decompression");
TclSetErrorCode(zshPtr->interp, "TCL", "ZIP", "STATE");
}
Tcl_SetByteArrayLength(data, existing);
return TCL_ERROR;
}
if (zshPtr->currentInput) {
Tcl_DecrRefCount(zshPtr->currentInput);
|
| ︙ | ︙ | |||
2216 2217 2218 2219 2220 2221 2222 |
* -> channel */
return ZlibPushSubcmd(interp, objc, objv);
}
return TCL_ERROR;
badLevel:
| < | | | | | | 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 |
* -> channel */
return ZlibPushSubcmd(interp, objc, objv);
}
return TCL_ERROR;
badLevel:
TclPrintfResult(interp, "level must be 0 to 9");
TclSetErrorCode(interp, "TCL", "VALUE", "COMPRESSIONLEVEL");
if (extraInfoStr) {
Tcl_AddErrorInfo(interp, extraInfoStr);
}
return TCL_ERROR;
badBuffer:
TclPrintfResult(interp,
"buffer size must be %d to %d",
MIN_NONSTREAM_BUFFER_SIZE, MAX_BUFFER_SIZE);
TclSetErrorCode(interp, "TCL", "VALUE", "BUFFERSIZE");
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* ZlibStreamSubcmd --
|
| ︙ | ︙ | |||
2361 2362 2363 2364 2365 2366 2367 |
*/
if (levelObj == NULL) {
level = Z_DEFAULT_COMPRESSION;
} else if (Tcl_GetIntFromObj(interp, levelObj, &level) != TCL_OK) {
return TCL_ERROR;
} else if (level < 0 || level > 9) {
| < | | | 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 |
*/
if (levelObj == NULL) {
level = Z_DEFAULT_COMPRESSION;
} else if (Tcl_GetIntFromObj(interp, levelObj, &level) != TCL_OK) {
return TCL_ERROR;
} else if (level < 0 || level > 9) {
TclPrintfResult(interp, "level must be 0 to 9");
TclSetErrorCode(interp, "TCL", "VALUE", "COMPRESSIONLEVEL");
Tcl_AddErrorInfo(interp, "\n (in -level option)");
return TCL_ERROR;
}
if (compDictObj) {
if (NULL == Tcl_GetBytesFromObj(interp, compDictObj, (Tcl_Size *)NULL)) {
return TCL_ERROR;
|
| ︙ | ︙ | |||
2480 2481 2482 2483 2484 2485 2486 |
}
/*
* Sanity checks.
*/
if (mode == TCL_ZLIB_STREAM_DEFLATE && !(chanMode & TCL_WRITABLE)) {
| | | < | | | < | | | | < | | < | | < | | | | | < < | 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 |
}
/*
* Sanity checks.
*/
if (mode == TCL_ZLIB_STREAM_DEFLATE && !(chanMode & TCL_WRITABLE)) {
TclPrintfResult(interp,
"compression may only be applied to writable channels");
TclSetErrorCode(interp, "TCL", "ZIP", "UNWRITABLE");
return TCL_ERROR;
}
if (mode == TCL_ZLIB_STREAM_INFLATE && !(chanMode & TCL_READABLE)) {
TclPrintfResult(interp,
"decompression may only be applied to readable channels");
TclSetErrorCode(interp, "TCL", "ZIP", "UNREADABLE");
return TCL_ERROR;
}
/*
* Parse options.
*/
level = Z_DEFAULT_COMPRESSION;
for (i=4 ; i<objc ; i++) {
if (Tcl_GetIndexFromObj(interp, objv[i], pushOptions, "option", 0,
&option) != TCL_OK) {
return TCL_ERROR;
}
if (++i > objc - 1) {
TclPrintfResult(interp,
"value missing for %s option", pushOptions[option]);
TclSetErrorCode(interp, "TCL", "ZIP", "NOVAL");
return TCL_ERROR;
}
switch (option) {
case poHeader: /* -header headerDict */
headerObj = objv[i];
if (Tcl_DictObjSize(interp, headerObj, &dummy) != TCL_OK) {
goto genericOptionError;
}
break;
case poLevel: /* -level compLevel */
if (Tcl_GetIntFromObj(interp, objv[i], (int *) &level) != TCL_OK) {
goto genericOptionError;
}
if (level < 0 || level > 9) {
TclPrintfResult(interp, "level must be 0 to 9");
TclSetErrorCode(interp, "TCL", "VALUE", "COMPRESSIONLEVEL");
goto genericOptionError;
}
break;
case poLimit: /* -limit numBytes */
if (Tcl_GetIntFromObj(interp, objv[i], (int *) &limit) != TCL_OK) {
goto genericOptionError;
}
if (limit < 1 || limit > MAX_BUFFER_SIZE) {
TclPrintfResult(interp,
"read ahead limit must be 1 to %d", MAX_BUFFER_SIZE);
TclSetErrorCode(interp, "TCL", "VALUE", "BUFFERSIZE");
goto genericOptionError;
}
break;
case poDictionary: /* -dictionary compDict */
if (format == TCL_ZLIB_FORMAT_GZIP) {
TclPrintfResult(interp,
"a compression dictionary may not be set in the "
"gzip format");
TclSetErrorCode(interp, "TCL", "ZIP", "BADOPT");
goto genericOptionError;
}
compDictObj = objv[i];
break;
}
}
if (compDictObj && (NULL == Tcl_GetBytesFromObj(interp, compDictObj,
(Tcl_Size *)NULL))) {
return TCL_ERROR;
}
if (ZlibStackChannelTransform(interp, mode, format, level, limit, chan,
headerObj, compDictObj) == NULL) {
return TCL_ERROR;
}
Tcl_SetObjResult(interp, objv[3]);
return TCL_OK;
genericOptionError:
TclPrintfErrorInfo(interp, "\n (in %s option)", pushOptions[option]);
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* ZlibStreamCmd --
|
| ︙ | ︙ | |||
2756 2757 2758 2759 2760 2761 2762 |
flush = -2;
} else {
flush = Z_FINISH;
}
break;
case ao_buffer: /* -buffer bufferSize */
if (i == objc - 2) {
| | | | | | < | | | | | | | | 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 |
flush = -2;
} else {
flush = Z_FINISH;
}
break;
case ao_buffer: /* -buffer bufferSize */
if (i == objc - 2) {
TclPrintfResult(interp,
"\"-buffer\" option must be followed by integer "
"decompression buffersize");
TclSetErrorCode(interp, "TCL", "ZIP", "NOVAL");
return TCL_ERROR;
}
if (Tcl_GetIntFromObj(interp, objv[++i], &buffersize) != TCL_OK) {
return TCL_ERROR;
}
if (buffersize < 1 || buffersize > MAX_BUFFER_SIZE) {
TclPrintfResult(interp,
"buffer size must be 1 to %d", MAX_BUFFER_SIZE);
TclSetErrorCode(interp, "TCL", "VALUE", "BUFFERSIZE");
return TCL_ERROR;
}
break;
case ao_dictionary: /* -dictionary compDict */
if (i == objc - 2) {
TclPrintfResult(interp,
"\"-dictionary\" option must be followed by"
" compression dictionary bytes");
TclSetErrorCode(interp, "TCL", "ZIP", "NOVAL");
return TCL_ERROR;
}
compDictObj = objv[++i];
break;
}
if (flush == -2) {
TclPrintfResult(interp,
"\"-flush\", \"-fullflush\" and \"-finalize\" options"
" are mutually exclusive");
TclSetErrorCode(interp, "TCL", "ZIP", "EXCLUSIVE");
return TCL_ERROR;
}
}
if (flush == -1) {
flush = 0;
}
|
| ︙ | ︙ | |||
2883 2884 2885 2886 2887 2888 2889 |
flush = -2;
} else {
flush = Z_FINISH;
}
break;
case po_dictionary: /* -dictionary compDict */
if (i == objc - 2) {
| | | | | | | | 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 |
flush = -2;
} else {
flush = Z_FINISH;
}
break;
case po_dictionary: /* -dictionary compDict */
if (i == objc - 2) {
TclPrintfResult(interp,
"\"-dictionary\" option must be followed by"
" compression dictionary bytes");
TclSetErrorCode(interp, "TCL", "ZIP", "NOVAL");
return TCL_ERROR;
}
compDictObj = objv[++i];
break;
}
if (flush == -2) {
TclPrintfResult(interp,
"\"-flush\", \"-fullflush\" and \"-finalize\" options"
" are mutually exclusive");
TclSetErrorCode(interp, "TCL", "ZIP", "EXCLUSIVE");
return TCL_ERROR;
}
}
if (flush == -1) {
flush = 0;
}
|
| ︙ | ︙ | |||
2942 2943 2944 2945 2946 2947 2948 |
Tcl_Obj *resultObj;
if (objc != 2) {
Tcl_WrongNumArgs(interp, 2, objv, NULL);
return TCL_ERROR;
} else if (zshPtr->mode != TCL_ZLIB_STREAM_INFLATE
|| zshPtr->format != TCL_ZLIB_FORMAT_GZIP) {
| | | < | | 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 |
Tcl_Obj *resultObj;
if (objc != 2) {
Tcl_WrongNumArgs(interp, 2, objv, NULL);
return TCL_ERROR;
} else if (zshPtr->mode != TCL_ZLIB_STREAM_INFLATE
|| zshPtr->format != TCL_ZLIB_FORMAT_GZIP) {
TclPrintfResult(interp,
"only gunzip streams can produce header information");
TclSetErrorCode(interp, "TCL", "ZIP", "BADOP");
return TCL_ERROR;
}
TclNewObj(resultObj);
ExtractHeader(&zshPtr->gzHeaderPtr->header, resultObj);
Tcl_SetObjResult(interp, resultObj);
return TCL_OK;
|
| ︙ | ︙ | |||
3031 3032 3033 3034 3035 3036 3037 |
}
if (written && Tcl_WriteRaw(chanDataPtr->parent,
chanDataPtr->outBuffer, written) == TCL_IO_FAILURE) {
/* TODO: is this the right way to do errors on close?
* Note: when close is called from FinalizeIOSubsystem then
* interp may be NULL */
if (!TclInThreadExit() && interp) {
| | | | 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 |
}
if (written && Tcl_WriteRaw(chanDataPtr->parent,
chanDataPtr->outBuffer, written) == TCL_IO_FAILURE) {
/* TODO: is this the right way to do errors on close?
* Note: when close is called from FinalizeIOSubsystem then
* interp may be NULL */
if (!TclInThreadExit() && interp) {
TclPrintfResult(interp,
"error while finalizing file: %s",
Tcl_PosixError(interp));
}
result = TCL_ERROR;
break;
}
} while (e != Z_STREAM_END);
(void) deflateEnd(&chanDataPtr->outStream);
} else {
|
| ︙ | ︙ | |||
3167 3168 3169 3170 3171 3172 3173 | *errorCodePtr = Tcl_GetErrno(); return -1; } /* more bytes (or Eof if readBytes == 0) */ chanDataPtr->inStream.avail_in += readBytes; | | | 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 |
*errorCodePtr = Tcl_GetErrno();
return -1;
}
/* more bytes (or Eof if readBytes == 0) */
chanDataPtr->inStream.avail_in += readBytes;
copyDecompressed:
/*
* Transform the read chunk, if not empty. Anything we get
* back is a transformation result to be put into our buffers, and
* the next iteration will put it into the result.
* For the case readBytes is 0 which signaling Eof in parent, the
* partial data waiting is converted and returned.
|
| ︙ | ︙ | |||
3270 3271 3272 3273 3274 3275 3276 |
}
if (e == Z_OK) {
return toWrite - chanDataPtr->outStream.avail_in;
}
errObj = Tcl_NewListObj(0, NULL);
| | < | 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 |
}
if (e == Z_OK) {
return toWrite - chanDataPtr->outStream.avail_in;
}
errObj = Tcl_NewListObj(0, NULL);
Tcl_ListObjAppendElement(NULL, errObj, TclNewString("-errorcode"));
Tcl_ListObjAppendElement(NULL, errObj,
ConvertErrorToList(e, chanDataPtr->outStream.adler));
Tcl_ListObjAppendElement(NULL, errObj,
Tcl_NewStringObj(chanDataPtr->outStream.msg, TCL_AUTO_LENGTH));
Tcl_SetChannelError(chanDataPtr->parent, errObj);
*errorCodePtr = EINVAL;
return -1;
|
| ︙ | ︙ | |||
3319 3320 3321 3322 3323 3324 3325 |
/*
* Write the bytes we've received to the next layer.
*/
if (len > 0 && Tcl_WriteRaw(chanDataPtr->parent, chanDataPtr->outBuffer,
len) == TCL_IO_FAILURE) {
| | | < | 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 |
/*
* Write the bytes we've received to the next layer.
*/
if (len > 0 && Tcl_WriteRaw(chanDataPtr->parent, chanDataPtr->outBuffer,
len) == TCL_IO_FAILURE) {
TclPrintfResult(interp,
"problem flushing channel: %s", Tcl_PosixError(interp));
return TCL_ERROR;
}
/*
* If we get to this point, either we're in the Z_OK or the
* Z_BUF_ERROR state. In the former case, we're done. In the latter
* case, it's because there's more bytes to go than would fit in the
|
| ︙ | ︙ | |||
3405 3406 3407 3408 3409 3410 3411 |
int flushType;
if (value[0] == 'f' && strcmp(value, "full") == 0) {
flushType = Z_FULL_FLUSH;
} else if (value[0] == 's' && strcmp(value, "sync") == 0) {
flushType = Z_SYNC_FLUSH;
} else {
| | | | < | | < | 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 |
int flushType;
if (value[0] == 'f' && strcmp(value, "full") == 0) {
flushType = Z_FULL_FLUSH;
} else if (value[0] == 's' && strcmp(value, "sync") == 0) {
flushType = Z_SYNC_FLUSH;
} else {
TclPrintfResult(interp,
"unknown -flush type \"%s\": must be full or sync",
value);
TclSetErrorCode(interp, "TCL", "VALUE", "FLUSH");
return TCL_ERROR;
}
/*
* Try to actually do the flush now.
*/
return ZlibTransformFlush(interp, chanDataPtr, flushType);
}
} else {
if (optionName && strcmp(optionName, "-limit") == 0) {
int newLimit;
if (Tcl_GetInt(interp, value, &newLimit) != TCL_OK) {
return TCL_ERROR;
} else if (newLimit < 1 || newLimit > MAX_BUFFER_SIZE) {
TclPrintfResult(interp, "-limit must be between 1 and 65536");
TclSetErrorCode(interp, "TCL", "VALUE", "READLIMIT");
return TCL_ERROR;
}
}
}
if (setOptionProc == NULL) {
if (chanDataPtr->format == TCL_ZLIB_FORMAT_GZIP) {
|
| ︙ | ︙ | |||
3522 3523 3524 3525 3526 3527 3528 |
Tcl_DStringAppendElement(dsPtr,
TclGetString(chanDataPtr->compDictObj));
} else {
Tcl_DStringAppendElement(dsPtr, "");
}
} else {
if (chanDataPtr->compDictObj) {
| < | < < < | 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 |
Tcl_DStringAppendElement(dsPtr,
TclGetString(chanDataPtr->compDictObj));
} else {
Tcl_DStringAppendElement(dsPtr, "");
}
} else {
if (chanDataPtr->compDictObj) {
TclDStringAppendObj(dsPtr, chanDataPtr->compDictObj);
}
return TCL_OK;
}
}
/*
* The "header" option, which is only valid on inflating gzip channels,
|
| ︙ | ︙ | |||
3973 3974 3975 3976 3977 3978 3979 |
}
}
return resBytes;
handleError:
errObj = Tcl_NewListObj(0, NULL);
| | < | 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 |
}
}
return resBytes;
handleError:
errObj = Tcl_NewListObj(0, NULL);
Tcl_ListObjAppendElement(NULL, errObj, TclNewString("-errorcode"));
Tcl_ListObjAppendElement(NULL, errObj,
ConvertErrorToList(e, chanDataPtr->inStream.adler));
Tcl_ListObjAppendElement(NULL, errObj,
Tcl_NewStringObj(chanDataPtr->inStream.msg, TCL_AUTO_LENGTH));
Tcl_SetChannelError(chanDataPtr->parent, errObj);
*errorCodePtr = EINVAL;
return -1;
|
| ︙ | ︙ |
Changes to macosx/tclMacOSXFCmd.c.
| ︙ | ︙ | |||
131 132 133 134 135 136 137 |
finderinfo *finder = (finderinfo *) &finfo.data;
off_t *rsrcForkSize = (off_t *) &finfo.data;
const char *native;
result = TclpObjStat(fileName, &statBuf);
if (result != 0) {
| | | | | | | | 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 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 |
finderinfo *finder = (finderinfo *) &finfo.data;
off_t *rsrcForkSize = (off_t *) &finfo.data;
const char *native;
result = TclpObjStat(fileName, &statBuf);
if (result != 0) {
TclPrintfResult(interp,
"could not read \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
return TCL_ERROR;
}
if (S_ISDIR(statBuf.st_mode) && objIndex != MACOSX_HIDDEN_ATTRIBUTE) {
/*
* Directories only support attribute "-hidden".
*/
errno = EISDIR;
TclPrintfResult(interp,
"invalid attribute: %s", Tcl_PosixError(interp));
return TCL_ERROR;
}
bzero(&alist, sizeof(struct attrlist));
alist.bitmapcount = ATTR_BIT_MAP_COUNT;
if (objIndex == MACOSX_RSRCLENGTH_ATTRIBUTE) {
alist.fileattr = ATTR_FILE_RSRCLENGTH;
} else {
alist.commonattr = ATTR_CMN_FNDRINFO;
}
native = (const char *)Tcl_FSGetNativePath(fileName);
result = getattrlist(native, &alist, &finfo, sizeof(fileinfobuf), 0);
if (result != 0) {
TclPrintfResult(interp,
"could not read attributes of \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
return TCL_ERROR;
}
switch (objIndex) {
case MACOSX_CREATOR_ATTRIBUTE:
*attributePtrPtr = NewOSTypeObj(
OSSwapBigToHostInt32(finder->creator));
|
| ︙ | ︙ | |||
184 185 186 187 188 189 190 |
break;
case MACOSX_RSRCLENGTH_ATTRIBUTE:
TclNewIntObj(*attributePtrPtr, *rsrcForkSize);
break;
}
return TCL_OK;
#else
| < | | | 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
break;
case MACOSX_RSRCLENGTH_ATTRIBUTE:
TclNewIntObj(*attributePtrPtr, *rsrcForkSize);
break;
}
return TCL_OK;
#else
TclPrintfResult(interp, "Mac OS X file attributes not supported");
TclSetErrorCode(interp, "TCL", "UNSUPPORTED");
return TCL_ERROR;
#endif /* HAVE_GETATTRLIST */
}
/*
*---------------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
227 228 229 230 231 232 233 |
finderinfo *finder = (finderinfo *) &finfo.data;
off_t *rsrcForkSize = (off_t *) &finfo.data;
const char *native;
result = TclpObjStat(fileName, &statBuf);
if (result != 0) {
| | | | | | | | 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
finderinfo *finder = (finderinfo *) &finfo.data;
off_t *rsrcForkSize = (off_t *) &finfo.data;
const char *native;
result = TclpObjStat(fileName, &statBuf);
if (result != 0) {
TclPrintfResult(interp,
"could not read \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
return TCL_ERROR;
}
if (S_ISDIR(statBuf.st_mode) && objIndex != MACOSX_HIDDEN_ATTRIBUTE) {
/*
* Directories only support attribute "-hidden".
*/
errno = EISDIR;
TclPrintfResult(interp,
"invalid attribute: %s", Tcl_PosixError(interp));
return TCL_ERROR;
}
bzero(&alist, sizeof(struct attrlist));
alist.bitmapcount = ATTR_BIT_MAP_COUNT;
if (objIndex == MACOSX_RSRCLENGTH_ATTRIBUTE) {
alist.fileattr = ATTR_FILE_RSRCLENGTH;
} else {
alist.commonattr = ATTR_CMN_FNDRINFO;
}
native = (const char *)Tcl_FSGetNativePath(fileName);
result = getattrlist(native, &alist, &finfo, sizeof(fileinfobuf), 0);
if (result != 0) {
TclPrintfResult(interp,
"could not read attributes of \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
return TCL_ERROR;
}
if (objIndex != MACOSX_RSRCLENGTH_ATTRIBUTE) {
OSType t;
int h;
|
| ︙ | ︙ | |||
294 295 296 297 298 299 300 |
break;
}
result = setattrlist(native, &alist,
&finfo.data, sizeof(finfo.data), 0);
if (result != 0) {
| | | | | | | 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
break;
}
result = setattrlist(native, &alist,
&finfo.data, sizeof(finfo.data), 0);
if (result != 0) {
TclPrintfResult(interp,
"could not set attributes of \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
return TCL_ERROR;
}
} else {
Tcl_WideInt newRsrcForkSize;
if (TclGetWideIntFromObj(interp, attributePtr,
&newRsrcForkSize) != TCL_OK) {
return TCL_ERROR;
}
if (newRsrcForkSize != *rsrcForkSize) {
Tcl_DString ds;
/*
* Only setting rsrclength to 0 to strip a file's resource fork is
* supported.
*/
if (newRsrcForkSize != 0) {
TclPrintfResult(interp,
"setting nonzero rsrclength not supported");
TclSetErrorCode(interp, "TCL", "UNSUPPORTED");
return TCL_ERROR;
}
/*
* Construct path to resource fork.
*/
|
| ︙ | ︙ | |||
348 349 350 351 352 353 354 |
result = close(fd);
}
}
Tcl_DStringFree(&ds);
if (result != 0) {
| | | < | | | 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
result = close(fd);
}
}
Tcl_DStringFree(&ds);
if (result != 0) {
TclPrintfResult(interp,
"could not truncate resource fork of \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
return TCL_ERROR;
}
}
}
return TCL_OK;
#else
TclPrintfResult(interp, "Mac OS X file attributes not supported");
TclSetErrorCode(interp, "TCL", "UNSUPPORTED");
return TCL_ERROR;
#endif
}
/*
*---------------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
629 630 631 632 633 634 635 |
Tcl_Size length;
string = TclGetStringFromObj(objPtr, &length);
Tcl_UtfToExternalDStringEx(NULL, encoding, string, length, TCL_ENCODING_PROFILE_TCL8, &ds, NULL);
if (Tcl_DStringLength(&ds) > 4) {
if (interp) {
| | | | | 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 |
Tcl_Size length;
string = TclGetStringFromObj(objPtr, &length);
Tcl_UtfToExternalDStringEx(NULL, encoding, string, length, TCL_ENCODING_PROFILE_TCL8, &ds, NULL);
if (Tcl_DStringLength(&ds) > 4) {
if (interp) {
TclPrintfResult(interp,
"expected Macintosh OS type but got \"%s\": ", string);
TclSetErrorCode(interp, "TCL", "VALUE", "MAC_OSTYPE");
}
result = TCL_ERROR;
} else {
OSType osType;
char bytes[4] = {'\0','\0','\0','\0'};
memcpy(bytes, Tcl_DStringValue(&ds), Tcl_DStringLength(&ds));
|
| ︙ | ︙ |
Changes to tests/fCmd.test.
| ︙ | ︙ | |||
2901 2902 2903 2904 2905 2906 2907 |
} -result relative/path
test fCmd-32.14.1 {Tcl_FSTildeExpand relative/path} -constraints testfstildeexpand -body {
testfstildeexpand relative/path
} -result relative/path
test fCmd-32.15 {file tildeexpand ~\\path} -body {
file tildeexpand ~\\foo
} -constraints win -result [file join $::env(HOME)/foo]
| | | | | | 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 |
} -result relative/path
test fCmd-32.14.1 {Tcl_FSTildeExpand relative/path} -constraints testfstildeexpand -body {
testfstildeexpand relative/path
} -result relative/path
test fCmd-32.15 {file tildeexpand ~\\path} -body {
file tildeexpand ~\\foo
} -constraints win -result [file join $::env(HOME)/foo]
test fCmd-32.15.1 {Tcl_FSTildeExpand ~\\path} -constraints {testfstildeexpand win} -body {
testfstildeexpand ~\\foo
} -result [file join $::env(HOME)/foo]
test fCmd-32.16 {file tildeexpand ~USER\\bar} -body {
# Note - as in 8.x this form does NOT necessarily give same result as
# env(HOME) even when user is current user. Assume result contains user
# name, else not sure how to check
string tolower [file tildeexpand ~$::tcl_platform(user)\\bar]
} -constraints win -match glob -result [file join [gethomedirglob $::tcl_platform(user)] bar]
test fCmd-32.16.1 {Tcl_FSTildeExpand ~USER\\bar} -constraints {testfstildeexpand win} -body {
# Note - as in 8.x this form does NOT necessarily give same result as
# env(HOME) even when user is current user. Assume result contains user
# name, else not sure how to check
string tolower [testfstildeexpand ~$::tcl_platform(user)\\bar]
} -match glob -result [file join [gethomedirglob $::tcl_platform(user)] bar]
test fCmd-32.17 {file tildeexpand ~USER does not mirror HOME} -setup {
set ::env(HOME) [file join $::env(HOME) foo]
} -cleanup {
set ::env(HOME) [file dirname $::env(HOME)]
} -body {
string tolower [file tildeexpand ~$::tcl_platform(user)]
} -match glob -result [gethomedirglob $::tcl_platform(user)]
|
| ︙ | ︙ |
Changes to unix/tclLoadDl.c.
| ︙ | ︙ | |||
125 126 127 128 129 130 131 |
* Write the string to a variable first to work around a compiler bug
* in the Sun Forte 6 compiler. [Bug 1503729]
*/
const char *errorStr = dlerror();
if (interp) {
| | | | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
* Write the string to a variable first to work around a compiler bug
* in the Sun Forte 6 compiler. [Bug 1503729]
*/
const char *errorStr = dlerror();
if (interp) {
TclPrintfResult(interp,
"couldn't load file \"%s\": %s",
TclGetString(pathPtr), errorStr);
}
return TCL_ERROR;
}
newHandle = (Tcl_LoadHandle)Tcl_Alloc(sizeof(*newHandle));
newHandle->clientData = handle;
newHandle->findSymbolProcPtr = &FindSymbol;
newHandle->unloadFileProcPtr = &UnloadFile;
|
| ︙ | ︙ | |||
225 226 227 228 229 230 231 |
if (proc == NULL) {
const char *errorStr = dlerror();
if (interp) {
if (!errorStr) {
errorStr = "unknown";
}
| | | | < | 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
if (proc == NULL) {
const char *errorStr = dlerror();
if (interp) {
if (!errorStr) {
errorStr = "unknown";
}
TclPrintfResult(interp,
"cannot find symbol \"%s\": %s", symbol, errorStr);
TclSetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol);
}
}
return proc;
}
/*
*----------------------------------------------------------------------
|
| ︙ | ︙ |
Changes to unix/tclLoadDyld.c.
| ︙ | ︙ | |||
160 161 162 163 164 165 166 |
*loadHandle = newHandle;
result = TCL_OK;
} else {
Tcl_Obj *errObj;
TclNewObj(errObj);
if (errMsg != NULL) {
| | | 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
*loadHandle = newHandle;
result = TCL_OK;
} else {
Tcl_Obj *errObj;
TclNewObj(errObj);
if (errMsg != NULL) {
Tcl_AppendToObj(errObj, errMsg, TCL_AUTO_LENGTH);
}
Tcl_SetObjResult(interp, errObj);
result = TCL_ERROR;
}
Tcl_DStringFree(&ds);
return result;
|
| ︙ | ︙ | |||
266 267 268 269 270 271 272 |
proc = (Tcl_LibraryInitProc *)NSAddressOfSymbol(nsSymbol);
}
Tcl_DStringFree(&newName);
#endif /* TCL_LOAD_FROM_MEMORY */
}
Tcl_DStringFree(&ds);
if (errMsg && (interp != NULL)) {
| | | | < | 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
proc = (Tcl_LibraryInitProc *)NSAddressOfSymbol(nsSymbol);
}
Tcl_DStringFree(&newName);
#endif /* TCL_LOAD_FROM_MEMORY */
}
Tcl_DStringFree(&ds);
if (errMsg && (interp != NULL)) {
TclPrintfResult(interp,
"cannot find symbol \"%s\": %s", symbol, errMsg);
TclSetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol);
}
return (void *)proc;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ |
Changes to unix/tclLoadNext.c.
| ︙ | ︙ | |||
96 97 98 99 100 101 102 |
}
if (!result) {
char *data;
int len, maxlen;
NXGetMemoryBuffer(errorStream, &data, &len, &maxlen);
| | | | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
}
if (!result) {
char *data;
int len, maxlen;
NXGetMemoryBuffer(errorStream, &data, &len, &maxlen);
TclPrintfResult(interp,
"couldn't load file \"%s\": %s", fileName, data);
NXCloseMemory(errorStream, NX_FREEBUFFER);
return TCL_ERROR;
}
NXCloseMemory(errorStream, NX_FREEBUFFER);
newHandle = (Tcl_LoadHandle)Tcl_Alloc(sizeof(*newHandle));
newHandle->clientData = INT2PTR(1);
|
| ︙ | ︙ | |||
146 147 148 149 150 151 152 |
sym[0] = '_';
sym[1] = 0;
strcat(sym, symbol);
rld_lookup(NULL, sym, (unsigned long *) &proc);
}
if (proc == NULL && interp != NULL) {
| < | | | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
sym[0] = '_';
sym[1] = 0;
strcat(sym, symbol);
rld_lookup(NULL, sym, (unsigned long *) &proc);
}
if (proc == NULL && interp != NULL) {
TclPrintfResult(interp, "cannot find symbol \"%s\"", symbol);
TclSetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol);
}
return proc;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ |
Changes to unix/tclLoadOSF.c.
| ︙ | ︙ | |||
106 107 108 109 110 111 112 |
}
native = Tcl_DStringValue(&ds);
lm = (Tcl_LibraryInitProc *) load(native, LDR_NOFLAGS);
Tcl_DStringFree(&ds);
}
if (lm == LDR_NULL_MODULE) {
| | | | 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
}
native = Tcl_DStringValue(&ds);
lm = (Tcl_LibraryInitProc *) load(native, LDR_NOFLAGS);
Tcl_DStringFree(&ds);
}
if (lm == LDR_NULL_MODULE) {
TclPrintfResult(interp,
"couldn't load file \"%s\": %s",
fileName, Tcl_PosixError(interp));
return TCL_ERROR;
}
*clientDataPtr = NULL;
/*
* My convention is to use a [OSF loader] package name the same as shlib,
|
| ︙ | ︙ | |||
163 164 165 166 167 168 169 |
Tcl_Interp *interp,
Tcl_LoadHandle loadHandle,
const char *symbol)
{
void *proc = ldr_lookup_package((char *) loadHandle, symbol);
if (proc == NULL && interp != NULL) {
| < | | | 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
Tcl_Interp *interp,
Tcl_LoadHandle loadHandle,
const char *symbol)
{
void *proc = ldr_lookup_package((char *) loadHandle, symbol);
if (proc == NULL && interp != NULL) {
TclPrintfResult(interp, "cannot find symbol \"%s\"", symbol);
TclSetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol);
}
return proc;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ |
Changes to unix/tclLoadShl.c.
| ︙ | ︙ | |||
92 93 94 95 96 97 98 |
}
native = Tcl_DStringValue(&ds);
handle = shl_load(native, BIND_DEFERRED|BIND_VERBOSE|DYNAMIC_PATH, 0L);
Tcl_DStringFree(&ds);
}
if (handle == NULL) {
| | | | 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
}
native = Tcl_DStringValue(&ds);
handle = shl_load(native, BIND_DEFERRED|BIND_VERBOSE|DYNAMIC_PATH, 0L);
Tcl_DStringFree(&ds);
}
if (handle == NULL) {
TclPrintfResult(interp,
"couldn't load file \"%s\": %s",
fileName, Tcl_PosixError(interp));
return TCL_ERROR;
}
newHandle = (Tcl_LoadHandle)Tcl_Alloc(sizeof(*newHandle));
newHandle->clientData = handle;
newHandle->findSymbolProcPtr = &FindSymbol;
newHandle->unloadFileProcPtr = *unloadProcPtr = &UnloadFile;
*loadHandle = newHandle;
|
| ︙ | ︙ | |||
148 149 150 151 152 153 154 |
if (shl_findsym(&handle, Tcl_DStringValue(&newName),
(short) TYPE_PROCEDURE, (void *)&proc) != 0) {
proc = NULL;
}
Tcl_DStringFree(&newName);
}
if (proc == NULL && interp != NULL) {
| | | | 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
if (shl_findsym(&handle, Tcl_DStringValue(&newName),
(short) TYPE_PROCEDURE, (void *)&proc) != 0) {
proc = NULL;
}
Tcl_DStringFree(&newName);
}
if (proc == NULL && interp != NULL) {
TclPrintfResult(interp,
"cannot find symbol \"%s\": %s",
symbol, Tcl_PosixError(interp));
}
return proc;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ |
Changes to unix/tclUnixChan.c.
| ︙ | ︙ | |||
107 108 109 110 111 112 113 |
int stop;
} TtyAttrs;
#endif /* SUPPORTS_TTY */
#define UNSUPPORTED_OPTION(detail) \
if (interp) { \
| | | | | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
int stop;
} TtyAttrs;
#endif /* SUPPORTS_TTY */
#define UNSUPPORTED_OPTION(detail) \
if (interp) { \
TclPrintfResult(interp, \
"%s not supported for this platform", (detail)); \
TclSetErrorCode(interp, "TCL", "UNSUPPORTED"); \
}
/*
* Static routines for this file:
*/
static int FileBlockModeProc(void *instanceData, int mode);
|
| ︙ | ︙ | |||
676 677 678 679 680 681 682 |
if ((len > 1) && (strncmp(optionName, "-stat", len) == 0)) {
Tcl_Obj *dictObj = StatOpenFile(fsPtr);
const char *dictContents;
Tcl_Size dictLength;
if (dictObj == NULL) {
| | | | 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
if ((len > 1) && (strncmp(optionName, "-stat", len) == 0)) {
Tcl_Obj *dictObj = StatOpenFile(fsPtr);
const char *dictContents;
Tcl_Size dictLength;
if (dictObj == NULL) {
TclPrintfResult(interp,
"couldn't read file channel status: %s",
Tcl_PosixError(interp));
return TCL_ERROR;
}
/*
* Transfer dictionary to the DString. Note that we don't do this as
* an element as this is an option that can't be retrieved with a
* general probe.
|
| ︙ | ︙ | |||
819 820 821 822 823 824 825 |
return TCL_ERROR;
#endif /* CRTSCTS */
} else if (strncasecmp(value, "DTRDSR", vlen) == 0) {
UNSUPPORTED_OPTION("-handshake DTRDSR");
return TCL_ERROR;
} else {
if (interp) {
| | | | | | | | | 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 |
return TCL_ERROR;
#endif /* CRTSCTS */
} else if (strncasecmp(value, "DTRDSR", vlen) == 0) {
UNSUPPORTED_OPTION("-handshake DTRDSR");
return TCL_ERROR;
} else {
if (interp) {
TclPrintfResult(interp,
"bad value for -handshake: must be one of"
" xonxoff, rtscts, dtrdsr or none");
TclSetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE",
"VALUE");
}
return TCL_ERROR;
}
tcsetattr(fsPtr->fileState.fd, TCSADRAIN, &iostate);
return TCL_OK;
}
/*
* Option -xchar {\x11 \x13}
*/
if ((len > 1) && (strncmp(optionName, "-xchar", len) == 0)) {
if (Tcl_SplitList(interp, value, &argc, &argv) == TCL_ERROR) {
return TCL_ERROR;
} else if (argc != 2) {
badXchar:
if (interp) {
TclPrintfResult(interp,
"bad value for -xchar: should be a list of"
" two elements with each a single 8-bit character");
TclSetErrorCode(interp, "TCL", "VALUE", "XCHAR");
}
Tcl_Free(argv);
return TCL_ERROR;
}
tcgetattr(fsPtr->fileState.fd, &iostate);
|
| ︙ | ︙ | |||
906 907 908 909 910 911 912 |
Tcl_Size i;
if (Tcl_SplitList(interp, value, &argc, &argv) == TCL_ERROR) {
return TCL_ERROR;
}
if ((argc % 2) == 1) {
if (interp) {
| | | | | | 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 |
Tcl_Size i;
if (Tcl_SplitList(interp, value, &argc, &argv) == TCL_ERROR) {
return TCL_ERROR;
}
if ((argc % 2) == 1) {
if (interp) {
TclPrintfResult(interp,
"bad value for -ttycontrol: should be a list of"
" signal,value pairs");
TclSetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE",
"VALUE");
}
Tcl_Free(argv);
return TCL_ERROR;
}
ioctl(fsPtr->fileState.fd, TIOCMGET, &control);
for (i = 0; i < argc-1; i += 2) {
|
| ︙ | ︙ | |||
948 949 950 951 952 953 954 |
#else /* TIOCSBRK & TIOCCBRK */
UNSUPPORTED_OPTION("-ttycontrol BREAK");
Tcl_Free(argv);
return TCL_ERROR;
#endif /* TIOCSBRK & TIOCCBRK */
} else {
if (interp) {
| | | | | | 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 |
#else /* TIOCSBRK & TIOCCBRK */
UNSUPPORTED_OPTION("-ttycontrol BREAK");
Tcl_Free(argv);
return TCL_ERROR;
#endif /* TIOCSBRK & TIOCCBRK */
} else {
if (interp) {
TclPrintfResult(interp,
"bad signal \"%s\" for -ttycontrol: must be"
" DTR, RTS or BREAK", argv[i]);
TclSetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE",
"VALUE");
}
Tcl_Free(argv);
return TCL_ERROR;
}
} /* -ttycontrol options loop */
ioctl(fsPtr->fileState.fd, TIOCMSET, &control);
|
| ︙ | ︙ | |||
980 981 982 983 984 985 986 |
fsPtr->closeMode = CLOSE_DEFAULT;
} else if (strncasecmp(value, "DRAIN", vlen) == 0) {
fsPtr->closeMode = CLOSE_DRAIN;
} else if (strncasecmp(value, "DISCARD", vlen) == 0) {
fsPtr->closeMode = CLOSE_DISCARD;
} else {
if (interp) {
| | | | | | | | 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 |
fsPtr->closeMode = CLOSE_DEFAULT;
} else if (strncasecmp(value, "DRAIN", vlen) == 0) {
fsPtr->closeMode = CLOSE_DRAIN;
} else if (strncasecmp(value, "DISCARD", vlen) == 0) {
fsPtr->closeMode = CLOSE_DISCARD;
} else {
if (interp) {
TclPrintfResult(interp,
"bad mode \"%s\" for -closemode: must be"
" default, discard, or drain", value);
TclSetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE",
"VALUE");
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
* Option -inputmode normal|password|raw
*/
if ((len > 2) && (strncmp(optionName, "-inputmode", len) == 0)) {
if (tcgetattr(fsPtr->fileState.fd, &iostate) < 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"couldn't read serial terminal control state: %s",
Tcl_PosixError(interp));
}
return TCL_ERROR;
}
if (strncasecmp(value, "NORMAL", vlen) == 0) {
SET_BITS(iostate.c_iflag, BRKINT | IGNPAR | ISTRIP | ICRNL | IXON);
SET_BITS(iostate.c_oflag, OPOST);
SET_BITS(iostate.c_lflag, ECHO | ECHONL | ICANON | ISIG);
|
| ︙ | ︙ | |||
1038 1039 1040 1041 1042 1043 1044 |
/*
* Reset to the initial state, whatever that is.
*/
memcpy(&iostate, &fsPtr->initState, sizeof(struct termios));
} else {
if (interp) {
| | | | | | | | 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 |
/*
* Reset to the initial state, whatever that is.
*/
memcpy(&iostate, &fsPtr->initState, sizeof(struct termios));
} else {
if (interp) {
TclPrintfResult(interp,
"bad mode \"%s\" for -inputmode: must be"
" normal, password, raw, or reset", value);
TclSetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE",
"VALUE");
}
return TCL_ERROR;
}
if (tcsetattr(fsPtr->fileState.fd, TCSADRAIN, &iostate) < 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"couldn't update serial terminal control state: %s",
Tcl_PosixError(interp));
}
return TCL_ERROR;
}
/*
* If we've changed the state from default, schedule a reset later.
* Note that this specifically does not detect changes made by calling
|
| ︙ | ︙ | |||
1147 1148 1149 1150 1151 1152 1153 |
if (len == 0) {
Tcl_DStringAppendElement(dsPtr, "-inputmode");
}
if (len==0 || (len>1 && strncmp(optionName, "-inputmode", len)==0)) {
valid = 1;
if (tcgetattr(fsPtr->fileState.fd, &iostate) < 0) {
if (interp != NULL) {
| | | | 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 |
if (len == 0) {
Tcl_DStringAppendElement(dsPtr, "-inputmode");
}
if (len==0 || (len>1 && strncmp(optionName, "-inputmode", len)==0)) {
valid = 1;
if (tcgetattr(fsPtr->fileState.fd, &iostate) < 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"couldn't read serial terminal control state: %s",
Tcl_PosixError(interp));
}
return TCL_ERROR;
}
if (iostate.c_lflag & ICANON) {
if (iostate.c_lflag & ECHO) {
Tcl_DStringAppendElement(dsPtr, "normal");
} else {
|
| ︙ | ︙ | |||
1257 1258 1259 1260 1261 1262 1263 |
if ((len > 1) && (strncmp(optionName, "-winsize", len) == 0)) {
struct winsize ws;
valid = 1;
if (ioctl(fsPtr->fileState.fd, TIOCGWINSZ, &ws) < 0) {
if (interp != NULL) {
| | | | 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 |
if ((len > 1) && (strncmp(optionName, "-winsize", len) == 0)) {
struct winsize ws;
valid = 1;
if (ioctl(fsPtr->fileState.fd, TIOCGWINSZ, &ws) < 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"couldn't read terminal size: %s",
Tcl_PosixError(interp));
}
return TCL_ERROR;
}
snprintf(buf, sizeof(buf), "%d", ws.ws_col);
Tcl_DStringAppendElement(dsPtr, buf);
snprintf(buf, sizeof(buf), "%d", ws.ws_row);
Tcl_DStringAppendElement(dsPtr, buf);
|
| ︙ | ︙ | |||
1618 1619 1620 1621 1622 1623 1624 |
i = sscanf(mode, "%d,%c,%d,%d%n",
&ttyPtr->baud,
&parity,
&ttyPtr->data,
&ttyPtr->stop, &end);
if ((i != 4) || (mode[end] != '\0')) {
if (interp != NULL) {
| | | | | 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 |
i = sscanf(mode, "%d,%c,%d,%d%n",
&ttyPtr->baud,
&parity,
&ttyPtr->data,
&ttyPtr->stop, &end);
if ((i != 4) || (mode[end] != '\0')) {
if (interp != NULL) {
TclPrintfResult(interp,
"%s: should be baud,parity,data,stop", bad);
TclSetErrorCode(interp, "TCL", "VALUE", "SERIALMODE");
}
return TCL_ERROR;
}
/*
* Only allow setting mark/space parity on platforms that support it Make
* sure to allow for the case where strchr is a macro. [Bug: 5089]
|
| ︙ | ︙ | |||
1644 1645 1646 1647 1648 1649 1650 |
#else
#define PARITY_CHARS "noe"
#define PARITY_MSG "n, o, or e"
#endif /* PAREXT */
if (strchr(PARITY_CHARS, parity) == NULL) {
if (interp != NULL) {
| | | | | | | | | | | 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 |
#else
#define PARITY_CHARS "noe"
#define PARITY_MSG "n, o, or e"
#endif /* PAREXT */
if (strchr(PARITY_CHARS, parity) == NULL) {
if (interp != NULL) {
TclPrintfResult(interp,
"%s parity: should be %s", bad, PARITY_MSG);
TclSetErrorCode(interp, "TCL", "VALUE", "SERIALMODE");
}
return TCL_ERROR;
}
ttyPtr->parity = parity;
if ((ttyPtr->data < 5) || (ttyPtr->data > 8)) {
if (interp != NULL) {
TclPrintfResult(interp,
"%s data: should be 5, 6, 7, or 8", bad);
TclSetErrorCode(interp, "TCL", "VALUE", "SERIALMODE");
}
return TCL_ERROR;
}
if ((ttyPtr->stop < 0) || (ttyPtr->stop > 2)) {
if (interp != NULL) {
TclPrintfResult(interp,
"%s stop: should be 1 or 2", bad);
TclSetErrorCode(interp, "TCL", "VALUE", "SERIALMODE");
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
1788 1789 1790 1791 1792 1793 1794 |
(*TclGetString(pathPtr) == '~') /* possible tilde expansion */
) &&
Tcl_FSGetNormalizedPath(interp, pathPtr) == NULL
) {
return NULL;
}
| | | | | | | 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 |
(*TclGetString(pathPtr) == '~') /* possible tilde expansion */
) &&
Tcl_FSGetNormalizedPath(interp, pathPtr) == NULL
) {
return NULL;
}
TclPrintfResult(interp,
"couldn't open \"%s\": filename is invalid on this platform",
TclGetString(pathPtr));
}
return NULL;
}
#ifdef DJGPP
SET_BITS(mode, O_BINARY);
#endif
fd = TclOSopen(native, mode, permissions);
if (fd < 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"couldn't open \"%s\": %s",
TclGetString(pathPtr), Tcl_PosixError(interp));
}
return NULL;
}
/*
* Set close-on-exec flag on the fd so that child processes will not
* inherit this fd.
|
| ︙ | ︙ | |||
2080 2081 2082 2083 2084 2085 2086 |
FILE *f;
chan = Tcl_GetChannel(interp, chanID, &chanMode);
if (chan == NULL) {
return TCL_ERROR;
}
if (forWriting && !(chanMode & TCL_WRITABLE)) {
| < | | < < | | < | 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 |
FILE *f;
chan = Tcl_GetChannel(interp, chanID, &chanMode);
if (chan == NULL) {
return TCL_ERROR;
}
if (forWriting && !(chanMode & TCL_WRITABLE)) {
TclPrintfResult(interp, "\"%s\" wasn't opened for writing", chanID);
TclSetErrorCode(interp, "TCL", "VALUE", "CHANNEL", "NOT_WRITABLE");
return TCL_ERROR;
} else if (!forWriting && !(chanMode & TCL_READABLE)) {
TclPrintfResult(interp, "\"%s\" wasn't opened for reading", chanID);
TclSetErrorCode(interp, "TCL", "VALUE", "CHANNEL", "NOT_READABLE");
return TCL_ERROR;
}
/*
* We allow creating a FILE * out of file based, pipe based and socket
* based channels. We currently do not allow any other channel types,
* because it is likely that stdio will not know what to do with them.
|
| ︙ | ︙ | |||
2118 2119 2120 2121 2122 2123 2124 |
* The call to fdopen below is probably dangerous, since it will
* truncate an existing file if the file is being opened for
* writing....
*/
f = fdopen(fd, (forWriting ? "w" : "r"));
if (f == NULL) {
| | | | | < | | < | 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 |
* The call to fdopen below is probably dangerous, since it will
* truncate an existing file if the file is being opened for
* writing....
*/
f = fdopen(fd, (forWriting ? "w" : "r"));
if (f == NULL) {
TclPrintfResult(interp,
"cannot get a FILE * for \"%s\"", chanID);
TclSetErrorCode(interp, "TCL", "VALUE", "CHANNEL",
"FILE_FAILURE");
return TCL_ERROR;
}
*filePtr = f;
return TCL_OK;
}
}
TclPrintfResult(interp, "\"%s\" cannot be used to get a FILE *", chanID);
TclSetErrorCode(interp, "TCL", "VALUE", "CHANNEL", "NO_DESCRIPTOR");
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* FileTruncateProc --
|
| ︙ | ︙ |
Changes to unix/tclUnixFCmd.c.
| ︙ | ︙ | |||
1335 1336 1337 1338 1339 1340 1341 |
struct group *groupPtr;
int result;
result = TclpObjStat(fileName, &statBuf);
if (result != 0) {
if (interp != NULL) {
| | | | 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 |
struct group *groupPtr;
int result;
result = TclpObjStat(fileName, &statBuf);
if (result != 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"could not read \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
}
return TCL_ERROR;
}
groupPtr = TclpGetGrGid(statBuf.st_gid);
if (groupPtr == NULL) {
|
| ︙ | ︙ | |||
1389 1390 1391 1392 1393 1394 1395 |
struct passwd *pwPtr;
int result;
result = TclpObjStat(fileName, &statBuf);
if (result != 0) {
if (interp != NULL) {
| | | | 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 |
struct passwd *pwPtr;
int result;
result = TclpObjStat(fileName, &statBuf);
if (result != 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"could not read \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
}
return TCL_ERROR;
}
pwPtr = TclpGetPwUid(statBuf.st_uid);
if (pwPtr == NULL) {
|
| ︙ | ︙ | |||
1440 1441 1442 1443 1444 1445 1446 |
Tcl_StatBuf statBuf;
int result;
result = TclpObjStat(fileName, &statBuf);
if (result != 0) {
if (interp != NULL) {
| | | | 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 |
Tcl_StatBuf statBuf;
int result;
result = TclpObjStat(fileName, &statBuf);
if (result != 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"could not read \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
}
return TCL_ERROR;
}
*attributePtrPtr = Tcl_ObjPrintf(
"%0#5o", ((int)statBuf.st_mode & 0x7FFF));
return TCL_OK;
|
| ︙ | ︙ | |||
1497 1498 1499 1500 1501 1502 1503 |
}
native = Tcl_DStringValue(&ds);
groupPtr = TclpGetGrNam(native); /* INTL: Native. */
Tcl_DStringFree(&ds);
if (groupPtr == NULL) {
if (interp != NULL) {
| | | | < | | | 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 |
}
native = Tcl_DStringValue(&ds);
groupPtr = TclpGetGrNam(native); /* INTL: Native. */
Tcl_DStringFree(&ds);
if (groupPtr == NULL) {
if (interp != NULL) {
TclPrintfResult(interp,
"could not set group for file \"%s\":"
" group \"%s\" does not exist",
TclGetString(fileName), string);
TclSetErrorCode(interp, "TCL", "OPERATION", "SETGRP", "NO_GROUP");
}
return TCL_ERROR;
}
gid = groupPtr->gr_gid;
}
native = (const char *)Tcl_FSGetNativePath(fileName);
result = chown(native, (uid_t) -1, (gid_t) gid); /* INTL: Native. */
if (result != 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"could not set group for file \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
1568 1569 1570 1571 1572 1573 1574 |
}
native = Tcl_DStringValue(&ds);
pwPtr = TclpGetPwNam(native); /* INTL: Native. */
Tcl_DStringFree(&ds);
if (pwPtr == NULL) {
if (interp != NULL) {
| | | | < | | | 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 |
}
native = Tcl_DStringValue(&ds);
pwPtr = TclpGetPwNam(native); /* INTL: Native. */
Tcl_DStringFree(&ds);
if (pwPtr == NULL) {
if (interp != NULL) {
TclPrintfResult(interp,
"could not set owner for file \"%s\":"
" user \"%s\" does not exist",
TclGetString(fileName), string);
TclSetErrorCode(interp, "TCL", "OPERATION", "SETOWN", "NO_USER");
}
return TCL_ERROR;
}
uid = pwPtr->pw_uid;
}
native = (const char *)Tcl_FSGetNativePath(fileName);
result = chown(native, (uid_t) uid, (gid_t) -1); /* INTL: Native. */
if (result != 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"could not set owner for file \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
1635 1636 1637 1638 1639 1640 1641 |
if ((modeStringPtr[scanned] == '0')
&& (modeStringPtr[scanned+1] >= '0')
&& (modeStringPtr[scanned+1] <= '7')) {
/* Leading zero - attempt octal interpretation */
Tcl_Obj *modeObj;
TclNewLiteralStringObj(modeObj, "0o");
| | | | | | | | | | 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 1687 1688 1689 1690 1691 1692 |
if ((modeStringPtr[scanned] == '0')
&& (modeStringPtr[scanned+1] >= '0')
&& (modeStringPtr[scanned+1] <= '7')) {
/* Leading zero - attempt octal interpretation */
Tcl_Obj *modeObj;
TclNewLiteralStringObj(modeObj, "0o");
Tcl_AppendToObj(modeObj, modeStringPtr+scanned+1, TCL_AUTO_LENGTH);
result = TclGetWideIntFromObj(NULL, modeObj, &mode);
Tcl_DecrRefCount(modeObj);
}
if (result == TCL_OK
|| TclGetWideIntFromObj(NULL, attributePtr, &mode) == TCL_OK) {
newMode = (mode_t) (mode & 0x00007FFF);
} else {
Tcl_StatBuf buf;
/*
* Try the forms "rwxrwxrwx" and "ugo=rwx"
*
* We get the current mode of the file, in order to allow for ug+-=rwx
* style chmod strings.
*/
result = TclpObjStat(fileName, &buf);
if (result != 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"could not read \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
}
return TCL_ERROR;
}
newMode = (mode_t) (buf.st_mode & 0x00007FFF);
if (GetModeFromPermString(NULL, modeStringPtr, &newMode) != TCL_OK) {
if (interp != NULL) {
TclPrintfResult(interp,
"unknown permission string format \"%s\"",
modeStringPtr);
TclSetErrorCode(interp, "TCL", "VALUE", "PERMISSION");
}
return TCL_ERROR;
}
}
native = (const char *)Tcl_FSGetNativePath(fileName);
result = chmod(native, newMode); /* INTL: Native. */
if (result != 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"could not set permissions for file \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
}
return TCL_ERROR;
}
return TCL_OK;
}
#ifndef DJGPP
|
| ︙ | ︙ | |||
2375 2376 2377 2378 2379 2380 2381 |
static void
StatError(
Tcl_Interp *interp, /* The interp that has the error */
Tcl_Obj *fileName) /* The name of the file which caused the
* error. */
{
Tcl_WinConvertError(GetLastError());
| | | | 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 |
static void
StatError(
Tcl_Interp *interp, /* The interp that has the error */
Tcl_Obj *fileName) /* The name of the file which caused the
* error. */
{
Tcl_WinConvertError(GetLastError());
TclPrintfResult(interp, "could not read \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
}
static WCHAR *
winPathFromObj(
Tcl_Obj *fileName)
{
size_t size;
|
| ︙ | ︙ | |||
2528 2529 2530 2531 2532 2533 2534 |
Tcl_StatBuf statBuf;
int result;
result = TclpObjStat(fileName, &statBuf);
if (result != 0) {
if (interp != NULL) {
| | | | 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 |
Tcl_StatBuf statBuf;
int result;
result = TclpObjStat(fileName, &statBuf);
if (result != 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"could not read \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
}
return TCL_ERROR;
}
TclNewIntObj(*attributePtrPtr, (statBuf.st_flags & UF_IMMUTABLE) != 0);
return TCL_OK;
}
|
| ︙ | ︙ | |||
2574 2575 2576 2577 2578 2579 2580 |
return TCL_ERROR;
}
result = TclpObjStat(fileName, &statBuf);
if (result != 0) {
if (interp != NULL) {
| | | | | | 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 |
return TCL_ERROR;
}
result = TclpObjStat(fileName, &statBuf);
if (result != 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"could not read \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
}
return TCL_ERROR;
}
if (readonly) {
statBuf.st_flags |= UF_IMMUTABLE;
} else {
statBuf.st_flags &= ~UF_IMMUTABLE;
}
native = (const char *)Tcl_FSGetNativePath(fileName);
result = chflags(native, statBuf.st_flags); /* INTL: Native. */
if (result != 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"could not set flags for file \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
}
return TCL_ERROR;
}
return TCL_OK;
}
#endif /* defined(HAVE_CHFLAGS) && defined(UF_IMMUTABLE) */
|
| ︙ | ︙ |
Changes to unix/tclUnixFile.c.
| ︙ | ︙ | |||
317 318 319 320 321 322 323 |
return TCL_OK;
}
d = TclOSopendir(native); /* INTL: Native. */
if (d == NULL) {
Tcl_DStringFree(&ds);
if (interp != NULL) {
| | | | 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
return TCL_OK;
}
d = TclOSopendir(native); /* INTL: Native. */
if (d == NULL) {
Tcl_DStringFree(&ds);
if (interp != NULL) {
TclPrintfResult(interp,
"couldn't read directory \"%s\": %s",
Tcl_DStringValue(&dsOrig), Tcl_PosixError(interp));
}
Tcl_DStringFree(&dsOrig);
Tcl_DecrRefCount(fileNamePtr);
return TCL_ERROR;
}
nativeDirLen = Tcl_DStringLength(&ds);
|
| ︙ | ︙ | |||
788 789 790 791 792 793 794 |
#ifdef USEGETWD
if (getwd(buffer) == NULL) /* INTL: Native. */
#else
if (getcwd(buffer, MAXPATHLEN+1) == NULL) /* INTL: Native. */
#endif /* USEGETWD */
{
if (interp != NULL) {
| | | | 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 |
#ifdef USEGETWD
if (getwd(buffer) == NULL) /* INTL: Native. */
#else
if (getcwd(buffer, MAXPATHLEN+1) == NULL) /* INTL: Native. */
#endif /* USEGETWD */
{
if (interp != NULL) {
TclPrintfResult(interp,
"error getting working directory name: %s",
Tcl_PosixError(interp));
}
return NULL;
}
if (Tcl_ExternalToUtfDStringEx(interp, NULL, buffer, TCL_INDEX_NONE, 0, bufferPtr, NULL) != TCL_OK) {
return NULL;
}
return Tcl_DStringValue(bufferPtr);
|
| ︙ | ︙ |
Changes to unix/tclUnixInit.c.
| ︙ | ︙ | |||
825 826 827 828 829 830 831 |
while ((q = strchr(p, ':')) != NULL) {
Tcl_ListObjAppendElement(NULL, pkgListObj, Tcl_NewStringObj(p, q-p));
p = q+1;
}
if (*p) {
Tcl_ListObjAppendElement(NULL, pkgListObj, Tcl_NewStringObj(p, -1));
}
| | | 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 |
while ((q = strchr(p, ':')) != NULL) {
Tcl_ListObjAppendElement(NULL, pkgListObj, Tcl_NewStringObj(p, q-p));
p = q+1;
}
if (*p) {
Tcl_ListObjAppendElement(NULL, pkgListObj, Tcl_NewStringObj(p, -1));
}
Tcl_SetVar2Ex(interp, "tcl_pkgPath", NULL, pkgListObj, TCL_GLOBAL_ONLY);
{
/* Some platforms build configure scripts expect ~ expansion so do that */
Tcl_Obj *origPaths;
Tcl_Obj *resolvedPaths;
origPaths = Tcl_GetVar2Ex(interp, "tcl_pkgPath", NULL, TCL_GLOBAL_ONLY);
resolvedPaths = TclResolveTildePathList(origPaths);
|
| ︙ | ︙ |
Changes to unix/tclUnixPipe.c.
| ︙ | ︙ | |||
290 291 292 293 294 295 296 |
TclpTempFileNameForLibrary(
Tcl_Interp *interp, /* Tcl interpreter. */
TCL_UNUSED(Tcl_Obj *) /*path*/)
{
Tcl_Obj *retval = TclpTempFileName();
if (retval == NULL) {
| | | | 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
TclpTempFileNameForLibrary(
Tcl_Interp *interp, /* Tcl interpreter. */
TCL_UNUSED(Tcl_Obj *) /*path*/)
{
Tcl_Obj *retval = TclpTempFileName();
if (retval == NULL) {
TclPrintfResult(interp,
"couldn't create temporary file: %s",
Tcl_PosixError(interp));
}
return retval;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
443 444 445 446 447 448 449 |
/*
* Create a pipe that the child can use to return error information if
* anything goes wrong.
*/
if (TclpCreatePipe(&errPipeIn, &errPipeOut) == 0) {
| | | | 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
/*
* Create a pipe that the child can use to return error information if
* anything goes wrong.
*/
if (TclpCreatePipe(&errPipeIn, &errPipeOut) == 0) {
TclPrintfResult(interp,
"couldn't create pipe: %s", Tcl_PosixError(interp));
goto error;
}
/*
* We need to allocate and convert this before the fork so it is properly
* deallocated later
*/
|
| ︙ | ︙ | |||
606 607 608 609 610 611 612 |
TclStackFree(interp, newArgv);
TclStackFree(interp, dsArray);
if (pid == -1) {
#ifdef HAVE_POSIX_SPAWNP
errno = childErrno;
#endif
| | | < | | 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
TclStackFree(interp, newArgv);
TclStackFree(interp, dsArray);
if (pid == -1) {
#ifdef HAVE_POSIX_SPAWNP
errno = childErrno;
#endif
TclPrintfResult(interp,
"couldn't fork child process: %s", Tcl_PosixError(interp));
goto error;
}
/*
* Read back from the error pipe to see if the child started up OK. The
* info in the pipe (if any) consists of a decimal errno value followed by
* an error message.
*/
TclpCloseFile(errPipeOut);
errPipeOut = NULL;
fd = GetFd(errPipeIn);
count = read(fd, errSpace, sizeof(errSpace) - 1);
if (count > 0) {
char *end;
errSpace[count] = 0;
errno = strtol(errSpace, &end, 10);
TclPrintfResult(interp, "%s: %s", end, Tcl_PosixError(interp));
goto error;
}
TclpCloseFile(errPipeIn);
*pidPtr = (Tcl_Pid)INT2PTR(pid);
return TCL_OK;
|
| ︙ | ︙ | |||
912 913 914 915 916 917 918 |
Tcl_Channel *rchan, /* Returned read side. */
Tcl_Channel *wchan, /* Returned write side. */
TCL_UNUSED(int) /*flags*/) /* Reserved for future use. */
{
int fileNums[2];
if (pipe(fileNums) < 0) {
| | | | 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 |
Tcl_Channel *rchan, /* Returned read side. */
Tcl_Channel *wchan, /* Returned write side. */
TCL_UNUSED(int) /*flags*/) /* Reserved for future use. */
{
int fileNums[2];
if (pipe(fileNums) < 0) {
TclPrintfResult(interp, "pipe creation failed: %s",
Tcl_PosixError(interp));
return TCL_ERROR;
}
fcntl(fileNums[0], F_SETFD, FD_CLOEXEC);
fcntl(fileNums[1], F_SETFD, FD_CLOEXEC);
*rchan = Tcl_MakeFileChannel(INT2PTR(fileNums[0]), TCL_READABLE);
|
| ︙ | ︙ |
Changes to unix/tclUnixSock.c.
| ︙ | ︙ | |||
824 825 826 827 828 829 830 |
(const char *) &val, sizeof(int));
#else
ret = -1;
Tcl_SetErrno(ENOTSUP);
#endif
if (ret < 0) {
if (interp) {
| | | | 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 |
(const char *) &val, sizeof(int));
#else
ret = -1;
Tcl_SetErrno(ENOTSUP);
#endif
if (ret < 0) {
if (interp) {
TclPrintfResult(interp,
"couldn't set socket option: %s",
Tcl_PosixError(interp));
}
return TCL_ERROR;
}
return TCL_OK;
}
if ((len > 1) && (optionName[1] == 'n') &&
(strncmp(optionName, "-nodelay", len) == 0)) {
|
| ︙ | ︙ | |||
848 849 850 851 852 853 854 |
(const char *) &val, sizeof(int));
#else
ret = -1;
Tcl_SetErrno(ENOTSUP);
#endif
if (ret < 0) {
if (interp) {
| | | | 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 |
(const char *) &val, sizeof(int));
#else
ret = -1;
Tcl_SetErrno(ENOTSUP);
#endif
if (ret < 0) {
if (interp) {
TclPrintfResult(interp,
"couldn't set socket option: %s",
Tcl_PosixError(interp));
}
return TCL_ERROR;
}
return TCL_OK;
}
return Tcl_BadChannelOption(interp, optionName, "keepalive nodelay");
}
|
| ︙ | ︙ | |||
973 974 975 976 977 978 979 |
* (len==0), don't flag an error at that point because it could be
* an fconfigure request on a server socket (which have no peer).
* Same must be done on win&mac.
*/
if (len) {
if (interp) {
| | | < | 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 |
* (len==0), don't flag an error at that point because it could be
* an fconfigure request on a server socket (which have no peer).
* Same must be done on win&mac.
*/
if (len) {
if (interp) {
TclPrintfResult(interp,
"can't get peername: %s", Tcl_PosixError(interp));
}
return TCL_ERROR;
}
}
}
if ((len == 0) || ((len > 1) && (optionName[1] == 's') &&
|
| ︙ | ︙ | |||
1016 1017 1018 1019 1020 1021 1022 |
if (found) {
if (len) {
return TCL_OK;
}
Tcl_DStringEndSublist(dsPtr);
} else {
if (interp) {
| | | | 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 |
if (found) {
if (len) {
return TCL_OK;
}
Tcl_DStringEndSublist(dsPtr);
} else {
if (interp) {
TclPrintfResult(interp,
"can't get sockname: %s", Tcl_PosixError(interp));
}
return TCL_ERROR;
}
}
if ((len == 0) || ((len > 1) && (optionName[1] == 'k') &&
(strncmp(optionName, "-keepalive", len) == 0))) {
|
| ︙ | ︙ | |||
1460 1461 1462 1463 1464 1465 1466 |
* Failure for either a synchronous connection, or an async one that
* failed before it could enter background mode, e.g. because an
* invalid -myaddr was given.
*/
if (interp != NULL) {
errno = error;
| | | | 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 |
* Failure for either a synchronous connection, or an async one that
* failed before it could enter background mode, e.g. because an
* invalid -myaddr was given.
*/
if (interp != NULL) {
errno = error;
TclPrintfResult(interp,
"couldn't open socket: %s", Tcl_PosixError(interp));
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
1512 1513 1514 1515 1516 1517 1518 |
if (!TclCreateSocketAddress(interp, &addrlist, host, port, 0, &errorMsg)
|| !TclCreateSocketAddress(interp, &myaddrlist, myaddr, myport, 1,
&errorMsg)) {
if (addrlist != NULL) {
freeaddrinfo(addrlist);
}
if (interp != NULL) {
| < | | 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 |
if (!TclCreateSocketAddress(interp, &addrlist, host, port, 0, &errorMsg)
|| !TclCreateSocketAddress(interp, &myaddrlist, myaddr, myport, 1,
&errorMsg)) {
if (addrlist != NULL) {
freeaddrinfo(addrlist);
}
if (interp != NULL) {
TclPrintfResult(interp, "couldn't open socket: %s", errorMsg);
}
return NULL;
}
/*
* Allocate a new TcpState for this socket.
*/
|
| ︙ | ︙ | |||
1861 1862 1863 1864 1865 1866 1867 |
}
if (statePtr != NULL) {
statePtr->channel = Tcl_CreateChannel(&tcpChannelType, channelName,
statePtr, 0);
return statePtr->channel;
}
if (interp != NULL) {
| | < | < < < < < < | 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 |
}
if (statePtr != NULL) {
statePtr->channel = Tcl_CreateChannel(&tcpChannelType, channelName,
statePtr, 0);
return statePtr->channel;
}
if (interp != NULL) {
TclPrintfResult(interp, "couldn't open socket: %s",
(errorMsg == NULL ? Tcl_PosixError(interp) : errorMsg));
}
if (sock != -1) {
close(sock);
}
return NULL;
}
|
| ︙ | ︙ |
Changes to win/Makefile.in.
| ︙ | ︙ | |||
583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
@POST_MAKE_LIB@
${TCL_DLL_FILE}: ${TCL_LIB_FILE} ${TCL_OBJS} tcl.$(RES) @ZLIB_DLL_FILE@ @TOMMATH_DLL_FILE@ ${TCL_ZIP_FILE}
@$(RM) ${TCL_DLL_FILE} $(TCL_LIB_FILE)
@MAKE_DLL@ ${TCL_OBJS} tcl.$(RES) $(SHLIB_LD_LIBS)
$(COPY) tclsh.exe.manifest ${TCL_DLL_FILE}.manifest
@VC_MANIFEST_EMBED_DLL@
@if test "${ZIPFS_BUILD}" = "1" ; then \
cat ${TCL_ZIP_FILE} >> ${TCL_DLL_FILE}; \
fi
ifeq (,$(findstring --disable-shared,$(PKG_CFG_ARGS)))
${TCL_LIB_FILE}:
@$(RM) ${TCL_DLL_FILE} $(TCL_LIB_FILE)
| > | 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 |
@POST_MAKE_LIB@
${TCL_DLL_FILE}: ${TCL_LIB_FILE} ${TCL_OBJS} tcl.$(RES) @ZLIB_DLL_FILE@ @TOMMATH_DLL_FILE@ ${TCL_ZIP_FILE}
@$(RM) ${TCL_DLL_FILE} $(TCL_LIB_FILE)
@MAKE_DLL@ ${TCL_OBJS} tcl.$(RES) $(SHLIB_LD_LIBS)
$(COPY) tclsh.exe.manifest ${TCL_DLL_FILE}.manifest
@VC_MANIFEST_EMBED_DLL@
@-sleep 2
@if test "${ZIPFS_BUILD}" = "1" ; then \
cat ${TCL_ZIP_FILE} >> ${TCL_DLL_FILE}; \
fi
ifeq (,$(findstring --disable-shared,$(PKG_CFG_ARGS)))
${TCL_LIB_FILE}:
@$(RM) ${TCL_DLL_FILE} $(TCL_LIB_FILE)
|
| ︙ | ︙ |
Changes to win/tclWinChan.c.
| ︙ | ︙ | |||
891 892 893 894 895 896 897 |
STORE_ELEM("mode", Tcl_NewWideIntObj(mode));
/*
* Windows only has files and directories, as far as we're concerned.
* Anything else and we definitely couldn't have got here anyway.
*/
if (attr & FILE_ATTRIBUTE_DIRECTORY) {
| | | | 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 |
STORE_ELEM("mode", Tcl_NewWideIntObj(mode));
/*
* Windows only has files and directories, as far as we're concerned.
* Anything else and we definitely couldn't have got here anyway.
*/
if (attr & FILE_ATTRIBUTE_DIRECTORY) {
STORE_ELEM("type", TclNewString("directory"));
} else {
STORE_ELEM("type", TclNewString("file"));
}
#undef STORE_ELEM
return dictObj;
}
static int
|
| ︙ | ︙ | |||
930 931 932 933 934 935 936 |
if ((len > 1) && (strncmp(optionName, "-stat", len) == 0)) {
Tcl_Obj *dictObj = StatOpenFile(infoPtr);
const char *dictContents;
Tcl_Size dictLength;
if (dictObj == NULL) {
| | | | 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 |
if ((len > 1) && (strncmp(optionName, "-stat", len) == 0)) {
Tcl_Obj *dictObj = StatOpenFile(infoPtr);
const char *dictContents;
Tcl_Size dictLength;
if (dictObj == NULL) {
TclPrintfResult(interp,
"couldn't read file channel status: %s",
Tcl_PosixError(interp));
return TCL_ERROR;
}
/*
* Transfer dictionary to the DString. Note that we don't do this as
* an element as this is an option that can't be retrieved with a
* general probe.
|
| ︙ | ︙ | |||
1000 1001 1002 1003 1004 1005 1006 | /* * We need this just to ensure we return the correct error messages under * some circumstances (relative paths only), so because the normalization * is very expensive, don't invoke it for native or absolute paths. * Note: since paths starting with ~ are relative in 9.0 for windows, * it doesn't need to consider tilde expansion (in opposite to 8.x). */ | < < | | < | < | | | 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 |
/*
* We need this just to ensure we return the correct error messages under
* some circumstances (relative paths only), so because the normalization
* is very expensive, don't invoke it for native or absolute paths.
* Note: since paths starting with ~ are relative in 9.0 for windows,
* it doesn't need to consider tilde expansion (in opposite to 8.x).
*/
if (!TclFSCwdIsNative()
&& Tcl_FSGetPathType(pathPtr) != TCL_PATH_ABSOLUTE
&& Tcl_FSGetNormalizedPath(interp, pathPtr) == NULL) {
return NULL;
}
TclPrintfResult(interp,
"couldn't open \"%s\": filename is invalid on this platform",
TclGetString(pathPtr));
}
return NULL;
}
switch (mode & O_ACCMODE) {
case O_RDONLY:
accessMode = GENERIC_READ;
|
| ︙ | ︙ | |||
1070 1071 1072 1073 1074 1075 1076 |
*/
if (NativeIsComPort(nativeName)) {
handle = TclWinSerialOpen(INVALID_HANDLE_VALUE, nativeName, accessMode);
if (handle == INVALID_HANDLE_VALUE) {
Tcl_WinConvertError(GetLastError());
if (interp) {
| | | | 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 |
*/
if (NativeIsComPort(nativeName)) {
handle = TclWinSerialOpen(INVALID_HANDLE_VALUE, nativeName, accessMode);
if (handle == INVALID_HANDLE_VALUE) {
Tcl_WinConvertError(GetLastError());
if (interp) {
TclPrintfResult(interp,
"couldn't open serial \"%s\": %s",
TclGetString(pathPtr), Tcl_PosixError(interp));
}
return NULL;
}
/*
* For natively-named Windows serial ports we are done.
*/
|
| ︙ | ︙ | |||
1127 1128 1129 1130 1131 1132 1133 |
if ((err & 0xFFFFL) == ERROR_OPEN_FAILED) {
err = TEST_FLAG(mode, O_CREAT) ? ERROR_FILE_EXISTS
: ERROR_FILE_NOT_FOUND;
}
Tcl_WinConvertError(err);
if (interp) {
| | | | 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 |
if ((err & 0xFFFFL) == ERROR_OPEN_FAILED) {
err = TEST_FLAG(mode, O_CREAT) ? ERROR_FILE_EXISTS
: ERROR_FILE_NOT_FOUND;
}
Tcl_WinConvertError(err);
if (interp) {
TclPrintfResult(interp,
"couldn't open \"%s\": %s",
TclGetString(pathPtr), Tcl_PosixError(interp));
}
return NULL;
}
channel = NULL;
switch (FileGetType(handle)) {
|
| ︙ | ︙ | |||
1151 1152 1153 1154 1155 1156 1157 |
* fail, because the channel exists.
*/
handle = TclWinSerialOpen(handle, nativeName, accessMode);
if (handle == INVALID_HANDLE_VALUE) {
Tcl_WinConvertError(GetLastError());
if (interp) {
| | | | 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 |
* fail, because the channel exists.
*/
handle = TclWinSerialOpen(handle, nativeName, accessMode);
if (handle == INVALID_HANDLE_VALUE) {
Tcl_WinConvertError(GetLastError());
if (interp) {
TclPrintfResult(interp,
"couldn't reopen serial \"%s\": %s",
TclGetString(pathPtr), Tcl_PosixError(interp));
}
return NULL;
}
channel = TclWinOpenSerialChannel(handle, channelName,
channelPermissions);
break;
case FILE_TYPE_CONSOLE:
|
| ︙ | ︙ | |||
1188 1189 1190 1191 1192 1193 1194 |
default:
/*
* The handle is of an unknown type, probably /dev/nul equivalent or
* possibly a closed handle.
*/
channel = NULL;
| | | < | < | 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 |
default:
/*
* The handle is of an unknown type, probably /dev/nul equivalent or
* possibly a closed handle.
*/
channel = NULL;
TclPrintfResult(interp,
"couldn't open \"%s\": bad file type", TclGetString(pathPtr));
TclSetErrorCode(interp, "TCL", "VALUE", "CHANNEL", "BAD_TYPE");
break;
}
return channel;
}
/*
|
| ︙ | ︙ |
Changes to win/tclWinConsole.c.
| ︙ | ︙ | |||
2274 2275 2276 2277 2278 2279 2280 |
if ((chanInfoPtr->flags & CONSOLE_READ_OPS) && (len > 1) &&
(strncmp(optionName, "-inputmode", len) == 0)) {
DWORD mode;
if (GetConsoleMode(chanInfoPtr->handle, &mode) == 0) {
Tcl_WinConvertError(GetLastError());
if (interp != NULL) {
| | | | | | | | | | 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 |
if ((chanInfoPtr->flags & CONSOLE_READ_OPS) && (len > 1) &&
(strncmp(optionName, "-inputmode", len) == 0)) {
DWORD mode;
if (GetConsoleMode(chanInfoPtr->handle, &mode) == 0) {
Tcl_WinConvertError(GetLastError());
if (interp != NULL) {
TclPrintfResult(interp,
"couldn't read console mode: %s",
Tcl_PosixError(interp));
}
return TCL_ERROR;
}
if (strncasecmp(value, "NORMAL", vlen) == 0) {
mode |=
ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
} else if (strncasecmp(value, "PASSWORD", vlen) == 0) {
mode |= ENABLE_LINE_INPUT|ENABLE_PROCESSED_INPUT;
mode &= ~ENABLE_ECHO_INPUT;
} else if (strncasecmp(value, "RAW", vlen) == 0) {
mode &= ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
} else if (strncasecmp(value, "RESET", vlen) == 0) {
/*
* Reset to the initial mode, whatever that is.
*/
mode = chanInfoPtr->initMode;
} else {
if (interp) {
TclPrintfResult(interp,
"bad mode \"%s\" for -inputmode: must be"
" normal, password, raw, or reset", value);
TclSetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE",
"VALUE");
}
return TCL_ERROR;
}
if (SetConsoleMode(chanInfoPtr->handle, mode) == 0) {
Tcl_WinConvertError(GetLastError());
if (interp != NULL) {
TclPrintfResult(interp,
"couldn't set console mode: %s",
Tcl_PosixError(interp));
}
return TCL_ERROR;
}
return TCL_OK;
}
|
| ︙ | ︙ | |||
2377 2378 2379 2380 2381 2382 2383 |
if (len==0 || (len>1 && strncmp(optionName, "-inputmode", len)==0)) {
DWORD mode;
valid = 1;
if (GetConsoleMode(chanInfoPtr->handle, &mode) == 0) {
Tcl_WinConvertError(GetLastError());
if (interp != NULL) {
| | | | 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 |
if (len==0 || (len>1 && strncmp(optionName, "-inputmode", len)==0)) {
DWORD mode;
valid = 1;
if (GetConsoleMode(chanInfoPtr->handle, &mode) == 0) {
Tcl_WinConvertError(GetLastError());
if (interp != NULL) {
TclPrintfResult(interp,
"couldn't read console mode: %s",
Tcl_PosixError(interp));
}
return TCL_ERROR;
}
if (mode & ENABLE_LINE_INPUT) {
if (mode & ENABLE_ECHO_INPUT) {
Tcl_DStringAppendElement(dsPtr, "normal");
} else {
|
| ︙ | ︙ | |||
2411 2412 2413 2414 2415 2416 2417 |
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
valid = 1;
if (!GetConsoleScreenBufferInfo(chanInfoPtr->handle,
&consoleInfo)) {
Tcl_WinConvertError(GetLastError());
if (interp != NULL) {
| | | | 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 |
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
valid = 1;
if (!GetConsoleScreenBufferInfo(chanInfoPtr->handle,
&consoleInfo)) {
Tcl_WinConvertError(GetLastError());
if (interp != NULL) {
TclPrintfResult(interp,
"couldn't read console size: %s",
Tcl_PosixError(interp));
}
return TCL_ERROR;
}
Tcl_DStringStartSublist(dsPtr);
snprintf(buf, sizeof(buf), "%d",
consoleInfo.srWindow.Right - consoleInfo.srWindow.Left + 1);
Tcl_DStringAppendElement(dsPtr, buf);
|
| ︙ | ︙ |
Changes to win/tclWinDde.c.
| ︙ | ︙ | |||
377 378 379 380 381 382 383 |
}
if (r == TCL_OK) {
r = Tcl_ListObjGetElements(interp, srvListPtr, &srvCount,
&srvPtrPtr);
}
if (r != TCL_OK) {
Tcl_DStringInit(&dString);
| | | 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
}
if (r == TCL_OK) {
r = Tcl_ListObjGetElements(interp, srvListPtr, &srvCount,
&srvPtrPtr);
}
if (r != TCL_OK) {
Tcl_DStringInit(&dString);
OutputDebugStringW(Tcl_UtfToWCharDString(Tcl_GetStringResult(interp), -1, &dString));
Tcl_DStringFree(&dString);
return NULL;
}
/*
* Pick a name to use for the application. Use "name" if it's not
* already in use. Otherwise add a suffix such as " #2", trying larger
|
| ︙ | ︙ |
Changes to win/tclWinFCmd.c.
| ︙ | ︙ | |||
1476 1477 1478 1479 1480 1481 1482 |
static void
StatError(
Tcl_Interp *interp, /* The interp that has the error */
Tcl_Obj *fileName) /* The name of the file which caused the
* error. */
{
Tcl_WinConvertError(GetLastError());
| | | | 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 |
static void
StatError(
Tcl_Interp *interp, /* The interp that has the error */
Tcl_Obj *fileName) /* The name of the file which caused the
* error. */
{
Tcl_WinConvertError(GetLastError());
TclPrintfResult(interp, "could not read \"%s\": %s",
TclGetString(fileName), Tcl_PosixError(interp));
}
/*
*----------------------------------------------------------------------
*
* GetWinFileAttributes --
*
|
| ︙ | ︙ | |||
1595 1596 1597 1598 1599 1600 1601 |
Tcl_Size pathc, i, length;
Tcl_Obj *splitPath;
splitPath = Tcl_FSSplitPath(fileName, &pathc);
if (splitPath == NULL || pathc == 0) {
if (interp != NULL) {
| | | | 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 |
Tcl_Size pathc, i, length;
Tcl_Obj *splitPath;
splitPath = Tcl_FSSplitPath(fileName, &pathc);
if (splitPath == NULL || pathc == 0) {
if (interp != NULL) {
TclPrintfResult(interp,
"could not read \"%s\": no such file or directory",
TclGetString(fileName));
errno = ENOENT;
Tcl_PosixError(interp);
}
goto cleanup;
}
/*
|
| ︙ | ︙ | |||
1875 1876 1877 1878 1879 1880 1881 |
static int
CannotSetAttribute(
Tcl_Interp *interp, /* The interp we are using for errors. */
int objIndex, /* The index of the attribute. */
Tcl_Obj *fileName, /* The name of the file. */
TCL_UNUSED(Tcl_Obj *) /*attributePtr*/)
{
| | | | 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 |
static int
CannotSetAttribute(
Tcl_Interp *interp, /* The interp we are using for errors. */
int objIndex, /* The index of the attribute. */
Tcl_Obj *fileName, /* The name of the file. */
TCL_UNUSED(Tcl_Obj *) /*attributePtr*/)
{
TclPrintfResult(interp,
"cannot set attribute \"%s\" for file \"%s\": attribute is readonly",
tclpFileAttrStrings[objIndex], TclGetString(fileName));
errno = EINVAL;
Tcl_PosixError(interp);
return TCL_ERROR;
}
/*
*---------------------------------------------------------------------------
|
| ︙ | ︙ |
Changes to win/tclWinFile.c.
| ︙ | ︙ | |||
1034 1035 1036 1037 1038 1039 1040 |
Tcl_DStringFree(&dsOrig);
return TCL_OK;
}
Tcl_WinConvertError(err);
if (interp != NULL) {
| | | | 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 |
Tcl_DStringFree(&dsOrig);
return TCL_OK;
}
Tcl_WinConvertError(err);
if (interp != NULL) {
TclPrintfResult(interp,
"couldn't read directory \"%s\": %s",
Tcl_DStringValue(&dsOrig), Tcl_PosixError(interp));
}
Tcl_DStringFree(&dsOrig);
return TCL_ERROR;
}
Tcl_DStringFree(&ds);
/*
|
| ︙ | ︙ | |||
1515 1516 1517 1518 1519 1520 1521 |
/*
* User exists but has no home dir. Return
* "{GetProfilesDirectory}/<user>".
*/
GetProfilesDirectoryW(buf, &size);
Tcl_WCharToUtfDString(buf, size-1, bufferPtr);
| | | 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 |
/*
* User exists but has no home dir. Return
* "{GetProfilesDirectory}/<user>".
*/
GetProfilesDirectoryW(buf, &size);
Tcl_WCharToUtfDString(buf, size-1, bufferPtr);
TclDStringAppendLiteral(bufferPtr, "/");
Tcl_DStringAppend(bufferPtr, name, nameLen);
}
result = Tcl_DStringValue(bufferPtr);
/*
* Be sure we return normalized path
*/
|
| ︙ | ︙ | |||
1941 1942 1943 1944 1945 1946 1947 |
WCHAR buffer[MAX_PATH];
char *p;
WCHAR *native;
if (GetCurrentDirectoryW(MAX_PATH, buffer) == 0) {
Tcl_WinConvertError(GetLastError());
if (interp != NULL) {
| | | | 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 |
WCHAR buffer[MAX_PATH];
char *p;
WCHAR *native;
if (GetCurrentDirectoryW(MAX_PATH, buffer) == 0) {
Tcl_WinConvertError(GetLastError());
if (interp != NULL) {
TclPrintfResult(interp,
"error getting working directory name: %s",
Tcl_PosixError(interp));
}
return NULL;
}
/*
* Watch for the weird Windows c:\\UNC syntax.
*/
|
| ︙ | ︙ | |||
2618 2619 2620 2621 2622 2623 2624 | * Tcl_GetStringFromObj(to, &pathLen); * nextCheckpoint = pathLen; * * So, instead we have to start from the beginning. */ nextCheckpoint = 0; | | | 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 |
* Tcl_GetStringFromObj(to, &pathLen);
* nextCheckpoint = pathLen;
*
* So, instead we have to start from the beginning.
*/
nextCheckpoint = 0;
Tcl_AppendToObj(to, currentPathEndPosition, TCL_AUTO_LENGTH);
/*
* Convert link to forward slashes.
*/
for (path = TclGetString(to); *path != 0; path++) {
if (*path == '\\') {
|
| ︙ | ︙ | |||
2792 2793 2794 2795 2796 2797 2798 | */ Tcl_Obj *tmpPathPtr; Tcl_Size len; tmpPathPtr = Tcl_NewStringObj(Tcl_DStringValue(&ds), nextCheckpoint); | | | 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 |
*/
Tcl_Obj *tmpPathPtr;
Tcl_Size len;
tmpPathPtr = Tcl_NewStringObj(Tcl_DStringValue(&ds),
nextCheckpoint);
Tcl_AppendToObj(tmpPathPtr, lastValidPathEnd, TCL_AUTO_LENGTH);
path = TclGetStringFromObj(tmpPathPtr, &len);
Tcl_SetStringObj(pathPtr, path, len);
Tcl_DecrRefCount(tmpPathPtr);
} else {
/*
* End of string was reached above.
*/
|
| ︙ | ︙ | |||
2865 2866 2867 2868 2869 2870 2871 | * Path of form /foo/bar which is a path in the root directory of the * current volume. */ const char *drive = TclGetString(useThisCwd); absolutePath = Tcl_NewStringObj(drive,2); | | | 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 |
* Path of form /foo/bar which is a path in the root directory of the
* current volume.
*/
const char *drive = TclGetString(useThisCwd);
absolutePath = Tcl_NewStringObj(drive,2);
Tcl_AppendToObj(absolutePath, path, TCL_AUTO_LENGTH);
Tcl_IncrRefCount(absolutePath);
/*
* We have a refCount on the cwd.
*/
} else {
/*
|
| ︙ | ︙ | |||
2898 2899 2900 2901 2902 2903 2904 |
if (drive[cwdLen-1] != '/' && (path[2] != '\0')) {
/*
* Only add a trailing '/' if needed, which is if there isn't
* one already, and if we are going to be adding some more
* characters.
*/
| | | | | 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 |
if (drive[cwdLen-1] != '/' && (path[2] != '\0')) {
/*
* Only add a trailing '/' if needed, which is if there isn't
* one already, and if we are going to be adding some more
* characters.
*/
TclAppendLiteralToObj(absolutePath, "/");
}
} else {
Tcl_DecrRefCount(useThisCwd);
useThisCwd = NULL;
/*
* The path is not in the current drive, but is volume-relative.
* The way Tcl 8.3 handles this is that it treats such a path as
* relative to the root of the drive. We therefore behave the same
* here. This behaviour is, however, different to that of the
* windows command-line. If we want to fix this at some point in
* the future (at the expense of a behaviour change to Tcl), we
* could use the '_dgetdcwd' Win32 API to get the drive's cwd.
*/
absolutePath = Tcl_NewStringObj(path, 2);
TclAppendLiteralToObj(absolutePath, "/");
}
Tcl_IncrRefCount(absolutePath);
Tcl_AppendToObj(absolutePath, path + 2, TCL_AUTO_LENGTH);
}
*useThisCwdPtr = useThisCwd;
return absolutePath;
}
/*
*---------------------------------------------------------------------------
|
| ︙ | ︙ |
Changes to win/tclWinInit.c.
| ︙ | ︙ | |||
401 402 403 404 405 406 407 |
Tcl_GetEncodingNameFromEnvironment(
Tcl_DString *bufPtr)
{
UINT acp = GetACP();
Tcl_DStringInit(bufPtr);
if (acp == CP_UTF8) {
| | | 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
Tcl_GetEncodingNameFromEnvironment(
Tcl_DString *bufPtr)
{
UINT acp = GetACP();
Tcl_DStringInit(bufPtr);
if (acp == CP_UTF8) {
TclDStringAppendLiteral(bufPtr, "utf-8");
} else {
Tcl_DStringSetLength(bufPtr, 2 + TCL_INTEGER_SPACE);
snprintf(Tcl_DStringValue(bufPtr), 2 + TCL_INTEGER_SPACE, "cp%d",
GetACP());
Tcl_DStringSetLength(bufPtr, strlen(Tcl_DStringValue(bufPtr)));
}
return Tcl_DStringValue(bufPtr);
|
| ︙ | ︙ |
Changes to win/tclWinLoad.c.
| ︙ | ︙ | |||
129 130 131 132 133 134 135 |
* about any problem, but it's better than nothing. It'd be even
* better if there was a way to get what DLLs
*/
if (interp) {
switch (lastError) {
case ERROR_MOD_NOT_FOUND:
| | | > | | | > | | | | > | < | | | | > | | | 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 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 |
* about any problem, but it's better than nothing. It'd be even
* better if there was a way to get what DLLs
*/
if (interp) {
switch (lastError) {
case ERROR_MOD_NOT_FOUND:
TclSetErrorCode(interp, "WIN_LOAD", "MOD_NOT_FOUND");
goto notFoundMsg;
case ERROR_DLL_NOT_FOUND:
TclSetErrorCode(interp, "WIN_LOAD", "DLL_NOT_FOUND");
notFoundMsg:
TclAppendLiteralToObj(errMsg,
"this library or a dependent library could not be "
"found in library path");
break;
case ERROR_PROC_NOT_FOUND:
TclSetErrorCode(interp, "WIN_LOAD", "PROC_NOT_FOUND");
TclAppendLiteralToObj(errMsg,
"A function specified in the import table could "
"not be resolved by the system. Windows is not "
"telling which one, I'm sorry.");
break;
case ERROR_INVALID_DLL:
TclSetErrorCode(interp, "WIN_LOAD", "INVALID_DLL");
TclAppendLiteralToObj(errMsg,
"this library or a dependent library is damaged");
break;
case ERROR_DLL_INIT_FAILED:
TclSetErrorCode(interp, "WIN_LOAD", "DLL_INIT_FAILED");
TclAppendLiteralToObj(errMsg,
"the library initialization routine failed");
break;
case ERROR_BAD_EXE_FORMAT:
TclSetErrorCode(interp, "WIN_LOAD", "BAD_EXE_FORMAT");
TclAppendLiteralToObj(errMsg,
"Bad exe format. Possibly a 32/64-bit mismatch.");
break;
default:
Tcl_WinConvertError(lastError);
Tcl_AppendToObj(errMsg, Tcl_PosixError(interp), TCL_AUTO_LENGTH);
}
Tcl_SetObjResult(interp, errMsg);
}
return TCL_ERROR;
}
/*
|
| ︙ | ︙ | |||
221 222 223 224 225 226 227 |
Tcl_DStringInit(&ds);
TclDStringAppendLiteral(&ds, "_");
sym2 = Tcl_DStringAppend(&ds, symbol, TCL_INDEX_NONE);
proc = (void *)GetProcAddress(hInstance, sym2);
Tcl_DStringFree(&ds);
}
if (proc == NULL && interp != NULL) {
| < | | | 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
Tcl_DStringInit(&ds);
TclDStringAppendLiteral(&ds, "_");
sym2 = Tcl_DStringAppend(&ds, symbol, TCL_INDEX_NONE);
proc = (void *)GetProcAddress(hInstance, sym2);
Tcl_DStringFree(&ds);
}
if (proc == NULL && interp != NULL) {
TclPrintfResult(interp, "cannot find symbol \"%s\"", symbol);
TclSetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol);
}
return proc;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
288 289 290 291 292 293 294 |
{
Tcl_Obj *fileName; /* Name of the temp file. */
Tcl_Obj *tail; /* Tail of the source path. */
Tcl_MutexLock(&dllDirectoryNameMutex);
if (dllDirectoryName == NULL) {
if (InitDLLDirectoryName() == TCL_ERROR) {
| | | | | 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
{
Tcl_Obj *fileName; /* Name of the temp file. */
Tcl_Obj *tail; /* Tail of the source path. */
Tcl_MutexLock(&dllDirectoryNameMutex);
if (dllDirectoryName == NULL) {
if (InitDLLDirectoryName() == TCL_ERROR) {
TclPrintfResult(interp,
"couldn't create temporary directory: %s",
Tcl_PosixError(interp));
Tcl_MutexUnlock(&dllDirectoryNameMutex);
return NULL;
}
}
Tcl_MutexUnlock(&dllDirectoryNameMutex);
/*
* Now we know where to put temporary DLLs, construct the name.
*/
fileName = TclpNativeToNormalized(dllDirectoryName);
tail = TclPathPart(interp, path, TCL_PATH_TAIL);
if (tail == NULL) {
Tcl_DecrRefCount(fileName);
return NULL;
}
TclAppendLiteralToObj(fileName, "/");
Tcl_AppendObjToObj(fileName, tail);
return fileName;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ |
Changes to win/tclWinPipe.c.
| ︙ | ︙ | |||
1028 1029 1030 1031 1032 1033 1034 |
}
} else {
DuplicateHandle(hProcess, inputHandle, hProcess, &startInfo.hStdInput,
0, TRUE, DUPLICATE_SAME_ACCESS);
}
if (startInfo.hStdInput == INVALID_HANDLE_VALUE) {
Tcl_WinConvertError(GetLastError());
| | | | 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 |
}
} else {
DuplicateHandle(hProcess, inputHandle, hProcess, &startInfo.hStdInput,
0, TRUE, DUPLICATE_SAME_ACCESS);
}
if (startInfo.hStdInput == INVALID_HANDLE_VALUE) {
Tcl_WinConvertError(GetLastError());
TclPrintfResult(interp,
"couldn't duplicate input handle: %s",
Tcl_PosixError(interp));
goto end;
}
if (outputHandle == INVALID_HANDLE_VALUE) {
/*
* If handle was not set, output should be sent to an infinitely deep
* sink. Under Windows 95, some 16 bit applications cannot have stdout
|
| ︙ | ︙ | |||
1057 1058 1059 1060 1061 1062 1063 |
&secAtts, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
} else {
DuplicateHandle(hProcess, outputHandle, hProcess,
&startInfo.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS);
}
if (startInfo.hStdOutput == INVALID_HANDLE_VALUE) {
Tcl_WinConvertError(GetLastError());
| | | | | | 1057 1058 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 |
&secAtts, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
} else {
DuplicateHandle(hProcess, outputHandle, hProcess,
&startInfo.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS);
}
if (startInfo.hStdOutput == INVALID_HANDLE_VALUE) {
Tcl_WinConvertError(GetLastError());
TclPrintfResult(interp,
"couldn't duplicate output handle: %s",
Tcl_PosixError(interp));
goto end;
}
if (errorHandle == INVALID_HANDLE_VALUE) {
/*
* If handle was not set, errors should be sent to an infinitely deep
* sink.
*/
startInfo.hStdError = CreateFileW(L"NUL:", GENERIC_WRITE, 0,
&secAtts, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
} else {
DuplicateHandle(hProcess, errorHandle, hProcess, &startInfo.hStdError,
0, TRUE, DUPLICATE_SAME_ACCESS);
}
if (startInfo.hStdError == INVALID_HANDLE_VALUE) {
Tcl_WinConvertError(GetLastError());
TclPrintfResult(interp,
"couldn't duplicate error handle: %s",
Tcl_PosixError(interp));
goto end;
}
/*
* If we do not have a console window, then we must run DOS and WIN32
* console mode applications as detached processes. This tells the loader
* that the child application should not inherit the console, and that it
|
| ︙ | ︙ | |||
1139 1140 1141 1142 1143 1144 1145 |
BuildCommandLine(execPath, argc, argv, &cmdLine);
if (CreateProcessW(NULL, (WCHAR *) Tcl_DStringValue(&cmdLine),
NULL, NULL, TRUE, (DWORD) createFlags, NULL, NULL, &startInfo,
&procInfo) == 0) {
Tcl_WinConvertError(GetLastError());
| | | | 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 |
BuildCommandLine(execPath, argc, argv, &cmdLine);
if (CreateProcessW(NULL, (WCHAR *) Tcl_DStringValue(&cmdLine),
NULL, NULL, TRUE, (DWORD) createFlags, NULL, NULL, &startInfo,
&procInfo) == 0) {
Tcl_WinConvertError(GetLastError());
TclPrintfResult(interp, "couldn't execute \"%s\": %s",
argv[0], Tcl_PosixError(interp));
goto end;
}
/*
* This wait is used to force the OS to give some time to the DOS process.
*/
|
| ︙ | ︙ | |||
1388 1389 1390 1391 1392 1393 1394 |
}
break;
}
Tcl_DStringFree(&nameBuf);
if (applType == APPL_NONE) {
Tcl_WinConvertError(GetLastError());
| | | | 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 |
}
break;
}
Tcl_DStringFree(&nameBuf);
if (applType == APPL_NONE) {
Tcl_WinConvertError(GetLastError());
TclPrintfResult(interp, "couldn't execute \"%s\": %s",
originalName, Tcl_PosixError(interp));
return APPL_NONE;
}
if (applType == APPL_WIN3X) {
/*
* Replace long path name of executable with short path name for
* 16-bit applications. Otherwise the application may not be able to
|
| ︙ | ︙ | |||
1870 1871 1872 1873 1874 1875 1876 |
sec.nLength = sizeof(SECURITY_ATTRIBUTES);
sec.lpSecurityDescriptor = NULL;
sec.bInheritHandle = FALSE;
if (!CreatePipe(&readHandle, &writeHandle, &sec, 0)) {
Tcl_WinConvertError(GetLastError());
| | | | 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 |
sec.nLength = sizeof(SECURITY_ATTRIBUTES);
sec.lpSecurityDescriptor = NULL;
sec.bInheritHandle = FALSE;
if (!CreatePipe(&readHandle, &writeHandle, &sec, 0)) {
Tcl_WinConvertError(GetLastError());
TclPrintfResult(interp,
"pipe creation failed: %s", Tcl_PosixError(interp));
return TCL_ERROR;
}
*rchan = Tcl_MakeFileChannel((void *)readHandle, TCL_READABLE);
Tcl_RegisterChannel(interp, *rchan);
*wchan = Tcl_MakeFileChannel((void *)writeHandle, TCL_WRITABLE);
|
| ︙ | ︙ |
Changes to win/tclWinReg.c.
| ︙ | ︙ | |||
1204 1205 1206 1207 1208 1209 1210 |
REGSAM mode) /* Mode flags to pass. */
{
DWORD result, size;
Tcl_DString subkey;
HKEY hKey;
REGSAM saveMode = mode;
static int checkExProc = 0;
| | < < < < | 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 |
REGSAM mode) /* Mode flags to pass. */
{
DWORD result, size;
Tcl_DString subkey;
HKEY hKey;
REGSAM saveMode = mode;
static int checkExProc = 0;
static LONG (* regDeleteKeyExProc) (HKEY, LPCWSTR, REGSAM, DWORD) = (LONG (*) (HKEY, LPCWSTR, REGSAM, DWORD)) NULL;
/*
* Do not allow NULL or empty key name.
*/
if (!keyName || *keyName == '\0') {
return ERROR_BADKEY;
|
| ︙ | ︙ | |||
1248 1249 1250 1251 1252 1253 1254 |
*/
if (mode && !checkExProc) {
HMODULE handle;
checkExProc = 1;
handle = GetModuleHandleW(L"ADVAPI32");
| | | | | | 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 |
*/
if (mode && !checkExProc) {
HMODULE handle;
checkExProc = 1;
handle = GetModuleHandleW(L"ADVAPI32");
regDeleteKeyExProc = (LONG (*) (HKEY, LPCWSTR, REGSAM, DWORD))
(void *)GetProcAddress(handle, "RegDeleteKeyExW");
}
if (mode && regDeleteKeyExProc) {
result = regDeleteKeyExProc(startKey, keyName, mode, 0);
} else {
result = RegDeleteKeyW(startKey, keyName);
}
break;
} else if (result == ERROR_SUCCESS) {
result = RecursiveDeleteKey(hKey,
(const WCHAR *) Tcl_DStringValue(&subkey), mode);
|
| ︙ | ︙ |
Changes to win/tclWinSerial.c.
| ︙ | ︙ | |||
1648 1649 1650 1651 1652 1653 1654 |
infoPtr->flags &= ~SERIAL_CLOSE_MASK;
infoPtr->flags |= SERIAL_CLOSE_DRAIN;
} else if (strncasecmp(value, "DISCARD", vlen) == 0) {
infoPtr->flags &= ~SERIAL_CLOSE_MASK;
infoPtr->flags |= SERIAL_CLOSE_DISCARD;
} else {
if (interp) {
| | | | | | 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 |
infoPtr->flags &= ~SERIAL_CLOSE_MASK;
infoPtr->flags |= SERIAL_CLOSE_DRAIN;
} else if (strncasecmp(value, "DISCARD", vlen) == 0) {
infoPtr->flags &= ~SERIAL_CLOSE_MASK;
infoPtr->flags |= SERIAL_CLOSE_DISCARD;
} else {
if (interp) {
TclPrintfResult(interp,
"bad mode \"%s\" for -closemode: must be"
" default, discard, or drain", value);
TclSetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE",
"VALUE");
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
1674 1675 1676 1677 1678 1679 1680 |
Tcl_DStringInit(&ds);
native = Tcl_UtfToWCharDString(value, TCL_INDEX_NONE, &ds);
result = BuildCommDCBW(native, &dcb);
Tcl_DStringFree(&ds);
if (result == FALSE) {
if (interp != NULL) {
| | | | | 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 |
Tcl_DStringInit(&ds);
native = Tcl_UtfToWCharDString(value, TCL_INDEX_NONE, &ds);
result = BuildCommDCBW(native, &dcb);
Tcl_DStringFree(&ds);
if (result == FALSE) {
if (interp != NULL) {
TclPrintfResult(interp,
"bad value \"%s\" for -mode: should be baud,parity,data,stop",
value);
TclSetErrorCode(interp, "TCL", "VALUE", "SERIALMODE");
}
return TCL_ERROR;
}
/*
* Default settings for serial communications.
*/
|
| ︙ | ︙ | |||
1738 1739 1740 1741 1742 1743 1744 |
dcb.fOutxCtsFlow = TRUE;
dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
} else if (strncasecmp(value, "DTRDSR", vlen) == 0) {
dcb.fOutxDsrFlow = TRUE;
dcb.fDtrControl = DTR_CONTROL_HANDSHAKE;
} else {
if (interp != NULL) {
| | | | | 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 |
dcb.fOutxCtsFlow = TRUE;
dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
} else if (strncasecmp(value, "DTRDSR", vlen) == 0) {
dcb.fOutxDsrFlow = TRUE;
dcb.fDtrControl = DTR_CONTROL_HANDSHAKE;
} else {
if (interp != NULL) {
TclPrintfResult(interp,
"bad value \"%s\" for -handshake: must be one of"
" xonxoff, rtscts, dtrdsr or none", value);
TclSetErrorCode(interp, "TCL", "VALUE", "HANDSHAKE");
}
return TCL_ERROR;
}
if (!SetCommState(infoPtr->handle, &dcb)) {
goto setStateFailed;
}
|
| ︙ | ︙ | |||
1767 1768 1769 1770 1771 1772 1773 |
if (Tcl_SplitList(interp, value, &argc, &argv) == TCL_ERROR) {
return TCL_ERROR;
}
if (argc != 2) {
badXchar:
if (interp != NULL) {
| | | < | | 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 |
if (Tcl_SplitList(interp, value, &argc, &argv) == TCL_ERROR) {
return TCL_ERROR;
}
if (argc != 2) {
badXchar:
if (interp != NULL) {
TclPrintfResult(interp,
"bad value for -xchar: should be a list of"
" two elements with each a single 8-bit character");
TclSetErrorCode(interp, "TCL", "VALUE", "XCHAR");
}
Tcl_Free((void *)argv);
return TCL_ERROR;
}
/*
* These dereferences are safe, even in the zero-length string cases,
|
| ︙ | ︙ | |||
1825 1826 1827 1828 1829 1830 1831 |
int res = TCL_OK;
if (Tcl_SplitList(interp, value, &argc, &argv) == TCL_ERROR) {
return TCL_ERROR;
}
if ((argc % 2) == 1) {
if (interp != NULL) {
| | | | < | | | < | | | < | | | | | | < | 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 |
int res = TCL_OK;
if (Tcl_SplitList(interp, value, &argc, &argv) == TCL_ERROR) {
return TCL_ERROR;
}
if ((argc % 2) == 1) {
if (interp != NULL) {
TclPrintfResult(interp,
"bad value \"%s\" for -ttycontrol: should be "
"a list of signal,value pairs", value);
TclSetErrorCode(interp, "TCL", "VALUE", "TTYCONTROL");
}
Tcl_Free((void *)argv);
return TCL_ERROR;
}
for (i = 0; i < argc - 1; i += 2) {
if (Tcl_GetBoolean(interp, argv[i+1], &flag) == TCL_ERROR) {
res = TCL_ERROR;
break;
}
if (strncasecmp(argv[i], "DTR", strlen(argv[i])) == 0) {
if (!EscapeCommFunction(infoPtr->handle,
(DWORD) (flag ? SETDTR : CLRDTR))) {
if (interp != NULL) {
TclPrintfResult(interp, "can't set DTR signal");
TclSetErrorCode(interp, "TCL", "OPERATION",
"FCONFIGURE", "TTY_SIGNAL");
}
res = TCL_ERROR;
break;
}
} else if (strncasecmp(argv[i], "RTS", strlen(argv[i])) == 0) {
if (!EscapeCommFunction(infoPtr->handle,
(DWORD) (flag ? SETRTS : CLRRTS))) {
if (interp != NULL) {
TclPrintfResult(interp, "can't set RTS signal");
TclSetErrorCode(interp, "TCL", "OPERATION",
"FCONFIGURE", "TTY_SIGNAL");
}
res = TCL_ERROR;
break;
}
} else if (strncasecmp(argv[i], "BREAK", strlen(argv[i])) == 0) {
if (!EscapeCommFunction(infoPtr->handle,
(DWORD) (flag ? SETBREAK : CLRBREAK))) {
if (interp != NULL) {
TclPrintfResult(interp, "can't set BREAK signal");
TclSetErrorCode(interp, "TCL", "OPERATION",
"FCONFIGURE", "TTY_SIGNAL");
}
res = TCL_ERROR;
break;
}
} else {
if (interp != NULL) {
TclPrintfResult(interp,
"bad signal name \"%s\" for -ttycontrol: must be"
" DTR, RTS or BREAK", argv[i]);
TclSetErrorCode(interp, "TCL", "VALUE", "TTY_SIGNAL");
}
res = TCL_ERROR;
break;
}
}
Tcl_Free((void *)argv);
|
| ︙ | ︙ | |||
1918 1919 1920 1921 1922 1923 1924 |
inSize = atoi(argv[0]);
outSize = atoi(argv[1]);
}
Tcl_Free((void *)argv);
if ((argc < 1) || (argc > 2) || (inSize <= 0) || (outSize <= 0)) {
if (interp != NULL) {
| | | | | | | 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 |
inSize = atoi(argv[0]);
outSize = atoi(argv[1]);
}
Tcl_Free((void *)argv);
if ((argc < 1) || (argc > 2) || (inSize <= 0) || (outSize <= 0)) {
if (interp != NULL) {
TclPrintfResult(interp,
"bad value \"%s\" for -sysbuffer: should be "
"a list of one or two integers > 0", value);
TclSetErrorCode(interp, "TCL", "VALUE", "SYS_BUFFER");
}
return TCL_ERROR;
}
if (!SetupComm(infoPtr->handle, inSize, outSize)) {
if (interp != NULL) {
Tcl_WinConvertError(GetLastError());
TclPrintfResult(interp,
"can't setup comm buffers: %s",
Tcl_PosixError(interp));
}
return TCL_ERROR;
}
infoPtr->sysBufRead = inSize;
infoPtr->sysBufWrite = outSize;
/*
|
| ︙ | ︙ | |||
1980 1981 1982 1983 1984 1985 1986 |
if (Tcl_GetInt(interp, value, &msec) != TCL_OK) {
return TCL_ERROR;
}
tout.ReadTotalTimeoutConstant = msec;
if (!SetCommTimeouts(infoPtr->handle, &tout)) {
if (interp != NULL) {
Tcl_WinConvertError(GetLastError());
| | | < | | | | | 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 |
if (Tcl_GetInt(interp, value, &msec) != TCL_OK) {
return TCL_ERROR;
}
tout.ReadTotalTimeoutConstant = msec;
if (!SetCommTimeouts(infoPtr->handle, &tout)) {
if (interp != NULL) {
Tcl_WinConvertError(GetLastError());
TclPrintfResult(interp,
"can't set comm timeouts: %s", Tcl_PosixError(interp));
}
return TCL_ERROR;
}
return TCL_OK;
}
return Tcl_BadChannelOption(interp, optionName,
"closemode mode handshake pollinterval sysbuffer timeout "
"ttycontrol xchar");
getStateFailed:
if (interp != NULL) {
Tcl_WinConvertError(GetLastError());
TclPrintfResult(interp,
"can't get comm state: %s", Tcl_PosixError(interp));
}
return TCL_ERROR;
setStateFailed:
if (interp != NULL) {
Tcl_WinConvertError(GetLastError());
TclPrintfResult(interp,
"can't set comm state: %s", Tcl_PosixError(interp));
}
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
2086 2087 2088 2089 2090 2091 2092 |
char parity;
const char *stop;
char buf[2 * TCL_INTEGER_SPACE + 16];
if (!GetCommState(infoPtr->handle, &dcb)) {
if (interp != NULL) {
Tcl_WinConvertError(GetLastError());
| | | | 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 |
char parity;
const char *stop;
char buf[2 * TCL_INTEGER_SPACE + 16];
if (!GetCommState(infoPtr->handle, &dcb)) {
if (interp != NULL) {
Tcl_WinConvertError(GetLastError());
TclPrintfResult(interp,
"can't get comm state: %s", Tcl_PosixError(interp));
}
return TCL_ERROR;
}
valid = 1;
parity = 'n';
if (dcb.Parity <= 4) {
|
| ︙ | ︙ | |||
2156 2157 2158 2159 2160 2161 2162 |
if (len==0 || (len>1 && strncmp(optionName, "-xchar", len) == 0)) {
char buf[4];
valid = 1;
if (!GetCommState(infoPtr->handle, &dcb)) {
if (interp != NULL) {
Tcl_WinConvertError(GetLastError());
| | | | 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 |
if (len==0 || (len>1 && strncmp(optionName, "-xchar", len) == 0)) {
char buf[4];
valid = 1;
if (!GetCommState(infoPtr->handle, &dcb)) {
if (interp != NULL) {
Tcl_WinConvertError(GetLastError());
TclPrintfResult(interp,
"can't get comm state: %s", Tcl_PosixError(interp));
}
return TCL_ERROR;
}
buf[Tcl_UniCharToUtf(UCHAR(dcb.XonChar), buf)] = '\0';
Tcl_DStringAppendElement(dsPtr, buf);
buf[Tcl_UniCharToUtf(UCHAR(dcb.XoffChar), buf)] = '\0';
Tcl_DStringAppendElement(dsPtr, buf);
|
| ︙ | ︙ | |||
2234 2235 2236 2237 2238 2239 2240 |
if (len>4 && strncmp(optionName, "-ttystatus", len)==0) {
DWORD status;
if (!GetCommModemStatus(infoPtr->handle, &status)) {
if (interp != NULL) {
Tcl_WinConvertError(GetLastError());
| | | | 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 |
if (len>4 && strncmp(optionName, "-ttystatus", len)==0) {
DWORD status;
if (!GetCommModemStatus(infoPtr->handle, &status)) {
if (interp != NULL) {
Tcl_WinConvertError(GetLastError());
TclPrintfResult(interp,
"can't get tty status: %s", Tcl_PosixError(interp));
}
return TCL_ERROR;
}
valid = 1;
SerialModemStatusStr(status, dsPtr);
}
|
| ︙ | ︙ |
Changes to win/tclWinSock.c.
| ︙ | ︙ | |||
1214 1215 1216 1217 1218 1219 1220 |
return TCL_ERROR;
}
rtn = setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
(const char *) &boolVar, sizeof(boolVar));
if (rtn != 0) {
Tcl_WinConvertError(WSAGetLastError());
if (interp) {
| | | | | | 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 |
return TCL_ERROR;
}
rtn = setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
(const char *) &boolVar, sizeof(boolVar));
if (rtn != 0) {
Tcl_WinConvertError(WSAGetLastError());
if (interp) {
TclPrintfResult(interp,
"couldn't set socket option: %s",
Tcl_PosixError(interp));
}
return TCL_ERROR;
}
return TCL_OK;
}
if ((len > 1) && (optionName[1] == 'n') &&
(strncmp(optionName, "-nodelay", len) == 0)) {
BOOL boolVar;
int rtn;
if (Tcl_GetBoolean(interp, value, &boolVar) != TCL_OK) {
return TCL_ERROR;
}
rtn = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
(const char *) &boolVar, sizeof(boolVar));
if (rtn != 0) {
Tcl_WinConvertError(WSAGetLastError());
if (interp) {
TclPrintfResult(interp,
"couldn't set socket option: %s",
Tcl_PosixError(interp));
}
return TCL_ERROR;
}
return TCL_OK;
}
return Tcl_BadChannelOption(interp, optionName, "keepalive nodelay");
}
|
| ︙ | ︙ | |||
1423 1424 1425 1426 1427 1428 1429 |
* an fconfigure request on a server socket (such sockets have no
* peer). {Copied from unix/tclUnixChan.c}
*/
if (len) {
Tcl_WinConvertError((DWORD) WSAGetLastError());
if (interp) {
| | | < | 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 |
* an fconfigure request on a server socket (such sockets have no
* peer). {Copied from unix/tclUnixChan.c}
*/
if (len) {
Tcl_WinConvertError((DWORD) WSAGetLastError());
if (interp) {
TclPrintfResult(interp,
"can't get peername: %s", Tcl_PosixError(interp));
}
return TCL_ERROR;
}
}
}
if ((len == 0) || HAVE_OPTION("-sockname")) {
|
| ︙ | ︙ | |||
1497 1498 1499 1500 1501 1502 1503 |
if (len) {
return TCL_OK;
}
Tcl_DStringEndSublist(dsPtr);
} else {
if (interp) {
Tcl_WinConvertError((DWORD) WSAGetLastError());
| | | | 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 |
if (len) {
return TCL_OK;
}
Tcl_DStringEndSublist(dsPtr);
} else {
if (interp) {
Tcl_WinConvertError((DWORD) WSAGetLastError());
TclPrintfResult(interp,
"can't get sockname: %s", Tcl_PosixError(interp));
}
return TCL_ERROR;
}
}
if ((len == 0) || HAVE_OPTION("-keepalive")) {
int optlen;
|
| ︙ | ︙ | |||
1966 1967 1968 1969 1970 1971 1972 |
}
/*
* Error message on synchronous connect
*/
if (interp != NULL) {
| | | | 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 |
}
/*
* Error message on synchronous connect
*/
if (interp != NULL) {
TclPrintfResult(interp,
"couldn't open socket: %s", Tcl_PosixError(interp));
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
|
| ︙ | ︙ | |||
2020 2021 2022 2023 2024 2025 2026 |
if (!TclCreateSocketAddress(interp, &addrlist, host, port, 0, &errorMsg)
|| !TclCreateSocketAddress(interp, &myaddrlist, myaddr, myport, 1,
&errorMsg)) {
if (addrlist != NULL) {
freeaddrinfo(addrlist);
}
if (interp != NULL) {
| < | | 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 |
if (!TclCreateSocketAddress(interp, &addrlist, host, port, 0, &errorMsg)
|| !TclCreateSocketAddress(interp, &myaddrlist, myaddr, myport, 1,
&errorMsg)) {
if (addrlist != NULL) {
freeaddrinfo(addrlist);
}
if (interp != NULL) {
TclPrintfResult(interp, "couldn't open socket: %s", errorMsg);
}
return NULL;
}
statePtr = NewSocketInfo(INVALID_SOCKET);
statePtr->addrlist = addrlist;
statePtr->myaddrlist = myaddrlist;
|
| ︙ | ︙ | |||
2295 2296 2297 2298 2299 2300 2301 |
Tcl_CloseEx(NULL, statePtr->channel, 0);
return NULL;
}
return statePtr->channel;
}
if (interp != NULL) {
| | | | 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 |
Tcl_CloseEx(NULL, statePtr->channel, 0);
return NULL;
}
return statePtr->channel;
}
if (interp != NULL) {
TclPrintfResult(interp,
"couldn't open socket: %s",
(errorMsg ? errorMsg : Tcl_PosixError(interp)));
}
if (sock != INVALID_SOCKET) {
closesocket(sock);
}
return NULL;
}
|
| ︙ | ︙ |