From 257d2b53f2c1c9f1ea362662ac74a0ccb203537c Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 11 Dec 2023 13:45:31 +0000 Subject: [PATCH] size_t -> Tcl_Size, as recommended with Tcl 9 --- configure | 33 ++++++++++++++++++++++----------- generic/sample.c | 4 ++-- generic/sample.h | 2 +- generic/tclsample.c | 33 ++++++++++++++++----------------- win/nmakehlp.c | 5 ++--- win/rules.vc | 8 ++++++++ 6 files changed, 51 insertions(+), 34 deletions(-) diff --git a/configure b/configure index fad6c14..2e93de9 100755 --- a/configure +++ b/configure @@ -650,6 +650,7 @@ TCLSH_PROG VC_MANIFEST_EMBED_EXE VC_MANIFEST_EMBED_DLL RANLIB_STUB +PKG_STUB_LIB_FILE MAKE_STUB_LIB MAKE_STATIC_LIB MAKE_SHARED_LIB @@ -715,7 +716,6 @@ PKG_HEADERS PKG_TCL_SOURCES PKG_STUB_OBJECTS PKG_STUB_SOURCES -PKG_STUB_LIB_FILE PKG_LIB_FILE9 PKG_LIB_FILE8 PKG_LIB_FILE @@ -2563,8 +2563,6 @@ printf "%s\n" "$as_me: configuring ${PACKAGE_NAME} ${PACKAGE_VERSION}" >&6;} - # Substitute STUB_LIB_FILE in case package creates a stub library too. - # We AC_SUBST these here to ensure they are subst'ed, # in case the user doesn't call TEA_ADD_... @@ -5091,6 +5089,12 @@ printf "%s\n" "$tcl_cv_cc_pipe" >&6; } fi fi + if test "${TCL_MAJOR_VERSION}" -lt 9 -a "${TCL_MINOR_VERSION}" -lt 7; then + +printf "%s\n" "#define Tcl_Size int" >>confdefs.h + + fi + #-------------------------------------------------------------------- # Common compiler flag setup #-------------------------------------------------------------------- @@ -5319,9 +5323,7 @@ printf "%s\n" "$ac_cv_c_bigendian" >&6; } no) ;; #( universal) - -printf "%s\n" "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h - + # ;; #( *) as_fn_error $? "unknown endianness @@ -8810,7 +8812,11 @@ printf "%s\n" "#define TCL_MAJOR_VERSION 8" >>confdefs.h eval eval "PKG_LIB_FILE=${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}" fi # Some packages build their own stubs libraries - eval eval "PKG_STUB_LIB_FILE=${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}stub${UNSHARED_LIB_SUFFIX}" + if test "${TCL_MAJOR_VERSION}" -gt 8 -a x"${with_tcl8}" == x; then + eval eval "PKG_STUB_LIB_FILE=${PACKAGE_LIB_PREFIX8}${PACKAGE_NAME}stub.a" + else + eval eval "PKG_STUB_LIB_FILE=${PACKAGE_LIB_PREFIX8}${PACKAGE_NAME}stub${UNSHARED_LIB_SUFFIX}" + fi if test "$GCC" = "yes"; then PKG_STUB_LIB_FILE=lib${PKG_STUB_LIB_FILE} fi @@ -8829,12 +8835,16 @@ printf "%s\n" "#define TCL_MAJOR_VERSION 8" >>confdefs.h eval eval "PKG_LIB_FILE=lib${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}${SHARED_LIB_SUFFIX}" RANLIB=: else - eval eval "PKG_LIB_FILE=lib${PACKAGE_LIB_PREFIX8}${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}" - eval eval "PKG_LIB_FILE=lib${PACKAGE_LIB_PREFIX9}${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}" + eval eval "PKG_LIB_FILE8=lib${PACKAGE_LIB_PREFIX8}${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}" + eval eval "PKG_LIB_FILE9=lib${PACKAGE_LIB_PREFIX9}${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}" eval eval "PKG_LIB_FILE=lib${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}" fi # Some packages build their own stubs libraries - eval eval "PKG_STUB_LIB_FILE=lib${PACKAGE_LIB_PREFIX8}${PACKAGE_NAME}stub${UNSHARED_LIB_SUFFIX}" + if test "${TCL_MAJOR_VERSION}" -gt 8 -a x"${with_tcl8}" == x; then + eval eval "PKG_STUB_LIB_FILE=lib${PACKAGE_LIB_PREFIX8}${PACKAGE_NAME}stub.a" + else + eval eval "PKG_STUB_LIB_FILE=lib${PACKAGE_LIB_PREFIX8}${PACKAGE_NAME}stub${UNSHARED_LIB_SUFFIX}" + fi fi # These are escaped so that only CFLAGS is picked up at configure time. @@ -8848,6 +8858,8 @@ printf "%s\n" "#define TCL_MAJOR_VERSION 8" >>confdefs.h + # Substitute STUB_LIB_FILE in case package creates a stub library too. + @@ -9070,7 +9082,6 @@ LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs - CFLAGS="${CFLAGS} ${CPPFLAGS}"; CPPFLAGS="" : "${CONFIG_STATUS=./config.status}" diff --git a/generic/sample.c b/generic/sample.c index cdba0ee..f74f54b 100644 --- a/generic/sample.c +++ b/generic/sample.c @@ -225,9 +225,9 @@ void SHA1Update( SHA1_CTX* context, /* Context to update */ unsigned char* data, /* Data used for update */ - size_t len) /* Length of data */ + Tcl_Size len) /* Length of data */ { - size_t i, j; + Tcl_Size i, j; j = (context->count[0] >> 3) & 63; if ((context->count[0] += len << 3) < (len << 3)) { diff --git a/generic/sample.h b/generic/sample.h index f33d367..7c954fa 100644 --- a/generic/sample.h +++ b/generic/sample.h @@ -44,7 +44,7 @@ typedef struct { } SHA1_CTX; MODULE_SCOPE void SHA1Init(SHA1_CTX* context); -MODULE_SCOPE void SHA1Update(SHA1_CTX* context, unsigned char* data, size_t len); +MODULE_SCOPE void SHA1Update(SHA1_CTX* context, unsigned char* data, Tcl_Size len); MODULE_SCOPE void SHA1Final(SHA1_CTX* context, unsigned char digest[20]); /* diff --git a/generic/tclsample.c b/generic/tclsample.c index 1925a42..f1686c7 100644 --- a/generic/tclsample.c +++ b/generic/tclsample.c @@ -30,7 +30,7 @@ static const unsigned char itoa64f[] = static int numcontexts = 0; static SHA1_CTX *sha1Contexts = NULL; -static size_t *ctxtotalRead = NULL; +static Tcl_Size *ctxtotalRead = NULL; static int Sha1_Cmd(void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); @@ -78,7 +78,7 @@ Sha1_Cmd( int doinit = 1; int dofinal = 1; Tcl_Obj *descriptorObj = NULL; - size_t totalRead = 0, n; + Tcl_Size totalRead = 0, n; int i, j, mask, bits, offset; (void)dummy; @@ -114,7 +114,7 @@ Sha1_Cmd( switch ((enum ShaOpts) index) { case SHAOPT_INIT: for (contextnum = 1; contextnum < numcontexts; contextnum++) { - if (ctxtotalRead[contextnum] == (size_t)-1) { + if (ctxtotalRead[contextnum] == -1) { break; } } @@ -126,8 +126,8 @@ Sha1_Cmd( numcontexts++; sha1Contexts = (SHA1_CTX *) ckrealloc((void *) sha1Contexts, numcontexts * sizeof(SHA1_CTX)); - ctxtotalRead = (size_t *)ckrealloc(ctxtotalRead, - numcontexts * sizeof(size_t)); + ctxtotalRead = (Tcl_Size *)ckrealloc(ctxtotalRead, + numcontexts * sizeof(Tcl_Size)); } ctxtotalRead[contextnum] = 0; SHA1Init(&sha1Context); @@ -189,7 +189,7 @@ Sha1_Cmd( if (descriptorObj != NULL) { if ((sscanf(Tcl_GetString(descriptorObj), "sha1%d", &contextnum) != 1) || (contextnum >= numcontexts) || - (ctxtotalRead[contextnum] == (size_t)-1)) { + (ctxtotalRead[contextnum] == -1)) { Tcl_AppendResult(interp, "invalid sha1 descriptor \"", Tcl_GetString(descriptorObj), "\"", NULL); return TCL_ERROR; @@ -205,19 +205,18 @@ Sha1_Cmd( if (chan != NULL) { goto wrongArgs; } - string = Tcl_GetString(stringObj); - totalRead = stringObj->length; + string = Tcl_GetStringFromObj(stringObj, &totalRead); SHA1Update(&sha1Context, (unsigned char *) string, totalRead); } else if (chan != NULL) { bufPtr = (char *)ckalloc(TCL_READ_CHUNK_SIZE); totalRead = 0; - while ((n = (size_t)Tcl_Read(chan, bufPtr, + while ((n = Tcl_Read(chan, bufPtr, maxbytes == 0 ? TCL_READ_CHUNK_SIZE - : (TCL_READ_CHUNK_SIZE < (size_t)maxbytes + : (TCL_READ_CHUNK_SIZE < maxbytes ? TCL_READ_CHUNK_SIZE - : (size_t)maxbytes))) != 0) { - if (n == (size_t)-1) { + : maxbytes))) != 0) { + if (n == -1) { ckfree(bufPtr); Tcl_AppendResult(interp, Tcl_GetString(objv[0]), ": ", Tcl_GetChannelName(chan), Tcl_PosixError(interp), @@ -230,8 +229,8 @@ Sha1_Cmd( SHA1Update(&sha1Context, (unsigned char *) bufPtr, n); if (copychan != NULL) { - n = (size_t)Tcl_Write(copychan, bufPtr, n); - if (n == (size_t)-1) { + n = Tcl_Write(copychan, bufPtr, n); + if (n == -1) { ckfree(bufPtr); Tcl_AppendResult(interp, Tcl_GetString(objv[0]), ": ", Tcl_GetChannelName(copychan), @@ -240,7 +239,7 @@ Sha1_Cmd( } } - if ((maxbytes > 0) && ((size_t)maxbytes <= n)) { + if ((maxbytes > 0) && (maxbytes <= n)) { break; } maxbytes -= n; @@ -298,7 +297,7 @@ Sha1_Cmd( buf[j++] = '\0'; Tcl_AppendResult(interp, buf, NULL); if (contextnum > 0) { - ctxtotalRead[contextnum] = (size_t)-1; + ctxtotalRead[contextnum] = -1; } return TCL_OK; @@ -435,7 +434,7 @@ Sample_Init( numcontexts = 1; sha1Contexts = (SHA1_CTX *) ckalloc(sizeof(SHA1_CTX)); - ctxtotalRead = (size_t *) ckalloc(sizeof(size_t)); + ctxtotalRead = (Tcl_Size *) ckalloc(sizeof(Tcl_Size)); ctxtotalRead[0] = 0; return TCL_OK; diff --git a/win/nmakehlp.c b/win/nmakehlp.c index c8b39a7..b0799f8 100644 --- a/win/nmakehlp.c +++ b/win/nmakehlp.c @@ -19,7 +19,6 @@ #pragma comment (lib, "kernel32.lib") #endif #include -#include /* * This library is required for x64 builds with _some_ versions of MSVC @@ -272,7 +271,7 @@ CheckForCompilerFeature( if (!ok) { DWORD err = GetLastError(); int chars = snprintf(msg, sizeof(msg) - 1, - "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err); + "Tried to launch: \"%s\", but got error [%lu]: ", cmdline, err); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS| FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPSTR)&msg[chars], @@ -406,7 +405,7 @@ CheckForLinkerFeature( if (!ok) { DWORD err = GetLastError(); int chars = snprintf(msg, sizeof(msg) - 1, - "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err); + "Tried to launch: \"%s\", but got error [%lu]: ", cmdline, err); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS| FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPSTR)&msg[chars], diff --git a/win/rules.vc b/win/rules.vc index 3a95aab..4ee70ff 100644 --- a/win/rules.vc +++ b/win/rules.vc @@ -1240,7 +1240,11 @@ TKIMPLIBNAME = tk$(TK_VERSION)$(SUFX).lib TKLIBNAME = tcl9tk$(TK_VERSION)$(SUFX).$(EXT) TKIMPLIBNAME = tcl9tk$(TK_VERSION)$(SUFX).lib !endif +!if $(TK_MAJOR_VERSION) == 8 TKSTUBLIBNAME = tkstub$(TK_VERSION).lib +!else +TKSTUBLIBNAME = tkstub.lib +!endif !if $(DOING_TK) WISH = $(OUT_DIR)\$(WISHNAME) @@ -1530,6 +1534,10 @@ INCLUDES = $(INCLUDES) -I"$(GENERICDIR)" -I"$(WIN_DIR)" -I"$(COMPATDIR)" # cflags contains generic flags used for building practically all object files cflags = -nologo -c $(COMPILERFLAGS) $(carch) $(cwarn) -Fp$(TMP_DIR)^\ $(cdebug) +!if $(TCL_MAJOR_VERSION) == 8 && $(TCL_MINOR_VERSION) < 7 +cflags = $(cflags) -DTcl_Size=int +!endif + # appcflags contains $(cflags) and flags for building the application # object files (e.g. tclsh, or wish) pkgcflags contains $(cflags) plus # flags used for building shared object files The two differ in the