3434
3535#if MICROPY_PY_UCTYPES
3636
37- /// \module uctypes - Access data structures in memory
38- ///
39- /// The module allows to define layout of raw data structure (using terms
40- /// of C language), and then access memory buffers using this definition.
41- /// The module also provides convenience functions to access memory buffers
42- /// contained in Python objects or wrap memory buffers in Python objects.
43- /// \constant UINT8_1 - uint8_t value type
44-
45- /// \class struct - C-like structure
46- ///
47- /// Encapsulalation of in-memory data structure. This class doesn't define
48- /// any methods, only attribute access (for structure fields) and
49- /// indexing (for pointer and array fields).
50- ///
51- /// Usage:
52- ///
53- /// # Define layout of a structure with 2 fields
54- /// # 0 and 4 are byte offsets of fields from the beginning of struct
55- /// # they are logically ORed with field type
56- /// FOO_STRUCT = {"a": 0 | uctypes.UINT32, "b": 4 | uctypes.UINT8}
57- ///
58- /// # Example memory buffer to access (contained in bytes object)
59- /// buf = b"\x64\0\0\0\0x14"
60- ///
61- /// # Create structure object referring to address of
62- /// # the data in the buffer above
63- /// s = uctypes.struct(FOO_STRUCT, uctypes.addressof(buf))
64- ///
65- /// # Access fields
66- /// print(s.a, s.b)
67- /// # Result:
68- /// # 100, 20
37+ // The uctypes module allows defining the layout of a raw data structure (using
38+ // terms of the C language), and then access memory buffers using this definition.
39+ // The module also provides convenience functions to access memory buffers
40+ // contained in Python objects or wrap memory buffers in Python objects.
6941
7042#define LAYOUT_LITTLE_ENDIAN (0)
7143#define LAYOUT_BIG_ENDIAN (1)
@@ -647,29 +619,24 @@ STATIC mp_int_t uctypes_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo,
647619 return 0 ;
648620}
649621
650- /// \function addressof()
651- /// Return address of object's data (applies to object providing buffer
652- /// interface).
622+ // addressof()
623+ // Return address of object's data (applies to objects providing the buffer interface).
653624STATIC mp_obj_t uctypes_struct_addressof (mp_obj_t buf ) {
654625 mp_buffer_info_t bufinfo ;
655626 mp_get_buffer_raise (buf , & bufinfo , MP_BUFFER_READ );
656627 return mp_obj_new_int ((mp_int_t )(uintptr_t )bufinfo .buf );
657628}
658629MP_DEFINE_CONST_FUN_OBJ_1 (uctypes_struct_addressof_obj , uctypes_struct_addressof );
659630
660- /// \function bytearray_at()
661- /// Capture memory at given address of given size as bytearray. Memory is
662- /// captured by reference (and thus memory pointed by bytearray may change
663- /// or become invalid at later time). Use bytes_at() to capture by value.
631+ // bytearray_at()
632+ // Capture memory at given address of given size as bytearray.
664633STATIC mp_obj_t uctypes_struct_bytearray_at (mp_obj_t ptr , mp_obj_t size ) {
665634 return mp_obj_new_bytearray_by_ref (mp_obj_int_get_truncated (size ), (void * )(uintptr_t )mp_obj_int_get_truncated (ptr ));
666635}
667636MP_DEFINE_CONST_FUN_OBJ_2 (uctypes_struct_bytearray_at_obj , uctypes_struct_bytearray_at );
668637
669- /// \function bytes_at()
670- /// Capture memory at given address of given size as bytes. Memory is
671- /// captured by value, i.e. copied. Use bytearray_at() to capture by reference
672- /// ("zero copy").
638+ // bytes_at()
639+ // Capture memory at given address of given size as bytes.
673640STATIC mp_obj_t uctypes_struct_bytes_at (mp_obj_t ptr , mp_obj_t size ) {
674641 return mp_obj_new_bytes ((void * )(uintptr_t )mp_obj_int_get_truncated (ptr ), mp_obj_int_get_truncated (size ));
675642}
@@ -695,36 +662,19 @@ STATIC const mp_rom_map_elem_t mp_module_uctypes_globals_table[] = {
695662 { MP_ROM_QSTR (MP_QSTR_bytes_at ), MP_ROM_PTR (& uctypes_struct_bytes_at_obj ) },
696663 { MP_ROM_QSTR (MP_QSTR_bytearray_at ), MP_ROM_PTR (& uctypes_struct_bytearray_at_obj ) },
697664
698- /// \moduleref uctypes
699-
700- /// \constant NATIVE - Native structure layout - native endianness,
701- /// platform-specific field alignment
702665 { MP_ROM_QSTR (MP_QSTR_NATIVE ), MP_ROM_INT (LAYOUT_NATIVE ) },
703- /// \constant LITTLE_ENDIAN - Little-endian structure layout, tightly packed
704- /// (no alignment constraints)
705666 { MP_ROM_QSTR (MP_QSTR_LITTLE_ENDIAN ), MP_ROM_INT (LAYOUT_LITTLE_ENDIAN ) },
706- /// \constant BIG_ENDIAN - Big-endian structure layout, tightly packed
707- /// (no alignment constraints)
708667 { MP_ROM_QSTR (MP_QSTR_BIG_ENDIAN ), MP_ROM_INT (LAYOUT_BIG_ENDIAN ) },
709668
710- /// \constant VOID - void value type, may be used only as pointer target type.
711669 { MP_ROM_QSTR (MP_QSTR_VOID ), MP_ROM_INT (TYPE2SMALLINT (UINT8 , VAL_TYPE_BITS )) },
712670
713- /// \constant UINT8 - uint8_t value type
714671 { MP_ROM_QSTR (MP_QSTR_UINT8 ), MP_ROM_INT (TYPE2SMALLINT (UINT8 , 4 )) },
715- /// \constant INT8 - int8_t value type
716672 { MP_ROM_QSTR (MP_QSTR_INT8 ), MP_ROM_INT (TYPE2SMALLINT (INT8 , 4 )) },
717- /// \constant UINT16 - uint16_t value type
718673 { MP_ROM_QSTR (MP_QSTR_UINT16 ), MP_ROM_INT (TYPE2SMALLINT (UINT16 , 4 )) },
719- /// \constant INT16 - int16_t value type
720674 { MP_ROM_QSTR (MP_QSTR_INT16 ), MP_ROM_INT (TYPE2SMALLINT (INT16 , 4 )) },
721- /// \constant UINT32 - uint32_t value type
722675 { MP_ROM_QSTR (MP_QSTR_UINT32 ), MP_ROM_INT (TYPE2SMALLINT (UINT32 , 4 )) },
723- /// \constant INT32 - int32_t value type
724676 { MP_ROM_QSTR (MP_QSTR_INT32 ), MP_ROM_INT (TYPE2SMALLINT (INT32 , 4 )) },
725- /// \constant UINT64 - uint64_t value type
726677 { MP_ROM_QSTR (MP_QSTR_UINT64 ), MP_ROM_INT (TYPE2SMALLINT (UINT64 , 4 )) },
727- /// \constant INT64 - int64_t value type
728678 { MP_ROM_QSTR (MP_QSTR_INT64 ), MP_ROM_INT (TYPE2SMALLINT (INT64 , 4 )) },
729679
730680 { MP_ROM_QSTR (MP_QSTR_BFUINT8 ), MP_ROM_INT (TYPE2SMALLINT (BFUINT8 , 4 )) },
0 commit comments