int size = %2;
if (size < 0)
size = %1.size();
%CPPSELF.allocate((const void*) %1.data(), size);
Py_ssize_t dataSize = %CPPSELF.size();
void* data = %CPPSELF.map(%1);
if (!data) {
Py_INCREF(Py_None);
%PYARG_0 = Py_None;
} else if (%1 == QGLBuffer::ReadOnly) {
%PYARG_0 = PyBuffer_FromMemory(data, dataSize);
} else {
%PYARG_0 = PyBuffer_FromReadWriteMemory(data, dataSize);
}
char *data = new char[%3];
bool result = %CPPSELF.read(%1, data, %3);
QByteArray ret;
if (result)
ret.append((const char*)data, %3);
%PYARG_0 = Shiboken::makeTuple(result, ret);
delete[] data;
int size = %3;
if (size < 0)
size = %2.size();
%CPPSELF.write(%1, (const void*) %2.data(), size);