Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Difference From 0ca94b41a13ea375 To e722c70aad11a12a
2017-05-05
| ||
22:57 | TIP#457: Remove -varname, add level for -upvar check-in: 824ce85c80 user: mlafon tags: tip-457 | |
2017-04-23
| ||
20:46 | TIP#457: Update proc and info documentation check-in: e722c70aad user: mlafon tags: tip-457 | |
2017-04-20
| ||
22:01 | TIP#457: Fix warnings in InfoArgSpecCmd check-in: 68a6d74898 user: mlafon tags: tip-457 | |
10:13 | Entry for text.n into exclude_refs_map inserted. check-in: 9b324dcab5 user: gcramer tags: trunk | |
06:15 | merge trunk check-in: 78f8e94175 user: jan.nijtmans tags: tip-312 | |
2017-04-18
| ||
21:09 | merge trunk check-in: d54a7e08cc user: mlafon tags: tip-457 | |
19:02 | merge core-8-6-branch check-in: 0ca94b41a1 user: jan.nijtmans tags: trunk | |
19:01 | Fix [bc432269]: http fails in a safe interpreter check-in: 4b43637b77 user: jan.nijtmans tags: core-8-6-branch | |
2017-04-17
| ||
12:05 | Repair revised tests that failed. check-in: 467717ad27 user: dgp tags: trunk | |
Changes to doc/info.n.
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | .TP \fBinfo args \fIprocname\fR . Returns a list containing the names of the arguments to procedure \fIprocname\fR, in order. \fIProcname\fR must be the name of a Tcl command procedure. .TP \fBinfo body \fIprocname\fR . Returns the body of procedure \fIprocname\fR. \fIProcname\fR must be the name of a Tcl command procedure. .TP \fBinfo class\fI subcommand class\fR ?\fIarg ...\fR .VS 8.6 | > > > > > > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | .TP \fBinfo args \fIprocname\fR . Returns a list containing the names of the arguments to procedure \fIprocname\fR, in order. \fIProcname\fR must be the name of a Tcl command procedure. .TP \fBinfo argspec ?\fIarg ...\fR . Returns information about the arguments specification of Tcl-pure procedures, lambda or class methods. The \fIsubcommand\fRs are described in \fBARGSPEC INTROSPECTION\fR below. .TP \fBinfo body \fIprocname\fR . Returns the body of procedure \fIprocname\fR. \fIProcname\fR must be the name of a Tcl command procedure. .TP \fBinfo class\fI subcommand class\fR ?\fIarg ...\fR .VS 8.6 |
︙ | ︙ | |||
394 395 396 397 398 399 400 401 402 403 404 405 406 407 | the resulting list of variable names has each matching namespace variable qualified with the name of its namespace. Note that a currently-visible variable may not yet .QW exist if it has not been set (e.g. a variable declared but not set by \fBvariable\fR). .SS "CLASS INTROSPECTION" .VS 8.6 .PP The following \fIsubcommand\fR values are supported by \fBinfo class\fR: .VE 8.6 .TP \fBinfo class call\fI class method\fR | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 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 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 | the resulting list of variable names has each matching namespace variable qualified with the name of its namespace. Note that a currently-visible variable may not yet .QW exist if it has not been set (e.g. a variable declared but not set by \fBvariable\fR). .SS "ARGSPEC INTROSPECTION" .VS .PP The following \fIsubcommand\fR values are supported by \fBinfo argspec\fR: .VE .TP \fBinfo argspec constructor \fIclassName \fR?\fIarg\fR? .VS If \fIarg\fR is specified, returns a list containing the argument specifiers which describe the argument \fIarg\fR of the constructor of the class \fIclassName\fR. If \fIarg\fR is not specified, returns a list containing the argument specifiers list of all arguments of the constructor of the class \fIclassName\fR. .TP \fBinfo argspec lambda \fIlambdaTerm \fR?\fIarg\fR? .VS If \fIarg\fR is specified, returns a list containing the argument specifiers which describe the argument \fIarg\fR of the lambda \fIlambdaTerm\fR. If \fIarg\fR is not specified, returns a list containing the argument specifiers list of all arguments of the lambda \fIlambdaTerm\fR. .TP \fBinfo argspec method \fIclassName methodName \fR?\fIarg\fR? .VS If \fIarg\fR is specified, returns a list containing the argument specifiers which describe the argument \fIarg\fR of the method \fImethodName\fR of the class \fIclassName\fR. If \fIarg\fR is not specified, returns a list containing the argument specifiers list of all arguments of the method \fImethodName\fR of the class \fIclassName\fR. .TP \fBinfo argspec objmethod \fIobject methodName \fR?\fIarg\fR? .VS If \fIarg\fR is specified, returns a list containing the argument specifiers which describe the argument \fIarg\fR of the method \fImethodName\fR of the object \fIobject\fR. If \fIarg\fR is not specified, returns a list containing the argument specifiers list of all arguments of the method \fImethodName\fR of the object \fIobject\fR. .TP \fBinfo argspec proc \fIprocName \fR?\fIarg\fR? .VS If \fIarg\fR is specified, returns a list containing the argument specifiers which describe the argument \fIarg\fR of the procedure \fIprocName\fR. If \fIarg\fR is not specified, returns a list containing the argument specifiers list of all arguments of the procedure \fIprocName\fR. .TP \fBinfo argspec specifiers .VS Returns a list containing the argument specifiers supported by the current interpreter. .PP Note that the returned argument specifiers in all subcommands, except \fIspecifiers\fR, may not be exactly the same as the ones used during the procedure creation, but they are strictly equivalents. .VE .PP .CS proc p {{a -name A -name arg} {b -required 1 -default def}} {} info argspec proc p a \fI\(-> returns {a -name {A arg}}\fR info argspec proc p \fI\(-> returns {{a -name {A arg}} b}\fR .CE .PP In the example above, \fI-name A -name arg\fR and \fI-name {A arg}\fR are equivalent specifiers. Using \fI-required 1\fR and a default value on a non-keyword argument is equivalent to using no specifiers, as the default value is ignored when \fI-required 1\fR is used and will also force the argument to be specified. .VE .SS "CLASS INTROSPECTION" .VS 8.6 .PP The following \fIsubcommand\fR values are supported by \fBinfo class\fR: .VE 8.6 .TP \fBinfo class call\fI class method\fR |
︙ | ︙ |
Changes to doc/proc.n.
︙ | ︙ | |||
26 27 28 29 30 31 32 | and the new procedure is created in the current namespace. If \fIname\fR includes any namespace qualifiers, the procedure is created in the specified namespace. \fIArgs\fR specifies the formal arguments to the procedure. It consists of a list, possibly empty, each of whose elements specifies one argument. Each argument specifier is also a list with either | > | | > > > > | > > > > | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 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 | and the new procedure is created in the current namespace. If \fIname\fR includes any namespace qualifiers, the procedure is created in the specified namespace. \fIArgs\fR specifies the formal arguments to the procedure. It consists of a list, possibly empty, each of whose elements specifies one argument. Each argument specifier is also a list with either one, two fields or an odd number of fields. If there is only a single field in the specifier then it is the name of the argument; if there are two fields, then the first is the argument name and the second is its default value; if there are an odd number of fields, then the first is the argument name and the remaining fields are extended argument specifiers. See \fBEXTENDED ARGUMENT SPECIFIERS\fR below for details on allowed specifiers. Arguments with default values that are followed by non-defaulted arguments become required arguments; enough actual arguments must be supplied to allow all arguments up to and including the last required formal argument. .PP When \fIname\fR is invoked a local variable will be created for each of the formal arguments to the procedure; its value will be the value of corresponding argument in the invoking command or the argument's default value. Actual positional arguments are assigned to formal arguments strictly in order. Arguments with default values need not be specified in a procedure invocation. However, there must be enough actual arguments for all the formal arguments that do not have defaults, and there must not be any extra actual arguments. Arguments with default values that are followed by non-defaulted arguments become de-facto required arguments, though this may change in a future version of Tcl; portable code should ensure that all optional arguments come after all required arguments. .PP Named arguments, defined with the \fB-name\fR or \fB-switch\fR extended argument specifiers have a specific handling detailed in \fBNAMED ARGUMENTS HANDLING\fR below. .PP There is an other special case to permit procedures with variable numbers of arguments. If the last formal argument has the name .QW \fBargs\fR , then a call to the procedure may contain more actual arguments than the procedure has formal arguments. In this case, all of the actual arguments starting at the one that would be assigned to \fBargs\fR are combined into a list (as if the \fBlist\fR command had been used); this combined value is assigned to the local variable \fBargs\fR. .PP When \fIbody\fR is being executed, variable names normally refer to local variables, which are created automatically when referenced and deleted when the procedure returns. One local variable is automatically created for each of the procedure's arguments. Other variables can only be accessed by invoking one of the \fBglobal\fR, \fBvariable\fR, \fBupvar\fR or \fBnamespace upvar\fR commands or by using the \fB-upvar 1\fR extended argument specifier. The current namespace when \fIbody\fR is executed will be the namespace that the procedure's name exists in, which will be the namespace that it was created in unless it has been changed with \fBrename\fR. '\" We may change this! It makes [variable] unstable when renamed and is '\" frankly pretty crazy, but doing it right is harder than it looks. .PP The \fBproc\fR command returns an empty string. When a procedure is invoked, the procedure's return value is the value specified in a \fBreturn\fR command. If the procedure does not execute an explicit \fBreturn\fR, then its return value is the value of the last command executed in the procedure's body. If an error occurs while executing the procedure body, then the procedure-as-a-whole will return that same error. .SS "EXTENDED ARGUMENT SPECIFIERS" .VS .PP The following extended specifiers can be used to define an argument: .VE .TP \fB-default \fIvalue\fR .VS Set \fIvalue\fR as the default value for the argument. It is ignored if \fB-required 1\fR is also used. .TP \fB-name \fInames\fR .VS Defines the argument to be a named argument. \fINames\fR can be string or a list of strings, each string being added as a potential name for this argument. If \fB-name\fR is used several times for the same argument, all strings are added as potential names. See \fBNAMED ARGUMENTS HANDLING\fR below for details on named arguments. .TP \fB-required \fIbool\fR .VS Defines that the argument is required or not to be set by the caller. If \fIbool\fR is true, it is required to be set and any default value is ignored. It is the default handling for non-named argument without a default value. If \fIbool\fR is false, it is not required to be set and the related argument will be left unset if there is no default value. It is the default handling for named argument. .TP \fB-switch \fIswitches\fR .VS Defines the argument to be a flag/switch named argument. \fISwitches\fR is a list of potential switches for this argument. Each switch is defined either as a single string or as a list of a string and a value. When the switch is defined as a single string, the string is used as both the switch name and the switch value. When the switch is defined as a list of two entries, the first one is the switch name and the second one is the switch value. If \fB-switch\fR is used several times for the same argument, all switches are added as potential switches. On call-site, the related switch value will be set on the argument if one of the switch names is used. See \fBNAMED ARGUMENTS HANDLING\fR below for details on named arguments. .TP \fB-upvar \fIbool\fR .VS If \fIbool\fR is set to true, this will cause the related variable, rather than taking the parameter value, to become an alias to the variable in caller's scope corresponding to the parameter value. This specifier is incompatible with the \fB-switch\fR specifier. .TP \fB-varname \fIvarname\fR .VS Defines a new variable named \fIvarname\fR which will be added in the procedure with the original value of the parameter. This is mostly used with \fB-upvar 1\fR to access the name of the linked variable. .VE .SS "NAMED ARGUMENTS HANDLING" .VS .PP Named argument are arguments defined using the \fB-name\fR or \fB-switch\fR extended argument specifiers. They have a special handling on call-site. All contiguous named arguments, called named group, are handled together, they are not required to be declared in order, can be omited or declared multiple times. The handling of a named group is started when previous formal arguments have been assigned. Each named parameter uses a string starting with a dash character, followed by the name of the related argument. If it is not a switch argument, it is followed by the value to assign to the formal argument. The handling of a named group is ended if the next parameter is a multiple-elements list, does not start with a dash or is the special \fB--\fR keyword. Remaining parameters, except the \fB--\fR keyword if used, are then assigned to following positional arguments using the default handling. .VE .SH EXAMPLES .PP This is a procedure that takes two arguments and prints both their sum and their product. It also returns the string .QW OK to the caller as an explicit result. .PP |
︙ | ︙ | |||
105 106 107 108 109 110 111 | \fBproc\fR printArguments args { foreach arg $args { puts $arg } } .CE .PP | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | \fBproc\fR printArguments args { foreach arg $args { puts $arg } } .CE .PP These procedures are a bit like the \fBincr\fR command, except they multiply the contents of the named variable by the value, which defaults to \fB2\fR. The second procedure uses extended argument specifiers and especially the \fB-upvar\fR specifier: .PP .CS \fBproc\fR mult {varName {multiplier 2}} { upvar 1 $varName var set var [expr {$var * $multiplier}] } \fBproc\fR mult {{var -upvar 1} {multiplier -default 2}} { set var [expr {$var * $multiplier}] } .CE .PP This is a procedure that uses named argument for the first two arguments. \fILevel\fR defaults to \fB1\fR and can be defined using either \fB-level \fIlevelValue\fR or one of the switches \fB-debug\fR (\fB0\fR) or \fB-error\fR (\fB3\fR). \fITime\fR can be defined using either \fB-time \fItimeValue\fR or \fB-timestamp \fItimeValue\fR. If none is used, \fItime\fR will be left unset in the procedure. .PP .CS \fBproc\fR log { {level -name level -switch {{debug 0} {error 3}} -default 1} {time -name {time timestamp}} {message} } { if {![info exists time]} {set time [clock seconds]} array set levels {0 DEBUG 1 INFO 2 WARN 3 ERROR} puts "[clock format $time] : $levels($level) : $message" } % log -level 2 "Warning..." Sun Apr 23 20:29:41 UTC 2017 : WARN : Warning... % log -timestamp 946684800 -debug -- -Y2K- Sat Jan 01 00:00:00 UTC 2000 : DEBUG : -Y2K- .CE .SH "SEE ALSO" info(n), unknown(n) .SH KEYWORDS argument, procedure '\" Local Variables: '\" mode: nroff '\" End: |
Changes to generic/tclCmdIL.c.
︙ | ︙ | |||
15 16 17 18 19 20 21 22 23 24 25 26 27 28 | * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tclInt.h" #include "tclRegexp.h" /* * During execution of the "lsort" command, structures of the following type * are used to arrange the objects being sorted into a collection of linked * lists. */ | > > | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tclInt.h" #include "tclRegexp.h" #include "tclCompile.h" #include "tclOOInt.h" /* * During execution of the "lsort" command, structures of the following type * are used to arrange the objects being sorted into a collection of linked * lists. */ |
︙ | ︙ | |||
104 105 106 107 108 109 110 111 112 113 114 115 116 117 | * Forward declarations for procedures defined in this file: */ static int DictionaryCompare(const char *left, const char *right); static Tcl_NRPostProc IfConditionCallback; static int InfoArgsCmd(ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int InfoBodyCmd(ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int InfoCmdCountCmd(ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int InfoCommandsCmd(ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int InfoCompleteCmd(ClientData dummy, Tcl_Interp *interp, | > > | 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | * Forward declarations for procedures defined in this file: */ static int DictionaryCompare(const char *left, const char *right); static Tcl_NRPostProc IfConditionCallback; static int InfoArgsCmd(ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int InfoArgSpecCmd(ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int InfoBodyCmd(ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int InfoCmdCountCmd(ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int InfoCommandsCmd(ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static int InfoCompleteCmd(ClientData dummy, Tcl_Interp *interp, |
︙ | ︙ | |||
157 158 159 160 161 162 163 164 165 166 167 168 169 170 | /* * Array of values describing how to implement each standard subcommand of the * "info" command. */ static const EnsembleImplMap defaultInfoMap[] = { {"args", InfoArgsCmd, TclCompileBasic1ArgCmd, NULL, NULL, 0}, {"body", InfoBodyCmd, TclCompileBasic1ArgCmd, NULL, NULL, 0}, {"cmdcount", InfoCmdCountCmd, TclCompileBasic0ArgCmd, NULL, NULL, 0}, {"commands", InfoCommandsCmd, TclCompileInfoCommandsCmd, NULL, NULL, 0}, {"complete", InfoCompleteCmd, TclCompileBasic1ArgCmd, NULL, NULL, 0}, {"coroutine", TclInfoCoroutineCmd, TclCompileInfoCoroutineCmd, NULL, NULL, 0}, {"default", InfoDefaultCmd, TclCompileBasic3ArgCmd, NULL, NULL, 0}, {"errorstack", InfoErrorStackCmd, TclCompileBasic0Or1ArgCmd, NULL, NULL, 0}, | > | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | /* * Array of values describing how to implement each standard subcommand of the * "info" command. */ static const EnsembleImplMap defaultInfoMap[] = { {"args", InfoArgsCmd, TclCompileBasic1ArgCmd, NULL, NULL, 0}, {"argspec", InfoArgSpecCmd, TclCompileBasic2ArgCmd, NULL, NULL, 0}, {"body", InfoBodyCmd, TclCompileBasic1ArgCmd, NULL, NULL, 0}, {"cmdcount", InfoCmdCountCmd, TclCompileBasic0ArgCmd, NULL, NULL, 0}, {"commands", InfoCommandsCmd, TclCompileInfoCommandsCmd, NULL, NULL, 0}, {"complete", InfoCompleteCmd, TclCompileBasic1ArgCmd, NULL, NULL, 0}, {"coroutine", TclInfoCoroutineCmd, TclCompileInfoCoroutineCmd, NULL, NULL, 0}, {"default", InfoDefaultCmd, TclCompileBasic3ArgCmd, NULL, NULL, 0}, {"errorstack", InfoErrorStackCmd, TclCompileBasic0Or1ArgCmd, NULL, NULL, 0}, |
︙ | ︙ | |||
510 511 512 513 514 515 516 517 518 519 520 521 522 523 | Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewStringObj(localPtr->name, -1)); } } Tcl_SetObjResult(interp, listObjPtr); return TCL_OK; } /* *---------------------------------------------------------------------- * * InfoBodyCmd -- * * Called to implement the "info body" command that returns the body for | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 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 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 714 715 716 717 718 719 720 721 722 723 724 725 726 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 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 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 | Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewStringObj(localPtr->name, -1)); } } Tcl_SetObjResult(interp, listObjPtr); return TCL_OK; } /* *---------------------------------------------------------------------- * * InfoArgSpecCmd -- * * Called to implement the "info argspec" command that returns the * extendend argument specification for a procedure. * Handles the following syntaxes: * * info argspec proc procName ?arg? * info argspec lambda lambdaTerm ?arg? * info argspec constructor className ?arg? * info argspec method className methodName ?arg? * info argspec objmethod object methodName ?arg? * info argspec specifiers * * Results: * Returns TCL_OK if successful and TCL_ERROR if there is an error. * * Side effects: * Returns a result in the interpreter's result object. If there is an * error, the result is an error message. * *---------------------------------------------------------------------- */ static int InfoArgSpecCmd( ClientData dummy, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { static const char *const types[] = { "proc", "lambda", "constructor", "method", "objmethod", "specifiers", NULL, }; static const char *const specifiers[] = { /* supported specifiers, must be ordered */ "-default", "-name", "-required", "-switch", "-upvar", "-varname", NULL }; enum Types { ARGSPEC_PROC, ARGSPEC_LAMBDA, ARGSPEC_CONSTRUCTOR, ARGSPEC_METHOD, ARGSPEC_OBJMETHOD, ARGSPEC_SPECIFIERS }; register Interp *iPtr = (Interp *) interp; const char *procName = NULL, *argName = NULL; Proc *procPtr = NULL; CompiledLocal *localPtr; Tcl_Obj *listObjPtr; Object *oPtr; Method *methodPtr; Tcl_HashEntry *hPtr; int idx, result; if (objc < 2) { Tcl_WrongNumArgs(interp, 1, objv, "type ..."); return TCL_ERROR; } if (Tcl_GetIndexFromObj(interp, objv[1], types, "type", 0, &idx)!=TCL_OK) { return TCL_ERROR; } switch ((enum Types) idx) { case ARGSPEC_PROC: if (objc < 3 || objc > 4) { Tcl_WrongNumArgs(interp, 1, objv, "proc procname ?arg?"); return TCL_ERROR; } procName = TclGetString(objv[2]); procPtr = TclFindProc(iPtr, procName); if (procPtr == NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "\"%s\" isn't a procedure", procName)); Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "PROCEDURE", procName, NULL); return TCL_ERROR; } argName = (objc == 4) ? TclGetString(objv[3]) : NULL; break; case ARGSPEC_LAMBDA: if (objc < 3 || objc > 4) { Tcl_WrongNumArgs(interp, 1, objv, "lambda lambdaTerm ?arg?"); return TCL_ERROR; } if (objv[2]->typePtr == &tclLambdaType) { procPtr = objv[2]->internalRep.twoPtrValue.ptr1; } if (procPtr == NULL || procPtr->iPtr != (Interp *) interp) { result = tclLambdaType.setFromAnyProc(interp, objv[2]); if (result != TCL_OK) { return result; } procPtr = objv[2]->internalRep.twoPtrValue.ptr1; } procName = "lambdaTerm"; argName = (objc == 4) ? TclGetString(objv[3]) : NULL; break; case ARGSPEC_CONSTRUCTOR: if (objc < 3 || objc > 4) { Tcl_WrongNumArgs(interp, 1, objv, "constructor className ?arg?"); return TCL_ERROR; } oPtr = (Object *) Tcl_GetObjectFromObj(interp, objv[2]); if (oPtr == NULL) { return TCL_ERROR; } if (oPtr->classPtr == NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "\"%s\" is not a class", TclGetString(objv[2]))); Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "CLASS", TclGetString(objv[2]), NULL); return TCL_ERROR; } methodPtr = oPtr->classPtr->constructorPtr; if (methodPtr == NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "\"%s\" has no defined constructor", TclGetString(objv[2]))); Tcl_SetErrorCode(interp, "TCL", "OPERATION", "ARGSPEC", "CONSRUCTOR", NULL); return TCL_ERROR; } procPtr = TclOOGetProcFromMethod(methodPtr); if (procPtr == NULL) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "body not available for this kind of constructor", -1)); Tcl_SetErrorCode(interp, "TCL", "OPERATION", "ARGSPEC", "METHODTYPE", NULL); return TCL_ERROR; } procName = "constructor"; argName = (objc == 4) ? TclGetString(objv[3]) : NULL; break; case ARGSPEC_METHOD: if (objc < 4 || objc > 5) { Tcl_WrongNumArgs(interp, 1, objv, "method className methodName ?arg?"); return TCL_ERROR; } oPtr = (Object *) Tcl_GetObjectFromObj(interp, objv[2]); if (oPtr == NULL) { return TCL_ERROR; } if (oPtr->classPtr == NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "\"%s\" is not a class", TclGetString(objv[2]))); Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "CLASS", TclGetString(objv[2]), NULL); return TCL_ERROR; } procName = TclGetString(objv[3]); hPtr = Tcl_FindHashEntry(&oPtr->classPtr->classMethods, (char *) objv[3]); if (hPtr == NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "unknown method \"%s\"", procName)); Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "METHOD", TclGetString(objv[3]), NULL); return TCL_ERROR; } procPtr = TclOOGetProcFromMethod(Tcl_GetHashValue(hPtr)); if (procPtr == NULL) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "body not available for this kind of method", -1)); Tcl_SetErrorCode(interp, "TCL", "OPERATION", "ARGSPEC", "METHODTYPE", NULL); return TCL_ERROR; } argName = (objc == 5) ? TclGetString(objv[4]) : NULL; break; case ARGSPEC_OBJMETHOD: if (objc < 4 || objc > 5) { Tcl_WrongNumArgs(interp, 1, objv, "objmethod object methodName ?arg?"); return TCL_ERROR; } oPtr = (Object *) Tcl_GetObjectFromObj(interp, objv[2]); if (oPtr == NULL) { return TCL_ERROR; } if (oPtr->methodsPtr == NULL) { hPtr = NULL; } else { hPtr = Tcl_FindHashEntry(oPtr->methodsPtr, (char *) objv[3]); } procName = TclGetString(objv[3]); if (hPtr == NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "unknown method \"%s\"", procName)); Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "METHOD", TclGetString(objv[3]), NULL); return TCL_ERROR; } procPtr = TclOOGetProcFromMethod(Tcl_GetHashValue(hPtr)); if (procPtr == NULL) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "body not available for this kind of method", -1)); Tcl_SetErrorCode(interp, "TCL", "OPERATION", "ARGSPEC", "METHODTYPE", NULL); return TCL_ERROR; } argName = (objc == 5) ? TclGetString(objv[4]) : NULL; break; case ARGSPEC_SPECIFIERS: listObjPtr = Tcl_NewListObj(0, NULL); for (idx = 0; specifiers[idx] != NULL; idx++) { Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewStringObj(specifiers[idx], -1)); } Tcl_SetObjResult(interp, listObjPtr); return TCL_OK; break; } if (argName == NULL) { /* info argspec ... procName */ listObjPtr = Tcl_NewListObj(0, NULL); for (localPtr = procPtr->firstLocalPtr; localPtr != NULL; localPtr = localPtr->nextPtr) { if (TclIsVarArgument(localPtr)) { Tcl_ListObjAppendElement(interp, listObjPtr, TclProcGetArgSpec(interp, localPtr, TCL_GETARGSPEC_WITH_NAME)); } } Tcl_SetObjResult(interp, listObjPtr); return TCL_OK; } /* info argspec ... procName arg */ for (localPtr = procPtr->firstLocalPtr; localPtr != NULL; localPtr = localPtr->nextPtr) { if (TclIsVarArgument(localPtr) && (strcmp(argName, localPtr->name) == 0)) { listObjPtr = TclProcGetArgSpec(interp, localPtr, 0); Tcl_SetObjResult(interp, listObjPtr); return TCL_OK; } } Tcl_SetObjResult(interp, Tcl_ObjPrintf( "%s \"%s\" doesn't have an argument \"%s\"", Tcl_GetString(objv[1]), procName, argName)); Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "ARGUMENT", argName, NULL); return TCL_ERROR; } /* *---------------------------------------------------------------------- * * InfoBodyCmd -- * * Called to implement the "info body" command that returns the body for |
︙ | ︙ |
Changes to generic/tclCompile.c.
︙ | ︙ | |||
3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 | localPtr->frameIndex = localVar; localPtr->flags = 0; if (name == NULL) { localPtr->flags |= VAR_TEMPORARY; } localPtr->defValuePtr = NULL; localPtr->resolveInfo = NULL; if (name != NULL) { memcpy(localPtr->name, name, (size_t) nameBytes); } localPtr->name[nameBytes] = '\0'; procPtr->numCompiledLocals++; } | > | 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 | localPtr->frameIndex = localVar; localPtr->flags = 0; if (name == NULL) { localPtr->flags |= VAR_TEMPORARY; } localPtr->defValuePtr = NULL; localPtr->resolveInfo = NULL; localPtr->argSpecPtr = NULL; if (name != NULL) { memcpy(localPtr->name, name, (size_t) nameBytes); } localPtr->name[nameBytes] = '\0'; procPtr->numCompiledLocals++; } |
︙ | ︙ |
Changes to generic/tclInt.h.
︙ | ︙ | |||
694 695 696 697 698 699 700 701 702 703 704 705 706 707 | * VAR_TEMPORARY - 1 if the local variable is an anonymous * temporary variable. Temporaries have a NULL * name. * VAR_RESOLVED - 1 if name resolution has been done for this * variable. * VAR_IS_ARGS 1 if this variable is the last argument and is * named "args". */ /* * FLAGS RENUMBERED: everything breaks already, make things simpler. * * IMPORTANT: skip the values 0x10, 0x20, 0x40, 0x800 corresponding to * TCL_TRACE_(READS/WRITES/UNSETS/ARRAY): makes code simpler in tclTrace.c | > > > > > > > > > > > > > > | 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 | * VAR_TEMPORARY - 1 if the local variable is an anonymous * temporary variable. Temporaries have a NULL * name. * VAR_RESOLVED - 1 if name resolution has been done for this * variable. * VAR_IS_ARGS 1 if this variable is the last argument and is * named "args". * VAR_NAMED_GROUP 1 means that this argument is part of a named * group defined using an extended argument * specification. * VAR_ARG_UPVAR 1 means that this argument has been defined * using the -upvar extended arg specification. * VAR_ARG_HAS_VARNAME 1 means that this variable has been specified * with the -varname specifier and that a * dedicated variable has been created to store * the original value. * VAR_ARG_IS_VARNAME 1 means that this variable has been added to * store the name of a passed-by-name argument, * defined using an extended arg specification. * VAR_ARG_OPTIONAL 1 means that this argument is not required to * be specified on call-site. */ /* * FLAGS RENUMBERED: everything breaks already, make things simpler. * * IMPORTANT: skip the values 0x10, 0x20, 0x40, 0x800 corresponding to * TCL_TRACE_(READS/WRITES/UNSETS/ARRAY): makes code simpler in tclTrace.c |
︙ | ︙ | |||
735 736 737 738 739 740 741 742 743 744 745 746 747 748 | (VAR_TRACED_READ|VAR_TRACED_WRITE|VAR_TRACED_ARRAY|VAR_TRACED_UNSET) /* Special handling on initialisation (only CompiledLocal). */ #define VAR_ARGUMENT 0x100 /* KEEP OLD VALUE! See tclProc.c */ #define VAR_TEMPORARY 0x200 /* KEEP OLD VALUE! See tclProc.c */ #define VAR_IS_ARGS 0x400 #define VAR_RESOLVED 0x8000 /* * Macros to ensure that various flag bits are set properly for variables. * The ANSI C "prototypes" for these macros are: * * MODULE_SCOPE void TclSetVarScalar(Var *varPtr); * MODULE_SCOPE void TclSetVarArray(Var *varPtr); | > > > > > | 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 | (VAR_TRACED_READ|VAR_TRACED_WRITE|VAR_TRACED_ARRAY|VAR_TRACED_UNSET) /* Special handling on initialisation (only CompiledLocal). */ #define VAR_ARGUMENT 0x100 /* KEEP OLD VALUE! See tclProc.c */ #define VAR_TEMPORARY 0x200 /* KEEP OLD VALUE! See tclProc.c */ #define VAR_IS_ARGS 0x400 #define VAR_RESOLVED 0x8000 #define VAR_NAMED_GROUP 0x10000 #define VAR_ARG_UPVAR 0x20000 #define VAR_ARG_IS_VARNAME 0x40000 #define VAR_ARG_HAS_VARNAME 0x80000 #define VAR_ARG_OPTIONAL 0x100000 /* * Macros to ensure that various flag bits are set properly for variables. * The ANSI C "prototypes" for these macros are: * * MODULE_SCOPE void TclSetVarScalar(Var *varPtr); * MODULE_SCOPE void TclSetVarArray(Var *varPtr); |
︙ | ︙ | |||
841 842 843 844 845 846 847 848 849 850 851 852 853 854 | #define TclIsVarInHash(varPtr) \ ((varPtr)->flags & VAR_IN_HASHTABLE) #define TclIsVarDeadHash(varPtr) \ ((varPtr)->flags & VAR_DEAD_HASH) #define TclGetVarNsPtr(varPtr) \ (TclIsVarInHash(varPtr) \ ? ((TclVarHashTable *) ((((VarInHash *) (varPtr))->entry.tablePtr)))->nsPtr \ : NULL) #define VarHashRefCount(varPtr) \ ((VarInHash *) (varPtr))->refCount | > > > | 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 | #define TclIsVarInHash(varPtr) \ ((varPtr)->flags & VAR_IN_HASHTABLE) #define TclIsVarDeadHash(varPtr) \ ((varPtr)->flags & VAR_DEAD_HASH) #define TclIsVarWithExtArgs(varPtr) \ ((varPtr)->flags & (VAR_NAMED_GROUP|VAR_ARG_UPVAR|VAR_ARG_HAS_VARNAME|VAR_ARG_OPTIONAL)) #define TclGetVarNsPtr(varPtr) \ (TclIsVarInHash(varPtr) \ ? ((TclVarHashTable *) ((((VarInHash *) (varPtr))->entry.tablePtr)))->nsPtr \ : NULL) #define VarHashRefCount(varPtr) \ ((VarInHash *) (varPtr))->refCount |
︙ | ︙ | |||
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | * tclProc.c, tclCompile.c, and tclExecute.c. *---------------------------------------------------------------- */ /* * Forward declaration to prevent an error when the forward reference to * Command is encountered in the Proc and ImportRef types declared below. */ struct Command; /* * The variable-length structure below describes a local variable of a * procedure that was recognized by the compiler. These variables have a name, * an element in the array of compiler-assigned local variables in the * procedure's call frame, and various other items of information. If the * local variable is a formal argument, it may also have a default value. The | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 | * tclProc.c, tclCompile.c, and tclExecute.c. *---------------------------------------------------------------- */ /* * Forward declaration to prevent an error when the forward reference to * Command is encountered in the Proc and ImportRef types declared below. * Same for CompiledLocal in the NamedGroupEntry type. */ struct Command; struct CompiledLocal; /* * The variable-length structure below describes an entry in a group of * named parameter defined together. */ typedef struct NamedGroupEntry { struct NamedGroupEntry *nextPtr; /* Next entry in the named-group, or NULL if * this is the last entry. */ int nameLength; /* The number of characters in entry's name */ int localIndex; /* Index of the related local in the array of * compiler-assigned variables in the procedure * call frame. */ Tcl_Obj *valuePtr; /* Pointer to the default value of the named * parameter, used with the -switch argument * specifier. NULL if it is related to a named * parameter created with the -name argument * specifier. */ struct CompiledLocal *localPtr; /* Pointer to the related local in the linked * list of locals for the procedure. */ char name[1]; /* Name of the entry starts here. The actual * size of this field will be large enough to * hold the name. MUST BE THE LAST FIELD IN * THE STRUCTURE! */ } NamedGroupEntry; /* * The structure below describes an extended argument specification applied * on a proc argument (see TIP#457). */ typedef struct ExtendedArgSpec { struct NamedGroupEntry *firstNamedEntryPtr; /* Pointer to the first named parameter entry * defined on the proc argument. */ struct NamedGroupEntry *lastNamedEntryPtr; /* Pointer to the last named parameter entry * defined on the proc argument. */ int varnameIndex; /* Index of the local created to store the * name of the passed-by-name argument. Set * to -1 when not used. */ Tcl_HashTable *namedHashTable; /* Pointer to the hash table created for a * fast lookup of named entry. The pointer is * only set on the first local of a named * group. */ } ExtendedArgSpec; /* * The variable-length structure below describes a local variable of a * procedure that was recognized by the compiler. These variables have a name, * an element in the array of compiler-assigned local variables in the * procedure's call frame, and various other items of information. If the * local variable is a formal argument, it may also have a default value. The |
︙ | ︙ | |||
919 920 921 922 923 924 925 | * variable's name. Used to speed up variable * 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, | > | > > > | 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 | * variable's name. Used to speed up variable * 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, * VAR_RESOLVED, VAR_NAMED_GROUP and VAR_ARG_* * make sense. */ Tcl_Obj *defValuePtr; /* Pointer to the default value of an * argument, if any. NULL if not an argument * or, if an argument, no default value. */ Tcl_ResolvedVarInfo *resolveInfo; /* Customized variable resolution info * supplied by the Tcl_ResolveCompiledVarProc * associated with a namespace. Each variable * is marked by a unique ClientData tag during * compilation, and that same tag is used to * find the variable at runtime. */ ExtendedArgSpec *argSpecPtr; /* Extended argument specification if this is * a proc argument defined using one. */ char name[1]; /* Name of the local variable starts here. If * the name is NULL, this will just be '\0'. * The actual size of this field will be large * enough to hold the name. MUST BE THE LAST * FIELD IN THE STRUCTURE! */ } CompiledLocal; |
︙ | ︙ | |||
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 | * procedure. */ Tcl_Obj *bodyPtr; /* Points to the ByteCode object for * procedure's body command. */ int numArgs; /* Number of formal parameters. */ int numCompiledLocals; /* Count of local variables recognized by the * compiler including arguments and * temporaries. */ CompiledLocal *firstLocalPtr; /* Pointer to first of the procedure's * compiler-allocated local variables, or NULL * if none. The first numArgs entries in this * list describe the procedure's formal * arguments. */ CompiledLocal *lastLocalPtr;/* Pointer to the last allocated local * variable or NULL if none. This has frame * index (numCompiledLocals-1). */ } Proc; /* * The type of functions called to process errors found during the execution * of a procedure (or lambda term or ...). */ typedef void (ProcErrorProc)(Tcl_Interp *interp, Tcl_Obj *procNameObj); | > > > > > > > > > > > | 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 1065 1066 1067 1068 1069 1070 1071 1072 1073 | * procedure. */ Tcl_Obj *bodyPtr; /* Points to the ByteCode object for * procedure's body command. */ int numArgs; /* Number of formal parameters. */ int numCompiledLocals; /* Count of local variables recognized by the * compiler including arguments and * temporaries. */ int flags; /* Various flag bits. See below. */ CompiledLocal *firstLocalPtr; /* Pointer to first of the procedure's * compiler-allocated local variables, or NULL * if none. The first numArgs entries in this * list describe the procedure's formal * arguments. */ CompiledLocal *lastLocalPtr;/* Pointer to the last allocated local * variable or NULL if none. This has frame * index (numCompiledLocals-1). */ } Proc; /* * Flag bits for procedures. * * PROC_HAS_EXT_ARG_SPEC 1 means that the procedure has at least one * argument defined using an extended argument * specification. */ #define PROC_HAS_EXT_ARG_SPEC 0x01 /* * The type of functions called to process errors found during the execution * of a procedure (or lambda term or ...). */ typedef void (ProcErrorProc)(Tcl_Interp *interp, Tcl_Obj *procNameObj); |
︙ | ︙ | |||
2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 | #define TCL_DD_CONVERSION_TYPE_MASK 0x3 /* Mask to isolate the conversion type */ #define TCL_DD_STEELE0 0x1 /* 'Steele&White' after masking */ #define TCL_DD_SHORTEST0 0x0 /* 'Shortest possible' after masking */ /* *---------------------------------------------------------------- * Procedures shared among Tcl modules but not used by the outside world: *---------------------------------------------------------------- */ MODULE_SCOPE void TclAppendBytesToByteArray(Tcl_Obj *objPtr, | > > > > > > > > > | 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 | #define TCL_DD_CONVERSION_TYPE_MASK 0x3 /* Mask to isolate the conversion type */ #define TCL_DD_STEELE0 0x1 /* 'Steele&White' after masking */ #define TCL_DD_SHORTEST0 0x0 /* 'Shortest possible' after masking */ /* Flags for TclProcGetArgSpec */ #define TCL_GETARGSPEC_WITH_NAME 0x01 /* Include arg name before specification */ #define TCL_GETARGSPEC_TRY_OLDSTYLE 0x02 /* Return argument spec using old-style * specification if there is no other options * set on argument */ /* *---------------------------------------------------------------- * Procedures shared among Tcl modules but not used by the outside world: *---------------------------------------------------------------- */ MODULE_SCOPE void TclAppendBytesToByteArray(Tcl_Obj *objPtr, |
︙ | ︙ | |||
3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 | const char *expected, const char *bytes, int numBytes, const char **endPtrPtr, int flags); MODULE_SCOPE void TclParseInit(Tcl_Interp *interp, const char *string, int numBytes, Tcl_Parse *parsePtr); MODULE_SCOPE int TclParseAllWhiteSpace(const char *src, int numBytes); MODULE_SCOPE int TclProcessReturn(Tcl_Interp *interp, int code, int level, Tcl_Obj *returnOpts); MODULE_SCOPE int TclpObjLstat(Tcl_Obj *pathPtr, Tcl_StatBuf *buf); MODULE_SCOPE Tcl_Obj * TclpTempFileName(void); MODULE_SCOPE Tcl_Obj * TclpTempFileNameForLibrary(Tcl_Interp *interp, Tcl_Obj* pathPtr); MODULE_SCOPE Tcl_Obj * TclNewFSPathObj(Tcl_Obj *dirPtr, const char *addStrRep, int len); MODULE_SCOPE int TclpDeleteFile(const void *path); MODULE_SCOPE void TclpFinalizeCondition(Tcl_Condition *condPtr); | > > | 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 | const char *expected, const char *bytes, int numBytes, const char **endPtrPtr, int flags); MODULE_SCOPE void TclParseInit(Tcl_Interp *interp, const char *string, int numBytes, Tcl_Parse *parsePtr); MODULE_SCOPE int TclParseAllWhiteSpace(const char *src, int numBytes); MODULE_SCOPE int TclProcessReturn(Tcl_Interp *interp, int code, int level, Tcl_Obj *returnOpts); MODULE_SCOPE Tcl_Obj * TclProcGetArgSpec(Tcl_Interp *interp, CompiledLocal *argPtr, int flags); MODULE_SCOPE int TclpObjLstat(Tcl_Obj *pathPtr, Tcl_StatBuf *buf); MODULE_SCOPE Tcl_Obj * TclpTempFileName(void); MODULE_SCOPE Tcl_Obj * TclpTempFileNameForLibrary(Tcl_Interp *interp, Tcl_Obj* pathPtr); MODULE_SCOPE Tcl_Obj * TclNewFSPathObj(Tcl_Obj *dirPtr, const char *addStrRep, int len); MODULE_SCOPE int TclpDeleteFile(const void *path); MODULE_SCOPE void TclpFinalizeCondition(Tcl_Condition *condPtr); |
︙ | ︙ | |||
3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 | MODULE_SCOPE int TclSubstTokens(Tcl_Interp *interp, Tcl_Token *tokenPtr, int count, int *tokensLeftPtr, int line, int *clNextOuter, const char *outerScript); MODULE_SCOPE int TclTrimLeft(const char *bytes, int numBytes, const char *trim, int numTrim); MODULE_SCOPE int TclTrimRight(const char *bytes, int numBytes, const char *trim, int numTrim); MODULE_SCOPE int TclUtfCasecmp(const char *cs, const char *ct); MODULE_SCOPE int TclUtfCount(int ch); MODULE_SCOPE Tcl_Obj * TclpNativeToNormalized(ClientData clientData); MODULE_SCOPE Tcl_Obj * TclpFilesystemPathType(Tcl_Obj *pathPtr); MODULE_SCOPE int TclpDlopen(Tcl_Interp *interp, Tcl_Obj *pathPtr, Tcl_LoadHandle *loadHandle, Tcl_FSUnloadFileProc **unloadProcPtr, int flags); | > > | 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 | MODULE_SCOPE int TclSubstTokens(Tcl_Interp *interp, Tcl_Token *tokenPtr, int count, int *tokensLeftPtr, int line, int *clNextOuter, const char *outerScript); MODULE_SCOPE int TclTrimLeft(const char *bytes, int numBytes, const char *trim, int numTrim); MODULE_SCOPE int TclTrimRight(const char *bytes, int numBytes, const char *trim, int numTrim); MODULE_SCOPE int TclUpvarForExtArg(Tcl_Interp *interp, Tcl_Obj *varNamePtr, const char *localNameStr); MODULE_SCOPE int TclUtfCasecmp(const char *cs, const char *ct); MODULE_SCOPE int TclUtfCount(int ch); MODULE_SCOPE Tcl_Obj * TclpNativeToNormalized(ClientData clientData); MODULE_SCOPE Tcl_Obj * TclpFilesystemPathType(Tcl_Obj *pathPtr); MODULE_SCOPE int TclpDlopen(Tcl_Interp *interp, Tcl_Obj *pathPtr, Tcl_LoadHandle *loadHandle, Tcl_FSUnloadFileProc **unloadProcPtr, int flags); |
︙ | ︙ |
Changes to generic/tclOO.c.
︙ | ︙ | |||
182 183 184 185 186 187 188 | */ static const char *clonedBody = "foreach p [info procs [info object namespace $originObject]::*] {" " set args [info args $p];" " set idx -1;" " foreach a $args {" | | < | 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | */ static const char *clonedBody = "foreach p [info procs [info object namespace $originObject]::*] {" " set args [info args $p];" " set idx -1;" " foreach a $args {" " lset args [incr idx] [concat $a [info argspec proc $p $a]]" " };" " set b [info body $p];" " set p [namespace tail $p];" " proc $p $args $b;" "};" "foreach v [info vars [info object namespace $originObject]::*] {" " upvar 0 $v vOrigin;" |
︙ | ︙ |
Changes to generic/tclOOInfo.c.
︙ | ︙ | |||
264 265 266 267 268 269 270 | return TCL_ERROR; } resultObjs[0] = Tcl_NewObj(); for (localPtr=procPtr->firstLocalPtr; localPtr!=NULL; localPtr=localPtr->nextPtr) { if (TclIsVarArgument(localPtr)) { | | | < < < < < | | 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | return TCL_ERROR; } resultObjs[0] = Tcl_NewObj(); for (localPtr=procPtr->firstLocalPtr; localPtr!=NULL; localPtr=localPtr->nextPtr) { if (TclIsVarArgument(localPtr)) { Tcl_Obj *argObj = TclProcGetArgSpec(interp, localPtr, TCL_GETARGSPEC_WITH_NAME|TCL_GETARGSPEC_TRY_OLDSTYLE); Tcl_ListObjAppendElement(NULL, resultObjs[0], argObj); } } resultObjs[1] = TclOOGetMethodBody(Tcl_GetHashValue(hPtr)); Tcl_SetObjResult(interp, Tcl_NewListObj(2, resultObjs)); return TCL_OK; } |
︙ | ︙ | |||
854 855 856 857 858 859 860 | return TCL_ERROR; } resultObjs[0] = Tcl_NewObj(); for (localPtr=procPtr->firstLocalPtr; localPtr!=NULL; localPtr=localPtr->nextPtr) { if (TclIsVarArgument(localPtr)) { | | | < < < < < | | 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 | return TCL_ERROR; } resultObjs[0] = Tcl_NewObj(); for (localPtr=procPtr->firstLocalPtr; localPtr!=NULL; localPtr=localPtr->nextPtr) { if (TclIsVarArgument(localPtr)) { Tcl_Obj *argObj = TclProcGetArgSpec(interp, localPtr, TCL_GETARGSPEC_WITH_NAME|TCL_GETARGSPEC_TRY_OLDSTYLE); Tcl_ListObjAppendElement(NULL, resultObjs[0], argObj); } } resultObjs[1] = TclOOGetMethodBody(clsPtr->constructorPtr); Tcl_SetObjResult(interp, Tcl_NewListObj(2, resultObjs)); return TCL_OK; } |
︙ | ︙ | |||
922 923 924 925 926 927 928 | return TCL_ERROR; } resultObjs[0] = Tcl_NewObj(); for (localPtr=procPtr->firstLocalPtr; localPtr!=NULL; localPtr=localPtr->nextPtr) { if (TclIsVarArgument(localPtr)) { | | | < < < < < | | 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 | return TCL_ERROR; } resultObjs[0] = Tcl_NewObj(); for (localPtr=procPtr->firstLocalPtr; localPtr!=NULL; localPtr=localPtr->nextPtr) { if (TclIsVarArgument(localPtr)) { Tcl_Obj *argObj = TclProcGetArgSpec(interp, localPtr, TCL_GETARGSPEC_WITH_NAME|TCL_GETARGSPEC_TRY_OLDSTYLE); Tcl_ListObjAppendElement(NULL, resultObjs[0], argObj); } } resultObjs[1] = TclOOGetMethodBody(Tcl_GetHashValue(hPtr)); Tcl_SetObjResult(interp, Tcl_NewListObj(2, resultObjs)); return TCL_OK; } |
︙ | ︙ |
Changes to generic/tclOOMethod.c.
︙ | ︙ | |||
1293 1294 1295 1296 1297 1298 1299 | * Copy the argument list. */ argsObj = Tcl_NewObj(); for (localPtr=pmPtr->procPtr->firstLocalPtr; localPtr!=NULL; localPtr=localPtr->nextPtr) { if (TclIsVarArgument(localPtr)) { | | | < < < < | | 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 | * Copy the argument list. */ argsObj = Tcl_NewObj(); for (localPtr=pmPtr->procPtr->firstLocalPtr; localPtr!=NULL; localPtr=localPtr->nextPtr) { if (TclIsVarArgument(localPtr)) { Tcl_Obj *argObj = TclProcGetArgSpec(interp, localPtr, TCL_GETARGSPEC_WITH_NAME|TCL_GETARGSPEC_TRY_OLDSTYLE); Tcl_ListObjAppendElement(NULL, argsObj, argObj); } } /* * Must strip the internal representation in order to ensure that any * bound references to instance variables are removed. [Bug 3609693] |
︙ | ︙ |
Changes to generic/tclProc.c.
︙ | ︙ | |||
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | */ static void DupLambdaInternalRep(Tcl_Obj *objPtr, Tcl_Obj *copyPtr); static void FreeLambdaInternalRep(Tcl_Obj *objPtr); static int InitArgsAndLocals(Tcl_Interp *interp, Tcl_Obj *procNameObj, int skip); static void InitResolvedLocals(Tcl_Interp *interp, ByteCode *codePtr, Var *defPtr, Namespace *nsPtr); static void InitLocalCache(Proc *procPtr); static void ProcBodyDup(Tcl_Obj *srcPtr, Tcl_Obj *dupPtr); static void ProcBodyFree(Tcl_Obj *objPtr); static int ProcWrongNumArgs(Tcl_Interp *interp, int skip); static void MakeProcError(Tcl_Interp *interp, Tcl_Obj *procNameObj); static void MakeLambdaError(Tcl_Interp *interp, Tcl_Obj *procNameObj); static int SetLambdaFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr); static Tcl_NRPostProc ApplyNR2; static Tcl_NRPostProc InterpProcNR2; static Tcl_NRPostProc Uplevel_Callback; /* * The ProcBodyObjType type | > > > > > > > > > > | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | */ static void DupLambdaInternalRep(Tcl_Obj *objPtr, Tcl_Obj *copyPtr); static void FreeLambdaInternalRep(Tcl_Obj *objPtr); static int InitArgsAndLocals(Tcl_Interp *interp, Tcl_Obj *procNameObj, int skip); static int InitArgsWithOptions(Tcl_Interp *interp, Tcl_Obj *procNameObj, Tcl_Obj *const *argObjs, int numArgs); static void InitResolvedLocals(Tcl_Interp *interp, ByteCode *codePtr, Var *defPtr, Namespace *nsPtr); static void InitLocalCache(Proc *procPtr); static void ProcBodyDup(Tcl_Obj *srcPtr, Tcl_Obj *dupPtr); static void ProcBodyFree(Tcl_Obj *objPtr); static int ProcWrongNumArgs(Tcl_Interp *interp, int skip); static void MakeProcError(Tcl_Interp *interp, Tcl_Obj *procNameObj); static void MakeLambdaError(Tcl_Interp *interp, Tcl_Obj *procNameObj); static int SetLambdaFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr); static int ProcParseArgSpec(Tcl_Interp *interp, const char *argSpec, int argIdx, int isLastArg, CompiledLocal **localPtrPtr, CompiledLocal **lastLocalPtrPtr, Tcl_HashTable **namedHashPtrPtr); static inline int ProcCheckScalarArg(const char *arg, const char **err); static void ProcCompiledLocalsFree(CompiledLocal *localPtr); static Tcl_NRPostProc ApplyNR2; static Tcl_NRPostProc InterpProcNR2; static Tcl_NRPostProc Uplevel_Callback; /* * The ProcBodyObjType type |
︙ | ︙ | |||
393 394 395 396 397 398 399 | Proc **procPtrPtr) /* Returns: pointer to proc data. */ { Interp *iPtr = (Interp *) interp; const char **argArray = NULL; register Proc *procPtr; int i, length, result, numArgs; | | | | > | 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | Proc **procPtrPtr) /* Returns: pointer to proc data. */ { Interp *iPtr = (Interp *) interp; const char **argArray = NULL; register Proc *procPtr; int i, length, result, numArgs; const char *args, *bytes; register CompiledLocal *localPtr = NULL; CompiledLocal *newLocalPtr, *lastLocalPtr; int precompiled = 0, numLocalsDiff = 0; Tcl_HashTable *hPtr = NULL; 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 * there may be no source code). |
︙ | ︙ | |||
460 461 462 463 464 465 466 467 468 469 470 471 472 473 | procPtr = ckalloc(sizeof(Proc)); procPtr->iPtr = iPtr; procPtr->refCount = 1; procPtr->bodyPtr = bodyPtr; procPtr->numArgs = 0; /* Actual argument count is set below. */ procPtr->numCompiledLocals = 0; procPtr->firstLocalPtr = NULL; procPtr->lastLocalPtr = NULL; } /* * Break up the argument list into argument specifiers, then process each * argument specifier. If the body is precompiled, processing is limited | > | 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | procPtr = ckalloc(sizeof(Proc)); procPtr->iPtr = iPtr; procPtr->refCount = 1; procPtr->bodyPtr = bodyPtr; procPtr->numArgs = 0; /* Actual argument count is set below. */ procPtr->numCompiledLocals = 0; procPtr->flags = 0; procPtr->firstLocalPtr = NULL; procPtr->lastLocalPtr = NULL; } /* * Break up the argument list into argument specifiers, then process each * argument specifier. If the body is precompiled, processing is limited |
︙ | ︙ | |||
496 497 498 499 500 501 502 | localPtr = procPtr->firstLocalPtr; } else { procPtr->numArgs = numArgs; procPtr->numCompiledLocals = numArgs; } for (i = 0; i < numArgs; i++) { | < < < < < < < | < > < < < < < < < < | < < < < < < < < | < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | | < < | | | | < | < < | | | | | > > | | | | | > > > > > > > | > > > > > > > < < | > > | > > > > | | | > | | < < < < < < | < < < < < < < < < < | < < | < < < < < < < < < < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 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 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 714 715 716 717 718 719 720 721 722 723 724 725 726 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 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 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 808 809 810 811 812 813 814 815 816 817 818 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 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 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 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 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 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 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 | localPtr = procPtr->firstLocalPtr; } else { procPtr->numArgs = numArgs; procPtr->numCompiledLocals = numArgs; } for (i = 0; i < numArgs; i++) { result = ProcParseArgSpec(interp, argArray[i], i + numLocalsDiff, (i == numArgs - 1), &newLocalPtr, &lastLocalPtr, &hPtr); if (result != TCL_OK) { goto procError; } if (precompiled) { Tcl_Obj *argSpec1, *argSpec2; /* * 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 != newLocalPtr->nameLength) || (strcmp(localPtr->name, newLocalPtr->name)) || (localPtr->frameIndex != newLocalPtr->frameIndex) || !(localPtr->flags & VAR_ARGUMENT)) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "procedure \"%s\": formal parameter %d is " "inconsistent with precompiled body", procName, i)); ProcCompiledLocalsFree(newLocalPtr); Tcl_SetErrorCode(interp, "TCL", "OPERATION", "PROC", "BYTECODELIES", NULL); goto procError; } /* * Compare the argument specification. */ argSpec1 = TclProcGetArgSpec(interp, localPtr, 0); argSpec2 = TclProcGetArgSpec(interp, newLocalPtr, 0); if (strcmp(Tcl_GetString(argSpec1), Tcl_GetString(argSpec2)) != 0) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "procedure \"%s\": formal parameter \"%s\" has " "argument spec inconsistent with precompiled body", procName, newLocalPtr->name)); ProcCompiledLocalsFree(newLocalPtr); Tcl_DecrRefCount(argSpec1); Tcl_DecrRefCount(argSpec2); Tcl_SetErrorCode(interp, "TCL", "OPERATION", "PROC", "BYTECODELIES", NULL); goto procError; } if ((i == numArgs - 1) && (localPtr->nameLength == 4) && (localPtr->name[0] == 'a') && (strcmp(localPtr->name, "args") == 0)) { localPtr->flags |= VAR_IS_ARGS; } if (newLocalPtr != lastLocalPtr) { /* adjust numArgs/numCompiledLocals if ProcParseArgSpec * has created additional locals for varname. */ int diff = lastLocalPtr->frameIndex - newLocalPtr->frameIndex; numLocalsDiff += diff; while ((diff-- > 0) && (localPtr != NULL)) { localPtr = localPtr->nextPtr; } } Tcl_DecrRefCount(argSpec1); Tcl_DecrRefCount(argSpec2); ProcCompiledLocalsFree(newLocalPtr); localPtr = localPtr->nextPtr; } else { if (newLocalPtr != lastLocalPtr) { /* adjust numArgs/numCompiledLocals if ProcParseArgSpec * has created additional locals for varname. */ int diff = lastLocalPtr->frameIndex - newLocalPtr->frameIndex; procPtr->numArgs += diff; procPtr->numCompiledLocals += diff; numLocalsDiff += diff; } if (procPtr->firstLocalPtr == NULL) { procPtr->firstLocalPtr = newLocalPtr; procPtr->lastLocalPtr = lastLocalPtr; } else { procPtr->lastLocalPtr->nextPtr = newLocalPtr; procPtr->lastLocalPtr = lastLocalPtr; } if (TclIsVarWithExtArgs(newLocalPtr)) { procPtr->flags |= PROC_HAS_EXT_ARG_SPEC; } } } *procPtrPtr = procPtr; ckfree(argArray); return TCL_OK; procError: if (precompiled) { procPtr->refCount--; } else { Tcl_DecrRefCount(bodyPtr); ProcCompiledLocalsFree(procPtr->firstLocalPtr); ckfree(procPtr); } if (argArray != NULL) { ckfree(argArray); } return TCL_ERROR; } /* *---------------------------------------------------------------------- * * ProcCheckScalarArg -- * * Check that the argument name is a scalar. * * Results: * Returns TCL_OK if argument is a scalar. Returns TCL_ERROR and * set |err| with an error description if it is not a scalar. * * Side effects: * None. * *---------------------------------------------------------------------- */ static inline int ProcCheckScalarArg( const char *arg, /* Argument name. */ const char **err) /* Error description (output) */ { const char *p = arg; /* * Check that the formal parameter name is a scalar. */ while (*p != '\0') { if (*p == '(') { const char *q = p; do { q++; } while (*q != '\0'); q--; if (*q == ')') { /* We have an array element. */ *err = "is an array element"; return TCL_ERROR; } } else if ((*p == ':') && (*(p+1) == ':')) { *err = "is not a simple name"; return TCL_ERROR; } p++; } return TCL_OK; } /* *---------------------------------------------------------------------- * * ProcAddNamedGroupEntry -- * * Create a NamedGroupEntry for a specific CompiledLocal object. * NamedGroupEntry are created for each name defined using -name * or -switch argument specifier. In the later case, a value is * also associated with the name. * A Tcl_HashTable object is shared between all contiguous named * parameters, it is created when parsing the first entry. * * Results: * Returns TCL_OK on success and TCL_ERROR if anything goes wrong. * * Side effects: * If anything goes wrong, this function returns an error message in the * interpreter. On success, memory is allocated and linked into the * ExtendedArgSpec structure. A Tcl_HashTable is allocated when * parsing the first entry of a named group entry. * *---------------------------------------------------------------------- */ static int ProcAddNamedGroupEntry( Tcl_Interp *interp, /* Interpreter containing proc. */ CompiledLocal *localPtr, /* Related CompiledLocal */ const char *argName, /* Name string to add */ Tcl_Obj *valuePtr, /* Value to add when related to a -switch * argspec (NULL for -name argspec) */ Tcl_HashTable **namedHashPtrPtr) /* Shared Tcl_HashTable created on the first * named parameter entry to speedup lookups * of named parameters. */ { NamedGroupEntry *entryPtr; ExtendedArgSpec *argSpecPtr = localPtr->argSpecPtr; int length = strlen(argName), isNew; Tcl_HashEntry *hPtr; Tcl_HashTable *namedHashPtr; /* * Check that the name is not empty, does not contain a space or has * not already been added. */ if (length == 0) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "named argument with no name", -1)); return TCL_ERROR; } else if (strchr(argName, ' ') != NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "named argument \"%s\" with unexpected space character", argName)); return TCL_ERROR; } else if ((*namedHashPtrPtr != NULL) && (Tcl_FindHashEntry(*namedHashPtrPtr, argName) != NULL)) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "named argument \"%s\" has been used more than once " "in the same named group", argName)); return TCL_ERROR; } entryPtr = ckalloc(TclOffset(NamedGroupEntry, name) + length+1); entryPtr->nextPtr = NULL; entryPtr->nameLength = length; entryPtr->localIndex = localPtr->frameIndex; entryPtr->localPtr = localPtr; entryPtr->valuePtr = valuePtr; memcpy(entryPtr->name, argName, length+1); if (entryPtr->valuePtr != NULL) { Tcl_IncrRefCount(entryPtr->valuePtr); } if (argSpecPtr->firstNamedEntryPtr == NULL) { argSpecPtr->firstNamedEntryPtr = entryPtr; } else { argSpecPtr->lastNamedEntryPtr->nextPtr = entryPtr; } argSpecPtr->lastNamedEntryPtr = entryPtr; /* Either use existing hash table or create a new one */ if (*namedHashPtrPtr != NULL) { namedHashPtr = *namedHashPtrPtr; } else { namedHashPtr = ckalloc(sizeof(Tcl_HashTable)); Tcl_InitHashTable(namedHashPtr, TCL_STRING_KEYS); argSpecPtr->namedHashTable = namedHashPtr; *namedHashPtrPtr = namedHashPtr; } hPtr = Tcl_CreateHashEntry(namedHashPtr, argName, &isNew); Tcl_SetHashValue(hPtr, entryPtr); localPtr->flags |= VAR_NAMED_GROUP; return TCL_OK; } /* *---------------------------------------------------------------------- * * ProcParseArgSpec -- * * Given an argument specification defined either using old-style * (arg ?default?) or extended argument specification (TIP#457), * create and initialize the related CompiledLocal entry, including * any required additional entries (for '-varname name'). * * Results: * Returns TCL_OK on success, along with a pointer to the created * CompiledLocal entry and a pointer to the last CompiledLocal entry. * A Tcl_HashTable object is shared between all contiguous named * parameters, it is created when parsing the first entry. * Returns TCL_ERROR and set an error if the argument specification * is not valid. * * Side effects: * CompiledLocal and related entries are allocated. A Tcl_HashTable * is allocated when parsing the first entry of a named group entry. * *---------------------------------------------------------------------- */ static int ProcParseArgSpec( Tcl_Interp *interp, /* Interpreter containing proc. */ const char *argSpec, /* Argument specification. */ int argIdx, /* Argument index in the array of variables * in the procedure call frame. */ int isLastArg, /* != 0 means this is the last argument. */ CompiledLocal **localPtrPtr, /* On success, store the created CompiledLocal * here. */ CompiledLocal **lastLocalPtrPtr, /* On sucess, store the pointer to the last * created CompiledLocal here. */ Tcl_HashTable **namedHashPtrPtr) /* Shared Tcl_HashTable created on the first * named parameter entry to speedup lookups * of named parameters. */ { CompiledLocal *localPtr = NULL, *varNamePtr = NULL; ExtendedArgSpec *argSpecPtr; const char **fieldValues = NULL; int fieldCount, length; const char *err; Tcl_Obj *boolObj; int required = -1, hasSwitch = 0; int result, i, j, boolVal; /* * Divide the argument specifier into a list. */ result = Tcl_SplitList(interp, argSpec, &fieldCount, &fieldValues); if (result != TCL_OK) { goto parseError; } if ((fieldCount > 2) && (fieldCount % 2 != 1)) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "unexpected fields number in argument specifier \"%s\"", argSpec)); goto parseError; } else if ((fieldCount == 0) || (*fieldValues[0] == 0)) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "argument with no name", -1)); goto parseError; } /* * Check that the formal parameter name is a scalar. */ if (ProcCheckScalarArg(fieldValues[0], &err) != TCL_OK) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "formal parameter \"%s\" %s", fieldValues[0], err)); goto parseError; } length = strlen(fieldValues[0]); localPtr = ckalloc(TclOffset(CompiledLocal, name) + length+1); localPtr->nextPtr = NULL; localPtr->nameLength = length; localPtr->frameIndex = argIdx; localPtr->flags = VAR_ARGUMENT; localPtr->defValuePtr = NULL; localPtr->resolveInfo = NULL; localPtr->argSpecPtr = NULL; memcpy(localPtr->name, fieldValues[0], length+1); if ((isLastArg != 0) && (localPtr->nameLength == 4) && (localPtr->name[0] == 'a') && (strcmp(localPtr->name, "args") == 0)) { localPtr->flags |= VAR_IS_ARGS; } if (fieldCount <= 2) { /* old-style argument specification (arg ?default?) */ if (fieldCount == 2) { localPtr->defValuePtr = Tcl_NewStringObj(fieldValues[1], -1); Tcl_IncrRefCount(localPtr->defValuePtr); } *localPtrPtr = localPtr; *lastLocalPtrPtr = localPtr; *namedHashPtrPtr = NULL; ckfree(fieldValues); return TCL_OK; } /* * Check and handle each extended argument specification. */ argSpecPtr = ckalloc(sizeof(ExtendedArgSpec)); argSpecPtr->firstNamedEntryPtr = NULL; argSpecPtr->lastNamedEntryPtr = NULL; argSpecPtr->varnameIndex = -1; argSpecPtr->namedHashTable = NULL; localPtr->argSpecPtr = argSpecPtr; for (i = 1 ; i < fieldCount ; i += 2) { length = strlen(fieldValues[i]); if (*fieldValues[i] != '-') { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "unknown argument option \"%s\" or " "too many fields in argument specifier \"%s\"", fieldValues[i], argSpec)); goto parseError; } else if ((length == 8) && (strcmp(fieldValues[i], "-default") == 0)) { /* * Handle '-default <value>', keep value in localPtr->defValuePtr. */ if (localPtr->defValuePtr != NULL) { Tcl_DecrRefCount(localPtr->defValuePtr); } localPtr->defValuePtr = Tcl_NewStringObj(fieldValues[i+1], -1); Tcl_IncrRefCount(localPtr->defValuePtr); } else if ((length == 5) && (strcmp(fieldValues[i], "-name") == 0)) { /* * Handle '-name name', this create a name group if not * already created. */ int nameCount; const char **nameValues; result = Tcl_SplitList(interp, fieldValues[i+1], &nameCount, &nameValues); if (result != TCL_OK) { goto parseError; } for (j = 0; j < nameCount; j++) { result = ProcAddNamedGroupEntry(interp, localPtr, nameValues[j], NULL, namedHashPtrPtr); if (result != TCL_OK) { ckfree(nameValues); goto parseError; } } ckfree(nameValues); } else if ((length == 7) && (strcmp(fieldValues[i], "-switch") == 0)) { /* * Handle '-switch switch', this create a name group (with a value) * if not already created. */ int swCount, swEntCount; const char **swValues, **swEntValues; result = Tcl_SplitList(interp, fieldValues[i+1], &swCount, &swValues); if (result != TCL_OK) { goto parseError; } for (j = 0; j < swCount; j++) { result = Tcl_SplitList(interp, swValues[j], &swEntCount, &swEntValues); if (result != TCL_OK) { ckfree(swValues); goto parseError; } if (swEntCount == 1) { /* one field, use switch name as value */ result = ProcAddNamedGroupEntry(interp, localPtr, swEntValues[0], Tcl_NewStringObj(swEntValues[0], -1), namedHashPtrPtr); } else if (swEntCount == 2) { /* two fields, use second one as value */ result = ProcAddNamedGroupEntry(interp, localPtr, swEntValues[0], Tcl_NewStringObj(swEntValues[1], -1), namedHashPtrPtr); } else { /* invalid number of fields */ Tcl_SetObjResult(interp, Tcl_ObjPrintf( "incorrect switch value \"%s\"", swValues[j])); result = TCL_ERROR; } ckfree(swEntValues); if (result != TCL_OK) { ckfree(swValues); goto parseError; } } hasSwitch = 1; ckfree(swValues); } else if ((length == 6) && (strcmp(fieldValues[i], "-upvar") == 0)) { /* * Handle '-upvar bool', set or unset VAR_ARG_UPVAR flag. */ boolObj = Tcl_NewStringObj(fieldValues[i+1], -1); Tcl_IncrRefCount(boolObj); result = Tcl_GetBooleanFromObj(NULL, boolObj, &boolVal); TclDecrRefCount(boolObj); if (result != TCL_OK) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "Invalid boolean \"%s\" for -upvar arg specifier", fieldValues[i+1])); goto parseError; } else if (boolVal) { localPtr->flags |= VAR_ARG_UPVAR; } else { localPtr->flags &= VAR_ARG_UPVAR; } } else if ((length == 8) && (strcmp(fieldValues[i], "-varname") == 0)) { /* * Handle '-varname name', create variable, set varnameIndex */ const char *err; length = strlen(fieldValues[i+1]); if (length == 0) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "varname argument with no name", -1)); goto parseError; } else if (ProcCheckScalarArg(fieldValues[i+1], &err) != TCL_OK) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "varname parameter \"%s\" %s", fieldValues[i+1], err)); goto parseError; } else if (varNamePtr != NULL) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "varname already set", -1)); goto parseError; } varNamePtr = ckalloc(TclOffset(CompiledLocal, name) + length+1); varNamePtr->nextPtr = NULL; varNamePtr->nameLength = length; varNamePtr->frameIndex = argIdx + 1; varNamePtr->flags = VAR_ARG_IS_VARNAME; varNamePtr->defValuePtr = NULL; varNamePtr->resolveInfo = NULL; varNamePtr->argSpecPtr = NULL; memcpy(varNamePtr->name, fieldValues[i+1], length + 1); argSpecPtr->varnameIndex = varNamePtr->frameIndex; localPtr->flags |= VAR_ARG_HAS_VARNAME; localPtr->nextPtr = varNamePtr; } else if ((length == 9) && (strcmp(fieldValues[i], "-required") == 0)) { /* * Handle '-required bool', set required var which will be used * to set VAR_ARG_OPTIONAL flag depending on the other specifiers. */ boolObj = Tcl_NewStringObj(fieldValues[i+1], -1); Tcl_IncrRefCount(boolObj); result = Tcl_GetBooleanFromObj(NULL, boolObj, &boolVal); TclDecrRefCount(boolObj); if (result != TCL_OK) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "Invalid boolean \"%s\" for -required arg specifier", fieldValues[i+1])); goto parseError; } else if (boolVal) { required = 1; } else { required = 0; } } else { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "unknown argument option \"%s\" or " "too many fields in argument specifier \"%s\"", fieldValues[i], argSpec)); goto parseError; } } if (hasSwitch) { if (localPtr->flags & VAR_ARG_UPVAR) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "-upvar can't be used with -switch", -1)); goto parseError; } if (localPtr->flags & VAR_ARG_HAS_VARNAME) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "-varname can't be used with -switch", -1)); goto parseError; } } if (varNamePtr != NULL) { /* Argument created to handle '-varname arg' specifier must have * the VAR_NAMED_GROUP flag when the related argument is part of * a named group. This is required when searching the end of the * named group. */ if (localPtr->flags & VAR_NAMED_GROUP) { varNamePtr->flags |= VAR_NAMED_GROUP; } } if ((required == 1) && (localPtr->defValuePtr)) { /* '-required 1' explicitely set, remove the default value to * enforce the requirement. */ Tcl_DecrRefCount(localPtr->defValuePtr); localPtr->defValuePtr = NULL; } else if ((required == 0) || ((required == -1) && (localPtr->flags & VAR_NAMED_GROUP))) { /* Variable is optional if '-required 0' has been explicitely set, * or if is part of a named group and no '-requirement' specifier * has been used. */ localPtr->flags |= VAR_ARG_OPTIONAL; } if ((*namedHashPtrPtr != NULL) && !(localPtr->flags & VAR_NAMED_GROUP)) { /* Not part of a named group anymore, unset current named hash table */ *namedHashPtrPtr = NULL; } *localPtrPtr = localPtr; *lastLocalPtrPtr = (varNamePtr != NULL) ? varNamePtr : localPtr; ckfree(fieldValues); return TCL_OK; parseError: if (localPtr != NULL) { ProcCompiledLocalsFree(localPtr); } if (fieldValues) { ckfree(fieldValues); } Tcl_SetErrorCode(interp, "TCL", "OPERATION", "PROC", "FORMALARGUMENTFORMAT", NULL); return TCL_ERROR; } /* *---------------------------------------------------------------------- * * TclGetFrame -- * * Given a description of a procedure frame, such as the first argument |
︙ | ︙ | |||
1069 1070 1071 1072 1073 1074 1075 | Tcl_Interp *interp, int skip) { CallFrame *framePtr = ((Interp *)interp)->varFramePtr; register Proc *procPtr = framePtr->procPtr; register Var *defPtr; int localCt = procPtr->numCompiledLocals, numArgs, i; | | | 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 | Tcl_Interp *interp, int skip) { CallFrame *framePtr = ((Interp *)interp)->varFramePtr; register Proc *procPtr = framePtr->procPtr; register Var *defPtr; int localCt = procPtr->numCompiledLocals, numArgs, i; Tcl_Obj **desiredObjs, *argObj, *finalObj = NULL; const char *final = NULL; /* * Build up desired argument list for Tcl_WrongNumArgs */ numArgs = framePtr->procPtr->numArgs; |
︙ | ︙ | |||
1091 1092 1093 1094 1095 1096 1097 | desiredObjs[0] = framePtr->objv[skip-1]; #else desiredObjs[0] = Tcl_NewListObj(1, framePtr->objv + skip - 1); #endif /* AVOID_HACKS_FOR_ITCL */ } Tcl_IncrRefCount(desiredObjs[0]); | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | < | | | | > | | | | | | | | | > > > > | 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 | desiredObjs[0] = framePtr->objv[skip-1]; #else desiredObjs[0] = Tcl_NewListObj(1, framePtr->objv + skip - 1); #endif /* AVOID_HACKS_FOR_ITCL */ } Tcl_IncrRefCount(desiredObjs[0]); if (procPtr->flags & PROC_HAS_EXT_ARG_SPEC) { CompiledLocal *localPtr; int first = 1; TclNewObj(finalObj); numArgs = 0; for (localPtr = procPtr->firstLocalPtr; localPtr != NULL; localPtr = localPtr->nextPtr) { if (!TclIsVarArgument(localPtr)) { continue; } else if (localPtr->flags & VAR_IS_ARGS) { argObj = Tcl_NewStringObj("?arg ...?", -1); } else if ((localPtr->argSpecPtr != NULL) && (localPtr->argSpecPtr->firstNamedEntryPtr != NULL)) { NamedGroupEntry *namedGroupPtr; TclNewObj(argObj); for (namedGroupPtr = localPtr->argSpecPtr->firstNamedEntryPtr; namedGroupPtr != NULL; namedGroupPtr = namedGroupPtr->nextPtr) { Tcl_AppendStringsToObj(argObj, "|-", namedGroupPtr->name, NULL); if (localPtr->flags & VAR_ARG_UPVAR) { Tcl_AppendStringsToObj(argObj, " &", localPtr->name, "&", NULL); } else if (namedGroupPtr->valuePtr == NULL) { Tcl_AppendStringsToObj(argObj, " ", localPtr->name, NULL); } } Tcl_AppendStringsToObj(argObj, "|", NULL); } else { if (localPtr->flags & VAR_ARG_UPVAR) { TclNewObj(argObj); Tcl_AppendStringsToObj(argObj, "&", localPtr->name, "&", NULL); } else { argObj = Tcl_NewStringObj(localPtr->name, localPtr->nameLength); } } if ((localPtr->defValuePtr != NULL) || (localPtr->flags & VAR_ARG_OPTIONAL)) { Tcl_AppendStringsToObj(finalObj, first ? "?" : " ?", Tcl_GetString(argObj), "?", NULL); } else { Tcl_AppendStringsToObj(finalObj, first ? "" : " ", Tcl_GetString(argObj), NULL); } first = 0; Tcl_DecrRefCount(argObj); } final = Tcl_GetString(finalObj); } else { defPtr = (Var *) (&framePtr->localCachePtr->varName0 + localCt); for (i=1 ; i<=numArgs ; i++, defPtr++) { Tcl_Obj *namePtr = localName(framePtr, i-1); if (defPtr->value.objPtr != NULL) { TclNewObj(argObj); Tcl_AppendStringsToObj(argObj, "?", TclGetString(namePtr), "?", NULL); } else if (defPtr->flags & VAR_IS_ARGS) { numArgs--; final = "?arg ...?"; break; } else { argObj = namePtr; Tcl_IncrRefCount(namePtr); } desiredObjs[i] = argObj; } } Tcl_ResetResult(interp); Tcl_WrongNumArgs(interp, numArgs+1, desiredObjs, final); for (i=0 ; i<=numArgs ; i++) { Tcl_DecrRefCount(desiredObjs[i]); } if (finalObj != NULL) { Tcl_DecrRefCount(finalObj); } TclStackFree(interp, desiredObjs); return TCL_ERROR; } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 | if (numArgs == 0) { if (argCt) { goto incorrectArgs; } else { goto correctArgs; } } imax = ((argCt < numArgs-1) ? argCt : numArgs-1); for (i = 0; i < imax; i++, varPtr++, defPtr ? defPtr++ : defPtr) { /* * "Normal" arguments; last formal is special, depends on it being * 'args'. */ | > > > > > > > > > > > > > > | 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 | if (numArgs == 0) { if (argCt) { goto incorrectArgs; } else { goto correctArgs; } } if ((procPtr->flags & PROC_HAS_EXT_ARG_SPEC) != 0) { int result; memset(varPtr, 0, numArgs*sizeof(Var)); result = InitArgsWithOptions(interp, procNameObj, argObjs, argCt); varPtr += numArgs; if (result != TCL_OK) { goto incorrectArgs; } else { goto correctArgs; } } imax = ((argCt < numArgs-1) ? argCt : numArgs-1); for (i = 0; i < imax; i++, varPtr++, defPtr ? defPtr++ : defPtr) { /* * "Normal" arguments; last formal is special, depends on it being * 'args'. */ |
︙ | ︙ | |||
1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 | TclInitRewriteEnsemble(interp, skip-1, 0, framePtr->objv)) { TclNRAddCallback(interp, TclClearRootEnsemble, NULL, NULL, NULL, NULL); } memset(varPtr, 0, ((framePtr->compiledLocals + localCt)-varPtr) * sizeof(Var)); return ProcWrongNumArgs(interp, skip); } /* *---------------------------------------------------------------------- * * TclPushProcCallFrame -- * * Compiles a proc body if necessary, then pushes a CallFrame suitable | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 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 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 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 2205 2206 2207 2208 2209 2210 2211 2212 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 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 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 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 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 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 | TclInitRewriteEnsemble(interp, skip-1, 0, framePtr->objv)) { TclNRAddCallback(interp, TclClearRootEnsemble, NULL, NULL, NULL, NULL); } memset(varPtr, 0, ((framePtr->compiledLocals + localCt)-varPtr) * sizeof(Var)); return ProcWrongNumArgs(interp, skip); } /* *---------------------------------------------------------------------- * * InitArgsWithOptions -- * * This routine is invoked in order to initialize the arguments * for a new call frame for a proc with extended arguments * specification. The numArgs variables in the array of local * variables must be initialized prior to calling this function. * * Results: * A standard Tcl result. * * Side effects: * The numArgs variables inside the array of local variables * can be initialized with object references, even if an error * is returned. * *---------------------------------------------------------------------- */ static int InitArgsWithOptions( register Tcl_Interp *interp,/* Interpreter in which procedure was * invoked. */ Tcl_Obj *procNameObj, /* Procedure name for error reporting. */ Tcl_Obj *const *argObjs, /* Array of input arguments */ int argCt) /* Number of input arguments */ { CallFrame *framePtr = ((Interp *)interp)->varFramePtr; register Proc *procPtr = framePtr->procPtr; register Var *varPtr = framePtr->compiledLocals, *localVarPtr; int numArgs = procPtr->numArgs, iLocal, iArg; Tcl_Obj *objPtr; CompiledLocal *localPtr; NamedGroupEntry *namedGroupPtr; int optLength, result; const char *optStr; for (iLocal = 0, iArg = 0, localPtr = procPtr->firstLocalPtr; iLocal < numArgs; iLocal++, localPtr = localPtr->nextPtr) { if (!TclIsVarArgument(localPtr)) { /* most probably a local allocated for -varname */ continue; } else if (localPtr->flags & VAR_IS_ARGS) { /* * 'args' last argument, copy remaining arguments (can be empty) */ objPtr = Tcl_NewListObj(argCt-iArg, argObjs+iArg); varPtr[iLocal].value.objPtr = objPtr; Tcl_IncrRefCount(objPtr); iArg = argCt; /* all arguments have been handled */ } else if (localPtr->flags & VAR_NAMED_GROUP) { /* * Start of a named argument group. Handle all of them together. */ for (; iArg < argCt; iArg++) { if ((argObjs[iArg]->typePtr == &tclListType) && (ListRepPtr(argObjs[iArg])->elemCount > 1)) { /* multiple-elements list, end named group before getting * string representation. */ break; } optStr = TclGetString(argObjs[iArg]); if (*optStr != '-') { /* argument without leading dash, end named group */ break; } optStr++; optLength = strlen(optStr); if ((optLength == 1) && (optStr[0] == '-')) { /* end-of-option marker (--) */ iArg++; break; } /* * Find the referenced argument using the hash table * created with the first name of the named group. */ namedGroupPtr = NULL; if (localPtr->argSpecPtr->namedHashTable != NULL) { Tcl_HashEntry *hPtr; hPtr = Tcl_FindHashEntry( localPtr->argSpecPtr->namedHashTable, optStr); if (hPtr != NULL) { namedGroupPtr = Tcl_GetHashValue(hPtr); } } if (namedGroupPtr == NULL) { return TCL_ERROR; /* not found */ } else if (namedGroupPtr->valuePtr) { objPtr = namedGroupPtr->valuePtr; } else if (iArg+1 < argCt) { objPtr = argObjs[++iArg]; } else { return TCL_ERROR; /* not enough input args */ } if (namedGroupPtr->localPtr->flags & VAR_ARG_UPVAR) { result = TclUpvarForExtArg(interp, objPtr, namedGroupPtr->localPtr->name); if (result != TCL_OK) { return result; } } else { localVarPtr = &(varPtr[namedGroupPtr->localIndex]); if (localVarPtr->value.objPtr != NULL) { Tcl_DecrRefCount(localVarPtr->value.objPtr); } localVarPtr->value.objPtr = objPtr; Tcl_IncrRefCount(objPtr); } if (namedGroupPtr->localPtr->flags & VAR_ARG_HAS_VARNAME) { localVarPtr = &(varPtr[namedGroupPtr->localPtr->argSpecPtr->varnameIndex]); if (localVarPtr->value.objPtr != NULL) { Tcl_DecrRefCount(localVarPtr->value.objPtr); } localVarPtr->value.objPtr = objPtr; Tcl_IncrRefCount(objPtr); } } /* * Ensure that all variables in the named group have been * set, have a default value or are optionals. localPtr is set * to the last argument of the named group so that the loop * will continue with the next argument. iLocal is updated in * the same way. */ for (; ; localPtr=localPtr->nextPtr, iLocal++) { if (!varPtr[iLocal].value.objPtr) { if (localPtr->defValuePtr) { objPtr = localPtr->defValuePtr; varPtr[iLocal].value.objPtr = objPtr; Tcl_IncrRefCount(objPtr); } else if (!(localPtr->flags & VAR_ARG_OPTIONAL)) { return TCL_ERROR; } } /* stop on the last argument of the named group */ if ((localPtr->nextPtr == NULL) || !(localPtr->nextPtr->flags & (VAR_NAMED_GROUP))) { break; } } } else if (iArg < argCt) { /* * Set normal or 'upvar' variable using next input argument. */ objPtr = argObjs[iArg++]; if (localPtr->flags & VAR_ARG_UPVAR) { result = TclUpvarForExtArg(interp, objPtr, localPtr->name); if (result != TCL_OK) { return result; } } else { varPtr[iLocal].value.objPtr = objPtr; Tcl_IncrRefCount(objPtr); } if (localPtr->flags & VAR_ARG_HAS_VARNAME) { localVarPtr = &(varPtr[localPtr->argSpecPtr->varnameIndex]); if (localVarPtr->value.objPtr != NULL) { Tcl_DecrRefCount(localVarPtr->value.objPtr); } localVarPtr->value.objPtr = objPtr; Tcl_IncrRefCount(objPtr); } } else if (localPtr->defValuePtr) { /* * No more input arguments, set default value */ objPtr = localPtr->defValuePtr; varPtr[iLocal].value.objPtr = objPtr; Tcl_IncrRefCount(objPtr); } else if (!(localPtr->flags & VAR_ARG_OPTIONAL)) { /* * No more input arguments, no default value, not optional. */ return TCL_ERROR; } } if (iArg < argCt) { /* * Remaining input arguments which have not been handled. */ return TCL_ERROR; } return TCL_OK; } /* *---------------------------------------------------------------------- * * TclProcGetArgSpec -- * * This routine is invoked in order to build an argument specification * for an existing argument. The TCL_GETARGSPEC_WITH_NAME or * TCL_GETARGSPEC_TRY_OLDSTYLE flags can be used to change how the * returned list is built. * * Results: * Returns a pointer to a newly allocated Tcl_Obj list. * * Side effects: * The returned list is allocated. * *---------------------------------------------------------------------- */ Tcl_Obj * TclProcGetArgSpec( Tcl_Interp *interp, CompiledLocal *localPtr, int flags) { Tcl_Obj *listObjPtr, *nameListPtr = NULL, *switchListPtr = NULL; NamedGroupEntry *ngPtr; listObjPtr = Tcl_NewListObj(0, NULL); if (flags & TCL_GETARGSPEC_WITH_NAME) { Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewStringObj(localPtr->name, localPtr->nameLength)); } if ((flags & TCL_GETARGSPEC_TRY_OLDSTYLE) && (!TclIsVarWithExtArgs(localPtr))) { if (localPtr->defValuePtr != NULL) { Tcl_ListObjAppendElement(interp, listObjPtr, localPtr->defValuePtr); } return listObjPtr; } if (localPtr->defValuePtr != NULL) { Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewStringObj("-default", -1)); Tcl_ListObjAppendElement(interp, listObjPtr, localPtr->defValuePtr); } if ((localPtr->flags & VAR_NAMED_GROUP) && !(localPtr->flags & VAR_ARG_OPTIONAL)) { Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewStringObj("-required", -1)); Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewBooleanObj(1)); } else if (!(localPtr->flags & VAR_NAMED_GROUP) && (localPtr->flags & VAR_ARG_OPTIONAL)) { Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewStringObj("-required", -1)); Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewBooleanObj(0)); } if (localPtr->flags & VAR_ARG_UPVAR) { Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewStringObj("-upvar", -1)); Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewBooleanObj(1)); } if ((localPtr->argSpecPtr != NULL) && (localPtr->argSpecPtr->firstNamedEntryPtr != NULL)) { for (ngPtr = localPtr->argSpecPtr->firstNamedEntryPtr; ngPtr != NULL; ngPtr = ngPtr->nextPtr) { Tcl_Obj *objArray[2] = { Tcl_NewStringObj(ngPtr->name, ngPtr->nameLength), ngPtr->valuePtr }; if (objArray[1] == NULL) { if (nameListPtr == NULL) { nameListPtr = Tcl_NewListObj(0, NULL); } Tcl_ListObjAppendElement(interp, nameListPtr, objArray[0]); } else if ((objArray[0]->length == objArray[1]->length) && (strcmp(Tcl_GetString(objArray[0]), Tcl_GetString(objArray[1])) == 0)) { if (switchListPtr == NULL) { switchListPtr = Tcl_NewListObj(0, NULL); } Tcl_ListObjAppendElement(interp, switchListPtr, objArray[0]); } else { if (switchListPtr == NULL) { switchListPtr = Tcl_NewListObj(0, NULL); } Tcl_ListObjAppendElement(interp, switchListPtr, Tcl_NewListObj(2, objArray)); } } } if (nameListPtr != NULL) { Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewStringObj("-name", -1)); Tcl_ListObjAppendElement(interp, listObjPtr, nameListPtr); } if (switchListPtr != NULL) { Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewStringObj("-switch", -1)); Tcl_ListObjAppendElement(interp, listObjPtr, switchListPtr); } if ((localPtr->argSpecPtr != NULL) && (localPtr->argSpecPtr->varnameIndex >= 0)) { CompiledLocal *upLocal = localPtr->nextPtr; while ((upLocal != NULL) && (upLocal->frameIndex != localPtr->argSpecPtr->varnameIndex)) { upLocal = upLocal->nextPtr; } if (upLocal != NULL) { Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewStringObj("-varname", -1)); Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewStringObj(upLocal->name, upLocal->nameLength)); } } return listObjPtr; } /* *---------------------------------------------------------------------- * * TclPushProcCallFrame -- * * Compiles a proc body if necessary, then pushes a CallFrame suitable |
︙ | ︙ | |||
2006 2007 2008 2009 2010 2011 2012 | if (lastPtr) { lastPtr->nextPtr = NULL; } else { procPtr->firstLocalPtr = NULL; } procPtr->lastLocalPtr = lastPtr; | < < < < < < < < < < < < < > | 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 | if (lastPtr) { lastPtr->nextPtr = NULL; } else { procPtr->firstLocalPtr = NULL; } procPtr->lastLocalPtr = lastPtr; procPtr->numCompiledLocals = procPtr->numArgs; ProcCompiledLocalsFree(clPtr); } (void) TclPushStackFrame(interp, &framePtr, (Tcl_Namespace *) nsPtr, /* isProcCallFrame */ 0); /* * TIP #280: We get the invoking context from the cmdFrame which |
︙ | ︙ | |||
2140 2141 2142 2143 2144 2145 2146 | *---------------------------------------------------------------------- */ void TclProcCleanupProc( register Proc *procPtr) /* Procedure to be deleted. */ { | < < < < < | < < < < < < < < < < < < < < < < | 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 | *---------------------------------------------------------------------- */ void TclProcCleanupProc( register Proc *procPtr) /* Procedure to be deleted. */ { Tcl_Obj *bodyPtr = procPtr->bodyPtr; Tcl_HashEntry *hePtr = NULL; CmdFrame *cfPtr = NULL; Interp *iPtr = procPtr->iPtr; if (bodyPtr != NULL) { Tcl_DecrRefCount(bodyPtr); } ProcCompiledLocalsFree(procPtr->firstLocalPtr); ckfree(procPtr); /* * TIP #280: Release the location data associated with this Proc * structure, if any. The interpreter may not exist (For example for * procbody structures created by tbcload. */ |
︙ | ︙ | |||
2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 | } ckfree(cfPtr->line); cfPtr->line = NULL; ckfree(cfPtr); } Tcl_DeleteHashEntry(hePtr); } /* *---------------------------------------------------------------------- * * TclUpdateReturnInfo -- * * This function is called when procedures return, and at other points | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 | } ckfree(cfPtr->line); cfPtr->line = NULL; ckfree(cfPtr); } Tcl_DeleteHashEntry(hePtr); } /* *---------------------------------------------------------------------- * * ProcCompiledLocalsFree -- * * This function does all the real work of freeing up a CompiledLocal * linked list. * * Results: * None. * * Side effects: * Memory gets freed. * *---------------------------------------------------------------------- */ static void ProcCompiledLocalsFree( CompiledLocal *localPtr) { CompiledLocal *nextLocalPtr = localPtr; Tcl_ResolvedVarInfo *resVarInfo; NamedGroupEntry *entryPtr, *nextEntryPtr; while (nextLocalPtr != NULL) { localPtr = nextLocalPtr; nextLocalPtr = nextLocalPtr->nextPtr; resVarInfo = localPtr->resolveInfo; if (resVarInfo) { if (resVarInfo->deleteProc) { resVarInfo->deleteProc(resVarInfo); } else { ckfree(resVarInfo); } } if (localPtr->defValuePtr != NULL) { Tcl_DecrRefCount(localPtr->defValuePtr); } if (localPtr->argSpecPtr != NULL) { entryPtr = localPtr->argSpecPtr->firstNamedEntryPtr; while (entryPtr != NULL) { nextEntryPtr = entryPtr->nextPtr; if (entryPtr->valuePtr) { Tcl_DecrRefCount(entryPtr->valuePtr); } ckfree(entryPtr); entryPtr = nextEntryPtr; } ckfree(localPtr->argSpecPtr); } ckfree(localPtr); } } /* *---------------------------------------------------------------------- * * TclUpdateReturnInfo -- * * This function is called when procedures return, and at other points |
︙ | ︙ |
Changes to generic/tclVar.c.
︙ | ︙ | |||
4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 | result = ObjMakeUpvar(interp, framePtr, part1Ptr, part2, 0, localNamePtr, flags, -1); Tcl_DecrRefCount(part1Ptr); Tcl_DecrRefCount(localNamePtr); return result; } /* *---------------------------------------------------------------------- * * Tcl_GetVariableFullName -- * * Given a Tcl_Var token returned by Tcl_FindNamespaceVar, this function | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | result = ObjMakeUpvar(interp, framePtr, part1Ptr, part2, 0, localNamePtr, flags, -1); Tcl_DecrRefCount(part1Ptr); Tcl_DecrRefCount(localNamePtr); return result; } /* *---------------------------------------------------------------------- * * TclUpvarForExtArg -- * * This function links one variable to another. It is used during * initialization of proc variables which use the upvar extended * argument specification. * * Results: * A standard Tcl completion code. If an error occurs then an error * message is left in the interp's result. * * Side effects: * The variable in upper frame whose name is given by varName becomes * accessible under the name localNameStr, so that references to * localNameStr are redirected to the other variable like a symbolic * link. * *---------------------------------------------------------------------- */ int TclUpvarForExtArg( Tcl_Interp *interp, /* Command interpreter in which varName is to * be looked up. */ Tcl_Obj *varNamePtr, /* Name of variable in interp to link to. */ const char *localNameStr) /* Name of link variable. */ { int result; CallFrame *framePtr; Tcl_Obj *localNamePtr; if (TclObjGetFrame(interp, NULL, &framePtr) == -1) { return TCL_ERROR; } localNamePtr = Tcl_NewStringObj(localNameStr, -1); Tcl_IncrRefCount(localNamePtr); result = ObjMakeUpvar(interp, framePtr, varNamePtr, NULL, 0, localNamePtr, 0, -1); Tcl_DecrRefCount(localNamePtr); return result; } /* *---------------------------------------------------------------------- * * Tcl_GetVariableFullName -- * * Given a Tcl_Var token returned by Tcl_FindNamespaceVar, this function |
︙ | ︙ |
Changes to tests/apply.test.
︙ | ︙ | |||
45 46 47 48 49 50 51 | } {1 {argument with no name} {argument with no name (parsing lambda expression "{{}} boo") invoked from within "apply $lambda"}} test apply-2.3 {malformed lambda} { set lambda [list {{a b c}} boo] list [catch {apply $lambda} msg] $msg $::errorInfo | | | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | } {1 {argument with no name} {argument with no name (parsing lambda expression "{{}} boo") invoked from within "apply $lambda"}} test apply-2.3 {malformed lambda} { set lambda [list {{a b c}} boo] list [catch {apply $lambda} msg] $msg $::errorInfo } {1 {unknown argument option "b" or too many fields in argument specifier "a b c"} {unknown argument option "b" or too many fields in argument specifier "a b c" (parsing lambda expression "{{a b c}} boo") invoked from within "apply $lambda"}} test apply-2.4 {malformed lambda} { set lambda [list a(1) boo] list [catch {apply $lambda} msg] $msg $::errorInfo } {1 {formal parameter "a(1)" is an array element} {formal parameter "a(1)" is an array element |
︙ | ︙ |
Changes to tests/info.test.
︙ | ︙ | |||
36 37 38 39 40 41 42 | test info-1.1 {info args option} { proc t1 {a bbb c} {return foo} info args t1 } {a bbb c} test info-1.2 {info args option} { proc t1 {{a default1} {bbb default2} {c default3} args} {return foo} | | | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | test info-1.1 {info args option} { proc t1 {a bbb c} {return foo} info args t1 } {a bbb c} test info-1.2 {info args option} { proc t1 {{a default1} {bbb default2} {c default3} args} {return foo} info args t1 } {a bbb c args} test info-1.3 {info args option} { proc t1 "" {return foo} info args t1 } {} test info-1.4 {info args option} -body { catch {rename t1 {}} |
︙ | ︙ | |||
674 675 676 677 678 679 680 | unset functions msg test info-21.1 {miscellaneous error conditions} -returnCodes error -body { info } -result {wrong # args: should be "info subcommand ?arg ...?"} test info-21.2 {miscellaneous error conditions} -returnCodes error -body { info gorp | | | | | | 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | unset functions msg test info-21.1 {miscellaneous error conditions} -returnCodes error -body { info } -result {wrong # args: should be "info subcommand ?arg ...?"} test info-21.2 {miscellaneous error conditions} -returnCodes error -body { info gorp } -result {unknown or ambiguous subcommand "gorp": must be args, argspec, body, class, cmdcount, commands, complete, coroutine, default, errorstack, exists, frame, functions, globals, hostname, level, library, loaded, locals, nameofexecutable, object, patchlevel, procs, script, sharedlibextension, tclversion, or vars} test info-21.3 {miscellaneous error conditions} -returnCodes error -body { info c } -result {unknown or ambiguous subcommand "c": must be args, argspec, body, class, cmdcount, commands, complete, coroutine, default, errorstack, exists, frame, functions, globals, hostname, level, library, loaded, locals, nameofexecutable, object, patchlevel, procs, script, sharedlibextension, tclversion, or vars} test info-21.4 {miscellaneous error conditions} -returnCodes error -body { info l } -result {unknown or ambiguous subcommand "l": must be args, argspec, body, class, cmdcount, commands, complete, coroutine, default, errorstack, exists, frame, functions, globals, hostname, level, library, loaded, locals, nameofexecutable, object, patchlevel, procs, script, sharedlibextension, tclversion, or vars} test info-21.5 {miscellaneous error conditions} -returnCodes error -body { info s } -result {unknown or ambiguous subcommand "s": must be args, argspec, body, class, cmdcount, commands, complete, coroutine, default, errorstack, exists, frame, functions, globals, hostname, level, library, loaded, locals, nameofexecutable, object, patchlevel, procs, script, sharedlibextension, tclversion, or vars} ## # ### ### ### ######### ######### ######### ## info frame ## Helper # For the more complex results we cut the file name down to remove path |
︙ | ︙ | |||
2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 | } -body { demo } -cleanup { unset -nocomplain body rename demo {} rename probe {} } -result 3 # cleanup catch {namespace delete test_ns_info1 test_ns_info2} ::tcltest::cleanupTests return | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 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 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 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 | } -body { demo } -cleanup { unset -nocomplain body rename demo {} rename probe {} } -result 3 # ------------------------------------------------------------------------- # info argspec test info-40-0 {info argspec missing type} -body { info argspec } -returnCodes error -result {wrong # args: should be "info argspec type ..."} test info-40-1 {info argspec proc with old-style proc} { proc p { a { b 1 } { c {} } } {} list [info argspec proc p a] [info argspec proc p b] [info argspec proc p c] } {{} {-default 1} {-default {}}} test info-40-2 {info argspec proc missing procname} -body { info argspec proc } -returnCodes error -result {wrong # args: should be "info argspec proc procname ?arg?"} test info-40-3 {info argspec proc too many args} -body { info argspec proc proc arg foo } -returnCodes error -result {wrong # args: should be "info argspec proc procname ?arg?"} test info-40-4 {info argspec proc unknown proc} -body { info argspec proc fooproc x } -returnCodes error -result {"fooproc" isn't a procedure} test info-40-5 {info argspec proc unknown arg} -body { proc p {a} {} info argspec proc p x } -returnCodes error -result {proc "p" doesn't have an argument "x"} test info-40-6 {info argspec proc on local variable} -body { proc p {a} {set x 0} info argspec proc p x } -returnCodes error -result {proc "p" doesn't have an argument "x"} test info-40-7 {info argspec proc on varname name} -body { proc p {{a -varname up}} {} info argspec proc p up } -returnCodes error -result {proc "p" doesn't have an argument "up"} test info-40-8 {info argspec proc with new-style proc} { proc p { { a -default 2 } { b -upvar 1 } { c -upvar 1 -varname up } { d -required 0 } } {} list [info argspec proc p a] [info argspec proc p b] [info argspec proc p c] [info argspec proc p d] } {{-default 2} {-upvar 1} {-upvar 1 -varname up} {-required 0}} test info-40-9 {info argspec proc with multiple named args} { proc p { { a -default 0 -name val -switch {flag1 { flag2 22 }} -name {val2}} } {} info argspec proc p a } {-default 0 -name {val val2} -switch {flag1 {flag2 22}}} test info-40-10 {info argspec proc without arg} { proc p { { a -default 2 } { b -name {B B1} -required 1 } args } {} info argspec proc p } {{a -default 2} {b -required 1 -name {B B1}} args} test info-40-11 {info argspec unknown type} -body { info argspec foo } -returnCodes error -result {bad type "foo": must be proc, lambda, constructor, method, objmethod, or specifiers} test info-40-12 {info argspec lambda} { set l [list {{a -name A} {b -default 5}} {list $a $b}] list [info argspec lambda $l] [info argspec lambda $l a] } {{{a -name A} {b -default 5}} {-name A}} test info-40-13 {info argspec lambda not a lambda} -body { proc p {} {} info argspec lambda p } -returnCodes error -result {can't interpret "p" as a lambda expression} test info-40-14 {info argspec specifiers} { info argspec specifiers } {-default -name -required -switch -upvar -varname} test info-40-15 {info argspec objmethod} -setup { oo::object create foo } -body { oo::objdefine foo method bar {a {b B} {c -switch {{C 1}} -default 0}} {} list [info argspec objmethod foo bar] [info argspec objmethod foo bar c] } -cleanup { foo destroy } -result {{a {b -default B} {c -default 0 -switch {{C 1}}}} {-default 0 -switch {{C 1}}}} test info-40-15 {info argspec constructor} -setup { oo::class create testClass { constructor {{a -default 0 -name A}} { } } } -body { list [info argspec constructor testClass] [info argspec constructor testClass a] } -cleanup { testClass destroy } -result {{{a -default 0 -name A}} {-default 0 -name A}} test info-40-16 {info argspec method} -setup { oo::class create testClass { method m {a {b -required 0}} { } } } -body { list [info argspec method testClass m] [info argspec method testClass m b] } -cleanup { testClass destroy } -result {{a {b -required 0}} {-required 0}} # cleanup catch {namespace delete test_ns_info1 test_ns_info2} ::tcltest::cleanupTests return |
Changes to tests/oo.test.
︙ | ︙ | |||
3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 | } {} test oo-35.4 {Bug 593baa032c: mixins list teardown} { # Bug makes this crash, especially with mem-debugging on oo::class create B {} oo::class create D {mixin B} namespace eval [info object namespace D] [list [namespace which B] destroy] } {} cleanupTests return # Local Variables: # mode: tcl | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 | } {} test oo-35.4 {Bug 593baa032c: mixins list teardown} { # Bug makes this crash, especially with mem-debugging on oo::class create B {} oo::class create D {mixin B} namespace eval [info object namespace D] [list [namespace which B] destroy] } {} # TIP457-related tests test oo-36.1 {OO/CloneProcedureMethod with extended argspec} { oo::object create foo oo::objdefine foo { method p { {x -default off -switch {{ON on}}} } { lappend ::result [self object] >$x< } } set result {} foo p; foo p -ON oo::copy foo bar bar p; bar p -ON foo destroy; bar destroy set result } {::foo >off< ::foo >on< ::bar >off< ::bar >on<} catch {foo destroy} catch {bar destroy} test oo-36.2 {OO/clonedBody with extended argspec} -setup { oo::class create ArbitraryClass {export eval} } -body { ArbitraryClass create a a eval {proc foo {a {n -name num -default 3}} { return [string repeat $a $n] }} set result [a eval {foo A -num 2}] oo::copy a b lappend result [b eval {foo B -num 4}] [b eval {foo C}] } -cleanup { ArbitraryClass destroy } -result {AA BBBB CCC} test oo-36.3 {"info object definition" with extended argspec} -setup { oo::object create foo } -body { oo::objdefine foo method bar {a {b B} {c -switch {{C 1}} -default 0} {d -upvar true -varname up} args} {body} set result [info object definition foo bar] } -cleanup { foo destroy } -result {{a {b B} {c -default 0 -switch {{C 1}}} {d -upvar 1 -varname up} args} body} test oo-36.4 {"info class definition" with extended argspec} -setup { oo::class create foo } -body { oo::define foo method bar {a {b 8} {c -name C} {d -name D -upvar true} args} {body} set result [info class definition foo bar] } -cleanup { foo destroy } -result {{a {b 8} {c -name C} {d -upvar 1 -name D} args} body} test oo-36.5 {OO constructor with extended argspec} { oo::class create testClass { constructor {{a -default 0 -name A}} { global result lappend result [self object] $a } } set result {} testClass create foo1 testClass create foo2 -A 5 testClass destroy return $result } {::foo1 0 ::foo2 5} cleanupTests return # Local Variables: # mode: tcl |
︙ | ︙ |
Added tests/proc-enh.test.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 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 177 178 179 180 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 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 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 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 | # Commands covered: proc # # This file contains a collection of tests for one or more of the Tcl built-in # commands. Sourcing this file into Tcl runs the tests and generates output # for errors. No output means no errors were found. # # See the file "license.terms" for information on usage and redistribution of # this file, and for a DISCLAIMER OF ALL WARRANTIES. if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest namespace import -force ::tcltest::* } testConstraint procbodytest [expr {![catch {package require procbodytest}]}] # proc-enh-1.x: error while parsing argspec test proc-enh-1.1 {argspec parsing error: unexpected fields number} { list [catch { proc p {{a -default 1 -name}} {} } msg] $msg $errorCode } {1 {unexpected fields number in argument specifier "a -default 1 -name"} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.2 {argspec parsing error: argument with no name} { list [catch { proc p {{}} {} } msg] $msg $errorCode } {1 {argument with no name} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.3 {argspec parsing error: formal parameter is an array elt} { list [catch { proc p {a(1)} {} } msg] $msg $errorCode } {1 {formal parameter "a(1)" is an array element} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.4 {argspec parsing error: formal parameter is not a simple name} { list [catch { proc p {a::b} {} } msg] $msg $errorCode } {1 {formal parameter "a::b" is not a simple name} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.5 {argspec parsing error: unknown option} { list [catch { proc p {{a -foo 1}} {} } msg] $msg $errorCode } {1 {unknown argument option "-foo" or too many fields in argument specifier "a -foo 1"} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.5b {argspec parsing error: unknown option} { list [catch { proc p {{a foo 1}} {} } msg] $msg $errorCode } {1 {unknown argument option "foo" or too many fields in argument specifier "a foo 1"} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.6 {argspec parsing error: empty named argument} { list [catch { proc p {{a -name {""}}} {} } msg] $msg $errorCode } {1 {named argument with no name} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.7 {argspec parsing error: named argument with space} { list [catch { proc p {{a -name {"a b"}}} {} } msg] $msg $errorCode } {1 {named argument "a b" with unexpected space character} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.8 {argspec parsing error: empty named argument (switch)} { list [catch { proc p {{a -switch {a {}}}} {} } msg] $msg $errorCode } {1 {incorrect switch value ""} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.9 {argspec parsing error: named argument with space (switch)} { list [catch { proc p {{a -switch {a {"a b" 3}}}} {} } msg] $msg $errorCode } {1 {named argument "a b" with unexpected space character} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.10 {argspec parsing error: two many fields in switch} { list [catch { proc p {{a -switch {{a b c}}}} {} } msg] $msg $errorCode } {1 {incorrect switch value "a b c"} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.11 {argspec parsing error: upvar with no boolean} { list [catch { proc p {{a -upvar foo}} {} } msg] $msg $errorCode } {1 {Invalid boolean "foo" for -upvar arg specifier} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.12 {argspec parsing error: varname argument with no name} { list [catch { proc p {{a -varname {}}} {} } msg] $msg $errorCode } {1 {varname argument with no name} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.13 {argspec parsing error: varname parameter is an array elt} { list [catch { proc p {{a -varname a(1)}} {} } msg] $msg $errorCode } {1 {varname parameter "a(1)" is an array element} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.14 {argspec parsing error: varname is not a simple name} { list [catch { proc p {{a -varname a::b}} {} } msg] $msg $errorCode } {1 {varname parameter "a::b" is not a simple name} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.15 {argspec parsing error: varname set twice} { list [catch { proc p {{a -varname up1 -varname up2}} {} } msg] $msg $errorCode } {1 {varname already set} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.16 {argspec parsing error: required with no boolean} { list [catch { proc p {{a -required foo}} {} } msg] $msg $errorCode } {1 {Invalid boolean "foo" for -required arg specifier} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.16 {argspec parsing error: same arg name used twice} { list [catch { proc p {{a -name A} {b -name B} {a2 -name A}} {} } msg] $msg $errorCode } {1 {named argument "A" has been used more than once in the same named group} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.17 {argspec parsing error: -upvar with -switch} { list [catch { proc p {{a -switch A -upvar 1}} {} } msg] $msg $errorCode } {1 {-upvar can't be used with -switch} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} test proc-enh-1.18 {argspec parsing error: -varname with -switch} { list [catch { proc p {{a -switch A -varname va}} {} } msg] $msg $errorCode } {1 {-varname can't be used with -switch} {TCL OPERATION PROC FORMALARGUMENTFORMAT}} # proc-enh-2.x: correct usage test proc-enh-2.1 {correct usage: -default} { proc p { { a -default 1 } } { list $a } list [p] [p 2] } {1 2} test proc-enh-2.2 {correct usage: -default set twice} { proc p { { a -default 1 -default 2 } } { return $a }; p } {2} test proc-enh-2.3 {correct usage: -name} { proc p {{a -name A} {b -name {B0 B1}} {c -name C0 -name C1}} { list $a $b $c }; list [p -B0 5 -A 1 -C1 6] [p -C0 0 -B1 8 -A 2 -C0 3] } {{1 5 6} {2 8 3}} test proc-enh-2.4 {correct usage: -switch} { proc p {{a -switch {A}} {b -switch {B0 {B1 b1}}} {c -switch {{C0 c0}} -switch C1}} { list $a $b $c }; list [p -B1 -C1 -A] [p -A -C0 -B0] } {{A b1 C1} {A B0 c0}} test proc-enh-2.5 {correct usage: -switch + -name} { proc p {{v -name val -switch {{low 0} {high 9}}}} { return $v } list [p -low] [p -val 5] [p -high] } {0 5 9} test proc-enh-2.6 {correct usage: -required} { proc p {{a -required 0}} { if {[info exists a]} { return $a } else { return unset } }; list [p] [p 2] } {unset 2} test proc-enh-2.7 {correct usage: -required + -switch} { proc p {{a -required 0 -switch dbg}} { if {[info exists a]} { return $a } else { return unset } }; list [p] [p -dbg] } {unset dbg} test proc-enh-2.8 {correct usage: -upvar} { proc p {{a -upvar 1}} { incr a; return $a } set i 5; if [info exists j] { unset j } list [p i] [p j] [list $i $j] } {6 1 {6 1}} test proc-enh-2.8 {correct usage: -upvar + -varname} { proc p {{a -varname up -upvar 1}} { incr a; list $up $a } set i 5; if [info exists j] { unset j } list [p i] [p j] [list $i $j] } {{i 6} {j 1} {6 1}} test proc-enh-2.9 {correct usage: -upvar + -varname + -name} { proc p {{a -varname up1 -upvar 1 -name A} {b -name B -upvar 1 -varname up2}} { incr a; incr b; list $up1 $a $up2 $b } set i 5; if [info exists j] { unset j } list [p -B j -A i] [p -A j -B i] [list $i $j] } {{i 6 j 1} {j 2 i 7} {7 2}} test proc-enh-2.10 {correct usage: end of named group} { proc p {{a -name A -default 0} {b -default 1 -name B} args} { list $a $b $args } list [p foo] [p -B 3 -- -A 5] } {{0 1 foo} {0 3 {-A 5}}} test proc-enh-2.11 {correct usage: -upvar inside a named group (not last one)} { proc p {{v -name var -upvar 1} {i -default 1 -name incr}} { incr v $i } if [info exists i] {unset i} list [p -var i -incr 2] [p -incr 3 -var i] [p -var i] } {2 5 6} test proc-enh-2.12 {correct usage: -upvar inside a named group + end-of-option marker} { proc p {{v -name var -upvar 1 -varname nm} {i -default 1 -name incr} args} { incr v $i; list $nm $v $args } set i 0 list [p -var i] [p -var i -- -incr 3] [p -var i -- a b c] [p -var i -- -- abc] } {{i 1 {}} {i 2 {-incr 3}} {i 3 {a b c}} {i 4 {-- abc}}} test proc-enh-2.13 {correct usage: two distinct named group} { proc p {{a -switch A -default 0} {b -switch B -default 0} c {d -switch D -default 0} {e -switch E -default 0}} { list $a $b $c $d $e } list [p -B 5 -E -D] [p -- foo -E] } {{0 B 5 D E} {0 0 foo 0 E}} test proc-enh-2.14 {correct usage: named arg without required is optionnal} { proc p {{a -name A}} { if {[info exists a]} { return $a } else { return unset } }; list [p] [p -A 2] } {unset 2} test proc-enh-2.15 {correct usage: multi-elems list must not be handled as a named name} { proc p {{a -name A -default 0} b} { list $a $b }; set l [list -Z 1] p $l } {0 {-Z 1}} test proc-enh-2.16 {correct usage: varname without upvar} { proc p {{a -name A -varname vn1} {b -varname vn2}} { list $a $vn1 $b $vn2 }; p -A i j } {i i j j} # proc-enh-3.x: wrong # args test proc-enh-3.1 {wrong # args: -name arg without value} { proc p {{a -name A} {b -name B -default 1}} { } list [catch { p -A } msg] $msg $errorCode } {1 {wrong # args: should be "p ?|-A a|? ?|-B b|?"} {TCL WRONGARGS}} test proc-enh-3.2 {wrong # args: named group ended by an arg with leading dash} { proc p {{a -name A} {b -name B} args} { } list [catch { p -b Z -5 } msg] $msg $errorCode } {1 {wrong # args: should be "p ?|-A a|? ?|-B b|? ?arg ...?"} {TCL WRONGARGS}} test proc-enh-3.3 {wrong # args: named group followed by too many options} { proc p {{a -name A -default 1} b} { } list [catch { p -- 5 6 } msg] $msg $errorCode } {1 {wrong # args: should be "p ?|-A a|? b"} {TCL WRONGARGS}} test proc-enh-3.4 {wrong # args: required named group with name+switch} { proc p {{a -name A -switch {A0 A1} -required 1}} { } list [catch { p } msg] $msg $errorCode } {1 {wrong # args: should be "p |-A a|-A0|-A1|"} {TCL WRONGARGS}} test proc-enh-3.5 {wrong # args: required named group with upvar} { proc p {{a -name A -upvar 1 -required 1} {b -upvar 1}} { } list [catch { p } msg] $msg $errorCode } {1 {wrong # args: should be "p |-A &a&| &b&"} {TCL WRONGARGS}} test proc-enh-3.6 {wrong # args: two distinct named group, specified in wrong order} { proc p {{a -switch A} {b -switch B} c {d -switch D} {e -switch E}} { } list [catch { p -E 1 } msg] $msg $errorCode } {1 {wrong # args: should be "p ?|-A|? ?|-B|? c ?|-D|? ?|-E|?"} {TCL WRONGARGS}} # proc-enh-4.x: errors during call test proc-enh-4.1 {errors during call: -upvar read access with non-existing arg} { proc p {{a -upvar 1}} { return $a } if [info exists v] { unset v} list [catch { p v } msg] $msg $errorCode } {1 {can't read "a": no such variable} {TCL READ VARNAME}} test proc-enh-4.2 {errors during call: -upvar read access with non-existing arg + -name} { proc p {{a -upvar 1 -name A}} { return $a } if [info exists v] { unset v} list [catch { p -A v } msg] $msg $errorCode } {1 {can't read "a": no such variable} {TCL READ VARNAME}} # proc-enh-5.x: precompiled test proc-enh-5.1 {precompiled: inconsistent arg default value} -body { proc p {x y {z -default 2}} { } procbodytest::proc t {x y {z ZZ}} p } -constraints procbodytest -returnCodes error -cleanup { catch {rename p ""} catch {rename t ""} } -result {procedure "t": formal parameter "z" has argument spec inconsistent with precompiled body} test proc-enh-5.2 {precompiled: inconsistent arg spec} -body { proc p {x y {z -name z}} { } procbodytest::proc t {x y {z -name ZZ}} p } -constraints procbodytest -returnCodes error -cleanup { catch {rename p ""} catch {rename t ""} } -result {procedure "t": formal parameter "z" has argument spec inconsistent with precompiled body} test proc-enh-5.3 {precompiled: with upvar arg} -body { proc p {x {y -upvar 1 -varname up} z} { } procbodytest::proc t {x {y -upvar 1 -varname up} z} p } -constraints procbodytest -result {} # proc-enh-6.x: apply/lambda test proc-enh-6.1 {apply/lambda: wrong args} { set lambda [list {{a -name A -switch A1 -required 1} {b -default B0 -name B}} {list $a $b}] list [catch { apply $lambda } msg] $msg $errorCode } {1 {wrong # args: should be "apply lambdaExpr |-A a|-A1| ?|-B b|?"} {TCL WRONGARGS}} test proc-enh-6.2 {apply/lambda: correct usage} { set lambda [list {{a -name A -switch A1} {b -default B0 -name B}} {list $a $b}] list [apply $lambda -A1] [apply $lambda -B 4 -A 8] } {{A1 B0} {8 4}} # cleanup ::tcltest::cleanupTests return # Local Variables: # mode: tcl # fill-column: 78 # End: |
Changes to tests/proc-old.test.
︙ | ︙ | |||
274 275 276 277 278 279 280 | list [catch {proc tproc {{} y} {return foo}} msg] $msg } {1 {argument with no name}} test proc-old-5.6 {error conditions} { list [catch {proc tproc {{} y} {return foo}} msg] $msg } {1 {argument with no name}} test proc-old-5.7 {error conditions} { list [catch {proc tproc {{x 1 2} y} {return foo}} msg] $msg | | | 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | list [catch {proc tproc {{} y} {return foo}} msg] $msg } {1 {argument with no name}} test proc-old-5.6 {error conditions} { list [catch {proc tproc {{} y} {return foo}} msg] $msg } {1 {argument with no name}} test proc-old-5.7 {error conditions} { list [catch {proc tproc {{x 1 2} y} {return foo}} msg] $msg } {1 {unknown argument option "1" or too many fields in argument specifier "x 1 2"}} test proc-old-5.8 {error conditions} { catch {return} } 2 proc tproc {} { set a 22 global a } |
︙ | ︙ |
Changes to tests/proc.test.
︙ | ︙ | |||
260 261 262 263 264 265 266 | } set rv [p P Q R] procbodytest::proc t {x y z} p lappend rv [t S T U] } -constraints procbodytest -returnCodes error -cleanup { catch {rename p ""} catch {rename t ""} | | | | | 260 261 262 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 | } set rv [p P Q R] procbodytest::proc t {x y z} p lappend rv [t S T U] } -constraints procbodytest -returnCodes error -cleanup { catch {rename p ""} catch {rename t ""} } -result {procedure "t": formal parameter "z" has argument spec inconsistent with precompiled body} test proc-4.6 {TclCreateProc, procbody obj, inconsistent arg default type} -body { proc p {x y z} { set v [join [list $x $y $z]] set w [string tolower $v] return "$v:$w" } set rv [p P Q R] procbodytest::proc t {x y {z Z}} p lappend rv [t S T U] } -returnCodes error -constraints procbodytest -cleanup { catch {rename p ""} catch {rename t ""} } -result {procedure "t": formal parameter "z" has argument spec inconsistent with precompiled body} test proc-4.7 {TclCreateProc, procbody obj, inconsistent arg default value} -body { proc p {x y {z Z}} { set v [join [list $x $y $z]] set w [string tolower $v] return "$v:$w" } set rv [p P Q R] procbodytest::proc t {x y {z ZZ}} p lappend rv [t S T U] } -constraints procbodytest -returnCodes error -cleanup { catch {rename p ""} catch {rename t ""} } -result {procedure "t": formal parameter "z" has argument spec inconsistent with precompiled body} test proc-4.8 {TclCreateProc, procbody obj, no leak on multiple iterations} -setup { proc getbytes {} { set lines [split [memory info] "\n"] lindex $lines 3 3 } proc px x { set y [string tolower $x] |
︙ | ︙ |