Skip to content

Commit

Permalink
Add support for c-writerchannel
Browse files Browse the repository at this point in the history
  • Loading branch information
chpock committed May 17, 2024
1 parent 93a196b commit 4363f13
Show file tree
Hide file tree
Showing 25 changed files with 1,187 additions and 37 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2024-05-17 Konstantin Kushnir <[email protected]>
* Add support for c-writerchannel. This removes the dependency on vfs::memchan and improves memory utilization/performance

2024-05-15 Konstantin Kushnir <[email protected]>
* Refactor Tcl/C code
* Add support for changecount subcommand for fsindex
Expand Down
64 changes: 63 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ COOKFS_PKGCONFIG_FEATURE_METADATA
COOKFS_PKGCONFIG_USECFSINDEX
COOKFS_PKGCONFIG_USEXZ
COOKFS_PKGCONFIG_USEBZ2
COOKFS_PKGCONFIG_USECWRITERCHAN
COOKFS_PKGCONFIG_USECREADERCHAN
COOKFS_PKGCONFIG_USECPAGES
COOKFS_PKGCONFIG_FEATURE_ASIDE
Expand Down Expand Up @@ -789,6 +790,7 @@ enable_tcl_fallback
enable_c_pages
enable_c_fsindex
enable_c_readerchannel
enable_c_writerchannel
enable_c_pkgconfig
enable_c_vfs
'
Expand Down Expand Up @@ -1434,6 +1436,7 @@ Optional Features:
--disable-c-pages Use pages handling written in C. Defaults to true
--disable-c-fsindex Use index handling written in C. Defaults to true
--disable-c-readerchannel Use reader handler written in C. Defaults to true
--disable-c-writerchannel Use writer handler written in C. Defaults to true
--disable-c-pkgconfig Use pkgconfig written in C. Defaults to true
--enable-c-vfs Use VFS support written in C. Defaults to false
Expand Down Expand Up @@ -8638,6 +8641,14 @@ else $as_nop
USECREADERCHAN=yes
fi

# Check whether --enable-c-writerchannel was given.
if test ${enable_c_writerchannel+y}
then :
enableval=$enable_c_writerchannel; USECWRITERCHAN=${enableval}
else $as_nop
USECWRITERCHAN=yes
fi

# Check whether --enable-c-pkgconfig was given.
if test ${enable_c_pkgconfig+y}
then :
Expand Down Expand Up @@ -8937,6 +8948,8 @@ else
USECVFS="no"
# c-readerchannel requires c-pages
USECREADERCHAN="no"
# c-writerchannel requires c-pages
USECWRITERCHAN="no"
fi

if test ${USECFSINDEX} = yes; then
Expand Down Expand Up @@ -8984,11 +8997,12 @@ else
USECVFS="no"
# c-readerchannel requires c-fsindex
USECREADERCHAN="no"
# c-writerchannel requires c-fsindex
USECWRITERCHAN="no"
fi

COOKFS_PKGCONFIG_FEATURE_METADATA=1

# reader channel requires support for pages in C
if test ${USECREADERCHAN} = yes; then
printf "%s\n" "#define COOKFS_USECREADERCHAN 1" >>confdefs.h

Expand Down Expand Up @@ -9034,6 +9048,51 @@ else
USECVFS="no"
fi

if test ${USECWRITERCHAN} = yes; then
printf "%s\n" "#define COOKFS_USECWRITERCHAN 1" >>confdefs.h

COOKFS_PKGCONFIG_USECWRITERCHAN=1

vars="writerchannel.c"
for i in $vars; do
case $i in
\$*)
# allow $-var names
PKG_SOURCES="$PKG_SOURCES $i"
PKG_OBJECTS="$PKG_OBJECTS $i"
;;
*)
# check for existence - allows for generic/win/unix VPATH
# To add more dirs here (like 'src'), you have to update VPATH
# in Makefile.in as well
if test ! -f "${srcdir}/$i" -a ! -f "${srcdir}/generic/$i" \
-a ! -f "${srcdir}/win/$i" -a ! -f "${srcdir}/unix/$i" \
-a ! -f "${srcdir}/macosx/$i" \
; then
as_fn_error $? "could not find source file '$i'" "$LINENO" 5
fi
PKG_SOURCES="$PKG_SOURCES $i"
# this assumes it is in a VPATH dir
i=`basename $i`
# handle user calling this before or after TEA_SETUP_COMPILER
if test x"${OBJEXT}" != x ; then
j="`echo $i | sed -e 's/\.[^.]*$//'`.${OBJEXT}"
else
j="`echo $i | sed -e 's/\.[^.]*$//'`.\${OBJEXT}"
fi
PKG_OBJECTS="$PKG_OBJECTS $j"
;;
esac
done



