diff options
Diffstat (limited to 'Lib/tcl')
-rw-r--r-- | Lib/tcl/Makefile.in | 2 | ||||
-rw-r--r-- | Lib/tcl/argcargv.i | 27 | ||||
-rw-r--r-- | Lib/tcl/carrays.i | 3 | ||||
-rw-r--r-- | Lib/tcl/mactkinit.c | 233 | ||||
-rw-r--r-- | Lib/tcl/std_auto_ptr.i | 39 | ||||
-rw-r--r-- | Lib/tcl/std_map.i | 17 | ||||
-rw-r--r-- | Lib/tcl/std_string_view.i | 2 | ||||
-rw-r--r-- | Lib/tcl/std_unique_ptr.i | 39 | ||||
-rw-r--r-- | Lib/tcl/std_vector.i | 85 | ||||
-rw-r--r-- | Lib/tcl/swigmove.i | 1 | ||||
-rw-r--r-- | Lib/tcl/tclapi.swg | 6 | ||||
-rw-r--r-- | Lib/tcl/tclerrors.swg | 6 | ||||
-rw-r--r-- | Lib/tcl/tclinit.swg | 5 | ||||
-rw-r--r-- | Lib/tcl/tclprimtypes.swg | 37 | ||||
-rw-r--r-- | Lib/tcl/tclrun.swg | 103 | ||||
-rw-r--r-- | Lib/tcl/tclruntime.swg | 16 | ||||
-rw-r--r-- | Lib/tcl/tclsh.i | 55 | ||||
-rw-r--r-- | Lib/tcl/tclstrings.swg | 4 | ||||
-rw-r--r-- | Lib/tcl/tcltypemaps.swg | 5 | ||||
-rw-r--r-- | Lib/tcl/tclwstrings.swg | 15 | ||||
-rw-r--r-- | Lib/tcl/typemaps.i | 8 | ||||
-rw-r--r-- | Lib/tcl/wish.i | 70 |
22 files changed, 301 insertions, 477 deletions
diff --git a/Lib/tcl/Makefile.in b/Lib/tcl/Makefile.in index 13d7d4653..019091c98 100644 --- a/Lib/tcl/Makefile.in +++ b/Lib/tcl/Makefile.in @@ -45,7 +45,7 @@ LIBS = # SWIGCC = Compiler used to compile the wrapper file SWIG = $(exec_prefix)/bin/swig -SWIGOPT = -tcl # use -tcl8 for Tcl 8.0 +SWIGOPT = -tcl SWIGCC = $(CC) # SWIG Library files. Uncomment if rebuilding tclsh diff --git a/Lib/tcl/argcargv.i b/Lib/tcl/argcargv.i new file mode 100644 index 000000000..e93f69146 --- /dev/null +++ b/Lib/tcl/argcargv.i @@ -0,0 +1,27 @@ +/* ------------------------------------------------------------- + * SWIG library containing argc and argv multi-argument typemaps + * ------------------------------------------------------------- */ + +%typemap(in) (int ARGC, char **ARGV) { + Tcl_Size i, nitems; + Tcl_Obj **listobjv; + if (Tcl_ListObjGetElements(interp, $input, &nitems, &listobjv) == TCL_ERROR) { + SWIG_exception_fail(SWIG_ValueError, "in method '$symname', Expecting list of argv"); + goto fail; + } + $1 = ($1_ltype) nitems; + $2 = (char **) malloc((nitems+1)*sizeof(char *)); + for (i = 0; i < nitems; i++) { + $2[i] = Tcl_GetString(listobjv[i]); + } + $2[i] = NULL; +} + +%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) { + Tcl_Size len; + $1 = Tcl_ListObjLength(interp, $input, &len) == TCL_OK; +} + +%typemap(freearg) (int ARGC, char **ARGV) { + free((void *)$2); +} diff --git a/Lib/tcl/carrays.i b/Lib/tcl/carrays.i index 0236672d3..c1e6db3f0 100644 --- a/Lib/tcl/carrays.i +++ b/Lib/tcl/carrays.i @@ -1,4 +1 @@ %include <typemaps/carrays.swg> - - - diff --git a/Lib/tcl/mactkinit.c b/Lib/tcl/mactkinit.c deleted file mode 100644 index 8d1420088..000000000 --- a/Lib/tcl/mactkinit.c +++ /dev/null @@ -1,233 +0,0 @@ -/* ----------------------------------------------------------------------------- - * mactkinit.c - * - * This is a support file needed to build a new version of Wish. - * Normally, this capability is found in TkAppInit.c, but this creates - * tons of namespace problems for many applications. - * ----------------------------------------------------------------------------- */ - -#include <Gestalt.h> -#include <ToolUtils.h> -#include <Fonts.h> -#include <Dialogs.h> -#include <SegLoad.h> -#include <Traps.h> - -#include "tk.h" -#include "tkInt.h" -#include "tkMacInt.h" - -typedef int (*TclMacConvertEventPtr) _ANSI_ARGS_((EventRecord *eventPtr)); -Tcl_Interp *gStdoutInterp = NULL; - -void TclMacSetEventProc _ANSI_ARGS_((TclMacConvertEventPtr procPtr)); -int TkMacConvertEvent _ANSI_ARGS_((EventRecord *eventPtr)); - -/* - * Prototypes for functions the ANSI library needs to link against. - */ -short InstallConsole _ANSI_ARGS_((short fd)); -void RemoveConsole _ANSI_ARGS_((void)); -long WriteCharsToConsole _ANSI_ARGS_((char *buff, long n)); -long ReadCharsFromConsole _ANSI_ARGS_((char *buff, long n)); -char * __ttyname _ANSI_ARGS_((long fildes)); -short SIOUXHandleOneEvent _ANSI_ARGS_((EventRecord *event)); - -/* - * Forward declarations for procedures defined later in this file: - */ - -/* - *---------------------------------------------------------------------- - * - * MacintoshInit -- - * - * This procedure calls Mac specific initialization calls. Most of - * these calls must be made as soon as possible in the startup - * process. - * - * Results: - * Returns TCL_OK if everything went fine. If it didn't the - * application should probably fail. - * - * Side effects: - * Inits the application. - * - *---------------------------------------------------------------------- - */ - -int -MacintoshInit() -{ - int i; - long result, mask = 0x0700; /* mask = system 7.x */ - - /* - * Tk needs us to set the qd pointer it uses. This is needed - * so Tk doesn't have to assume the availiblity of the qd global - * variable. Which in turn allows Tk to be used in code resources. - */ - tcl_macQdPtr = &qd; - - InitGraf(&tcl_macQdPtr->thePort); - InitFonts(); - InitWindows(); - InitMenus(); - InitDialogs((long) NULL); - InitCursor(); - - /* - * Make sure we are running on system 7 or higher - */ - - if ((NGetTrapAddress(_Gestalt, ToolTrap) == - NGetTrapAddress(_Unimplemented, ToolTrap)) - || (((Gestalt(gestaltSystemVersion, &result) != noErr) - || (mask != (result & mask))))) { - panic("Tcl/Tk requires System 7 or higher."); - } - - /* - * Make sure we have color quick draw - * (this means we can't run on 68000 macs) - */ - - if (((Gestalt(gestaltQuickdrawVersion, &result) != noErr) - || (result < gestalt32BitQD13))) { - panic("Tk requires Color QuickDraw."); - } - - - FlushEvents(everyEvent, 0); - SetEventMask(everyEvent); - - /* - * Set up stack & heap sizes - */ - /* TODO: stack size - size = StackSpace(); - SetAppLimit(GetAppLimit() - 8192); - */ - MaxApplZone(); - for (i = 0; i < 4; i++) { - (void) MoreMasters(); - } - - TclMacSetEventProc(TkMacConvertEvent); - TkConsoleCreate(); - - return TCL_OK; -} - -/* - *---------------------------------------------------------------------- - * - * SetupMainInterp -- - * - * This procedure calls initialization routines require a Tcl - * interp as an argument. This call effectively makes the passed - * iterpreter the "main" interpreter for the application. - * - * Results: - * Returns TCL_OK if everything went fine. If it didn't the - * application should probably fail. - * - * Side effects: - * More initialization. - * - *---------------------------------------------------------------------- - */ - -int -SetupMainInterp( - Tcl_Interp *interp) -{ - /* - * Initialize the console only if we are running as an interactive - * application. - */ - - TkMacInitAppleEvents(interp); - TkMacInitMenus(interp); - - if (strcmp(Tcl_GetVar(interp, "tcl_interactive", TCL_GLOBAL_ONLY), "1") - == 0) { - if (TkConsoleInit(interp) == TCL_ERROR) { - goto error; - } - } - - /* - * Attach the global interpreter to tk's expected global console - */ - - gStdoutInterp = interp; - - return TCL_OK; - -error: - panic(interp->result); - return TCL_ERROR; -} - -/* - *---------------------------------------------------------------------- - * - * InstallConsole, RemoveConsole, etc. -- - * - * The following functions provide the UI for the console package. - * Users wishing to replace SIOUX with their own console package - * need only provide the four functions below in a library. - * - * Results: - * See SIOUX documentation for details. - * - * Side effects: - * See SIOUX documentation for details. - * - *---------------------------------------------------------------------- - */ - -short -InstallConsole(short fd) -{ -#pragma unused (fd) - - return 0; -} - -void -RemoveConsole(void) -{ -} - -long -WriteCharsToConsole(char *buffer, long n) -{ - TkConsolePrint(gStdoutInterp, TCL_STDOUT, buffer, n); - return n; -} - -long -ReadCharsFromConsole(char *buffer, long n) -{ - return 0; -} - -extern char * -__ttyname(long fildes) -{ - static char *devicename = "null device"; - - if (fildes >= 0 && fildes <= 2) { - return (devicename); - } - - return (0L); -} - -short -SIOUXHandleOneEvent(EventRecord *event) -{ - return 0; -} diff --git a/Lib/tcl/std_auto_ptr.i b/Lib/tcl/std_auto_ptr.i new file mode 100644 index 000000000..b24809af7 --- /dev/null +++ b/Lib/tcl/std_auto_ptr.i @@ -0,0 +1,39 @@ +/* ----------------------------------------------------------------------------- + * std_auto_ptr.i + * + * SWIG library file for handling std::auto_ptr. + * Memory ownership is passed from the std::auto_ptr C++ layer to the proxy + * class when returning a std::auto_ptr from a function. + * Memory ownership is passed from the proxy class to the std::auto_ptr in the + * C++ layer when passed as a parameter to a wrapped function. + * ----------------------------------------------------------------------------- */ + +%define %auto_ptr(TYPE) +%typemap(in, noblock=1) std::auto_ptr< TYPE > (void *argp = 0, int res = 0) { + res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags); + if (!SWIG_IsOK(res)) { + if (res == SWIG_ERROR_RELEASE_NOT_OWNED) { + %releasenotowned_fail(res, "TYPE *", $symname, $argnum); + } else { + %argument_fail(res, "TYPE *", $symname, $argnum); + } + } + $1.reset((TYPE *)argp); +} + +%typemap (out) std::auto_ptr< TYPE > %{ + Tcl_SetObjResult(interp, SWIG_NewInstanceObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN)); +%} + +%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::auto_ptr< TYPE > { + void *vptr = 0; + int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0); + $1 = SWIG_CheckState(res); +} + +%template() std::auto_ptr< TYPE >; +%enddef + +namespace std { + template <class T> class auto_ptr {}; +} diff --git a/Lib/tcl/std_map.i b/Lib/tcl/std_map.i index 2c7f40ac7..5c8bc75fc 100644 --- a/Lib/tcl/std_map.i +++ b/Lib/tcl/std_map.i @@ -47,7 +47,11 @@ namespace std { throw std::out_of_range("key not found"); } void set(const K& key, const T& x) { +%#ifdef __cpp_lib_map_try_emplace + (*self).insert_or_assign(key, x); +%#else (*self)[key] = x; +%#endif } void del(const K& key) throw (std::out_of_range) { std::map< K, T, C >::iterator i = self->find(key); @@ -63,17 +67,4 @@ namespace std { } }; -// Legacy macros (deprecated) -%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) -#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary" -%enddef - -%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) -#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary" -%enddef - -%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) -#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary" -%enddef - } diff --git a/Lib/tcl/std_string_view.i b/Lib/tcl/std_string_view.i new file mode 100644 index 000000000..9d922bccd --- /dev/null +++ b/Lib/tcl/std_string_view.i @@ -0,0 +1,2 @@ +%include <typemaps/std_string_view.swg> + diff --git a/Lib/tcl/std_unique_ptr.i b/Lib/tcl/std_unique_ptr.i new file mode 100644 index 000000000..0ea324cda --- /dev/null +++ b/Lib/tcl/std_unique_ptr.i @@ -0,0 +1,39 @@ +/* ----------------------------------------------------------------------------- + * std_unique_ptr.i + * + * SWIG library file for handling std::unique_ptr. + * Memory ownership is passed from the std::unique_ptr C++ layer to the proxy + * class when returning a std::unique_ptr from a function. + * Memory ownership is passed from the proxy class to the std::unique_ptr in the + * C++ layer when passed as a parameter to a wrapped function. + * ----------------------------------------------------------------------------- */ + +%define %unique_ptr(TYPE) +%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) { + res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags); + if (!SWIG_IsOK(res)) { + if (res == SWIG_ERROR_RELEASE_NOT_OWNED) { + %releasenotowned_fail(res, "TYPE *", $symname, $argnum); + } else { + %argument_fail(res, "TYPE *", $symname, $argnum); + } + } + $1.reset((TYPE *)argp); +} + +%typemap (out) std::unique_ptr< TYPE > %{ + Tcl_SetObjResult(interp, SWIG_NewInstanceObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN)); +%} + +%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::unique_ptr< TYPE > { + void *vptr = 0; + int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0); + $1 = SWIG_CheckState(res); +} + +%template() std::unique_ptr< TYPE >; +%enddef + +namespace std { + template <class T> class unique_ptr {}; +} diff --git a/Lib/tcl/std_vector.i b/Lib/tcl/std_vector.i index 5fba5379f..f950ee3fd 100644 --- a/Lib/tcl/std_vector.i +++ b/Lib/tcl/std_vector.i @@ -34,11 +34,11 @@ %{ #include <vector> -Tcl_Obj* SwigString_FromString(const std::string &s) { - return Tcl_NewStringObj(s.data(), (int)s.length()); +SWIGINTERN Tcl_Obj* SwigString_FromString(const std::string &s) { + return Tcl_NewStringObj(s.data(), (Tcl_Size)s.length()); } -int Tcl_GetBoolFromObj(Tcl_Interp *interp, Tcl_Obj *o, bool *val) { +SWIGINTERN int SWIG_Tcl_GetBoolFromObj(Tcl_Interp *interp, Tcl_Obj *o, bool *val) { int v; int res = Tcl_GetBooleanFromObj(interp, o, &v); if (res == TCL_OK) { @@ -47,9 +47,10 @@ int Tcl_GetBoolFromObj(Tcl_Interp *interp, Tcl_Obj *o, bool *val) { return res; } -int SwigString_AsString(Tcl_Interp *interp, Tcl_Obj *o, std::string *val) { - int len; +SWIGINTERN int SwigString_AsString(Tcl_Interp *interp, Tcl_Obj *o, std::string *val) { + Tcl_Size len; const char* temp = Tcl_GetStringFromObj(o, &len); + (void)interp; if (temp == NULL) return TCL_ERROR; val->assign(temp, len); @@ -84,16 +85,16 @@ namespace std { template<class T> class vector { %typemap(in) vector< T > (std::vector< T > *v) { Tcl_Obj **listobjv; - int nitems; - int i; + Tcl_Size nitems; + Tcl_Size i; T* temp; - if (SWIG_ConvertPtr($input, (void **) &v, \ + if (SWIG_ConvertPtr($input, (void **) &v, $&1_descriptor, 0) == 0){ $1 = *v; } else { // It isn't a vector< T > so it should be a list of T's - if(Tcl_ListObjGetElements(interp, $input, \ + if(Tcl_ListObjGetElements(interp, $input, &nitems, &listobjv) == TCL_ERROR) return TCL_ERROR; $1 = std::vector< T >(); @@ -113,12 +114,12 @@ namespace std { %typemap(in) const vector< T >* (std::vector< T > *v, std::vector< T > w), const vector< T >& (std::vector< T > *v, std::vector< T > w) { Tcl_Obj **listobjv; - int nitems; - int i; + Tcl_Size nitems; + Tcl_Size i; T* temp; - if(SWIG_ConvertPtr($input, (void **) &v, \ - $&1_descriptor, 0) == 0) { + if(SWIG_ConvertPtr($input, (void **) &v, + $1_descriptor, 0) == 0) { $1 = v; } else { // It isn't a vector< T > so it should be a list of T's @@ -143,7 +144,7 @@ namespace std { %typemap(out) vector< T > { for (unsigned int i=0; i<$1.size(); i++) { T* ptr = new T((($1_type &)$1)[i]); - Tcl_ListObjAppendElement(interp, $result, \ + Tcl_ListObjAppendElement(interp, $result, SWIG_NewInstanceObj(ptr, $descriptor(T *), 0)); @@ -152,11 +153,11 @@ namespace std { %typecheck(SWIG_TYPECHECK_VECTOR) vector< T > { Tcl_Obj **listobjv; - int nitems; + Tcl_Size nitems; T* temp; std::vector< T > *v; - if(SWIG_ConvertPtr($input, (void **) &v, \ + if(SWIG_ConvertPtr($input, (void **) &v, $&1_descriptor, 0) == 0) { /* wrapped vector */ $1 = 1; @@ -168,7 +169,7 @@ namespace std { else if (nitems == 0) $1 = 1; - //check the first value to see if it is of correct type + //check the first value to see if it is of correct type else if ((SWIG_ConvertPtr(listobjv[0], (void **) &temp, $descriptor(T *),0)) != 0) @@ -181,11 +182,11 @@ namespace std { %typecheck(SWIG_TYPECHECK_VECTOR) const vector< T >&, const vector< T >* { Tcl_Obj **listobjv; - int nitems; + Tcl_Size nitems; T* temp; std::vector< T > *v; - if(SWIG_ConvertPtr($input, (void **) &v, \ + if(SWIG_ConvertPtr($input, (void **) &v, $1_descriptor, 0) == 0){ /* wrapped vector */ $1 = 1; @@ -197,7 +198,7 @@ namespace std { else if (nitems == 0) $1 = 1; - //check the first value to see if it is of correct type + //check the first value to see if it is of correct type else if ((SWIG_ConvertPtr(listobjv[0], (void **) &temp, $descriptor(T *),0)) != 0) @@ -260,11 +261,11 @@ namespace std { %typemap(in) vector< T > (std::vector< T > *v){ Tcl_Obj **listobjv; - int nitems; - int i; + Tcl_Size nitems; + Tcl_Size i; T temp; - if(SWIG_ConvertPtr($input, (void **) &v, \ + if(SWIG_ConvertPtr($input, (void **) &v, $&1_descriptor, 0) == 0) { $1 = *v; } else { @@ -284,11 +285,11 @@ namespace std { %typemap(in) const vector< T >& (std::vector< T > *v,std::vector< T > w), const vector< T >* (std::vector< T > *v,std::vector< T > w) { Tcl_Obj **listobjv; - int nitems; - int i; + Tcl_Size nitems; + Tcl_Size i; T temp; - if(SWIG_ConvertPtr($input, (void **) &v, \ + if(SWIG_ConvertPtr($input, (void **) &v, $1_descriptor, 0) == 0) { $1 = v; } else { @@ -308,18 +309,18 @@ namespace std { %typemap(out) vector< T > { for (unsigned int i=0; i<$1.size(); i++) { - Tcl_ListObjAppendElement(interp, $result, \ + Tcl_ListObjAppendElement(interp, $result, CONVERT_TO((($1_type &)$1)[i])); } } %typecheck(SWIG_TYPECHECK_VECTOR) vector< T > { Tcl_Obj **listobjv; - int nitems; + Tcl_Size nitems; T temp; std::vector< T > *v; - if(SWIG_ConvertPtr($input, (void **) &v, \ + if(SWIG_ConvertPtr($input, (void **) &v, $&1_descriptor, 0) == 0){ /* wrapped vector */ $1 = 1; @@ -331,22 +332,22 @@ namespace std { else if (nitems == 0) $1 = 1; - //check the first value to see if it is of correct type - if (CONVERT_FROM(interp, listobjv[0], &temp) == TCL_ERROR) - $1 = 0; - else - $1 = 1; + //check the first value to see if it is of correct type + else if (CONVERT_FROM(interp, listobjv[0], &temp) == TCL_ERROR) + $1 = 0; + else + $1 = 1; } } %typecheck(SWIG_TYPECHECK_VECTOR) const vector< T >&, const vector< T >*{ Tcl_Obj **listobjv; - int nitems; + Tcl_Size nitems; T temp; std::vector< T > *v; - if(SWIG_ConvertPtr($input, (void **) &v, \ + if(SWIG_ConvertPtr($input, (void **) &v, $1_descriptor, 0) == 0){ /* wrapped vector */ $1 = 1; @@ -358,11 +359,11 @@ namespace std { else if (nitems == 0) $1 = 1; - //check the first value to see if it is of correct type - if (CONVERT_FROM(interp, listobjv[0], &temp) == TCL_ERROR) - $1 = 0; - else - $1 = 1; + //check the first value to see if it is of correct type + else if (CONVERT_FROM(interp, listobjv[0], &temp) == TCL_ERROR) + $1 = 0; + else + $1 = 1; } } @@ -412,7 +413,7 @@ namespace std { }; %enddef - specialize_std_vector(bool, Tcl_GetBoolFromObj, Tcl_NewBooleanObj); + specialize_std_vector(bool, SWIG_Tcl_GetBoolFromObj, Tcl_NewBooleanObj); specialize_std_vector(char, SwigInt_As<char>,Tcl_NewIntObj); specialize_std_vector(int, Tcl_GetIntFromObj,Tcl_NewIntObj); specialize_std_vector(short, SwigInt_As<short>, Tcl_NewIntObj); diff --git a/Lib/tcl/swigmove.i b/Lib/tcl/swigmove.i new file mode 100644 index 000000000..62ecca768 --- /dev/null +++ b/Lib/tcl/swigmove.i @@ -0,0 +1 @@ +%include <typemaps/swigmove.swg> diff --git a/Lib/tcl/tclapi.swg b/Lib/tcl/tclapi.swg index 2187de52e..03c3967ad 100644 --- a/Lib/tcl/tclapi.swg +++ b/Lib/tcl/tclapi.swg @@ -23,8 +23,8 @@ typedef struct swig_const_info { swig_type_info **ptype; } swig_const_info; -typedef int (*swig_wrapper)(ClientData, Tcl_Interp *, int, Tcl_Obj *CONST []); -typedef int (*swig_wrapper_func)(ClientData, Tcl_Interp *, int, Tcl_Obj *CONST []); +typedef int (*swig_wrapper)(ClientData, Tcl_Interp *, int, Tcl_Obj *const []); +typedef int (*swig_wrapper_func)(ClientData, Tcl_Interp *, int, Tcl_Obj *const []); typedef char *(*swig_variable_func)(ClientData, Tcl_Interp *, char *, char *, int); typedef void (*swig_delete_func)(ClientData); @@ -63,7 +63,7 @@ typedef struct swig_instance { /* Structure for command table */ typedef struct { const char *name; - int (*wrapper)(ClientData, Tcl_Interp *, int, Tcl_Obj *CONST []); + int (*wrapper)(ClientData, Tcl_Interp *, int, Tcl_Obj *const []); ClientData clientdata; } swig_command_info; diff --git a/Lib/tcl/tclerrors.swg b/Lib/tcl/tclerrors.swg index 889d3ad50..73d73f8cf 100644 --- a/Lib/tcl/tclerrors.swg +++ b/Lib/tcl/tclerrors.swg @@ -51,15 +51,15 @@ SWIG_Tcl_SetErrorObj(Tcl_Interp *interp, const char *ctype, Tcl_Obj *obj) { Tcl_ResetResult(interp); Tcl_SetObjResult(interp, obj); - Tcl_SetErrorCode(interp, "SWIG", ctype, NULL); + Tcl_SetErrorCode(interp, "SWIG", ctype, (char *)NULL); } SWIGINTERN void SWIG_Tcl_SetErrorMsg(Tcl_Interp *interp, const char *ctype, const char *mesg) { Tcl_ResetResult(interp); - Tcl_SetErrorCode(interp, "SWIG", ctype, NULL); - Tcl_AppendResult(interp, ctype, " ", mesg, NULL); + Tcl_SetErrorCode(interp, "SWIG", ctype, (char *)NULL); + Tcl_AppendResult(interp, ctype, " ", mesg, (char *)NULL); /* Tcl_AddErrorInfo(interp, ctype); Tcl_AddErrorInfo(interp, " "); diff --git a/Lib/tcl/tclinit.swg b/Lib/tcl/tclinit.swg index 3140bdcdb..eb9e3ecaa 100644 --- a/Lib/tcl/tclinit.swg +++ b/Lib/tcl/tclinit.swg @@ -24,7 +24,7 @@ SWIGEXPORT int SWIG_init(Tcl_Interp *); /* Compatibility version for TCL stubs */ #ifndef SWIG_TCL_STUBS_VERSION -#define SWIG_TCL_STUBS_VERSION "8.1" +#define SWIG_TCL_STUBS_VERSION "8.4-" #endif %} @@ -100,8 +100,7 @@ SWIGEXPORT int SWIG_init(Tcl_Interp *interp) { size_t i; if (interp == 0) return TCL_ERROR; #ifdef USE_TCL_STUBS - /* (char*) cast is required to avoid compiler warning/error for Tcl < 8.4. */ - if (Tcl_InitStubs(interp, (char*)SWIG_TCL_STUBS_VERSION, 0) == NULL) { + if (Tcl_InitStubs(interp, SWIG_TCL_STUBS_VERSION, 0) == NULL) { return TCL_ERROR; } #endif diff --git a/Lib/tcl/tclprimtypes.swg b/Lib/tcl/tclprimtypes.swg index 3b6d04f59..ddefa7db5 100644 --- a/Lib/tcl/tclprimtypes.swg +++ b/Lib/tcl/tclprimtypes.swg @@ -61,7 +61,7 @@ SWIG_From_dec(unsigned long)(unsigned long value) return SWIG_From(long)(%numeric_cast(value, long)); } else { char temp[256]; - sprintf(temp, "%lu", value); + SWIG_snprintf(temp, sizeof(temp), "%lu", value); return Tcl_NewStringObj(temp,-1); } } @@ -82,7 +82,7 @@ SWIG_AsVal_dec(unsigned long)(Tcl_Obj *obj, unsigned long *val) { get it as a string so we can distinguish these cases. */ } { - int len = 0; + Tcl_Size len = 0; const char *nptr = Tcl_GetStringFromObj(obj, &len); if (nptr && len > 0) { char *endptr; @@ -122,7 +122,7 @@ SWIG_From_dec(long long)(long long value) return SWIG_From(long)(%numeric_cast(value,long)); } else { char temp[256]; - sprintf(temp, "%lld", value); + SWIG_snprintf(temp, sizeof(temp), "%lld", value); return Tcl_NewStringObj(temp,-1); } } @@ -136,30 +136,13 @@ SWIG_From_dec(long long)(long long value) SWIGINTERN int SWIG_AsVal_dec(long long)(Tcl_Obj *obj, long long *val) { - long v; - if (Tcl_GetLongFromObj(0,obj, &v) == TCL_OK) { + Tcl_WideInt v; + if (Tcl_GetWideIntFromObj(0, obj, &v) == TCL_OK) { + if (sizeof(v) > sizeof(*val) && (v < LLONG_MIN || v > LLONG_MAX)) { + return SWIG_OverflowError; + } if (val) *val = v; return SWIG_OK; - } else { - int len = 0; - const char *nptr = Tcl_GetStringFromObj(obj, &len); - if (nptr && len > 0) { - char *endptr; - long long v; - errno = 0; - v = strtoll(nptr, &endptr,0); - if (nptr[0] == '\0' || *endptr != '\0') - return SWIG_TypeError; - if ((v == LLONG_MAX || v == LLONG_MIN) && errno == ERANGE) { - errno = 0; - return SWIG_OverflowError; - } else { - if (*endptr == '\0') { - if (val) *val = v; - return SWIG_OK; - } - } - } } return SWIG_TypeError; } @@ -180,7 +163,7 @@ SWIG_From_dec(unsigned long long)(unsigned long long value) return SWIG_From(long long)(%numeric_cast(value, long long)); } else { char temp[256]; - sprintf(temp, "%llu", value); + SWIG_snprintf(temp, sizeof(temp), "%llu", value); return Tcl_NewStringObj(temp,-1); } } @@ -200,7 +183,7 @@ SWIG_AsVal_dec(unsigned long long)(Tcl_Obj *obj, unsigned long long *val) if (val) *val = (unsigned long) v; return SWIG_OK; } else { - int len = 0; + Tcl_Size len = 0; const char *nptr = Tcl_GetStringFromObj(obj, &len); if (nptr && len > 0) { char *endptr; diff --git a/Lib/tcl/tclrun.swg b/Lib/tcl/tclrun.swg index 9010b9c87..debbd091e 100644 --- a/Lib/tcl/tclrun.swg +++ b/Lib/tcl/tclrun.swg @@ -67,8 +67,8 @@ #define SWIG_GetConstant SWIG_GetConstantObj #define SWIG_Tcl_GetConstant SWIG_Tcl_GetConstantObj -#if TCL_MAJOR_VERSION >= 8 && TCL_MINOR_VERSION >= 5 -#define SWIG_TCL_HASHTABLE_INIT {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 5) +#define SWIG_TCL_HASHTABLE_INIT {0, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0} #else #define SWIG_TCL_HASHTABLE_INIT {0} #endif @@ -118,10 +118,13 @@ SWIG_Tcl_Disown(void *ptr) { return 0; } +SWIGRUNTIME void SWIG_Tcl_ObjectDelete(ClientData clientData); + /* Convert a pointer value */ SWIGRUNTIME int SWIG_Tcl_ConvertPtrFromString(Tcl_Interp *interp, const char *c, void **ptr, swig_type_info *ty, int flags) { swig_cast_info *tc; + const char *cmd_name; /* Pointer values must start with leading underscore */ while (*c != '_') { *ptr = (void *) 0; @@ -137,7 +140,7 @@ SWIG_Tcl_ConvertPtrFromString(Tcl_Interp *interp, const char *c, void **ptr, swi /* from being called when c is not a command, firing the unknown proc */ if (Tcl_VarEval(interp,"info commands ", c, (char *) NULL) == TCL_OK) { Tcl_Obj *result = Tcl_GetObjResult(interp); - if (*(Tcl_GetStringFromObj(result, NULL)) == 0) { + if (*(Tcl_GetString(result)) == 0) { /* It's not a command, so it can't be a pointer */ Tcl_ResetResult(interp); return SWIG_ERROR; @@ -155,32 +158,55 @@ SWIG_Tcl_ConvertPtrFromString(Tcl_Interp *interp, const char *c, void **ptr, swi return SWIG_ERROR; } - c = Tcl_GetStringFromObj(Tcl_GetObjResult(interp), NULL); + c = Tcl_GetString(Tcl_GetObjResult(interp)); } + cmd_name = c; c++; c = SWIG_UnpackData(c,ptr,sizeof(void *)); + if (ty) { + Tcl_CmdInfo info; tc = c ? SWIG_TypeCheck(c,ty) : 0; if (!tc) { return SWIG_ERROR; } - if (flags & SWIG_POINTER_DISOWN) { - SWIG_Disown((void *) *ptr); - } - { - int newmemory = 0; - *ptr = SWIG_TypeCast(tc,(void *) *ptr,&newmemory); - assert(!newmemory); /* newmemory handling not yet implemented */ + if (Tcl_GetCommandInfo(interp, cmd_name, &info)) { + /* When creating a pointer string, SWIG_Tcl_NewInstanceObj calls Tcl_CreateObjCommand and sets + * info.objClientData to an instance of swig_instance. Detecting when we can cast any info.objClientData + * to swig_instance is not simple as it may be an unrelated command; we use deleteProc to determine this. */ + if (info.deleteProc == SWIG_Tcl_ObjectDelete) { + swig_instance *inst = (swig_instance *)info.objClientData; + if (!inst->thisvalue) { + *ptr = 0; + } + assert(inst->thisvalue == *ptr); + if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) && !SWIG_Thisown(inst->thisvalue)) { + return SWIG_ERROR_RELEASE_NOT_OWNED; + } else { + if (flags & SWIG_POINTER_DISOWN) { + SWIG_Disown((void *) *ptr); + } + if (flags & SWIG_POINTER_CLEAR) { + inst->thisvalue = 0; + } + { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,(void *) *ptr, &newmemory); + assert(!newmemory); /* newmemory handling not yet implemented */ + } + } + } } } + return SWIG_OK; } /* Convert a pointer value */ SWIGRUNTIMEINLINE int SWIG_Tcl_ConvertPtr(Tcl_Interp *interp, Tcl_Obj *oc, void **ptr, swig_type_info *ty, int flags) { - return SWIG_Tcl_ConvertPtrFromString(interp, Tcl_GetStringFromObj(oc,NULL), ptr, ty, flags); + return SWIG_Tcl_ConvertPtrFromString(interp, Tcl_GetString(oc), ptr, ty, flags); } /* Convert a pointer value */ @@ -207,7 +233,7 @@ SWIG_Tcl_ConvertPacked(Tcl_Interp *SWIGUNUSEDPARM(interp) , Tcl_Obj *obj, void * const char *c; if (!obj) goto type_error; - c = Tcl_GetStringFromObj(obj,NULL); + c = Tcl_GetString(obj); /* Pointer values must start with leading underscore */ if (*c != '_') goto type_error; c++; @@ -306,7 +332,7 @@ SWIG_Tcl_ObjectDelete(ClientData clientData) { /* Function to invoke object methods given an instance */ SWIGRUNTIME int -SWIG_Tcl_MethodCommand(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST _objv[]) { +SWIG_Tcl_MethodCommand(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const _objv[]) { char *method, *attrname; swig_instance *inst = (swig_instance *) clientData; swig_method *meth; @@ -326,7 +352,7 @@ SWIG_Tcl_MethodCommand(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_ Tcl_SetResult(interp, (char *) "wrong # args.", TCL_STATIC); return TCL_ERROR; } - method = Tcl_GetStringFromObj(objv[1],NULL); + method = Tcl_GetString(objv[1]); if (strcmp(method,"-acquire") == 0) { inst->destroy = 1; SWIG_Acquire(inst->thisvalue); @@ -389,7 +415,7 @@ SWIG_Tcl_MethodCommand(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_ Tcl_SetResult(interp, (char *) "wrong # args.", TCL_STATIC); return TCL_ERROR; } - attrname = Tcl_GetStringFromObj(objv[2],NULL); + attrname = Tcl_GetString(objv[2]); attr = cls->attributes; while (attr && attr->name) { if ((strcmp(attr->name, attrname) == 0) && (attr->getmethod)) { @@ -423,7 +449,7 @@ SWIG_Tcl_MethodCommand(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_ } i = 2; while (i < objc) { - attrname = Tcl_GetStringFromObj(objv[i],NULL); + attrname = Tcl_GetString(objv[i]); attr = cls->attributes; while (attr && attr->name) { if ((strcmp(attr->name, attrname) == 0) && (attr->setmethod)) { @@ -490,19 +516,30 @@ SWIG_Tcl_NewInstanceObj(Tcl_Interp *interp, void *thisvalue, swig_type_info *typ /* Check to see if this pointer belongs to a class or not */ if (thisvalue && (type->clientdata) && (interp)) { Tcl_CmdInfo ci; + int has_command; char *name; - name = Tcl_GetStringFromObj(robj,NULL); - if (!Tcl_GetCommandInfo(interp,name, &ci) || (flags)) { + name = Tcl_GetString(robj); + has_command = Tcl_GetCommandInfo(interp, name, &ci); + if (!has_command || flags) { swig_instance *newinst = (swig_instance *) malloc(sizeof(swig_instance)); newinst->thisptr = Tcl_DuplicateObj(robj); Tcl_IncrRefCount(newinst->thisptr); newinst->thisvalue = thisvalue; newinst->classptr = (swig_class *) type->clientdata; newinst->destroy = flags; - newinst->cmdtok = Tcl_CreateObjCommand(interp, Tcl_GetStringFromObj(robj,NULL), (swig_wrapper_func) SWIG_MethodCommand, (ClientData) newinst, (swig_delete_func) SWIG_ObjectDelete); + newinst->cmdtok = Tcl_CreateObjCommand(interp, Tcl_GetString(robj), (swig_wrapper_func) SWIG_Tcl_MethodCommand, (ClientData) newinst, (swig_delete_func) SWIG_Tcl_ObjectDelete); if (flags) { SWIG_Acquire(thisvalue); } + } else { + swig_instance *inst = (swig_instance *)ci.objClientData; + /* Restore thisvalue as SWIG_POINTER_CLEAR may have been used to set it to zero. + Occurs when the C pointer is re-used by the memory allocator and the command has + been created and not destroyed - bug?? - see cpp11_std_unique_ptr_runme.tcl test. */ + if (inst->thisvalue != thisvalue) { + assert(inst->thisvalue == 0); + inst->thisvalue = thisvalue; + } } } return robj; @@ -510,7 +547,7 @@ SWIG_Tcl_NewInstanceObj(Tcl_Interp *interp, void *thisvalue, swig_type_info *typ /* Function to create objects */ SWIGRUNTIME int -SWIG_Tcl_ObjectConstructor(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { +SWIG_Tcl_ObjectConstructor(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { Tcl_Obj *newObj = 0; void *thisvalue = 0; swig_instance *newinst = 0; @@ -527,7 +564,7 @@ SWIG_Tcl_ObjectConstructor(ClientData clientData, Tcl_Interp *interp, int objc, } cons = classptr->constructor; if (objc > 1) { - char *s = Tcl_GetStringFromObj(objv[1],NULL); + char *s = Tcl_GetString(objv[1]); if (strcmp(s,"-this") == 0) { thisarg = 2; cons = 0; @@ -539,7 +576,7 @@ SWIG_Tcl_ObjectConstructor(ClientData clientData, Tcl_Interp *interp, int objc, } else if (objc >= 3) { char *s1; name = s; - s1 = Tcl_GetStringFromObj(objv[2],NULL); + s1 = Tcl_GetString(objv[2]); if (strcmp(s1,"-this") == 0) { thisarg = 3; cons = 0; @@ -555,12 +592,12 @@ SWIG_Tcl_ObjectConstructor(ClientData clientData, Tcl_Interp *interp, int objc, return result; } newObj = Tcl_DuplicateObj(Tcl_GetObjResult(interp)); - if (!name) name = Tcl_GetStringFromObj(newObj,NULL); + if (!name) name = Tcl_GetString(newObj); } else if (thisarg > 0) { if (thisarg < objc) { destroy = 0; newObj = Tcl_DuplicateObj(objv[thisarg]); - if (!name) name = Tcl_GetStringFromObj(newObj,NULL); + if (!name) name = Tcl_GetString(newObj); } else { Tcl_SetResult(interp, (char *) "wrong # args.", TCL_STATIC); return TCL_ERROR; @@ -582,7 +619,7 @@ SWIG_Tcl_ObjectConstructor(ClientData clientData, Tcl_Interp *interp, int objc, if (destroy) { SWIG_Acquire(thisvalue); } - newinst->cmdtok = Tcl_CreateObjCommand(interp,name, (swig_wrapper) SWIG_MethodCommand, (ClientData) newinst, (swig_delete_func) SWIG_ObjectDelete); + newinst->cmdtok = Tcl_CreateObjCommand(interp,name, (swig_wrapper) SWIG_Tcl_MethodCommand, (ClientData) newinst, (swig_delete_func) SWIG_Tcl_ObjectDelete); return TCL_OK; } @@ -590,7 +627,7 @@ SWIG_Tcl_ObjectConstructor(ClientData clientData, Tcl_Interp *interp, int objc, * Get arguments * -----------------------------------------------------------------------------*/ SWIGRUNTIME int -SWIG_Tcl_GetArgs(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], const char *fmt, ...) { +SWIG_Tcl_GetArgs(Tcl_Interp *interp, int objc, Tcl_Obj *const objv[], const char *fmt, ...) { int argno = 0, opt = 0; long tempi; double tempd; @@ -619,7 +656,7 @@ SWIG_Tcl_GetArgs(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], const char vptr = va_arg(ap,void *); if (vptr) { if (isupper(*c)) { - obj = SWIG_Tcl_GetConstantObj(Tcl_GetStringFromObj(objv[argno+1],0)); + obj = SWIG_Tcl_GetConstantObj(Tcl_GetString(objv[argno+1])); if (!obj) obj = objv[argno+1]; } else { obj = objv[argno+1]; @@ -643,15 +680,15 @@ SWIG_Tcl_GetArgs(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], const char break; case 's': case 'S': if (*(c+1) == '#') { - int *vlptr = (int *) va_arg(ap, void *); + Tcl_Size *vlptr = (Tcl_Size *) va_arg(ap, void *); *((char **) vptr) = Tcl_GetStringFromObj(obj, vlptr); c++; } else { - *((char **)vptr) = Tcl_GetStringFromObj(obj,NULL); + *((char **)vptr) = Tcl_GetString(obj); } break; case 'c': case 'C': - *((char *)vptr) = *(Tcl_GetStringFromObj(obj,NULL)); + *((char *)vptr) = *(Tcl_GetString(obj)); break; case 'p': case 'P': ty = (swig_type_info *) va_arg(ap, void *); @@ -676,11 +713,11 @@ SWIG_Tcl_GetArgs(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], const char argerror: { char temp[32]; - sprintf(temp,"%d", argno+1); + SWIG_snprintf(temp, sizeof(temp), "%d", argno+1); c = strchr(fmt,':'); if (!c) c = strchr(fmt,';'); if (!c) c = (char *)""; - Tcl_AppendResult(interp,c," argument ", temp, NULL); + Tcl_AppendResult(interp,c," argument ", temp, (char *)NULL); va_end(ap); return TCL_ERROR; } diff --git a/Lib/tcl/tclruntime.swg b/Lib/tcl/tclruntime.swg index bb4edd745..3b34a76c0 100644 --- a/Lib/tcl/tclruntime.swg +++ b/Lib/tcl/tclruntime.swg @@ -6,6 +6,22 @@ #include <stdlib.h> #include <stdarg.h> #include <ctype.h> + +/* Check, if Tcl version supports Tcl_Size, + which was introduced in Tcl 8.7 and 9. +*/ +#ifndef TCL_SIZE_MAX + #include <limits.h> + #define TCL_SIZE_MAX INT_MAX + + #ifndef Tcl_Size + typedef int Tcl_Size; + #endif + + #define TCL_SIZE_MODIFIER "" + #define Tcl_GetSizeIntFromObj Tcl_GetIntFromObj + #define Tcl_NewSizeIntObj Tcl_NewIntObj +#endif %} %insert(runtime) "swigrun.swg"; /* Common C API type-checking code */ diff --git a/Lib/tcl/tclsh.i b/Lib/tcl/tclsh.i index 160ba8d8f..e908756c1 100644 --- a/Lib/tcl/tclsh.i +++ b/Lib/tcl/tclsh.i @@ -4,20 +4,15 @@ * SWIG File for building new tclsh program * ----------------------------------------------------------------------------- */ -#ifdef AUTODOC -%subsection "tclsh.i" -%text %{ -This module provides the Tcl_AppInit() function needed to build a -new version of the tclsh executable. This file should not be used -when using dynamic loading. To make an interface file work with -both static and dynamic loading, put something like this in your -interface file : - - #ifdef STATIC - %include <tclsh.i> - #endif -%} -#endif +// This module provides the Tcl_AppInit() function needed to build a +// new version of the tclsh executable. This file should not be used +// when using dynamic loading. To make an interface file work with +// both static and dynamic loading, put something like this in your +// interface file : +// +// #ifdef STATIC +// %include <tclsh.i> +// #endif %{ @@ -33,10 +28,6 @@ char *SWIG_RcFileName = "~/.myapprc"; #endif -#ifdef MAC_TCL -extern int MacintoshInit _ANSI_ARGS_((void)); -#endif - int Tcl_AppInit(Tcl_Interp *interp){ if (Tcl_Init(interp) == TCL_ERROR) @@ -46,40 +37,16 @@ int Tcl_AppInit(Tcl_Interp *interp){ if (SWIG_init(interp) == TCL_ERROR) return TCL_ERROR; -#if TCL_MAJOR_VERSION > 7 || TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION >= 5 - Tcl_SetVar(interp, (char *) "tcl_rcFileName",SWIG_RcFileName,TCL_GLOBAL_ONLY); -#else - tcl_RcFileName = SWIG_RcFileName; -#endif -#ifdef SWIG_RcRsrcName - Tcl_SetVar(interp, (char *) "tcl_rcRsrcName",SWIG_RcRsrcName,TCL_GLOBAL); -#endif - + Tcl_SetVar(interp, (char *) "tcl_rcFileName",SWIG_RcFileName,TCL_GLOBAL_ONLY); + return TCL_OK; } -#if TCL_MAJOR_VERSION > 7 || TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION >= 4 int main(int argc, char **argv) { -#ifdef MAC_TCL - char *newArgv[2]; - - if (MacintoshInit() != TCL_OK) { - Tcl_Exit(1); - } - - argc = 1; - newArgv[0] = "tclsh"; - newArgv[1] = NULL; - argv = newArgv; -#endif - Tcl_Main(argc, argv, Tcl_AppInit); return(0); } -#else -extern int main(); -#endif %} diff --git a/Lib/tcl/tclstrings.swg b/Lib/tcl/tclstrings.swg index 540d6270e..738c81362 100644 --- a/Lib/tcl/tclstrings.swg +++ b/Lib/tcl/tclstrings.swg @@ -6,7 +6,7 @@ SWIGINTERN int SWIG_AsCharPtrAndSize(Tcl_Obj *obj, char** cptr, size_t* psize, int *alloc) { - int len = 0; + Tcl_Size len = 0; char *cstr = Tcl_GetStringFromObj(obj, &len); if (cstr) { if (cptr) *cptr = cstr; @@ -24,7 +24,7 @@ SWIG_AsCharPtrAndSize(Tcl_Obj *obj, char** cptr, size_t* psize, int *alloc) SWIGINTERNINLINE Tcl_Obj * SWIG_FromCharPtrAndSize(const char* carray, size_t size) { - return (size < INT_MAX) ? Tcl_NewStringObj(carray, %numeric_cast(size,int)) : NULL; + return (size < TCL_SIZE_MAX) ? Tcl_NewStringObj(carray, %numeric_cast(size,Tcl_Size)) : NULL; } } diff --git a/Lib/tcl/tcltypemaps.swg b/Lib/tcl/tcltypemaps.swg index ad31bcfc9..66cce47ec 100644 --- a/Lib/tcl/tcltypemaps.swg +++ b/Lib/tcl/tcltypemaps.swg @@ -77,11 +77,6 @@ #endif -%typemap(throws,noblock=1) SWIGTYPE CLASS { - SWIG_set_result(SWIG_NewInstanceObj(%as_voidptr(SWIG_new_copy($1, $1_ltype)), $&1_descriptor, 1)); - SWIG_fail; -} - %typemap(out) SWIGTYPE = SWIGTYPE INSTANCE; %typemap(out) SWIGTYPE * = SWIGTYPE *INSTANCE; %typemap(out) SWIGTYPE *const = SWIGTYPE *; diff --git a/Lib/tcl/tclwstrings.swg b/Lib/tcl/tclwstrings.swg index b3b682e30..76da2ab08 100644 --- a/Lib/tcl/tclwstrings.swg +++ b/Lib/tcl/tclwstrings.swg @@ -12,14 +12,14 @@ SWIGINTERN int SWIG_AsWCharPtrAndSize(Tcl_Obj *obj, wchar_t** cptr, size_t* psize, int *alloc) { - int len = 0; + Tcl_Size len = 0; Tcl_UniChar *ustr = Tcl_GetUnicodeFromObj(obj, &len); if (ustr) { if (cptr) { Tcl_Encoding encoding = NULL; char *src = (char *) ustr; - int srcLen = (len)*sizeof(Tcl_UniChar); - int dstLen = sizeof(wchar_t)*(len + 1); + Tcl_Size srcLen = (len)*sizeof(Tcl_UniChar); + Tcl_Size dstLen = sizeof(wchar_t)*(len + 1); char *dst = %new_array(dstLen, char); int flags = 0; Tcl_EncodingState *statePtr = 0; @@ -29,6 +29,7 @@ SWIG_AsWCharPtrAndSize(Tcl_Obj *obj, wchar_t** cptr, size_t* psize, int *alloc) Tcl_UtfToExternal(0, encoding, src, srcLen, flags, statePtr, dst, dstLen, &srcRead, &dstWrote, &dstChars); + *cptr = (wchar_t*)dst; if (alloc) *alloc = SWIG_NEWOBJ; } if (psize) *psize = len + 1; @@ -43,11 +44,11 @@ SWIGINTERNINLINE Tcl_Obj * SWIG_FromWCharPtrAndSize(const wchar_t* carray, size_t size) { Tcl_Obj *res = NULL; - if (size < INT_MAX) { + if (size < TCL_SIZE_MAX) { Tcl_Encoding encoding = NULL; char *src = (char *) carray; - int srcLen = (int)(size*sizeof(wchar_t)); - int dstLen = (int)(size*sizeof(Tcl_UniChar)); + Tcl_Size srcLen = (Tcl_Size)(size*sizeof(wchar_t)); + Tcl_Size dstLen = (Tcl_Size)(size*sizeof(Tcl_UniChar)); char *dst = %new_array(dstLen, char); int flags = 0; Tcl_EncodingState *statePtr = 0; @@ -58,7 +59,7 @@ SWIG_FromWCharPtrAndSize(const wchar_t* carray, size_t size) Tcl_ExternalToUtf(0, encoding, src, srcLen, flags, statePtr, dst, dstLen, &srcRead, &dstWrote, &dstChars); - res = Tcl_NewUnicodeObj((Tcl_UniChar*)dst, (int)size); + res = Tcl_NewUnicodeObj((Tcl_UniChar*)dst, (Tcl_Size)size); %delete_array(dst); } return res; diff --git a/Lib/tcl/typemaps.i b/Lib/tcl/typemaps.i index 04a5c78f3..4f42cfc2a 100644 --- a/Lib/tcl/typemaps.i +++ b/Lib/tcl/typemaps.i @@ -164,14 +164,14 @@ or you can use the %apply directive : %typemap(in) long long *INPUT($*1_ltype temp), long long &INPUT($*1_ltype temp) { - temp = ($*1_ltype) strtoll(Tcl_GetStringFromObj($input,NULL),0,0); + temp = ($*1_ltype) strtoll(Tcl_GetString($input),0,0); $1 = &temp; } %typemap(in) unsigned long long *INPUT($*1_ltype temp), unsigned long long &INPUT($*1_ltype temp) { - temp = ($*1_ltype) strtoull(Tcl_GetStringFromObj($input,NULL),0,0); + temp = ($*1_ltype) strtoull(Tcl_GetString($input),0,0); $1 = &temp; } @@ -275,7 +275,7 @@ output values. { char temp[256]; Tcl_Obj *o; - sprintf(temp,"%lld",(long long)*($1)); + SWIG_snprintf(temp,sizeof(temp),"%lld",(long long)*($1)); o = Tcl_NewStringObj(temp,-1); Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o); } @@ -284,7 +284,7 @@ output values. { char temp[256]; Tcl_Obj *o; - sprintf(temp,"%llu",(unsigned long long)*($1)); + SWIG_snprintf(temp,sizeof(temp),"%llu",(unsigned long long)*($1)); o = Tcl_NewStringObj(temp,-1); Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o); } diff --git a/Lib/tcl/wish.i b/Lib/tcl/wish.i index 260032a81..6969b2ac5 100644 --- a/Lib/tcl/wish.i +++ b/Lib/tcl/wish.i @@ -4,25 +4,20 @@ * SWIG File for making wish * ----------------------------------------------------------------------------- */ -#ifdef AUTODOC -%subsection "wish.i" -%text %{ -This module provides the Tk_AppInit() function needed to build a -new version of the wish executable. Like tclsh.i, this file should -not be used with dynamic loading. To make an interface file work with -both static and dynamic loading, put something like this in your -interface file : - - #ifdef STATIC - %include <wish.i> - #endif - -A startup file may be specified by defining the symbol SWIG_RcFileName -as follows (this should be included in a code-block) : - - #define SWIG_RcFileName "~/.mywishrc" -%} -#endif +// This module provides the Tk_AppInit() function needed to build a +// new version of the wish executable. Like tclsh.i, this file should +// not be used with dynamic loading. To make an interface file work with +// both static and dynamic loading, put something like this in your +// interface file : +// +// #ifdef STATIC +// %include <wish.i> +// #endif +// +// A startup file may be specified by defining the symbol SWIG_RcFileName +// as follows (this should be included in a code-block) : +// +// #define SWIG_RcFileName "~/.mywishrc" %{ @@ -35,11 +30,6 @@ as follows (this should be included in a code-block) : char *SWIG_RcFileName = "~/.wishrc"; #endif -#ifdef MAC_TCL -extern int MacintoshInit _ANSI_ARGS_((void)); -extern int SetupMainInterp _ANSI_ARGS_((Tcl_Interp *interp)); -#endif - /* *---------------------------------------------------------------------- * @@ -61,10 +51,9 @@ extern int SetupMainInterp _ANSI_ARGS_((Tcl_Interp *interp)); int Tcl_AppInit(Tcl_Interp *interp) { -#ifndef MAC_TCL Tk_Window main; main = Tk_MainWindow(interp); -#endif + /* * Call the init procedures for included packages. Each call should * look like this: @@ -93,10 +82,6 @@ int Tcl_AppInit(Tcl_Interp *interp) return TCL_ERROR; } -#ifdef MAC_TCL - SetupMainInterp(interp); -#endif - /* * Specify a user-specific startup file to invoke if the application * is run interactively. Typically the startup file is "~/.apprc" @@ -104,35 +89,12 @@ int Tcl_AppInit(Tcl_Interp *interp) * then no user-specific startup file will be run under any conditions. */ -#if TCL_MAJOR_VERSION >= 8 || TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION >= 5 - Tcl_SetVar(interp, (char *) "tcl_rcFileName",SWIG_RcFileName,TCL_GLOBAL_ONLY); -#else - tcl_RcFileName = SWIG_RcFileName; -#endif - -/* For Macintosh might also want this */ - -#ifdef MAC_TCL -#ifdef SWIG_RcRsrcName - Tcl_SetVar(interp, (char *) "tcl_rcRsrcName",SWIG_RcRsrcName,TCL_GLOBAL_ONLY); -#endif -#endif + Tcl_SetVar(interp, (char *) "tcl_rcFileName",SWIG_RcFileName,TCL_GLOBAL_ONLY); return TCL_OK; } #if TK_MAJOR_VERSION >= 4 int main(int argc, char **argv) { - -#ifdef MAC_TCL - char *newArgv[2]; - if (MacintoshInit() != TCL_OK) { - Tcl_Exit(1); - } - argc = 1; - newArgv[0] = "Wish"; - newArgv[1] = NULL; - argv = newArgv; -#endif Tk_Main(argc, argv, Tcl_AppInit); return(0); } |