Skip to content

Commit a74bfba

Browse files
authored
Explicitly define namespaces in headers instead of relying on include site (#27)
* Explicitly define namespaces in headers instead of relying on include site The old way was supposedly undefined behavior according to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105707 and began causing the build to fail on GCC 12.2. Explicitly declaring the namespaces within the headers themselves fixes the build and doesn't seem like it would have unintended consequences (most of the headers are private and only included once anyway). Also some fixes for the CI which has long languished. EP-209
1 parent 4c1ef5a commit a74bfba

File tree

14 files changed

+79
-8
lines changed

14 files changed

+79
-8
lines changed

.github/workflows/linux-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
build:
1111

12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-20.04
1313

1414
steps:
1515
- uses: actions/checkout@v2

.github/workflows/mac-ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
build:
1111

12-
runs-on: macos-latest
12+
runs-on: macos-11
1313

1414
steps:
1515
- uses: actions/checkout@v2
@@ -18,8 +18,8 @@ jobs:
1818
brew update
1919
brew install tcl-tk || true
2020
sudo mkdir -p /usr/local
21-
sudo ln -sf /usr/local/opt/tcl-tk/include /usr/local/include/tcl8.6
22-
sudo cp /usr/local/opt/tcl-tk/lib/libtcl* /usr/local/lib
21+
sudo ln -sf /usr/local/opt/tcl-tk/include/tcl-tk /usr/local/include/tcl8.6
22+
sudo install /usr/local/opt/tcl-tk/lib/libtcl* /usr/local/lib
2323
sudo ln -sf /usr/local/opt/tcl-tk/bin/tclsh8.6 /usr/local/bin/tclsh
2424
sudo ln -sf /usr/local/opt/tcl-tk/bin/tclsh8.6 /usr/local/bin/tclsh8.6
2525
- name: make

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ project(cpptcl)
55
include(cmake/version.cmake)
66
load_git_properties(cpptcl ${CMAKE_BINARY_DIR}/generated)
77

8-
set(CPPTCL_VERSION 2.2.5)
8+
set(CPPTCL_VERSION 2.2.8)
99

1010
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
1111
message(STATUS "Setting build type to Release as none was specified.")

cpptcl/cpptcl.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,28 @@ void set_result(Tcl_Interp *interp, std::string const &s);
110110
void set_result(Tcl_Interp *interp, void *p);
111111
void set_result(Tcl_Interp *interp, object const &o);
112112

113+
}
114+
115+
}
116+
113117
// helper functor for converting Tcl objects to the given type
114118
#include "cpptcl/details/conversions.h"
115119

116120
// dispatchers able to capture (or ignore) the result
117121
#include "cpptcl/details/dispatchers.h"
118122

123+
namespace Tcl {
124+
125+
namespace details {
126+
119127
// helper for checking for required number of parameters
120128
// (throws tcl_error when not met)
121129
void check_params_no(int objc, int required, const std::string &message);
122130

123131
// helper for gathering optional params in variadic functions
124132
object get_var_params(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], int from, policies const &pol);
125133

126-
// the callback_base is used to store callback handlers in a polynorphic map
134+
// the callback_base is used to store callback handlers in a polymorphic map
127135
class callback_base {
128136
public:
129137
virtual ~callback_base() {}
@@ -190,6 +198,10 @@ template <class C> class class_handler : public class_handler_base {
190198
}
191199
};
192200

201+
}
202+
203+
}
204+
193205
// factory functions for creating class objects
194206
#include "cpptcl/details/constructors.h"
195207

