Skip to content

Commit

Permalink
all: Make all mp_obj_type_t defs use MP_DEFINE_CONST_OBJ_TYPE.
Browse files Browse the repository at this point in the history
In preparation for upcoming rework of mp_obj_type_t layout.

Signed-off-by: Jim Mussared <[email protected]>
  • Loading branch information
jimmo authored and dpgeorge committed Sep 19, 2022
1 parent cdb8807 commit 662b976
Show file tree
Hide file tree
Showing 227 changed files with 2,547 additions and 2,188 deletions.
17 changes: 9 additions & 8 deletions extmod/machine_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,13 +730,14 @@ STATIC const mp_machine_i2c_p_t mp_machine_soft_i2c_p = {
.transfer = mp_machine_soft_i2c_transfer,
};

const mp_obj_type_t mp_machine_soft_i2c_type = {
{ &mp_type_type },
.name = MP_QSTR_SoftI2C,
.print = mp_machine_soft_i2c_print,
.make_new = mp_machine_soft_i2c_make_new,
.protocol = &mp_machine_soft_i2c_p,
.locals_dict = (mp_obj_dict_t *)&mp_machine_i2c_locals_dict,
};
MP_DEFINE_CONST_OBJ_TYPE(
mp_machine_soft_i2c_type,
MP_QSTR_SoftI2C,
MP_TYPE_FLAG_NONE,
mp_machine_soft_i2c_make_new,
print, mp_machine_soft_i2c_print,
protocol, &mp_machine_soft_i2c_p,
locals_dict, (mp_obj_dict_t *)&mp_machine_i2c_locals_dict
);

#endif // MICROPY_PY_MACHINE_SOFTI2C
14 changes: 8 additions & 6 deletions extmod/machine_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ STATIC mp_obj_t machine_mem_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t va
}
}

const mp_obj_type_t machine_mem_type = {
{ &mp_type_type },
.name = MP_QSTR_mem,
.print = machine_mem_print,
.subscr = machine_mem_subscr,
};
MP_DEFINE_CONST_OBJ_TYPE(
machine_mem_type,
MP_QSTR_mem,
MP_TYPE_FLAG_NONE,
MP_TYPE_NULL_MAKE_NEW,
print, machine_mem_print,
subscr, machine_mem_subscr
);

const machine_mem_obj_t machine_mem8_obj = {{&machine_mem_type}, 1};
const machine_mem_obj_t machine_mem16_obj = {{&machine_mem_type}, 2};
Expand Down
13 changes: 7 additions & 6 deletions extmod/machine_pinbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ STATIC const mp_pin_p_t pinbase_pin_p = {
.ioctl = pinbase_ioctl,
};

const mp_obj_type_t machine_pinbase_type = {
{ &mp_type_type },
.name = MP_QSTR_PinBase,
.make_new = pinbase_make_new,
.protocol = &pinbase_pin_p,
};
MP_DEFINE_CONST_OBJ_TYPE(
machine_pinbase_type,
MP_QSTR_PinBase,
MP_TYPE_FLAG_NONE,
pinbase_make_new,
protocol, &pinbase_pin_p
);

#endif // MICROPY_PY_MACHINE
15 changes: 8 additions & 7 deletions extmod/machine_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,13 @@ STATIC const mp_rom_map_elem_t machine_pwm_locals_dict_table[] = {
};
STATIC MP_DEFINE_CONST_DICT(machine_pwm_locals_dict, machine_pwm_locals_dict_table);

const mp_obj_type_t machine_pwm_type = {
{ &mp_type_type },
.name = MP_QSTR_PWM,
.print = mp_machine_pwm_print,
.make_new = mp_machine_pwm_make_new,
.locals_dict = (mp_obj_dict_t *)&machine_pwm_locals_dict,
};
MP_DEFINE_CONST_OBJ_TYPE(
machine_pwm_type,
MP_QSTR_PWM,
MP_TYPE_FLAG_NONE,
mp_machine_pwm_make_new,
print, mp_machine_pwm_print,
locals_dict, &machine_pwm_locals_dict
);

