[Tutor] Need help on modifying buffer passed to python script from c

R. Alan Monroe R. Alan Monroe" <amonroe@columbus.rr.com
Sat Jun 7 10:04:01 2003


Here are the relevant parts of the c program

PyObject *themodule, *thefunc, *theresult, *thebuf;
int themem[100];
themem[0] = 26;
thebuf = PyBuffer_FromReadWriteMemory(themem, 100);
theresult = PyObject_CallFunctionObjArgs( thefunc, thebuf, NULL);

... and the python script

def render( thepointer ):
    print "python thepointer[0] ", thepointer[0]  # an arrow character
    print "python type(thepointer) ", type(thepointer)  # <type 'buffer'>
    print "python type(thepointer[0]) ", type(thepointer[0])  #  <type 'str'>
    print "python ord(thepointer[0]) ", ord(thepointer[0])  # 26, as expected
    thepointer[0] += 1   #<--- program error, can't increment a string

This is for the Sonique vis plugin I mentioned a few days ago. The
problem I'm running into is that python thinks the buffer is a big
string, but I want it to be treated as integers (it's an offscreen
ARGB buffer to be blitted to the screen). Is there a way of "tricking"
Python into seeing it as something other than 'str'?


Alan