From 4bb83d21d82dd85d12a0520889971701b37ab54a Mon Sep 17 00:00:00 2001 From: Stefano Weidmann Date: Sat, 19 Oct 2024 12:40:26 +0200 Subject: [PATCH] Make compilable with Tcl 9.0.0 --- tclreadline.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/tclreadline.c b/tclreadline.c index 3ce28e9..3515d5b 100644 --- a/tclreadline.c +++ b/tclreadline.c @@ -25,6 +25,25 @@ # include #endif +/* Check, if Tcl version supports Tcl_Size, + * which was introduced in Tcl 8.7 and 9. + */ +#ifndef TCL_SIZE_MAX +#include +#define TCL_SIZE_MAX INT_MAX + +#ifndef Tcl_Size +typedef int Tcl_Size; +#endif + +#define TCL_SIZE_MODIFIER "" +#define Tcl_GetSizeIntFromObj Tcl_GetIntFromObj +#endif + +/* TCL 9 does not define CONST anymore */ +#ifndef CONST +#define CONST const +#endif #ifdef EXTEND_LINE_BUFFER /* @@ -595,9 +614,15 @@ int Tclreadline_Init(Tcl_Interp *interp) { int status; - #ifdef USE_TCL_STUBS - Tcl_InitStubs(interp, "8.6", 0); + /* Require 8.6 or later (9.0 also ok) */ +#ifdef USE_TCL_STUBS + if ( NULL == Tcl_InitStubs(interp, "8.6-", 0)) +#else + if (NULL == Tcl_PkgRequire(interp, "Tcl", "8.6-", 0)) #endif + { + return TCL_ERROR; + } Tcl_CreateObjCommand(interp, "::tclreadline::readline", TclReadlineCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); tclrl_interp = interp; @@ -733,7 +758,7 @@ TclReadlineCompletion(char* text, int start, int end) char start_s[BUFSIZ], end_s[BUFSIZ]; Tcl_Obj* obj; Tcl_Obj** objv; - int objc; + Tcl_Size objc; int state; char* quoted_text = TclReadlineQuote(text, "$[]{}\""); char* quoted_rl_line_buffer = TclReadlineQuote(rl_line_buffer, "$[]{}\""); @@ -760,7 +785,8 @@ TclReadlineCompletion(char* text, int start, int end) return matches; if (objc) { - int i, length; + int i; + Tcl_Size length; matches = (char**) MALLOC(sizeof(char*) * (objc + 1)); for (i = 0; i < objc; i++) { matches[i] = strdup(Tcl_GetStringFromObj(objv[i], &length));