From aa4274da58363cc82765a9eba3e5f3a957573041 Mon Sep 17 00:00:00 2001 From: dgp Date: Thu, 8 Nov 2012 15:25:30 +0000 Subject: Create Tcl 8.6.0 release branch --- README | 2 +- generic/tcl.h | 6 +++--- library/init.tcl | 2 +- unix/configure | 2 +- unix/configure.in | 2 +- unix/tcl.spec | 2 +- win/configure | 2 +- win/configure.in | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README b/README index 56f7e38..f8965b4 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ README: Tcl - This is the Tcl 8.6b3 source distribution. + This is the Tcl 8.6.0 source distribution. http://tcl.sourceforge.net/ You can get any source release of Tcl from the file distributions link at the above URL. diff --git a/generic/tcl.h b/generic/tcl.h index 5f6146e..d765967 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -55,11 +55,11 @@ extern "C" { #define TCL_MAJOR_VERSION 8 #define TCL_MINOR_VERSION 6 -#define TCL_RELEASE_LEVEL TCL_BETA_RELEASE -#define TCL_RELEASE_SERIAL 3 +#define TCL_RELEASE_LEVEL TCL_FINAL_RELEASE +#define TCL_RELEASE_SERIAL 0 #define TCL_VERSION "8.6" -#define TCL_PATCH_LEVEL "8.6b3" +#define TCL_PATCH_LEVEL "8.6.0" /* *---------------------------------------------------------------------------- diff --git a/library/init.tcl b/library/init.tcl index 3ec78af..e836df9 100644 --- a/library/init.tcl +++ b/library/init.tcl @@ -15,7 +15,7 @@ if {[info commands package] == ""} { error "version mismatch: library\nscripts expect Tcl version 7.5b1 or later but the loaded version is\nonly [info patchlevel]" } -package require -exact Tcl 8.6b3 +package require -exact Tcl 8.6.0 # Compute the auto path to use in this interpreter. # The values on the path come from several locations: diff --git a/unix/configure b/unix/configure index cbb10b4..f778a7b 100755 --- a/unix/configure +++ b/unix/configure @@ -1335,7 +1335,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu TCL_VERSION=8.6 TCL_MAJOR_VERSION=8 TCL_MINOR_VERSION=6 -TCL_PATCH_LEVEL="b3" +TCL_PATCH_LEVEL=".0" VERSION=${TCL_VERSION} #------------------------------------------------------------------------ diff --git a/unix/configure.in b/unix/configure.in index f4b695d..087bb05 100644 --- a/unix/configure.in +++ b/unix/configure.in @@ -25,7 +25,7 @@ m4_ifdef([SC_USE_CONFIG_HEADERS], [ TCL_VERSION=8.6 TCL_MAJOR_VERSION=8 TCL_MINOR_VERSION=6 -TCL_PATCH_LEVEL="b3" +TCL_PATCH_LEVEL=".0" VERSION=${TCL_VERSION} #------------------------------------------------------------------------ diff --git a/unix/tcl.spec b/unix/tcl.spec index 0c42aa4..27f7189 100644 --- a/unix/tcl.spec +++ b/unix/tcl.spec @@ -4,7 +4,7 @@ Name: tcl Summary: Tcl scripting language development environment -Version: 8.6b3 +Version: 8.6.0 Release: 2 License: BSD Group: Development/Languages diff --git a/win/configure b/win/configure index 0258898..03a20b4 100755 --- a/win/configure +++ b/win/configure @@ -1311,7 +1311,7 @@ SHELL=/bin/sh TCL_VERSION=8.6 TCL_MAJOR_VERSION=8 TCL_MINOR_VERSION=6 -TCL_PATCH_LEVEL="b3" +TCL_PATCH_LEVEL=".0" VER=$TCL_MAJOR_VERSION$TCL_MINOR_VERSION TCL_DDE_VERSION=1.4 diff --git a/win/configure.in b/win/configure.in index 0426bb1..b0c007a 100644 --- a/win/configure.in +++ b/win/configure.in @@ -14,7 +14,7 @@ SHELL=/bin/sh TCL_VERSION=8.6 TCL_MAJOR_VERSION=8 TCL_MINOR_VERSION=6 -TCL_PATCH_LEVEL="b3" +TCL_PATCH_LEVEL=".0" VER=$TCL_MAJOR_VERSION$TCL_MINOR_VERSION TCL_DDE_VERSION=1.4 -- cgit v0.12 From ad8ed66c0296f8baa6364cb9704835ca44b83138 Mon Sep 17 00:00:00 2001 From: dgp Date: Thu, 8 Nov 2012 15:43:45 +0000 Subject: Declare TclOO portion of the Tcl API to be stable -> TclOO 1.0 --- generic/tclOO.h | 2 +- tests/oo.test | 2 +- tests/ooNext2.test | 2 +- unix/tclooConfig.sh | 2 +- win/tclooConfig.sh | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/generic/tclOO.h b/generic/tclOO.h index 280481c..cf253b1 100644 --- a/generic/tclOO.h +++ b/generic/tclOO.h @@ -39,7 +39,7 @@ extern const char *TclOOInitializeStubs( * win/tclooConfig.sh */ -#define TCLOO_VERSION "0.7" +#define TCLOO_VERSION "1.0" #define TCLOO_PATCHLEVEL TCLOO_VERSION /* diff --git a/tests/oo.test b/tests/oo.test index 540cdf3..5d34077 100644 --- a/tests/oo.test +++ b/tests/oo.test @@ -7,7 +7,7 @@ # See the file "license.terms" for information on usage and redistribution of # this file, and for a DISCLAIMER OF ALL WARRANTIES. -package require -exact TclOO 0.7 ;# Must match value in generic/tclOO.h +package require TclOO 1.0 package require tcltest 2 if {"::tcltest" in [namespace children]} { namespace import -force ::tcltest::* diff --git a/tests/ooNext2.test b/tests/ooNext2.test index e78e0d0..d77e8d1 100644 --- a/tests/ooNext2.test +++ b/tests/ooNext2.test @@ -7,7 +7,7 @@ # See the file "license.terms" for information on usage and redistribution of # this file, and for a DISCLAIMER OF ALL WARRANTIES. -package require -exact TclOO 0.7 ;# Must match value in configure.in +package require TclOO 1.0 package require tcltest 2 if {"::tcltest" in [namespace children]} { namespace import -force ::tcltest::* diff --git a/unix/tclooConfig.sh b/unix/tclooConfig.sh index dce540a..d2be8dd 100644 --- a/unix/tclooConfig.sh +++ b/unix/tclooConfig.sh @@ -16,4 +16,4 @@ TCLOO_STUB_LIB_SPEC="" TCLOO_INCLUDE_SPEC="" TCLOO_PRIVATE_INCLUDE_SPEC="" TCLOO_CFLAGS=-DUSE_TCLOO_STUBS -TCLOO_VERSION=0.7 +TCLOO_VERSION=1.0 diff --git a/win/tclooConfig.sh b/win/tclooConfig.sh index dce540a..d2be8dd 100644 --- a/win/tclooConfig.sh +++ b/win/tclooConfig.sh @@ -16,4 +16,4 @@ TCLOO_STUB_LIB_SPEC="" TCLOO_INCLUDE_SPEC="" TCLOO_PRIVATE_INCLUDE_SPEC="" TCLOO_CFLAGS=-DUSE_TCLOO_STUBS -TCLOO_VERSION=0.7 +TCLOO_VERSION=1.0 -- cgit v0.12 From 55ceb591d7bd0c530c73961be1c05996e8cc5920 Mon Sep 17 00:00:00 2001 From: dgp Date: Wed, 12 Dec 2012 20:16:13 +0000 Subject: Prefer to extract package data from the *contents* not the directory name. --- pkgs/package.list.txt | 2 +- tools/tcltk-man2html.tcl | 57 +++++++++++++++++++++++++++++++++++++++++------- unix/Makefile.in | 3 +-- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/pkgs/package.list.txt b/pkgs/package.list.txt index f12111d..a13b0fb 100644 --- a/pkgs/package.list.txt +++ b/pkgs/package.list.txt @@ -23,4 +23,4 @@ TDBC TDBC tdbcmysql tdbc::mysql tdbcodbc tdbc::odbc tdbcpostgres tdbc::postgres -tdbcsqlite3- tdbc::sqlite3 +tdbcsqlite3 tdbc::sqlite3 diff --git a/tools/tcltk-man2html.tcl b/tools/tcltk-man2html.tcl index 270a774..f392bce 100755 --- a/tools/tcltk-man2html.tcl +++ b/tools/tcltk-man2html.tcl @@ -461,18 +461,15 @@ proc plus-pkgs {type args} { if {!$build_tcl} return set result {} set pkgsdir $tcltkdir/$tcldir/pkgs - foreach {dir name} $args { - set globpat $pkgsdir/{$dir,$dir\[0-9\]*}/doc/*.$type + foreach {dir name version} $args { + set globpat $pkgsdir/$dir/doc/*.$type if {![llength [glob -type f -nocomplain $globpat]]} { # Fallback for manpages generated using doctools - set globpat $pkgsdir/{$dir,$dir\[0-9\]*}/doc/man/*.$type + set globpat $pkgsdir/$dir/doc/man/*.$type if {![llength [glob -type f -nocomplain $globpat]]} { continue } } - regexp "pkgs/${dir}(.*)/doc$" \ - [lindex [glob -type d $pkgsdir/{$dir,$dir\[0-9\]*}/doc] 0] \ - -> version switch $type { n { set title "$name Package Commands" @@ -650,6 +647,42 @@ try { append appdir "$tkdir" } + + # When building docs for Tcl, try to build docs for bundled packages too + set packageBuildList {} + if {$build_tcl} { + set pkgsDir [file join $tcltkdir $tcldir pkgs] + set subdirs [glob -nocomplain -types d -tails -directory $pkgsDir *] + + foreach dir [lsort $subdirs] { + # Parse the subdir name into (name, version) as fallback... + set description [split $dir -] + if {2 != [llength $description]} { + regexp {([^0-9]*)(.*)} $dir -> n v + set description [list $n $v] + } + + # ... but try to extract (name, version) from subdir contents + try { + set f [open [file join $pkgsDir $dir configure.in]] + foreach line [split [read $f] \n] { + if {2 == [scan $line \ + { AC_INIT ( [%[^]]] , [%[^]]] ) } n v]} { + set description [list $n $v] + break + } + } + } finally { + catch {close $f; unset f} + } + + if {[file exists [file join $pkgsDir $dir configure]]} { + # Looks like a package, record our best extraction attempt + lappend packageBuildList $dir {*}$description + } + } + } + # Get the list of packages to try, and what their human-readable names # are. Note that the package directory list should be version-less. try { @@ -674,6 +707,14 @@ try { } } + # Convert to human readable names, if applicable + for {set idx 0} {$idx < [llength $packageBuildList]} {incr idx 3} { + lassign [lrange $packageBuildList $idx $idx+2] d n v + if {[dict exists $packageDirNameMap $n]} { + lset packageBuildList $idx+1 [dict get $packageDirNameMap $n] + } + } + # # Invoke the scraper/converter engine. # @@ -684,12 +725,12 @@ try { "The commands which the tclsh interpreter implements."] \ [plus-base $build_tk $tkdir doc/*.n {Tk Commands} TkCmd \ "The additional commands which the wish interpreter implements."] \ - {*}[plus-pkgs n {*}$packageDirNameMap] \ + {*}[plus-pkgs n {*}$packageBuildList] \ [plus-base $build_tcl $tcldir doc/*.3 {Tcl C API} TclLib \ "The C functions which a Tcl extended C program may use."] \ [plus-base $build_tk $tkdir doc/*.3 {Tk C API} TkLib \ "The additional C functions which a Tk extended C program may use."] \ - {*}[plus-pkgs 3 {*}$packageDirNameMap] + {*}[plus-pkgs 3 {*}$packageBuildList] } on error {msg opts} { # On failure make sure we show what went wrong. We're not supposed # to get here though; it represents a bug in the script. diff --git a/unix/Makefile.in b/unix/Makefile.in index 680d4ce..df05759 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -2019,8 +2019,7 @@ dist: $(UNIX_DIR)/configure $(UNIX_DIR)/tclConfig.h.in $(UNIX_DIR)/tcl.pc.in $(M cp -p $(TOMMATH_SRCS) $(TOMMATH_DIR)/*.h \ $(DISTDIR)/libtommath mkdir $(DISTDIR)/pkgs - cp $(TOP_DIR)/pkgs/README $(TOP_DIR)/pkgs/package.list.txt \ - $(DISTDIR)/pkgs + cp $(TOP_DIR)/pkgs/README $(DISTDIR)/pkgs for i in `ls $(DISTROOT)/pkgs/*.tar.gz 2> /dev/null`; do \ tar -C $(DISTDIR)/pkgs -xzf "$$i"; \ done -- cgit v0.12 From b59e26b4ebf4d75131241be768955f8ae29e498f Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 21 Dec 2012 08:16:50 +0000 Subject: Turn pkgb.so into a Tcl9 interoperability test library: Whatever Tcl9 looks like, loading pkgb.so in Tcl 9 should either result in an error-message, either succeed, but never crash. Eliminate unnessarcy static HasStubSupport() and isDigit() functions, just do the same inline. --- ChangeLog | 8 ++++++ generic/tclStubLib.c | 33 +++++++---------------- unix/dltest/pkgb.c | 76 ++++++++++++++++++++++++++++------------------------ 3 files changed, 58 insertions(+), 59 deletions(-) diff --git a/ChangeLog b/ChangeLog index 092d5f9..204275f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2012-12-21 Jan Nijtmans + + * unix/dltest/pkgb.c: Turn pkgb.so into a Tcl9 interoperability test + library: Whatever Tcl9 looks like, loading pkgb.so in Tcl 9 should + either result in an error-message, either succeed, but never crash. + * generic/tclStubLib.c: Eliminate unnessarcy static HasStubSupport() and + isDigit() functions, just do the same inline. + 2012-12-13 Jan Nijtmans * generic/tcl.h: Fix Tcl_DecrRefCount macro such that it diff --git a/generic/tclStubLib.c b/generic/tclStubLib.c index ceee8f3..7b62f5e 100644 --- a/generic/tclStubLib.c +++ b/generic/tclStubLib.c @@ -19,28 +19,11 @@ TclPlatStubs *tclPlatStubsPtr = NULL; TclIntStubs *tclIntStubsPtr = NULL; TclIntPlatStubs *tclIntPlatStubsPtr = NULL; -static TclStubs * -HasStubSupport(interp) - Tcl_Interp *interp; -{ - Interp *iPtr = (Interp *) interp; - - if (iPtr->stubTable && (iPtr->stubTable->magic == TCL_STUB_MAGIC)) { - return iPtr->stubTable; - } - interp->result = "interpreter uses an incompatible stubs mechanism"; - interp->freeProc = TCL_STATIC; - return NULL; -} - /* - * Use our own isdigit to avoid linking to libc on windows + * Use our own ISDIGIT to avoid linking to libc on windows */ -static int isDigit(const int c) -{ - return (c >= '0' && c <= '9'); -} +#define ISDIGIT(c) (((unsigned)((c)-'0')) <= 9) /* *---------------------------------------------------------------------- @@ -66,9 +49,10 @@ Tcl_InitStubs(interp, version, exact) CONST char *version; int exact; { + Interp *iPtr = (Interp *) interp; CONST char *actualVersion = NULL; ClientData pkgData = NULL; - TclStubs *stubsPtr; + TclStubs *stubsPtr = iPtr->stubTable; /* * We can't optimize this check by caching tclStubsPtr because that @@ -76,8 +60,9 @@ Tcl_InitStubs(interp, version, exact) * times. [Bug 615304] */ - stubsPtr = HasStubSupport(interp); - if (!stubsPtr) { + if (!stubsPtr || (stubsPtr->magic != TCL_STUB_MAGIC)) { + iPtr->result = "interpreter uses an incompatible stubs mechanism"; + iPtr->freeProc = TCL_STATIC; return NULL; } @@ -90,7 +75,7 @@ Tcl_InitStubs(interp, version, exact) int count = 0; while (*p) { - count += !isDigit(*p++); + count += !ISDIGIT(*p++); } if (count == 1) { CONST char *q = actualVersion; @@ -99,7 +84,7 @@ Tcl_InitStubs(interp, version, exact) while (*p && (*p == *q)) { p++; q++; } - if (*p || isDigit(*q)) { + if (*p || ISDIGIT(*q)) { /* Construct error message */ stubsPtr->tcl_PkgRequireEx(interp, "Tcl", version, 1, NULL); return NULL; diff --git a/unix/dltest/pkgb.c b/unix/dltest/pkgb.c index d7a7e5b..0bff98b 100644 --- a/unix/dltest/pkgb.c +++ b/unix/dltest/pkgb.c @@ -1,15 +1,16 @@ -/* +/* * pkgb.c -- * - * This file contains a simple Tcl package "pkgb" that is intended - * for testing the Tcl dynamic loading facilities. It can be used - * in both safe and unsafe interpreters. + * This file contains a simple Tcl package "pkgb" that is intended for + * testing the Tcl dynamic loading facilities. It can be used in both + * safe and unsafe interpreters. * * Copyright (c) 1995 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ + #include "tcl.h" /* @@ -17,17 +18,17 @@ */ static int Pkgb_SubObjCmd _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[])); + Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])); static int Pkgb_UnsafeObjCmd _ANSI_ARGS_((ClientData clientData, - Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[])); + Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])); /* *---------------------------------------------------------------------- * * Pkgb_SubObjCmd -- * - * This procedure is invoked to process the "pkgb_sub" Tcl command. - * It expects two arguments and returns their difference. + * This procedure is invoked to process the "pkgb_sub" Tcl command. It + * expects two arguments and returns their difference. * * Results: * A standard Tcl result. @@ -43,17 +44,17 @@ Pkgb_SubObjCmd(dummy, interp, objc, objv) ClientData dummy; /* Not used. */ Tcl_Interp *interp; /* Current interpreter. */ int objc; /* Number of arguments. */ - Tcl_Obj * CONST objv[]; /* Argument objects. */ + Tcl_Obj *CONST objv[]; /* Argument objects. */ { int first, second; if (objc != 3) { Tcl_WrongNumArgs(interp, 1, objv, "num num"); - return TCL_ERROR; + return TCL_ERROR; } if ((Tcl_GetIntFromObj(interp, objv[1], &first) != TCL_OK) || (Tcl_GetIntFromObj(interp, objv[2], &second) != TCL_OK)) { - return TCL_ERROR; + return TCL_ERROR; } Tcl_SetObjResult(interp, Tcl_NewIntObj(first - second)); return TCL_OK; @@ -64,8 +65,8 @@ Pkgb_SubObjCmd(dummy, interp, objc, objv) * * Pkgb_UnsafeObjCmd -- * - * This procedure is invoked to process the "pkgb_unsafe" Tcl command. - * It just returns a constant string. + * This procedure is invoked to process the "pkgb_unsafe" Tcl command. It + * just returns a constant string. * * Results: * A standard Tcl result. @@ -81,10 +82,9 @@ Pkgb_UnsafeObjCmd(dummy, interp, objc, objv) ClientData dummy; /* Not used. */ Tcl_Interp *interp; /* Current interpreter. */ int objc; /* Number of arguments. */ - Tcl_Obj * CONST objv[]; /* Argument objects. */ + Tcl_Obj *CONST objv[]; /* Argument objects. */ { - Tcl_SetObjResult(interp, Tcl_NewStringObj("unsafe command invoked", -1)); - return TCL_OK; + return Tcl_EvalEx(interp, "list unsafe command invoked", -1, TCL_EVAL_GLOBAL); } /* @@ -92,8 +92,8 @@ Pkgb_UnsafeObjCmd(dummy, interp, objc, objv) * * Pkgb_Init -- * - * This is a package initialization procedure, which is called - * by Tcl when this package is to be added to an interpreter. + * This is a package initialization procedure, which is called by Tcl + * when this package is to be added to an interpreter. * * Results: * None. @@ -104,17 +104,20 @@ Pkgb_UnsafeObjCmd(dummy, interp, objc, objv) *---------------------------------------------------------------------- */ -int +DLLEXPORT int Pkgb_Init(interp) - Tcl_Interp *interp; /* Interpreter in which the package is - * to be made available. */ + Tcl_Interp *interp; /* Interpreter in which the package is to be + * made available. */ { int code; - if (Tcl_InitStubs(interp, TCL_VERSION, 1) == NULL) { - return TCL_ERROR; + if (Tcl_InitStubs(interp, "8.4", 0) == NULL) { + if (Tcl_InitStubs(interp, "8.4-", 0) == NULL) { + return TCL_ERROR; + } + Tcl_ResetResult(interp); } - code = Tcl_PkgProvide(interp, "Pkgb", "2.3"); + code = Tcl_PkgProvideEx(interp, "Pkgb", "2.3", NULL); if (code != TCL_OK) { return code; } @@ -130,8 +133,8 @@ Pkgb_Init(interp) * * Pkgb_SafeInit -- * - * This is a package initialization procedure, which is called - * by Tcl when this package is to be added to an unsafe interpreter. + * This is a package initialization procedure, which is called by Tcl + * when this package is to be added to a safe interpreter. * * Results: * None. @@ -142,19 +145,22 @@ Pkgb_Init(interp) *---------------------------------------------------------------------- */ -int +DLLEXPORT int Pkgb_SafeInit(interp) - Tcl_Interp *interp; /* Interpreter in which the package is - * to be made available. */ + Tcl_Interp *interp; /* Interpreter in which the package is to be + * made available. */ { int code; - if (Tcl_InitStubs(interp, TCL_VERSION, 1) == NULL) { - return TCL_ERROR; + if (Tcl_InitStubs(interp, "8.4", 0) == NULL) { + if (Tcl_InitStubs(interp, "8.4-", 0) == NULL) { + return TCL_ERROR; + } + Tcl_ResetResult(interp); } - code = Tcl_PkgProvide(interp, "Pkgb", "2.3"); + code = Tcl_PkgProvideEx(interp, "Pkgb", "2.3", NULL); if (code != TCL_OK) { - return code; + return code; } Tcl_CreateObjCommand(interp, "pkgb_sub", Pkgb_SubObjCmd, (ClientData) 0, (Tcl_CmdDeleteProc *) NULL); -- cgit v0.12 From a40590fd31db326000458a35d4bff19a8f7a3b4d Mon Sep 17 00:00:00 2001 From: ferrieux Date: Sat, 22 Dec 2012 19:05:34 +0000 Subject: Stop leaking allocated space when objifying a zero-length DString. [Bug 3598150] spotted by afredd. --- ChangeLog | 5 +++++ generic/tclUtil.c | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 336da37..49da827 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-12-22 Alexandre Ferrieux + + * generic/tclUtil.c: Stop leaking allocated space when objifying a + zero-length DString. [Bug 3598150] spotted by afredd. + 2012-12-21 Jan Nijtmans * unix/dltest/pkgb.c: Inline compat Tcl_GetDefaultEncodingDir. diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 13e54ec..ddf067b 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -2927,14 +2927,16 @@ TclDStringToObj( { Tcl_Obj *result; - if (dsPtr->length == 0) { - TclNewObj(result); - } else if (dsPtr->string == dsPtr->staticSpace) { - /* - * Static buffer, so must copy. - */ - - TclNewStringObj(result, dsPtr->string, dsPtr->length); + if (dsPtr->string == dsPtr->staticSpace) { + if (dsPtr->length == 0) { + TclNewObj(result); + } else { + /* + * Static buffer, so must copy. + */ + + TclNewStringObj(result, dsPtr->string, dsPtr->length); + } } else { /* * Dynamic buffer, so transfer ownership and reset. -- cgit v0.12 From 42c352d6258bc3ec26c19183c29b5a4ac4301a81 Mon Sep 17 00:00:00 2001 From: dkf Date: Sun, 23 Dec 2012 08:17:17 +0000 Subject: Change back to using an isDigit function. We simply don't need to make any (formally non-portable) assumptions about what happens when an unsigned zero is decremented, and the code isn't in a performance-critical area. Remark by jan.nijtmans: The macro is perfectly portable! Not portable is the exact result of the substraction ('\xB0' - '0' might give 0x80 on some platforms and 0xffffff80 on others), but comparing <= 9 always gives the correct result. We are only checking for digits here! The macro correctly inlines with any compiler, so it's better anyway. Remark by dkf: But it's less clear. In this code, that's more important than a teeny bit of speed from inlining in a non-critical location. --- generic/tclStubLib.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/generic/tclStubLib.c b/generic/tclStubLib.c index f61e0ca..859cbf9 100644 --- a/generic/tclStubLib.c +++ b/generic/tclStubLib.c @@ -24,10 +24,13 @@ const TclIntStubs *tclIntStubsPtr = NULL; const TclIntPlatStubs *tclIntPlatStubsPtr = NULL; /* - * Use our own ISDIGIT to avoid linking to libc on windows + * Use our own isDigit to avoid linking to libc on windows */ -#define ISDIGIT(c) (((unsigned)((c)-'0')) <= 9) +static int isDigit(const int c) +{ + return (c >= '0' && c <= '9'); +} /* *---------------------------------------------------------------------- @@ -79,7 +82,7 @@ Tcl_InitStubs( int count = 0; while (*p) { - count += !ISDIGIT(*p++); + count += !isDigit(*p++); } if (count == 1) { const char *q = actualVersion; @@ -88,7 +91,7 @@ Tcl_InitStubs( while (*p && (*p == *q)) { p++; q++; } - if (*p || ISDIGIT(*q)) { + if (*p || isDigit(*q)) { /* Construct error message */ stubsPtr->tcl_PkgRequireEx(interp, "Tcl", version, 1, NULL); return NULL; -- cgit v0.12 From d525cce307b002900a04c58a4adff1470f24202c Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 26 Dec 2012 09:55:45 +0000 Subject: eliminate dependancy of compat/*.h on tcl.h --- compat/dirent2.h | 10 ++--- compat/dlfcn.h | 19 ++++------ compat/stdlib.h | 51 +++++++++++-------------- compat/string.h | 74 +++++++++++++++--------------------- compat/unistd.h | 112 ++++++++++++++++++++++++++----------------------------- 5 files changed, 115 insertions(+), 151 deletions(-) diff --git a/compat/dirent2.h b/compat/dirent2.h index c00d2f4..5be08ba 100644 --- a/compat/dirent2.h +++ b/compat/dirent2.h @@ -14,10 +14,6 @@ #ifndef _DIRENT #define _DIRENT -#ifndef _TCL -#include -#endif - /* * Dirent structure, which holds information about a single * directory entry. @@ -50,8 +46,8 @@ typedef struct _dirdesc { * Procedures defined for reading directories: */ -extern void closedir _ANSI_ARGS_((DIR *dirp)); -extern DIR * opendir _ANSI_ARGS_((char *name)); -extern struct dirent * readdir _ANSI_ARGS_((DIR *dirp)); +extern void closedir (DIR *dirp); +extern DIR * opendir (char *name); +extern struct dirent * readdir (DIR *dirp); #endif /* _DIRENT */ diff --git a/compat/dlfcn.h b/compat/dlfcn.h index 1a6a118..fb27ea0 100644 --- a/compat/dlfcn.h +++ b/compat/dlfcn.h @@ -1,4 +1,4 @@ -/* +/* * dlfcn.h -- * * This file provides a replacement for the header file "dlfcn.h" @@ -19,7 +19,6 @@ */ /* - * @(#)dlfcn.h 1.4 revision of 95/04/25 09:36:52 * This is an unpublished work copyright (c) 1992 HELIOS Software GmbH * 30159 Hannover, Germany */ @@ -27,10 +26,6 @@ #ifndef __dlfcn_h__ #define __dlfcn_h__ -#ifndef _TCL -#include -#endif - #ifdef __cplusplus extern "C" { #endif @@ -47,14 +42,14 @@ extern "C" { * that contains functions to be called to initialize and terminate. */ struct dl_info { - void (*init) _ANSI_ARGS_((void)); - void (*fini) _ANSI_ARGS_((void)); + void (*init) (void); + void (*fini) (void); }; -VOID *dlopen _ANSI_ARGS_((const char *path, int mode)); -VOID *dlsym _ANSI_ARGS_((void *handle, const char *symbol)); -char *dlerror _ANSI_ARGS_((void)); -int dlclose _ANSI_ARGS_((void *handle)); +void *dlopen (const char *path, int mode); +void *dlsym (void *handle, const char *symbol); +char *dlerror (void); +int dlclose (void *handle); #ifdef __cplusplus } diff --git a/compat/stdlib.h b/compat/stdlib.h index 4d1a386..0ad4c1d 100644 --- a/compat/stdlib.h +++ b/compat/stdlib.h @@ -1,43 +1,36 @@ /* * stdlib.h -- * - * Declares facilities exported by the "stdlib" portion of - * the C library. This file isn't complete in the ANSI-C - * sense; it only declares things that are needed by Tcl. - * This file is needed even on many systems with their own - * stdlib.h (e.g. SunOS) because not all stdlib.h files - * declare all the procedures needed here (such as strtod). + * Declares facilities exported by the "stdlib" portion of the C library. + * This file isn't complete in the ANSI-C sense; it only declares things + * that are needed by Tcl. This file is needed even on many systems with + * their own stdlib.h (e.g. SunOS) because not all stdlib.h files declare + * all the procedures needed here (such as strtod). * * Copyright (c) 1991 The Regents of the University of California. * Copyright (c) 1994-1998 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #ifndef _STDLIB #define _STDLIB -#include - -extern void abort _ANSI_ARGS_((void)); -extern double atof _ANSI_ARGS_((CONST char *string)); -extern int atoi _ANSI_ARGS_((CONST char *string)); -extern long atol _ANSI_ARGS_((CONST char *string)); -extern char * calloc _ANSI_ARGS_((unsigned int numElements, - unsigned int size)); -extern void exit _ANSI_ARGS_((int status)); -extern int free _ANSI_ARGS_((char *blockPtr)); -extern char * getenv _ANSI_ARGS_((CONST char *name)); -extern char * malloc _ANSI_ARGS_((unsigned int numBytes)); -extern void qsort _ANSI_ARGS_((VOID *base, int n, int size, - int (*compar)(CONST VOID *element1, CONST VOID - *element2))); -extern char * realloc _ANSI_ARGS_((char *ptr, unsigned int numBytes)); -extern double strtod _ANSI_ARGS_((CONST char *string, char **endPtr)); -extern long strtol _ANSI_ARGS_((CONST char *string, char **endPtr, - int base)); -extern unsigned long strtoul _ANSI_ARGS_((CONST char *string, - char **endPtr, int base)); +extern void abort(void); +extern double atof(const char *string); +extern int atoi(const char *string); +extern long atol(const char *string); +extern char * calloc(unsigned int numElements, unsigned int size); +extern void exit(int status); +extern int free(char *blockPtr); +extern char * getenv(const char *name); +extern char * malloc(unsigned int numBytes); +extern void qsort(void *base, int n, int size, int (*compar)( + const void *element1, const void *element2)); +extern char * realloc(char *ptr, unsigned int numBytes); +extern double strtod(const char *string, char **endPtr); +extern long strtol(const char *string, char **endPtr, int base); +extern unsigned long strtoul(const char *string, char **endPtr, int base); #endif /* _STDLIB */ diff --git a/compat/string.h b/compat/string.h index 4eb2b86..42be10c 100644 --- a/compat/string.h +++ b/compat/string.h @@ -6,66 +6,52 @@ * Copyright (c) 1991-1993 The Regents of the University of California. * Copyright (c) 1994-1996 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #ifndef _STRING #define _STRING -#include - /* - * The following #include is needed to define size_t. (This used to - * include sys/stdtypes.h but that doesn't exist on older versions - * of SunOS, e.g. 4.0.2, so I'm trying sys/types.h now.... hopefully - * it exists everywhere) + * The following #include is needed to define size_t. (This used to include + * sys/stdtypes.h but that doesn't exist on older versions of SunOS, e.g. + * 4.0.2, so I'm trying sys/types.h now.... hopefully it exists everywhere) */ #include #ifdef __APPLE__ -extern VOID * memchr _ANSI_ARGS_((CONST VOID *s, int c, size_t n)); +extern void * memchr(const void *s, int c, size_t n); #else -extern char * memchr _ANSI_ARGS_((CONST VOID *s, int c, size_t n)); +extern char * memchr(const void *s, int c, size_t n); #endif -extern int memcmp _ANSI_ARGS_((CONST VOID *s1, CONST VOID *s2, - size_t n)); -extern char * memcpy _ANSI_ARGS_((VOID *t, CONST VOID *f, size_t n)); +extern int memcmp(const void *s1, const void *s2, size_t n); +extern char * memcpy(void *t, const void *f, size_t n); #ifdef NO_MEMMOVE -#define memmove(d, s, n) bcopy ((s), (d), (n)) +#define memmove(d,s,n) (bcopy((s), (d), (n))) #else -extern char * memmove _ANSI_ARGS_((VOID *t, CONST VOID *f, - size_t n)); +extern char * memmove(void *t, const void *f, size_t n); #endif -extern char * memset _ANSI_ARGS_((VOID *s, int c, size_t n)); +extern char * memset(void *s, int c, size_t n); -extern int strcasecmp _ANSI_ARGS_((CONST char *s1, - CONST char *s2)); -extern char * strcat _ANSI_ARGS_((char *dst, CONST char *src)); -extern char * strchr _ANSI_ARGS_((CONST char *string, int c)); -extern int strcmp _ANSI_ARGS_((CONST char *s1, CONST char *s2)); -extern char * strcpy _ANSI_ARGS_((char *dst, CONST char *src)); -extern size_t strcspn _ANSI_ARGS_((CONST char *string, - CONST char *chars)); -extern char * strdup _ANSI_ARGS_((CONST char *string)); -extern char * strerror _ANSI_ARGS_((int error)); -extern size_t strlen _ANSI_ARGS_((CONST char *string)); -extern int strncasecmp _ANSI_ARGS_((CONST char *s1, - CONST char *s2, size_t n)); -extern char * strncat _ANSI_ARGS_((char *dst, CONST char *src, - size_t numChars)); -extern int strncmp _ANSI_ARGS_((CONST char *s1, CONST char *s2, - size_t nChars)); -extern char * strncpy _ANSI_ARGS_((char *dst, CONST char *src, - size_t numChars)); -extern char * strpbrk _ANSI_ARGS_((CONST char *string, - CONST char *chars)); -extern char * strrchr _ANSI_ARGS_((CONST char *string, int c)); -extern size_t strspn _ANSI_ARGS_((CONST char *string, - CONST char *chars)); -extern char * strstr _ANSI_ARGS_((CONST char *string, - CONST char *substring)); -extern char * strtok _ANSI_ARGS_((char *s, CONST char *delim)); +extern int strcasecmp(const char *s1, const char *s2); +extern char * strcat(char *dst, const char *src); +extern char * strchr(const char *string, int c); +extern int strcmp(const char *s1, const char *s2); +extern char * strcpy(char *dst, const char *src); +extern size_t strcspn(const char *string, const char *chars); +extern char * strdup(const char *string); +extern char * strerror(int error); +extern size_t strlen(const char *string); +extern int strncasecmp(const char *s1, const char *s2, size_t n); +extern char * strncat(char *dst, const char *src, size_t numChars); +extern int strncmp(const char *s1, const char *s2, size_t nChars); +extern char * strncpy(char *dst, const char *src, size_t numChars); +extern char * strpbrk(const char *string, const char *chars); +extern char * strrchr(const char *string, int c); +extern size_t strspn(const char *string, const char *chars); +extern char * strstr(const char *string, const char *substring); +extern char * strtok(char *s, const char *delim); #endif /* _STRING */ diff --git a/compat/unistd.h b/compat/unistd.h index 1a40e90..2de5bd0 100644 --- a/compat/unistd.h +++ b/compat/unistd.h @@ -1,82 +1,76 @@ /* * unistd.h -- * - * Macros, CONSTants and prototypes for Posix conformance. + * Macros, constants and prototypes for Posix conformance. * - * Copyright 1989 Regents of the University of California - * Permission to use, copy, modify, and distribute this - * software and its documentation for any purpose and without - * fee is hereby granted, provided that the above copyright - * notice appear in all copies. The University of California - * makes no representations about the suitability of this - * software for any purpose. It is provided "as is" without - * express or implied warranty. + * Copyright 1989 Regents of the University of California Permission to use, + * copy, modify, and distribute this software and its documentation for any + * purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies. The University of California makes + * no representations about the suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. */ #ifndef _UNISTD #define _UNISTD #include -#ifndef _TCL -# include "tcl.h" -#endif #ifndef NULL #define NULL 0 #endif /* - * Strict POSIX stuff goes here. Extensions go down below, in the - * ifndef _POSIX_SOURCE section. + * Strict POSIX stuff goes here. Extensions go down below, in the ifndef + * _POSIX_SOURCE section. */ -extern void _exit _ANSI_ARGS_((int status)); -extern int access _ANSI_ARGS_((CONST char *path, int mode)); -extern int chdir _ANSI_ARGS_((CONST char *path)); -extern int chown _ANSI_ARGS_((CONST char *path, uid_t owner, gid_t group)); -extern int close _ANSI_ARGS_((int fd)); -extern int dup _ANSI_ARGS_((int oldfd)); -extern int dup2 _ANSI_ARGS_((int oldfd, int newfd)); -extern int execl _ANSI_ARGS_((CONST char *path, ...)); -extern int execle _ANSI_ARGS_((CONST char *path, ...)); -extern int execlp _ANSI_ARGS_((CONST char *file, ...)); -extern int execv _ANSI_ARGS_((CONST char *path, char **argv)); -extern int execve _ANSI_ARGS_((CONST char *path, char **argv, char **envp)); -extern int execvp _ANSI_ARGS_((CONST char *file, char **argv)); -extern pid_t fork _ANSI_ARGS_((void)); -extern char *getcwd _ANSI_ARGS_((char *buf, size_t size)); -extern gid_t getegid _ANSI_ARGS_((void)); -extern uid_t geteuid _ANSI_ARGS_((void)); -extern gid_t getgid _ANSI_ARGS_((void)); -extern int getgroups _ANSI_ARGS_((int bufSize, int *buffer)); -extern pid_t getpid _ANSI_ARGS_((void)); -extern uid_t getuid _ANSI_ARGS_((void)); -extern int isatty _ANSI_ARGS_((int fd)); -extern long lseek _ANSI_ARGS_((int fd, long offset, int whence)); -extern int pipe _ANSI_ARGS_((int *fildes)); -extern int read _ANSI_ARGS_((int fd, char *buf, size_t size)); -extern int setgid _ANSI_ARGS_((gid_t group)); -extern int setuid _ANSI_ARGS_((uid_t user)); -extern unsigned sleep _ANSI_ARGS_ ((unsigned seconds)); -extern char *ttyname _ANSI_ARGS_((int fd)); -extern int unlink _ANSI_ARGS_((CONST char *path)); -extern int write _ANSI_ARGS_((int fd, CONST char *buf, size_t size)); +extern void _exit(int status); +extern int access(const char *path, int mode); +extern int chdir(const char *path); +extern int chown(const char *path, uid_t owner, gid_t group); +extern int close(int fd); +extern int dup(int oldfd); +extern int dup2(int oldfd, int newfd); +extern int execl(const char *path, ...); +extern int execle(const char *path, ...); +extern int execlp(const char *file, ...); +extern int execv(const char *path, char **argv); +extern int execve(const char *path, char **argv, char **envp); +extern int execvpw(const char *file, char **argv); +extern pid_t fork(void); +extern char * getcwd(char *buf, size_t size); +extern gid_t getegid(void); +extern uid_t geteuid(void); +extern gid_t getgid(void); +extern int getgroups(int bufSize, int *buffer); +extern pid_t getpid(void); +extern uid_t getuid(void); +extern int isatty(int fd); +extern long lseek(int fd, long offset, int whence); +extern int pipe(int *fildes); +extern int read(int fd, char *buf, size_t size); +extern int setgid(gid_t group); +extern int setuid(uid_t user); +extern unsigned sleep(unsigned seconds); +extern char * ttyname(int fd); +extern int unlink(const char *path); +extern int write(int fd, const char *buf, size_t size); #ifndef _POSIX_SOURCE -extern char *crypt _ANSI_ARGS_((CONST char *, CONST char *)); -extern int fchown _ANSI_ARGS_((int fd, uid_t owner, gid_t group)); -extern int flock _ANSI_ARGS_((int fd, int operation)); -extern int ftruncate _ANSI_ARGS_((int fd, unsigned long length)); -extern int ioctl _ANSI_ARGS_((int fd, int request, ...)); -extern int readlink _ANSI_ARGS_((CONST char *path, char *buf, int bufsize)); -extern int setegid _ANSI_ARGS_((gid_t group)); -extern int seteuid _ANSI_ARGS_((uid_t user)); -extern int setreuid _ANSI_ARGS_((int ruid, int euid)); -extern int symlink _ANSI_ARGS_((CONST char *, CONST char *)); -extern int ttyslot _ANSI_ARGS_((void)); -extern int truncate _ANSI_ARGS_((CONST char *path, unsigned long length)); -extern int vfork _ANSI_ARGS_((void)); +extern char * crypt(const char *, const char *); +extern int fchown(int fd, uid_t owner, gid_t group); +extern int flock(int fd, int operation); +extern int ftruncate(int fd, unsigned long length); +extern int ioctl(int fd, int request, ...); +extern int readlink(const char *path, char *buf, int bufsize); +extern int setegid(gid_t group); +extern int seteuidw(uid_t user); +extern int setreuid(int ruid, int euid); +extern int symlink(const char *, const char *); +extern int ttyslot(void); +extern int truncate(const char *path, unsigned long length); +extern int vfork(void); #endif /* _POSIX_SOURCE */ #endif /* _UNISTD */ - -- cgit v0.12 From 20253b8c7d3f3c59314380703be48df859cdf9e6 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 27 Dec 2012 14:41:15 +0000 Subject: [Bug 3598580]: Tcl_ListObjReplace may release deleted elements too early Tests!? Where are the tests!?! They are in test listobj-11.1 --- ChangeLog | 5 +++++ generic/tclListObj.c | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 204275f..728b677 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-12-27 Jan Nijtmans + + * generic/tclListObj.c: [Bug 3598580]: Tcl_ListObjReplace may release + deleted elements too early + 2012-12-21 Jan Nijtmans * unix/dltest/pkgb.c: Turn pkgb.so into a Tcl9 interoperability test diff --git a/generic/tclListObj.c b/generic/tclListObj.c index fffe6a2..b4af98a 100644 --- a/generic/tclListObj.c +++ b/generic/tclListObj.c @@ -655,6 +655,10 @@ Tcl_ListObjReplace(interp, listPtr, first, count, objc, objv) count = 0; } + for (i = 0; i < objc; i++) { + Tcl_IncrRefCount(objv[i]); + } + numRequired = (numElems - count + objc); if (numRequired <= listRepPtr->maxElemCount) { /* @@ -689,7 +693,6 @@ Tcl_ListObjReplace(interp, listPtr, first, count, objc, objv) for (i = 0, j = first; i < objc; i++, j++) { elemPtrs[j] = objv[i]; - Tcl_IncrRefCount(objv[i]); } /* @@ -745,7 +748,6 @@ Tcl_ListObjReplace(interp, listPtr, first, count, objc, objv) for (i = 0, j = first; i < objc; i++, j++) { newPtrs[j] = objv[i]; - Tcl_IncrRefCount(objv[i]); } listRepPtr->elemCount = numRequired; -- cgit v0.12 From ac61536f6a47bcbaa93399b81a184f647d62a259 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 27 Dec 2012 20:54:31 +0000 Subject: restore old refcounts in TCL_ERROR case. --- generic/tclListObj.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/generic/tclListObj.c b/generic/tclListObj.c index 1166759..97e7152 100644 --- a/generic/tclListObj.c +++ b/generic/tclListObj.c @@ -906,6 +906,9 @@ Tcl_ListObjReplace( listRepPtr = AttemptNewList(interp, newMax, NULL); if (listRepPtr == NULL) { + for (i = 0; i < objc; i++) { + objv[i]->refCount--; + } return TCL_ERROR; } -- cgit v0.12 From 7523143f3e7c3a026b3addb99bfeb70dd9adaff5 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sat, 29 Dec 2012 00:06:42 +0000 Subject: For Tcl9, do a real Tcl_DecrRefCount --- generic/tclListObj.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/generic/tclListObj.c b/generic/tclListObj.c index 97e7152..5b73a155 100644 --- a/generic/tclListObj.c +++ b/generic/tclListObj.c @@ -907,7 +907,11 @@ Tcl_ListObjReplace( listRepPtr = AttemptNewList(interp, newMax, NULL); if (listRepPtr == NULL) { for (i = 0; i < objc; i++) { +#if TCL_MAJOR_VERSION > 8 + Tcl_DecrRefCount(objv[i]); +#else objv[i]->refCount--; +#endif } return TCL_ERROR; } -- cgit v0.12 From 42b09bbed6f6321e1ef37e138d47cb0a508d3f93 Mon Sep 17 00:00:00 2001 From: dkf Date: Mon, 31 Dec 2012 02:39:40 +0000 Subject: Working towards more efficient treatment of non-bytecoded ensemble subcommands. --- generic/tclCompile.c | 5 ++++ generic/tclCompile.h | 4 ++- generic/tclEnsemble.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++---- generic/tclExecute.c | 57 ++++++++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+), 6 deletions(-) diff --git a/generic/tclCompile.c b/generic/tclCompile.c index 309682d..c052531 100644 --- a/generic/tclCompile.c +++ b/generic/tclCompile.c @@ -529,6 +529,11 @@ InstructionDesc const tclInstructionTable[] = { /* Forces the variable indexed by opnd to be an array. Does not touch * the stack. */ + {"invokeReplace", 5, INT_MIN, 1, {OPERAND_UINT4}}, + /* Invoke command named objv[0], replacing the first two words with + * the word at the top of the stack; + * = */ + {NULL, 0, 0, 0, {OPERAND_NONE}} }; diff --git a/generic/tclCompile.h b/generic/tclCompile.h index 3302f9b..4d8ed65 100644 --- a/generic/tclCompile.h +++ b/generic/tclCompile.h @@ -711,8 +711,10 @@ typedef struct ByteCode { #define INST_ARRAY_MAKE_STK 161 #define INST_ARRAY_MAKE_IMM 162 +#define INST_INVOKE_REPLACE 163 + /* The last opcode */ -#define LAST_INST_OPCODE 162 +#define LAST_INST_OPCODE 163 /* * Table describing the Tcl bytecode instructions: their name (for displaying diff --git a/generic/tclEnsemble.c b/generic/tclEnsemble.c index b76c603..8f0d4fe 100644 --- a/generic/tclEnsemble.c +++ b/generic/tclEnsemble.c @@ -35,6 +35,14 @@ static void MakeCachedEnsembleCommand(Tcl_Obj *objPtr, static void FreeEnsembleCmdRep(Tcl_Obj *objPtr); static void DupEnsembleCmdRep(Tcl_Obj *objPtr, Tcl_Obj *copyPtr); static void StringOfEnsembleCmdRep(Tcl_Obj *objPtr); +static int CompileToCompiledCommand(Tcl_Interp *interp, + Tcl_Parse *parsePtr, Tcl_Token *tokenPtr, + int len, Tcl_Obj **elems, Command *cmdPtr, + CompileEnv *envPtr); +static int CompileToInvokedCommand(Tcl_Interp *interp, + Tcl_Parse *parsePtr, Tcl_Token *tokenPtr, + int len, Tcl_Obj **elems, Command *cmdPtr, + CompileEnv *envPtr); /* * The lists of subcommands and options for the [namespace ensemble] command. @@ -2734,7 +2742,6 @@ TclCompileEnsemble( Tcl_Token *tokenPtr; Tcl_Obj *mapObj, *subcmdObj, *targetCmdObj, *listObj, **elems; Tcl_Command ensemble = (Tcl_Command) cmdPtr; - Tcl_Parse synthetic; int len, result, flags = 0, i; unsigned numBytes; const char *word; @@ -2920,7 +2927,7 @@ TclCompileEnsemble( if (Tcl_ListObjGetElements(NULL, targetCmdObj, &len, &elems) != TCL_OK) { return TCL_ERROR; } - if (len > 1 && Tcl_IsSafe(interp)) { + if (len > 1 || Tcl_IsSafe(interp)) { return TCL_ERROR; } targetCmdObj = elems[0]; @@ -2928,7 +2935,7 @@ TclCompileEnsemble( Tcl_IncrRefCount(targetCmdObj); cmdPtr = (Command *) Tcl_GetCommandFromObj(interp, targetCmdObj); TclDecrRefCount(targetCmdObj); - if (cmdPtr == NULL || cmdPtr->compileProc == NULL + if (cmdPtr == NULL || cmdPtr->nsPtr->flags & NS_SUPPRESS_COMPILATION || cmdPtr->flags * CMD_HAS_EXEC_TRACES || ((Interp *)interp)->flags & DONT_COMPILE_CMDS_INLINE) { @@ -2942,10 +2949,39 @@ TclCompileEnsemble( /* * Now we've done the mapping process, can now actually try to compile. - * We do this by handing off to the subcommand's actual compiler. But to - * do that, we have to perform some trickery to rewrite the arguments. + * If there is a subcommand compiler and that successfully produces code, + * we'll use that. Otherwise, we fall back to generating opcodes to do the + * invoke at runtime. */ + if (cmdPtr->compileProc != NULL && + CompileToCompiledCommand(interp, parsePtr, tokenPtr, + len, elems, cmdPtr, envPtr) == TCL_OK) { + return TCL_OK; + } + return CompileToInvokedCommand(interp, parsePtr, tokenPtr, + len, elems, cmdPtr, envPtr); +} + +/* + * How to compile a subcommand using its own command compiler. To do that, we + * have to perform some trickery to rewrite the arguments, as compilers *must* + * have parse tokens that refer to addresses in the original script. + */ + +static int +CompileToCompiledCommand( + Tcl_Interp *interp, + Tcl_Parse *parsePtr, + Tcl_Token *tokenPtr, + int len, + Tcl_Obj **elems, + Command *cmdPtr, + CompileEnv *envPtr) /* Holds resulting instructions. */ +{ + Tcl_Parse synthetic; + int result, i; + TclParseInit(interp, NULL, 0, &synthetic); synthetic.numWords = parsePtr->numWords - 2 + len; TclGrowParseTokenArray(&synthetic, 2*len); @@ -3001,6 +3037,41 @@ TclCompileEnsemble( Tcl_FreeParse(&synthetic); return result; } + +static int +CompileToInvokedCommand( + Tcl_Interp *interp, + Tcl_Parse *parsePtr, + Tcl_Token *tokenPtr, + int len, + Tcl_Obj **elems, + Command *cmdPtr, + CompileEnv *envPtr) /* Holds resulting instructions. */ +{ + Tcl_Obj *objPtr = Tcl_NewObj(); + char *bytes; + int length, i, literal; + + if (len != 1) { + return TCL_ERROR; + } + + // TODO: Generate magic (with new instruction) for setting up the ensemble + // rewriting... + + for (i=0,tokenPtr=parsePtr->tokenPtr ; inumWords ; i++) { + TclCompileTokens(interp, tokenPtr+1, tokenPtr->numComponents, envPtr); + tokenPtr = TokenAfter(tokenPtr); + } + Tcl_GetCommandFullName(interp, (Tcl_Command) cmdPtr, objPtr); + bytes = Tcl_GetStringFromObj(objPtr, &length); + literal = TclRegisterNewCmdLiteral(envPtr, bytes, length); + TclDecrRefCount(objPtr); + TclEmitPush(literal, envPtr); + TclEmitInstInt4(INST_INVOKE_REPLACE, parsePtr->numWords, envPtr); + TclAdjustStackDepth(-1, envPtr); + return TCL_OK; +} /* * Local Variables: diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 2b5f713..3fab3cc 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -2972,6 +2972,63 @@ TEBCresume( Tcl_Panic("TclNRExecuteByteCode: obsolete INST_CALL_FUNC1 found"); #endif + case INST_INVOKE_REPLACE: + objc = TclGetUInt4AtPtr(pc+1); + objPtr = POP_OBJECT(); + objv = &OBJ_AT_DEPTH(objc-1); + cleanup = objc; +#ifdef TCL_COMPILE_DEBUG + if (tclTraceExec >= 2) { + int i; + + if (traceInstructions) { + strncpy(cmdNameBuf, TclGetString(objv[0]), 20); + TRACE(("%u => call (implementation %s) ", + objc, O2S(objPtr))); + } else { + fprintf(stdout, + "%d: (%u) invoking (using implementation %s) ", + iPtr->numLevels, (unsigned)(pc - codePtr->codeStart), + O2S(objPtr)); + } + for (i = 0; i < objc; i++) { + TclPrintObject(stdout, objv[i], 15); + fprintf(stdout, " "); + } + fprintf(stdout, "\n"); + fflush(stdout); + } +#endif /*TCL_COMPILE_DEBUG*/ + { + Tcl_Obj *copyPtr = Tcl_NewListObj(objc - 1, NULL); + register List *listRepPtr = copyPtr->internalRep.twoPtrValue.ptr1; + Tcl_Obj **copyObjv = &listRepPtr->elements; + int i; + + listRepPtr->elemCount = objc - 1; + copyObjv[0] = objPtr; + memcpy(copyObjv+1, objv+2, sizeof(Tcl_Obj *) * (objc - 2)); + for (i=1 ; idata.tebc.pc = (char *) pc; + iPtr->cmdFramePtr = bcFramePtr; + if (iPtr->flags & INTERP_DEBUG_FRAME) { + TclArgumentBCEnter((Tcl_Interp *) iPtr, objv, objc, + codePtr, bcFramePtr, pc - codePtr->codeStart); + } + iPtr->ensembleRewrite.sourceObjs = objv; + iPtr->ensembleRewrite.numRemovedObjs = 2; + iPtr->ensembleRewrite.numInsertedObjs = 1; + DECACHE_STACK_INFO(); + pc += 5; + TEBC_YIELD(); + TclNRAddCallback(interp, TclClearRootEnsemble, NULL,NULL,NULL,NULL); + iPtr->evalFlags |= TCL_EVAL_REDIRECT; + return TclNREvalObjEx(interp, objPtr, TCL_EVAL_INVOKE, NULL, INT_MIN); + /* * ----------------------------------------------------------------- * Start of INST_LOAD instructions. -- cgit v0.12 From 1c7c1c74c471463c45093f14f25a4f69af26211f Mon Sep 17 00:00:00 2001 From: dkf Date: Mon, 31 Dec 2012 12:32:13 +0000 Subject: Marked some string subcommands as obsolete, following discussion on tcl-core. --- ChangeLog | 6 ++++++ doc/string.n | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 43b6dfa..d814777 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-12-31 Donal K. Fellows + + * doc/string.n: Noted the obsolescence of the 'bytelength', + 'wordstart' and 'wordend' subcommands, and moved them to later in the + file. + 2012-12-27 Jan Nijtmans * generic/tclListObj.c: [Bug 3598580]: Tcl_ListObjReplace may release diff --git a/doc/string.n b/doc/string.n index 6b3cc59..f5eae39 100644 --- a/doc/string.n +++ b/doc/string.n @@ -19,26 +19,6 @@ string \- Manipulate strings Performs one of several string operations, depending on \fIoption\fR. The legal \fIoption\fRs (which may be abbreviated) are: .TP -\fBstring bytelength \fIstring\fR -. -Returns a decimal string giving the number of bytes used to represent -\fIstring\fR in memory. Because UTF\-8 uses one to three bytes to -represent Unicode characters, the byte length will not be the same as -the character length in general. The cases where a script cares about -the byte length are rare. -.RS -.PP -In almost all cases, you should use the -\fBstring length\fR operation (including determining the length of a -Tcl byte array value). Refer to the \fBTcl_NumUtfChars\fR manual -entry for more details on the UTF\-8 representation. -.PP -\fICompatibility note:\fR it is likely that this subcommand will be -withdrawn in a future version of Tcl. It is better to use the -\fBencoding convertto\fR command to convert a string to a known -encoding and then apply \fBstring length\fR to that. -.RE -.TP \fBstring compare\fR ?\fB\-nocase\fR? ?\fB\-length int\fR? \fIstring1 string2\fR . Perform a character-by-character comparison of strings \fIstring1\fR @@ -354,6 +334,31 @@ Returns a value equal to \fIstring\fR except that any trailing characters present in the string given by \fIchars\fR are removed. If \fIchars\fR is not specified then white space is removed (any character for which \fBstring is space\fR returns 1, and "\0"). +.SS "OBSOLETE SUBCOMMANDS" +.PP +These subcommands are currently supported, but are likely to go away in a +future release as their functionality is either virtually never used or highly +misleading. +.TP +\fBstring bytelength \fIstring\fR +. +Returns a decimal string giving the number of bytes used to represent +\fIstring\fR in memory. Because UTF\-8 uses one to three bytes to +represent Unicode characters, the byte length will not be the same as +the character length in general. The cases where a script cares about +the byte length are rare. +.RS +.PP +In almost all cases, you should use the +\fBstring length\fR operation (including determining the length of a +Tcl byte array value). Refer to the \fBTcl_NumUtfChars\fR manual +entry for more details on the UTF\-8 representation. +.PP +\fICompatibility note:\fR it is likely that this subcommand will be +withdrawn in a future version of Tcl. It is better to use the +\fBencoding convertto\fR command to convert a string to a known +encoding and then apply \fBstring length\fR to that. +.RE .TP \fBstring wordend \fIstring charIndex\fR . -- cgit v0.12 From d51a3b0e2cbc83b69e055dfaf9b8d9faa74fec70 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 2 Jan 2013 14:12:40 +0000 Subject: test Tcl_GetErrorLine() forwards/backwards compatibility in pkgb.so as well --- unix/dltest/pkgb.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/unix/dltest/pkgb.c b/unix/dltest/pkgb.c index 0bff98b..99f189f 100644 --- a/unix/dltest/pkgb.c +++ b/unix/dltest/pkgb.c @@ -39,6 +39,10 @@ static int Pkgb_UnsafeObjCmd _ANSI_ARGS_((ClientData clientData, *---------------------------------------------------------------------- */ +#ifndef Tcl_GetErrorLine +# define Tcl_GetErrorLine(interp) ((interp)->errorLine) +#endif + static int Pkgb_SubObjCmd(dummy, interp, objc, objv) ClientData dummy; /* Not used. */ @@ -54,6 +58,9 @@ Pkgb_SubObjCmd(dummy, interp, objc, objv) } if ((Tcl_GetIntFromObj(interp, objv[1], &first) != TCL_OK) || (Tcl_GetIntFromObj(interp, objv[2], &second) != TCL_OK)) { + char buf[TCL_INTEGER_SPACE]; + sprintf(buf, "%d", Tcl_GetErrorLine(interp)); + Tcl_AppendResult(interp, " in line: ", buf, NULL); return TCL_ERROR; } Tcl_SetObjResult(interp, Tcl_NewIntObj(first - second)); -- cgit v0.12 From 27cb36afb649f2c7fc5594e7150b4755ba29599f Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 2 Jan 2013 14:16:03 +0000 Subject: Marked some string subcommands as obsolete, following discussion on tcl-core. --- ChangeLog | 6 ++++++ doc/string.n | 63 ++++++++++++++++++++++++++++++++---------------------------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 728b677..8eb7af6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-12-31 Donal K. Fellows + + * doc/string.n: Noted the obsolescence of the 'bytelength', + 'wordstart' and 'wordend' subcommands, and moved them to later in the + file. + 2012-12-27 Jan Nijtmans * generic/tclListObj.c: [Bug 3598580]: Tcl_ListObjReplace may release diff --git a/doc/string.n b/doc/string.n index ef49f15..2f9d2e7 100644 --- a/doc/string.n +++ b/doc/string.n @@ -20,16 +20,6 @@ string \- Manipulate strings Performs one of several string operations, depending on \fIoption\fR. The legal \fIoption\fRs (which may be abbreviated) are: .TP -\fBstring bytelength \fIstring\fR -Returns a decimal string giving the number of bytes used to represent -\fIstring\fR in memory. Because UTF\-8 uses one to three bytes to -represent Unicode characters, the byte length will not be the same as -the character length in general. The cases where a script cares about -the byte length are rare. In almost all cases, you should use the -\fBstring length\fR operation (including determining the length of a -Tcl ByteArray object). Refer to the \fBTcl_NumUtfChars\fR manual -entry for more details on the UTF\-8 representation. -.TP \fBstring compare\fR ?\fB\-nocase\fR? ?\fB\-length int\fR? \fIstring1 string2\fR Perform a character-by-character comparison of strings \fIstring1\fR and \fIstring2\fR. Returns \-1, 0, or 1, depending on whether @@ -47,13 +37,13 @@ the first \fIlength\fR characters are used in the comparison. If \fB\-length\fR is negative, it is ignored. If \fB\-nocase\fR is specified, then the strings are compared in a case-insensitive manner. .TP -\fBstring first \fIstring1 string2\fR ?\fIstartIndex\fR? -Search \fIstring2\fR for a sequence of characters that exactly match -the characters in \fIstring1\fR. If found, return the index of the -first character in the first such match within \fIstring2\fR. If not +\fBstring first \fIneedleString haystackString\fR ?\fIstartIndex\fR? +Search \fIhaystackString\fR for a sequence of characters that exactly match +the characters in \fIneedleString\fR. If found, return the index of the +first character in the first such match within \fIhaystackString\fR. If not found, return \-1. If \fIstartIndex\fR is specified (in any of the forms accepted by the \fBindex\fR method), then the search is -constrained to start with the character in \fIstring2\fR specified by +constrained to start with the character in \fIhaystackString\fR specified by the index. For example, .RS .CS @@ -80,17 +70,17 @@ The last char of the string minus the specified integer offset (e.g. \fBend\-1\fR would refer to the "c" in "abcd"). .PP If \fIcharIndex\fR is less than 0 or greater than or equal to the -length of the string then an empty string is returned. +length of the string then this command returns an empty string. .RE .TP \fBstring is \fIclass\fR ?\fB\-strict\fR? ?\fB\-failindex \fIvarname\fR? \fIstring\fR Returns 1 if \fIstring\fR is a valid member of the specified character class, otherwise returns 0. If \fB\-strict\fR is specified, then an -empty string returns 0, otherwise and empty string will return 1 on +empty string returns 0, otherwise an empty string will return 1 on any class. If \fB\-failindex\fR is specified, then if the function returns 0, the index in the string where the class was no longer valid will be stored in the variable named \fIvarname\fR. The \fIvarname\fR -will not be set if the function returns 1. The following character +will not be set if \fBstring is\fR returns 1. The following character classes are recognized (the class name can be abbreviated): .RS .IP \fBalnum\fR 12 @@ -144,13 +134,13 @@ function will return 0, then the \fIvarname\fR will always be set to 0, due to the varied nature of a valid boolean value. .RE .TP -\fBstring last \fIstring1 string2\fR ?\fIlastIndex\fR? -Search \fIstring2\fR for a sequence of characters that exactly match -the characters in \fIstring1\fR. If found, return the index of the -first character in the last such match within \fIstring2\fR. If there +\fBstring last \fIneedleString haystackString\fR ?\fIlastIndex\fR? +Search \fIhaystackString\fR for a sequence of characters that exactly match +the characters in \fIneedleString\fR. If found, return the index of the +first character in the last such match within \fIhaystackString\fR. If there is no match, then return \-1. If \fIlastIndex\fR is specified (in any of the forms accepted by the \fBindex\fR method), then only the -characters in \fIstring2\fR at or before the specified \fIlastIndex\fR +characters in \fIhaystackString\fR at or before the specified \fIlastIndex\fR will be considered by the search. For example, .RS .CS @@ -198,7 +188,7 @@ it will return the string \fB02c322c222c\fR. .TP \fBstring match\fR ?\fB\-nocase\fR? \fIpattern\fR \fIstring\fR See if \fIpattern\fR matches \fIstring\fR; return 1 if it does, 0 if -it doesn't. If \fB\-nocase\fR is specified, then the pattern attempts +it does not. If \fB\-nocase\fR is specified, then the pattern attempts to match against the string in a case insensitive manner. For the two strings to match, their contents must be identical except that the following special sequences may appear in \fIpattern\fR: @@ -278,21 +268,36 @@ specified as for the \fBindex\fR method. .TP \fBstring trim \fIstring\fR ?\fIchars\fR? Returns a value equal to \fIstring\fR except that any leading or -trailing characters from the set given by \fIchars\fR are removed. If +trailing characters present in the string given by \fIchars\fR are removed. If \fIchars\fR is not specified then white space is removed (spaces, tabs, newlines, and carriage returns). .TP \fBstring trimleft \fIstring\fR ?\fIchars\fR? Returns a value equal to \fIstring\fR except that any leading -characters from the set given by \fIchars\fR are removed. If +characters present in the string given by \fIchars\fR are removed. If \fIchars\fR is not specified then white space is removed (spaces, tabs, newlines, and carriage returns). .TP \fBstring trimright \fIstring\fR ?\fIchars\fR? Returns a value equal to \fIstring\fR except that any trailing -characters from the set given by \fIchars\fR are removed. If +characters present in the string given by \fIchars\fR are removed. If \fIchars\fR is not specified then white space is removed (spaces, tabs, newlines, and carriage returns). +.SH "OBSOLETE SUBCOMMANDS" +.PP +These subcommands are currently supported, but are likely to go away in a +future release as their functionality is either virtually never used or highly +misleading. +.TP +\fBstring bytelength \fIstring\fR +Returns a decimal string giving the number of bytes used to represent +\fIstring\fR in memory. Because UTF\-8 uses one to three bytes to +represent Unicode characters, the byte length will not be the same as +the character length in general. The cases where a script cares about +the byte length are rare. In almost all cases, you should use the +\fBstring length\fR operation (including determining the length of a +Tcl ByteArray object). Refer to the \fBTcl_NumUtfChars\fR manual +entry for more details on the UTF\-8 representation. .TP \fBstring wordend \fIstring charIndex\fR Returns the index of the character just after the last one in the word @@ -315,9 +320,9 @@ prefix of the string \fBfoobar\fR. .CS set length [\fBstring length\fR $string] if {$length == 0} { - set isPrefix 0 + set isPrefix 0 } else { - set isPrefix [\fBstring equal\fR -length $length $string "foobar"] + set isPrefix [\fBstring equal\fR -length $length $string "foobar"] } .CE -- cgit v0.12 From 3f4534b92ba967574dc4106bc346ccbbfed9d638 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 2 Jan 2013 14:18:15 +0000 Subject: Don't free ctrl.script if thread creation fails: it is a constant string "testthread wait" normally. --- generic/tclThreadTest.c | 1 - 1 file changed, 1 deletion(-) diff --git a/generic/tclThreadTest.c b/generic/tclThreadTest.c index d298e5b..9d17f56 100644 --- a/generic/tclThreadTest.c +++ b/generic/tclThreadTest.c @@ -420,7 +420,6 @@ TclCreateThread(interp, script, joinable) TCL_THREAD_STACK_DEFAULT, joinable) != TCL_OK) { Tcl_MutexUnlock(&threadMutex); Tcl_AppendResult(interp,"can't create a new thread",NULL); - ckfree((void*)ctrl.script); return TCL_ERROR; } -- cgit v0.12 From 92d844b187a1a7cd56fc2955b50aa461cd9e0086 Mon Sep 17 00:00:00 2001 From: dkf Date: Wed, 2 Jan 2013 15:10:00 +0000 Subject: Passing more tests. --- generic/tclCompile.c | 2 +- generic/tclEnsemble.c | 119 +++++++++++++++++++++++++++++++++----------------- generic/tclExecute.c | 24 ++++++---- 3 files changed, 94 insertions(+), 51 deletions(-) diff --git a/generic/tclCompile.c b/generic/tclCompile.c index c052531..45a74d7 100644 --- a/generic/tclCompile.c +++ b/generic/tclCompile.c @@ -529,7 +529,7 @@ InstructionDesc const tclInstructionTable[] = { /* Forces the variable indexed by opnd to be an array. Does not touch * the stack. */ - {"invokeReplace", 5, INT_MIN, 1, {OPERAND_UINT4}}, + {"invokeReplace", 6, INT_MIN, 2, {OPERAND_UINT4,OPERAND_UINT1}}, /* Invoke command named objv[0], replacing the first two words with * the word at the top of the stack; * = */ diff --git a/generic/tclEnsemble.c b/generic/tclEnsemble.c index 8f0d4fe..8cd9717 100644 --- a/generic/tclEnsemble.c +++ b/generic/tclEnsemble.c @@ -39,9 +39,9 @@ static int CompileToCompiledCommand(Tcl_Interp *interp, Tcl_Parse *parsePtr, Tcl_Token *tokenPtr, int len, Tcl_Obj **elems, Command *cmdPtr, CompileEnv *envPtr); -static int CompileToInvokedCommand(Tcl_Interp *interp, +static void CompileToInvokedCommand(Tcl_Interp *interp, Tcl_Parse *parsePtr, Tcl_Token *tokenPtr, - int len, Tcl_Obj **elems, Command *cmdPtr, + Tcl_Obj *replacements, Command *cmdPtr, CompileEnv *envPtr); /* @@ -2739,24 +2739,24 @@ TclCompileEnsemble( * compiled. */ CompileEnv *envPtr) /* Holds resulting instructions. */ { - Tcl_Token *tokenPtr; + Tcl_Token *tokenPtr = TokenAfter(parsePtr->tokenPtr); Tcl_Obj *mapObj, *subcmdObj, *targetCmdObj, *listObj, **elems; + Tcl_Obj *replaced = Tcl_NewObj(), *replacement; Tcl_Command ensemble = (Tcl_Command) cmdPtr; - int len, result, flags = 0, i; + int len, result, flags = 0, i, depth = 1; unsigned numBytes; const char *word; - if (parsePtr->numWords < 2) { - return TCL_ERROR; + Tcl_IncrRefCount(replaced); + if (parsePtr->numWords < depth + 1) { + goto failed; } - - tokenPtr = TokenAfter(parsePtr->tokenPtr); if (tokenPtr->type != TCL_TOKEN_SIMPLE_WORD) { /* * Too hard. */ - return TCL_ERROR; + goto failed; } word = tokenPtr[1].start; @@ -2775,7 +2775,7 @@ TclCompileEnsemble( * to proceed. */ - return TCL_ERROR; + goto failed; } /* @@ -2789,7 +2789,7 @@ TclCompileEnsemble( * Figuring out how to compile this has become too much. Bail out. */ - return TCL_ERROR; + goto failed; } /* @@ -2812,7 +2812,7 @@ TclCompileEnsemble( Tcl_Obj *matchObj = NULL; if (Tcl_ListObjGetElements(NULL, listObj, &len, &elems) != TCL_OK) { - return TCL_ERROR; + goto failed; } for (i=0 ; i 1 || Tcl_IsSafe(interp)) { - return TCL_ERROR; + goto failed; } targetCmdObj = elems[0]; @@ -2944,7 +2950,12 @@ TclCompileEnsemble( * Cannot compile. */ - return TCL_ERROR; + goto failed; + } + depth++; + + if (cmdPtr->compileProc == TclCompileEnsemble) { + // TODO: Back round the loop to parse the next level down. } /* @@ -2957,10 +2968,23 @@ TclCompileEnsemble( if (cmdPtr->compileProc != NULL && CompileToCompiledCommand(interp, parsePtr, tokenPtr, len, elems, cmdPtr, envPtr) == TCL_OK) { - return TCL_OK; + goto succeeded; + } else if (len != 1) { + goto failed; } - return CompileToInvokedCommand(interp, parsePtr, tokenPtr, - len, elems, cmdPtr, envPtr); + CompileToInvokedCommand(interp, parsePtr, tokenPtr, replaced, + cmdPtr, envPtr); + succeeded: + if (replaced != NULL) { + Tcl_DecrRefCount(replaced); + } + return TCL_OK; + + failed: + if (replaced != NULL) { + Tcl_DecrRefCount(replaced); + } + return TCL_ERROR; } /* @@ -3038,39 +3062,52 @@ CompileToCompiledCommand( return result; } -static int +static void CompileToInvokedCommand( Tcl_Interp *interp, Tcl_Parse *parsePtr, Tcl_Token *tokenPtr, - int len, - Tcl_Obj **elems, + Tcl_Obj *replacements, Command *cmdPtr, CompileEnv *envPtr) /* Holds resulting instructions. */ { - Tcl_Obj *objPtr = Tcl_NewObj(); + Tcl_Token *tokPtr; + Tcl_Obj *objPtr, **words; char *bytes; - int length, i, literal; - - if (len != 1) { - return TCL_ERROR; - } + int length, i, numWords; // TODO: Generate magic (with new instruction) for setting up the ensemble // rewriting... - for (i=0,tokenPtr=parsePtr->tokenPtr ; inumWords ; i++) { - TclCompileTokens(interp, tokenPtr+1, tokenPtr->numComponents, envPtr); - tokenPtr = TokenAfter(tokenPtr); + Tcl_ListObjGetElements(NULL, replacements, &numWords, &words); + for (i=0,tokPtr=parsePtr->tokenPtr ; inumWords ; i++) { + if (i > 0 && i-1 < numWords) { + bytes = Tcl_GetStringFromObj(words[i-1], &length); + PushLiteral(envPtr, bytes, length); + } else { + TclCompileTokens(interp, tokPtr+1, tokPtr->numComponents, envPtr); + } + tokPtr = TokenAfter(tokPtr); } + + /* + * Push the name of the command we're actually dispatching to as part of + * the implementation. + */ + + objPtr = Tcl_NewObj(); Tcl_GetCommandFullName(interp, (Tcl_Command) cmdPtr, objPtr); bytes = Tcl_GetStringFromObj(objPtr, &length); - literal = TclRegisterNewCmdLiteral(envPtr, bytes, length); + PushLiteral(envPtr, bytes, length); TclDecrRefCount(objPtr); - TclEmitPush(literal, envPtr); + + /* + * Do the replacing dispatch. + */ + TclEmitInstInt4(INST_INVOKE_REPLACE, parsePtr->numWords, envPtr); - TclAdjustStackDepth(-1, envPtr); - return TCL_OK; + TclEmitInt1(numWords+1, envPtr); + TclAdjustStackDepth(-1, envPtr); /* Correction to stack depth calcs. */ } /* diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 3fab3cc..b0da17d 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -2974,6 +2974,7 @@ TEBCresume( case INST_INVOKE_REPLACE: objc = TclGetUInt4AtPtr(pc+1); + opnd = TclGetUInt1AtPtr(pc+5); objPtr = POP_OBJECT(); objv = &OBJ_AT_DEPTH(objc-1); cleanup = objc; @@ -2983,8 +2984,7 @@ TEBCresume( if (traceInstructions) { strncpy(cmdNameBuf, TclGetString(objv[0]), 20); - TRACE(("%u => call (implementation %s) ", - objc, O2S(objPtr))); + TRACE(("%u => call (implementation %s) ", objc, O2S(objPtr))); } else { fprintf(stdout, "%d: (%u) invoking (using implementation %s) ", @@ -2992,7 +2992,13 @@ TEBCresume( O2S(objPtr)); } for (i = 0; i < objc; i++) { - TclPrintObject(stdout, objv[i], 15); + if (i < opnd) { + fprintf(stdout, "<"); + TclPrintObject(stdout, objv[i], 15); + fprintf(stdout, ">"); + } else { + TclPrintObject(stdout, objv[i], 15); + } fprintf(stdout, " "); } fprintf(stdout, "\n"); @@ -3000,15 +3006,15 @@ TEBCresume( } #endif /*TCL_COMPILE_DEBUG*/ { - Tcl_Obj *copyPtr = Tcl_NewListObj(objc - 1, NULL); + Tcl_Obj *copyPtr = Tcl_NewListObj(objc - opnd + 1, NULL); register List *listRepPtr = copyPtr->internalRep.twoPtrValue.ptr1; Tcl_Obj **copyObjv = &listRepPtr->elements; int i; - listRepPtr->elemCount = objc - 1; + listRepPtr->elemCount = objc - opnd + 1; copyObjv[0] = objPtr; - memcpy(copyObjv+1, objv+2, sizeof(Tcl_Obj *) * (objc - 2)); - for (i=1 ; icodeStart); } iPtr->ensembleRewrite.sourceObjs = objv; - iPtr->ensembleRewrite.numRemovedObjs = 2; + iPtr->ensembleRewrite.numRemovedObjs = opnd; iPtr->ensembleRewrite.numInsertedObjs = 1; DECACHE_STACK_INFO(); - pc += 5; + pc += 6; TEBC_YIELD(); TclNRAddCallback(interp, TclClearRootEnsemble, NULL,NULL,NULL,NULL); iPtr->evalFlags |= TCL_EVAL_REDIRECT; -- cgit v0.12 From 810edde822b6b99b1dcc766be690db919e90e361 Mon Sep 17 00:00:00 2001 From: dkf Date: Wed, 2 Jan 2013 18:33:27 +0000 Subject: All tests pass except one; not sure what's wrong there. --- generic/tclCompCmds.c | 8 +-- generic/tclEnsemble.c | 154 ++++++++++++++++++++++++++++++++------------------ tests/info.test | 26 ++++----- tests/nre.test | 26 +-------- 4 files changed, 118 insertions(+), 96 deletions(-) diff --git a/generic/tclCompCmds.c b/generic/tclCompCmds.c index 160fa3c..8fa191b 100644 --- a/generic/tclCompCmds.c +++ b/generic/tclCompCmds.c @@ -5791,7 +5791,7 @@ TclCompileVariableCmd( */ valueTokenPtr = parsePtr->tokenPtr; - for (i=2; i<=numWords; i+=2) { + for (i=1; iextCmdMapPtr; \ + int eclIndex = mapPtr->nuloc - 1 +#define CompileWord(envPtr, tokenPtr, interp, word) \ + if ((tokenPtr)->type == TCL_TOKEN_SIMPLE_WORD) { \ + TclEmitPush(TclRegisterNewLiteral((envPtr), (tokenPtr)[1].start, \ + (tokenPtr)[1].size), (envPtr)); \ + } else { \ + if (mapPtr->loc[eclIndex].next) { \ + envPtr->line = mapPtr->loc[eclIndex].line[word]; \ + envPtr->clNext = mapPtr->loc[eclIndex].next[word]; \ + } \ + TclCompileTokens((interp), (tokenPtr)+1, (tokenPtr)->numComponents, \ + (envPtr)); \ + } static inline Tcl_Obj * NewNsObj( @@ -2743,11 +2761,14 @@ TclCompileEnsemble( Tcl_Obj *mapObj, *subcmdObj, *targetCmdObj, *listObj, **elems; Tcl_Obj *replaced = Tcl_NewObj(), *replacement; Tcl_Command ensemble = (Tcl_Command) cmdPtr; - int len, result, flags = 0, i, depth = 1; + Command *oldCmdPtr = cmdPtr, *newCmdPtr; + int len, result, flags = 0, i, depth = 1, invokeAnyway = 0; + int ourResult = TCL_ERROR; unsigned numBytes; const char *word; Tcl_IncrRefCount(replaced); + checkNextWord: if (parsePtr->numWords < depth + 1) { goto failed; } @@ -2915,6 +2936,7 @@ TclCompileEnsemble( */ if (matched != 1) { + invokeAnyway = 1; goto failed; } } @@ -2933,29 +2955,33 @@ TclCompileEnsemble( if (Tcl_ListObjGetElements(NULL, targetCmdObj, &len, &elems) != TCL_OK) { goto failed; } - if (len > 1 || Tcl_IsSafe(interp)) { + if (len != 1) { goto failed; } targetCmdObj = elems[0]; + oldCmdPtr = cmdPtr; Tcl_IncrRefCount(targetCmdObj); - cmdPtr = (Command *) Tcl_GetCommandFromObj(interp, targetCmdObj); + newCmdPtr = (Command *) Tcl_GetCommandFromObj(interp, targetCmdObj); TclDecrRefCount(targetCmdObj); - if (cmdPtr == NULL - || cmdPtr->nsPtr->flags & NS_SUPPRESS_COMPILATION - || cmdPtr->flags * CMD_HAS_EXEC_TRACES + if (newCmdPtr == NULL || Tcl_IsSafe(interp) + || newCmdPtr->nsPtr->flags & NS_SUPPRESS_COMPILATION + || newCmdPtr->flags & CMD_HAS_EXEC_TRACES || ((Interp *)interp)->flags & DONT_COMPILE_CMDS_INLINE) { /* * Maps to an undefined command or a command without a compiler. * Cannot compile. */ - goto failed; + goto cleanup; } + cmdPtr = newCmdPtr; depth++; if (cmdPtr->compileProc == TclCompileEnsemble) { - // TODO: Back round the loop to parse the next level down. + tokenPtr = TokenAfter(tokenPtr); + ensemble = (Tcl_Command) cmdPtr; + goto checkNextWord; } /* @@ -2965,26 +2991,44 @@ TclCompileEnsemble( * invoke at runtime. */ - if (cmdPtr->compileProc != NULL && - CompileToCompiledCommand(interp, parsePtr, tokenPtr, - len, elems, cmdPtr, envPtr) == TCL_OK) { - goto succeeded; - } else if (len != 1) { - goto failed; - } - CompileToInvokedCommand(interp, parsePtr, tokenPtr, replaced, - cmdPtr, envPtr); - succeeded: - if (replaced != NULL) { - Tcl_DecrRefCount(replaced); + invokeAnyway = 1; + if (cmdPtr->compileProc != NULL) { + if (CompileToCompiledCommand(interp, parsePtr, tokenPtr, depth, + cmdPtr, envPtr) == TCL_OK) { + ourResult = TCL_OK; + goto cleanup; + } } - return TCL_OK; + + /* + * Failed to do a full compile for some reason. Try to do a direct invoke + * instead of going through the ensemble lookup process again. + */ failed: + if (len == 1 && depth < 250) { + if (depth > 1) { + if (!invokeAnyway) { + cmdPtr = oldCmdPtr; + depth--; + } + (void) Tcl_ListObjReplace(NULL, replaced, depth, 2, 0, NULL); + } + CompileToInvokedCommand(interp, parsePtr, replaced, cmdPtr, envPtr); + ourResult = TCL_OK; + } + + /* + * Release the memory we allocated. If we've got here, we've either done + * something useful or we're in a case that we can't compile at all and + * we're just giving up. + */ + + cleanup: if (replaced != NULL) { Tcl_DecrRefCount(replaced); } - return TCL_ERROR; + return ourResult; } /* @@ -2998,46 +3042,44 @@ CompileToCompiledCommand( Tcl_Interp *interp, Tcl_Parse *parsePtr, Tcl_Token *tokenPtr, - int len, - Tcl_Obj **elems, + int depth, Command *cmdPtr, CompileEnv *envPtr) /* Holds resulting instructions. */ { Tcl_Parse synthetic; + Tcl_Token *tokPtr; int result, i; TclParseInit(interp, NULL, 0, &synthetic); - synthetic.numWords = parsePtr->numWords - 2 + len; - TclGrowParseTokenArray(&synthetic, 2*len); - synthetic.numTokens = 2*len; + synthetic.numWords = parsePtr->numWords - depth + 1; + TclGrowParseTokenArray(&synthetic, 2); + synthetic.numTokens = 2; /* - * Now we have the space to work in, install something rewritten. Note - * that we are here praying for all our might that none of these words are - * a script; the error detection code will crash if that happens and there - * is nothing we can do to avoid it! + * Now we have the space to work in, install something rewritten. The + * first word will "officially" be the structured ensemble name. */ - for (i=0 ; itokenPtr[0].start; + synthetic.tokenPtr[0].numComponents = 1; + synthetic.tokenPtr[1].type = TCL_TOKEN_TEXT; + synthetic.tokenPtr[1].start = parsePtr->tokenPtr[0].start; + synthetic.tokenPtr[1].numComponents = 0; + tokPtr = parsePtr->tokenPtr; + for (i=0 ; istart-synthetic.tokenPtr[0].start)+tokPtr->size; + + synthetic.tokenPtr[0].size = sclen; + synthetic.tokenPtr[1].size = sclen; + tokPtr = TokenAfter(tokPtr); } /* * Copy over the real argument tokens. */ - for (i=len; itokenPtr ; inumWords ; i++) { - if (i > 0 && i-1 < numWords) { + if (i > 0 && i < numWords+1) { bytes = Tcl_GetStringFromObj(words[i-1], &length); PushLiteral(envPtr, bytes, length); } else { - TclCompileTokens(interp, tokPtr+1, tokPtr->numComponents, envPtr); + CompileWord(envPtr, tokPtr, interp, i); } tokPtr = TokenAfter(tokPtr); } @@ -3098,7 +3140,9 @@ CompileToInvokedCommand( objPtr = Tcl_NewObj(); Tcl_GetCommandFullName(interp, (Tcl_Command) cmdPtr, objPtr); bytes = Tcl_GetStringFromObj(objPtr, &length); - PushLiteral(envPtr, bytes, length); + cmdLit = TclRegisterNewCmdLiteral(envPtr, bytes, length); + TclSetCmdNameObj(interp, envPtr->literalArrayPtr[cmdLit].objPtr, cmdPtr); + TclEmitPush(cmdLit, envPtr); TclDecrRefCount(objPtr); /* diff --git a/tests/info.test b/tests/info.test index 5078e11..ebc853a 100644 --- a/tests/info.test +++ b/tests/info.test @@ -692,31 +692,31 @@ test info-21.5 {miscellaneous error conditions} -returnCodes error -body { ## # ### ### ### ######### ######### ######### ## info frame + ## Helper # For the more complex results we cut the file name down to remove path # dependencies, and we use only part of the first line of the reported # command. The latter is required because otherwise the whole test case may # appear in some results, but the result is part of the testcase. An infinite # string would be required to describe that. The cutting-down breaks this. + proc reduce {frame} { - set pos [lsearch -exact $frame cmd] - incr pos - set cmd [lindex $frame $pos] + set cmd [dict get $frame cmd] if {[regexp \n $cmd]} { - set first [string range [lindex [split $cmd \n] 0] 0 end-4] - set frame [lreplace $frame $pos $pos $first] + dict set frame cmd \ + [string range [lindex [split $cmd \n] 0] 0 end-4] } - set pos [lsearch -exact $frame file] - if {$pos >=0} { - incr pos - set tail [file tail [lindex $frame $pos]] - set frame [lreplace $frame $pos $pos $tail] + if {[dict exists $frame file]} { + dict set frame file \ + [file tail [dict get $frame file]] } - set frame + return $frame } + proc subinterp {} { interp create sub ; interp debug sub -frame 1; interp eval sub [list proc reduce [info args reduce] [info body reduce]] } + ## Helper # Generate a stacktrace from the current location to top. This code # not only depends on the exact location of things, but also on the @@ -1454,9 +1454,9 @@ test info-30.1 {bs+nl in literal words, procedure body, compiled} -body { test info-30.2 {bs+nl in literal words, namespace script} { namespace eval xxx { variable res \ - [reduce [info frame 0]];# line 1457 + [info frame 0];# line 1457 } - return $xxx::res + return [reduce $xxx::res] } {type source line 1457 file info.test cmd {info frame 0} level 0} test info-30.3 {bs+nl in literal words, namespace multi-word script} { diff --git a/tests/nre.test b/tests/nre.test index b8ef2e0..b5eb032 100644 --- a/tests/nre.test +++ b/tests/nre.test @@ -74,7 +74,6 @@ test nre-1.1 {self-recursive procs} -setup { } -constraints { testnrelevels } -result {{0 1 1 1} 0} - test nre-1.2 {self-recursive lambdas} -setup { set a [list i [makebody {apply $::a $i}]] } -body { @@ -85,7 +84,6 @@ test nre-1.2 {self-recursive lambdas} -setup { } -constraints { testnrelevels } -result {{0 1 1 1} 0} - test nre-1.3 {mutually recursive procs and lambdas} -setup { proc a i { apply $::b [incr i] @@ -164,8 +162,7 @@ test nre-5.1 {[namespace eval] is not recursive} -setup { namespace delete ::foo } -constraints { testnrelevels -} -result {{0 3 2 2} 0} - +} -result {{0 2 2 2} 0} test nre-5.2 {[namespace eval] is not recursive} -setup { namespace eval ::foo { setabs @@ -177,7 +174,7 @@ test nre-5.2 {[namespace eval] is not recursive} -setup { namespace delete ::foo } -constraints { testnrelevels -} -result {{0 3 2 2} 0} +} -result {{0 2 2 2} 0} test nre-6.1 {[uplevel] is not recursive} -setup { proc a i [makebody {uplevel 1 [list a $i]}] @@ -189,7 +186,6 @@ test nre-6.1 {[uplevel] is not recursive} -setup { } -constraints { testnrelevels } -result {{0 2 2 0} 0} - test nre-6.2 {[uplevel] is not recursive} -setup { setabs proc a i [makebody {uplevel 1 "set x $i; a $i"}] @@ -211,7 +207,6 @@ test nre-7.1 {[catch] is not recursive} -setup { } -constraints { testnrelevels } -result {{0 3 3 0} 0} - test nre-7.2 {[if] is not recursive} -setup { setabs proc a i [makebody {uplevel 1 "if 1 {a $i}"}] @@ -222,7 +217,6 @@ test nre-7.2 {[if] is not recursive} -setup { } -constraints { testnrelevels } -result {{0 2 2 0} 0} - test nre-7.3 {[while] is not recursive} -setup { setabs proc a i [makebody {uplevel 1 "while 1 {set res \[a $i\]; break}; set res"}] @@ -233,7 +227,6 @@ test nre-7.3 {[while] is not recursive} -setup { } -constraints { testnrelevels } -result {{0 2 2 0} 0} - test nre-7.4 {[for] is not recursive} -setup { setabs proc a i [makebody {uplevel 1 "for {set j 0} {\$j < 10} {incr j} {set res \[a $i\]; break}; set res"}] @@ -244,7 +237,6 @@ test nre-7.4 {[for] is not recursive} -setup { } -constraints { testnrelevels } -result {{0 2 2 0} 0} - test nre-7.5 {[foreach] is not recursive} -setup { # # Enable once [foreach] is NR-enabled @@ -258,7 +250,6 @@ test nre-7.5 {[foreach] is not recursive} -setup { } -constraints { testnrelevels } -result {{0 3 3 0} 0} - test nre-7.6 {[eval] is not recursive} -setup { proc a i [makebody {eval [list a $i]}] } -body { @@ -269,7 +260,6 @@ test nre-7.6 {[eval] is not recursive} -setup { } -constraints { testnrelevels } -result {{0 2 2 1} 0} - test nre-7.7 {[eval] is not recursive} -setup { proc a i [makebody {eval "a $i"}] } -body { @@ -280,7 +270,6 @@ test nre-7.7 {[eval] is not recursive} -setup { } -constraints { testnrelevels } -result {{0 2 2 1} 0} - test nre-7.8 {bug #2910748: switch out of stale BC is not nre-aware} -setup { proc foo args {} foo @@ -295,18 +284,15 @@ test nre-7.8 {bug #2910748: switch out of stale BC is not nre-aware} -setup { } -body { # if switching to plain eval is not nre aware, this will cause a "cannot # yield" error - list [bar] [bar] [bar] } -cleanup { rename bar {} rename foo {} } -result {1 2 3} - test nre-8.1 {nre and {*}} -body { # force an expansion that grows the evaluation stack, check that nre # adapts the TEBCdataPtr. This crashes on failure. - proc inner {} { set long [lrepeat 1000000 1] list {*}$long @@ -321,21 +307,18 @@ test nre-8.2 {nre and {*}, [Bug 2415422]} -body { # force an expansion that grows the evaluation stack, check that nre # adapts the bcFramePtr. This causes an NRE assertion to fail if it is not # done properly. - proc nop {} {} proc crash {} { foreach val [list {*}[lrepeat 100000 x]] { nop } } - crash } -cleanup { rename nop {} rename crash {} } - # # Basic TclOO tests # @@ -351,7 +334,6 @@ test nre-oo.1 {really deep calls in oo - direct} -setup { } -constraints { testnrelevels } -result {{0 1 1 1} 0} - test nre-oo.2 {really deep calls in oo - call via [self]} -setup { oo::object create foo oo::objdefine foo method bar i [makebody {[self] bar $i}] @@ -363,7 +345,6 @@ test nre-oo.2 {really deep calls in oo - call via [self]} -setup { } -constraints { testnrelevels } -result {{0 1 1 1} 0} - test nre-oo.3 {really deep calls in oo - private calls} -setup { oo::object create foo oo::objdefine foo method bar i [makebody {my bar $i}] @@ -375,7 +356,6 @@ test nre-oo.3 {really deep calls in oo - private calls} -setup { } -constraints { testnrelevels } -result {{0 1 1 1} 0} - test nre-oo.4 {really deep calls in oo - overriding} -setup { oo::class create foo { method bar i [makebody {my bar $i}] @@ -392,7 +372,6 @@ test nre-oo.4 {really deep calls in oo - overriding} -setup { } -constraints { testnrelevels } -result {{0 1 1 1} 0} - test nre-oo.5 {really deep calls in oo - forwards} -setup { oo::object create foo set body [makebody {my boo $i}] @@ -409,7 +388,6 @@ test nre-oo.5 {really deep calls in oo - forwards} -setup { testnrelevels } -result {{0 2 1 1} 0} - # # NASTY BUG found by tcllib's interp package # -- cgit v0.12 From 824efe60eb61baf70614388faa035d26131ed1c8 Mon Sep 17 00:00:00 2001 From: mig Date: Wed, 2 Jan 2013 19:20:54 +0000 Subject: remove stray calls to Tcl_Alloc and friends: the core should only use ckalloc to allow MEM_DEBUG to work properly --- ChangeLog | 7 +++++++ generic/tclEnsemble.c | 2 +- generic/tclExecute.c | 6 +++--- generic/tclIORTrans.c | 6 +++--- generic/tclInt.h | 2 +- generic/tclTomMathInterface.c | 6 +++--- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index d814777..289e10a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2013-01-02 Miguel Sofer + + * generic/tclEnsemble.c: Remove stray calls to Tcl_Alloc and + * generic/tclExecute.c: friends: the core should only use ckalloc + * generic/tclIORTrans.c: to allow MEM_DEBUG to work properly + * generic/tclTomMathInterface.c: + 2012-12-31 Donal K. Fellows * doc/string.n: Noted the obsolescence of the 'bytelength', diff --git a/generic/tclEnsemble.c b/generic/tclEnsemble.c index b76c603..d8fcf97 100644 --- a/generic/tclEnsemble.c +++ b/generic/tclEnsemble.c @@ -1579,7 +1579,7 @@ TclMakeEnsemble( Tcl_DStringFree(&buf); Tcl_DStringFree(&hiddenBuf); if (nameParts != NULL) { - Tcl_Free((char *) nameParts); + ckfree((char *) nameParts); } return ensemble; } diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 2b5f713..a9b3fb4 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -1212,7 +1212,7 @@ TclStackFree( Tcl_Obj **markerPtr, *marker; if (iPtr == NULL || iPtr->execEnvPtr == NULL) { - Tcl_Free((char *) freePtr); + ckfree((char *) freePtr); return; } @@ -1272,7 +1272,7 @@ TclStackAlloc( int numWords = (numBytes + (sizeof(Tcl_Obj *) - 1))/sizeof(Tcl_Obj *); if (iPtr == NULL || iPtr->execEnvPtr == NULL) { - return (void *) Tcl_Alloc(numBytes); + return (void *) ckalloc(numBytes); } return (void *) StackAllocWords(interp, numWords); @@ -1291,7 +1291,7 @@ TclStackRealloc( int numWords; if (iPtr == NULL || iPtr->execEnvPtr == NULL) { - return (void *) Tcl_Realloc((char *) ptr, numBytes); + return (void *) ckrealloc((char *) ptr, numBytes); } eePtr = iPtr->execEnvPtr; diff --git a/generic/tclIORTrans.c b/generic/tclIORTrans.c index 2b9efb9..1de635f 100644 --- a/generic/tclIORTrans.c +++ b/generic/tclIORTrans.c @@ -2942,7 +2942,7 @@ ResultClear( return; } - Tcl_Free((char *) rPtr->buf); + ckfree((char *) rPtr->buf); rPtr->buf = NULL; rPtr->allocated = 0; } @@ -2977,10 +2977,10 @@ ResultAdd( if (rPtr->allocated == 0) { rPtr->allocated = toWrite + RB_INCREMENT; - rPtr->buf = UCHARP(Tcl_Alloc(rPtr->allocated)); + rPtr->buf = UCHARP(ckalloc(rPtr->allocated)); } else { rPtr->allocated += toWrite + RB_INCREMENT; - rPtr->buf = UCHARP(Tcl_Realloc((char *) rPtr->buf, + rPtr->buf = UCHARP(ckrealloc((char *) rPtr->buf, rPtr->allocated)); } } diff --git a/generic/tclInt.h b/generic/tclInt.h index 1d04c82..52f1a32 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -4008,7 +4008,7 @@ typedef const char *TclDTraceStr; */ # define TclAllocObjStorageEx(interp, objPtr) \ - (objPtr) = (Tcl_Obj *) Tcl_Alloc(sizeof(Tcl_Obj)) + (objPtr) = (Tcl_Obj *) ckalloc(sizeof(Tcl_Obj)) # define TclFreeObjStorageEx(interp, objPtr) \ ckfree((char *) (objPtr)) diff --git a/generic/tclTomMathInterface.c b/generic/tclTomMathInterface.c index 775e86b..48db8c3 100644 --- a/generic/tclTomMathInterface.c +++ b/generic/tclTomMathInterface.c @@ -111,7 +111,7 @@ extern void * TclBNAlloc( size_t x) { - return (void *) Tcl_Alloc((unsigned int) x); + return (void *) ckalloc((unsigned int) x); } /* @@ -135,7 +135,7 @@ TclBNRealloc( void *p, size_t s) { - return (void *) Tcl_Realloc((char *) p, (unsigned int) s); + return (void *) ckrealloc((char *) p, (unsigned int) s); } /* @@ -161,7 +161,7 @@ extern void TclBNFree( void *p) { - Tcl_Free((char *) p); + ckree((char *) p); } #endif -- cgit v0.12 From 415a324f3cbb26121cb4836b48f68ba5b6b8cf56 Mon Sep 17 00:00:00 2001 From: mig Date: Wed, 2 Jan 2013 19:27:09 +0000 Subject: remove stray calls to Tcl_Alloc and friends: the core should only use ckalloc to allow MEM_DEBUG to work properly --- ChangeLog | 7 +++++++ generic/tclExecute.c | 6 +++--- generic/tclTomMathInterface.c | 6 +++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index ef01964..4779e0f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2013-01-02 Miguel Sofer + + * generic/tclEnsemble.c: Remove stray calls to Tcl_Alloc and + * generic/tclExecute.c: friends: the core should only use ckalloc + * generic/tclIORTrans.c: to allow MEM_DEBUG to work properly + * generic/tclTomMathInterface.c: + 2012-12-31 Donal K. Fellows * doc/string.n: Noted the obsolescence of the 'bytelength', diff --git a/generic/tclExecute.c b/generic/tclExecute.c index f2efa0f..229d7c6 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -1063,7 +1063,7 @@ TclStackFree( Tcl_Obj **markerPtr; if (iPtr == NULL || iPtr->execEnvPtr == NULL) { - Tcl_Free((char *) freePtr); + ckfree((char *) freePtr); return; } @@ -1112,7 +1112,7 @@ TclStackAlloc( int numWords = (numBytes + (sizeof(Tcl_Obj *) - 1))/sizeof(Tcl_Obj *); if (iPtr == NULL || iPtr->execEnvPtr == NULL) { - return (void *) Tcl_Alloc(numBytes); + return (void *) ckalloc(numBytes); } return (void *) StackAllocWords(interp, numWords); @@ -1131,7 +1131,7 @@ TclStackRealloc( int numWords; if (iPtr == NULL || iPtr->execEnvPtr == NULL) { - return (void *) Tcl_Realloc((char *) ptr, numBytes); + return (void *) ckrealloc((char *) ptr, numBytes); } eePtr = iPtr->execEnvPtr; diff --git a/generic/tclTomMathInterface.c b/generic/tclTomMathInterface.c index 6e5dac3..89c1132 100644 --- a/generic/tclTomMathInterface.c +++ b/generic/tclTomMathInterface.c @@ -112,7 +112,7 @@ extern void * TclBNAlloc( size_t x) { - return (void *) Tcl_Alloc((unsigned int) x); + return (void *) ckalloc((unsigned int) x); } /* @@ -136,7 +136,7 @@ TclBNRealloc( void *p, size_t s) { - return (void *) Tcl_Realloc((char *) p, (unsigned int) s); + return (void *) ckrealloc((char *) p, (unsigned int) s); } /* @@ -162,7 +162,7 @@ extern void TclBNFree( void *p) { - Tcl_Free((char *) p); + ckfree((char *) p); } #endif -- cgit v0.12 From e82d1f6be8957bb381a19b3663a3e0c34c1480b3 Mon Sep 17 00:00:00 2001 From: dkf Date: Thu, 3 Jan 2013 00:37:29 +0000 Subject: Got the test suite passing cleanly. Excellent. --- generic/tclEnsemble.c | 95 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 35 deletions(-) diff --git a/generic/tclEnsemble.c b/generic/tclEnsemble.c index 5bef6e8..d12ffe6 100644 --- a/generic/tclEnsemble.c +++ b/generic/tclEnsemble.c @@ -4,7 +4,7 @@ * Contains support for ensembles (see TIP#112), which provide simple * mechanism for creating composite commands on top of namespaces. * - * Copyright (c) 2005-2010 Donal K. Fellows. + * Copyright (c) 2005-2013 Donal K. Fellows. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -36,8 +36,8 @@ static void FreeEnsembleCmdRep(Tcl_Obj *objPtr); static void DupEnsembleCmdRep(Tcl_Obj *objPtr, Tcl_Obj *copyPtr); static void StringOfEnsembleCmdRep(Tcl_Obj *objPtr); static int CompileToCompiledCommand(Tcl_Interp *interp, - Tcl_Parse *parsePtr, Tcl_Token *tokenPtr, - int depth, Command *cmdPtr, CompileEnv *envPtr); + Tcl_Parse *parsePtr, int depth, Command *cmdPtr, + CompileEnv *envPtr); static void CompileToInvokedCommand(Tcl_Interp *interp, Tcl_Parse *parsePtr, Tcl_Obj *replacements, Command *cmdPtr, CompileEnv *envPtr); @@ -92,18 +92,9 @@ const Tcl_ObjType tclEnsembleCmdType = { #define DefineLineInformation \ ExtCmdLoc *mapPtr = envPtr->extCmdMapPtr; \ int eclIndex = mapPtr->nuloc - 1 -#define CompileWord(envPtr, tokenPtr, interp, word) \ - if ((tokenPtr)->type == TCL_TOKEN_SIMPLE_WORD) { \ - TclEmitPush(TclRegisterNewLiteral((envPtr), (tokenPtr)[1].start, \ - (tokenPtr)[1].size), (envPtr)); \ - } else { \ - if (mapPtr->loc[eclIndex].next) { \ - envPtr->line = mapPtr->loc[eclIndex].line[word]; \ - envPtr->clNext = mapPtr->loc[eclIndex].next[word]; \ - } \ - TclCompileTokens((interp), (tokenPtr)+1, (tokenPtr)->numComponents, \ - (envPtr)); \ - } +#define SetLineInformation(word) \ + envPtr->line = mapPtr->loc[eclIndex].line[(word)]; \ + envPtr->clNext = mapPtr->loc[eclIndex].next[(word)] static inline Tcl_Obj * NewNsObj( @@ -2768,6 +2759,12 @@ TclCompileEnsemble( const char *word; Tcl_IncrRefCount(replaced); + + /* + * This is where we return to if we are parsing multiple nested compiled + * ensembles. [info object] is such a beast. + */ + checkNextWord: if (parsePtr->numWords < depth + 1) { goto failed; @@ -2978,6 +2975,11 @@ TclCompileEnsemble( cmdPtr = newCmdPtr; depth++; + /* + * See whether we have a nested ensemble. If we do, we can go round the + * mulberry bush again, consuming the next word. + */ + if (cmdPtr->compileProc == TclCompileEnsemble) { tokenPtr = TokenAfter(tokenPtr); ensemble = (Tcl_Command) cmdPtr; @@ -2992,12 +2994,10 @@ TclCompileEnsemble( */ invokeAnyway = 1; - if (cmdPtr->compileProc != NULL) { - if (CompileToCompiledCommand(interp, parsePtr, tokenPtr, depth, - cmdPtr, envPtr) == TCL_OK) { - ourResult = TCL_OK; - goto cleanup; - } + if (CompileToCompiledCommand(interp, parsePtr, depth, cmdPtr, + envPtr) == TCL_OK) { + ourResult = TCL_OK; + goto cleanup; } /* @@ -3025,9 +3025,7 @@ TclCompileEnsemble( */ cleanup: - if (replaced != NULL) { - Tcl_DecrRefCount(replaced); - } + Tcl_DecrRefCount(replaced); return ourResult; } @@ -3041,15 +3039,18 @@ static int CompileToCompiledCommand( Tcl_Interp *interp, Tcl_Parse *parsePtr, - Tcl_Token *tokenPtr, int depth, Command *cmdPtr, CompileEnv *envPtr) /* Holds resulting instructions. */ { Tcl_Parse synthetic; - Tcl_Token *tokPtr; + Tcl_Token *tokenPtr; int result, i; + if (cmdPtr->compileProc == NULL) { + return TCL_ERROR; + } + TclParseInit(interp, NULL, 0, &synthetic); synthetic.numWords = parsePtr->numWords - depth + 1; TclGrowParseTokenArray(&synthetic, 2); @@ -3057,7 +3058,9 @@ CompileToCompiledCommand( /* * Now we have the space to work in, install something rewritten. The - * first word will "officially" be the structured ensemble name. + * first word will "officially" be the bytes of the structured ensemble + * name. That's technically wrong, but nobody will care; we just need + * *something* here... */ synthetic.tokenPtr[0].type = TCL_TOKEN_SIMPLE_WORD; @@ -3066,13 +3069,13 @@ CompileToCompiledCommand( synthetic.tokenPtr[1].type = TCL_TOKEN_TEXT; synthetic.tokenPtr[1].start = parsePtr->tokenPtr[0].start; synthetic.tokenPtr[1].numComponents = 0; - tokPtr = parsePtr->tokenPtr; - for (i=0 ; istart-synthetic.tokenPtr[0].start)+tokPtr->size; + for (i=0,tokenPtr=parsePtr->tokenPtr ; istart - synthetic.tokenPtr[0].start) + + tokenPtr->size; synthetic.tokenPtr[0].size = sclen; synthetic.tokenPtr[1].size = sclen; - tokPtr = TokenAfter(tokPtr); + tokenPtr = TokenAfter(tokenPtr); } /* @@ -3082,12 +3085,12 @@ CompileToCompiledCommand( for (i=1; inumComponents + 1; TclGrowParseTokenArray(&synthetic, toCopy); memcpy(synthetic.tokenPtr + synthetic.numTokens, tokenPtr, sizeof(Tcl_Token) * toCopy); synthetic.numTokens += toCopy; + tokenPtr = TokenAfter(tokenPtr); } /* @@ -3104,6 +3107,11 @@ CompileToCompiledCommand( return result; } +/* + * How to compile a subcommand to a _replacing_ invoke of its implementation + * command. + */ + static void CompileToInvokedCommand( Tcl_Interp *interp, @@ -3118,16 +3126,33 @@ CompileToInvokedCommand( int length, i, numWords, cmdLit; DefineLineInformation; - // TODO: Generate magic (with new instruction) for setting up the ensemble - // rewriting... + /* + * Push the words of the command. Take care; the command words may be + * scripts that have backslashes in them, and [info frame 0] can see the + * difference. Hence the call to TclContinuationsEnterDerived... + */ Tcl_ListObjGetElements(NULL, replacements, &numWords, &words); for (i=0,tokPtr=parsePtr->tokenPtr ; inumWords ; i++) { if (i > 0 && i < numWords+1) { bytes = Tcl_GetStringFromObj(words[i-1], &length); PushLiteral(envPtr, bytes, length); + } else if (tokPtr->type == TCL_TOKEN_SIMPLE_WORD) { + int literal = TclRegisterNewLiteral(envPtr, + tokPtr[1].start, tokPtr[1].size); + + if (envPtr->clNext) { + TclContinuationsEnterDerived( + envPtr->literalArrayPtr[literal].objPtr, + tokPtr[1].start - envPtr->source, + mapPtr->loc[eclIndex].next[i]); + } + TclEmitPush(literal, envPtr); } else { - CompileWord(envPtr, tokPtr, interp, i); + if (envPtr->clNext) { + SetLineInformation(i); + } + CompileTokens(envPtr, tokPtr, interp); } tokPtr = TokenAfter(tokPtr); } -- cgit v0.12 From e59a5820dfdb6c77acd3497b07b8236b51bd04d8 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 3 Jan 2013 09:22:04 +0000 Subject: test case for bug-3598580: Tcl_ListObjReplace may release deleted elements too early --- generic/tclTestObj.c | 11 +++++++++++ tests/listObj.test | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c index a55704a..8e9dc93 100644 --- a/generic/tclTestObj.c +++ b/generic/tclTestObj.c @@ -736,6 +736,17 @@ TestobjCmd(clientData, interp, objc, objv) } SetVarToObj(destIndex, varPtr[varIndex]); Tcl_SetObjResult(interp, varPtr[destIndex]); + } else if (strcmp(subCmd, "bug3598580") == 0) { + Tcl_Obj *listObjPtr, *elemObjPtr; + if (objc != 2) { + goto wrongNumArgs; + } + elemObjPtr = Tcl_NewIntObj(123); + listObjPtr = Tcl_NewListObj(1, &elemObjPtr); + /* Replace the single list element through itself, nonsense but legal. */ + Tcl_ListObjReplace(interp, listObjPtr, 0, 1, 1, &elemObjPtr); + Tcl_SetObjResult(interp, listObjPtr); + return TCL_OK; } else if (strcmp(subCmd, "convert") == 0) { char *typeName; if (objc != 4) { diff --git a/tests/listObj.test b/tests/listObj.test index aa319bb..390ee64 100644 --- a/tests/listObj.test +++ b/tests/listObj.test @@ -181,6 +181,10 @@ test listobj-9.1 {UpdateStringOfList} { string length [list foo\x00help] } 8 +test listobj-11.1 {bug 3598580} { + testobj bug3598580 +} 123 + # cleanup ::tcltest::cleanupTests return -- cgit v0.12