Skip to content

Commit

Permalink
Explicitly define namespaces in headers instead of relying on include…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
NasaGeek authored Jun 2, 2023
1 parent 4c1ef5a commit a74bfba
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
build:

runs-on: ubuntu-latest
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/mac-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
build:

runs-on: macos-latest
runs-on: macos-11

steps:
- uses: actions/checkout@v2
Expand All @@ -18,8 +18,8 @@ jobs:
brew update
brew install tcl-tk || true
sudo mkdir -p /usr/local
sudo ln -sf /usr/local/opt/tcl-tk/include /usr/local/include/tcl8.6
sudo cp /usr/local/opt/tcl-tk/lib/libtcl* /usr/local/lib
sudo ln -sf /usr/local/opt/tcl-tk/include/tcl-tk /usr/local/include/tcl8.6
sudo install /usr/local/opt/tcl-tk/lib/libtcl* /usr/local/lib
sudo ln -sf /usr/local/opt/tcl-tk/bin/tclsh8.6 /usr/local/bin/tclsh
sudo ln -sf /usr/local/opt/tcl-tk/bin/tclsh8.6 /usr/local/bin/tclsh8.6
- name: make
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(cpptcl)
include(cmake/version.cmake)
load_git_properties(cpptcl ${CMAKE_BINARY_DIR}/generated)

set(CPPTCL_VERSION 2.2.5)
set(CPPTCL_VERSION 2.2.8)

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to Release as none was specified.")
Expand Down
27 changes: 24 additions & 3 deletions cpptcl/cpptcl.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,28 @@ void set_result(Tcl_Interp *interp, std::string const &s);
void set_result(Tcl_Interp *interp, void *p);
void set_result(Tcl_Interp *interp, object const &o);

}

}

// helper functor for converting Tcl objects to the given type
#include "cpptcl/details/conversions.h"

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

namespace Tcl {

namespace details {

// helper for checking for required number of parameters
// (throws tcl_error when not met)
void check_params_no(int objc, int required, const std::string &message);

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

// the callback_base is used to store callback handlers in a polynorphic map
// the callback_base is used to store callback handlers in a polymorphic map
class callback_base {
public:
virtual ~callback_base() {}
Expand Down Expand Up @@ -190,6 +198,10 @@ template <class C> class class_handler : public class_handler_base {
}
};

}

}

// factory functions for creating class objects
#include "cpptcl/details/constructors.h"

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

