Skip to content

Commit 94beeab

Browse files
jimmodpgeorge
authored andcommitted
py/obj: Convert make_new into a mp_obj_type_t slot.
Instead of being an explicit field, it's now a slot like all the other methods. This is a marginal code size improvement because most types have a make_new (100/138 on PYBV11), however it improves consistency in how types are declared, removing the special case for make_new. Signed-off-by: Jim Mussared <[email protected]>
1 parent 6da41b5 commit 94beeab

File tree

248 files changed

+316
-397
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

248 files changed

+316
-397
lines changed

drivers/ninaw10/nina_wifi_bsp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int nina_bsp_init(void) {
7373
MP_OBJ_NEW_SMALL_INT(MICROPY_HW_WIFI_SPI_BAUDRATE),
7474
};
7575

76-
MP_STATE_PORT(mp_wifi_spi) = machine_spi_type.make_new((mp_obj_t)&machine_spi_type, 2, 0, args);
76+
MP_STATE_PORT(mp_wifi_spi) = MP_OBJ_TYPE_GET_SLOT(&machine_spi_type, make_new)((mp_obj_t)&machine_spi_type, 2, 0, args);
7777
return 0;
7878
}
7979

examples/natmod/framebuf/framebuf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a
2020

2121
mp_type_framebuf.base.type = (void*)&mp_type_type;
2222
mp_type_framebuf.name = MP_QSTR_FrameBuffer;
23-
mp_type_framebuf.make_new = framebuf_make_new;
24-
MP_OBJ_TYPE_SET_SLOT(&mp_type_framebuf, buffer, framebuf_get_buffer, 0);
23+
MP_OBJ_TYPE_SET_SLOT(&mp_type_framebuf, make_new, framebuf_make_new, 0);
24+
MP_OBJ_TYPE_SET_SLOT(&mp_type_framebuf, buffer, framebuf_get_buffer, 1);
2525
framebuf_locals_dict_table[0] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_fill), MP_OBJ_FROM_PTR(&framebuf_fill_obj) };
2626
framebuf_locals_dict_table[1] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_fill_rect), MP_OBJ_FROM_PTR(&framebuf_fill_rect_obj) };
2727
framebuf_locals_dict_table[2] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_pixel), MP_OBJ_FROM_PTR(&framebuf_pixel_obj) };
@@ -33,7 +33,7 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a
3333
framebuf_locals_dict_table[8] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_blit), MP_OBJ_FROM_PTR(&framebuf_blit_obj) };
3434
framebuf_locals_dict_table[9] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_scroll), MP_OBJ_FROM_PTR(&framebuf_scroll_obj) };
3535
framebuf_locals_dict_table[10] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_text), MP_OBJ_FROM_PTR(&framebuf_text_obj) };
36-
MP_OBJ_TYPE_SET_SLOT(&mp_type_framebuf, locals_dict, (void*)&framebuf_locals_dict, 1);
36+
MP_OBJ_TYPE_SET_SLOT(&mp_type_framebuf, locals_dict, (void*)&framebuf_locals_dict, 2);
3737

3838
mp_store_global(MP_QSTR_FrameBuffer, MP_OBJ_FROM_PTR(&mp_type_framebuf));
3939
mp_store_global(MP_QSTR_FrameBuffer1, MP_OBJ_FROM_PTR(&legacy_framebuffer1_obj));

examples/natmod/uzlib/uzlib.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a
2020

2121
decompio_type.base.type = mp_fun_table.type_type;
2222
decompio_type.name = MP_QSTR_DecompIO;
23-
decompio_type.make_new = &decompio_make_new;
24-
MP_OBJ_TYPE_SET_SLOT(&decompio_type, protocol, &decompio_stream_p, 0);
23+
MP_OBJ_TYPE_SET_SLOT(&decompio_type, make_new, &decompio_make_new, 0);
24+
MP_OBJ_TYPE_SET_SLOT(&decompio_type, protocol, &decompio_stream_p, 1);
2525
decompio_locals_dict_table[0] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_read), MP_OBJ_FROM_PTR(&mp_stream_read_obj) };
2626
decompio_locals_dict_table[1] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_readinto), MP_OBJ_FROM_PTR(&mp_stream_readinto_obj) };
2727
decompio_locals_dict_table[2] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_readline), MP_OBJ_FROM_PTR(&mp_stream_unbuffered_readline_obj) };
28-
MP_OBJ_TYPE_SET_SLOT(&decompio_type, locals_dict, (void*)&decompio_locals_dict, 1);
28+
MP_OBJ_TYPE_SET_SLOT(&decompio_type, locals_dict, (void*)&decompio_locals_dict, 2);
2929

3030
mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_uzlib));
3131
mp_store_global(MP_QSTR_decompress, MP_OBJ_FROM_PTR(&mod_uzlib_decompress_obj));

extmod/machine_i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
734734
mp_machine_soft_i2c_type,
735735
MP_QSTR_SoftI2C,
736736
MP_TYPE_FLAG_NONE,
737-
mp_machine_soft_i2c_make_new,
737+
make_new, mp_machine_soft_i2c_make_new,
738738
print, mp_machine_soft_i2c_print,
739739
protocol, &mp_machine_soft_i2c_p,
740740
locals_dict, &mp_machine_i2c_locals_dict

extmod/machine_i2c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
--n_args; \
3939
++all_args; \
4040
} \
41-
return mp_machine_soft_i2c_type.make_new(&mp_machine_soft_i2c_type, n_args, n_kw, all_args); \
41+
return MP_OBJ_TYPE_GET_SLOT(&mp_machine_soft_i2c_type, make_new)(&mp_machine_soft_i2c_type, n_args, n_kw, all_args); \
4242
} \
4343
} while (0)
4444

extmod/machine_mem.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ MP_DEFINE_CONST_OBJ_TYPE(
105105
machine_mem_type,
106106
MP_QSTR_mem,
107107
MP_TYPE_FLAG_NONE,
108-
MP_TYPE_NULL_MAKE_NEW,
109108
print, machine_mem_print,
110109
subscr, machine_mem_subscr
111110
);

extmod/machine_pinbase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
8181
machine_pinbase_type,
8282
MP_QSTR_PinBase,
8383
MP_TYPE_FLAG_NONE,
84-
pinbase_make_new,
84+
make_new, pinbase_make_new,
8585
protocol, &pinbase_pin_p
8686
);
8787

extmod/machine_pwm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
136136
machine_pwm_type,
137137
MP_QSTR_PWM,
138138
MP_TYPE_FLAG_NONE,
139-
mp_machine_pwm_make_new,
139+
make_new, mp_machine_pwm_make_new,
140140
print, mp_machine_pwm_print,
141141
locals_dict, &machine_pwm_locals_dict
142142
);

extmod/machine_signal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
176176
machine_signal_type,
177177
MP_QSTR_Signal,
178178
MP_TYPE_FLAG_NONE,
179-
signal_make_new,
179+
make_new, signal_make_new,
180180
call, signal_call,
181181
protocol, &signal_pin_p,
182182
locals_dict, &signal_locals_dict

extmod/machine_spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
255255
mp_machine_soft_spi_type,
256256
MP_QSTR_SoftSPI,
257257
MP_TYPE_FLAG_NONE,
258-
mp_machine_soft_spi_make_new,
258+
make_new, mp_machine_soft_spi_make_new,
259259
print, mp_machine_soft_spi_print,
260260
protocol, &mp_machine_soft_spi_p,
261261
locals_dict, &mp_machine_spi_locals_dict

0 commit comments

Comments
 (0)