Skip to content

Commit

Permalink
size_t -> Tcl_Size, as recommended with Tcl 9
Browse files Browse the repository at this point in the history
  • Loading branch information
jan.nijtmans committed Dec 11, 2023
1 parent b8e2adc commit 257d2b5
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 34 deletions.
33 changes: 22 additions & 11 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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_...
Expand Down Expand Up @@ -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
#--------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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.




Expand Down Expand Up @@ -9070,7 +9082,6 @@ LIBOBJS=$ac_libobjs
LTLIBOBJS=$ac_ltlibobjs
CFLAGS="${CFLAGS} ${CPPFLAGS}"; CPPFLAGS=""
: "${CONFIG_STATUS=./config.status}"
Expand Down
4 changes: 2 additions & 2 deletions generic/sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion generic/sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

/*
Expand Down
33 changes: 16 additions & 17 deletions generic/tclsample.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[]);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -240,7 +239,7 @@ Sha1_Cmd(
}
}

if ((maxbytes > 0) && ((size_t)maxbytes <= n)) {
if ((maxbytes > 0) && (maxbytes <= n)) {
break;
}
maxbytes -= n;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions win/nmakehlp.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#pragma comment (lib, "kernel32.lib")
#endif
#include <stdio.h>
#include <math.h>

/*
* This library is required for x64 builds with _some_ versions of MSVC
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down
8 changes: 8 additions & 0 deletions win/rules.vc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 257d2b5

Please sign in to comment.