namespace Tcl {

namespace details {

// this class is used to provide the "def" interface for defining
// class member functions

Expand Down Expand Up @@ -444,8 +460,12 @@ class interpreter {
bool owner_;
};

}

#include "cpptcl/cpptcl_object.h"

namespace Tcl {

// the InputIterator should give object& or Tcl_Obj* when dereferenced
template <class InputIterator> details::result interpreter::eval(InputIterator first, InputIterator last) {
std::vector<Tcl_Obj *> v;
Expand All @@ -458,18 +478,19 @@ template <class InputIterator> details::result interpreter::eval(InputIterator f
return details::result(interp_);
}

namespace details {
}

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

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

} // namespace details

#include "cpptcl/details/bind.h"

namespace Tcl {

inline std::ostream & operator<<(std::ostream &os, const object& obj)
{
return os << obj.get<std::string>();
Expand Down
4 changes: 4 additions & 0 deletions cpptcl/cpptcl_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#ifndef CPPTCL_OBJECT_H
#define CPPTCL_OBJECT_H

namespace Tcl {

class object;

/*
Expand Down Expand Up @@ -243,4 +245,6 @@ template <> char const *object::get<char const *>(interpreter &i) const;
template <> std::string object::get<std::string>(interpreter &i) const;
template <> std::vector<char> object::get<std::vector<char>>(interpreter &i) const;

}

#endif /* CPPTCL_OBJECT_H */
4 changes: 4 additions & 0 deletions cpptcl/details/bind.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
namespace Tcl {

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 {
private:
object cmd_;
Expand Down Expand Up @@ -173,3 +175,5 @@ template <typename R> struct Bind<R, void, void, void, void, void, void, void, v
return (R)(interpreter::getDefault()->eval(obj));
}
};

}
6 changes: 6 additions & 0 deletions cpptcl/details/callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <tuple>
#include <utility>

namespace Tcl { namespace details {

template <typename R> class callback0 : public callback_base {
typedef R (*functor_type)();

Expand Down Expand Up @@ -213,3 +215,7 @@ template <typename R, typename T1, typename T2, typename T3, typename T4, typena
private:
functor_type f_;
};

}

}
6 changes: 6 additions & 0 deletions cpptcl/details/callbacks_v.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

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

namespace Tcl { namespace details {

template <typename R> class callback1<R, object const &> : public callback_base {
typedef object const &T1;
typedef R (*functor_type)(T1);
Expand Down Expand Up @@ -199,3 +201,7 @@ template <typename R, typename T1, typename T2, typename T3, typename T4, typena
private:
functor_type f_;
};

}

}
5 changes: 5 additions & 0 deletions cpptcl/details/constructors.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//

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

template <class C, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9> struct construct {
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); }
Expand Down Expand Up @@ -49,3 +50,7 @@ template <class C, typename T1> struct construct<C, T1, void, void, void, void,
template <class C> struct construct<C, void, void, void, void, void, void, void, void, void> {
static C *doit() { return new C(); }
};

}

}
4 changes: 4 additions & 0 deletions cpptcl/details/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// helper functor for converting Tcl objects to the given type
// (it is a struct instead of function,
// because I need to partially specialize it)
namespace Tcl { namespace details {

template <typename T> struct tcl_cast;

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

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

}

}
6 changes: 6 additions & 0 deletions cpptcl/details/dispatchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// capture its return value
// further dispatch<void> specialization ignores the res

namespace Tcl { namespace details {

template <typename R> struct dispatch {
template <class Functor> static void do_dispatch(Tcl_Interp *interp, Functor f) {
R res = f();
Expand Down Expand Up @@ -87,3 +89,7 @@ template <> struct dispatch<void> {

template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, class Functor> static void do_dispatch(Tcl_Interp *, Functor f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) { f(t1, t2, t3, t4, t5, t6, t7, t8, t9); }
};

}

}
5 changes: 5 additions & 0 deletions cpptcl/details/metahelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//

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

template <class C, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9> struct get_callback_type_for_construct { typedef callback9<C *, T1, T2, T3, T4, T5, T6, T7, T8, T9> type; };

Expand All @@ -29,3 +30,7 @@ template <class C, typename T1, typename T2> struct get_callback_type_for_constr
template <class C, typename T1> struct get_callback_type_for_construct<C, T1, void, void, void, void, void, void, void, void> { typedef callback1<C *, T1> type; };

template <class C> struct get_callback_type_for_construct<C, void, void, void, void, void, void, void, void, void> { typedef callback0<C *> type; };

}

}
5 changes: 5 additions & 0 deletions cpptcl/details/methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//

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

template <class C, typename R> class method0 : public object_cmd_base {
typedef R (C::*mem_type)();
Expand Down Expand Up @@ -302,3 +303,7 @@ template <class C, typename R, typename T1, typename T2, typename T3, typename T
cmem_type cf_;
bool cmem_;
};

}

}
5 changes: 5 additions & 0 deletions cpptcl/details/methods_v.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//

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

template <class C, typename R> class method1<C, R, object const &> : public object_cmd_base {
typedef object const &T1;
Expand Down Expand Up @@ -261,3 +262,7 @@ template <class C, typename R, typename T1, typename T2, typename T3, typename T
cmem_type cf_;
bool cmem_;
};

}

}

0 comments on commit a74bfba

Please sign in to comment.