Skip to content

Commit 26ae1c7

Browse files
committed
Move & comment the field access macros
1 parent 44a3da5 commit 26ae1c7

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

py/obj.h

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -565,41 +565,33 @@ void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flag
565565

566566
struct _mp_obj_type_ext {
567567
// Corresponds to __call__ special method, ie T(...).
568-
#define MP_TYPE_CALL ext[0].call
569568
mp_call_fun_t call;
570569

571570
// Implements unary and binary operations.
572571
// Can return MP_OBJ_NULL if the operation is not supported.
573-
#define MP_TYPE_UNARY_OP ext[0].unary_op
574572
mp_unary_op_fun_t unary_op;
575-
#define MP_TYPE_BINARY_OP ext[0].binary_op
576573
mp_binary_op_fun_t binary_op;
577574

578575
// Implements load, store and delete subscripting:
579576
// - value = MP_OBJ_SENTINEL means load
580577
// - value = MP_OBJ_NULL means delete
581578
// - all other values mean store the value
582579
// Can return MP_OBJ_NULL if operation not supported.
583-
#define MP_TYPE_SUBSCR ext[0].subscr
584580
mp_subscr_fun_t subscr;
585581

586582
// Corresponds to __iter__ special method.
587583
// Can use the given mp_obj_iter_buf_t to store iterator object,
588584
// otherwise can return a pointer to an object on the heap.
589-
#define MP_TYPE_GETITER ext[0].getiter
590585
mp_getiter_fun_t getiter;
591586

592587
// Corresponds to __next__ special method. May return MP_OBJ_STOP_ITERATION
593588
// as an optimisation instead of raising StopIteration() with no args.
594-
#define MP_TYPE_ITERNEXT ext[0].iternext
595589
mp_fun_1_t iternext;
596590

597591
// Implements the buffer protocol if supported by this type.
598-
#define MP_TYPE_GET_BUFFER ext[0].buffer_p.get_buffer
599592
mp_buffer_p_t buffer_p;
600593

601594
// One of disjoint protocols (interfaces), like mp_stream_p_t, etc.
602-
#define MP_TYPE_PROTOCOL ext[0].protocol
603595
const void *protocol;
604596
};
605597

@@ -686,18 +678,35 @@ struct _mp_obj_full_type_t {
686678
};
687679

688680

689-
extern size_t mp_type_size(const mp_obj_type_t *);
681+
// If the type object in question is known to have the extended fields, you can
682+
// refer to type->MP_TYPE_CALL. Otherwise, you have to use mp_type_call(type)
683+
// The same goes for other fields within the extended region.
684+
#define MP_TYPE_CALL ext[0].call
685+
#define MP_TYPE_UNARY_OP ext[0].unary_op
686+
#define MP_TYPE_BINARY_OP ext[0].binary_op
687+
#define MP_TYPE_SUBSCR ext[0].subscr
688+
#define MP_TYPE_GETITER ext[0].getiter
689+
#define MP_TYPE_ITERNEXT ext[0].iternext
690+
#define MP_TYPE_GET_BUFFER ext[0].buffer_p.get_buffer
691+
#define MP_TYPE_PROTOCOL ext[0].protocol
690692
extern mp_call_fun_t mp_type_call(const mp_obj_type_t *);
691693
extern mp_unary_op_fun_t mp_type_unary_op(const mp_obj_type_t *);
692694
extern mp_binary_op_fun_t mp_type_binary_op(const mp_obj_type_t *);
693-
extern mp_attr_fun_t mp_type_attr(const mp_obj_type_t *);
694695
extern mp_subscr_fun_t mp_type_subscr(const mp_obj_type_t *);
695696
extern mp_getiter_fun_t mp_type_getiter(const mp_obj_type_t *);
696697
extern mp_fun_1_t mp_type_iternext(const mp_obj_type_t *);
697698
extern mp_getbuffer_fun_t mp_type_getbuffer(const mp_obj_type_t *);
698699
extern const void *mp_type_protocol(const mp_obj_type_t *);
700+
701+
// These fields ended up not being placed in the extended area, but accessors
702+
// were created for them anyway.
703+
extern mp_attr_fun_t mp_type_attr(const mp_obj_type_t *);
699704
extern const void *mp_type_parent(const mp_obj_type_t *);
700705

706+
// Return the size of a type object, which can be one of two lengths depending whether it has
707+
// the extended fields or not.
708+
extern size_t mp_type_size(const mp_obj_type_t *);
709+
701710
// Constant types, globally accessible
702711
extern const mp_obj_type_t mp_type_type;
703712
extern const mp_obj_type_t mp_type_object;

0 commit comments

Comments
 (0)