#endif // MICROPY_PY_MACHINE_PWM
17 changes: 9 additions & 8 deletions extmod/machine_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,14 @@ STATIC const mp_pin_p_t signal_pin_p = {
.ioctl = signal_ioctl,
};

const mp_obj_type_t machine_signal_type = {
{ &mp_type_type },
.name = MP_QSTR_Signal,
.make_new = signal_make_new,
.call = signal_call,
.protocol = &signal_pin_p,
.locals_dict = (void *)&signal_locals_dict,
};
MP_DEFINE_CONST_OBJ_TYPE(
machine_signal_type,
MP_QSTR_Signal,
MP_TYPE_FLAG_NONE,
signal_make_new,
call, signal_call,
protocol, &signal_pin_p,
locals_dict, (void *)&signal_locals_dict
);

#endif // MICROPY_PY_MACHINE
17 changes: 9 additions & 8 deletions extmod/machine_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,14 @@ const mp_machine_spi_p_t mp_machine_soft_spi_p = {
.transfer = mp_machine_soft_spi_transfer,
};

const mp_obj_type_t mp_machine_soft_spi_type = {
{ &mp_type_type },
.name = MP_QSTR_SoftSPI,
.print = mp_machine_soft_spi_print,
.make_new = mp_machine_soft_spi_make_new,
.protocol = &mp_machine_soft_spi_p,
.locals_dict = (mp_obj_dict_t *)&mp_machine_spi_locals_dict,
};
MP_DEFINE_CONST_OBJ_TYPE(
mp_machine_soft_spi_type,
MP_QSTR_SoftSPI,
MP_TYPE_FLAG_NONE,
mp_machine_soft_spi_make_new,
print, mp_machine_soft_spi_print,
protocol, &mp_machine_soft_spi_p,
locals_dict, (mp_obj_dict_t *)&mp_machine_spi_locals_dict
);

#endif // MICROPY_PY_MACHINE_SOFTSPI
33 changes: 17 additions & 16 deletions extmod/modbluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,16 @@ STATIC void ringbuf_get_uuid(ringbuf_t *ringbuf, mp_obj_bluetooth_uuid_t *uuid)

#endif // !MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS

const mp_obj_type_t mp_type_bluetooth_uuid = {
{ &mp_type_type },
.name = MP_QSTR_UUID,
.make_new = bluetooth_uuid_make_new,
.unary_op = bluetooth_uuid_unary_op,
.binary_op = bluetooth_uuid_binary_op,
.locals_dict = NULL,
.print = bluetooth_uuid_print,
.buffer = bluetooth_uuid_get_buffer,
};
MP_DEFINE_CONST_OBJ_TYPE(
mp_type_bluetooth_uuid,
MP_QSTR_UUID,
MP_TYPE_FLAG_NONE,
bluetooth_uuid_make_new,
unary_op, bluetooth_uuid_unary_op,
binary_op, bluetooth_uuid_binary_op,
print, bluetooth_uuid_print,
buffer, bluetooth_uuid_get_buffer
);

// ----------------------------------------------------------------------------
// Bluetooth object: General
Expand Down Expand Up @@ -976,12 +976,13 @@ STATIC const mp_rom_map_elem_t bluetooth_ble_locals_dict_table[] = {
};
STATIC MP_DEFINE_CONST_DICT(bluetooth_ble_locals_dict, bluetooth_ble_locals_dict_table);

STATIC const mp_obj_type_t mp_type_bluetooth_ble = {
{ &mp_type_type },
.name = MP_QSTR_BLE,
.make_new = bluetooth_ble_make_new,
.locals_dict = (void *)&bluetooth_ble_locals_dict,
};
STATIC MP_DEFINE_CONST_OBJ_TYPE(
mp_type_bluetooth_ble,
MP_QSTR_BLE,
MP_TYPE_FLAG_NONE,
bluetooth_ble_make_new,
locals_dict, (void *)&bluetooth_ble_locals_dict
);

