Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

‘PyNs3<classname>__PythonHelper’ was not declared in this scope #4

Closed
tomhenderson opened this issue Feb 25, 2016 · 1 comment
Closed

Comments

@tomhenderson
Copy link
Contributor

I have a question regarding the failure of bindings compilation for some proposed changes to ns-3 NetDevice.

To reproduce:
git clone https://github.com/stavallo/ns-3-dev-git
cd ns-3-dev-git
git checkout -b queue-disc-exp remotes/origin/queue-disc-exp
./waf configure --enable-modules=network --with-pybindgen=/path/to/pybindgen
./waf build
./waf --apiscan=network
./waf build

fails with:

In file included from src/network/bindings/ns3module.cc:1:0:
src/network/bindings/ns3module.h: In member function ‘virtual bool PythonCallbackImpl1::operator()(ns3::Ptrns3::NetDevice, ns3::Ptr, short unsigned int, const ns3::Address&, const ns3::Address&, ns3::NetDevice::PacketType)’:
src/network/bindings/ns3module.h:4944:96: error: ‘PyNs3NetDevice__PythonHelper’ was not declared in this scope

Here is some context on this change. Until now, NetDevice was pure abstract, but the changes proposed in this class add some non-virtual methods and private data.

If I modify NetDevice with some trivial non-virtual methods and private data, pybindgen still works, so it has to do with something about the specific nature of the proposed changes and not generically about moving from pure abstract to abstract.

The compilation is failing in the definition of one of the callbacks:

bool
operator()(ns3::Ptr< ns3::NetDevice > arg1, ns3::Ptr< ns3::Packet const > arg2, unsigned short arg3, ns3::Address const & arg4, ns3::Address const & arg5, ns3::NetDevice::PacketType arg6)
{
    if (typeid(*(const_cast<ns3::NetDevice *> (ns3::PeekPointer (arg1)))).name() == typeid(PyNs3NetDevice__PythonHelper).name())
    {
        py_NetDevice = (PyNs3NetDevice*) (((PyNs3NetDevice__PythonHelper*) const_cast<ns3::NetDevice *> (ns3::PeekPointer (arg1)))->m_pyself);
        py_NetDevice->obj = const_cast<ns3::NetDevice *> (ns3::PeekPointer (arg1));
        Py_INCREF(py_NetDevice);
    } else {
        wrapper_lookup_iter = PyNs3ObjectBase_wrapper_registry.find((void *) const_cast<ns3::NetDevice *> (ns3::PeekPointer (arg1)));

where the PyNs3NetDevice__PythonHelper does not exist because this is an abstract class still.

In the previous version of the bindings, the if () branch does not exist, and the function moves directly to
wrapper_lookup_iter = PyNs3ObjectBase_wrapper_registry.find((void *) const_cast<ns3::NetDevice *> (ns3::PeekPointer (arg1)));

so what appears to be the problem is that something is triggering pybindgen to include this TypeId check, which is failing due to lack of the PyNs3NetDevice__PythonHelper class.

At this point I'm not clear whether it is a pybindgen issue or not.

@gjcarneiro
Copy link
Owner

It looks like this is a side-effect of some code generation customisations I did for ns-3. I don't think normal PBG usage is affected.

It happens that we generate some code to support ns-3 callbacks wrappers in advance, before PBG gets a chance to call generate_forward_declarations(), which would invalidate the "helper class" at that point. We generate code thinking we will have a helper class, but PBG changes its mind later on when it finds out the helper class could not be generated (possibly due to some pure virtual method for which we could not generate wrappers). Basically, stupid PBG design decisions, if I were to start from scratch I would do a lot of things differently...

Can you please apply the attached patch to ns-3? Thanks.

p.diff.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants