Skip to content

Commit

Permalink
Refactor internal names for procedures/objects
Browse files Browse the repository at this point in the history
  • Loading branch information
chpock committed May 18, 2024
1 parent b643014 commit 5371474
Show file tree
Hide file tree
Showing 25 changed files with 727 additions and 787 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
work when readerchannel.tcl memchan.tcl pages.tcl fsindex.tcl unavailable,
but C module contains all required functionality.
* Return Tcl error from writer when closing a channel
* Refactor internal names for procedures/objects

2024-05-17 Konstantin Kushnir <[email protected]>
* Add support for c-writerchannel. This removes the dependency on vfs::memchan and improves memory utilization/performance
Expand Down
31 changes: 8 additions & 23 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -5453,29 +5453,14 @@ printf "%s\n" "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h



vars="scripts/cookvfs.tcl scripts/memchan.tcl scripts/vfs.tcl scripts/optimize.tcl scripts/asyncworker_process.tcl scripts/asyncworker_thread.tcl"
for i in $vars; do
# check for existence, be strict because it is installed
if test ! -f "${srcdir}/$i" ; then
as_fn_error $? "could not find tcl source file '${srcdir}/$i'" "$LINENO" 5
fi
PKG_TCL_SOURCES="$PKG_TCL_SOURCES $i"
done



vars="scripts/readerchannel.tcl"
for i in $vars; do
# check for existence, be strict because it is installed
if test ! -f "${srcdir}/$i" ; then
as_fn_error $? "could not find tcl source file '${srcdir}/$i'" "$LINENO" 5
fi
PKG_TCL_SOURCES="$PKG_TCL_SOURCES $i"
done



