Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-12-09 10:57:26


Ralf,

Casting a function pointer to a void* is not guaranteed to work portably.
Section 3.9.2 para 4 which grants you the ability to use void* to hold a
range of pointers specifically limits that range to pointers to objects. 1.8
para 1 which describes objects specifically says: "A function is not an
object, regardless of whether or not it occupies storage in the way that
objects do." I would prefer a portable solution, wouldn't you?

In any case, wouldn't you prefer not to have to do all this manual work? I
think I can arrange it so that you don't have to. It seems to me that in
this case, the maintainer of dvect and the maintainer of ivect both have to
recompile whenever either class changes anyway, so it's really unclear what
you're gaining by breaking them into separate modules.

Regards,
Davef
----- Original Message -----
From: <rwgk_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Saturday, December 09, 2000 4:58 AM
Subject: [boost] Re: [Boost Python Library] Mixing types wrapped in
different modules

> The next incremental step of implementing the feature originally
> proposed in this thread can be viewed at:
>
> http://cci.lbl.gov/~rwgk/cvs/cvsweb.cgi/bpl_tru64/
>
> The basic idea is very simple:
>
> 1. Wrap to_python (to avoid a cast in step 2). E.g.:
>
> PyObject *export_create_dvect(const vects::dvect& dv)
> {
> return BOOST_PYTHON_CONVERSION::to_python(dv);
> }
>
> 2. Export this function as PyCObject via the module's __dict__:
>
> this_module.add(
> python::ref(PyCObject_FromVoidPtr((void *) export_create_dvect,
> NULL)),
> "to_python_dvect");
>
> 3. Import the PyCObject in the other module (not shown, see new
> version of
> import_constructor.cpp), cast to function pointer and call the
> imported to_python():
>
> typedef PyObject *(*cvtr)(const vects::dvect&);
>
> PyObject *ivect_as_dvect_2(const vects::ivect& iv)
> {
> vects::dvect dv(iv.size());
> vects::dvect::iterator diter = dv.begin();
> for (int i = 0; i < iv.size(); i++) diter[i] = iv[i];
> cvtr to_python_dvect = (cvtr) import_cobject
> ("dvect", "to_python_dvect");
> PyObject *pydv = (*to_python_dvect)(dv);
> return pydv;
> }
>
> The tst_vects.py file is unchanged and works as before.
>
> The next incremental step of my plan is to export/import from_python
> in a similar way.
>
> Ralf
>
>
>
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk