Skip to content

Commit

Permalink
Add support for Tcl 9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chpock committed May 30, 2024
1 parent fe9ee63 commit 7c3449d
Show file tree
Hide file tree
Showing 36 changed files with 424 additions and 259 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/linux-build-9.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Linux (with Tcl 9.0)
on: [push]
permissions:
contents: read
defaults:
run:
shell: bash
jobs:
build:
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:

- name: Checkout Tcl
uses: actions/checkout@v4
with:
repository: tcltk/tcl
ref: core-9-0-b2-rc
path: tcl
- name: Configure Tcl
working-directory: tcl/unix
run: |
./configure --prefix=$HOME/tcl_install || {
cat config.log
echo "::error::Failure during Configure Tcl"
exit 1
}
- name: Build Tcl
working-directory: tcl/unix
run: |
make -j || {
echo "::error::Failure during Build Tcl"
exit 1
}
- name: Install Tcl
working-directory: tcl/unix
run: |
make install || {
echo "::error::Failure during Install Tcl"
exit 1
}
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Configure
run: |
./configure --with-tcl=$HOME/tcl_install/lib || {
cat config.log
echo "::error::Failure during Configure"
exit 1
}
- name: Build
run: |
make -j || {
echo "::error::Failure during Build"
exit 1
}
- name: Run Tests
run: |
MEMDEBUG=1 make test || {
echo "::error::Failure during Test"
exit 1
}
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
2024-05-30 Konstantin Kushnir <[email protected]>
* Fix multiple memory leaks
* Add feature to build without Tcl commands
* Add support for Tcl 9.0

2024-05-29 Konstantin Kushnir <[email protected]>
* Fix a regression when register volume and unregister with vfs::unmount
Expand Down
2 changes: 1 addition & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ AC_INIT([cookfs],[1.6.0])
# as well as PKG_LIB_FILE and PKG_STUB_LIB_FILE.
#--------------------------------------------------------------------

TEA_INIT([3.7])
TEA_INIT([3.13])

AC_CONFIG_AUX_DIR(tclconfig)

Expand Down
2 changes: 1 addition & 1 deletion generic/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ unsigned char *Cookfs_Int2Binary(int *input, unsigned char *output, int count);
unsigned char *Cookfs_Binary2WideInt(unsigned char *input, Tcl_WideInt *output, int count);
unsigned char *Cookfs_WideInt2Binary(Tcl_WideInt *input, unsigned char *output, int count);

void Cookfs_MD5(unsigned char *buf, unsigned int len, unsigned char digest[16]);
void Cookfs_MD5(unsigned char *buf, Tcl_Size len, unsigned char digest[16]);
Tcl_Obj *Cookfs_MD5FromObj(Tcl_Obj *obj);

#endif /* COOKFS_COMMON_H */
8 changes: 7 additions & 1 deletion generic/cookfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@
*----------------------------------------------------------------------
*/

#if TCL_MAJOR_VERSION > 8
#define MIN_TCL_VERSION "9.0"
#else
#define MIN_TCL_VERSION "8.5"
#endif