vars="scripts/writer.tcl"
vars="
scripts/writerchannel.tcl
scripts/vfs.tcl
scripts/asyncworker_process.tcl
scripts/asyncworker_thread.tcl
scripts/readerchannel.tcl
scripts/writer.tcl
"
for i in $vars; do
# check for existence, be strict because it is installed
if test ! -f "${srcdir}/$i" ; then
Expand Down
11 changes: 8 additions & 3 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ TEA_ADD_INCLUDES([-I\"`${CYGPATH} ${srcdir}/generic`\"])
TEA_ADD_LIBS([])
TEA_ADD_CFLAGS([-Wall -Wextra -pedantic -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections -fvisibility=hidden])
TEA_ADD_STUB_SOURCES([])
TEA_ADD_TCL_SOURCES([scripts/cookvfs.tcl scripts/memchan.tcl scripts/vfs.tcl scripts/optimize.tcl scripts/asyncworker_process.tcl scripts/asyncworker_thread.tcl])
TEA_ADD_TCL_SOURCES([scripts/readerchannel.tcl])
TEA_ADD_TCL_SOURCES([scripts/writer.tcl])
TEA_ADD_TCL_SOURCES([
scripts/writerchannel.tcl
scripts/vfs.tcl
scripts/asyncworker_process.tcl
scripts/asyncworker_thread.tcl
scripts/readerchannel.tcl
scripts/writer.tcl
])

#--------------------------------------------------------------------
# Define a special symbol for Windows (BUILD_sample in this case) so
Expand Down
4 changes: 2 additions & 2 deletions generic/cookfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ Cookfs_Init(Tcl_Interp *interp)
#ifdef COOKFS_USEPKGCONFIG
Tcl_RegisterConfig(interp, PACKAGE_NAME, cookfs_pkgconfig, "iso8859-1");

if (Tcl_PkgProvide(interp, "vfs::" PACKAGE_NAME "::pkgconfig", PACKAGE_VERSION) != TCL_OK) {
if (Tcl_PkgProvide(interp, PACKAGE_NAME "::pkgconfig", PACKAGE_VERSION) != TCL_OK) {
return TCL_ERROR;
}
#endif

if (Tcl_PkgProvide(interp, "vfs::" PACKAGE_NAME "::c", PACKAGE_VERSION) != TCL_OK) {
if (Tcl_PkgProvide(interp, PACKAGE_NAME "::c", PACKAGE_VERSION) != TCL_OK) {
return TCL_ERROR;
}

Expand Down
3 changes: 2 additions & 1 deletion generic/fsindexCmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ static int CookfsFsindexCmdImport(Cookfs_Fsindex *fsIndex, Tcl_Interp *interp, i
*/

int Cookfs_InitFsindexCmd(Tcl_Interp *interp) {
Tcl_CreateNamespace(interp, "::cookfs::c::fsindex", NULL, NULL);
Tcl_CreateObjCommand(interp, "::cookfs::c::fsindex", CookfsRegisterFsindexObjectCmd,
(ClientData) NULL, NULL);

Tcl_CreateAlias(interp, "::cookfs::fsindex", interp, "::cookfs::c::fsindex", 0, NULL);
return TCL_OK;
}

Expand Down
4 changes: 4 additions & 0 deletions generic/hashes.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,15 @@ int Cookfs_InitHashesCmd(Tcl_Interp *interp) {
Tcl_CreateObjCommand(interp, "::cookfs::c::md5", (Tcl_ObjCmdProc *)CookfsMd5Cmd,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);

Tcl_CreateAlias(interp, "::cookfs::md5", interp, "::cookfs::c::md5", 0, NULL);

#ifdef COOKFS_USEXZ
Tcl_CreateObjCommand(interp, "::cookfs::c::sha256", (Tcl_ObjCmdProc *)CookfsSha256Cmd,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateAlias(interp, "::cookfs::sha256", interp, "::cookfs::c::sha256", 0, NULL);
Tcl_CreateObjCommand(interp, "::cookfs::c::sha1", (Tcl_ObjCmdProc *)CookfsSha1Cmd,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateAlias(interp, "::cookfs::sha1", interp, "::cookfs::c::sha1", 0, NULL);
#endif

return TCL_OK;
Expand Down
53 changes: 53 additions & 0 deletions generic/pages.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,54 @@ static int CookfsReadIndex(Tcl_Interp *interp, Cookfs_Pages *p);
static void CookfsPagesPageExtendIfNeeded(Cookfs_Pages *p, int count);
static void CookfsTruncateFileIfNeeded(Cookfs_Pages *p, Tcl_WideInt targetOffset);

/*
*----------------------------------------------------------------------
*
* Cookfs_PagesGetLastError --
*
* Gets the description of the last error that occurred
*
* Results:
* None
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/

Tcl_Obj *Cookfs_PagesGetLastError(Cookfs_Pages *p) {
return p->lastErrorObj;
}

/*
*----------------------------------------------------------------------
*
* Cookfs_PagesSetLastError --
*
* Sets the description of the last error that occurred
*
* Results:
* None
*
* Side effects:
* Discards the previous registered error message
*
*----------------------------------------------------------------------
*/

void Cookfs_PagesSetLastError(Cookfs_Pages *p, const char *msg) {
if (p->lastErrorObj != NULL) {
Tcl_DecrRefCount(p->lastErrorObj);
}
if (msg == NULL) {
p->lastErrorObj = NULL;
} else {
p->lastErrorObj = Tcl_NewStringObj(msg, -1);
Tcl_IncrRefCount(p->lastErrorObj);
}
}


/*
*----------------------------------------------------------------------
Expand Down Expand Up @@ -117,6 +165,7 @@ Cookfs_Pages *Cookfs_PagesInit(Tcl_Interp *interp, Tcl_Obj *fileName, int fileRe

/* initialize basic information */
rc->interp = interp;
rc->lastErrorObj = NULL;
rc->commandToken = NULL;
rc->isAside = isAside;
Cookfs_PagesInitCompr(rc);
Expand Down Expand Up @@ -439,6 +488,10 @@ void Cookfs_PagesFini(Cookfs_Pages *p) {
Tcl_DeleteCommandFromToken(p->interp, p->commandToken);
}

if (p->lastErrorObj != NULL) {
Tcl_DecrRefCount(p->lastErrorObj);
}

CookfsLog(printf("Cleaning up pages"))
/* clean up storage */
Tcl_Free((void *) p);
Expand Down
4 changes: 4 additions & 0 deletions generic/pages.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef struct Cookfs_Pages {
/* main interp */
Tcl_Interp *interp;
Tcl_Command commandToken;
Tcl_Obj *lastErrorObj;
#ifdef COOKFS_USEXZ
CXzProps xzEncoderProps;
CXzEncHandle xzEncoder;
Expand Down Expand Up @@ -166,6 +167,9 @@ int Cookfs_PagesSetMaxAge(Cookfs_Pages *p, int maxAge);
int Cookfs_PagesTickTock(Cookfs_Pages *p);
int Cookfs_PagesIsCached(Cookfs_Pages *p, int index);

void Cookfs_PagesSetLastError(Cookfs_Pages *p, const char *msg);
Tcl_Obj *Cookfs_PagesGetLastError(Cookfs_Pages *p);

#endif /* COOKFS_USECPAGES */

#endif /* COOKFS_PAGES_H */
11 changes: 8 additions & 3 deletions generic/pagesCmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ static int CookfsRegisterPagesObjectCmd(ClientData clientData, Tcl_Interp *inter
*/

int Cookfs_InitPagesCmd(Tcl_Interp *interp) {
Tcl_CreateNamespace(interp, "::cookfs::c::pages", NULL, NULL);
Tcl_CreateObjCommand(interp, "::cookfs::c::pages", CookfsRegisterPagesObjectCmd,
(ClientData) NULL, NULL);

Tcl_CreateAlias(interp, "::cookfs::pages", interp, "::cookfs::c::pages", 0, NULL);
return TCL_OK;
}

Expand All @@ -63,7 +64,7 @@ void CookfsRegisterExistingPagesObjectCmd(Tcl_Interp *interp, Cookfs_Pages *p) {
}
char buf[128];
/* create Tcl command and return its name */
sprintf(buf, "::cookfs::c::pageshandle%p", (void *)p);
sprintf(buf, "::cookfs::c::pages::handle%p", (void *)p);
p->commandToken = Tcl_CreateObjCommand(interp, buf, CookfsPagesCmd,
(ClientData)p, CookfsPagesDeleteProc);
p->interp = interp;
Expand Down Expand Up @@ -334,7 +335,11 @@ static int CookfsPagesCmd(ClientData clientData, Tcl_Interp *interp, int objc, T
}
idx = Cookfs_PageAdd(p, objv[2]);
if (idx < 0) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("Unable to add page", -1));
Tcl_Obj *err = Cookfs_PagesGetLastError(p);
if (err == NULL) {
err = Tcl_NewStringObj("Unable to add page", -1);
}
Tcl_SetObjResult(interp, err);
return TCL_ERROR;
}

Expand Down
1 change: 1 addition & 0 deletions generic/pagesCompr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,7 @@ static Tcl_Obj *CookfsReadPageCustom(Cookfs_Pages *p, int size) {
int count;

if (p->decompressCommandPtr == NULL) {
Cookfs_PagesSetLastError(p, "No decompresscommand specified");
return NULL;
}

Expand Down
47 changes: 31 additions & 16 deletions pkgIndex.tcl.in
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
package ifneeded vfs::@PACKAGE_NAME@ @PACKAGE_VERSION@ [list source [file join $dir cookvfs.tcl]]
package ifneeded vfs::@PACKAGE_NAME@::tcl::memchan @PACKAGE_VERSION@ [list source [file join $dir memchan.tcl]]
package ifneeded vfs::@PACKAGE_NAME@::tcl::vfs @PACKAGE_VERSION@ [list source [file join $dir vfs.tcl]]
package ifneeded vfs::@PACKAGE_NAME@::tcl::readerchannel @PACKAGE_VERSION@ [list source [file join $dir readerchannel.tcl]]
package ifneeded vfs::@PACKAGE_NAME@::tcl::writer @PACKAGE_VERSION@ [list source [file join $dir writer.tcl]]
package ifneeded vfs::@PACKAGE_NAME@::tcl::pages @PACKAGE_VERSION@ [list source [file join $dir pages.tcl]]
package ifneeded vfs::@PACKAGE_NAME@::tcl::fsindex @PACKAGE_VERSION@ [list source [file join $dir fsindex.tcl]]
package ifneeded vfs::@PACKAGE_NAME@::tcl::optimize @PACKAGE_VERSION@ [list source [file join $dir optimize.tcl]]
package ifneeded vfs::@PACKAGE_NAME@::asyncworker::process @PACKAGE_VERSION@ [list source [file join $dir asyncworker_process.tcl]]
package ifneeded vfs::@PACKAGE_NAME@::asyncworker::thread @PACKAGE_VERSION@ [list source [file join $dir asyncworker_thread.tcl]]
package ifneeded @PACKAGE_NAME@::c @PACKAGE_VERSION@ [list load [file join $dir @PKG_LIB_FILE@] @PACKAGE_NAME@]

package ifneeded vfs::@PACKAGE_NAME@::pkgconfig @PACKAGE_VERSION@ [list ::apply {{ dir } {
if { @COOKFS_PKGCONFIG_USECPKGCONFIG@ } {
load [file join $dir @PKG_LIB_FILE@] @PACKAGE_NAME@
} else {
source [file join $dir pkgconfig.tcl]
package ifneeded @PACKAGE_NAME@::tcl::pkgconfig @PACKAGE_VERSION@ [list source [file join $dir pkgconfig.tcl]]
package ifneeded @PACKAGE_NAME@::tcl::writerchannel @PACKAGE_VERSION@ [list source [file join $dir writerchannel.tcl]]
package ifneeded @PACKAGE_NAME@::tcl::vfs @PACKAGE_VERSION@ [list source [file join $dir vfs.tcl]]
package ifneeded @PACKAGE_NAME@::tcl::readerchannel @PACKAGE_VERSION@ [list source [file join $dir readerchannel.tcl]]
package ifneeded @PACKAGE_NAME@::tcl::writer @PACKAGE_VERSION@ [list source [file join $dir writer.tcl]]
package ifneeded @PACKAGE_NAME@::tcl::pages @PACKAGE_VERSION@ [list source [file join $dir pages.tcl]]
package ifneeded @PACKAGE_NAME@::tcl::fsindex @PACKAGE_VERSION@ [list source [file join $dir fsindex.tcl]]
package ifneeded @PACKAGE_NAME@::asyncworker::process @PACKAGE_VERSION@ [list source [file join $dir asyncworker_process.tcl]]
package ifneeded @PACKAGE_NAME@::asyncworker::thread @PACKAGE_VERSION@ [list source [file join $dir asyncworker_thread.tcl]]

package ifneeded @PACKAGE_NAME@ @PACKAGE_VERSION@ [list ::apply {{ dir } {
# As for now, always load C module
package require @PACKAGE_NAME@::c @PACKAGE_VERSION@
if { ![llength [info commands @PACKAGE_NAME@::pkgconfig]] } {
package require @PACKAGE_NAME@::tcl::pkgconfig @PACKAGE_VERSION@
}
if { ![@PACKAGE_NAME@::pkgconfig get c-pages] } {
package require @PACKAGE_NAME@::tcl::pages @PACKAGE_VERSION@
}
if { ![@PACKAGE_NAME@::pkgconfig get c-fsindex] } {
package require @PACKAGE_NAME@::tcl::fsindex @PACKAGE_VERSION@
}
if { ![@PACKAGE_NAME@::pkgconfig get c-vfs] } {
package require @PACKAGE_NAME@::tcl::vfs @PACKAGE_VERSION@
}
package require @PACKAGE_NAME@::tcl::writer @PACKAGE_VERSION@
package provide @PACKAGE_NAME@ @PACKAGE_VERSION@
}} $dir]

package ifneeded vfs::@PACKAGE_NAME@::c @PACKAGE_VERSION@ [list load [file join $dir @PKG_LIB_FILE@] @PACKAGE_NAME@]
package ifneeded vfs::@PACKAGE_NAME@ @PACKAGE_VERSION@ [list ::apply {{ dir } {
package require @PACKAGE_NAME@ @PACKAGE_VERSION@
package provide vfs::@PACKAGE_NAME@ @PACKAGE_VERSION@
}} $dir]
3 changes: 1 addition & 2 deletions pkgconfig.tcl.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
namespace eval cookfs {}
namespace eval cookfs {}

proc cookfs::pkgconfig {{command ""} {value ""} {newValue ""}} {
variable pkgconfig
Expand Down Expand Up @@ -51,5 +50,5 @@ proc cookfs::pkgconfig {{command ""} {value ""} {newValue ""}} {
error "Usage: ::cookfs::pkgconfig list|get paramName"
}

package provide vfs::cookfs::pkgconfig 1.6.0
package provide cookfs::tcl::pkgconfig 1.6.0

2 changes: 1 addition & 1 deletion scripts/asyncworker_process.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,4 @@ proc cookfs::asyncworker::process::writeData {chan data} {
flush $chan
}

package provide vfs::cookfs::asyncworker::process 1.6.0
package provide cookfs::asyncworker::process 1.6.0
2 changes: 1 addition & 1 deletion scripts/asyncworker_thread.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,4 @@ proc ::cookfs::asyncworker::thread::handle {name cmd idx arg} {
}
}

package provide vfs::cookfs::asyncworker::thread 1.6.0
package provide cookfs::asyncworker::thread 1.6.0
Loading

0 comments on commit 5371474

Please sign in to comment.