diff --git a/pybindgen/cppclass.py b/pybindgen/cppclass.py index 3da027b..445402e 100644 --- a/pybindgen/cppclass.py +++ b/pybindgen/cppclass.py @@ -828,7 +828,9 @@ public: elif isinstance(method, function.Function): assert name is not None assert isinstance(method.parameters[0], CppClassParameterBase) - assert method.parameters[0].cpp_class is self + assert method.parameters[0].cpp_class is self, \ + "expected first parameter to be of class %s, but it is of class %s" % \ + (self.full_name, method.parameters[0].cpp_class.full_name) method.parameters[0].take_value_from_python_self = True method.module = self.module method.is_virtual = False diff --git a/pybindgen/enum.py b/pybindgen/enum.py index e2fec11..057e98f 100644 --- a/pybindgen/enum.py +++ b/pybindgen/enum.py @@ -51,18 +51,17 @@ class Enum(object): """Set the Module object this class belongs to; can only be set once""" assert self._module is None self._module = module + if self.outer_class is None: - if module.cpp_namespace_prefix: - if module.cpp_namespace_prefix == '::': - self.full_name = self.name + if self._module.cpp_namespace_prefix: + if self._module.cpp_namespace_prefix == '::': + self.full_name = '::' + self.name else: - self.full_name = module.cpp_namespace_prefix + '::' + self.name + self.full_name = self._module.cpp_namespace_prefix + '::' + self.name else: self.full_name = self.name - if not self.full_name.startswith('::'): - self.full_name = '::' + self.full_name else: - self.full_name = self.outer_class.full_name + '::' + self.name + self.full_name = '::'.join([self.outer_class.full_name, self.name]) ## Register type handlers for the enum type assert self.name diff --git a/pybindgen/gccxmlparser.py b/pybindgen/gccxmlparser.py index fe2c60e..8529527 100644 --- a/pybindgen/gccxmlparser.py +++ b/pybindgen/gccxmlparser.py @@ -57,8 +57,8 @@ def normalize_name(decl_string): cls_name = decl_string template_parameters = None if not _digits.match(cls_name): - if not cls_name.startswith('::') and cls_name not in cpptypes.FUNDAMENTAL_TYPES: - cls_name = '::' + cls_name + if cls_name.startswith('::'): + cls_name = cls_name[2:] if template_parameters is None: return cls_name else: @@ -948,37 +948,6 @@ class ModuleParser(object): for hook in self._pre_scan_hooks: hook(self, fun, global_annotations, parameter_annotations) - if global_annotations.get("ignore", False): - continue - - is_constructor_of = global_annotations.get("is_constructor_of", None) - return_annotations = parameter_annotations.get('return', {}) - if is_constructor_of: - return_annotations['caller_owns_return'] = 'true' - try: - return_type = type_registry.lookup_return(fun.return_type, return_annotations) - except (TypeLookupError, TypeConfigurationError), ex: - warnings.warn_explicit("Return value '%s' error (used in %s): %r" - % (fun.return_type.decl_string, fun, ex), - Warning, fun.location.file_name, fun.location.line) - continue - arguments = [] - for arg in fun.arguments: - try: - arguments.append(type_registry.lookup_parameter(arg.type, arg.name, - parameter_annotations.get(arg.name, {}))) - except (TypeLookupError, TypeConfigurationError), ex: - warnings.warn_explicit("Parameter '%s %s' error (used in %s): %r" - % (arg.type.decl_string, arg.name, fun, ex), - Warning, fun.location.file_name, fun.location.line) - - ok = False - break - else: - ok = True - if not ok: - continue - as_method = None of_class = None alt_name = None @@ -1000,6 +969,49 @@ class ModuleParser(object): if ignore: continue + + is_constructor_of = global_annotations.get("is_constructor_of", None) + return_annotations = parameter_annotations.get('return', {}) + if is_constructor_of: + return_annotations['caller_owns_return'] = 'true' + try: + return_type = type_registry.lookup_return(fun.return_type, return_annotations) + except (TypeLookupError, TypeConfigurationError), ex: + warnings.warn_explicit("Return value '%s' error (used in %s): %r" + % (fun.return_type.decl_string, fun, ex), + Warning, fun.location.file_name, fun.location.line) + continue + except TypeError, ex: + warnings.warn_explicit("Return value '%s' error (used in %s): %r" + % (fun.return_type.decl_string, fun, ex), + Warning, fun.location.file_name, fun.location.line) + raise + arguments = [] + for argnum, arg in enumerate(fun.arguments): + annotations = parameter_annotations.get(arg.name, {}) + if argnum == 0 and as_method is not None \ + and isinstance(arg.type, cpptypes.pointer_t): + annotations.setdefault("transfer_ownership", "false") + try: + arguments.append(type_registry.lookup_parameter(arg.type, arg.name, + annotations)) + except (TypeLookupError, TypeConfigurationError), ex: + warnings.warn_explicit("Parameter '%s %s' error (used in %s): %r" + % (arg.type.decl_string, arg.name, fun, ex), + Warning, fun.location.file_name, fun.location.line) + + ok = False + break + except TypeError, ex: + warnings.warn_explicit("Parameter '%s %s' error (used in %s): %r" + % (arg.type.decl_string, arg.name, fun, ex), + Warning, fun.location.file_name, fun.location.line) + raise + else: + ok = True + if not ok: + continue + if as_method is not None: assert of_class is not None cpp_class = type_registry.find_class(of_class, (self.module_namespace_name or '::'))