Does pybindgen support cross module inheritance?

Asked by Mike Owen

Is it possible to use pybindgen to expose a C++ inheritance hierarchy where the base class is wrapped in one python module and the derived class in another? As an example suppose I have the following classes in a header "classes.hh":

#include <iostream>

class Base {
public:
  Base() { std::cerr << "Base::Base()" << std::endl; }
  virtual ~Base() { std::cerr << "Base::~Base()" << std::endl; }
  virtual void do_something() const { std::cerr << "Base::do_something()" << std::endl; }
};

class Derived: public Base {
public:
  Derived(): Base() { std::cerr << "Derived::Derived()" << std::endl; }
  virtual ~Derived() { std::cerr << "Derived::~Derived()" << std::endl; }
  virtual void do_something() const { std::cerr << "Derived::do_something()" << std::endl; }
};

I expose the "Base" class in one pybindgen generated python module like so:

from pybindgen import *

# Module
mod = Module("A")
mod.add_include('"classes.hh"')

# Base
Base = mod.add_class("Base", allow_subclassing = True)
Base.add_constructor([])
Base.add_method("do_something", None, [], is_virtual=True)

I would like to wrap the "Derived" class in a separate module like the following:

from pybindgen import *
import A

# Module
mod = Module("B")
mod.add_include('"classes.hh"')

# Derived
Derived = mod.add_class("Derived", allow_subclassing = True, parent = A.Base)
Derived.add_constructor([])
Derived.add_method("do_something", None, [], is_virtual=True)

When I try and do this however, the code generated for module "B" above contains references to things that are defined in the code generated for "A" (not surprisingly), and so of course it doesn't compile. Is there some simple way to accomplish this kind of cross module inheritance with pybindgen?

Thanks!

Question information

Language:
English Edit question
Status:
Answered
For:
PyBindGen Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Gustavo Carneiro (gjc) said :
#1

The short answer is: no.

I would like to have this implemented, but it's not there yet and I have no plans to implement it in the next 6 months. Sorry :-/

For now you have to wrap everything in the same python module. The python module can have "submodules", but the modularity is fake, they will all belong to the same dll.

Revision history for this message
Mike Owen (mikeowen) said :
#2

OK, I figured that was the case. I don't suppose it's possible to have pybindgen generate the code for a single module as multiple .c files then either? The practical problem I'm running into is that the single uber-module I'm generating due to these inheritance hierarchies takes rather long to compile, so I'm looking for ways to break up the single large compile job into a number of smaller compilations that occur in parallel.

Revision history for this message
Gustavo Carneiro (gjc) said :
#3

Can you help with this problem?

Provide an answer of your own, or ask Mike Owen for more information if necessary.

To post a message you must log in.