# entry.buffer_aux.buffer_info_var.cname))
def get_release_buffer_code(entry):
- return "__Pyx_ReleaseBuffer((PyObject*)%s, &%s)" % (
+ return "__Pyx_SafeReleaseBuffer((PyObject*)%s, &%s)" % (
entry.cname,
entry.buffer_aux.buffer_info_var.cname)
if is_initialized:
# Release any existing buffer
- code.putln('__Pyx_ReleaseBuffer((PyObject*)%s, &%s);' % (
+ code.putln('__Pyx_SafeReleaseBuffer((PyObject*)%s, &%s);' % (
lhs_cname, bufstruct))
# Acquire
retcode_cname = code.funcstate.allocate_temp(PyrexTypes.c_int_type)
return 0;
}
buf->buf = NULL;
- if (PyObject_GetBuffer(obj, buf, flags) == -1) goto fail;
+ if (__Pyx_GetBuffer(obj, buf, flags) == -1) goto fail;
if (buf->ndim != nd) {
__Pyx_BufferNdimError(buf, nd);
goto fail;
find_buffer_types(env)
code = dedent("""
- #if PY_VERSION_HEX < 0x02060000
- static int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
+ #if (PY_MAJOR_VERSION < 3) && !(Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_NEWBUFFER)
+ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
""")
if len(types) > 0:
clause = "if"
code += dedent("""
}
- static void PyObject_ReleaseBuffer(PyObject *obj, Py_buffer *view) {
+ static void __Pyx_ReleaseBuffer(PyObject *obj, Py_buffer *view) {
""")
if len(types) > 0:
clause = "if"
""")
env.use_utility_code([dedent("""\
- #if PY_VERSION_HEX < 0x02060000
- static int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags);
- static void PyObject_ReleaseBuffer(PyObject *obj, Py_buffer *view);
+ #if (PY_MAJOR_VERSION < 3) && !(Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_NEWBUFFER)
+ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags);
+ static void __Pyx_ReleaseBuffer(PyObject *obj, Py_buffer *view);
+ #else
+ #define __Pyx_GetBuffer PyObject_GetBuffer
+ #define __Pyx_ReleaseBuffer PyObject_ReleaseBuffer
#endif
"""), code], codename)
# exporter.
#
acquire_utility_code = ["""\
-static INLINE void __Pyx_ReleaseBuffer(PyObject* obj, Py_buffer* info);
+static INLINE void __Pyx_SafeReleaseBuffer(PyObject* obj, Py_buffer* info);
static INLINE void __Pyx_ZeroBuffer(Py_buffer* buf); /*proto*/
static INLINE const char* __Pyx_ConsumeWhitespace(const char* ts); /*proto*/
static INLINE const char* __Pyx_BufferTypestringCheckEndian(const char* ts); /*proto*/
static void __Pyx_BufferNdimError(Py_buffer* buffer, int expected_ndim); /*proto*/
""", """
-static INLINE void __Pyx_ReleaseBuffer(PyObject* obj, Py_buffer* info) {
+static INLINE void __Pyx_SafeReleaseBuffer(PyObject* obj, Py_buffer* info) {
if (info->buf == NULL) return;
if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL;
- PyObject_ReleaseBuffer(obj, info);
+ __Pyx_ReleaseBuffer(obj, info);
}
static INLINE void __Pyx_ZeroBuffer(Py_buffer* buf) {