Skip to content

Commit c695f8b

Browse files
committed
remove some unneeded diffs
1 parent a069dc9 commit c695f8b

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

py/obj.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -685,18 +685,12 @@ mp_obj_t mp_obj_generic_subscript_getiter(mp_obj_t obj, mp_obj_iter_buf_t *iter_
685685

686686
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
687687
const mp_obj_type_t *type = mp_obj_get_type(obj);
688-
if (!MP_OBJ_TYPE_HAS_SLOT(type, buffer)) {
689-
return false;
688+
if (MP_OBJ_TYPE_HAS_SLOT(type, buffer)
689+
&& MP_OBJ_TYPE_GET_SLOT(type, buffer)(obj, bufinfo, flags & MP_BUFFER_RW) == 0) {
690+
return true;
690691
}
691-
int ret = MP_OBJ_TYPE_GET_SLOT(type, buffer)(obj, bufinfo, flags);
692-
if (ret != 0) {
693-
return false;
694-
}
695-
return true;
696-
}
697-
698-
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
699-
if (!mp_get_buffer(obj, bufinfo, flags)) {
692+
if (flags & MP_BUFFER_RAISE_IF_UNSUPPORTED) {
700693
mp_raise_TypeError(MP_ERROR_TEXT("object with buffer protocol required"));
701694
}
695+
return false;
702696
}

py/obj.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,17 +614,25 @@ typedef struct _mp_getiter_iternext_custom_t {
614614
} mp_getiter_iternext_custom_t;
615615

616616
// Buffer protocol
617+
617618
typedef struct _mp_buffer_info_t {
618619
void *buf; // can be NULL if len == 0
619620
size_t len; // in bytes
620621
int typecode; // as per binary.h
621622
} mp_buffer_info_t;
623+
622624
#define MP_BUFFER_READ (1)
623625
#define MP_BUFFER_WRITE (2)
624626
#define MP_BUFFER_RW (MP_BUFFER_READ | MP_BUFFER_WRITE)
627+
#define MP_BUFFER_RAISE_IF_UNSUPPORTED (4)
628+
625629
typedef mp_int_t (*mp_buffer_fun_t)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
630+
626631
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
627-
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
632+
633+
static inline void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
634+
mp_get_buffer(obj, bufinfo, flags | MP_BUFFER_RAISE_IF_UNSUPPORTED);
635+
}
628636

629637
// This struct will be updated to become a variable sized struct. In order to
630638
// use this as a member, or allocate dynamically, use the mp_obj_empty_type_t
@@ -1033,13 +1041,11 @@ mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args,
10331041
#define mp_obj_new_exception_msg(exc_type, msg) mp_obj_new_exception(exc_type)
10341042
#define mp_obj_new_exception_msg_varg(exc_type, ...) mp_obj_new_exception(exc_type)
10351043
#else
1036-
// CIRCUITPY-CHANGE
10371044
mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, mp_rom_error_text_t msg);
1038-
mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, ...); // counts args by number of % symbols in fmt, excluding %%; can only handle void* sizes (ie no float/double!)
1045+
mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, ...); // counts args by number of % symbols in fmt, excluding %%; can only handle void* sizes (ie no float/double!)
10391046
#endif
10401047
#ifdef va_start
1041-
// CIRCUITPY-CHANGE
1042-
mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, va_list arg); // same fmt restrictions as above
1048+
mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, va_list arg); // same fmt restrictions as above
10431049
#endif
10441050
mp_obj_t mp_obj_new_gen_wrap(mp_obj_t fun);
10451051
mp_obj_t mp_obj_new_closure(mp_obj_t fun, size_t n_closed, const mp_obj_t *closed);

0 commit comments

Comments
 (0)