STATIC const mp_rom_map_elem_t mp_module_bluetooth_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ubluetooth) },
Expand Down
22 changes: 12 additions & 10 deletions extmod/modbtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,19 @@ STATIC const mp_rom_map_elem_t btree_locals_dict_table[] = {

STATIC MP_DEFINE_CONST_DICT(btree_locals_dict, btree_locals_dict_table);

STATIC const mp_obj_type_t btree_type = {
{ &mp_type_type },
STATIC MP_DEFINE_CONST_OBJ_TYPE(
btree_type,
MP_QSTR_btree,
MP_TYPE_FLAG_NONE,
MP_TYPE_NULL_MAKE_NEW,
// Save on qstr's, reuse same as for module
.name = MP_QSTR_btree,
.print = btree_print,
.getiter = btree_getiter,
.iternext = btree_iternext,
.binary_op = btree_binary_op,
.subscr = btree_subscr,
.locals_dict = (void *)&btree_locals_dict,
};
print, btree_print,
getiter, btree_getiter,
iternext, btree_iternext,
binary_op, btree_binary_op,
subscr, btree_subscr,
locals_dict, (void *)&btree_locals_dict
);
#endif

STATIC const FILEVTABLE btree_stream_fvtable = {
Expand Down
15 changes: 8 additions & 7 deletions extmod/modframebuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,13 +829,14 @@ STATIC const mp_rom_map_elem_t framebuf_locals_dict_table[] = {
};
STATIC MP_DEFINE_CONST_DICT(framebuf_locals_dict, framebuf_locals_dict_table);

STATIC const mp_obj_type_t mp_type_framebuf = {
{ &mp_type_type },
.name = MP_QSTR_FrameBuffer,
.make_new = framebuf_make_new,
.buffer = framebuf_get_buffer,
.locals_dict = (mp_obj_dict_t *)&framebuf_locals_dict,
};
STATIC MP_DEFINE_CONST_OBJ_TYPE(
mp_type_framebuf,
MP_QSTR_FrameBuffer,
MP_TYPE_FLAG_NONE,
framebuf_make_new,
buffer, framebuf_get_buffer,
locals_dict, (mp_obj_dict_t *)&framebuf_locals_dict
);
#endif

// this factory function is provided for backwards compatibility with old FrameBuffer1 class
Expand Down
30 changes: 16 additions & 14 deletions extmod/modlwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,13 @@ STATIC const mp_rom_map_elem_t lwip_slip_locals_dict_table[] = {

STATIC MP_DEFINE_CONST_DICT(lwip_slip_locals_dict, lwip_slip_locals_dict_table);

STATIC const mp_obj_type_t lwip_slip_type = {
{ &mp_type_type },
.name = MP_QSTR_slip,
.make_new = lwip_slip_make_new,
.locals_dict = (mp_obj_dict_t *)&lwip_slip_locals_dict,
};
STATIC MP_DEFINE_CONST_OBJ_TYPE(
lwip_slip_type,
MP_QSTR_slip,
MP_TYPE_FLAG_NONE,
lwip_slip_make_new,
locals_dict, (mp_obj_dict_t *)&lwip_slip_locals_dict
);

#endif // MICROPY_PY_LWIP_SLIP

Expand Down Expand Up @@ -1594,14 +1595,15 @@ STATIC const mp_stream_p_t lwip_socket_stream_p = {
.ioctl = lwip_socket_ioctl,
};

STATIC const mp_obj_type_t lwip_socket_type = {
{ &mp_type_type },
.name = MP_QSTR_socket,
.print = lwip_socket_print,
.make_new = lwip_socket_make_new,
.protocol = &lwip_socket_stream_p,
.locals_dict = (mp_obj_dict_t *)&lwip_socket_locals_dict,
};
STATIC MP_DEFINE_CONST_OBJ_TYPE(
lwip_socket_type,
MP_QSTR_socket,
MP_TYPE_FLAG_NONE,
lwip_socket_make_new,
print, lwip_socket_print,
protocol, &lwip_socket_stream_p,
locals_dict, (mp_obj_dict_t *)&lwip_socket_locals_dict
);

/******************************************************************************/
// Support functions for memory protection. lwIP has its own memory management
Expand Down
30 changes: 16 additions & 14 deletions extmod/moduasyncio.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,13 @@ STATIC const mp_rom_map_elem_t task_queue_locals_dict_table[] = {
};
STATIC MP_DEFINE_CONST_DICT(task_queue_locals_dict, task_queue_locals_dict_table);

STATIC const mp_obj_type_t task_queue_type = {
{ &mp_type_type },
.name = MP_QSTR_TaskQueue,
.make_new = task_queue_make_new,
.locals_dict = (mp_obj_dict_t *)&task_queue_locals_dict,
};
STATIC MP_DEFINE_CONST_OBJ_TYPE(
task_queue_type,
MP_QSTR_TaskQueue,
MP_TYPE_FLAG_NONE,
task_queue_make_new,
locals_dict, (mp_obj_dict_t *)&task_queue_locals_dict
);

/******************************************************************************/
// Task class
Expand Down Expand Up @@ -286,14 +287,15 @@ STATIC mp_obj_t task_iternext(mp_obj_t self_in) {
return mp_const_none;
}

STATIC const mp_obj_type_t task_type = {
{ &mp_type_type },
.name = MP_QSTR_Task,
.make_new = task_make_new,
.attr = task_attr,
.getiter = task_getiter,
.iternext = task_iternext,
};
STATIC MP_DEFINE_CONST_OBJ_TYPE(
task_type,
MP_QSTR_Task,
MP_TYPE_FLAG_NONE,
task_make_new,
attr, task_attr,
getiter, task_getiter,
iternext, task_iternext
);

/******************************************************************************/
// C-level uasyncio module
Expand Down
13 changes: 7 additions & 6 deletions extmod/moducryptolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,13 @@ STATIC const mp_rom_map_elem_t ucryptolib_aes_locals_dict_table[] = {
};
STATIC MP_DEFINE_CONST_DICT(ucryptolib_aes_locals_dict, ucryptolib_aes_locals_dict_table);

STATIC const mp_obj_type_t ucryptolib_aes_type = {
{ &mp_type_type },
.name = MP_QSTR_aes,
.make_new = ucryptolib_aes_make_new,
.locals_dict = (void *)&ucryptolib_aes_locals_dict,
};
STATIC MP_DEFINE_CONST_OBJ_TYPE(
ucryptolib_aes_type,
MP_QSTR_aes,
MP_TYPE_FLAG_NONE,
ucryptolib_aes_make_new,
locals_dict, (void *)&ucryptolib_aes_locals_dict
);

STATIC const mp_rom_map_elem_t mp_module_ucryptolib_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ucryptolib) },
Expand Down
21 changes: 11 additions & 10 deletions extmod/moductypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,16 +634,17 @@ STATIC mp_obj_t uctypes_struct_bytes_at(mp_obj_t ptr, mp_obj_t size) {
}
MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytes_at_obj, uctypes_struct_bytes_at);

STATIC const mp_obj_type_t uctypes_struct_type = {
{ &mp_type_type },
.name = MP_QSTR_struct,
.print = uctypes_struct_print,
.make_new = uctypes_struct_make_new,
.attr = uctypes_struct_attr,
.subscr = uctypes_struct_subscr,
.unary_op = uctypes_struct_unary_op,
.buffer = uctypes_get_buffer,
};
STATIC MP_DEFINE_CONST_OBJ_TYPE(
uctypes_struct_type,
MP_QSTR_struct,
MP_TYPE_FLAG_NONE,
uctypes_struct_make_new,
print, uctypes_struct_print,
attr, uctypes_struct_attr,
subscr, uctypes_struct_subscr,
unary_op, uctypes_struct_unary_op,
buffer, uctypes_get_buffer
);

STATIC const mp_rom_map_elem_t mp_module_uctypes_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uctypes) },
Expand Down
Loading

0 comments on commit 662b976

Please sign in to comment.