Inheritance w/ memory_policy as boost shared_ptr
I've come across a problem in my understanding of pybindgen or a problem with pybindgen's handing of boost::shared_ptr<> and inheritance. I running on RH, gcc, and pybindgen's trunk as of Aug 1.
Thanks in advance for your assistance.
Code and script to create bindings are at the end of the message (gz sample project available).
-------
Description:
The example includes two classes a Parent and a Child (which extends Parent). Under the default
memory management policy, the code compiles correctly and can be easily tested. When
changing the memory policy to support boost's shared_ptr<>, compiling the generated binding code
will not compile.
A couple of observations of the generated code w/ boost memory policy:
1. Code: self_obj_before = reinterpret_cast< PyExampleParent* >(m_pyself)->obj;
Should this not be a cast to the boost::
2. Code: PyExampleChild_
As obj is a boost::
3. The Child data structure (PyExampleChild) contains a handle (obj) to the Child instance it
manages as the root class Parent. This is okay, except for cases where the generated code calls
the helper class or casts. Code:
// original: (helper_class == NULL)? (self->
/* modified */ (helper_class == NULL)? (self->
// error: invalid conversion from 'Example::Parent*' to 'Example::Child*'
self_
4. Code: ((PyExampleChil
Since self->obj is a boost::
-------
Code (.cpp not shown):
namespace Example {
class Parent {
public:
Parent();
virtual void hello();
};
class Child : public Parent {
public:
Child();
virtual void hello();
};
}
-------
bindings.py:
import sys
from pybindgen import Parameter, Module, FileCodeSink
from pybindgen import cppclass
def gen_shared():
mod = Module('Simple')
ns = mod.add_
ns.
# Note this creates code that does not compile (see README).
parentC = ns.add_
# Works as expected
#parentC = ns.add_
parentC.
parentC.
childC = ns.add_
childC.
childC.
out_
mod.
if __name__ == '__main__':
gen_shared()
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- PyBindGen Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Gustavo Carneiro
- Solved:
- Last query:
- Last reply: