diff --git a/pybindgen/cppattribute.py b/pybindgen/cppattribute.py index 1398e7a..738617d 100644 --- a/pybindgen/cppattribute.py +++ b/pybindgen/cppattribute.py @@ -243,8 +243,8 @@ class PyMetaclass(object): getsets -- name of a PyGetSetDef C array variable, or None """ assert getsets is None or isinstance(getsets, PyGetSetDef) - assert isinstance(name, str) - assert isinstance(parent_metaclass_expr, str) + assert isinstance(name, basestring) + assert isinstance(parent_metaclass_expr, basestring) self.name = name prefix = settings.name_prefix.capitalize() diff --git a/pybindgen/cppclass.py b/pybindgen/cppclass.py index 6943a41..fe4dab1 100644 --- a/pybindgen/cppclass.py +++ b/pybindgen/cppclass.py @@ -1004,7 +1004,7 @@ static void peekref_code = " && self->obj->%s() == 1" % self.peekref_method visit_self = ''' if (self->obj && typeid(*self->obj) == typeid(%s)%s) - Py_VISIT(self); + Py_VISIT((PyObject *) self); ''' % (self.helper_class.name, peekref_code) code_sink.writeln(r''' diff --git a/pybindgen/enum.py b/pybindgen/enum.py index 32d8e33..e2fec11 100644 --- a/pybindgen/enum.py +++ b/pybindgen/enum.py @@ -24,12 +24,12 @@ class Enum(object): be used when wrapping enums declared inside C++ classes. """ - assert isinstance(name, str) + assert isinstance(name, basestring) assert '::' not in name assert outer_class is None or isinstance(outer_class, CppClass) self.outer_class = outer_class for val in values: - if not isinstance(val, str): + if not isinstance(val, basestring): raise TypeError if not name: diff --git a/pybindgen/gccxmlparser.py b/pybindgen/gccxmlparser.py index b182483..1386643 100644 --- a/pybindgen/gccxmlparser.py +++ b/pybindgen/gccxmlparser.py @@ -800,7 +800,11 @@ class ModuleParser(object): if type_traits.has_trivial_constructor(cls): class_wrapper.add_constructor(CppConstructor([])) if not have_copy_constructor: - if type_traits.has_copy_constructor(cls): + try: # pygccxml > 0.9 + has_copy_constructor = type_traits.has_copy_constructor(cls) + except AttributeError: # pygccxml <= 0.9 + has_copy_constructor = type_traits.has_trivial_copy(cls) + if has_copy_constructor: class_wrapper.add_constructor(CppConstructor([ class_wrapper.ThisClassRefParameter("%s const &" % class_wrapper.full_name, 'ctor_arg', is_const=True)])) diff --git a/pybindgen/typehandlers/codesink.py b/pybindgen/typehandlers/codesink.py index 364807a..931f57a 100644 --- a/pybindgen/typehandlers/codesink.py +++ b/pybindgen/typehandlers/codesink.py @@ -34,7 +34,7 @@ class CodeSink(object): def _format_code(self, code): """Utility method for subclasses to use for formatting code (splits lines and indents them)""" - assert isinstance(code, str) + assert isinstance(code, basestring) l = [] for line in code.split('\n'): l.append(' '*self.indent_level + line) diff --git a/pybindgen/utils.py b/pybindgen/utils.py index b32bff0..a7ace82 100644 --- a/pybindgen/utils.py +++ b/pybindgen/utils.py @@ -33,7 +33,18 @@ def write_preamble(code_sink, min_python_version=(2, 3)): } \ } while (0) + +#define Py_VISIT(op) \ + do { \ + if (op) { \ + int vret = visit((PyObject *)(op), arg); \ + if (vret) \ + return vret; \ + } \ + } while (0) + #endif + ''') if min_python_version < (2, 5): @@ -47,15 +58,6 @@ typedef inquiry lenfunc; typedef intargfunc ssizeargfunc; typedef intobjargproc ssizeobjargproc; -#define Py_VISIT(op) \ - do { \ - if (op) { \ - int vret = visit((PyObject *)(op), arg); \ - if (vret) \ - return vret; \ - } \ - } while (0) - #endif ''') @@ -73,7 +75,7 @@ typedef intobjargproc ssizeobjargproc; def get_mangled_name(base_name, template_args): """for internal pybindgen use""" - assert isinstance(base_name, str) + assert isinstance(base_name, basestring) assert isinstance(template_args, (tuple, list)) if template_args: