|
@@ -80,11 +80,7 @@ INLINE void set_matrix_view(Py_buffer &view, int flags, int length, int size, bo
|
|
|
template<class Element>
|
|
template<class Element>
|
|
|
INLINE void Extension<PointerToArray<Element> >::
|
|
INLINE void Extension<PointerToArray<Element> >::
|
|
|
__init__(PyObject *self, PyObject *source) {
|
|
__init__(PyObject *self, PyObject *source) {
|
|
|
-#if PY_VERSION_HEX >= 0x02060000
|
|
|
|
|
if (PyObject_CheckBuffer(source)) {
|
|
if (PyObject_CheckBuffer(source)) {
|
|
|
-#else
|
|
|
|
|
- if (PyString_CheckExact(source)) {
|
|
|
|
|
-#endif
|
|
|
|
|
// It's a byte sequence, or any object that exports the buffer protocol.
|
|
// It's a byte sequence, or any object that exports the buffer protocol.
|
|
|
this->set_data(source);
|
|
this->set_data(source);
|
|
|
return;
|
|
return;
|
|
@@ -158,11 +154,7 @@ __setitem__(size_t n, const Element &value) {
|
|
|
template<class Element>
|
|
template<class Element>
|
|
|
INLINE PyObject *Extension<PointerToArray<Element> >::
|
|
INLINE PyObject *Extension<PointerToArray<Element> >::
|
|
|
get_data() const {
|
|
get_data() const {
|
|
|
-#if PY_MAJOR_VERSION >= 3
|
|
|
|
|
return PyBytes_FromStringAndSize((char *)this->_this->p(), sizeof(Element) * this->_this->size());
|
|
return PyBytes_FromStringAndSize((char *)this->_this->p(), sizeof(Element) * this->_this->size());
|
|
|
-#else
|
|
|
|
|
- return PyString_FromStringAndSize((char *)this->_this->p(), sizeof(Element) * this->_this->size());
|
|
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -175,7 +167,6 @@ get_data() const {
|
|
|
template<class Element>
|
|
template<class Element>
|
|
|
INLINE void Extension<PointerToArray<Element> >::
|
|
INLINE void Extension<PointerToArray<Element> >::
|
|
|
set_data(PyObject *data) {
|
|
set_data(PyObject *data) {
|
|
|
-#if PY_VERSION_HEX >= 0x02060000
|
|
|
|
|
if (PyObject_CheckBuffer(data)) {
|
|
if (PyObject_CheckBuffer(data)) {
|
|
|
// User passed a buffer object.
|
|
// User passed a buffer object.
|
|
|
Py_buffer view;
|
|
Py_buffer view;
|
|
@@ -208,33 +199,6 @@ set_data(PyObject *data) {
|
|
|
PyBuffer_Release(&view);
|
|
PyBuffer_Release(&view);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
- // In Python 2, there was also an older buffer protocol, supported by eg.
|
|
|
|
|
- // str and array objects.
|
|
|
|
|
-#if PY_MAJOR_VERSION < 3
|
|
|
|
|
- // The old, deprecated buffer interface, as used by eg. the array module.
|
|
|
|
|
- const void *buffer;
|
|
|
|
|
- Py_ssize_t buffer_len;
|
|
|
|
|
- if (!PyUnicode_CheckExact(data) &&
|
|
|
|
|
- PyObject_AsReadBuffer(data, &buffer, &buffer_len) == 0) {
|
|
|
|
|
- if (buffer_len % sizeof(Element) != 0) {
|
|
|
|
|
- PyErr_Format(PyExc_ValueError,
|
|
|
|
|
- "byte buffer is not a multiple of %zu bytes",
|
|
|
|
|
- sizeof(Element));
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (buffer_len > 0) {
|
|
|
|
|
- this->_this->resize(buffer_len / sizeof(Element));
|
|
|
|
|
- memcpy(this->_this->p(), buffer, buffer_len);
|
|
|
|
|
- } else {
|
|
|
|
|
- this->_this->clear();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-#endif
|
|
|
|
|
|
|
|
|
|
Dtool_Raise_TypeError("PointerToArray.set_data() requires a buffer object");
|
|
Dtool_Raise_TypeError("PointerToArray.set_data() requires a buffer object");
|
|
|
}
|
|
}
|
|
@@ -252,11 +216,7 @@ get_subdata(size_t n, size_t count) const {
|
|
|
n = std::min(n, this->_this->size());
|
|
n = std::min(n, this->_this->size());
|
|
|
count = std::max(count, n);
|
|
count = std::max(count, n);
|
|
|
count = std::min(count, this->_this->size() - n);
|
|
count = std::min(count, this->_this->size() - n);
|
|
|
-#if PY_MAJOR_VERSION >= 3
|
|
|
|
|
return PyBytes_FromStringAndSize((char *)(this->_this->p() + n), sizeof(Element) * count);
|
|
return PyBytes_FromStringAndSize((char *)(this->_this->p() + n), sizeof(Element) * count);
|
|
|
-#else
|
|
|
|
|
- return PyString_FromStringAndSize((char *)(this->_this->p() + n), sizeof(Element) * count);
|
|
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -277,11 +237,7 @@ __getitem__(size_t n) const {
|
|
|
template<class Element>
|
|
template<class Element>
|
|
|
INLINE PyObject *Extension<ConstPointerToArray<Element> >::
|
|
INLINE PyObject *Extension<ConstPointerToArray<Element> >::
|
|
|
get_data() const {
|
|
get_data() const {
|
|
|
-#if PY_MAJOR_VERSION >= 3
|
|
|
|
|
return PyBytes_FromStringAndSize((char *)this->_this->p(), sizeof(Element) * this->_this->size());
|
|
return PyBytes_FromStringAndSize((char *)this->_this->p(), sizeof(Element) * this->_this->size());
|
|
|
-#else
|
|
|
|
|
- return PyString_FromStringAndSize((char *)this->_this->p(), sizeof(Element) * this->_this->size());
|
|
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -297,11 +253,7 @@ get_subdata(size_t n, size_t count) const {
|
|
|
n = std::min(n, this->_this->size());
|
|
n = std::min(n, this->_this->size());
|
|
|
count = std::max(count, n);
|
|
count = std::max(count, n);
|
|
|
count = std::min(count, this->_this->size() - n);
|
|
count = std::min(count, this->_this->size() - n);
|
|
|
-#if PY_MAJOR_VERSION >= 3
|
|
|
|
|
return PyBytes_FromStringAndSize((char *)(this->_this->p() + n), sizeof(Element) * count);
|
|
return PyBytes_FromStringAndSize((char *)(this->_this->p() + n), sizeof(Element) * count);
|
|
|
-#else
|
|
|
|
|
- return PyString_FromStringAndSize((char *)(this->_this->p() + n), sizeof(Element) * count);
|
|
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -311,7 +263,6 @@ get_subdata(size_t n, size_t count) const {
|
|
|
template<class Element>
|
|
template<class Element>
|
|
|
INLINE int Extension<PointerToArray<Element> >::
|
|
INLINE int Extension<PointerToArray<Element> >::
|
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
|
-#if PY_VERSION_HEX >= 0x02060000
|
|
|
|
|
const char *format = get_format_code(Element);
|
|
const char *format = get_format_code(Element);
|
|
|
if (format == nullptr) {
|
|
if (format == nullptr) {
|
|
|
// Not supported.
|
|
// Not supported.
|
|
@@ -350,9 +301,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
|
view->internal = (void*) this->_this;
|
|
view->internal = (void*) this->_this;
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
-#else
|
|
|
|
|
- return -1;
|
|
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -362,7 +310,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
|
template<>
|
|
template<>
|
|
|
INLINE int Extension<PointerToArray<LMatrix3f> >::
|
|
INLINE int Extension<PointerToArray<LMatrix3f> >::
|
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
|
-#if PY_VERSION_HEX >= 0x02060000
|
|
|
|
|
if (self != nullptr) {
|
|
if (self != nullptr) {
|
|
|
Py_INCREF(self);
|
|
Py_INCREF(self);
|
|
|
}
|
|
}
|
|
@@ -376,9 +323,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
|
view->internal = (void*) this->_this;
|
|
view->internal = (void*) this->_this;
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
-#else
|
|
|
|
|
- return -1;
|
|
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -388,7 +332,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
|
template<>
|
|
template<>
|
|
|
INLINE int Extension<PointerToArray<LMatrix3d> >::
|
|
INLINE int Extension<PointerToArray<LMatrix3d> >::
|
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
|
-#if PY_VERSION_HEX >= 0x02060000
|
|
|
|
|
if (self != nullptr) {
|
|
if (self != nullptr) {
|
|
|
Py_INCREF(self);
|
|
Py_INCREF(self);
|
|
|
}
|
|
}
|
|
@@ -402,9 +345,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
|
view->internal = (void*) this->_this;
|
|
view->internal = (void*) this->_this;
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
-#else
|
|
|
|
|
- return -1;
|
|
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -414,7 +354,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
|
template<>
|
|
template<>
|
|
|
INLINE int Extension<PointerToArray<UnalignedLMatrix4f> >::
|
|
INLINE int Extension<PointerToArray<UnalignedLMatrix4f> >::
|
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
|
-#if PY_VERSION_HEX >= 0x02060000
|
|
|
|
|
if (self != nullptr) {
|
|
if (self != nullptr) {
|
|
|
Py_INCREF(self);
|
|
Py_INCREF(self);
|
|
|
}
|
|
}
|
|
@@ -428,9 +367,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
|
view->internal = (void*) this->_this;
|
|
view->internal = (void*) this->_this;
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
-#else
|
|
|
|
|
- return -1;
|
|
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -440,7 +376,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
|
template<>
|
|
template<>
|
|
|
INLINE int Extension<PointerToArray<UnalignedLMatrix4d> >::
|
|
INLINE int Extension<PointerToArray<UnalignedLMatrix4d> >::
|
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
|
-#if PY_VERSION_HEX >= 0x02060000
|
|
|
|
|
if (self != nullptr) {
|
|
if (self != nullptr) {
|
|
|
Py_INCREF(self);
|
|
Py_INCREF(self);
|
|
|
}
|
|
}
|
|
@@ -454,9 +389,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
|
view->internal = (void*) this->_this;
|
|
view->internal = (void*) this->_this;
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
-#else
|
|
|
|
|
- return -1;
|
|
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -465,14 +397,12 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) {
|
|
|
template<class Element>
|
|
template<class Element>
|
|
|
INLINE void Extension<PointerToArray<Element> >::
|
|
INLINE void Extension<PointerToArray<Element> >::
|
|
|
__releasebuffer__(PyObject *self, Py_buffer *view) const {
|
|
__releasebuffer__(PyObject *self, Py_buffer *view) const {
|
|
|
-#if PY_VERSION_HEX >= 0x02060000
|
|
|
|
|
// Note: PyBuffer_Release automatically decrements view->obj.
|
|
// Note: PyBuffer_Release automatically decrements view->obj.
|
|
|
if (view->internal != nullptr) {
|
|
if (view->internal != nullptr) {
|
|
|
// Oh, right, let's not forget to unref this.
|
|
// Oh, right, let's not forget to unref this.
|
|
|
unref_delete((const PointerToArray<Element> *)view->internal);
|
|
unref_delete((const PointerToArray<Element> *)view->internal);
|
|
|
view->internal = nullptr;
|
|
view->internal = nullptr;
|
|
|
}
|
|
}
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -482,7 +412,6 @@ __releasebuffer__(PyObject *self, Py_buffer *view) const {
|
|
|
template<class Element>
|
|
template<class Element>
|
|
|
INLINE int Extension<ConstPointerToArray<Element> >::
|
|
INLINE int Extension<ConstPointerToArray<Element> >::
|
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
|
-#if PY_VERSION_HEX >= 0x02060000
|
|
|
|
|
if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) {
|
|
if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) {
|
|
|
PyErr_SetString(PyExc_BufferError,
|
|
PyErr_SetString(PyExc_BufferError,
|
|
|
"Object is not writable.");
|
|
"Object is not writable.");
|
|
@@ -527,9 +456,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
|
view->internal = (void*) this->_this;
|
|
view->internal = (void*) this->_this;
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
-#else
|
|
|
|
|
- return -1;
|
|
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -538,7 +464,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
|
template<>
|
|
template<>
|
|
|
INLINE int Extension<ConstPointerToArray<LMatrix3f> >::
|
|
INLINE int Extension<ConstPointerToArray<LMatrix3f> >::
|
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
|
-#if PY_VERSION_HEX >= 0x02060000
|
|
|
|
|
if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) {
|
|
if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) {
|
|
|
PyErr_SetString(PyExc_BufferError,
|
|
PyErr_SetString(PyExc_BufferError,
|
|
|
"Object is not writable.");
|
|
"Object is not writable.");
|
|
@@ -557,9 +482,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
|
view->internal = (void*) this->_this;
|
|
view->internal = (void*) this->_this;
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
-#else
|
|
|
|
|
- return -1;
|
|
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -568,7 +490,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
|
template<>
|
|
template<>
|
|
|
INLINE int Extension<ConstPointerToArray<LMatrix3d> >::
|
|
INLINE int Extension<ConstPointerToArray<LMatrix3d> >::
|
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
|
-#if PY_VERSION_HEX >= 0x02060000
|
|
|
|
|
if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) {
|
|
if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) {
|
|
|
PyErr_SetString(PyExc_BufferError,
|
|
PyErr_SetString(PyExc_BufferError,
|
|
|
"Object is not writable.");
|
|
"Object is not writable.");
|
|
@@ -587,9 +508,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
|
view->internal = (void*) this->_this;
|
|
view->internal = (void*) this->_this;
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
-#else
|
|
|
|
|
- return -1;
|
|
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -598,7 +516,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
|
template<>
|
|
template<>
|
|
|
INLINE int Extension<ConstPointerToArray<UnalignedLMatrix4f> >::
|
|
INLINE int Extension<ConstPointerToArray<UnalignedLMatrix4f> >::
|
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
|
-#if PY_VERSION_HEX >= 0x02060000
|
|
|
|
|
if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) {
|
|
if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) {
|
|
|
PyErr_SetString(PyExc_BufferError,
|
|
PyErr_SetString(PyExc_BufferError,
|
|
|
"Object is not writable.");
|
|
"Object is not writable.");
|
|
@@ -617,9 +534,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
|
view->internal = (void*) this->_this;
|
|
view->internal = (void*) this->_this;
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
-#else
|
|
|
|
|
- return -1;
|
|
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -628,7 +542,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
|
template<>
|
|
template<>
|
|
|
INLINE int Extension<ConstPointerToArray<UnalignedLMatrix4d> >::
|
|
INLINE int Extension<ConstPointerToArray<UnalignedLMatrix4d> >::
|
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
__getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
|
-#if PY_VERSION_HEX >= 0x02060000
|
|
|
|
|
if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) {
|
|
if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) {
|
|
|
PyErr_SetString(PyExc_BufferError,
|
|
PyErr_SetString(PyExc_BufferError,
|
|
|
"Object is not writable.");
|
|
"Object is not writable.");
|
|
@@ -647,9 +560,6 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
|
view->internal = (void*) this->_this;
|
|
view->internal = (void*) this->_this;
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
-#else
|
|
|
|
|
- return -1;
|
|
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -658,12 +568,10 @@ __getbuffer__(PyObject *self, Py_buffer *view, int flags) const {
|
|
|
template<class Element>
|
|
template<class Element>
|
|
|
INLINE void Extension<ConstPointerToArray<Element> >::
|
|
INLINE void Extension<ConstPointerToArray<Element> >::
|
|
|
__releasebuffer__(PyObject *self, Py_buffer *view) const {
|
|
__releasebuffer__(PyObject *self, Py_buffer *view) const {
|
|
|
-#if PY_VERSION_HEX >= 0x02060000
|
|
|
|
|
// Note: PyBuffer_Release automatically decrements obj->view.
|
|
// Note: PyBuffer_Release automatically decrements obj->view.
|
|
|
if (view->internal != nullptr) {
|
|
if (view->internal != nullptr) {
|
|
|
// Oh, right, let's not forget to unref this.
|
|
// Oh, right, let's not forget to unref this.
|
|
|
unref_delete((const PointerToArray<Element> *)view->internal);
|
|
unref_delete((const PointerToArray<Element> *)view->internal);
|
|
|
view->internal = nullptr;
|
|
view->internal = nullptr;
|
|
|
}
|
|
}
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|