Dear binding developers or people interested in embed PySide or Shiboken related bindings into C++ applications.
The next version of Shiboken will include a set of functions to deal with
various kind of buffer API's found in Python, we are doing this to ease write
of buffer related code and a future Python3 port, so if you are writing some
code that uses Python buffers (or memory views) is recommended to use this
interface instead of the one found in Python.
The interface is minimalist and was created to deal only with contiguous
memory buffers, as the use case for non contiguous memory buffers in the
bindings world is a bit rare if not nonexistent.
Any C++ functions expecting pointers to memory buffers, etc are candidates to
use the buffer API, you just need to replace the argument type from
void*/char*/whatever to "PyBuffer" and write some inject code using the
Shiboken buffer API.
Unfortunately an automatic way to write these inject code isn't possible as
each function have different semantics, some of them needs the buffer size,
some not, etc...
** BEHAVIOR CHANGE **
If a function used to return a buffer object on previous versions of PySide it
will now return a memoryview if PySide was compiled for Python 2.7.
If a function accepts a buffer as argument on previous versions of PySide it
will now accept both, buffer or memoryview objects if PySide was compiled with
Python 2.7.
I'm afraid that this can break any existent code running on Python 2.7, so I
would like to hear some opinions regarding to this.
The C++ interface may change before the next Shiboken release but I guess it
wont.... anyway the current code can be viewed bellow.
namespace Shiboken
{
namespace Buffer
{
enum Type {
ReadOnly,
WriteOnly,
ReadWrite
};
/**
* Creates a new Python buffer pointing to a contiguous memory block at
* \p memory of size \p size.
*/
LIBSHIBOKEN_API PyObject* newObject(void* memory, Py_ssize_t size, Type
type);
/**
* Creates a new <b>read only</b> Python buffer pointing to a contiguous
memory block at
* \p memory of size \p size.
*/
LIBSHIBOKEN_API PyObject* newObject(const void* memory, Py_ssize_t size);
/**
* Check if is ok to use \p pyObj as argument in all function under
Shiboken::Buffer namespace.
*/
LIBSHIBOKEN_API bool checkType(PyObject* pyObj);
/**
* Returns a pointer to the memory pointed by the buffer \p pyObj, \p size
is filled with the buffer
* size if not null.
*
* If the \p pyObj is a non-contiguous buffer a Python error is set.
*/
LIBSHIBOKEN_API void* getPointer(PyObject* pyObj, Py_ssize_t* size = 0);
} // namespace Buffer
} // namespace Shiboken
--
Hugo Parente Lima
INdT - Instituto Nokia de Tecnologia
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ PySide mailing list [email protected] http://lists.pyside.org/listinfo/pyside
