Btrieve/C-extension question
Paul Simmonds
psimmo60 at hotmail.com
Fri Jun 20 05:24:28 EDT 2003
"vincent wehren" <v.wehren at home.nl> wrote in message news:<bcslog$70p$1 at news4.tilbu1.nb.home.nl>...
> "Paul Simmonds" <psimmo60 at hotmail.com> schrieb im Newsbeitrag
> news:94974e1a.0306190653.3a829cb6 at posting.google.com...
> > "vincent wehren" <v.wehren at home.nl> wrote in message
> news:<bcrua6$120$1 at news4.tilbu1.nb.home.nl>...
> > <Problem description snipped>
> > > Is it sensible to pass such a block of memory to Python and back?
> > > 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).
> >
> > I think you need a PyCObject.
>
> Thanks
> Yes, that was my guess too...
> So I did someting along the lines of:
>
> pos = PyCObject_FromVoidPtr(pos_blk; NULL) ;
> return Py_BuildValue("N", pos);
>
> Passing is back in where I was getting trouble:
> ( passed back in via PyArg_ParseTuple(args, "O", pos) )
> pos_blk = PyCObjectAsVoidPtr(pos);
> doesn't seem to work...
>
> I think I need to check to C side of things once more.
> Maybe there's some other Btrieve mystery that needs unravelling!
It looks like there might be a simpler problem. If you have declared
pos as a pointer to a PyObject, ParseTuple takes the addresses of the
pointers.
For example (untested):
PyObject *VoidPtr_ParseMe(PyObject *self, PyObject *args)
{ int flag;
PyObject *file;
if(!PyArg_ParseTuple(args,"Oi",&file,&flag)) return NULL;
/* This could be your problem /\
* Then this should work...*/
your_function(PyCObject_AsVoidPtr(file), flag);
etc...
}
Of course, if the mistake in your ParseTuple line was just a typo,
maybe you should take a look at exactly what gets put into the
CObject.
HTH,
Paul
>
> Vincent Wehren
>
More information about the Python-list
mailing list