Porting c extension - PyBuffer_New() deprecated in python3. What's the replacement?

Mark Heieis mheieis at alois.ca
Sat Jan 11 00:47:01 EST 2014


Hi

I need to convert the following existing c extension code to support 
Python 3.

// --- existing code ------

     // PyBuffer_New() deprecated in python3
     if (!(pyBuf = PyBuffer_New(len)))
     {
         return NULL;
     }

     // should use memoryview object in python3
     if (PyObject_AsWriteBuffer(pyBuf, &cbuf, &len))
     {
         Py_DECREF(pyBuf);
         return NULL ;
     }

// fill in cbuf
     ...

     return pyBuf ;

//-----------

I'm somewhat confounded in finding an equivalent (PyBuffer_New()) for 
creating a buffer of size len that has continuous memory in the c 
extension function for python3. cbuf is manipulated/filled in using c, 
after which the created pyBuf is then returned. So far, I haven't found 
much in the way of examples/doc for porting the deprecated 
Python-/C-level buffer API calls to the new C-level buffer 
API/memoryview object model.

Any guidance or direction to existing doc/example is much appreciated.

TIA.







More information about the Python-list mailing list