gobj: fix Python 3 support for GVADHandle::get_(sub)data/set_(sub)data

That said, you should really be using the buffer protocol; you can create a memoryview() directly around the GeomVertexArrayData.
This commit is contained in:
rdb 2018-06-14 14:10:35 +02:00
parent d22da73a4c
commit 9231694f8f
3 changed files with 12 additions and 10 deletions

View File

@ -518,10 +518,11 @@ prepare_now(PreparedGraphicsObjects *prepared_objects,
* a string. This is primarily for the benefit of high-level languages such
* as Python.
*/
INLINE std::string GeomVertexArrayDataHandle::
INLINE vector_uchar GeomVertexArrayDataHandle::
get_data() const {
mark_used();
return std::string((const char *)_cdata->_buffer.get_read_pointer(true), _cdata->_buffer.get_size());
const unsigned char *ptr = _cdata->_buffer.get_read_pointer(true);
return vector_uchar(ptr, ptr + _cdata->_buffer.get_size());
}
/**
@ -529,12 +530,13 @@ get_data() const {
* formatted as a string. This is primarily for the benefit of high-level
* languages such as Python.
*/
INLINE std::string GeomVertexArrayDataHandle::
INLINE vector_uchar GeomVertexArrayDataHandle::
get_subdata(size_t start, size_t size) const {
mark_used();
start = std::min(start, _cdata->_buffer.get_size());
size = std::min(size, _cdata->_buffer.get_size() - start);
return std::string((const char *)_cdata->_buffer.get_read_pointer(true) + start, size);
const unsigned char *ptr = _cdata->_buffer.get_read_pointer(true) + start;
return vector_uchar(ptr, ptr + size);
}
/**

View File

@ -842,7 +842,7 @@ copy_subdata_from(size_t to_start, size_t to_size,
* Python.
*/
void GeomVertexArrayDataHandle::
set_data(const string &data) {
set_data(const vector_uchar &data) {
nassertv(_writable);
mark_used();
@ -864,7 +864,7 @@ set_data(const string &data) {
* This is primarily for the benefit of high-level languages like Python.
*/
void GeomVertexArrayDataHandle::
set_subdata(size_t start, size_t size, const string &data) {
set_subdata(size_t start, size_t size, const vector_uchar &data) {
nassertv(_writable);
mark_used();

View File

@ -316,10 +316,10 @@ PUBLISHED:
PyObject *buffer,
size_t from_start, size_t from_size));
INLINE std::string get_data() const;
void set_data(const std::string &data);
INLINE std::string get_subdata(size_t start, size_t size) const;
void set_subdata(size_t start, size_t size, const std::string &data);
INLINE vector_uchar get_data() const;
void set_data(const vector_uchar &data);
INLINE vector_uchar get_subdata(size_t start, size_t size) const;
void set_subdata(size_t start, size_t size, const vector_uchar &data);
INLINE void mark_used() const;