Boost logo

Boost :

From: rwgk_at_[hidden]
Date: 2000-12-09 04:58:55


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