@@ -565,41 +565,33 @@ void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flag
565
565
566
566
struct _mp_obj_type_ext {
567
567
// Corresponds to __call__ special method, ie T(...).
568
- #define MP_TYPE_CALL ext[0].call
569
568
mp_call_fun_t call ;
570
569
571
570
// Implements unary and binary operations.
572
571
// Can return MP_OBJ_NULL if the operation is not supported.
573
- #define MP_TYPE_UNARY_OP ext[0].unary_op
574
572
mp_unary_op_fun_t unary_op ;
575
- #define MP_TYPE_BINARY_OP ext[0].binary_op
576
573
mp_binary_op_fun_t binary_op ;
577
574
578
575
// Implements load, store and delete subscripting:
579
576
// - value = MP_OBJ_SENTINEL means load
580
577
// - value = MP_OBJ_NULL means delete
581
578
// - all other values mean store the value
582
579
// Can return MP_OBJ_NULL if operation not supported.
583
- #define MP_TYPE_SUBSCR ext[0].subscr
584
580
mp_subscr_fun_t subscr ;
585
581
586
582
// Corresponds to __iter__ special method.
587
583
// Can use the given mp_obj_iter_buf_t to store iterator object,
588
584
// otherwise can return a pointer to an object on the heap.
589
- #define MP_TYPE_GETITER ext[0].getiter
590
585
mp_getiter_fun_t getiter ;
591
586
592
587
// Corresponds to __next__ special method. May return MP_OBJ_STOP_ITERATION
593
588
// as an optimisation instead of raising StopIteration() with no args.
594
- #define MP_TYPE_ITERNEXT ext[0].iternext
595
589
mp_fun_1_t iternext ;
596
590
597
591
// Implements the buffer protocol if supported by this type.
598
- #define MP_TYPE_GET_BUFFER ext[0].buffer_p.get_buffer
599
592
mp_buffer_p_t buffer_p ;
600
593
601
594
// One of disjoint protocols (interfaces), like mp_stream_p_t, etc.
602
- #define MP_TYPE_PROTOCOL ext[0].protocol
603
595
const void * protocol ;
604
596
};
605
597
@@ -686,18 +678,35 @@ struct _mp_obj_full_type_t {
686
678
};
687
679
688
680
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
690
692
extern mp_call_fun_t mp_type_call (const mp_obj_type_t * );
691
693
extern mp_unary_op_fun_t mp_type_unary_op (const mp_obj_type_t * );
692
694
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 * );
694
695
extern mp_subscr_fun_t mp_type_subscr (const mp_obj_type_t * );
695
696
extern mp_getiter_fun_t mp_type_getiter (const mp_obj_type_t * );
696
697
extern mp_fun_1_t mp_type_iternext (const mp_obj_type_t * );
697
698
extern mp_getbuffer_fun_t mp_type_getbuffer (const mp_obj_type_t * );
698
699
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 * );
699
704
extern const void * mp_type_parent (const mp_obj_type_t * );
700
705
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
+
701
710
// Constant types, globally accessible
702
711
extern const mp_obj_type_t mp_type_type ;
703
712
extern const mp_obj_type_t mp_type_object ;
0 commit comments