diff --git a/cc3200/mods/modnetwork.c b/cc3200/mods/modnetwork.c index b11b03638ba85feafadb69b58fea56cec1e6419a..44d316901796ad4cad97963fa003c955459851c9 100644 --- a/cc3200/mods/modnetwork.c +++ b/cc3200/mods/modnetwork.c @@ -91,7 +91,7 @@ STATIC const mp_arg_t network_server_args[] = { { MP_QSTR_login, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t network_server_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +STATIC mp_obj_t network_server_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c index 622a026c2e82c25b149712f6bab6ee55017cb6a5..e5b043dce06d005298d62f38cb46a2d36b24edc3 100644 --- a/cc3200/mods/modusocket.c +++ b/cc3200/mods/modusocket.c @@ -125,7 +125,7 @@ void modusocket_close_all_user_sockets (void) { // socket class // constructor socket(family=AF_INET, type=SOCK_STREAM, proto=IPPROTO_TCP, fileno=None) -STATIC mp_obj_t socket_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 4, false); // create socket object diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index a7ee5928120ea127318e8e97fc18a9937aa5237b..0e249d2d191769f222fabc33b8a2eaf04bb374da 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -821,7 +821,7 @@ STATIC const mp_arg_t wlan_init_args[] = { { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, { MP_QSTR_antenna, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = ANTENNA_TYPE_INTERNAL} }, }; -STATIC mp_obj_t wlan_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +STATIC mp_obj_t wlan_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/cc3200/mods/pybadc.c b/cc3200/mods/pybadc.c index 005c3650110035a229655f8f43370dc17b190a8a..22a90edb0a73f56795c81f6fedca085416d0efe9 100644 --- a/cc3200/mods/pybadc.c +++ b/cc3200/mods/pybadc.c @@ -140,7 +140,7 @@ STATIC const mp_arg_t pyb_adc_init_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 12} }, }; -STATIC mp_obj_t adc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/cc3200/mods/pybi2c.c b/cc3200/mods/pybi2c.c index 52a0851f2351c2c4c454bfa866c6b213d345e53f..6c64c3d9b8242ae05455a8a1d99d810a30c52d08 100644 --- a/cc3200/mods/pybi2c.c +++ b/cc3200/mods/pybi2c.c @@ -319,7 +319,7 @@ STATIC const mp_arg_t pyb_i2c_init_args[] = { { MP_QSTR_baudrate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 100000} }, { MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/cc3200/mods/pybpin.c b/cc3200/mods/pybpin.c index ce0e386ff5a503a1123a07cd7c29c275f4ed73ac..a8a19a1bd5a1dbfaa27540e42a7042519c63ad76 100644 --- a/cc3200/mods/pybpin.c +++ b/cc3200/mods/pybpin.c @@ -648,7 +648,7 @@ STATIC void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t mp_printf(print, ", alt=%d)", alt); } -STATIC mp_obj_t pin_make_new(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // Run an argument through the mapper and return the result. diff --git a/cc3200/mods/pybrtc.c b/cc3200/mods/pybrtc.c index 8d6b9b13edbf8514a8808c390da58d121dfd831c..ea99411052784ff970b0091bd6992098877598fb 100644 --- a/cc3200/mods/pybrtc.c +++ b/cc3200/mods/pybrtc.c @@ -285,7 +285,7 @@ STATIC const mp_arg_t pyb_rtc_init_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_datetime, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t pyb_rtc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/cc3200/mods/pybsd.c b/cc3200/mods/pybsd.c index ea81f30f86e75e00d9c9643f95578638bb670059..55b797dc785ac1b04dc24cdfa601c4015a3bf1c1 100644 --- a/cc3200/mods/pybsd.c +++ b/cc3200/mods/pybsd.c @@ -64,7 +64,7 @@ STATIC const mp_obj_t pyb_sd_def_pin[3] = {&pin_GP10, &pin_GP11, &pin_GP15}; DECLARE PRIVATE FUNCTIONS ******************************************************************************/ STATIC void pyb_sd_hw_init (pybsd_obj_t *self); -STATIC mp_obj_t pyb_sd_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args); +STATIC mp_obj_t pyb_sd_make_new (const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args); STATIC mp_obj_t pyb_sd_deinit (mp_obj_t self_in); /****************************************************************************** @@ -123,7 +123,7 @@ STATIC const mp_arg_t pyb_sd_init_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_pins, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t pyb_sd_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +STATIC mp_obj_t pyb_sd_make_new (const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/cc3200/mods/pybspi.c b/cc3200/mods/pybspi.c index b7e4310aec4bdcc699d086d282bbe13896108f0f..d4fcbe94b42174710f8d052219e3a53d50b57fa6 100644 --- a/cc3200/mods/pybspi.c +++ b/cc3200/mods/pybspi.c @@ -231,7 +231,7 @@ static const mp_arg_t pyb_spi_init_args[] = { { MP_QSTR_firstbit, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = PYBSPI_FIRST_BIT_MSB} }, { MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t pyb_spi_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/cc3200/mods/pybtimer.c b/cc3200/mods/pybtimer.c index 95eeb083c297690ae9c76abf20cda39b38c740bf..6a74f5a5c6bd6fcd9803700a14e87c0b4823a54c 100644 --- a/cc3200/mods/pybtimer.c +++ b/cc3200/mods/pybtimer.c @@ -356,7 +356,7 @@ error: /// Construct a new timer object of the given id. If additional /// arguments are given, then the timer is initialised by `init(...)`. /// `id` can be 1 to 4 -STATIC mp_obj_t pyb_timer_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c index 660453b7524cd747680c2bccbaa27363749cf498..87d89f02fb0a5135cdb8071ed972557deea34b7c 100644 --- a/cc3200/mods/pybuart.c +++ b/cc3200/mods/pybuart.c @@ -443,7 +443,7 @@ STATIC const mp_arg_t pyb_uart_init_args[] = { { MP_QSTR_stop, MP_ARG_INT, {.u_int = 1} }, { MP_QSTR_pins, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; -STATIC mp_obj_t pyb_uart_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/cc3200/mods/pybwdt.c b/cc3200/mods/pybwdt.c index 8448054ceb9bb20144ef2804961a7c2ecfbfa95a..6e5fe4714a7af3eeaa7d6ce4e3d75c91b3912df4 100644 --- a/cc3200/mods/pybwdt.c +++ b/cc3200/mods/pybwdt.c @@ -92,7 +92,7 @@ STATIC const mp_arg_t pyb_wdt_init_args[] = { { MP_QSTR_id, MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_timeout, MP_ARG_INT, {.u_int = 5000} }, // 5 s }; -STATIC mp_obj_t pyb_wdt_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { +STATIC mp_obj_t pyb_wdt_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { // check the arguments mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); diff --git a/esp8266/modesp.c b/esp8266/modesp.c index f6f60160b266d8fe9b1d8ab79e2f4c5d0b6036ab..c408cec2eb050852e5ea5ab6327af5868183b1d2 100644 --- a/esp8266/modesp.c +++ b/esp8266/modesp.c @@ -82,7 +82,7 @@ STATIC mp_obj_t esp_socket_make_new_base() { // constructor esp_socket(family=AF_INET, type=SOCK_STREAM, proto=IPPROTO_TCP, fileno=None) // Arguments ignored as we do not support UDP (yet) -STATIC mp_obj_t esp_socket_make_new(mp_obj_t type_in, mp_uint_t n_args, +STATIC mp_obj_t esp_socket_make_new(const mp_obj_type_t *type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 4, false); diff --git a/esp8266/modpybadc.c b/esp8266/modpybadc.c index ade63dfb348a2be4ce902a6c3417dbcdc58eb701..26b28c50b25bfb08be11dca6d5054c300243a93d 100644 --- a/esp8266/modpybadc.c +++ b/esp8266/modpybadc.c @@ -42,7 +42,7 @@ typedef struct _pyb_adc_obj_t { STATIC pyb_adc_obj_t pyb_adc_vdd3 = {{&pyb_adc_type}, true}; STATIC pyb_adc_obj_t pyb_adc_adc = {{&pyb_adc_type}, false}; -STATIC mp_obj_t pyb_adc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, +STATIC mp_obj_t pyb_adc_make_new(const mp_obj_type_t *type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); diff --git a/esp8266/modpybpin.c b/esp8266/modpybpin.c index a2ab9857389fd00f77b83f89b693b01b20efba10..3c3aebe6eac42cf1d9112fb1ea500deb02b89688 100644 --- a/esp8266/modpybpin.c +++ b/esp8266/modpybpin.c @@ -119,7 +119,7 @@ STATIC mp_obj_t pyb_pin_obj_init_helper(pyb_pin_obj_t *self, mp_uint_t n_args, c } // constructor(id, ...) -STATIC mp_obj_t pyb_pin_make_new(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // Run an argument through the mapper and return the result. diff --git a/esp8266/modpybrtc.c b/esp8266/modpybrtc.c index 1156216cc0f0d4a0baa68dd3886ea64f2ba5dd94..6c2dde691e82efdba79b3d8ec2163038ffa6528d 100644 --- a/esp8266/modpybrtc.c +++ b/esp8266/modpybrtc.c @@ -49,7 +49,7 @@ typedef struct _pyb_rtc_obj_t { // singleton RTC object STATIC const pyb_rtc_obj_t pyb_rtc_obj = {{&pyb_rtc_type}}; -STATIC mp_obj_t pyb_rtc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); diff --git a/extmod/moductypes.c b/extmod/moductypes.c index cd7e9d1782c9196c1fa1f6777d238d1e4c4fd720..9b078387b08818aba21079db292ae19fc7aef78d 100644 --- a/extmod/moductypes.c +++ b/extmod/moductypes.c @@ -121,10 +121,10 @@ STATIC NORETURN void syntax_error(void) { nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "syntax error in uctypes descriptor")); } -STATIC mp_obj_t uctypes_struct_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t uctypes_struct_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, 3, false); mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t); - o->base.type = MP_OBJ_TO_PTR(type_in); + o->base.type = type; o->addr = (void*)(uintptr_t)mp_obj_get_int(args[0]); o->desc = args[1]; o->flags = LAYOUT_NATIVE; diff --git a/extmod/moduhashlib.c b/extmod/moduhashlib.c index 6ddfa6141b9004feb2bdce5674ece9148510454d..86943578c0547f0c42f3e1b178b63defb3f8f4a2 100644 --- a/extmod/moduhashlib.c +++ b/extmod/moduhashlib.c @@ -41,10 +41,10 @@ typedef struct _mp_obj_hash_t { STATIC mp_obj_t hash_update(mp_obj_t self_in, mp_obj_t arg); -STATIC mp_obj_t hash_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t hash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX)); - o->base.type = MP_OBJ_TO_PTR(type_in); + o->base.type = type; sha256_init((CRYAL_SHA256_CTX*)o->state); if (n_args == 1) { hash_update(MP_OBJ_FROM_PTR(o), args[0]); diff --git a/py/modbuiltins.c b/py/modbuiltins.c index 53774110a8decd66d182bd9bf9c28a4dfed5e053..05bdbfecac9c7432698b9f3bb88e3500a6a50ebe 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -512,7 +512,7 @@ STATIC mp_obj_t mp_builtin_sorted(size_t n_args, const mp_obj_t *args, mp_map_t nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "must use keyword argument for key function")); } - mp_obj_t self = mp_type_list.make_new(MP_OBJ_FROM_PTR(&mp_type_list), 1, 0, args); + mp_obj_t self = mp_type_list.make_new(&mp_type_list, 1, 0, args); mp_obj_list_sort(1, &self, kwargs); return self; diff --git a/py/obj.h b/py/obj.h index 52b8b4f8d4b72c371f325aff31e4d411b23922a5..14c3a8120015ed7d5d6dd4bcb1adf67afeda292a 100644 --- a/py/obj.h +++ b/py/obj.h @@ -42,12 +42,14 @@ typedef machine_ptr_t mp_obj_t; typedef machine_const_ptr_t mp_const_obj_t; #endif -// Anything that wants to be a Micro Python object must have -// mp_obj_base_t as its first member (except small ints and qstrs) +// This mp_obj_type_t struct is a concrete MicroPython object which holds info +// about a type. See below for actual definition of the struct. +typedef struct _mp_obj_type_t mp_obj_type_t; -struct _mp_obj_type_t; +// Anything that wants to be a concrete MicroPython object must have mp_obj_base_t +// as its first member (small ints, qstr objs and inline floats are not concrete). struct _mp_obj_base_t { - const struct _mp_obj_type_t *type MICROPY_OBJ_BASE_ALIGNMENT; + const mp_obj_type_t *type MICROPY_OBJ_BASE_ALIGNMENT; }; typedef struct _mp_obj_base_t mp_obj_base_t; @@ -259,8 +261,8 @@ typedef struct _mp_rom_obj_t { mp_const_obj_t o; } mp_rom_obj_t; //static inline bool MP_OBJ_IS_TYPE(mp_const_obj_t o, const mp_obj_type_t *t) { return (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)(o))->type == (t))); } // this does not work for checking a string, use below macro for that //static inline bool MP_OBJ_IS_INT(mp_const_obj_t o) { return (MP_OBJ_IS_SMALL_INT(o) || MP_OBJ_IS_TYPE(o, &mp_type_int)); } // returns true if o is a small int or long int // Need to forward declare these for the inline function to compile. -extern const struct _mp_obj_type_t mp_type_int; -extern const struct _mp_obj_type_t mp_type_bool; +extern const mp_obj_type_t mp_type_int; +extern const mp_obj_type_t mp_type_bool; static inline bool mp_obj_is_integer(mp_const_obj_t o) { return MP_OBJ_IS_INT(o) || MP_OBJ_IS_TYPE(o, &mp_type_bool); } // returns true if o is bool, small int or long int //static inline bool MP_OBJ_IS_STR(mp_const_obj_t o) { return (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &mp_type_str)); } @@ -408,7 +410,7 @@ typedef enum { } mp_print_kind_t; typedef void (*mp_print_fun_t)(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind); -typedef mp_obj_t (*mp_make_new_fun_t)(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args); +typedef mp_obj_t (*mp_make_new_fun_t)(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); typedef mp_obj_t (*mp_call_fun_t)(mp_obj_t fun, size_t n_args, size_t n_kw, const mp_obj_t *args); typedef mp_obj_t (*mp_unary_op_fun_t)(mp_uint_t op, mp_obj_t); typedef mp_obj_t (*mp_binary_op_fun_t)(mp_uint_t op, mp_obj_t, mp_obj_t); @@ -510,8 +512,6 @@ struct _mp_obj_type_t { */ }; -typedef struct _mp_obj_type_t mp_obj_type_t; - // Constant types, globally accessible extern const mp_obj_type_t mp_type_type; extern const mp_obj_type_t mp_type_object; @@ -691,7 +691,7 @@ void mp_obj_exception_clear_traceback(mp_obj_t self_in); void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block); void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values); mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in); -mp_obj_t mp_obj_exception_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args); +mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args); mp_obj_t mp_alloc_emergency_exception_buf(mp_obj_t size_in); void mp_init_emergency_exception_buf(void); diff --git a/py/objarray.c b/py/objarray.c index 2c4813f54f2990306353decdd0434126828b1704..a17ae276e2e71c2e9fac891d3d50c60f89a9cc63 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -168,7 +168,7 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) { #endif #if MICROPY_PY_ARRAY -STATIC mp_obj_t array_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t array_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 1, 2, false); @@ -187,7 +187,7 @@ STATIC mp_obj_t array_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, con #endif #if MICROPY_PY_BUILTINS_BYTEARRAY -STATIC mp_obj_t bytearray_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t bytearray_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 0, 1, false); @@ -219,7 +219,7 @@ mp_obj_t mp_obj_new_memoryview(byte typecode, mp_uint_t nitems, void *items) { return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t memoryview_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t memoryview_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; // TODO possibly allow memoryview constructor to take start/stop so that one diff --git a/py/objbool.c b/py/objbool.c index 09878a7505ae29f4293a3515ab007ef879c9190f..8882a835d3bf247c4eeca84ae4a02e0562609b3e 100644 --- a/py/objbool.c +++ b/py/objbool.c @@ -52,7 +52,7 @@ STATIC void bool_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ } } -STATIC mp_obj_t bool_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t bool_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 0, 1, false); diff --git a/py/objcomplex.c b/py/objcomplex.c index df0467e3242a8ae8b43bea3e4f64f6827a97bb5a..5da655eb3c370a4398f15b659b89a5f5af23486b 100644 --- a/py/objcomplex.c +++ b/py/objcomplex.c @@ -69,7 +69,7 @@ STATIC void complex_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_ } } -STATIC mp_obj_t complex_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t complex_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 0, 2, false); diff --git a/py/objdict.c b/py/objdict.c index cb4c602b99be2bc85419e87b8a7587c2f1f516dc..cc1f502d0fc0d224200c80fc4030d6fa219715f4 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -82,12 +82,12 @@ STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ } } -STATIC mp_obj_t dict_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t dict_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_obj_t dict_out = mp_obj_new_dict(0); mp_obj_dict_t *dict = MP_OBJ_TO_PTR(dict_out); - dict->base.type = MP_OBJ_TO_PTR(type_in); + dict->base.type = type; #if MICROPY_PY_COLLECTIONS_ORDEREDDICT - if (MP_OBJ_TO_PTR(type_in) == &mp_type_ordereddict) { + if (type == &mp_type_ordereddict) { dict->map.is_ordered = 1; } #endif diff --git a/py/objenumerate.c b/py/objenumerate.c index 46c3e801dfe673151fe4ca39962be97e432af7bf..26a5740a169ba1ed461c8722070dd2828144a5be 100644 --- a/py/objenumerate.c +++ b/py/objenumerate.c @@ -45,7 +45,7 @@ STATIC const mp_arg_t enumerate_make_new_args[] = { }; #define ENUMERATE_MAKE_NEW_NUM_ARGS MP_ARRAY_SIZE(enumerate_make_new_args) -STATIC mp_obj_t enumerate_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t enumerate_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { #if MICROPY_CPYTHON_COMPAT // parse args mp_arg_val_t vals[ENUMERATE_MAKE_NEW_NUM_ARGS]; @@ -53,13 +53,13 @@ STATIC mp_obj_t enumerate_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, // create enumerate object mp_obj_enumerate_t *o = m_new_obj(mp_obj_enumerate_t); - o->base.type = MP_OBJ_TO_PTR(type_in); + o->base.type = type; o->iter = mp_getiter(vals[0].u_obj); o->cur = vals[1].u_int; #else (void)n_kw; mp_obj_enumerate_t *o = m_new_obj(mp_obj_enumerate_t); - o->base.type = type_in; + o->base.type = type; o->iter = mp_getiter(args[0]); o->cur = n_args > 1 ? mp_obj_get_int(args[1]) : 0; #endif diff --git a/py/objexcept.c b/py/objexcept.c index 83aa5286c6e03b60f34a5b3d73cf8b54a415e054..d8aecb80f0c6fd4a8fc56121cccde8c33ecb3cc0 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -114,7 +114,7 @@ STATIC void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_pr mp_obj_tuple_print(print, MP_OBJ_FROM_PTR(o->args), kind); } -mp_obj_t mp_obj_exception_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, false); mp_obj_exception_t *o = m_new_obj_var_maybe(mp_obj_exception_t, mp_obj_t, 0); if (o == NULL) { @@ -125,7 +125,7 @@ mp_obj_t mp_obj_exception_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, } else { o->args = MP_OBJ_TO_PTR(mp_obj_new_tuple(n_args, args)); } - o->base.type = MP_OBJ_TO_PTR(type_in); + o->base.type = type; o->traceback_data = NULL; return MP_OBJ_FROM_PTR(o); } @@ -290,7 +290,7 @@ mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg) mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, mp_uint_t n_args, const mp_obj_t *args) { assert(exc_type->make_new == mp_obj_exception_make_new); - return exc_type->make_new(MP_OBJ_FROM_PTR(exc_type), n_args, 0, args); + return exc_type->make_new(exc_type, n_args, 0, args); } mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg) { diff --git a/py/objfilter.c b/py/objfilter.c index 168f0e76125709fd81190905d008e6debfc8906a..e288102d380fb837e9afc3baafa2c1ad94e79cb2 100644 --- a/py/objfilter.c +++ b/py/objfilter.c @@ -34,10 +34,10 @@ typedef struct _mp_obj_filter_t { mp_obj_t iter; } mp_obj_filter_t; -STATIC mp_obj_t filter_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t filter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, 2, false); mp_obj_filter_t *o = m_new_obj(mp_obj_filter_t); - o->base.type = MP_OBJ_TO_PTR(type_in); + o->base.type = type; o->fun = args[0]; o->iter = mp_getiter(args[1]); return MP_OBJ_FROM_PTR(o); diff --git a/py/objfloat.c b/py/objfloat.c index f144bfd8642613b3b04f21d70c6a75bfa51374d4..aa37f9ab2dd1f1d94aa0d3a584c866dadb839882 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -69,7 +69,7 @@ STATIC void float_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t } } -STATIC mp_obj_t float_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t float_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 0, 1, false); diff --git a/py/objint.c b/py/objint.c index e548eb833e78f2c41a780904918c02c99463edea..46290a36fceeda9d4bf82e6c36b0d1d041fc3e92 100644 --- a/py/objint.c +++ b/py/objint.c @@ -42,7 +42,7 @@ #endif // This dispatcher function is expected to be independent of the implementation of long int -STATIC mp_obj_t mp_obj_int_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t mp_obj_int_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 0, 2, false); diff --git a/py/objlist.c b/py/objlist.c index 3fd38e81d965c3243ec88459e478c8b689bbb9ae..62928af064a232bb8c855d1f7aab06dbd8caabfa 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -68,7 +68,7 @@ STATIC mp_obj_t list_extend_from_iter(mp_obj_t list, mp_obj_t iterable) { return list; } -STATIC mp_obj_t list_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t list_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 0, 1, false); diff --git a/py/objmap.c b/py/objmap.c index a0293c36f8164f9baba50904c1bbdeaa9066a125..526bc0560045d9583581913b95d9393d0bcdeb61 100644 --- a/py/objmap.c +++ b/py/objmap.c @@ -36,10 +36,10 @@ typedef struct _mp_obj_map_t { mp_obj_t iters[]; } mp_obj_map_t; -STATIC mp_obj_t map_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t map_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, MP_OBJ_FUN_ARGS_MAX, false); mp_obj_map_t *o = m_new_obj_var(mp_obj_map_t, mp_obj_t, n_args - 1); - o->base.type = MP_OBJ_TO_PTR(type_in); + o->base.type = type; o->n_iters = n_args - 1; o->fun = args[0]; for (mp_uint_t i = 0; i < n_args - 1; i++) { diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c index 3e346032630525ac7c9d1bed53d79095baa6f376..62289f50f7b7a106dd76d82eadf7f9b855d14733 100644 --- a/py/objnamedtuple.c +++ b/py/objnamedtuple.c @@ -44,7 +44,7 @@ typedef struct _mp_obj_namedtuple_t { mp_obj_tuple_t tuple; } mp_obj_namedtuple_t; -STATIC mp_uint_t namedtuple_find_field(mp_obj_namedtuple_type_t *type, qstr name) { +STATIC mp_uint_t namedtuple_find_field(const mp_obj_namedtuple_type_t *type, qstr name) { for (mp_uint_t i = 0; i < type->n_fields; i++) { if (type->fields[i] == name) { return i; @@ -77,8 +77,8 @@ STATIC void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -STATIC mp_obj_t namedtuple_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { - mp_obj_namedtuple_type_t *type = MP_OBJ_TO_PTR(type_in); +STATIC mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { + const mp_obj_namedtuple_type_t *type = (const mp_obj_namedtuple_type_t*)type_in; mp_uint_t num_fields = type->n_fields; if (n_args + n_kw != num_fields) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { @@ -130,7 +130,7 @@ STATIC mp_obj_t namedtuple_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw } mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(num_fields, arg_objects)); - tuple->base.type = MP_OBJ_TO_PTR(type_in); + tuple->base.type = type_in; return MP_OBJ_FROM_PTR(tuple); } diff --git a/py/objobject.c b/py/objobject.c index 5cd37739407d678a2d776152a2c5902fa4ce76b7..bba6f053e68d81a86e5c561d16331eb515829330 100644 --- a/py/objobject.c +++ b/py/objobject.c @@ -33,11 +33,11 @@ typedef struct _mp_obj_object_t { mp_obj_base_t base; } mp_obj_object_t; -STATIC mp_obj_t object_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t object_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)args; mp_arg_check_num(n_args, n_kw, 0, 0, false); mp_obj_object_t *o = m_new_obj(mp_obj_object_t); - o->base.type = MP_OBJ_TO_PTR(type_in); + o->base.type = type; return MP_OBJ_FROM_PTR(o); } @@ -54,7 +54,7 @@ STATIC mp_obj_t object___new__(mp_obj_t cls) { "__new__ arg must be a user-type")); } mp_obj_t o = MP_OBJ_SENTINEL; - mp_obj_t res = mp_obj_instance_make_new(cls, 1, 0, &o); + mp_obj_t res = mp_obj_instance_make_new(MP_OBJ_TO_PTR(cls), 1, 0, &o); return res; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___new___fun_obj, object___new__); diff --git a/py/objproperty.c b/py/objproperty.c index 323696cf159d204a464a76f732db059da6c55683..80e39e093377abd4adaae995cca0a3b8522b4764 100644 --- a/py/objproperty.c +++ b/py/objproperty.c @@ -37,11 +37,11 @@ typedef struct _mp_obj_property_t { mp_obj_t proxy[3]; // getter, setter, deleter } mp_obj_property_t; -STATIC mp_obj_t property_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t property_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 4, false); mp_obj_property_t *o = m_new_obj(mp_obj_property_t); - o->base.type = MP_OBJ_TO_PTR(type_in); + o->base.type = type; if (n_args >= 4) { // doc ignored } diff --git a/py/objrange.c b/py/objrange.c index bec026ff6fda87de0f3bb881545456b2153ae325..79459316b19b3f7456c8e16a4ebc912298e48b73 100644 --- a/py/objrange.c +++ b/py/objrange.c @@ -90,11 +90,11 @@ STATIC void range_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind } } -STATIC mp_obj_t range_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t range_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 3, false); mp_obj_range_t *o = m_new_obj(mp_obj_range_t); - o->base.type = MP_OBJ_TO_PTR(type_in); + o->base.type = type; o->start = 0; o->step = 1; diff --git a/py/objreversed.c b/py/objreversed.c index b0da00a885f4a48585dbd541f0066ef6008b2708..1e54bb522ac35e066824d7ee7aae7ec079d97e93 100644 --- a/py/objreversed.c +++ b/py/objreversed.c @@ -38,7 +38,7 @@ typedef struct _mp_obj_reversed_t { mp_uint_t cur_index; // current index, plus 1; 0=no more, 1=last one (index 0) } mp_obj_reversed_t; -STATIC mp_obj_t reversed_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t reversed_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); // check if __reversed__ exists, and if so delegate to it @@ -49,7 +49,7 @@ STATIC mp_obj_t reversed_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, } mp_obj_reversed_t *o = m_new_obj(mp_obj_reversed_t); - o->base.type = MP_OBJ_TO_PTR(type_in); + o->base.type = type; o->seq = args[0]; o->cur_index = mp_obj_get_int(mp_obj_len(args[0])); // start at the end of the sequence diff --git a/py/objset.c b/py/objset.c index c83212c433ab893117e1143c33059c51a63b8080..8730918c15101c3acc231ae5ae820bf0466a4580 100644 --- a/py/objset.c +++ b/py/objset.c @@ -119,7 +119,7 @@ STATIC void set_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t #endif } -STATIC mp_obj_t set_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t set_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 1, false); switch (n_args) { @@ -127,7 +127,7 @@ STATIC mp_obj_t set_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const // create a new, empty set mp_obj_set_t *set = MP_OBJ_TO_PTR(mp_obj_new_set(0, NULL)); // set actual set/frozenset type - set->base.type = MP_OBJ_TO_PTR(type_in); + set->base.type = type; return MP_OBJ_FROM_PTR(set); } @@ -141,7 +141,7 @@ STATIC mp_obj_t set_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_set_store(set, item); } // Set actual set/frozenset type - ((mp_obj_set_t*)MP_OBJ_TO_PTR(set))->base.type = MP_OBJ_TO_PTR(type_in); + ((mp_obj_set_t*)MP_OBJ_TO_PTR(set))->base.type = type; return set; } } @@ -327,7 +327,7 @@ STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool if (is_set_or_frozenset(self_in)) { self = MP_OBJ_TO_PTR(self_in); } else { - self = MP_OBJ_TO_PTR(set_make_new(MP_OBJ_FROM_PTR(&mp_type_set), 1, 0, &self_in)); + self = MP_OBJ_TO_PTR(set_make_new(&mp_type_set, 1, 0, &self_in)); cleanup_self = true; } @@ -336,7 +336,7 @@ STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool if (is_set_or_frozenset(other_in)) { other = MP_OBJ_TO_PTR(other_in); } else { - other = MP_OBJ_TO_PTR(set_make_new(MP_OBJ_FROM_PTR(&mp_type_set), 1, 0, &other_in)); + other = MP_OBJ_TO_PTR(set_make_new(&mp_type_set, 1, 0, &other_in)); cleanup_other = true; } bool out = true; diff --git a/py/objstr.c b/py/objstr.c index a76ff0d7368a3df650da87927e90203c862903c7..8a0a19de15d637d84ec185c382269cf733fb54ba 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -131,7 +131,7 @@ STATIC void str_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t } } -mp_obj_t mp_obj_str_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { #if MICROPY_CPYTHON_COMPAT if (n_kw != 0) { mp_arg_error_unimpl_kw(); @@ -149,7 +149,7 @@ mp_obj_t mp_obj_str_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_print_t print; vstr_init_print(&vstr, 16, &print); mp_obj_print_helper(&print, args[0], PRINT_STR); - return mp_obj_new_str_from_vstr(MP_OBJ_TO_PTR(type_in), &vstr); + return mp_obj_new_str_from_vstr(type, &vstr); } default: // 2 or 3 args @@ -157,7 +157,7 @@ mp_obj_t mp_obj_str_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const if (MP_OBJ_IS_TYPE(args[0], &mp_type_bytes)) { GET_STR_DATA_LEN(args[0], str_data, str_len); GET_STR_HASH(args[0], str_hash); - mp_obj_str_t *o = MP_OBJ_TO_PTR(mp_obj_new_str_of_type(MP_OBJ_TO_PTR(type_in), NULL, str_len)); + mp_obj_str_t *o = MP_OBJ_TO_PTR(mp_obj_new_str_of_type(type, NULL, str_len)); o->data = str_data; o->hash = str_hash; return MP_OBJ_FROM_PTR(o); @@ -169,7 +169,7 @@ mp_obj_t mp_obj_str_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const } } -STATIC mp_obj_t bytes_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; #if MICROPY_CPYTHON_COMPAT @@ -426,7 +426,7 @@ STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) { if (!MP_OBJ_IS_TYPE(arg, &mp_type_list)) { // arg is not a list, try to convert it to one // TODO: Try to optimize? - arg = mp_type_list.make_new(MP_OBJ_FROM_PTR(&mp_type_list), 1, 0, &arg); + arg = mp_type_list.make_new(&mp_type_list, 1, 0, &arg); } mp_obj_list_get(arg, &seq_len, &seq_items); } @@ -1767,7 +1767,7 @@ STATIC mp_obj_t bytes_decode(size_t n_args, const mp_obj_t *args) { args = new_args; n_args++; } - return mp_obj_str_make_new(MP_OBJ_FROM_PTR(&mp_type_str), n_args, 0, args); + return mp_obj_str_make_new(&mp_type_str, n_args, 0, args); } // TODO: should accept kwargs too @@ -1779,7 +1779,7 @@ STATIC mp_obj_t str_encode(size_t n_args, const mp_obj_t *args) { args = new_args; n_args++; } - return bytes_make_new(MP_OBJ_NULL, n_args, 0, args); + return bytes_make_new(NULL, n_args, 0, args); } #endif diff --git a/py/objstr.h b/py/objstr.h index 1cfb19503850ceb207110e5b659b7a87a98ae63d..6179a74afc35fa2a4be2a2012089e83eb0145364 100644 --- a/py/objstr.h +++ b/py/objstr.h @@ -60,7 +60,7 @@ const byte *mp_obj_str_get_data_no_check(mp_obj_t self_in, size_t *len); else { str_len = ((mp_obj_str_t*)MP_OBJ_TO_PTR(str_obj_in))->len; str_data = ((mp_obj_str_t*)MP_OBJ_TO_PTR(str_obj_in))->data; } #endif -mp_obj_t mp_obj_str_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args); +mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args); void mp_str_print_json(const mp_print_t *print, const byte *str_data, size_t str_len); mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs); mp_obj_t mp_obj_str_split(size_t n_args, const mp_obj_t *args); diff --git a/py/objstringio.c b/py/objstringio.c index 357320cd2f680aab7743f194393223d30f9701e8..f50abfbc3a35d03699b1a12f8c9e357d4b680f20 100644 --- a/py/objstringio.c +++ b/py/objstringio.c @@ -120,15 +120,15 @@ STATIC mp_obj_t stringio___exit__(size_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(stringio___exit___obj, 4, 4, stringio___exit__); -STATIC mp_obj_stringio_t *stringio_new(mp_obj_t type_in) { +STATIC mp_obj_stringio_t *stringio_new(const mp_obj_type_t *type) { mp_obj_stringio_t *o = m_new_obj(mp_obj_stringio_t); - o->base.type = MP_OBJ_TO_PTR(type_in); + o->base.type = type; o->vstr = vstr_new(); o->pos = 0; return o; } -STATIC mp_obj_t stringio_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t stringio_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)n_kw; // TODO check n_kw==0 mp_obj_stringio_t *o = stringio_new(type_in); diff --git a/py/objtuple.c b/py/objtuple.c index 86720ed374241a02b84d4a71e5d2cf6d9ea53f0b..c21390a6033e87007396214d10e52aa3910b1bbe 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -61,7 +61,7 @@ void mp_obj_tuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t } } -STATIC mp_obj_t mp_obj_tuple_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t mp_obj_tuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 0, 1, false); diff --git a/py/objtype.c b/py/objtype.c index c9ab59642f7e79250d5d6d20128b2b51b04483b8..39998c558f302075341c073261f537cbbf0ce892 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -43,14 +43,14 @@ #define DEBUG_printf(...) (void)0 #endif -STATIC mp_obj_t static_class_method_make_new(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args); +STATIC mp_obj_t static_class_method_make_new(const mp_obj_type_t *self_in, size_t n_args, size_t n_kw, const mp_obj_t *args); /******************************************************************************/ // instance object -STATIC mp_obj_t mp_obj_new_instance(mp_obj_t class, uint subobjs) { +STATIC mp_obj_t mp_obj_new_instance(const mp_obj_type_t *class, uint subobjs) { mp_obj_instance_t *o = m_new_obj_var(mp_obj_instance_t, mp_obj_t, subobjs); - o->base.type = MP_OBJ_TO_PTR(class); + o->base.type = class; mp_map_init(&o->members, 0); mp_seq_clear(o->subobj, 0, subobjs, sizeof(*o->subobj)); return MP_OBJ_FROM_PTR(o); @@ -235,16 +235,14 @@ STATIC void instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_k mp_printf(print, "<%s object at %p>", mp_obj_get_type_str(self_in), self_in); } -mp_obj_t mp_obj_instance_make_new(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { - assert(MP_OBJ_IS_TYPE(self_in, &mp_type_type)); - mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in); +mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(mp_obj_is_instance_type(self)); const mp_obj_type_t *native_base; uint num_native_bases = instance_count_native_bases(self, &native_base); assert(num_native_bases < 2); - mp_obj_instance_t *o = MP_OBJ_TO_PTR(mp_obj_new_instance(self_in, num_native_bases)); + mp_obj_instance_t *o = MP_OBJ_TO_PTR(mp_obj_new_instance(self, num_native_bases)); // This executes only "__new__" part of obejection creation. // TODO: This won't work will for classes with native bases. @@ -269,14 +267,15 @@ mp_obj_t mp_obj_instance_make_new(mp_obj_t self_in, size_t n_args, size_t n_kw, if (init_fn[0] == MP_OBJ_SENTINEL) { // Native type's constructor is what wins - it gets all our arguments, // and none Python classes are initialized at all. - o->subobj[0] = native_base->make_new(MP_OBJ_FROM_PTR(native_base), n_args, n_kw, args); + o->subobj[0] = native_base->make_new(native_base, n_args, n_kw, args); } else if (init_fn[0] != MP_OBJ_NULL) { // now call Python class __new__ function with all args if (n_args == 0 && n_kw == 0) { - new_ret = mp_call_function_n_kw(init_fn[0], 1, 0, (mp_obj_t*)(void*)&self_in); + mp_obj_t args2[1] = {MP_OBJ_FROM_PTR(self)}; + new_ret = mp_call_function_n_kw(init_fn[0], 1, 0, args2); } else { mp_obj_t *args2 = m_new(mp_obj_t, 1 + n_args + 2 * n_kw); - args2[0] = self_in; + args2[0] = MP_OBJ_FROM_PTR(self); memcpy(args2 + 1, args, (n_args + 2 * n_kw) * sizeof(mp_obj_t)); new_ret = mp_call_function_n_kw(init_fn[0], n_args + 1, n_kw, args2); m_del(mp_obj_t, args2, 1 + n_args + 2 * n_kw); @@ -778,7 +777,7 @@ STATIC void type_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ mp_printf(print, "<class '%q'>", self->name); } -STATIC mp_obj_t type_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; mp_arg_check_num(n_args, n_kw, 1, 3, false); @@ -813,7 +812,7 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp } // make new instance - mp_obj_t o = self->make_new(self_in, n_args, n_kw, args); + mp_obj_t o = self->make_new(self, n_args, n_kw, args); // return new instance return o; @@ -931,7 +930,7 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) // __new__ slot exists; check if it is a function if (MP_OBJ_IS_FUN(elem->value)) { // __new__ is a function, wrap it in a staticmethod decorator - elem->value = static_class_method_make_new(MP_OBJ_FROM_PTR(&mp_type_staticmethod), 1, 0, &elem->value); + elem->value = static_class_method_make_new(&mp_type_staticmethod, 1, 0, &elem->value); } } @@ -957,7 +956,7 @@ STATIC void super_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind mp_print_str(print, ">"); } -STATIC mp_obj_t super_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; // 0 arguments are turned into 2 in the compiler // 1 argument is not yet implemented @@ -1108,8 +1107,7 @@ mp_obj_t mp_instance_cast_to_native_base(mp_const_obj_t self_in, mp_const_obj_t /******************************************************************************/ // staticmethod and classmethod types (probably should go in a different file) -STATIC mp_obj_t static_class_method_make_new(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { - mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t static_class_method_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(self == &mp_type_staticmethod || self == &mp_type_classmethod); mp_arg_check_num(n_args, n_kw, 1, 1, false); diff --git a/py/objtype.h b/py/objtype.h index 06227cf5a3ce63c52c9aef85d8dc57c1003812ba..61efd00c05b0df4367bdc26eade2162dce068c77 100644 --- a/py/objtype.h +++ b/py/objtype.h @@ -47,6 +47,6 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons #define mp_obj_is_instance_type(type) ((type)->make_new == mp_obj_instance_make_new) #define mp_obj_is_native_type(type) ((type)->make_new != mp_obj_instance_make_new) // this needs to be exposed for the above macros to work correctly -mp_obj_t mp_obj_instance_make_new(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args); +mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self_in, size_t n_args, size_t n_kw, const mp_obj_t *args); #endif // __MICROPY_INCLUDED_PY_OBJTYPE_H__ diff --git a/py/objzip.c b/py/objzip.c index 4b240fbbf7019eb7dc4f47d42e932931ee1634b3..d4cd614a4cad0e9491993a33063cda37449a6253 100644 --- a/py/objzip.c +++ b/py/objzip.c @@ -36,11 +36,11 @@ typedef struct _mp_obj_zip_t { mp_obj_t iters[]; } mp_obj_zip_t; -STATIC mp_obj_t zip_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t zip_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, false); mp_obj_zip_t *o = m_new_obj_var(mp_obj_zip_t, mp_obj_t, n_args); - o->base.type = MP_OBJ_TO_PTR(type_in); + o->base.type = type; o->n_iters = n_args; for (mp_uint_t i = 0; i < n_args; i++) { o->iters[i] = mp_getiter(args[i]); diff --git a/stmhal/accel.c b/stmhal/accel.c index 59d83bfb51215ebf14428e3d903fa87c6533910e..434a92a008d674b30abb19a393baad0283f7059b 100644 --- a/stmhal/accel.c +++ b/stmhal/accel.c @@ -130,7 +130,7 @@ STATIC pyb_accel_obj_t pyb_accel_obj; /// accel = pyb.Accel() /// pyb.delay(20) /// print(accel.x()) -STATIC mp_obj_t pyb_accel_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_accel_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); diff --git a/stmhal/adc.c b/stmhal/adc.c index d8ce90cb3fb845d90c04b43a85bbd8953dd19406..4e364c375df6b823c8c1227560b9e7af01785d4f 100644 --- a/stmhal/adc.c +++ b/stmhal/adc.c @@ -153,7 +153,7 @@ STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t /// \classmethod \constructor(pin) /// Create an ADC object associated with the given pin. /// This allows you to then read analog values on that pin. -STATIC mp_obj_t adc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t adc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check number of arguments mp_arg_check_num(n_args, n_kw, 1, 1, false); @@ -436,7 +436,7 @@ float adc_read_core_vref(ADC_HandleTypeDef *adcHandle) { /******************************************************************************/ /* Micro Python bindings : adc_all object */ -STATIC mp_obj_t adc_all_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t adc_all_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check number of arguments mp_arg_check_num(n_args, n_kw, 1, 1, false); diff --git a/stmhal/can.c b/stmhal/can.c index 005bd9e943d8c76967694371448ca8a1b228a999..b2330cd9c1b0e5ee510c88955400bf6195380a2d 100644 --- a/stmhal/can.c +++ b/stmhal/can.c @@ -339,7 +339,7 @@ STATIC mp_obj_t pyb_can_init_helper(pyb_can_obj_t *self, mp_uint_t n_args, const /// /// - `CAN(1)` is on `YA`: `(RX, TX) = (Y3, Y4) = (PB8, PB9)` /// - `CAN(2)` is on `YB`: `(RX, TX) = (Y5, Y6) = (PB12, PB13)` -STATIC mp_obj_t pyb_can_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_can_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/stmhal/dac.c b/stmhal/dac.c index 8573dcc2ad2aa0301c4ca26a9d5e1332994b0a7a..6d7491c314c1d2308a5c153314bce366bc681a71 100644 --- a/stmhal/dac.c +++ b/stmhal/dac.c @@ -192,7 +192,7 @@ STATIC mp_obj_t pyb_dac_init_helper(pyb_dac_obj_t *self, mp_uint_t n_args, const /// /// `port` can be a pin object, or an integer (1 or 2). /// DAC(1) is on pin X5 and DAC(2) is on pin X6. -STATIC mp_obj_t pyb_dac_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/stmhal/extint.c b/stmhal/extint.c index 57116dc374217ebcd0bcefd74eeafdaa4ed5308e..ebc4a4616b49315e4c4c8eec7cfc564cdc7fea61 100644 --- a/stmhal/extint.c +++ b/stmhal/extint.c @@ -307,7 +307,7 @@ STATIC const mp_arg_t pyb_extint_make_new_args[] = { }; #define PYB_EXTINT_MAKE_NEW_NUM_ARGS MP_ARRAY_SIZE(pyb_extint_make_new_args) -STATIC mp_obj_t extint_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t extint_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // type_in == extint_obj_type // parse args @@ -315,7 +315,7 @@ STATIC mp_obj_t extint_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_ mp_arg_parse_all_kw_array(n_args, n_kw, args, PYB_EXTINT_MAKE_NEW_NUM_ARGS, pyb_extint_make_new_args, vals); extint_obj_t *self = m_new_obj(extint_obj_t); - self->base.type = type_in; + self->base.type = type; self->line = extint_register(vals[0].u_obj, vals[1].u_int, vals[2].u_int, vals[3].u_obj, false); return self; diff --git a/stmhal/file.c b/stmhal/file.c index d7d8009b3ab77038635f95645719815ae075dae1..a61fa050cfaf16c52abd52c26b37bbc4a4b9badf 100644 --- a/stmhal/file.c +++ b/stmhal/file.c @@ -157,7 +157,7 @@ STATIC const mp_arg_t file_open_args[] = { }; #define FILE_OPEN_NUM_ARGS MP_ARRAY_SIZE(file_open_args) -STATIC mp_obj_t file_open(mp_obj_t type, mp_arg_val_t *args) { +STATIC mp_obj_t file_open(const mp_obj_type_t *type, mp_arg_val_t *args) { int mode = 0; const char *mode_s = mp_obj_str_get_str(args[1].u_obj); // TODO make sure only one of r, w, x, a, and b, t are specified @@ -180,11 +180,11 @@ STATIC mp_obj_t file_open(mp_obj_t type, mp_arg_val_t *args) { break; #if MICROPY_PY_IO_FILEIO case 'b': - type = (mp_obj_t)&mp_type_fileio; + type = &mp_type_fileio; break; #endif case 't': - type = (mp_obj_t)&mp_type_textio; + type = &mp_type_textio; break; } } @@ -207,10 +207,10 @@ STATIC mp_obj_t file_open(mp_obj_t type, mp_arg_val_t *args) { return o; } -STATIC mp_obj_t file_obj_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t file_obj_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { mp_arg_val_t arg_vals[FILE_OPEN_NUM_ARGS]; mp_arg_parse_all_kw_array(n_args, n_kw, args, FILE_OPEN_NUM_ARGS, file_open_args, arg_vals); - return file_open(type_in, arg_vals); + return file_open(type, arg_vals); } // TODO gc hook to close the file if not already closed @@ -275,6 +275,6 @@ mp_obj_t mp_builtin_open(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwarg // TODO: analyze buffering args and instantiate appropriate type mp_arg_val_t arg_vals[FILE_OPEN_NUM_ARGS]; mp_arg_parse_all(n_args, args, kwargs, FILE_OPEN_NUM_ARGS, file_open_args, arg_vals); - return file_open((mp_obj_t)&mp_type_textio, arg_vals); + return file_open(&mp_type_textio, arg_vals); } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); diff --git a/stmhal/i2c.c b/stmhal/i2c.c index c97629fd987061ee052b36a8da985a609fb8464f..263ac9ab27fbf29dba6c49d823be716fd6cb9e2c 100644 --- a/stmhal/i2c.c +++ b/stmhal/i2c.c @@ -395,7 +395,7 @@ STATIC mp_obj_t pyb_i2c_init_helper(const pyb_i2c_obj_t *self, mp_uint_t n_args, /// /// - `I2C(1)` is on the X position: `(SCL, SDA) = (X9, X10) = (PB6, PB7)` /// - `I2C(2)` is on the Y position: `(SCL, SDA) = (Y9, Y10) = (PB10, PB11)` -STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_i2c_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/stmhal/lcd.c b/stmhal/lcd.c index 12d96e699635f8742905ec5a265d906bf167e161..143ef9bbd76f1408e090cb1b7e62d43ce0fde3c4 100644 --- a/stmhal/lcd.c +++ b/stmhal/lcd.c @@ -192,7 +192,7 @@ STATIC void lcd_write_strn(pyb_lcd_obj_t *lcd, const char *str, unsigned int len /// /// Construct an LCD object in the given skin position. `skin_position` can be 'X' or 'Y', and /// should match the position where the LCD pyskin is plugged in. -STATIC mp_obj_t pyb_lcd_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_lcd_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, 1, false); diff --git a/stmhal/led.c b/stmhal/led.c index ca52931e3fce67548f795bfb6aeff6b0cc9c4d00..990d2046a12a5f2445defd816ebfaa86dd706331 100644 --- a/stmhal/led.c +++ b/stmhal/led.c @@ -217,7 +217,7 @@ void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t ki /// Create an LED object associated with the given LED: /// /// - `id` is the LED number, 1-4. -STATIC mp_obj_t led_obj_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, 1, false); diff --git a/stmhal/modnwcc3k.c b/stmhal/modnwcc3k.c index 20e7035e5b8ba2b6f41268a02496b98cdb590816..85dc0585a808dd3d65432262b309b1bbeabb32e6 100644 --- a/stmhal/modnwcc3k.c +++ b/stmhal/modnwcc3k.c @@ -428,7 +428,7 @@ STATIC const cc3k_obj_t cc3k_obj = {{(mp_obj_type_t*)&mod_network_nic_type_cc3k} // [SPI on Y position; Y6=B13=SCK, Y7=B14=MISO, Y8=B15=MOSI] // // STM32F4DISC: init(pyb.SPI(2), pyb.Pin.cpu.A15, pyb.Pin.cpu.B10, pyb.Pin.cpu.B11) -STATIC mp_obj_t cc3k_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t cc3k_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 4, 4, false); diff --git a/stmhal/modnwwiznet5k.c b/stmhal/modnwwiznet5k.c index 2feb9b95361bc81bc09e3fcb90db526b80373e32..b6f18354b9b4b9e9c1c4f754554b38a1d59e73c5 100644 --- a/stmhal/modnwwiznet5k.c +++ b/stmhal/modnwwiznet5k.c @@ -318,7 +318,7 @@ STATIC mp_obj_t wiznet5k_socket_disconnect(mp_obj_t self_in) { /// \classmethod \constructor(spi, pin_cs, pin_rst) /// Create and return a WIZNET5K object. -STATIC mp_obj_t wiznet5k_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 3, 3, false); diff --git a/stmhal/modusocket.c b/stmhal/modusocket.c index 402378a38d8691cc922706653dfffce87054c23d..8e461fe9ccf206eed41b1699c3247d10edf87394 100644 --- a/stmhal/modusocket.c +++ b/stmhal/modusocket.c @@ -41,7 +41,7 @@ STATIC const mp_obj_type_t socket_type; // constructor socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None) -STATIC mp_obj_t socket_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 4, false); // create socket object (not bound to any NIC yet) diff --git a/stmhal/pin.c b/stmhal/pin.c index a0f3994f787878a8c10351d345494e5829870c07..e3ae0be400f33a657feb8736db5448f938199712 100644 --- a/stmhal/pin.c +++ b/stmhal/pin.c @@ -244,7 +244,7 @@ STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, mp_uint_t n_args, cons /// \classmethod \constructor(id, ...) /// Create a new Pin object associated with the id. If additional arguments are given, /// they are used to initialise the pin. See `init`. -STATIC mp_obj_t pin_make_new(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pin_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); // Run an argument through the mapper and return the result. diff --git a/stmhal/rtc.c b/stmhal/rtc.c index ad595dd0ab1109dd22899bfd520ca41ffb4c7dd8..bb16e48d7a5469018324fee2c81be83f11e90304 100644 --- a/stmhal/rtc.c +++ b/stmhal/rtc.c @@ -418,7 +418,7 @@ STATIC const pyb_rtc_obj_t pyb_rtc_obj = {{&pyb_rtc_type}}; /// \classmethod \constructor() /// Create an RTC object. -STATIC mp_obj_t pyb_rtc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); diff --git a/stmhal/servo.c b/stmhal/servo.c index 7f5a09f7778a79908590a935945d432a7274c3d4..382b48f67a071a50e8839d9667a5b26ea076240f 100644 --- a/stmhal/servo.c +++ b/stmhal/servo.c @@ -185,7 +185,7 @@ STATIC void pyb_servo_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ /// \classmethod \constructor(id) /// Create a servo object. `id` is 1-4. -STATIC mp_obj_t pyb_servo_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_servo_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, 1, false); diff --git a/stmhal/spi.c b/stmhal/spi.c index d9bc7ec42fb788dc960937eb30eea27eec632f56..3a1737e4092457502888a375224e6c805b5263f3 100644 --- a/stmhal/spi.c +++ b/stmhal/spi.c @@ -466,7 +466,7 @@ STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, mp_uint_t n_args, /// /// At the moment, the NSS pin is not used by the SPI driver and is free /// for other use. -STATIC mp_obj_t pyb_spi_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_spi_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/stmhal/timer.c b/stmhal/timer.c index a97f1f259cb9f7dc9d4f2334322d618ae9fc6847..e1d659ceb06b2eff3ae4d616a89e829f84c6c460 100644 --- a/stmhal/timer.c +++ b/stmhal/timer.c @@ -637,7 +637,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, mp_uint_t n_args, c /// Construct a new timer object of the given id. If additional /// arguments are given, then the timer is initialised by `init(...)`. /// `id` can be 1 to 14, excluding 3. -STATIC mp_obj_t pyb_timer_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/stmhal/uart.c b/stmhal/uart.c index 024cc049b906d0b9e288e1bae0dd190f812dfe56..272b207eb7ee5b66e9adb7644a06b7ee4d48186a 100644 --- a/stmhal/uart.c +++ b/stmhal/uart.c @@ -589,7 +589,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, con /// - `UART(6)` is on `YA`: `(TX, RX) = (Y1, Y2) = (PC6, PC7)` /// - `UART(3)` is on `YB`: `(TX, RX) = (Y9, Y10) = (PB10, PB11)` /// - `UART(2)` is on: `(TX, RX) = (X3, X4) = (PA2, PA3)` -STATIC mp_obj_t pyb_uart_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/stmhal/usb.c b/stmhal/usb.c index ca7741590b723dec0406b028f5ab5818e6ea51ec..1e1469c564a9482352a7132f2256ffb664afac46 100644 --- a/stmhal/usb.c +++ b/stmhal/usb.c @@ -354,7 +354,7 @@ STATIC void pyb_usb_vcp_print(const mp_print_t *print, mp_obj_t self_in, mp_prin /// \classmethod \constructor() /// Create a new USB_VCP object. -STATIC mp_obj_t pyb_usb_vcp_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_usb_vcp_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); @@ -543,7 +543,7 @@ typedef struct _pyb_usb_hid_obj_t { STATIC const pyb_usb_hid_obj_t pyb_usb_hid_obj = {{&pyb_usb_hid_type}}; -STATIC mp_obj_t pyb_usb_hid_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_usb_hid_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); diff --git a/stmhal/usrsw.c b/stmhal/usrsw.c index 69b0ca9ab47c2c3273b3691f34f49f0596d874d0..c9b7690bf9c18e5c8010631ee0ec7d496cc2e410 100644 --- a/stmhal/usrsw.c +++ b/stmhal/usrsw.c @@ -83,7 +83,7 @@ void pyb_switch_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t /// \classmethod \constructor() /// Create and return a switch object. -STATIC mp_obj_t pyb_switch_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_switch_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 0, 0, false); diff --git a/teensy/led.c b/teensy/led.c index 5798f537bc6468f69b9e9de0fc34699ea59f64f6..c7ac8be1ff47add0a56bbb53dc69d26d96bb40e9 100644 --- a/teensy/led.c +++ b/teensy/led.c @@ -89,7 +89,7 @@ void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t ki mp_printf(print, "<LED %lu>", self->led_id); } -STATIC mp_obj_t led_obj_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { +STATIC mp_obj_t led_obj_make_new(const mp_obj_type_t *type, uint n_args, uint n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, 1, false); diff --git a/teensy/timer.c b/teensy/timer.c index 88583a09b4e63a4fd090817de8f1ab8f5142978f..af64ac708c6e52bc95e00cdbf477100c5dd3d32f 100644 --- a/teensy/timer.c +++ b/teensy/timer.c @@ -304,7 +304,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, uint n_args, const /// Construct a new timer object of the given id. If additional /// arguments are given, then the timer is initialised by `init(...)`. /// `id` can be 1 to 14, excluding 3. -STATIC mp_obj_t pyb_timer_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_timer_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/teensy/uart.c b/teensy/uart.c index 8b73d733ffb6fe9884247267e44d393b93b87aa0..b4c0a4d5b62ceb14ce54086bfaa8c1387937ed72 100644 --- a/teensy/uart.c +++ b/teensy/uart.c @@ -306,7 +306,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, uint n_args, const mp /// - `UART(6)` is on `YA`: `(TX, RX) = (Y1, Y2) = (PC6, PC7)` /// - `UART(3)` is on `YB`: `(TX, RX) = (Y9, Y10) = (PB10, PB11)` /// - `UART(2)` is on: `(TX, RX) = (X3, X4) = (PA2, PA3)` -STATIC mp_obj_t pyb_uart_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { +STATIC mp_obj_t pyb_uart_make_new(const mp_obj_type_t *type, uint n_args, uint n_kw, const mp_obj_t *args) { // check arguments mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); diff --git a/unix/file.c b/unix/file.c index 2d3eb7b5a215aae5967a9324bb1b42d4545b9e5e..9ce5b6978436b208884d72debde615317a0c5172 100644 --- a/unix/file.c +++ b/unix/file.c @@ -202,10 +202,10 @@ STATIC mp_obj_t fdfile_open(const mp_obj_type_t *type, mp_arg_val_t *args) { return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t fdfile_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t fdfile_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_val_t arg_vals[FILE_OPEN_NUM_ARGS]; mp_arg_parse_all_kw_array(n_args, n_kw, args, FILE_OPEN_NUM_ARGS, file_open_args, arg_vals); - return fdfile_open(MP_OBJ_TO_PTR(type_in), arg_vals); + return fdfile_open(type, arg_vals); } STATIC const mp_rom_map_elem_t rawfile_locals_dict_table[] = { diff --git a/unix/modffi.c b/unix/modffi.c index 337f7a7b7ce3f5289561c8bbdaf4916da48ebd02..86a0b4483f2fc7111eb5d768a7aad2c134ce11c6 100644 --- a/unix/modffi.c +++ b/unix/modffi.c @@ -301,7 +301,7 @@ STATIC mp_obj_t ffimod_addr(mp_obj_t self_in, mp_obj_t symname_in) { } MP_DEFINE_CONST_FUN_OBJ_2(ffimod_addr_obj, ffimod_addr); -STATIC mp_obj_t ffimod_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t ffimod_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)n_args; (void)n_kw; @@ -315,7 +315,7 @@ STATIC mp_obj_t ffimod_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, co nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno))); } mp_obj_ffimod_t *o = m_new_obj(mp_obj_ffimod_t); - o->base.type = MP_OBJ_TO_PTR(type_in); + o->base.type = type; o->handle = mod; return MP_OBJ_FROM_PTR(o); } @@ -478,7 +478,7 @@ STATIC const mp_obj_type_t opaque_type = { */ STATIC mp_obj_t mod_ffi_open(size_t n_args, const mp_obj_t *args) { - return ffimod_make_new((mp_obj_t)&ffimod_type, n_args, 0, args); + return ffimod_make_new(&ffimod_type, n_args, 0, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_ffi_open_obj, 1, 2, mod_ffi_open); diff --git a/unix/modsocket.c b/unix/modsocket.c index a9bb2e09ce010dd006a95306906f6fadf78a7ca1..8af229cde40155dd86b3d023ff5613e5866cc0c5 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -313,7 +313,7 @@ STATIC mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 3, socket_makefile); -STATIC mp_obj_t socket_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; (void)n_kw;