As I hinted at in an earlier email, I'm working on a module which will allow calling readdir() (and FindFirstFile on Windows, hopefully pretty uniformly) from Python. The responses I got convinced me that it was a good idea to write a C-to-Python bridge as an extension module.
What I'm not sure about is how to store pointers to *C* stuff between calls. In particular, opendir() returns a DIR* which you then need to pass to calls to readdir() in the future (and closedir()). So I've got this: static PyObject* py_opendir(PyObject* self, PyObject* args) { const char* dirname = 0; if (!PyArg_ParseTuple(args, "s", &dirname)) { return NULL; } // Eventually want to Py_BEGIN_ALLOW_THREADS here DIR* directory = opendir(dirname); PyObject out = PyBuildValue( ???, directory ); return out; } but I don't know what to build. (I might want to wrap it in a custom handle class or something, but I still need to know how to build the value I eventually store in an attribute of that class.) My best idea is to use an unsigned long (so "k") and add a static assertion that sizeof(long)==sizeof(void*). Is this the canonical way of doing something like this, or am I missing a better way? Evan
signature.asc
Description: OpenPGP digital signature
-- http://mail.python.org/mailman/listinfo/python-list