Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions cpptcl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ template <> long object::get<long>(interpreter &i) const {
template <> char const *object::get<char const *>(interpreter &) const { return get(); }

template <> string object::get<string>(interpreter &) const {
int len;
Tcl_Size len;
char const *buf = Tcl_GetStringFromObj(obj_, &len);
return string(buf, buf + len);
}
Expand All @@ -562,14 +562,14 @@ double object::asDouble() const { return get<double>(); }
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<char const *>(reinterpret_cast<char *>(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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
19 changes: 19 additions & 0 deletions cpptcl/cpptcl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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
#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);
Expand Down Expand Up @@ -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_; }

Expand Down
Loading