DLLEXPORT int
Cookfs_Init(Tcl_Interp *interp) // cppcheck-suppress unusedFunction
{

if (Tcl_InitStubs(interp, "8.5", 0) == NULL) {
if (Tcl_InitStubs(interp, MIN_TCL_VERSION, 0) == NULL) {
return TCL_ERROR;
}

Expand Down
17 changes: 17 additions & 0 deletions generic/cookfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@
# define STRINGIFY1(x) #x
#endif

/*
* Backwards compatibility for size type change
*/

#ifndef TCL_SIZE_MAX
#include <limits.h>
#ifndef Tcl_Size
typedef int Tcl_Size;
#endif /* Tcl_Size */
#define TCL_SIZE_MODIFIER ""
#define Tcl_GetSizeIntFromObj Tcl_GetIntFromObj
#define Tcl_NewSizeIntFromObj Tcl_NewIntObj
#define TCL_SIZE_MAX INT_MAX
#else
#define Tcl_NewSizeIntFromObj Tcl_NewWideIntObj
#endif /* TCL_SIZE_MAX */

#include "common.h"
#include "bindata.h"
#include "hashes.h"
Expand Down
12 changes: 7 additions & 5 deletions generic/fsindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ Cookfs_FsindexEntry *Cookfs_FsindexSet(Cookfs_Fsindex *i, Tcl_Obj *pathList, int
const Cookfs_FsindexEntry *foundFileNode;
Tcl_Obj *pathTail = NULL;
char *pathTailStr;
int pathTailLen;
int listSize;
Tcl_Size pathTailLen;
Tcl_Size listSize;

CookfsLog(printf("Cookfs_FsindexSet - start"))

Expand All @@ -490,7 +490,8 @@ Cookfs_FsindexEntry *Cookfs_FsindexSet(Cookfs_Fsindex *i, Tcl_Obj *pathList, int
return NULL;
}

CookfsLog(printf("Cookfs_FsindexSet - listSize=%d", listSize))
CookfsLog(printf("Cookfs_FsindexSet - listSize=%" TCL_SIZE_MODIFIER "d",
listSize));

if (listSize == 0) {
return NULL;
Expand Down Expand Up @@ -1083,7 +1084,7 @@ Cookfs_FsindexEntry *CookfsFsindexFindElement(const Cookfs_Fsindex *i, Tcl_Obj *

static Cookfs_FsindexEntry *CookfsFsindexFind(Cookfs_Fsindex *i, Cookfs_FsindexEntry **dirPtr, Tcl_Obj *pathList, int command, Cookfs_FsindexEntry *newFileNode) {
Cookfs_FsindexEntry *currentNode;
int listSize;
Tcl_Size listSize;
Tcl_Obj *pathTail;
char *pathTailStr;

Expand All @@ -1099,7 +1100,8 @@ static Cookfs_FsindexEntry *CookfsFsindexFind(Cookfs_Fsindex *i, Cookfs_FsindexE
}
}

CookfsLog(printf("CookfsFsindexCreateHashElement - LS=%d", listSize))
CookfsLog(printf("CookfsFsindexCreateHashElement - LS=%" TCL_SIZE_MODIFIER
"d", listSize))

/* find parent element */
currentNode = CookfsFsindexFindElement(i, pathList, listSize - 1);
Expand Down
2 changes: 1 addition & 1 deletion generic/fsindexCmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ static int CookfsFsindexCmdSetmtime(Cookfs_Fsindex *fsIndex, Tcl_Interp *interp,
*/

static int CookfsFsindexCmdSet(Cookfs_Fsindex *fsIndex, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) {
int numBlocks;
Tcl_Size numBlocks;
int fileBlockData;
Tcl_Obj *splitPath;
Tcl_Obj **listElements;
Expand Down
20 changes: 11 additions & 9 deletions generic/fsindexIO.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ Cookfs_Fsindex *Cookfs_FsindexFromPages(Cookfs_Fsindex *fsindex, Cookfs_Pages *p
Tcl_Obj *indexDataObj = Cookfs_PagesGetIndex(pages);
Tcl_IncrRefCount(indexDataObj);

int indexDataLen;
Tcl_Size indexDataLen;
Tcl_GetByteArrayFromObj(indexDataObj, &indexDataLen);
CookfsLog(printf("Cookfs_FsindexFromPages: got index data %d bytes",
indexDataLen));
CookfsLog(printf("Cookfs_FsindexFromPages: got index data %"
TCL_SIZE_MODIFIER "d bytes", indexDataLen));

if (indexDataLen) {
CookfsLog(printf("Cookfs_FsindexFromPages: import from the object..."));
Expand Down Expand Up @@ -149,7 +149,7 @@ Cookfs_Fsindex *Cookfs_FsindexFromPages(Cookfs_Fsindex *fsindex, Cookfs_Pages *p
*/

Cookfs_Fsindex *Cookfs_FsindexFromObject(Cookfs_Fsindex *fsindex, Tcl_Obj *o) {
int objLength;
Tcl_Size objLength;
int i;
unsigned char *bytes;
Cookfs_Fsindex *result;
Expand Down Expand Up @@ -184,13 +184,15 @@ Cookfs_Fsindex *Cookfs_FsindexFromObject(Cookfs_Fsindex *fsindex, Tcl_Obj *o) {
/* import root entry; import of subdirectories happens recursively */
i = CookfsFsindexImportDirectory(result, result->rootItem, bytes, objLength, 8);

CookfsLog(printf("Cookfs_FsindexFromObject - Import directory done - %d vs %d", i, objLength))
CookfsLog(printf("Cookfs_FsindexFromObject - Import directory done -"
" %d vs %" TCL_SIZE_MODIFIER "d", i, objLength))
if (i < objLength) {
// cppcheck-suppress unreadVariable symbolName=i
i = CookfsFsindexImportMetadata(result, bytes, objLength, i);
}

CookfsLog(printf("Cookfs_FsindexFromObject - Import metadata done - %d vs %d", i, objLength))
CookfsLog(printf("Cookfs_FsindexFromObject - Import metadata done -"
" %d vs %" TCL_SIZE_MODIFIER "d", i, objLength))

Cookfs_FsindexResetChangeCount(result);

Expand Down Expand Up @@ -226,7 +228,7 @@ static int CookfsFsindexExportDirectory(Cookfs_Fsindex *fsIndex, Cookfs_FsindexE
Cookfs_FsindexEntry *itemNode;

unsigned char *bytes;
int objLength;
Tcl_Size objLength;

/* get pointer to bytes in memory */
bytes = Tcl_GetByteArrayFromObj(result, &objLength);
Expand Down Expand Up @@ -462,7 +464,7 @@ static int CookfsFsindexImportDirectory(Cookfs_Fsindex *fsIndex, Cookfs_FsindexE
static int CookfsFsindexExportMetadata(Cookfs_Fsindex *fsIndex, Tcl_Obj *result, int objOffset) {
Tcl_HashEntry *hashEntry;
Tcl_HashSearch hashSearch;
int objSize;
Tcl_Size objSize;
int objInitialOffset = objOffset;
int objSizeChanged;
unsigned char *resultData;
Expand All @@ -488,7 +490,7 @@ static int CookfsFsindexExportMetadata(Cookfs_Fsindex *fsIndex, Tcl_Obj *result,
unsigned int keySize = strlen(paramName);

Tcl_Obj *valueObj = Tcl_GetHashValue(hashEntry);
int valueSize;
Tcl_Size valueSize;
unsigned char *valueData = Tcl_GetByteArrayFromObj(valueObj, &valueSize);

int size = keySize + 1 + valueSize;
Expand Down
6 changes: 3 additions & 3 deletions generic/hashes.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static int CookfsMd5Cmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl
Tcl_Obj *obj;
unsigned char *bytes;
unsigned char md5[MD5_DIGEST_SIZE];
int size;
Tcl_Size size;

if (objc < 2 || objc > 3) {
Tcl_WrongNumArgs(interp, 1, objv, "?-bin? data");
Expand Down Expand Up @@ -68,7 +68,7 @@ static int CookfsSha256Cmd(ClientData clientData, Tcl_Interp *interp, int objc,
unsigned char *bytes;
unsigned char sha256[SHA256_DIGEST_SIZE];
char hex[SHA256_DIGEST_SIZE*2+1];
int size;
Tcl_Size size;

if (objc < 2 || objc > 3) {
Tcl_WrongNumArgs(interp, 1, objv, "?-bin? data");
Expand Down Expand Up @@ -116,7 +116,7 @@ static int CookfsSha1Cmd(ClientData clientData, Tcl_Interp *interp, int objc, Tc
unsigned char *bytes;
unsigned char sha1[SHA1_DIGEST_SIZE];
char hex[SHA1_DIGEST_SIZE*2+1];
int size;
Tcl_Size size;

if (objc < 2 || objc > 3) {
Tcl_WrongNumArgs(interp, 1, objv, "?-bin? data");
Expand Down
8 changes: 4 additions & 4 deletions generic/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static void MD5Init (MD5_CTX *mdContext)
account for the presence of each of the characters inBuf[0..inLen-1]
in the message whose digest is being computed.
*/
static void MD5Update (register MD5_CTX *mdContext, unsigned char *inBuf, unsigned int inLen)
static void MD5Update (register MD5_CTX *mdContext, unsigned char *inBuf, Tcl_Size inLen)
{
register int i, ii;
int mdi;
Expand Down Expand Up @@ -318,7 +318,7 @@ static void Transform(register UINT4 *buf, register UINT4 *in)
*----------------------------------------------------------------------
*/

void Cookfs_MD5(unsigned char *buf, unsigned int len, unsigned char digest[16]) {
void Cookfs_MD5(unsigned char *buf, Tcl_Size len, unsigned char digest[16]) {
MD5_CTX ctx;
MD5Init(&ctx);
MD5Update(&ctx, buf, len);
Expand Down Expand Up @@ -348,11 +348,11 @@ Tcl_Obj *Cookfs_MD5FromObj(Tcl_Obj *obj) {
unsigned char md5sum[16];
char hex[36];
int i;
int size;
Tcl_Size size;

bytes = Tcl_GetByteArrayFromObj(obj, &size);

Cookfs_MD5(bytes, (unsigned int) size, md5sum);
Cookfs_MD5(bytes, size, md5sum);

for (i = 0; i < 16; i++) {
sprintf(hex + i + i, "%02X", ((int) md5sum[i]));
Expand Down
2 changes: 1 addition & 1 deletion generic/md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ typedef struct {
} MD5_CTX;

static void MD5Init (MD5_CTX *mdContext);
static void MD5Update (register MD5_CTX *mdContext, unsigned char *inBuf, unsigned int inLen);
static void MD5Update (register MD5_CTX *mdContext, unsigned char *inBuf, Tcl_Size inLen);
static void MD5Final (unsigned char digest[16], MD5_CTX *mdContext);
static void Transform (UINT4 *buf, UINT4 *in);

Expand Down
18 changes: 10 additions & 8 deletions generic/pages.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,16 +689,17 @@ static Tcl_WideInt Cookfs_PageSearchStamp(Cookfs_Pages *p) {

}

CookfsLog(printf("Cookfs_PageSearchStamp: read total %ld bytes and"
" could not find the stamp", read));
CookfsLog(printf("Cookfs_PageSearchStamp: read total %" TCL_LL_MODIFIER "d"
" bytes and could not find the stamp", read));

goto error;

found:


Cookfs_Binary2WideInt(&buf[i + COOKFS_SIGNATURE_LENGTH], &size, 1);
CookfsLog(printf("Cookfs_PageSearchStamp: return the size: %ld", size));
CookfsLog(printf("Cookfs_PageSearchStamp: return the size: %"
TCL_LL_MODIFIER "d", size));

error:

Expand Down Expand Up @@ -728,7 +729,8 @@ static Tcl_WideInt Cookfs_PageSearchStamp(Cookfs_Pages *p) {

int Cookfs_PageAddStamp(Cookfs_Pages *p, Tcl_WideInt size) {

CookfsLog(printf("Cookfs_PageAddStamp: enter, size: %ld", size));
CookfsLog(printf("Cookfs_PageAddStamp: enter, size: %" TCL_LL_MODIFIER "d",
size));

unsigned char sizeBin[8]; // 64-bit WideInt
Cookfs_WideInt2Binary(&size, sizeBin, 1);
Expand Down Expand Up @@ -801,7 +803,7 @@ int Cookfs_PageAddStamp(Cookfs_Pages *p, Tcl_WideInt size) {
*/

int Cookfs_PageAdd(Cookfs_Pages *p, Tcl_Obj *dataObj) {
int objLength;
Tcl_Size objLength;
unsigned char *bytes = Tcl_GetByteArrayFromObj(dataObj, &objLength);
return Cookfs_PageAddRaw(p, bytes, objLength);
}
Expand Down Expand Up @@ -873,7 +875,7 @@ int Cookfs_PageAddRaw(Cookfs_Pages *p, unsigned char *bytes, int objLength) {
/* even if MD5 checksums are the same, we still need to validate contents of the page */
Tcl_Obj *otherPageData;
unsigned char *otherBytes;
int otherObjLength;
Tcl_Size otherObjLength;
int isMatched = 1;

CookfsLog(printf("Cookfs_PageAdd: Comparing page %d", idx))
Expand Down Expand Up @@ -1424,7 +1426,7 @@ void Cookfs_PagesSetAside(Cookfs_Pages *p, Cookfs_Pages *aside) {
if (aside != NULL) {
CookfsLog(printf("Cookfs_PagesSetAside: Checking if index in add-aside archive should be overwritten."))
Tcl_Obj *asideIndex;
int asideIndexLength;
Tcl_Size asideIndexLength;
asideIndex = Cookfs_PagesGetIndex(aside);
Tcl_GetByteArrayFromObj(asideIndex, &asideIndexLength);
if (asideIndexLength == 0) {
Expand Down Expand Up @@ -1807,7 +1809,7 @@ static int CookfsReadIndex(Tcl_Interp *interp, Cookfs_Pages *p) {
Tcl_Seek(p->fileChannel, seekOffset, SEEK_SET);
byteObj = Tcl_NewObj();
if (Tcl_ReadChars(p->fileChannel, byteObj, 65536, 0) > 0) {
int size;
Tcl_Size size;
bytes = Tcl_GetByteArrayFromObj(byteObj, &size);
for (i = 0 ; i <= (size - COOKFS_SIGNATURE_LENGTH) ; i++) {
if (bytes[i] == p->fileSignature[0]) {
Expand Down
2 changes: 1 addition & 1 deletion generic/pagesCmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ int CookfsPagesCmdAside(Cookfs_Pages *pages, Tcl_Interp *interp, int objc, Tcl_O
}

Cookfs_Pages *asidePages;
int fileNameSize;
Tcl_Size fileNameSize;

Tcl_GetStringFromObj(objv[2], &fileNameSize);

Expand Down
Loading

0 comments on commit 7c3449d

Please sign in to comment.