else
COOKFS_PKGCONFIG_USECWRITERCHAN=0
# c-vfs requires c-writerchannel
USECVFS="no"
fi

if test ${USECVFS} = yes; then
as_fn_error $? "support for c-vfs is not ready yet" "$LINENO" 5
printf "%s\n" "#define COOKFS_USECVFS 1" >>confdefs.h
Expand Down Expand Up @@ -9087,6 +9146,7 @@ fi




if test ${USECPKGCONFIG} = yes; then
COOKFS_PKGCONFIG_USECPKGCONFIG=1
printf "%s\n" "#define COOKFS_PKGCONFIG_FEATURE_ASIDE $COOKFS_PKGCONFIG_FEATURE_ASIDE" >>confdefs.h
Expand All @@ -9095,6 +9155,8 @@ if test ${USECPKGCONFIG} = yes; then

printf "%s\n" "#define COOKFS_PKGCONFIG_USECREADERCHAN $COOKFS_PKGCONFIG_USECREADERCHAN" >>confdefs.h

printf "%s\n" "#define COOKFS_PKGCONFIG_USECWRITERCHAN $COOKFS_PKGCONFIG_USECWRITERCHAN" >>confdefs.h

printf "%s\n" "#define COOKFS_PKGCONFIG_USECPKGCONFIG $COOKFS_PKGCONFIG_USECPKGCONFIG" >>confdefs.h

printf "%s\n" "#define COOKFS_PKGCONFIG_USEBZ2 $COOKFS_PKGCONFIG_USEBZ2" >>confdefs.h
Expand Down
18 changes: 17 additions & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ AC_ARG_ENABLE(tcl-fallback, [ --enable-tcl-fallback Install Tcl scripts
AC_ARG_ENABLE(c-pages, [ --disable-c-pages Use pages handling written in C. Defaults to true], USECPAGES=${enableval}, USECPAGES=yes)
AC_ARG_ENABLE(c-fsindex, [ --disable-c-fsindex Use index handling written in C. Defaults to true], USECFSINDEX=${enableval}, USECFSINDEX=yes)
AC_ARG_ENABLE(c-readerchannel, [ --disable-c-readerchannel Use reader handler written in C. Defaults to true], USECREADERCHAN=${enableval}, USECREADERCHAN=yes)
AC_ARG_ENABLE(c-writerchannel, [ --disable-c-writerchannel Use writer handler written in C. Defaults to true], USECWRITERCHAN=${enableval}, USECWRITERCHAN=yes)
AC_ARG_ENABLE(c-pkgconfig, [ --disable-c-pkgconfig Use pkgconfig written in C. Defaults to true], USECPKGCONFIG=${enableval}, USECPKGCONFIG=yes)
AC_ARG_ENABLE(c-vfs, [ --enable-c-vfs Use VFS support written in C. Defaults to false], USECVFS=${enableval}, USECVFS=no)

Expand Down Expand Up @@ -182,6 +183,8 @@ else
USECVFS="no"
# c-readerchannel requires c-pages
USECREADERCHAN="no"
# c-writerchannel requires c-pages
USECWRITERCHAN="no"
fi

if test ${USECFSINDEX} = yes; then
Expand All @@ -194,11 +197,12 @@ else
USECVFS="no"
# c-readerchannel requires c-fsindex
USECREADERCHAN="no"
# c-writerchannel requires c-fsindex
USECWRITERCHAN="no"
fi

COOKFS_PKGCONFIG_FEATURE_METADATA=1

# reader channel requires support for pages in C
if test ${USECREADERCHAN} = yes; then
AC_DEFINE(COOKFS_USECREADERCHAN)
COOKFS_PKGCONFIG_USECREADERCHAN=1
Expand All @@ -209,6 +213,16 @@ else
USECVFS="no"
fi

if test ${USECWRITERCHAN} = yes; then
AC_DEFINE(COOKFS_USECWRITERCHAN)
COOKFS_PKGCONFIG_USECWRITERCHAN=1
TEA_ADD_SOURCES([writerchannel.c])
else
COOKFS_PKGCONFIG_USECWRITERCHAN=0
# c-vfs requires c-writerchannel
USECVFS="no"
fi

if test ${USECVFS} = yes; then
AC_MSG_ERROR([support for c-vfs is not ready yet])
AC_DEFINE(COOKFS_USECVFS)
Expand All @@ -221,6 +235,7 @@ fi
AC_SUBST(COOKFS_PKGCONFIG_FEATURE_ASIDE)
AC_SUBST(COOKFS_PKGCONFIG_USECPAGES)
AC_SUBST(COOKFS_PKGCONFIG_USECREADERCHAN)
AC_SUBST(COOKFS_PKGCONFIG_USECWRITERCHAN)
AC_SUBST(COOKFS_PKGCONFIG_USEBZ2)
AC_SUBST(COOKFS_PKGCONFIG_USEXZ)
AC_SUBST(COOKFS_PKGCONFIG_USECFSINDEX)
Expand All @@ -232,6 +247,7 @@ if test ${USECPKGCONFIG} = yes; then
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_FEATURE_ASIDE, $COOKFS_PKGCONFIG_FEATURE_ASIDE)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECPAGES, $COOKFS_PKGCONFIG_USECPAGES)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECREADERCHAN, $COOKFS_PKGCONFIG_USECREADERCHAN)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECWRITERCHAN, $COOKFS_PKGCONFIG_USECWRITERCHAN)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECPKGCONFIG, $COOKFS_PKGCONFIG_USECPKGCONFIG)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USEBZ2, $COOKFS_PKGCONFIG_USEBZ2)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USEXZ, $COOKFS_PKGCONFIG_USEXZ)
Expand Down
6 changes: 6 additions & 0 deletions generic/cookfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ Cookfs_Init(Tcl_Interp *interp)
}
#endif

