From cb5e679b6d04a4eec8b577189beccad5e4702328 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 10 May 2012 22:39:08 +0000 Subject: [PATCH] Add a convenience function to the API for creating a writable buffer object from a pointer and size. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@71407 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/wxpy_api.h | 7 +++++++ src/wxpybuffer.sip | 5 +---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/wxpy_api.h b/src/wxpy_api.h index 9b631ffd..d36c5b5a 100644 --- a/src/wxpy_api.h +++ b/src/wxpy_api.h @@ -95,6 +95,13 @@ inline void wxPyEndAllowThreads(PyThreadState* saved) { #define RETURN_NONE() { wxPyBLOCK_THREADS(Py_INCREF(Py_None)); return Py_None; } +inline PyObject* wxPyMakeBuffer(void* ptr, Py_ssize_t len) { + Py_buffer view; + PyBuffer_FillInfo(&view, NULL, ptr, len, 0, PyBUF_WRITABLE|PyBUF_FORMAT|PyBUF_ND); + return PyMemoryView_FromBuffer(&view); +} + + //-------------------------------------------------------------------------- // These are the API items whose implementation can not or should not be // inline functions or macros. The implementations will instead be accessed diff --git a/src/wxpybuffer.sip b/src/wxpybuffer.sip index 5039b4db..702ce1ca 100644 --- a/src/wxpybuffer.sip +++ b/src/wxpybuffer.sip @@ -37,9 +37,6 @@ // This isn't being used anywhere yet, but it should work. %ConvertFromTypeCode - Py_buffer view; - PyBuffer_FillInfo(&view, NULL, sipCpp->m_ptr, sipCpp->m_len, 0, - PyBUF_WRITABLE|PyBUF_FORMAT|PyBUF_ND); - return PyMemoryView_FromBuffer(&view); + return wxPyMakeBuffer(sipCpp->m_ptr, sipCpp->m_len); %End };