Btrieve/C-extension question

Fredrik Lundh fredrik at
Thu Jun 19 11:26:57 CEST 2003

vincent wehren <v.wehren at> wrote:

> Btrieve keeps track of file positions using a so-called position block.
> This is a 128-byte block of memory (e.g. UBYTE pos_blk[128]).

> Is it sensible to pass such a block of memory to Python and back?

why not?

> If so, what is the best way to go about this, I.O.W, how do I pass such a
> block of memory to Python and back (unchanged).

the "correct" approach would be to create a custom type, representing
the btrieve file, and store the position block in the object instance.

a much easier approach is to put the position block in a Python string,
and pass it around:

PyObject* getblock(PyObject* self, PyObject* args)

    return PyString_FromStringAndSize(blockptr, sizeof(block));

PyObject* useblock(PyObject* self, PyObject* args)
    some* blockptr;
    int blocksize;
    if (!PyArg_ParseTuple("s#", &blockptr, &blocksize))
        return NULL;

    assert(blocksize == sizeof(block)); /* to be on the safe side */



More information about the Python-list mailing list