From caf2f7fb91eb584180705e3bc0b0c2a17915ed2c Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Sun, 20 Jul 2008 19:44:14 +0100 Subject: [PATCH] Make CppClass parameter memory_policy slightly less restrictive (allow subclass to define memory_policy as long as no parent class has defined it before). --- pybindgen/cppclass.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pybindgen/cppclass.py b/pybindgen/cppclass.py index fcd3ba8..1860286 100644 --- a/pybindgen/cppclass.py +++ b/pybindgen/cppclass.py @@ -528,9 +528,17 @@ class CppClass(object): assert self.memory_policy is None self.memory_policy = ReferenceCountingFunctionsPolicy(incref_function, decref_function) else: - assert memory_policy is None, "only root classes may define memory policies" - assert not (free_function or incref_method or incref_function), "only root classes may define memory policies" - self.memory_policy = None + parent_tmp = None + have_parent_memory_policy = False + while parent_tmp is not None: + if parent.memory_policy is not None: + have_parent_memory_policy = True + break + assert memory_policy is None or not have_parent_memory_policy, \ + "changing memory policy from parent to child class not permitted" + assert not (free_function or incref_method or incref_function) or not have_parent_memory_policy, \ + "changing memory policy from parent to child class not permitted" + self.memory_policy = memory_policy if automatic_type_narrowing is None: if parent is None: