py: mp_buffer_info_t::buf may be valid, but NULL for empty objects.
This happens for example for zero-size arrays. As .get_buffer() method now has explicit return value, it's enough to distinguish success vs failure of getting buffer.
This commit is contained in:
parent
5f47ebbf82
commit
7133d91773
2
py/obj.c
2
py/obj.c
|
@ -410,7 +410,7 @@ bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int ret = type->buffer_p.get_buffer(obj, bufinfo, flags);
|
int ret = type->buffer_p.get_buffer(obj, bufinfo, flags);
|
||||||
if (ret != 0 || bufinfo->buf == NULL) {
|
if (ret != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
2
py/obj.h
2
py/obj.h
|
@ -210,7 +210,7 @@ typedef struct _mp_buffer_info_t {
|
||||||
// them with ver = sizeof(struct). Cons: overkill for *micro*?
|
// them with ver = sizeof(struct). Cons: overkill for *micro*?
|
||||||
//int ver; // ?
|
//int ver; // ?
|
||||||
|
|
||||||
void *buf;
|
void *buf; // can be NULL if len == 0
|
||||||
mp_int_t len; // in bytes
|
mp_int_t len; // in bytes
|
||||||
int typecode; // as per binary.h
|
int typecode; // as per binary.h
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue