From 357a350837a858f7808f4ab9b9b04ee9a6c1052d Mon Sep 17 00:00:00 2001 From: jeremyd2019 Date: Thu, 2 Jul 2020 15:09:54 -0700 Subject: [PATCH 1/2] Try both old and new buffer protocols on python2.7 While some objects on 2.7 might only implement the old buffer protocol, some (notably memoryview) only implement the new buffer protocol, so both need to be tried. --- src/wxpybuffer.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wxpybuffer.h b/src/wxpybuffer.h index 80d5e5ca..501ca9bc 100644 --- a/src/wxpybuffer.h +++ b/src/wxpybuffer.h @@ -31,8 +31,9 @@ public: #if PY_MAJOR_VERSION < 3 // Old buffer protocol int rv = PyObject_AsReadBuffer(obj, (const void**)&m_ptr, &m_len); - return rv != -1; - #else + if (rv != -1) + return true; + #endif // New buffer protocol Py_buffer view; if (PyObject_GetBuffer(obj, &view, PyBUF_SIMPLE) != 0) @@ -41,7 +42,6 @@ public: m_len = view.len; PyBuffer_Release(&view); return true; - #endif } From 4a292c3cda337587d2269171fc0484e33f23681f Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Thu, 2 Jul 2020 22:38:36 -0700 Subject: [PATCH 2/2] Revert "pywxrc: fix embedded resources in python 2.7 and 3" This reverts commit 234491058fc5a59084b6054d640ecfc17d3d35c1 now that memoryview works properly on python 2.7. --- wx/tools/pywxrc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wx/tools/pywxrc.py b/wx/tools/pywxrc.py index 649c0e7c..32c1c8a6 100644 --- a/wx/tools/pywxrc.py +++ b/wx/tools/pywxrc.py @@ -226,7 +226,7 @@ def __init_resources(): """ ADD_FILE_TO_MEMFS = """\ - wx.MemoryFSHandler.AddFile('XRC/%(memoryPath)s/%(filename)s', bytearray(%(filename)s)) + wx.MemoryFSHandler.AddFile('XRC/%(memoryPath)s/%(filename)s', memoryview(%(filename)s)) """ LOAD_RES_MEMFS = """\