@@ -202,6 +214,10 @@ template <class C> class class_handler : public class_handler_base {
202214
// helper meta function for figuring appropriate constructor callback
203215
#include "cpptcl/details/metahelpers.h"
204216

217+
namespace Tcl {
218+
219+
namespace details {
220+
205221
// this class is used to provide the "def" interface for defining
206222
// class member functions
207223

@@ -444,8 +460,12 @@ class interpreter {
444460
bool owner_;
445461
};
446462

463+
}
464+
447465
#include "cpptcl/cpptcl_object.h"
448466

467+
namespace Tcl {
468+
449469
// the InputIterator should give object& or Tcl_Obj* when dereferenced
450470
template <class InputIterator> details::result interpreter::eval(InputIterator first, InputIterator last) {
451471
std::vector<Tcl_Obj *> v;
@@ -458,18 +478,19 @@ template <class InputIterator> details::result interpreter::eval(InputIterator f
458478
return details::result(interp_);
459479
}
460480

461-
namespace details {
481+
}
462482

463483
// additional callback envelopes for variadic functions
464484
#include "cpptcl/details/callbacks_v.h"
465485

466486
// additional method envelopes for variadic methods
467487
#include "cpptcl/details/methods_v.h"
468488

469-
} // namespace details
470489

471490
#include "cpptcl/details/bind.h"
472491

492+
namespace Tcl {
493+
473494
inline std::ostream & operator<<(std::ostream &os, const object& obj)
474495
{
475496
return os << obj.get<std::string>();

cpptcl/cpptcl_object.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#ifndef CPPTCL_OBJECT_H
99
#define CPPTCL_OBJECT_H
1010

11+
namespace Tcl {
12+
1113
class object;
1214

1315
/*
@@ -243,4 +245,6 @@ template <> char const *object::get<char const *>(interpreter &i) const;
243245
template <> std::string object::get<std::string>(interpreter &i) const;
244246
template <> std::vector<char> object::get<std::vector<char>>(interpreter &i) const;
245247

248+
}
249+
246250
#endif /* CPPTCL_OBJECT_H */

cpptcl/details/bind.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
namespace Tcl {
2+
13
template <typename R, typename T1, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void, typename T9 = void> struct Bind {
24
private:
35
object cmd_;
@@ -173,3 +175,5 @@ template <typename R> struct Bind<R, void, void, void, void, void, void, void, v
173175
return (R)(interpreter::getDefault()->eval(obj));
174176
}
175177
};
178+
179+
}

cpptcl/details/callbacks.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <tuple>
1414
#include <utility>
1515

16+
namespace Tcl { namespace details {
17+
1618
template <typename R> class callback0 : public callback_base {
1719
typedef R (*functor_type)();
1820

@@ -213,3 +215,7 @@ template <typename R, typename T1, typename T2, typename T3, typename T4, typena
213215
private:
214216
functor_type f_;
215217
};
218+
219+
}
220+
221+
}

cpptcl/details/callbacks_v.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// Note: this file is not supposed to be a stand-alone header
1212

13+
namespace Tcl { namespace details {
14+
1315
template <typename R> class callback1<R, object const &> : public callback_base {
1416
typedef object const &T1;
1517
typedef R (*functor_type)(T1);
@@ -199,3 +201,7 @@ template <typename R, typename T1, typename T2, typename T3, typename T4, typena
199201
private:
200202
functor_type f_;
201203
};
204+
205+
}
206+
207+
}

cpptcl/details/constructors.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//
1010

1111
// Note: this file is not supposed to be a stand-alone header
12+
namespace Tcl { namespace details {
1213

1314
template <class C, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9> struct construct {
1415
static C *doit(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) { return new C(t1, t2, t3, t4, t5, t6, t7, t8, t9); }
@@ -49,3 +50,7 @@ template <class C, typename T1> struct construct<C, T1, void, void, void, void,
4950
template <class C> struct construct<C, void, void, void, void, void, void, void, void, void> {
5051
static C *doit() { return new C(); }
5152
};
53+
54+
}
55+
56+
}

cpptcl/details/conversions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// helper functor for converting Tcl objects to the given type
1414
// (it is a struct instead of function,
1515
// because I need to partially specialize it)
16+
namespace Tcl { namespace details {
1617

1718
template <typename T> struct tcl_cast;
1819

@@ -65,3 +66,6 @@ template <> struct tcl_cast<char const *> { static char const *from(Tcl_Interp *
6566

6667
template <> struct tcl_cast<object> { static object from(Tcl_Interp *, Tcl_Obj *, bool byReference = false); };
6768

69+
}
70+
71+
}

0 commit comments

Comments
 (0)