help with c <-> python buffer transfer

tkirke at gmail.com tkirke at gmail.com
Fri Aug 11 18:31:51 EDT 2006


How does one transfer a buffer object from python -> c and back again
(assuming the data gets modified)?
I can't seem to get this or anything else to work, but am clueless as
to what I'm doing wrong


using namespace boost::python;

static PyObject * proc_buf(PyObject *self, PyObject *args) {
    PyObject *resultobj;
    char* output_samples;
    int len;
    if (!PyArg_ParseTuple(args,"s#|l",&output_samples, &len)) {
	  return NULL;  /* wrong arguments provided */
    }
    for (int i=0;i<len;i++) {
	 output_samples[i]  *= 2; // for example
   }
   resultobj = PyString_FromStringAndSize(output_samples, len);
   return resultobj;
}


This compiles ok, but when in python I do

buf = proc_buf( bufx, len(bufx)
len(buf) 

I get 
len() of unsized object

Thanks




More information about the Python-list mailing list