Skip to content

Commit

Permalink
changes to attempt support of both Tcl8 and Tcl9
Browse files Browse the repository at this point in the history
  • Loading branch information
mxmanghi authored and bovine committed Jan 18, 2024
1 parent e7d7d75 commit 7522eaf
Show file tree
Hide file tree
Showing 6 changed files with 497 additions and 392 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2023-11-21 mxmanghi
* Increment to 1.8.1 to mark changes introduced to
build with Tcl 9.0
* Update to latest tcl.m4 version

2017-03-15 pm-conej
* yajl "number" should reject invalid arguments (#22)
* Increment to 1.6.2
Expand Down
5 changes: 3 additions & 2 deletions configure.in
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dnl to configure the system for the local environment.
# so you can encode the package version directly into the source files.
#-----------------------------------------------------------------------

AC_INIT([yajltcl], [1.7.0])
AC_INIT([yajltcl],[1.8.1])

#--------------------------------------------------------------------
# Call TEA_INIT as the first TEA_ macro to set up initial vars.
Expand Down Expand Up @@ -191,4 +191,5 @@ TEA_PROG_TCLSH
PKG_CHECK_MODULES([YAJL], [yajl >= 2.0], [],
[AC_MSG_ERROR([Cannot find yajl])])

AC_OUTPUT([Makefile pkgIndex.tcl])
AC_CONFIG_FILES([Makefile pkgIndex.tcl])
AC_OUTPUT
8 changes: 4 additions & 4 deletions generic/tclyajltcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ Yajltcl_Init(Tcl_Interp *interp)
* This may work with 8.0, but we are using strictly stubs here,
* which requires 8.1.
*/
if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {
if (Tcl_InitStubs(interp, "8.0-", 0) == NULL) {
return TCL_ERROR;
}

if (Tcl_PkgRequire(interp, "Tcl", "8.1", 0) == NULL) {
if (Tcl_PkgRequire(interp, "Tcl", "8.0-", 0) == NULL) {
return TCL_ERROR;
}

Expand Down Expand Up @@ -83,11 +83,11 @@ Yajltcl_SafeInit(Tcl_Interp *interp)
* This may work with 8.0, but we are using strictly stubs here,
* which requires 8.1.
*/
if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {
if (Tcl_InitStubs(interp, "8.0-", 0) == NULL) {
return TCL_ERROR;
}

if (Tcl_PkgRequire(interp, "Tcl", "8.1", 0) == NULL) {
if (Tcl_PkgRequire(interp, "Tcl", "8.0-", 0) == NULL) {
return TCL_ERROR;
}

Expand Down
20 changes: 10 additions & 10 deletions generic/yajltcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,8 @@ yajltcl_yajlObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_Obj

// number? generate a number string and value
case OPT_NUMBER: {
char *number;
int len;
char *number;
yajltcl_size len;

if (arg + 1 >= objc) {
Tcl_WrongNumArgs (interp, 1, objv, "number value");
Expand All @@ -980,23 +980,23 @@ yajltcl_yajlObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_Obj
Tcl_AppendResult(interp, "Invalid value \"", number ,"\" for number input.", NULL);
return TCL_ERROR;
}
gstatus = yajl_gen_number (hand, number, len);
gstatus = yajl_gen_number (hand, number, (int)len);
break;
}

// map_key or string? generate a "string" string and value
case OPT_MAP_KEY:
case OPT_STRING: {
char *string;
int len;
yajltcl_size len;

if (arg + 1 >= objc) {
Tcl_WrongNumArgs (interp, 1, objv, "string value");
return TCL_ERROR;
}

string = Tcl_GetStringFromObj (objv[++arg], &len);
gstatus = yajl_gen_string (hand, (unsigned char *)string, len);
gstatus = yajl_gen_string (hand, (unsigned char *)string, (int)len);
break;
}

Expand All @@ -1007,7 +1007,7 @@ yajltcl_yajlObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_Obj
case OPT_PARSE2HUDDLE:
case OPT_PARSE: {
char *string;
int len;
yajltcl_size len;
yajl_handle parseHandle = NULL;

if (arg + 1 >= objc) {
Expand All @@ -1024,7 +1024,7 @@ yajltcl_yajlObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_Obj
}

string = Tcl_GetStringFromObj (objv[++arg], &len);
pstatus = yajl_parse (parseHandle, (unsigned char *)string, len);
pstatus = yajl_parse (parseHandle, (unsigned char *)string,(int)len);

if (pstatus != yajl_status_ok) {
unsigned char *str = yajl_get_error (parseHandle, 1, (unsigned char *)string, len);
Expand Down Expand Up @@ -1282,12 +1282,12 @@ yajltcl_yajlObjCmd(clientData, interp, objc, objv)
if (strcmp (commandName, "#auto") == 0) {
static unsigned long nextAutoCounter = 0;
char *objName;
int baseNameLength;
yajltcl_size baseNameLength;

objName = Tcl_GetStringFromObj (objv[0], &baseNameLength);
baseNameLength += snprintf (NULL, 0, "%lu", nextAutoCounter) + 1;
commandName = ckalloc (baseNameLength);
snprintf (commandName, baseNameLength, "%s%lu", objName, nextAutoCounter++);
commandName = ckalloc ((size_t)baseNameLength);
snprintf (commandName, (size_t)baseNameLength, "%s%lu", objName, nextAutoCounter++);
autoGeneratedName = 1;
}

Expand Down
9 changes: 9 additions & 0 deletions generic/yajltcl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@
* for details.
*/

#include <tcl.h>

/* NB - fix the configure script */
#include <yajl/yajl_version.h>
#include <yajl/yajl_common.h>
#include <yajl/yajl_gen.h>
#include <yajl/yajl_parse.h>

#if TCL_MAJOR_VERSION == 9
#undef CONST
#define CONST const
#define yajltcl_size Tcl_Size
#else
#define yajltcl_size int
#endif

extern int
yajltcl_yajlObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objvp[]);

Expand Down
Loading

0 comments on commit 7522eaf

Please sign in to comment.