Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#36 typemap support for python buffer objects

v2.0
open
nobody
GL (10)
5
2006-01-24
2006-01-24
J Robert Ray
No

This is a patch for the void* typemap that adds support
for using python buffer objects.

It allows passing a pointer wrapped in python with
PyBuffer_FromMemory() to glTexImage2D et. al.

The patch also makes the typemap more strict in that it
will only take a buffer- or string-like object.

The old code would construct a temporary string
PyObject and return a pointer to the internal storage
of that PyObject.

But because it use Py_DECREF() immediately on the
temporary string object, the storage may be immediately
freed by python.

In the common case of passing a string object in, the
new temporary object would share the storage of the
string object and the memory would not be freed.

But some other object may be passed in that causes the
temporary string object to allocate its own copy (e.g.
an instance with __str__ method), the old typemap would
in this case end up with an invalid pointer.

The patch uses PyString_Check() to ensure that the
object passed in is a string-like object, and avoids
using a temporary PyObject.

Note: it could be possible to arrange for the old code
to work correctly by removing the Py_DECREF and using
SWIG's 'freearg' typemap functionality to clean up the
temporary PyObject.

This patch is against 2.0.1.09. I have visually
compared the same file in 2.0.2.01 and the typemap is
unchanged so this patch should apply there too.

Discussion

  • J Robert Ray
    J Robert Ray
    2006-01-24

    typemap buffer object patch

     
    Attachments