Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | resolves large discrepancies in proc/lambda between 8.5 and 8.6; coverage for [e3f481f187] regression to lookup non-ASCII proc/lambda formal arguments (TclCreateProc/TclPushVarName); cherry-picked from [c9251294d9b8b14d] (pyk-backport-to-8-6) and amend [3e12442cb7829c9f] (fix-comp-local-utf-regres). |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | sebres-8-5-comp-8-6-fix |
Files: | files | file ages | folders |
SHA3-256: |
fb2b91aea8dab9e75542ac89d46e4d86 |
User & Date: | sebres 2019-03-08 00:04:00.414 |
Context
2019-03-08
| ||
00:34 | test case for [408568] "variable substitution parsing limited to ASCII alphanumerics": illustrating ... check-in: 745068c247 user: sebres tags: bug-408568 | |
00:04 | resolves large discrepancies in proc/lambda between 8.5 and 8.6; coverage for [e3f481f187] regressi... Leaf check-in: fb2b91aea8 user: sebres tags: sebres-8-5-comp-8-6-fix | |
2019-03-05
| ||
16:25 | merge sebres-8-5-timerate (TIP#527 - New measurement facilities in TCL: New command timerate, perfor... check-in: 5c26638643 user: sebres tags: core-8-5-branch | |
2019-02-01
| ||
13:20 | merge fix [e3f481f187] regression to lookup non-ASCII proc/lambda formal arguments (TclCreateProc/Tc... check-in: 3e12442cb7 user: sebres tags: core-8-6-branch | |
2018-02-14
| ||
14:19 | merge pyk-backport-to-8-6 check-in: c9251294d9 user: pooryorick tags: core-8-6-branch | |
Changes
Changes to generic/tclCompCmds.c.
︙ | ︙ | |||
4779 4780 4781 4782 4783 4784 4785 | int *localIndexPtr, /* Must not be NULL. */ int *simpleVarNamePtr, /* Must not be NULL. */ int *isScalarPtr, /* Must not be NULL. */ int line, /* Line the token starts on. */ int* clNext) /* Reference to offset of next hidden cont. line */ { register const char *p; | | | | | | | > > | | | | | | > | | > | | | | | | | | | | 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 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 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 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 | int *localIndexPtr, /* Must not be NULL. */ int *simpleVarNamePtr, /* Must not be NULL. */ int *isScalarPtr, /* Must not be NULL. */ int line, /* Line the token starts on. */ int* clNext) /* Reference to offset of next hidden cont. line */ { register const char *p; const char *last, *name, *elName; register int n; Tcl_Token *elemTokenPtr = NULL; int nameLen, elNameLen, simpleVarName, localIndex; int elemTokenCount = 0, allocedTokens = 0, removedParen = 0; /* * Decide if we can use a frame slot for the var/array name or if we need * to emit code to compute and push the name at runtime. We use a frame * slot (entry in the array of local vars) if we are compiling a procedure * body and if the name is simple text that does not include namespace * qualifiers. */ simpleVarName = 0; name = elName = NULL; nameLen = elNameLen = 0; localIndex = -1; if (varTokenPtr->type == TCL_TOKEN_SIMPLE_WORD) { /* * A simple variable name. Divide it up into "name" and "elName" * strings. If it is not a local variable, look it up at runtime. */ simpleVarName = 1; name = varTokenPtr[1].start; nameLen = varTokenPtr[1].size; if (name[nameLen-1] == ')') { /* * last char is ')' => potential array reference. */ last = Tcl_UtfPrev(name + nameLen, name); if (*last == ')') { for (p = name; p < last; p = Tcl_UtfNext(p)) { if (*p == '(') { elName = p + 1; elNameLen = last - elName; nameLen = p - name; break; } } } if (interp && elNameLen) { /* * An array element, the element name is a simple string: * assemble the corresponding token. */ elemTokenPtr = (Tcl_Token *) TclStackAlloc(interp, sizeof(Tcl_Token)); allocedTokens = 1; elemTokenPtr->type = TCL_TOKEN_TEXT; elemTokenPtr->start = elName; elemTokenPtr->size = elNameLen; elemTokenPtr->numComponents = 0; elemTokenCount = 1; } } } else if (interp && ((n = varTokenPtr->numComponents) > 1) && (varTokenPtr[1].type == TCL_TOKEN_TEXT) && (varTokenPtr[n].type == TCL_TOKEN_TEXT) && (*((p = varTokenPtr[n].start + varTokenPtr[n].size)-1) == ')') && (*Tcl_UtfPrev(p, varTokenPtr[n].start) == ')')) { /* * Check for parentheses inside first token. */ simpleVarName = 0; for (p = varTokenPtr[1].start, last = p + varTokenPtr[1].size; p < last; p = Tcl_UtfNext(p)) { if (*p == '(') { simpleVarName = 1; break; } } if (simpleVarName) { int remainingLen; /* * Check the last token: if it is just ')', do not count it. * Otherwise, remove the ')' and flag so that it is restored at * the end. */ if (varTokenPtr[n].size == 1) { --n; } else { --varTokenPtr[n].size; removedParen = n; } name = varTokenPtr[1].start; nameLen = p - varTokenPtr[1].start; elName = p + 1; remainingLen = (varTokenPtr[2].start - p) - 1; elNameLen = (varTokenPtr[n].start-p) + varTokenPtr[n].size - 1; if (remainingLen) { /* * Make a first token with the extra characters in the first * token. */ elemTokenPtr = (Tcl_Token *) TclStackAlloc(interp, n * sizeof(Tcl_Token)); allocedTokens = 1; elemTokenPtr->type = TCL_TOKEN_TEXT; elemTokenPtr->start = elName; elemTokenPtr->size = remainingLen; elemTokenPtr->numComponents = 0; elemTokenCount = n; /* * Copy the remaining tokens. */ |
︙ | ︙ | |||
4915 4916 4917 4918 4919 4920 4921 | if (simpleVarName) { /* * See whether name has any namespace separators (::'s). */ int hasNsQualifiers = 0; | | | | | | | 4919 4920 4921 4922 4923 4924 4925 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 | if (simpleVarName) { /* * See whether name has any namespace separators (::'s). */ int hasNsQualifiers = 0; for (p = name, last = p + nameLen-1; p < last; p = Tcl_UtfNext(p)) { if ((*p == ':') && (*(p+1) == ':')) { hasNsQualifiers = 1; break; } } /* * Look up the var name's index in the array of local vars in the proc * frame. If retrieving the var's value and it doesn't already exist, * push its name and look it up at runtime. */ if ((envPtr->procPtr != NULL) && !hasNsQualifiers) { localIndex = TclFindCompiledLocal(name, nameLen, /*create*/ flags & TCL_CREATE_VAR, envPtr->procPtr); if ((flags & TCL_NO_LARGE_INDEX) && (localIndex > 255)) { /* * We'll push the name. */ localIndex = -1; } } if (interp && localIndex < 0) { PushLiteral(envPtr, name, nameLen); } /* * Compile the element script, if any. */ if (interp && elName != NULL) { if (elNameLen) { envPtr->line = line; envPtr->clNext = clNext; TclCompileTokens(interp, elemTokenPtr, elemTokenCount, envPtr); } else { PushLiteral(envPtr, "", 0); } } |
︙ | ︙ |
Changes to generic/tclExecute.c.
︙ | ︙ | |||
1101 1102 1103 1104 1105 1106 1107 | void * TclStackAlloc( Tcl_Interp *interp, int numBytes) { Interp *iPtr = (Interp *) interp; | | | | 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 | void * TclStackAlloc( Tcl_Interp *interp, int numBytes) { Interp *iPtr = (Interp *) interp; int numWords; if (iPtr == NULL || iPtr->execEnvPtr == NULL) { return (void *) ckalloc(numBytes); } numWords = (numBytes + (sizeof(Tcl_Obj *) - 1))/sizeof(Tcl_Obj *); return (void *) StackAllocWords(interp, numWords); } void * TclStackRealloc( Tcl_Interp *interp, void *ptr, |
︙ | ︙ |
Changes to generic/tclInt.h.
︙ | ︙ | |||
799 800 801 802 803 804 805 | */ typedef struct CompiledLocal { struct CompiledLocal *nextPtr; /* Next compiler-recognized local variable for * this procedure, or NULL if this is the last * local. */ | | | < | 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 | */ typedef struct CompiledLocal { struct CompiledLocal *nextPtr; /* Next compiler-recognized local variable for * this procedure, or NULL if this is the last * local. */ int nameLength; /* The number of bytes in local variable's name. * Among others used to speed up var lookups. */ int frameIndex; /* Index in the array of compiler-assigned * variables in the procedure call frame. */ int flags; /* Flag bits for the local variable. Same as * the flags for the Var structure above, * although only VAR_ARGUMENT, VAR_TEMPORARY, * and VAR_RESOLVED make sense. */ Tcl_Obj *defValuePtr; /* Pointer to the default value of an |
︙ | ︙ | |||
3724 3725 3726 3727 3728 3729 3730 | # define TclUniCharNcmp(cs,ct,n) memcmp((cs),(ct),(n)*sizeof(Tcl_UniChar)) #else /* !WORDS_BIGENDIAN */ # define TclUniCharNcmp Tcl_UniCharNcmp #endif /* WORDS_BIGENDIAN */ /* *---------------------------------------------------------------- | | | 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 | # define TclUniCharNcmp(cs,ct,n) memcmp((cs),(ct),(n)*sizeof(Tcl_UniChar)) #else /* !WORDS_BIGENDIAN */ # define TclUniCharNcmp Tcl_UniCharNcmp #endif /* WORDS_BIGENDIAN */ /* *---------------------------------------------------------------- * Macro used by the Tcl core to increment a namespace's export epoch * counter. The ANSI C "prototype" for this macro is: * * MODULE_SCOPE void TclInvalidateNsCmdLookup(Namespace *nsPtr); *---------------------------------------------------------------- */ #define TclInvalidateNsCmdLookup(nsPtr) \ |
︙ | ︙ |
Changes to generic/tclListObj.c.
︙ | ︙ | |||
47 48 49 50 51 52 53 | }; /* *---------------------------------------------------------------------- * * NewListIntRep -- * | | | | | | > | | | | > | | | 47 48 49 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 | }; /* *---------------------------------------------------------------------- * * NewListIntRep -- * * Creates a 'List' structure with space for 'objc' elements. 'objc' must * be > 0. If 'objv' is not NULL, The list is initialized with first * 'objc' values in that array. Otherwise the list is initialized to have * 0 elements, with space to add 'objc' more. Flag value 'p' indicates * how to behave on failure. * * Value * * A new 'List' structure with refCount 0. If some failure * prevents this NULL is returned if 'p' is 0 , and 'Tcl_Panic' * is called if it is not. * * Effect * * The refCount of each value in 'objv' is incremented as it is added * to the list. * *---------------------------------------------------------------------- */ static List * NewListIntRep( int objc, |
︙ | ︙ | |||
125 126 127 128 129 130 131 | } return listRepPtr; } /* *---------------------------------------------------------------------- * | | < < < < < < < | < | < < < < | 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | } return listRepPtr; } /* *---------------------------------------------------------------------- * * AttemptNewList -- * * Like NewListIntRep, but additionally sets an error message on failure. * *---------------------------------------------------------------------- */ static List * AttemptNewList( Tcl_Interp *interp, int objc, |
︙ | ︙ | |||
171 172 173 174 175 176 177 | } /* *---------------------------------------------------------------------- * * Tcl_NewListObj -- * | < | < < > < < > < | | | | | > | | | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | } /* *---------------------------------------------------------------------- * * Tcl_NewListObj -- * * Creates a new list object and adds values to it. When TCL_MEM_DEBUG is * defined, 'Tcl_DbNewListObj' is called instead. * * Value * * A new list 'Tcl_Obj' to which is appended values from 'objv', or if * 'objc' is less than or equal to zero, a list 'Tcl_Obj' having no * elements. The string representation of the new 'Tcl_Obj' is set to * NULL. The refCount of the list is 0. * * Effect * * The refCount of each elements in 'objv' is incremented as it is added * to the list. * *---------------------------------------------------------------------- */ #ifdef TCL_MEM_DEBUG #undef Tcl_NewListObj |
︙ | ︙ | |||
238 239 240 241 242 243 244 | return listPtr; } #endif /* if TCL_MEM_DEBUG */ /* *---------------------------------------------------------------------- * | | | < < < | | | | | | < < < < < < < < < < < | 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | return listPtr; } #endif /* if TCL_MEM_DEBUG */ /* *---------------------------------------------------------------------- * * Tcl_DbNewListObj -- * * Like 'Tcl_NewListObj', but it calls Tcl_DbCkalloc directly with the * file name and line number from its caller. This simplifies debugging * since the [memory active] command will report the correct file * name and line number when reporting objects that haven't been freed. * * When TCL_MEM_DEBUG is not defined, 'Tcl_NewListObj' is called instead. * *---------------------------------------------------------------------- */ #ifdef TCL_MEM_DEBUG Tcl_Obj * |
︙ | ︙ | |||
320 321 322 323 324 325 326 | #endif /* TCL_MEM_DEBUG */ /* *---------------------------------------------------------------------- * * Tcl_SetListObj -- * | | < < < | < < < < < < < < | 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | #endif /* TCL_MEM_DEBUG */ /* *---------------------------------------------------------------------- * * Tcl_SetListObj -- * * Like 'Tcl_NewListObj', but operates on an existing 'Tcl_Obj'instead of * creating a new one. * *---------------------------------------------------------------------- */ void Tcl_SetListObj( Tcl_Obj *objPtr, /* Object whose internal rep to init. */ |
︙ | ︙ | |||
377 378 379 380 381 382 383 | } /* *---------------------------------------------------------------------- * * TclListObjCopy -- * | | | | | < > | | | > | < > > | 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 | } /* *---------------------------------------------------------------------- * * TclListObjCopy -- * * Creates a new 'Tcl_Obj' which is a pure copy of a list value. This * provides for the C level a counterpart of the [lrange $list 0 end] * command, while using internals details to be as efficient as possible. * * Value * * The address of the new 'Tcl_Obj' which shares its internal * representation with 'listPtr', and whose refCount is 0. If 'listPtr' * is not actually a list, the value is NULL, and an error message is left * in 'interp' if it is not NULL. * * Effect * * 'listPtr' is converted to a list if it isn't one already. * *---------------------------------------------------------------------- */ Tcl_Obj * TclListObjCopy( Tcl_Interp *interp, /* Used to report errors if not NULL. */ |
︙ | ︙ | |||
418 419 420 421 422 423 424 | } /* *---------------------------------------------------------------------- * * Tcl_ListObjGetElements -- * | | < | > | > | | < < < | | | | | | > > > > > | < > | | 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 | } /* *---------------------------------------------------------------------- * * Tcl_ListObjGetElements -- * * Retreive the elements in a list 'Tcl_Obj'. * * Value * * TCL_OK * * A count of list elements is stored, 'objcPtr', And a pointer to the * array of elements in the list is stored in 'objvPtr'. * * The elements accessible via 'objvPtr' should be treated as readonly * and the refCount for each object is _not_ incremented; the caller * must do that if it holds on to a reference. Furthermore, the * pointer and length returned by this function may change as soon as * any function is called on the list object. Be careful about * retaining the pointer in a local data structure. * * TCL_ERROR * * 'listPtr' is not a valid list. An error message is left in the * interpreter's result if 'interp' is not NULL. * * Effect * * 'listPtr' is converted to a list object if it isn't one already. * *---------------------------------------------------------------------- */ int Tcl_ListObjGetElements( Tcl_Interp *interp, /* Used to report errors if not NULL. */ |
︙ | ︙ | |||
479 480 481 482 483 484 485 | } /* *---------------------------------------------------------------------- * * Tcl_ListObjAppendList -- * | < | > | > | | < > | > > | < | > | | | | > | | 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 | } /* *---------------------------------------------------------------------- * * Tcl_ListObjAppendList -- * * Appends the elements of elemListPtr to those of listPtr. * * Value * * TCL_OK * * Success. * * TCL_ERROR * * 'listPtr' or 'elemListPtr' are not valid lists. An error * message is left in the interpreter's result if 'interp' is not NULL. * * Effect * * The reference count of each element of 'elemListPtr' as it is added to * 'listPtr'. 'listPtr' and 'elemListPtr' are converted to 'tclListType' * if they are not already. Appending the new elements may cause the * array of element pointers in 'listObj' to grow. If any objects are * appended to 'listPtr'. Any preexisting string representation of * 'listPtr' is invalidated. * *---------------------------------------------------------------------- */ int Tcl_ListObjAppendList( Tcl_Interp *interp, /* Used to report errors if not NULL. */ |
︙ | ︙ | |||
536 537 538 539 540 541 542 | } /* *---------------------------------------------------------------------- * * Tcl_ListObjAppendElement -- * | | < < < | > | > > > > > | | | < | > > | < | | | | 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 | } /* *---------------------------------------------------------------------- * * Tcl_ListObjAppendElement -- * * Like 'Tcl_ListObjAppendList', but Appends a single value to a list. * * Value * * TCL_OK * * 'objPtr' is appended to the elements of 'listPtr'. * * TCL_ERROR * * listPtr does not refer to a list object and the object can not be * converted to one. An error message will be left in the * interpreter's result if interp is not NULL. * * Effect * * If 'listPtr' is not already of type 'tclListType', it is converted. * The 'refCount' of 'objPtr' is incremented as it is added to 'listPtr'. * Appending the new element may cause the the array of element pointers * in 'listObj' to grow. Any preexisting string representation of * 'listPtr' is invalidated. * *---------------------------------------------------------------------- */ int Tcl_ListObjAppendElement( Tcl_Interp *interp, /* Used to report errors if not NULL. */ |
︙ | ︙ | |||
650 651 652 653 654 655 656 | } /* *---------------------------------------------------------------------- * * Tcl_ListObjIndex -- * | | | < < < | > | > | > | | | > > > | | | > | | 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 | } /* *---------------------------------------------------------------------- * * Tcl_ListObjIndex -- * * Retrieve a pointer to the element of 'listPtr' at 'index'. The index * of the first element is 0. * * Value * * TCL_OK * * A pointer to the element at 'index' is stored in 'objPtrPtr'. If * 'index' is out of range, NULL is stored in 'objPtrPtr'. This * object should be treated as readonly and its 'refCount' is _not_ * incremented. The caller must do that if it holds on to the * reference. * * TCL_ERROR * * 'listPtr' is not a valid list. An an error message is left in the * interpreter's result if 'interp' is not NULL. * * Effect * * If 'listPtr' is not already of type 'tclListType', it is converted. * *---------------------------------------------------------------------- */ int Tcl_ListObjIndex( Tcl_Interp *interp, /* Used to report errors if not NULL. */ |
︙ | ︙ | |||
708 709 710 711 712 713 714 | } /* *---------------------------------------------------------------------- * * Tcl_ListObjLength -- * | | < < | > | > | > | < > | < | > | 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 | } /* *---------------------------------------------------------------------- * * Tcl_ListObjLength -- * * Retrieve the number of elements in a list. * * Value * * TCL_OK * * A count of list elements is stored at the address provided by * 'intPtr'. If 'listPtr' is not already of type 'tclListPtr', it is * converted. * * TCL_ERROR * * 'listPtr' is not a valid list. An error message will be left in * the interpreter's result if 'interp' is not NULL. * *---------------------------------------------------------------------- */ int Tcl_ListObjLength( Tcl_Interp *interp, /* Used to report errors if not NULL. */ |
︙ | ︙ | |||
756 757 758 759 760 761 762 | } /* *---------------------------------------------------------------------- * * Tcl_ListObjReplace -- * | < < | < | | | < > | | < > > > > | | < < < | > | | | < > > > > | < > | | | 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 | } /* *---------------------------------------------------------------------- * * Tcl_ListObjReplace -- * * Replace values in a list. * * If 'first' is zero or negative, it refers to the first element. If * 'first' outside the range of elements in the list, no elements are * deleted. * * If 'count' is zero or negative no elements are deleted, and any new * elements are inserted at the beginning of the list. * * Value * * TCL_OK * * The first 'objc' values of 'objv' replaced 'count' elements in 'listPtr' * starting at 'first'. If 'objc' 0, no new elements are added. * * TCL_ERROR * * 'listPtr' is not a valid list. An error message is left in the * interpreter's result if 'interp' is not NULL. * * Effect * * If 'listPtr' is not of type 'tclListType', it is converted if possible. * * The 'refCount' of each element appended to the list is incremented. * Similarly, the 'refCount' for each replaced element is decremented. * * If 'listPtr' is modified, any previous string representation is * invalidated. * *---------------------------------------------------------------------- */ int Tcl_ListObjReplace( Tcl_Interp *interp, /* Used for error reporting if not NULL. */ |
︙ | ︙ | |||
1007 1008 1009 1010 1011 1012 1013 | } /* *---------------------------------------------------------------------- * * TclLindexList -- * | | | | | | | > > | | < < < < < | 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 | } /* *---------------------------------------------------------------------- * * TclLindexList -- * * Implements the 'lindex' command when objc==3. * * Implemented entirely as a wrapper around 'TclLindexFlat'. Reconfigures * the argument format into required form while taking care to manage * shimmering so as to tend to keep the most useful intreps * and/or avoid the most expensive conversions. * * Value * * A pointer to the specified element, with its 'refCount' incremented, or * NULL if an error occurred. * * Notes * *---------------------------------------------------------------------- */ Tcl_Obj * TclLindexList( Tcl_Interp *interp, /* Tcl interpreter. */ |
︙ | ︙ | |||
1085 1086 1087 1088 1089 1090 1091 | Tcl_DecrRefCount(indexListCopy); return listPtr; } /* *---------------------------------------------------------------------- * | | | | | < < < < > > | < < < < | | > | 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 | Tcl_DecrRefCount(indexListCopy); return listPtr; } /* *---------------------------------------------------------------------- * * TclLindexFlat -- * * The core of the 'lindex' command, with all index * arguments presented as a flat list. * * Value * * A pointer to the object extracted, with its 'refCount' incremented, or * NULL if an error occurred. Thus, the calling code will usually do * something like: * * Tcl_SetObjResult(interp, result); * Tcl_DecrRefCount(result); * * *---------------------------------------------------------------------- */ Tcl_Obj * TclLindexFlat( Tcl_Interp *interp, /* Tcl interpreter. */ |
︙ | ︙ | |||
1179 1180 1181 1182 1183 1184 1185 | } /* *---------------------------------------------------------------------- * * TclLsetList -- * | | | < < | | < < > | < < < < | 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 | } /* *---------------------------------------------------------------------- * * TclLsetList -- * * The core of [lset] when objc == 4. Objv[2] may be either a * scalar index or a list of indices. * * Implemented entirely as a wrapper around 'TclLindexFlat', as described * for 'TclLindexList'. * * Value * * The new list, with the 'refCount' of 'valuPtr' incremented, or NULL if * there was an error. * *---------------------------------------------------------------------- */ Tcl_Obj * TclLsetList( Tcl_Interp *interp, /* Tcl interpreter. */ |
︙ | ︙ | |||
1257 1258 1259 1260 1261 1262 1263 | /* *---------------------------------------------------------------------- * * TclLsetFlat -- * * Core engine of the 'lset' command. * | | < > | < < > | < | | > > | > > | | | | | > > > | > | | < | | < < | | | | 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 | /* *---------------------------------------------------------------------- * * TclLsetFlat -- * * Core engine of the 'lset' command. * * Value * * The resulting list * * The 'refCount' of 'valuePtr' is incremented. If 'listPtr' was not * duplicated, its 'refCount' is incremented. The reference count of * an unduplicated object is therefore 2 (one for the returned pointer * and one for the variable that holds it). The reference count of a * duplicate object is 1, reflecting that result is the only active * reference. The caller is expected to store the result in the * variable and decrement its reference count. (INST_STORE_* does * exactly this.) * * NULL * * An error occurred. If 'listPtr' was duplicated, the reference * count on the duplicate is decremented so that it is 0, causing any * memory allocated by this function to be freed. * * * Effect * * On entry, the reference count of 'listPtr' does not reflect any * references held on the stack. The first action of this function is to * determine whether 'listPtr' is shared and to create a duplicate * unshared copy if it is. The reference count of the duplicate is * incremented. At this point, the reference count is 1 in either case so * that the object is considered unshared. * * The unshared list is altered directly to produce the result. * 'TclLsetFlat' maintains a linked list of 'Tcl_Obj' values whose string * representations must be spoilt by threading via 'ptr2' of the * two-pointer internal representation. On entry to 'TclLsetFlat', the * values of 'ptr2' are immaterial; on exit, the 'ptr2' field of any * Tcl_Obj that has been modified is set to NULL. * *---------------------------------------------------------------------- */ Tcl_Obj * |
︙ | ︙ | |||
1472 1473 1474 1475 1476 1477 1478 | } /* *---------------------------------------------------------------------- * * TclListObjSetElement -- * | | > > > | > | > > > > > | | > > > > | | | | | > | > | | | < < < | 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 | } /* *---------------------------------------------------------------------- * * TclListObjSetElement -- * * Set a single element of a list to a specified value. * * It is the caller's responsibility to invalidate the string * representation of the 'listPtr'. * * Value * * TCL_OK * * Success. * * TCL_ERROR * * 'listPtr' does not refer to a list object and cannot be converted * to one. An error message will be left in the interpreter result if * interp is not NULL. * * TCL_ERROR * * An index designates an element outside the range [0..listLength-1], * where 'listLength' is the count of elements in the list object * designated by 'listPtr'. An error message is left in the * interpreter result. * * Effect * * If 'listPtr' designates a shared object, 'Tcl_Panic' is called. If * 'listPtr' is not already of type 'tclListType', it is converted and the * internal representation is unshared. The 'refCount' of the element at * 'index' is decremented and replaced in the list with the 'valuePtr', * whose 'refCount' in turn is incremented. * * *---------------------------------------------------------------------- */ int TclListObjSetElement( Tcl_Interp *interp, /* Tcl interpreter; used for error reporting |
︙ | ︙ | |||
1601 1602 1603 1604 1605 1606 1607 | } /* *---------------------------------------------------------------------- * * FreeListInternalRep -- * | | | | < < | | | | 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 | } /* *---------------------------------------------------------------------- * * FreeListInternalRep -- * * Deallocate the storage associated with the internal representation of a * a list object. * * Effect * * The storage for the internal 'List' pointer of 'listPtr' is freed, the * 'internalRep.twoPtrValue.ptr1' of 'listPtr' is set to NULL, and the 'refCount' * of each element of the list is decremented. * *---------------------------------------------------------------------- */ static void FreeListInternalRep( Tcl_Obj *listPtr) /* List object with internal rep to free. */ |
︙ | ︙ | |||
1639 1640 1641 1642 1643 1644 1645 | } /* *---------------------------------------------------------------------- * * DupListInternalRep -- * | | | < < | | | > | > | | | > | < > > | 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 | } /* *---------------------------------------------------------------------- * * DupListInternalRep -- * * Initialize the internal representation of a list 'Tcl_Obj' to share the * internal representation of an existing list object. * * Effect * * The 'refCount' of the List internal rep is incremented. * *---------------------------------------------------------------------- */ static void DupListInternalRep( Tcl_Obj *srcPtr, /* Object with internal rep to copy. */ Tcl_Obj *copyPtr) /* Object with internal rep to set. */ { List *listRepPtr = ListRepPtr(srcPtr); ListSetIntRep(copyPtr, listRepPtr); } /* *---------------------------------------------------------------------- * * SetListFromAny -- * * Convert any object to a list. * * Value * * TCL_OK * * Success. The internal representation of 'objPtr' is set, and the type * of 'objPtr' is 'tclListType'. * * TCL_ERROR * * An error occured during conversion. An error message is left in the * interpreter's result if 'interp' is not NULL. * * *---------------------------------------------------------------------- */ static int SetListFromAny( Tcl_Interp *interp, /* Used for error reporting if not NULL. */ |
︙ | ︙ | |||
1796 1797 1798 1799 1800 1801 1802 | } /* *---------------------------------------------------------------------- * * UpdateStringOfList -- * | | > | | | < < | | | < | 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 | } /* *---------------------------------------------------------------------- * * UpdateStringOfList -- * * Update the string representation for a list object. * * Any previously-exising string representation is not invalidated, so * storage is lost if this has not been taken care of. * * Effect * * The string representation of 'listPtr' is set to the resulting string. * This string will be empty if the list has no elements. It is assumed * that the list internal representation is not NULL. * *---------------------------------------------------------------------- */ static void UpdateStringOfList( Tcl_Obj *listPtr) /* List object with string rep to update. */ |
︙ | ︙ |
Changes to generic/tclObj.c.
︙ | ︙ | |||
2440 2441 2442 2443 2444 2445 2446 | } /* *---------------------------------------------------------------------- * * Tcl_GetIntFromObj -- * | | < < < | > | | > > > | | | | | > > | | | 2440 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 | } /* *---------------------------------------------------------------------- * * Tcl_GetIntFromObj -- * * Retrieve the integer value of 'objPtr'. * * Value * * TCL_OK * * Success. * * TCL_ERROR * * An error occurred during conversion or the integral value can not * be represented as an integer (it might be too large). An error * message is left in the interpreter's result if 'interp' is not * NULL. * * Effect * * 'objPtr' is converted to an integer if necessary if it is not one * already. The conversion frees any previously-existing internal * representation. * *---------------------------------------------------------------------- */ int Tcl_GetIntFromObj( Tcl_Interp *interp, /* Used for error reporting if not NULL. */ |
︙ | ︙ |
Changes to generic/tclProc.c.
︙ | ︙ | |||
380 381 382 383 384 385 386 | Namespace *nsPtr, /* Namespace containing this proc. */ CONST char *procName, /* Unqualified name of this proc. */ Tcl_Obj *argsPtr, /* Description of arguments. */ Tcl_Obj *bodyPtr, /* Command body. */ Proc **procPtrPtr) /* Returns: pointer to proc data. */ { Interp *iPtr = (Interp *) interp; | < | < | | 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | Namespace *nsPtr, /* Namespace containing this proc. */ CONST char *procName, /* Unqualified name of this proc. */ Tcl_Obj *argsPtr, /* Description of arguments. */ Tcl_Obj *bodyPtr, /* Command body. */ Proc **procPtrPtr) /* Returns: pointer to proc data. */ { Interp *iPtr = (Interp *) interp; register Proc *procPtr; int i, result, numArgs; register CompiledLocal *localPtr = NULL; Tcl_Obj **argArray; int precompiled = 0; if (bodyPtr->typePtr == &tclProcBodyType) { /* * Because the body is a TclProProcBody, the actual body is already * compiled, and it is not shared with anyone else, so it's OK not to * unshare it (as a matter of fact, it is bad to unshare it, because |
︙ | ︙ | |||
423 424 425 426 427 428 429 | * means that the same code can not be shared by two procedures that * have a different number of arguments, even if their bodies are * identical. Note that we don't use Tcl_DuplicateObj since we would * not want any bytecode internal representation. */ if (Tcl_IsShared(bodyPtr)) { | > > | | | 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 | * means that the same code can not be shared by two procedures that * have a different number of arguments, even if their bodies are * identical. Note that we don't use Tcl_DuplicateObj since we would * not want any bytecode internal representation. */ if (Tcl_IsShared(bodyPtr)) { const char *bytes; int length; Tcl_Obj *sharedBodyPtr = bodyPtr; bytes = TclGetStringFromObj(bodyPtr, &length); bodyPtr = Tcl_NewStringObj(bytes, length); /* * TIP #280. * Ensure that the continuation line data for the original body is * not lost and applies to the new body as well. */ TclContinuationsCopy(bodyPtr, sharedBodyPtr); } /* * Create and initialize a Proc structure for the procedure. We * increment the ref count of the procedure's body object since there * will be a reference to it in the Proc structure. */ |
︙ | ︙ | |||
460 461 462 463 464 465 466 | } /* * Break up the argument list into argument specifiers, then process each * argument specifier. If the body is precompiled, processing is limited * to checking that the parsed argument is consistent with the one stored * in the Proc. | < < < | > | | | < | | | > > | < > | | < < < < | < | > | | < < < < < | | < | | | > | | | < > < > | < | | > > | | > | | > > | < < > | < < | < | | < < < | < | < < < | 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 491 492 493 494 495 496 497 498 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 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 | } /* * Break up the argument list into argument specifiers, then process each * argument specifier. If the body is precompiled, processing is limited * to checking that the parsed argument is consistent with the one stored * in the Proc. */ result = Tcl_ListObjGetElements(interp , argsPtr ,&numArgs ,&argArray); if (result != TCL_OK) { goto procError; } if (precompiled) { if (numArgs > procPtr->numArgs) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "procedure \"%s\": arg list contains %d entries, " "precompiled header expects %d", procName, numArgs, procPtr->numArgs)); goto procError; } localPtr = procPtr->firstLocalPtr; } else { procPtr->numArgs = numArgs; procPtr->numCompiledLocals = numArgs; } for (i = 0; i < numArgs; i++) { const char *argname, *argnamei, *argnamelast; int fieldCount, nameLength; Tcl_Obj **fieldValues; /* * Now divide the specifier up into name and default. */ result = Tcl_ListObjGetElements(interp, argArray[i], &fieldCount, &fieldValues); if (result != TCL_OK) { goto procError; } if (fieldCount > 2) { Tcl_Obj *errorObj = Tcl_NewStringObj( "too many fields in argument specifier \"", -1); Tcl_AppendObjToObj(errorObj, argArray[i]); Tcl_AppendToObj(errorObj, "\"", -1); Tcl_SetObjResult(interp, errorObj); goto procError; } if ((fieldCount == 0) || (fieldValues[0]->length == 0)) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "argument with no name", -1)); goto procError; } argname = Tcl_GetStringFromObj(fieldValues[0], &nameLength); /* * Check that the formal parameter name is a scalar. */ argnamei = argname; argnamelast = Tcl_UtfPrev(argname + nameLength, argname); while (argnamei < argnamelast) { if (*argnamei == '(') { if (*argnamelast == ')') { /* We have an array element. */ Tcl_SetObjResult(interp, Tcl_ObjPrintf( "formal parameter \"%s\" is an array element", Tcl_GetString(fieldValues[0]))); goto procError; } } else if (*argnamei == ':' && *(argnamei+1) == ':') { Tcl_Obj *errorObj = Tcl_NewStringObj( "formal parameter \"", -1); Tcl_AppendObjToObj(errorObj, fieldValues[0]); Tcl_AppendToObj(errorObj, "\" is not a simple name", -1); Tcl_SetObjResult(interp, errorObj); goto procError; } argnamei = Tcl_UtfNext(argnamei); } if (precompiled) { /* * Compare the parsed argument with the stored one. Note that the * only flag value that makes sense at this point is VAR_ARGUMENT * (its value was kept the same as pre VarReform to simplify * tbcload's processing of older byetcodes). * * The only other flag vlaue that is important to retrieve from * precompiled procs is VAR_TEMPORARY (also unchanged). It is * needed later when retrieving the variable names. */ 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)) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "procedure \"%s\": formal parameter %d is " "inconsistent with precompiled body", procName, i)); goto procError; } /* * Compare the default value if any. */ if (localPtr->defValuePtr != NULL) { int tmpLength, valueLength; const char *tmpPtr = TclGetStringFromObj(localPtr->defValuePtr, &tmpLength); const char *value = TclGetStringFromObj(fieldValues[1], &valueLength); if ((valueLength != tmpLength) || memcmp(value, tmpPtr, tmpLength) != 0 ) { Tcl_Obj *errorObj = Tcl_ObjPrintf( "procedure \"%s\": formal parameter \"", procName); Tcl_AppendObjToObj(errorObj, fieldValues[0]); Tcl_AppendToObj(errorObj, "\" has " "default value inconsistent with precompiled body", -1); Tcl_SetObjResult(interp, errorObj); goto procError; } } if ((i == numArgs - 1) && (localPtr->nameLength == 4) && (localPtr->name[0] == 'a') && (strcmp(localPtr->name, "args") == 0)) { localPtr->flags |= VAR_IS_ARGS; } localPtr = localPtr->nextPtr; } else { /* * Allocate an entry in the runtime procedure frame's array of * local variables for the argument. */ localPtr = (CompiledLocal *)ckalloc(TclOffset(CompiledLocal, name) + fieldValues[0]->length +1); if (procPtr->firstLocalPtr == NULL) { procPtr->firstLocalPtr = procPtr->lastLocalPtr = localPtr; } else { procPtr->lastLocalPtr->nextPtr = localPtr; procPtr->lastLocalPtr = localPtr; } localPtr->nextPtr = NULL; localPtr->nameLength = nameLength; localPtr->frameIndex = i; localPtr->flags = VAR_ARGUMENT; localPtr->resolveInfo = NULL; if (fieldCount == 2) { localPtr->defValuePtr = fieldValues[1]; Tcl_IncrRefCount(localPtr->defValuePtr); } else { localPtr->defValuePtr = NULL; } memcpy(localPtr->name, argname, fieldValues[0]->length + 1); if ((i == numArgs - 1) && (localPtr->nameLength == 4) && (localPtr->name[0] == 'a') && (memcmp(localPtr->name, "args", 4) == 0)) { localPtr->flags |= VAR_IS_ARGS; } } } *procPtrPtr = procPtr; return TCL_OK; procError: if (precompiled) { procPtr->refCount--; } else { Tcl_DecrRefCount(bodyPtr); while (procPtr->firstLocalPtr != NULL) { localPtr = procPtr->firstLocalPtr; procPtr->firstLocalPtr = localPtr->nextPtr; if (localPtr->defValuePtr != NULL) { Tcl_DecrRefCount(localPtr->defValuePtr); } ckfree((char *) localPtr); } ckfree((char *) procPtr); } return TCL_ERROR; } /* *---------------------------------------------------------------------- * * TclGetFrame -- |
︙ | ︙ |
Changes to generic/tclUtil.c.
︙ | ︙ | |||
3373 3374 3375 3376 3377 3378 3379 | } /* *---------------------------------------------------------------------- * * TclGetIntForIndex -- * | | | | | | < > > | < > > > | | > | | > | | | | 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 3399 3400 3401 3402 3403 3404 3405 3406 3407 | } /* *---------------------------------------------------------------------- * * TclGetIntForIndex -- * * Provides an integer corresponding to the list index held in a Tcl * object. The string value 'objPtr' is expected have the format * integer([+-]integer)? or end([+-]integer)?. * * Value * TCL_OK * * The index is stored at the address given by by 'indexPtr'. If * 'objPtr' has the value "end", the value stored is 'endValue'. * * TCL_ERROR * * The value of 'objPtr' does not have one of the expected formats. If * 'interp' is non-NULL, an error message is left in the interpreter's * result object. * * Effect * * The object referenced by 'objPtr' is converted, as needed, to an * integer, wide integer, or end-based-index object. * *---------------------------------------------------------------------- */ int TclGetIntForIndex( Tcl_Interp *interp, /* Interpreter to use for error reporting. If * NULL, then no error message is left after |
︙ | ︙ |
Changes to tests/var.test.
︙ | ︙ | |||
188 189 190 191 192 193 194 195 196 197 198 199 200 201 | namespace delete [namespace current] set result } } {0 2 1 {can't set "foo": upvar refers to element in deleted array}} test var-1.19 {TclLookupVar, right error message when parsing variable name} { list [catch {[format set] thisvar(doesntexist)} msg] $msg } {1 {can't read "thisvar(doesntexist)": no such variable}} test var-2.1 {Tcl_LappendObjCmd, create var if new} { catch {unset x} lappend x 1 2 } {1 2} test var-3.1 {MakeUpvar, TCL_NAMESPACE_ONLY not specified for other var} { | > > > > > > > > > > > > > > > > > > > > > > | 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 221 222 223 | namespace delete [namespace current] set result } } {0 2 1 {can't set "foo": upvar refers to element in deleted array}} test var-1.19 {TclLookupVar, right error message when parsing variable name} { list [catch {[format set] thisvar(doesntexist)} msg] $msg } {1 {can't read "thisvar(doesntexist)": no such variable}} test var-1.20 {TclLookupVar, regression on utf-8 variable names} -setup { proc p [list \u20ac \xe4] {info vars} } -body { # test variable with non-ascii name is available (euro and a-uml chars here): list \ [p 1 2] \ [apply [list [list \u20ac \xe4] {info vars}] 1 2] \ [apply [list [list [list \u20ac \u20ac] [list \xe4 \xe4]] {info vars}]] \ } -cleanup { rename p {} } -result [lrepeat 3 [list \u20ac \xe4]] test var-1.21 {TclLookupVar, regression on utf-8 variable names} -setup { proc p [list [list \u20ac v\u20ac] [list \xe4 v\xe4]] {list [set \u20ac] [set \xe4]} } -body { # test variable with non-ascii name (and default) is resolvable (euro and a-uml chars here): list \ [p] \ [apply [list [list \u20ac \xe4] {list [set \u20ac] [set \xe4]}] v\u20ac v\xe4] \ [apply [list [list [list \u20ac v\u20ac] [list \xe4 v\xe4]] {list [set \u20ac] [set \xe4]}]] \ } -cleanup { rename p {} } -result [lrepeat 3 [list v\u20ac v\xe4]] test var-2.1 {Tcl_LappendObjCmd, create var if new} { catch {unset x} lappend x 1 2 } {1 2} test var-3.1 {MakeUpvar, TCL_NAMESPACE_ONLY not specified for other var} { |
︙ | ︙ |