From db2389176bddb30734048a790ac9e6c6f2ec5d45 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 24 Nov 2016 16:20:05 +0000 Subject: Starting implementing the "package files" command. TIP still to be written. --- generic/tclInt.h | 1 + generic/tclLoad.c | 8 ++++- generic/tclPkg.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++------ tests/package.test | 2 +- 4 files changed, 92 insertions(+), 11 deletions(-) diff --git a/generic/tclInt.h b/generic/tclInt.h index 4257ea1..bfcd002 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -3100,6 +3100,7 @@ MODULE_SCOPE int TclpObjChdir(Tcl_Obj *pathPtr); MODULE_SCOPE Tcl_Channel TclpOpenTemporaryFile(Tcl_Obj *dirObj, Tcl_Obj *basenameObj, Tcl_Obj *extensionObj, Tcl_Obj *resultingNameObj); +MODULE_SCOPE void TclPkgFileSeen(Tcl_Interp *interp, const char *fileName); MODULE_SCOPE Tcl_Obj * TclPathPart(Tcl_Interp *interp, Tcl_Obj *pathPtr, Tcl_PathPart portion); MODULE_SCOPE char * TclpReadlink(const char *fileName, diff --git a/generic/tclLoad.c b/generic/tclLoad.c index be296b3..184c158 100644 --- a/generic/tclLoad.c +++ b/generic/tclLoad.c @@ -397,6 +397,12 @@ Tcl_LoadObjCmd( goto done; } + if (target == interp) { + /* Only register the file if the load is done in the + * current interpreter */ + TclPkgFileSeen(target, Tcl_GetString(objv[1])); + } + /* * Create a new record to describe this package. */ @@ -998,7 +1004,7 @@ Tcl_StaticPackage( } /* - * Package isn't loade in the current interp yet. Mark it as now being + * Package isn't loaded in the current interp yet. Mark it as now being * loaded. */ diff --git a/generic/tclPkg.c b/generic/tclPkg.c index 244eb94..3d052a6 100644 --- a/generic/tclPkg.c +++ b/generic/tclPkg.c @@ -32,6 +32,17 @@ typedef struct PkgAvail { * same package. */ } PkgAvail; +typedef struct PkgName { + struct PkgName *nextPtr; /* Next in list of package names being initialized. */ + char name[1]; +} PkgName; + +typedef struct PkgFiles { + PkgName *names; /* Package names being initialized. */ + Tcl_HashTable table; /* Table which contains files for each package */ +} PkgFiles; + + /* * For each package that is known in any way to an interpreter, there is one * record of the following type. These records are stored in the @@ -81,7 +92,7 @@ static const char * PkgRequireCore(Tcl_Interp *interp, const char *name, ((v) = ckalloc(len), memcpy((v),(s),(len))) #define DupString(v,s) \ do { \ - unsigned local__len = (unsigned) (strlen(s) + 1); \ + size_t local__len = strlen(s) + 1; \ DupBlock((v),(s),local__len); \ } while (0) @@ -189,6 +200,29 @@ Tcl_PkgProvideEx( *---------------------------------------------------------------------- */ +static void PkgFilesCleanupProc(ClientData clientData, + Tcl_Interp *interp) +{ + PkgFiles *pkgFiles = (PkgFiles *) clientData; + + while (pkgFiles->names) { + PkgName *name = pkgFiles->names; + pkgFiles->names = name->nextPtr; + ckfree(name); + } + Tcl_DeleteHashTable(&pkgFiles->table); + return; +} + +void TclPkgFileSeen(Tcl_Interp *interp, const char *fileName) +{ + PkgFiles *pkgFiles = (PkgFiles *) Tcl_GetAssocData(interp, "tclPkgFiles", NULL); + if (pkgFiles) { + const char *name = pkgFiles->names->name; + printf("Seen %s for package %s\n", fileName, name); + } +} + #undef Tcl_PkgRequire const char * Tcl_PkgRequire( @@ -489,12 +523,31 @@ PkgRequireCore( */ char *versionToProvide = bestPtr->version; + PkgFiles *pkgFiles; + PkgName *pkgName; script = bestPtr->script; pkgPtr->clientData = versionToProvide; - Tcl_Preserve(script); Tcl_Preserve(versionToProvide); + Tcl_Preserve(script); + /* If assocdata "tclPkgFiles" doesn't exist yet, create it */ + pkgFiles = Tcl_GetAssocData(interp, "tclPkgFiles", NULL); + if (!pkgFiles) { + pkgFiles = ckalloc(sizeof(PkgFiles)); + pkgFiles->names = NULL; + Tcl_InitHashTable(&pkgFiles->table, TCL_STRING_KEYS); + Tcl_SetAssocData(interp, "tclPkgFiles", PkgFilesCleanupProc, pkgFiles); + } + /* Push "ifneeded" package name in "tclPkgFiles" assocdata. */ + pkgName = ckalloc(sizeof(PkgName) + strlen(name)); + pkgName->nextPtr = pkgFiles->names; + strcpy(pkgName->name, name); + pkgFiles->names = pkgName; code = Tcl_EvalEx(interp, script, -1, TCL_EVAL_GLOBAL); + /* Pop the "ifneeded" package name from "tclPkgFiles" assocdata*/ + pkgName = pkgFiles->names; + pkgFiles->names = pkgFiles->names->nextPtr; + ckfree(pkgName); Tcl_Release(script); pkgPtr = FindPackage(interp, name); @@ -764,14 +817,14 @@ Tcl_PackageObjCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { static const char *const pkgOptions[] = { - "forget", "ifneeded", "names", "prefer", "present", - "provide", "require", "unknown", "vcompare", "versions", - "vsatisfies", NULL + "files", "forget", "ifneeded", "names", "prefer", + "present", "provide", "require", "unknown", "vcompare", + "versions", "vsatisfies", NULL }; enum pkgOptions { - PKG_FORGET, PKG_IFNEEDED, PKG_NAMES, PKG_PREFER, PKG_PRESENT, - PKG_PROVIDE, PKG_REQUIRE, PKG_UNKNOWN, PKG_VCOMPARE, PKG_VERSIONS, - PKG_VSATISFIES + PKG_FILES, PKG_FORGET, PKG_IFNEEDED, PKG_NAMES, PKG_PREFER, + PKG_PRESENT, PKG_PROVIDE, PKG_REQUIRE, PKG_UNKNOWN, PKG_VCOMPARE, + PKG_VERSIONS, PKG_VSATISFIES }; Interp *iPtr = (Interp *) interp; int optionIndex, exact, i, satisfies; @@ -794,6 +847,27 @@ Tcl_PackageObjCmd( return TCL_ERROR; } switch ((enum pkgOptions) optionIndex) { + case PKG_FILES: { + const char *keyString; + Tcl_Obj *result = Tcl_NewObj(); + + for (i = 2; i < objc; i++) { + keyString = TclGetString(objv[i]); + hPtr = Tcl_FindHashEntry(&iPtr->packageTable, keyString); + if (hPtr == NULL) { + continue; + } + pkgPtr = Tcl_GetHashValue(hPtr); + availPtr = pkgPtr->availPtr; + while (availPtr != NULL) { + Tcl_ListObjAppendElement(interp, result, Tcl_NewStringObj(availPtr->script, -1)); + availPtr = availPtr->nextPtr; + } + ckfree(pkgPtr); + } + Tcl_SetObjResult(interp, result); + break; + } case PKG_FORGET: { const char *keyString; @@ -1220,7 +1294,7 @@ FindPackage( void TclFreePackageInfo( - Interp *iPtr) /* Interpereter that is being deleted. */ + Interp *iPtr) /* Interpreter that is being deleted. */ { Package *pkgPtr; Tcl_HashSearch search; diff --git a/tests/package.test b/tests/package.test index 49346d8..99f9f06 100644 --- a/tests/package.test +++ b/tests/package.test @@ -832,7 +832,7 @@ test package-4.52 {Tcl_PackageCmd procedure, "vsatisfies" option} { } {0} test package-4.53 {Tcl_PackageCmd procedure, "versions" option} -body { package foo -} -returnCodes error -result {bad option "foo": must be forget, ifneeded, names, prefer, present, provide, require, unknown, vcompare, versions, or vsatisfies} +} -returnCodes error -result {bad option "foo": must be files, forget, ifneeded, names, prefer, present, provide, require, unknown, vcompare, versions, or vsatisfies} test package-4.54 {Tcl_PackageCmd procedure, "vsatisfies" option} -body { package vsatisfies 2.1 2.1-3.2-4.5 } -returnCodes error -result {expected versionMin-versionMax but got "2.1-3.2-4.5"} -- cgit v0.12 From fabd3e7dc8882faee98b35feb738939c197e23b5 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sat, 26 Nov 2016 17:47:27 +0000 Subject: Add "package files" testcase, which doesn give the right answer. So still work to do --- tests/load.test | 4 ++-- tests/package.test | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/load.test b/tests/load.test index 7c4b47f..94451e9 100644 --- a/tests/load.test +++ b/tests/load.test @@ -197,14 +197,14 @@ test load-8.2 {TclGetLoadedPackages procedure} -body { } -returnCodes error -result {could not find interpreter "gorp"} test load-8.3a {TclGetLoadedPackages procedure} [list teststaticpkg $dll $loaded] { lsort -index 1 [info loaded {}] -} [lsort -index 1 [list {{} Double} {{} More} {{} Another} {{} Test} [list [file join $testDir pkga$ext] Pkga] [list [file join $testDir pkgb$ext] Pkgb] {*}$alreadyLoaded]] +} [lsort -index 1 [list {{} Double} {{} More} {{} Another} {{} Test} [list [file join $testDir pkga$ext] Pkga] [list [file join $testDir pkgb$ext] Pkgb] [list [file join $testDir pkge$ext] Pkge] {*}$alreadyLoaded]] test load-8.3b {TclGetLoadedPackages procedure} [list teststaticpkg $dll $loaded] { lsort -index 1 [info loaded child] } [lsort -index 1 [list {{} Test} [list [file join $testDir pkgb$ext] Pkgb]]] test load-8.4 {TclGetLoadedPackages procedure} [list $dll $loaded teststaticpkg] { load [file join $testDir pkgb$ext] pkgb list [lsort -index 1 [info loaded {}]] [lsort [info commands pkgb_*]] -} [list [lsort -index 1 [concat [list [list [file join $testDir pkgb$ext] Pkgb] {{} Double} {{} More} {{} Another} {{} Test} [list [file join $testDir pkga$ext] Pkga]] $alreadyLoaded]] {pkgb_demo pkgb_sub pkgb_unsafe}] +} [list [lsort -index 1 [concat [list [list [file join $testDir pkgb$ext] Pkgb] [list [file join $testDir pkge$ext] Pkge] {{} Double} {{} More} {{} Another} {{} Test} [list [file join $testDir pkga$ext] Pkga]] $alreadyLoaded]] {pkgb_demo pkgb_sub pkgb_unsafe}] interp delete child test load-9.1 {Tcl_StaticPackage, load already-loaded package into another interp} \ diff --git a/tests/package.test b/tests/package.test index 99f9f06..7e8a42d 100644 --- a/tests/package.test +++ b/tests/package.test @@ -55,8 +55,8 @@ test package-1.7 {pkg::create gives correct output for 1 direct source} { ::pkg::create -name foo -version 1.0 -source test.tcl } {package ifneeded foo 1.0 [list source [file join $dir test.tcl]]} test package-1.8 {pkg::create gives correct output for 2 direct sources} { - ::pkg::create -name foo -version 1.0 -source test.tcl -source test2.tcl -} {package ifneeded foo 1.0 [list source [file join $dir test.tcl]]\n[list source [file join $dir test2.tcl]]} + list [::pkg::create -name foo -version 1.0 -source test.tcl -source test2.tcl] [package files foo] +} {{package ifneeded foo 1.0 [list source [file join $dir test.tcl]]\n[list source [file join $dir test2.tcl]]} {}} test package-1.9 {pkg::create gives correct output for 1 direct load} { ::pkg::create -name foo -version 1.0 -load test.so } {package ifneeded foo 1.0 [list load [file join $dir test.so]]} @@ -870,6 +870,14 @@ test package-5.2 {TclFreePackageInfo procedure} -body { } foo eval package require x 3.1 } -returnCodes error -match glob -result * +test package-5.3 {package files} -body { + interp create foo + foo eval { + package ifneeded t 2.4 {package provide t 2.4;package require http} + } + foo eval package require t 2.4 + foo eval {list [package files http] [package files t]} +} -result "[list {}] [file join $tcl_library http http.tcl]" test package-6.1 {CheckVersion procedure} { package vcompare 1 2.1 -- cgit v0.12 From e506fbc42c805d0a6dfe2982a6169a0397aeddad Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 28 Nov 2016 13:17:47 +0000 Subject: Complete implementation, tests and documentation --- doc/info.n | 7 +-- doc/package.n | 8 ++++ generic/tclCmdMZ.c | 27 ++++++++++- generic/tclInt.h | 1 + generic/tclInterp.c | 19 +++++++- generic/tclPkg.c | 24 ++++++---- library/init.tcl | 2 +- library/package.tcl | 2 +- library/tclIndex | 134 ++++++++++++++++++++++++++-------------------------- tests/package.test | 2 +- 10 files changed, 140 insertions(+), 86 deletions(-) diff --git a/doc/info.n b/doc/info.n index 477e272..01ca10b 100644 --- a/doc/info.n +++ b/doc/info.n @@ -297,10 +297,11 @@ scripts are stored. This is actually the value of the \fBtcl_library\fR variable and may be changed by setting \fBtcl_library\fR. .TP -\fBinfo loaded \fR?\fIinterp\fR? +\fBinfo loaded \fR?\fIinterp\fR? \fR?\fIpackage\fR? . -Returns a list describing all of the packages that have been loaded into -\fIinterp\fR with the \fBload\fR command. +Returns the filename loaded as part of \fIpackage\fR. If \fIpackage\fR +is not specified, returns a list describing all of the packages +that have been loaded into \fIinterp\fR with the \fBload\fR command. Each list element is a sub-list with two elements consisting of the name of the file from which the package was loaded and the name of the package. diff --git a/doc/package.n b/doc/package.n index 47b2aa6..5687480 100644 --- a/doc/package.n +++ b/doc/package.n @@ -12,6 +12,7 @@ package \- Facilities for package loading and version control .SH SYNOPSIS .nf +\fBpackage files\fR \fIpackage\fR \fBpackage forget\fR ?\fIpackage package ...\fR? \fBpackage ifneeded \fIpackage version\fR ?\fIscript\fR? \fBpackage names\fR @@ -43,6 +44,13 @@ primarily by system scripts that maintain the package database. The behavior of the \fBpackage\fR command is determined by its first argument. The following forms are permitted: .TP +\fBpackage files\fR \fIpackage\fR +. +Lists all files forming part of \fIpackage\fR. Auto-loaded files are not +included in this list, only files which were directly sourced during package +initialization. The list order corresponds with the order in which the +files were sourced. +.TP \fBpackage forget\fR ?\fIpackage package ...\fR? . Removes all information about each specified package from this interpreter, diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index ed3d9a5..7f2a2f3 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -989,8 +989,11 @@ TclNRSourceObjCmd( { const char *encodingName = NULL; Tcl_Obj *fileName; + int result; + void **pkgFiles = NULL; + void *names = NULL; - if (objc != 2 && objc !=4) { + if (objc < 2 || objc > 4) { Tcl_WrongNumArgs(interp, 1, objv, "?-encoding name? fileName"); return TCL_ERROR; } @@ -1008,8 +1011,28 @@ TclNRSourceObjCmd( return TCL_ERROR; } encodingName = TclGetString(objv[2]); + } else if (objc == 3) { + static const char *const nopkgoptions[] = { + "-nopkg", NULL + }; + int index; + + if (TCL_ERROR == Tcl_GetIndexFromObj(interp, objv[1], nopkgoptions, + "option", TCL_EXACT, &index)) { + return TCL_ERROR; + } + pkgFiles = Tcl_GetAssocData(interp, "tclPkgFiles", NULL); + /* Make sure that during the following TclNREvalFile no filenames + * are recorded for inclusion in the "package files" command */ + names = *pkgFiles; + *pkgFiles = NULL; } - return TclNREvalFile(interp, fileName, encodingName); + result = TclNREvalFile(interp, fileName, encodingName); + if (pkgFiles) { + /* restore "tclPkgFiles" assocdata to how it was. */ + *pkgFiles = names; + } + return result; } /* diff --git a/generic/tclInt.h b/generic/tclInt.h index bfcd002..9422a03 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -3101,6 +3101,7 @@ MODULE_SCOPE Tcl_Channel TclpOpenTemporaryFile(Tcl_Obj *dirObj, Tcl_Obj *basenameObj, Tcl_Obj *extensionObj, Tcl_Obj *resultingNameObj); MODULE_SCOPE void TclPkgFileSeen(Tcl_Interp *interp, const char *fileName); +MODULE_SCOPE void *TclInitPkgFiles(Tcl_Interp *interp); MODULE_SCOPE Tcl_Obj * TclPathPart(Tcl_Interp *interp, Tcl_Obj *pathPtr, Tcl_PathPart portion); MODULE_SCOPE char * TclpReadlink(const char *fileName, diff --git a/generic/tclInterp.c b/generic/tclInterp.c index 1bfe76a..7874de9 100644 --- a/generic/tclInterp.c +++ b/generic/tclInterp.c @@ -331,13 +331,24 @@ TclSetPreInitScript( *---------------------------------------------------------------------- */ +typedef struct PkgName { + struct PkgName *nextPtr; /* Next in list of package names being initialized. */ + char name[4]; +} PkgName; + int Tcl_Init( Tcl_Interp *interp) /* Interpreter to initialize. */ { + PkgName pkgName = {NULL, "Tcl"}; + PkgName **names = TclInitPkgFiles(interp); + int result = TCL_ERROR; + + pkgName.nextPtr = *names; + *names = &pkgName; if (tclPreInitScript != NULL) { if (Tcl_EvalEx(interp, tclPreInitScript, -1, 0) == TCL_ERROR) { - return TCL_ERROR; + goto end; } } @@ -382,7 +393,7 @@ Tcl_Init( * alternate tclInit command before calling Tcl_Init(). */ - return Tcl_EvalEx(interp, + result = Tcl_EvalEx(interp, "if {[namespace which -command tclInit] eq \"\"} {\n" " proc tclInit {} {\n" " global tcl_libPath tcl_library env tclDefaultLibrary\n" @@ -445,6 +456,10 @@ Tcl_Init( " }\n" "}\n" "tclInit", -1, 0); + +end: + *names = (*names)->nextPtr; + return result; } /* diff --git a/generic/tclPkg.c b/generic/tclPkg.c index c258987..c3cc54e 100644 --- a/generic/tclPkg.c +++ b/generic/tclPkg.c @@ -38,7 +38,7 @@ typedef struct PkgName { } PkgName; typedef struct PkgFiles { - PkgName *names; /* Package names being initialized. */ + PkgName *names; /* Package names being initialized. Must be first field*/ Tcl_HashTable table; /* Table which contains files for each package */ } PkgFiles; @@ -222,6 +222,19 @@ static void PkgFilesCleanupProc(ClientData clientData, return; } +void *TclInitPkgFiles(Tcl_Interp *interp) +{ + /* If assocdata "tclPkgFiles" doesn't exist yet, create it */ + PkgFiles *pkgFiles = Tcl_GetAssocData(interp, "tclPkgFiles", NULL); + if (!pkgFiles) { + pkgFiles = ckalloc(sizeof(PkgFiles)); + pkgFiles->names = NULL; + Tcl_InitHashTable(&pkgFiles->table, TCL_STRING_KEYS); + Tcl_SetAssocData(interp, "tclPkgFiles", PkgFilesCleanupProc, pkgFiles); + } + return pkgFiles; +} + void TclPkgFileSeen(Tcl_Interp *interp, const char *fileName) { PkgFiles *pkgFiles = (PkgFiles *) Tcl_GetAssocData(interp, "tclPkgFiles", NULL); @@ -549,14 +562,7 @@ PkgRequireCore( pkgPtr->clientData = versionToProvide; Tcl_Preserve(versionToProvide); Tcl_Preserve(script); - /* If assocdata "tclPkgFiles" doesn't exist yet, create it */ - pkgFiles = Tcl_GetAssocData(interp, "tclPkgFiles", NULL); - if (!pkgFiles) { - pkgFiles = ckalloc(sizeof(PkgFiles)); - pkgFiles->names = NULL; - Tcl_InitHashTable(&pkgFiles->table, TCL_STRING_KEYS); - Tcl_SetAssocData(interp, "tclPkgFiles", PkgFilesCleanupProc, pkgFiles); - } + pkgFiles = TclInitPkgFiles(interp); /* Push "ifneeded" package name in "tclPkgFiles" assocdata. */ pkgName = ckalloc(sizeof(PkgName) + strlen(name)); pkgName->nextPtr = pkgFiles->names; diff --git a/library/init.tcl b/library/init.tcl index 544ea77..bac6270 100644 --- a/library/init.tcl +++ b/library/init.tcl @@ -483,7 +483,7 @@ proc auto_load_index {} { set dir [lindex $auto_path $i] set f "" if {$issafe} { - catch {source [file join $dir tclIndex]} + catch {source -nopkg [file join $dir tclIndex]} } elseif {[catch {set f [open [file join $dir tclIndex]]}]} { continue } else { diff --git a/library/package.tcl b/library/package.tcl index 44e3b28..cb1bea6 100644 --- a/library/package.tcl +++ b/library/package.tcl @@ -488,7 +488,7 @@ proc tclPkgUnknown {name args} { set dir [file dirname $file] if {![info exists procdDirs($dir)]} { try { - source $file + source -nopkg $file } trap {POSIX EACCES} {} { # $file was not readable; silently ignore continue diff --git a/library/tclIndex b/library/tclIndex index 26603c1..2762ce4 100644 --- a/library/tclIndex +++ b/library/tclIndex @@ -1,75 +1,75 @@ # Tcl autoload index file, version 2.0 # -*- tcl -*- # This file is generated by the "auto_mkindex" command -# and sourced to set up indexing information for one or +# and source -nopkgd to set up indexing information for one or # more commands. Typically each line is a command that # sets an element in the auto_index array, where the # element name is the name of a command and the value is # a script that loads the command. -set auto_index(auto_reset) [list source [file join $dir auto.tcl]] -set auto_index(tcl_findLibrary) [list source [file join $dir auto.tcl]] -set auto_index(auto_mkindex) [list source [file join $dir auto.tcl]] -set auto_index(auto_mkindex_old) [list source [file join $dir auto.tcl]] -set auto_index(::auto_mkindex_parser::init) [list source [file join $dir auto.tcl]] -set auto_index(::auto_mkindex_parser::cleanup) [list source [file join $dir auto.tcl]] -set auto_index(::auto_mkindex_parser::mkindex) [list source [file join $dir auto.tcl]] -set auto_index(::auto_mkindex_parser::hook) [list source [file join $dir auto.tcl]] -set auto_index(::auto_mkindex_parser::slavehook) [list source [file join $dir auto.tcl]] -set auto_index(::auto_mkindex_parser::command) [list source [file join $dir auto.tcl]] -set auto_index(::auto_mkindex_parser::commandInit) [list source [file join $dir auto.tcl]] -set auto_index(::auto_mkindex_parser::fullname) [list source [file join $dir auto.tcl]] -set auto_index(history) [list source [file join $dir history.tcl]] -set auto_index(::tcl::HistAdd) [list source [file join $dir history.tcl]] -set auto_index(::tcl::HistKeep) [list source [file join $dir history.tcl]] -set auto_index(::tcl::HistClear) [list source [file join $dir history.tcl]] -set auto_index(::tcl::HistInfo) [list source [file join $dir history.tcl]] -set auto_index(::tcl::HistRedo) [list source [file join $dir history.tcl]] -set auto_index(::tcl::HistIndex) [list source [file join $dir history.tcl]] -set auto_index(::tcl::HistEvent) [list source [file join $dir history.tcl]] -set auto_index(::tcl::HistChange) [list source [file join $dir history.tcl]] -set auto_index(pkg_mkIndex) [list source [file join $dir package.tcl]] -set auto_index(tclPkgSetup) [list source [file join $dir package.tcl]] -set auto_index(tclPkgUnknown) [list source [file join $dir package.tcl]] -set auto_index(::tcl::MacOSXPkgUnknown) [list source [file join $dir package.tcl]] -set auto_index(::pkg::create) [list source [file join $dir package.tcl]] -set auto_index(parray) [list source [file join $dir parray.tcl]] -set auto_index(::safe::InterpStatics) [list source [file join $dir safe.tcl]] -set auto_index(::safe::InterpNested) [list source [file join $dir safe.tcl]] -set auto_index(::safe::interpCreate) [list source [file join $dir safe.tcl]] -set auto_index(::safe::interpInit) [list source [file join $dir safe.tcl]] -set auto_index(::safe::CheckInterp) [list source [file join $dir safe.tcl]] -set auto_index(::safe::interpConfigure) [list source [file join $dir safe.tcl]] -set auto_index(::safe::InterpCreate) [list source [file join $dir safe.tcl]] -set auto_index(::safe::InterpSetConfig) [list source [file join $dir safe.tcl]] -set auto_index(::safe::interpFindInAccessPath) [list source [file join $dir safe.tcl]] -set auto_index(::safe::interpAddToAccessPath) [list source [file join $dir safe.tcl]] -set auto_index(::safe::InterpInit) [list source [file join $dir safe.tcl]] -set auto_index(::safe::AddSubDirs) [list source [file join $dir safe.tcl]] -set auto_index(::safe::interpDelete) [list source [file join $dir safe.tcl]] -set auto_index(::safe::setLogCmd) [list source [file join $dir safe.tcl]] -set auto_index(::safe::SyncAccessPath) [list source [file join $dir safe.tcl]] -set auto_index(::safe::PathToken) [list source [file join $dir safe.tcl]] -set auto_index(::safe::TranslatePath) [list source [file join $dir safe.tcl]] -set auto_index(::safe::Log) [list source [file join $dir safe.tcl]] -set auto_index(::safe::CheckFileName) [list source [file join $dir safe.tcl]] -set auto_index(::safe::AliasGlob) [list source [file join $dir safe.tcl]] -set auto_index(::safe::AliasSource) [list source [file join $dir safe.tcl]] -set auto_index(::safe::AliasLoad) [list source [file join $dir safe.tcl]] -set auto_index(::safe::FileInAccessPath) [list source [file join $dir safe.tcl]] -set auto_index(::safe::DirInAccessPath) [list source [file join $dir safe.tcl]] -set auto_index(::safe::Subset) [list source [file join $dir safe.tcl]] -set auto_index(::safe::AliasSubset) [list source [file join $dir safe.tcl]] -set auto_index(::safe::AliasEncoding) [list source [file join $dir safe.tcl]] -set auto_index(tcl_wordBreakAfter) [list source [file join $dir word.tcl]] -set auto_index(tcl_wordBreakBefore) [list source [file join $dir word.tcl]] -set auto_index(tcl_endOfWord) [list source [file join $dir word.tcl]] -set auto_index(tcl_startOfNextWord) [list source [file join $dir word.tcl]] -set auto_index(tcl_startOfPreviousWord) [list source [file join $dir word.tcl]] -set auto_index(::tcl::tm::add) [list source [file join $dir tm.tcl]] -set auto_index(::tcl::tm::remove) [list source [file join $dir tm.tcl]] -set auto_index(::tcl::tm::list) [list source [file join $dir tm.tcl]] -set auto_index(::tcl::tm::Defaults) [list source [file join $dir tm.tcl]] -set auto_index(::tcl::tm::UnknownHandler) [list source [file join $dir tm.tcl]] -set auto_index(::tcl::tm::roots) [list source [file join $dir tm.tcl]] -set auto_index(::tcl::tm::path) [list source [file join $dir tm.tcl]] +set auto_index(auto_reset) [list source -nopkg [file join $dir auto.tcl]] +set auto_index(tcl_findLibrary) [list source -nopkg [file join $dir auto.tcl]] +set auto_index(auto_mkindex) [list source -nopkg [file join $dir auto.tcl]] +set auto_index(auto_mkindex_old) [list source -nopkg [file join $dir auto.tcl]] +set auto_index(::auto_mkindex_parser::init) [list source -nopkg [file join $dir auto.tcl]] +set auto_index(::auto_mkindex_parser::cleanup) [list source -nopkg [file join $dir auto.tcl]] +set auto_index(::auto_mkindex_parser::mkindex) [list source -nopkg [file join $dir auto.tcl]] +set auto_index(::auto_mkindex_parser::hook) [list source -nopkg [file join $dir auto.tcl]] +set auto_index(::auto_mkindex_parser::slavehook) [list source -nopkg [file join $dir auto.tcl]] +set auto_index(::auto_mkindex_parser::command) [list source -nopkg [file join $dir auto.tcl]] +set auto_index(::auto_mkindex_parser::commandInit) [list source -nopkg [file join $dir auto.tcl]] +set auto_index(::auto_mkindex_parser::fullname) [list source -nopkg [file join $dir auto.tcl]] +set auto_index(history) [list source -nopkg [file join $dir history.tcl]] +set auto_index(::tcl::HistAdd) [list source -nopkg [file join $dir history.tcl]] +set auto_index(::tcl::HistKeep) [list source -nopkg [file join $dir history.tcl]] +set auto_index(::tcl::HistClear) [list source -nopkg [file join $dir history.tcl]] +set auto_index(::tcl::HistInfo) [list source -nopkg [file join $dir history.tcl]] +set auto_index(::tcl::HistRedo) [list source -nopkg [file join $dir history.tcl]] +set auto_index(::tcl::HistIndex) [list source -nopkg [file join $dir history.tcl]] +set auto_index(::tcl::HistEvent) [list source -nopkg [file join $dir history.tcl]] +set auto_index(::tcl::HistChange) [list source -nopkg [file join $dir history.tcl]] +set auto_index(pkg_mkIndex) [list source -nopkg [file join $dir package.tcl]] +set auto_index(tclPkgSetup) [list source -nopkg [file join $dir package.tcl]] +set auto_index(tclPkgUnknown) [list source -nopkg [file join $dir package.tcl]] +set auto_index(::tcl::MacOSXPkgUnknown) [list source -nopkg [file join $dir package.tcl]] +set auto_index(::pkg::create) [list source -nopkg [file join $dir package.tcl]] +set auto_index(parray) [list source -nopkg [file join $dir parray.tcl]] +set auto_index(::safe::InterpStatics) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::InterpNested) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::interpCreate) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::interpInit) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::CheckInterp) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::interpConfigure) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::InterpCreate) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::InterpSetConfig) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::interpFindInAccessPath) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::interpAddToAccessPath) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::InterpInit) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::AddSubDirs) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::interpDelete) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::setLogCmd) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::SyncAccessPath) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::PathToken) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::TranslatePath) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::Log) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::CheckFileName) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::AliasGlob) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::AliasSource) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::AliasLoad) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::FileInAccessPath) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::DirInAccessPath) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::Subset) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::AliasSubset) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(::safe::AliasEncoding) [list source -nopkg [file join $dir safe.tcl]] +set auto_index(tcl_wordBreakAfter) [list source -nopkg [file join $dir word.tcl]] +set auto_index(tcl_wordBreakBefore) [list source -nopkg [file join $dir word.tcl]] +set auto_index(tcl_endOfWord) [list source -nopkg [file join $dir word.tcl]] +set auto_index(tcl_startOfNextWord) [list source -nopkg [file join $dir word.tcl]] +set auto_index(tcl_startOfPreviousWord) [list source -nopkg [file join $dir word.tcl]] +set auto_index(::tcl::tm::add) [list source -nopkg [file join $dir tm.tcl]] +set auto_index(::tcl::tm::remove) [list source -nopkg [file join $dir tm.tcl]] +set auto_index(::tcl::tm::list) [list source -nopkg [file join $dir tm.tcl]] +set auto_index(::tcl::tm::Defaults) [list source -nopkg [file join $dir tm.tcl]] +set auto_index(::tcl::tm::UnknownHandler) [list source -nopkg [file join $dir tm.tcl]] +set auto_index(::tcl::tm::roots) [list source -nopkg [file join $dir tm.tcl]] +set auto_index(::tcl::tm::path) [list source -nopkg [file join $dir tm.tcl]] diff --git a/tests/package.test b/tests/package.test index 7e8a42d..55bba8a 100644 --- a/tests/package.test +++ b/tests/package.test @@ -877,7 +877,7 @@ test package-5.3 {package files} -body { } foo eval package require t 2.4 foo eval {list [package files http] [package files t]} -} -result "[list {}] [file join $tcl_library http http.tcl]" +} -result {{} {}} test package-6.1 {CheckVersion procedure} { package vcompare 1 2.1 -- cgit v0.12 From 5f5b7e42b2337f1fc7e33bccf2bcd8155fe968bc Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 28 Nov 2016 15:29:36 +0000 Subject: slightly simpler --- generic/tclPkg.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/generic/tclPkg.c b/generic/tclPkg.c index c3cc54e..c8f418c 100644 --- a/generic/tclPkg.c +++ b/generic/tclPkg.c @@ -570,8 +570,7 @@ PkgRequireCore( pkgFiles->names = pkgName; code = Tcl_EvalEx(interp, script, -1, TCL_EVAL_GLOBAL); /* Pop the "ifneeded" package name from "tclPkgFiles" assocdata*/ - pkgName = pkgFiles->names; - pkgFiles->names = pkgFiles->names->nextPtr; + pkgFiles->names = pkgName->nextPtr; ckfree(pkgName); Tcl_Release(script); -- cgit v0.12 From 99d3d95f4b8ae074c1c23d5599e32d976a6cb529 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 29 Nov 2016 09:45:20 +0000 Subject: Implement the "package forget" part, which was still missing. Handle the case that a filename contains spaces. --- generic/tclPkg.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/generic/tclPkg.c b/generic/tclPkg.c index c8f418c..42dd08d 100644 --- a/generic/tclPkg.c +++ b/generic/tclPkg.c @@ -243,15 +243,16 @@ void TclPkgFileSeen(Tcl_Interp *interp, const char *fileName) Tcl_HashTable *table = &pkgFiles->table; int new; Tcl_HashEntry *entry = Tcl_CreateHashEntry(table, name, &new); - Tcl_Obj *obj = Tcl_NewStringObj(fileName, -1); + Tcl_Obj *list; if (new) { - Tcl_SetHashValue(entry, obj); - Tcl_IncrRefCount(obj); + list = Tcl_NewObj(); + Tcl_SetHashValue(entry, list); + Tcl_IncrRefCount(list); } else { - Tcl_Obj *list = Tcl_GetHashValue(entry); - Tcl_ListObjAppendElement(interp, list, obj); + list = Tcl_GetHashValue(entry); } + Tcl_ListObjAppendElement(interp, list, Tcl_NewStringObj(fileName, -1)); } } @@ -889,9 +890,19 @@ Tcl_PackageObjCmd( } case PKG_FORGET: { const char *keyString; + PkgFiles *pkgFiles = (PkgFiles *) Tcl_GetAssocData(interp, "tclPkgFiles", NULL); for (i = 2; i < objc; i++) { keyString = TclGetString(objv[i]); + if (pkgFiles) { + hPtr = Tcl_FindHashEntry(&pkgFiles->table, keyString); + if (hPtr) { + Tcl_Obj *obj = Tcl_GetHashValue(hPtr); + Tcl_DeleteHashEntry(hPtr); + Tcl_DecrRefCount(obj); + } + } + hPtr = Tcl_FindHashEntry(&iPtr->packageTable, keyString); if (hPtr == NULL) { continue; -- cgit v0.12