From 87aa66f09c01c3b3b28c0096becdb66e9f7c489a Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 29 Oct 2013 10:36:16 +0000 Subject: [PATCH] Py_buffer is not available in Python versions before 2.6 --- panda/src/express/pointerToArray.I | 7 ++++--- panda/src/express/pointerToArray.h | 2 ++ panda/src/express/virtualFileMountAndroidAsset.cxx | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/panda/src/express/pointerToArray.I b/panda/src/express/pointerToArray.I index d072311031..152276d1ff 100644 --- a/panda/src/express/pointerToArray.I +++ b/panda/src/express/pointerToArray.I @@ -96,6 +96,7 @@ PointerToArray(PyObject *self, PyObject *source) : // self in the constructor--the caller can't initialize this for us. ((Dtool_PyInstDef *)self)->_ptr_to_object = this; +#if PY_VERSION_HEX >= 0x02060000 if (PyObject_CheckBuffer(source)) { // User passed a buffer object. Py_buffer view; @@ -119,6 +120,7 @@ PointerToArray(PyObject *self, PyObject *source) : PyBuffer_Release(&view); return; } +#endif if (!PySequence_Check(source)) { // If passed with a non-sequence, this isn't the right constructor. @@ -1330,6 +1332,7 @@ clear() { } #ifdef HAVE_PYTHON +#if PY_VERSION_HEX >= 0x02060000 //////////////////////////////////////////////////////////////////// // Function: PointerToArray::__getbuffer__ // Access: Published @@ -1342,7 +1345,6 @@ INLINE int PointerToArray:: __getbuffer__(PyObject *self, Py_buffer *view, int flags) { const char *format = get_format_code(Element); - cerr << "non-const __getbuffer__ with fmt " << format << "\n"; if (format == NULL) { // Not supported. return -1; @@ -1411,14 +1413,12 @@ INLINE int ConstPointerToArray:: __getbuffer__(PyObject *self, Py_buffer *view, int flags) const { if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) { - cerr << "writable buffer requested of const array\n"; PyErr_SetString(PyExc_BufferError, "Object is not writable."); return -1; } const char *format = get_format_code(Element); - cerr << "const __getbuffer__ with fmt " << format << "\n"; if (format == NULL) { // Not supported. return -1; @@ -1474,6 +1474,7 @@ __releasebuffer__(PyObject *self, Py_buffer *view) const { view->internal = NULL; } } +#endif // PY_VERSION_HEX #endif // HAVE_PYTHON #endif // CPPPARSER diff --git a/panda/src/express/pointerToArray.h b/panda/src/express/pointerToArray.h index 1472f9d975..822d1d8902 100644 --- a/panda/src/express/pointerToArray.h +++ b/panda/src/express/pointerToArray.h @@ -131,9 +131,11 @@ PUBLISHED: INLINE int get_node_ref_count() const; #ifdef HAVE_PYTHON +#if PY_VERSION_HEX >= 0x02060000 int __getbuffer__(PyObject *self, Py_buffer *view, int flags); void __releasebuffer__(PyObject *self, Py_buffer *view) const; #endif +#endif #else // CPPPARSER // This is the actual, complete interface. diff --git a/panda/src/express/virtualFileMountAndroidAsset.cxx b/panda/src/express/virtualFileMountAndroidAsset.cxx index 8cb8dfa82d..e2b9858f4a 100644 --- a/panda/src/express/virtualFileMountAndroidAsset.cxx +++ b/panda/src/express/virtualFileMountAndroidAsset.cxx @@ -129,6 +129,7 @@ read_file(const Filename &file, bool do_uncompress, if (asset == (AAsset *)NULL) { express_cat.info() << "Unable to read " << file << "\n"; + return false; } // Reserve enough space to hold the entire file. @@ -251,7 +252,7 @@ get_system_info(const Filename &file, SubfileInfo &info) { // We don't actually need the file descriptor, so close it. close(fd); - info = SubfileInfo(_apk_path, start, length); + info = SubfileInfo(_apk_path, start, length); return true; }