Boost logo

Boost :

From: rwgk_at_[hidden]
Date: 2000-12-08 19:47:46

> What mechanism are you referring to?

The one that is implemented in

and used in

  PyObject *ivect_as_dvect_hack(const vects::ivect& iv)
    PyObject *dvect_constructor = import_constructor
("dvect", "dvect");
    python::tuple args(1);
    args.set_item(0, iv.as_tuple());
    PyObject *dvect = PyObject_CallObject(dvect_constructor, args.get
    return dvect;

import_constructor("dvect", "dvect") imports a pointer to a
callable Python object. PyObject_CallObject() uses this to
call the constructor that actually lives in

Using a PyCObject, one can export/import any type of pointer.
In fact, this is how, e.g., the NumPy CAPI is implemented.
See, e.g., the bottom quarter of this file:

The #define import_array() at the very bottom is essentially
the same as my import_constructor().

Note that all functions of the array CAPI are accessed via #defines,

#define PyArray_PutMask \
  (*(PyArray_PutMask_RET (*)PyArray_PutMask_PROTO) \

Admittedly, this looks quite ugly, but it is portable and at
the user level very convenient.

My hope is that this portable export/import mechanism including
instantiation of appropriate from_python/to_python templates
could be hidden from the BPL user.


Boost list run by bdawes at, gregod at, cpdaniel at, john at