Skip to content

Commit 7133d91

Browse files
committed
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.
1 parent 5f47ebb commit 7133d91

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

py/obj.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags) {
410410
return false;
411411
}
412412
int ret = type->buffer_p.get_buffer(obj, bufinfo, flags);
413-
if (ret != 0 || bufinfo->buf == NULL) {
413+
if (ret != 0) {
414414
return false;
415415
}
416416
return true;

py/obj.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ typedef struct _mp_buffer_info_t {
210210
// them with ver = sizeof(struct). Cons: overkill for *micro*?
211211
//int ver; // ?
212212

213-
void *buf;
213+
void *buf; // can be NULL if len == 0
214214
mp_int_t len; // in bytes
215215
int typecode; // as per binary.h
216216

0 commit comments

Comments
 (0)