From f3e00b1ecb615a670c1bf3abdb7aa59fa21b09ab Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Sun, 7 Aug 2011 16:51:57 +0100 Subject: [PATCH] Add setting to disable usage of internal GCC abi to check rtti stuff --- pybindgen/cppclass.py | 22 ++++++++++++++++++++++ pybindgen/settings.py | 10 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/pybindgen/cppclass.py b/pybindgen/cppclass.py index 2e0271f..1730b4b 100644 --- a/pybindgen/cppclass.py +++ b/pybindgen/cppclass.py @@ -1240,6 +1240,10 @@ public: m_map[std::string(cpp_type_info.name())] = python_wrapper; } +''') + + if settings.gcc_rtti_abi_complete: + code_sink.writeln(''' PyTypeObject * lookup_wrapper(const std::type_info &cpp_type_info, PyTypeObject *fallback_wrapper) { @@ -1286,6 +1290,24 @@ public: } ''') + else: + code_sink.writeln(''' + PyTypeObject * lookup_wrapper(const std::type_info &cpp_type_info, PyTypeObject *fallback_wrapper) + { + +#if PBG_TYPEMAP_DEBUG + std::cerr << "lookup_wrapper(this=" << this << ", type_name=" << cpp_type_info.name() << ")" << std::endl; +#endif + + PyTypeObject *python_wrapper = m_map[cpp_type_info.name()]; + return python_wrapper? python_wrapper : fallback_wrapper; + } +}; + +} +''') + + if self.import_from_module: code_sink.writeln("\nextern pybindgen::TypeMap *_%s;\n" % self.typeid_map_name) code_sink.writeln("#define %s (*_%s)\n" % (self.typeid_map_name, self.typeid_map_name)) diff --git a/pybindgen/settings.py b/pybindgen/settings.py index 5f3f2f7..45bb4f6 100644 --- a/pybindgen/settings.py +++ b/pybindgen/settings.py @@ -65,6 +65,16 @@ behaviour. But this is really deprecated; newer code should set deprecated_virtuals to False. """ + +gcc_rtti_abi_complete = True +""" +If True, and GCC >= 3 is detected at compile time, pybindgen will try +to use abi::__si_class_type_info to determine the closest registered +type for pointers to objects of unknown type. Notably, Mac OS X Lion +has GCC > 3 but which breaks this internal API, in which case it +should be disabled (set this option to False). +""" + def _get_deprecated_virtuals(): if deprecated_virtuals is None: import warnings