Opened 21 years ago
Closed 19 years ago
#925 closed Bugs (None)
export inhereted method under gcc fails
| Reported by: | andreitd | Owned by: | david_abrahams |
|---|---|---|---|
| Milestone: | Component: | python USE GITHUB | |
| Version: | None | Severity: | |
| Keywords: | Cc: |
Description
When I try to export a method inhereted from some base
class, I get compilation errors unless I also export
the base class. I've got a feeling it's compiler bug
(gcc 2.96),
but I am not entirely sure.
....................................
class Base {
public:
int f(int i) { return -i; }
};
class Derived : public Base {
};
BOOST_PYTHON_MODULE_INIT(ex_pmf_ext)
{
try
{
python::module_builder this_module("ex_pmf_ext");
python::class_builder<Derived>
derived_class(this_module, "Derived");
derived_class.def(python::constructor<>());
derived_class.def(&Derived::f, "f");
}
catch(...)
{
python::handle_exception();
}
}
.......................
The compiler says it can't find 'from_python()'
function for 'Base' class. The error message also shows
that the compiler sees '&Base::f' pointer-to-member
instead of
'&Derived::f'. That silent conversion seems to be a
primary cause of the entire problem.
...instantiated from
`boost::python::detail::wrapped_function_pointer<R,
F>::do_call (PyObject *, PyObject *) const [with R =
int, F = int ({unnamed}::Base::*) (int)]'...
If I add
...
python::class_builder<Base> base_class(this_module,
"Base");
derived_class.declare_base(base_class,python::without_downcast);
...
then everything works. However, it's obviously a
nuisance since the entire class hierarchy may be quite
convoluted or undocumented in general case (inhereted
from
vendor-supplied library, for instance), and I only care
about using this method through my 'Derived' class, not
the 'Base' class directly. Is this a bug in the
compiler (it
does not have the right to replace &Derived::f with
&Base::f, does it)? Of cause, I can define and export
functions like
int f(Derived *self,int i) {
return self->f(i);
}
Note:
See TracTickets
for help on using tickets.
