From 6137f3916fbb9419e19dc3603d0162d15387d1cc Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Sun, 20 Jul 2008 19:26:00 +0100 Subject: [PATCH] Fix some more deprecations --- pybindgen/__init__.py | 1 - pybindgen/cppclass.py | 10 ++++++++++ pybindgen/gccxmlparser.py | 19 +++++++++++-------- tests/foomodulegen.py | 6 ++++-- tests/wscript | 2 +- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/pybindgen/__init__.py b/pybindgen/__init__.py index 6b86106..b277c15 100644 --- a/pybindgen/__init__.py +++ b/pybindgen/__init__.py @@ -657,4 +657,3 @@ from enum import Enum from utils import write_preamble, param, retval import version - diff --git a/pybindgen/cppclass.py b/pybindgen/cppclass.py index ad60838..fcd3ba8 100644 --- a/pybindgen/cppclass.py +++ b/pybindgen/cppclass.py @@ -68,6 +68,10 @@ class ReferenceCountingMethodsPolicy(ReferenceCountingPolicy): def get_free_code(self, obj_expr): return ('%s->%s();' % (obj_expr, self.decref_method)) + def __repr__(self): + return 'cppclass.ReferenceCountingMethodsPolicy(incref_method=%r, decref_method=%r, peekref_method=%r)' \ + % (self.incref_method, self.decref_method, self.peekref_method) + class ReferenceCountingFunctionsPolicy(ReferenceCountingPolicy): def __init__(self, incref_function, decref_function, peekref_function=None): @@ -85,6 +89,9 @@ class ReferenceCountingFunctionsPolicy(ReferenceCountingPolicy): def get_free_code(self, obj_expr): return ('%s(%s);' % (obj_expr, self.decref_function)) + def __repr__(self): + return 'cppclass.ReferenceCountingFunctionsPolicy(incref_function=%r, decref_function=%r, peekref_function=%r)' \ + % (self.incref_function, self.decref_function, self.peekref_function) class FreeFunctionPolicy(MemoryPolicy): def __init__(self, free_function): @@ -94,6 +101,9 @@ class FreeFunctionPolicy(MemoryPolicy): def get_free_code(self, obj_expr): return ('%s(%s);' % (self.free_function, obj_expr)) + def __repr__(self): + return 'cppclass.FreeFunctionPolicy(%r)' % self.free_function + def default_instance_creation_function(cpp_class, code_block, lvalue, parameters, construct_type_name): diff --git a/pybindgen/gccxmlparser.py b/pybindgen/gccxmlparser.py index 567ba0b..e00d533 100644 --- a/pybindgen/gccxmlparser.py +++ b/pybindgen/gccxmlparser.py @@ -11,7 +11,7 @@ from typehandlers.codesink import FileCodeSink, CodeSink, NullCodeSink import typehandlers.base from typehandlers.base import ReturnValue, Parameter, TypeLookupError, TypeConfigurationError, NotSupportedError from pygccxml.declarations.enumeration import enumeration_t -from cppclass import CppClass, ReferenceCountingMethodsPolicy +from cppclass import CppClass, ReferenceCountingMethodsPolicy, FreeFunctionPolicy, ReferenceCountingFunctionsPolicy from pygccxml.declarations import type_traits from pygccxml.declarations import cpptypes from pygccxml.declarations import calldef @@ -669,7 +669,7 @@ class ModuleParser(object): self.module.add_include(inc) for pygen_sink in self._get_all_pygen_sinks(): - pygen_sink.writeln("from pybindgen import Module, FileCodeSink, param, retval") + pygen_sink.writeln("from pybindgen import Module, FileCodeSink, param, retval, cppclass") pygen_sink.writeln() pygen_sink = self._get_main_pygen_sink() @@ -823,19 +823,22 @@ pybindgen.settings.error_handler = ErrorHandler() elif name == 'is_singleton': kwargs.setdefault('is_singleton', annotations_scanner.parse_boolean(value)) elif name == 'incref_method': - kwargs.setdefault('incref_method', value) + kwargs.setdefault('memory_policy', ReferenceCountingMethodsPolicy( + incref_method=value, decref_method=annotations.get('decref_method', None), + peekref_method=annotations.get('peekref_method', None))) elif name == 'decref_method': - kwargs.setdefault('decref_method', value) + pass elif name == 'peekref_method': - kwargs.setdefault('peekref_method', value) + pass elif name == 'automatic_type_narrowing': kwargs.setdefault('automatic_type_narrowing', annotations_scanner.parse_boolean(value)) elif name == 'free_function': - kwargs.setdefault('free_function', value) + kwargs.setdefault('memory_policy', FreeFunctionPolicy(value)) elif name == 'incref_function': - kwargs.setdefault('incref_function', value) + kwargs.setdefault('memory_policy', ReferenceCountingFunctionsPolicy( + incref_function=value, decref_function=annotations.get('decref_function', None))) elif name == 'decref_function': - kwargs.setdefault('decref_function', value) + pass elif name == 'python_name': kwargs.setdefault('python_name', value) elif name == 'pygen_comment': diff --git a/tests/foomodulegen.py b/tests/foomodulegen.py index ded4eb6..c4ee128 100755 --- a/tests/foomodulegen.py +++ b/tests/foomodulegen.py @@ -10,6 +10,7 @@ from pybindgen import (ReturnValue, Parameter, Module, Function, FileCodeSink) from pybindgen import (CppMethod, CppConstructor, CppClass, Enum) from pybindgen.function import CustomFunctionWrapper from pybindgen.cppmethod import CustomCppMethodWrapper +from pybindgen import cppclass import foomodulegen_common @@ -52,8 +53,9 @@ def my_module_gen(out_file): ## Zbr is a reference counted class - Zbr = mod.add_class('Zbr', incref_method='Ref', decref_method='Unref', - peekref_method="GetReferenceCount", allow_subclassing=True) + Zbr = mod.add_class('Zbr', memory_policy=cppclass.ReferenceCountingMethodsPolicy( + incref_method='Ref', decref_method='Unref', peekref_method="GetReferenceCount"), + allow_subclassing=True) def helper_class_hook(helper_class): helper_class.add_custom_method( diff --git a/tests/wscript b/tests/wscript index 6ba1314..f356c96 100644 --- a/tests/wscript +++ b/tests/wscript @@ -18,7 +18,7 @@ def create_pyext_obj(bld, c_or_cpp_type): return bld.create_obj(c_or_cpp_type, 'plugin', 'pyext') -if 0: +if 1: DEPRECATION_ERRORS = '-Werror::DeprecationWarning' # deprecations become errors else: DEPRECATION_ERRORS = '-Wdefault::DeprecationWarning' # normal python behaviour