diff --git a/cpptcl.cc b/cpptcl.cc index 9cef8ab..e7a7aeb 100644 --- a/cpptcl.cc +++ b/cpptcl.cc @@ -548,7 +548,7 @@ template <> long object::get(interpreter &i) const { template <> char const *object::get(interpreter &) const { return get(); } template <> string object::get(interpreter &) const { - int len; + Tcl_Size len; char const *buf = Tcl_GetStringFromObj(obj_, &len); return string(buf, buf + len); } @@ -562,14 +562,14 @@ double object::asDouble() const { return get(); } char const *object::get() const { return Tcl_GetString(obj_); } char const *object::get(size_t &size) const { - int len; + Tcl_Size len; unsigned char *buf = Tcl_GetByteArrayFromObj(obj_, &len); size = len; return const_cast(reinterpret_cast(buf)); } size_t object::size(interpreter &i) const { - int len; + Tcl_Size len; int res = Tcl_ListObjLength(i.get(), obj_, &len); if (res != TCL_OK) { @@ -620,7 +620,7 @@ object &object::replace(size_t index, size_t count, object const &o, interpreter } object &object::replace_list(size_t index, size_t count, object const &o, interpreter &i) { - int objc; + Tcl_Size objc; Tcl_Obj **objv; int res = Tcl_ListObjGetElements(i.get(), o.obj_, &objc, &objv); @@ -673,12 +673,14 @@ interpreter::~interpreter() { } } +#if TCL_MAJOR_VERSION < 9 void interpreter::make_safe() { int cc = Tcl_MakeSafe(interp_); if (cc != TCL_OK) { throw tcl_error(interp_); } } +#endif result interpreter::eval(string const &script) { int cc = Tcl_Eval(interp_, script.c_str()); diff --git a/cpptcl/cpptcl.h b/cpptcl/cpptcl.h index 1852a6c..40318dd 100644 --- a/cpptcl/cpptcl.h +++ b/cpptcl/cpptcl.h @@ -38,6 +38,23 @@ #include "tcl.h" +/* 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 + // This function is not part of TCL, but is a useful helper. extern "C" { Tcl_Interp * Tcl_CreateInterpWithStubs(const char *version, int exact); @@ -360,7 +377,9 @@ class interpreter { interpreter(Tcl_Interp *, bool owner = false); ~interpreter(); +#if TCL_MAJOR_VERSION < 9 void make_safe(); +#endif Tcl_Interp *get() const { return interp_; }