#ifdef COOKFS_USECWRITERCHAN
if (Cookfs_InitWriterchannelCmd(interp) != TCL_OK) {
return TCL_ERROR;
}
#endif

if (Cookfs_InitBinaryDataCmd(interp) != TCL_OK) {
return TCL_ERROR;
}
Expand Down
5 changes: 5 additions & 0 deletions generic/cookfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,17 @@
#include "vfsCmd.h"
#endif /* COOKFS_USECVFS */

#ifdef COOKFS_USECWRITERCHAN
#include "writerchannel.h"
#endif /* COOKFS_USECWRITERCHAN */

#ifdef COOKFS_USEPKGCONFIG
static Tcl_Config const cookfs_pkgconfig[] = {
{"package-version", PACKAGE_VERSION},
{"c-pages", STRINGIFY(COOKFS_PKGCONFIG_USECPAGES)},
{"c-fsindex", STRINGIFY(COOKFS_PKGCONFIG_USECFSINDEX)},
{"c-readerchannel", STRINGIFY(COOKFS_PKGCONFIG_USECREADERCHAN)},
{"c-writerchannel", STRINGIFY(COOKFS_PKGCONFIG_USECWRITERCHAN)},
{"c-vfs", STRINGIFY(COOKFS_PKGCONFIG_USECVFS)},
{"feature-aside", STRINGIFY(COOKFS_PKGCONFIG_FEATURE_ASIDE)},
{"feature-bzip2", STRINGIFY(COOKFS_PKGCONFIG_USEBZ2)},
Expand Down
7 changes: 7 additions & 0 deletions generic/fsindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ Cookfs_Fsindex *Cookfs_FsindexInit(Cookfs_Fsindex *i) {
rc->blockIndexSize = 0;
rc->blockIndex = NULL;
rc->changeCount = 0;
rc->commandToken = NULL;
rc->interp = NULL;
Tcl_InitHashTable(&rc->metadataHash, TCL_STRING_KEYS);
return rc;
}
Expand Down Expand Up @@ -254,7 +256,12 @@ void Cookfs_FsindexCleanup(Cookfs_Fsindex *i) {
*/

void Cookfs_FsindexFini(Cookfs_Fsindex *i) {
CookfsLog(printf("Cookfs_FsindexFini: release"));
Cookfs_FsindexCleanup(i);
CookfsLog(printf("Cleaning tcl command"));
if (i->commandToken != NULL) {
Tcl_DeleteCommandFromToken(i->interp, i->commandToken);
}
Tcl_Free((void *) i);
}

Expand Down
2 changes: 2 additions & 0 deletions generic/fsindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ typedef struct Cookfs_Fsindex {
int *blockIndex;
int blockIndexSize;
Tcl_WideInt changeCount;
Tcl_Interp *interp;
Tcl_Command commandToken;
} Cookfs_Fsindex;

Cookfs_Fsindex *Cookfs_FsindexGetHandle(Tcl_Interp *interp, const char *cmdName);
Expand Down
42 changes: 37 additions & 5 deletions generic/fsindexCmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,37 @@ int Cookfs_InitFsindexCmd(Tcl_Interp *interp) {
return TCL_OK;
}

/*
*----------------------------------------------------------------------
*
* CookfsRegisterExistingFsindexObjectCmd --
*
* Creates a Tcl command for existing fsindex object
*
* Results:
* None
*
* Side effects:
* New Tcl command is created on success. Set the interp result to
* the name of the created command.
*
*----------------------------------------------------------------------
*/

void CookfsRegisterExistingFsindexObjectCmd(Tcl_Interp *interp, Cookfs_Fsindex *i) {
if (i->commandToken != NULL) {
return;
}
char buf[128];
/* create Tcl command and return its name */
sprintf(buf, "::cookfs::c::fsindexhandle%p", (void *)i);
i->commandToken = Tcl_CreateObjCommand(interp, buf, CookfsFsindexCmd,
(ClientData) i, CookfsFsindexDeleteProc);
i->interp = interp;
Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, -1));
}


