Skip to content

Commit bc76451

Browse files
authored
Merge pull request #28 from stefanoweidmann/tcl9
Make compilable with Tcl 9.0.0
2 parents d7ed494 + 4c9836c commit bc76451

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

cpptcl.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ template <> long object::get<long>(interpreter &i) const {
548548
template <> char const *object::get<char const *>(interpreter &) const { return get(); }
549549

550550
template <> string object::get<string>(interpreter &) const {
551-
int len;
551+
Tcl_Size len;
552552
char const *buf = Tcl_GetStringFromObj(obj_, &len);
553553
return string(buf, buf + len);
554554
}
@@ -562,14 +562,14 @@ double object::asDouble() const { return get<double>(); }
562562
char const *object::get() const { return Tcl_GetString(obj_); }
563563

564564
char const *object::get(size_t &size) const {
565-
int len;
565+
Tcl_Size len;
566566
unsigned char *buf = Tcl_GetByteArrayFromObj(obj_, &len);
567567
size = len;
568568
return const_cast<char const *>(reinterpret_cast<char *>(buf));
569569
}
570570

571571
size_t object::size(interpreter &i) const {
572-
int len;
572+
Tcl_Size len;
573573
int res = Tcl_ListObjLength(i.get(), obj_, &len);
574574

575575
if (res != TCL_OK) {
@@ -620,7 +620,7 @@ object &object::replace(size_t index, size_t count, object const &o, interpreter
620620
}
621621

622622
object &object::replace_list(size_t index, size_t count, object const &o, interpreter &i) {
623-
int objc;
623+
Tcl_Size objc;
624624
Tcl_Obj **objv;
625625

626626
int res = Tcl_ListObjGetElements(i.get(), o.obj_, &objc, &objv);
@@ -673,12 +673,14 @@ interpreter::~interpreter() {
673673
}
674674
}
675675

676+
#if TCL_MAJOR_VERSION < 9
676677
void interpreter::make_safe() {
677678
int cc = Tcl_MakeSafe(interp_);
678679
if (cc != TCL_OK) {
679680
throw tcl_error(interp_);
680681
}
681682
}
683+
#endif
682684

683685
result interpreter::eval(string const &script) {
684686
int cc = Tcl_Eval(interp_, script.c_str());

cpptcl/cpptcl.h

+19
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@
3838

3939
#include "tcl.h"
4040

41+
/* Check, if Tcl version supports Tcl_Size,
42+
* which was introduced in Tcl 8.7 and 9.
43+
*/
44+
#ifndef TCL_SIZE_MAX
45+
#include <limits.h>
46+
#define TCL_SIZE_MAX INT_MAX
47+
#ifndef Tcl_Size
48+
typedef int Tcl_Size;
49+
#endif
50+
#define TCL_SIZE_MODIFIER ""
51+
#define Tcl_GetSizeIntFromObj Tcl_GetIntFromObj
52+
#endif
53+
/* TCL 9 does not define CONST anymore */
54+
#ifndef CONST
55+
#define CONST const
56+
#endif
57+
4158
// This function is not part of TCL, but is a useful helper.
4259
extern "C" {
4360
Tcl_Interp * Tcl_CreateInterpWithStubs(const char *version, int exact);
@@ -360,7 +377,9 @@ class interpreter {
360377
interpreter(Tcl_Interp *, bool owner = false);
361378
~interpreter();
362379

380+
#if TCL_MAJOR_VERSION < 9
363381
void make_safe();
382+
#endif
364383

365384
Tcl_Interp *get() const { return interp_; }
366385

0 commit comments

Comments
 (0)