@@ -6,6 +6,12 @@ AND call SWIG_fail at the same time, because it will result in a double free.
66
77*/
88
9+ %inline %{
10+
11+ #include " ../bindings/python/python-typemaps.h"
12+
13+ %}
14+
915%typemap(in) char ** {
1016 /* Check if is a list */
1117 if (PythonList::Check ($input)) {
@@ -628,21 +634,12 @@ template <> bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
628634 }
629635}
630636
631- #if SWIG_VERSION < 0x040100
632- // The two pybuffer macros below are copied out of swig/Lib/python/pybuffer.i,
637+ // These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i,
633638// and fixed so they will not crash if PyObject_GetBuffer fails.
634639// https://github.com/swig/swig/issues/1640
635-
636- struct Py_buffer_RAII {
637- Py_buffer buffer = {};
638- Py_buffer_RAII (){};
639- Py_buffer &operator =(const Py_buffer_RAII &) = delete ;
640- Py_buffer_RAII (const Py_buffer_RAII &) = delete ;
641- ~Py_buffer_RAII () {
642- if (buffer.obj )
643- PyBuffer_Release (&buffer);
644- }
645- };
640+ //
641+ // I've also moved the call to PyBuffer_Release to the end of the SWIG wrapper,
642+ // doing it right away is not legal according to the python buffer protocol.
646643
647644%define %pybuffer_mutable_binary(TYPEMAP, SIZE)
648645%typemap(in) (TYPEMAP, SIZE) (Py_buffer_RAII view) {
@@ -677,9 +674,6 @@ struct Py_buffer_RAII {
677674 $2 = ($2_ltype)(size / sizeof ($*1_type));
678675}
679676%enddef
680- #else
681- %include <pybuffer.i>
682- #endif
683677
684678%pybuffer_binary(const uint8_t *buf, size_t num_bytes);
685679%pybuffer_mutable_binary(uint8_t *buf, size_t num_bytes);
0 commit comments