/* definitions of static and/or internal functions */

/*
Expand Down Expand Up @@ -111,10 +142,9 @@ static int CookfsRegisterFsindexObjectCmd(ClientData clientData, Tcl_Interp *int
return TCL_ERROR;
}

/* create new Tcl command to manage newly created fsindex and return its name */
Tcl_CreateObjCommand(interp, buf, CookfsFsindexCmd, (ClientData) i, CookfsFsindexDeleteProc);

Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, -1));
/* create Tcl command and return its name and set interp result to the command name */
CookfsLog(printf("Create Tcl command for the fsindex object..."))
CookfsRegisterExistingFsindexObjectCmd(interp, i);
return TCL_OK;

ERROR:
Expand All @@ -140,8 +170,10 @@ static int CookfsRegisterFsindexObjectCmd(ClientData clientData, Tcl_Interp *int
*/

static void CookfsFsindexDeleteProc(ClientData clientData) {
Cookfs_Fsindex *fsindex = (Cookfs_Fsindex *) clientData;
CookfsLog(printf("DELETING FSINDEX COMMAND"))
Cookfs_FsindexFini((Cookfs_Fsindex *) clientData);
fsindex->commandToken = NULL;
Cookfs_FsindexFini(fsindex);
CookfsLog(printf("DELETED FSINDEX COMMAND"))
}

Expand Down
1 change: 1 addition & 0 deletions generic/fsindexCmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifdef COOKFS_USECFSINDEX

int Cookfs_InitFsindexCmd(Tcl_Interp *interp);
void CookfsRegisterExistingFsindexObjectCmd(Tcl_Interp *interp, Cookfs_Fsindex *i);

#endif /* COOKFS_USECFSINDEX */

Expand Down
6 changes: 6 additions & 0 deletions generic/pages.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Cookfs_Pages *Cookfs_PagesInit(Tcl_Interp *interp, Tcl_Obj *fileName, int fileRe

/* initialize basic information */
rc->interp = interp;
rc->commandToken = NULL;
rc->isAside = isAside;
Cookfs_PagesInitCompr(rc);

Expand Down Expand Up @@ -433,6 +434,11 @@ void Cookfs_PagesFini(Cookfs_Pages *p) {
Tcl_Free((void *) p->dataPagesSize);
Tcl_Free((void *) p->dataPagesMD5);

CookfsLog(printf("Cleaning tcl command"));
if (p->commandToken != NULL) {
Tcl_DeleteCommandFromToken(p->interp, p->commandToken);
}

CookfsLog(printf("Cleaning up pages"))
/* clean up storage */
Tcl_Free((void *) p);
Expand Down
1 change: 1 addition & 0 deletions generic/pages.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef struct Cookfs_CacheEntry {
typedef struct Cookfs_Pages {
/* main interp */
Tcl_Interp *interp;
Tcl_Command commandToken;
#ifdef COOKFS_USEXZ
CXzProps xzEncoderProps;
CXzEncHandle xzEncoder;
Expand Down
Loading

0 comments on commit 4363f13

Please sign in to comment.