wip: continuing compilation fixes; mp_obj_alloc everywhere

This commit is contained in:
Dan Halbert 2023-08-07 20:45:57 -04:00
parent 465d1c673e
commit 0d2c3c3f08
228 changed files with 377 additions and 544 deletions

View File

@ -82,28 +82,23 @@ STATIC void add_generic_services(bleio_adapter_obj_t *adapter) {
// Generic Access Service setup.
bleio_uuid_obj_t *generic_access_service_uuid = m_new_obj(bleio_uuid_obj_t);
generic_access_service_uuid->base.type = &bleio_uuid_type;
bleio_uuid_obj_t *generic_access_service_uuid = mp_obj_malloc(bleio_uuid_obj_t, &bleio_uuid_type);
common_hal_bleio_uuid_construct(generic_access_service_uuid, 0x1800, NULL);
bleio_uuid_obj_t *device_name_characteristic_uuid = m_new_obj(bleio_uuid_obj_t);
device_name_characteristic_uuid->base.type = &bleio_uuid_type;
bleio_uuid_obj_t *device_name_characteristic_uuid = mp_obj_malloc(bleio_uuid_obj_t, &bleio_uuid_type);
common_hal_bleio_uuid_construct(device_name_characteristic_uuid, 0x2A00, NULL);
bleio_uuid_obj_t *appearance_characteristic_uuid = m_new_obj(bleio_uuid_obj_t);
appearance_characteristic_uuid->base.type = &bleio_uuid_type;
bleio_uuid_obj_t *appearance_characteristic_uuid = mp_obj_malloc(bleio_uuid_obj_t, &bleio_uuid_type);
common_hal_bleio_uuid_construct(appearance_characteristic_uuid, 0x2A01, NULL);
// Not implemented:
// Peripheral Preferred Connection Parameters
// Central Address Resolution
bleio_service_obj_t *generic_access_service = m_new_obj(bleio_service_obj_t);
generic_access_service->base.type = &bleio_service_type;
bleio_service_obj_t *generic_access_service = mp_obj_malloc(bleio_service_obj_t, &bleio_service_type);
common_hal_bleio_service_construct(generic_access_service, generic_access_service_uuid, false);
adapter->device_name_characteristic = m_new_obj(bleio_characteristic_obj_t);
adapter->device_name_characteristic->base.type = &bleio_characteristic_type;
adapter->device_name_characteristic = mp_obj_malloc(bleio_characteristic_obj_t, &bleio_characteristic_type);
char generic_name[] = { 'C', 'I', 'R', 'C', 'U', 'I', 'T', 'P', 'Y', 'n', 'n', 'n', 'n' };
mp_buffer_info_t generic_name_bufinfo = {
@ -132,8 +127,7 @@ STATIC void add_generic_services(bleio_adapter_obj_t *adapter) {
.len = sizeof(zero_16),
};
adapter->appearance_characteristic = m_new_obj(bleio_characteristic_obj_t);
adapter->appearance_characteristic->base.type = &bleio_characteristic_type;
adapter->appearance_characteristic = mp_obj_malloc(bleio_characteristic_obj_t, &bleio_characteristic_type);
common_hal_bleio_characteristic_construct(
adapter->appearance_characteristic,
@ -151,20 +145,16 @@ STATIC void add_generic_services(bleio_adapter_obj_t *adapter) {
// Generic Attribute Service setup.
bleio_uuid_obj_t *generic_attribute_service_uuid = m_new_obj(bleio_uuid_obj_t);
generic_attribute_service_uuid->base.type = &bleio_uuid_type;
bleio_uuid_obj_t *generic_attribute_service_uuid = mp_obj_malloc(bleio_uuid_obj_t, &bleio_uuid_type);
common_hal_bleio_uuid_construct(generic_attribute_service_uuid, 0x1801, NULL);
bleio_uuid_obj_t *service_changed_characteristic_uuid = m_new_obj(bleio_uuid_obj_t);
service_changed_characteristic_uuid->base.type = &bleio_uuid_type;
bleio_uuid_obj_t *service_changed_characteristic_uuid = mp_obj_malloc(bleio_uuid_obj_t, &bleio_uuid_type);
common_hal_bleio_uuid_construct(service_changed_characteristic_uuid, 0x2A05, NULL);
bleio_service_obj_t *generic_attribute_service = m_new_obj(bleio_service_obj_t);
generic_attribute_service->base.type = &bleio_service_type;
bleio_service_obj_t *generic_attribute_service = mp_obj_malloc(bleio_service_obj_t, &bleio_service_type);
common_hal_bleio_service_construct(generic_attribute_service, generic_attribute_service_uuid, false);
adapter->service_changed_characteristic = m_new_obj(bleio_characteristic_obj_t);
adapter->service_changed_characteristic->base.type = &bleio_characteristic_type;
adapter->service_changed_characteristic = mp_obj_malloc(bleio_characteristic_obj_t, &bleio_characteristic_type);
uint32_t zero_32 = 0;
mp_buffer_info_t zero_32_value = {
@ -416,8 +406,7 @@ bleio_address_obj_t *common_hal_bleio_adapter_get_address(bleio_adapter_obj_t *s
bt_addr_t addr;
hci_check_error(hci_read_bd_addr(&addr));
bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t);
address->base.type = &bleio_address_type;
bleio_address_obj_t *address = mp_obj_malloc(bleio_address_obj_t, &bleio_address_type);
common_hal_bleio_address_construct(address, addr.val, BT_ADDR_LE_PUBLIC);
return address;

View File

@ -453,8 +453,7 @@ void common_hal_bleio_connection_set_connection_interval(bleio_connection_intern
// for (size_t i = 0; i < response->count; ++i) {
// ble_gattc_service_t *gattc_service = &response->services[i];
// bleio_service_obj_t *service = m_new_obj(bleio_service_obj_t);
// service->base.type = &bleio_service_type;
// bleio_service_obj_t *service = mp_obj_malloc(bleio_service_obj_t, &bleio_service_type);
// // Initialize several fields at once.
// bleio_service_from_connection(service, bleio_connection_new_from_internal(connection));
@ -466,8 +465,7 @@ void common_hal_bleio_connection_set_connection_interval(bleio_connection_intern
// if (gattc_service->uuid.type != BLE_UUID_TYPE_UNKNOWN) {
// // Known service UUID.
// bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t);
// uuid->base.type = &bleio_uuid_type;
// bleio_uuid_obj_t *uuid = mp_obj_malloc(bleio_uuid_obj_t, &bleio_uuid_type);
// bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_service->uuid);
// service->uuid = uuid;
// } else {
@ -491,15 +489,14 @@ void common_hal_bleio_connection_set_connection_interval(bleio_connection_intern
// for (size_t i = 0; i < response->count; ++i) {
// ble_gattc_char_t *gattc_char = &response->chars[i];
// bleio_characteristic_obj_t *characteristic = m_new_obj(bleio_characteristic_obj_t);
// characteristic->base.type = &bleio_characteristic_type;
// bleio_characteristic_obj_t *characteristic =
// mp_obj_malloc(bleio_characteristic_obj_t, &bleio_characteristic_type);
// bleio_uuid_obj_t *uuid = NULL;
// if (gattc_char->uuid.type != BLE_UUID_TYPE_UNKNOWN) {
// // Known characteristic UUID.
// uuid = m_new_obj(bleio_uuid_obj_t);
// uuid->base.type = &bleio_uuid_type;
// uuid = mp_obj_malloc(bleio_uuid_obj_t, &bleio_uuid_type);
// bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_char->uuid);
// } else {
// // The discovery response contained a 128-bit UUID that has not yet been registered with the
@ -557,15 +554,13 @@ void common_hal_bleio_connection_set_connection_interval(bleio_connection_intern
// break;
// }
// bleio_descriptor_obj_t *descriptor = m_new_obj(bleio_descriptor_obj_t);
// descriptor->base.type = &bleio_descriptor_type;
// bleio_descriptor_obj_t *descriptor = mp_obj_malloc(bleio_descriptor_obj_t, &bleio_descriptor_type);
// bleio_uuid_obj_t *uuid = NULL;
// if (gattc_desc->uuid.type != BLE_UUID_TYPE_UNKNOWN) {
// // Known descriptor UUID.
// uuid = m_new_obj(bleio_uuid_obj_t);
// uuid->base.type = &bleio_uuid_type;
// uuid = mp_obj_malloc(bleio_uuid_obj_t, &bleio_uuid_type);
// bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_desc->uuid);
// } else {
// // The discovery response contained a 128-bit UUID that has not yet been registered with the
@ -750,8 +745,7 @@ mp_obj_t bleio_connection_new_from_internal(bleio_connection_internal_t *interna
if (internal->connection_obj != mp_const_none) {
return internal->connection_obj;
}
bleio_connection_obj_t *connection = m_new_obj(bleio_connection_obj_t);
connection->base.type = &bleio_connection_type;
bleio_connection_obj_t *connection = mp_obj_malloc(bleio_connection_obj_t, &bleio_connection_type);
connection->connection = internal;
internal->connection_obj = connection;

View File

@ -101,8 +101,7 @@ void common_hal_bleio_service_add_characteristic(bleio_service_obj_t *self,
if (characteristic->props & (CHAR_PROP_NOTIFY | CHAR_PROP_INDICATE)) {
// We need a CCCD if this characteristic is doing notify or indicate.
bleio_descriptor_obj_t *cccd = m_new_obj(bleio_descriptor_obj_t);
cccd->base.type = &bleio_descriptor_type;
bleio_descriptor_obj_t *cccd = mp_obj_malloc(bleio_descriptor_obj_t, &bleio_descriptor_type);
uint16_t zero = 0;
mp_buffer_info_t zero_cccd_value = {

View File

@ -382,6 +382,6 @@ const mp_obj_module_t mp_module_uhashlib = {
.globals = (mp_obj_dict_t *)&mp_module_uhashlib_globals,
};
MP_REGISTER_MODULE(MP_QSTR_uhashlib, mp_module_uhashlib, MICROPY_PY_UHASHLIB);
MP_REGISTER_MODULE(MP_QSTR_uhashlib, mp_module_uhashlib);
#endif // MICROPY_PY_UHASHLIB

View File

@ -57,4 +57,4 @@ const mp_obj_module_t samd_module = {
.globals = (mp_obj_dict_t *)&samd_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_samd, samd_module, CIRCUITPY_SAMD);
MP_REGISTER_MODULE(MP_QSTR_samd, samd_module);

View File

@ -127,4 +127,4 @@ const mp_obj_module_t _bhb_user_cmodule = {
.globals = (mp_obj_dict_t *)&_bhb_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR__bhb, _bhb_user_cmodule, MODULE_BHB_ENABLED);
MP_REGISTER_MODULE(MP_QSTR__bhb, _bhb_user_cmodule);

View File

@ -368,8 +368,8 @@ mp_obj_t common_hal_canio_listener_receive(canio_listener_obj_t *self) {
int index = self->hw->RXFS.bit.F0GI;
canio_can_rx_fifo_t *hw_message = &self->fifo[index];
bool rtr = hw_message->rxf0.bit.RTR;
canio_message_obj_t *message = m_new_obj(canio_message_obj_t);
message->base.type = rtr ? &canio_remote_transmission_request_type : &canio_message_type;
canio_message_obj_t *message =
mp_obj_malloc(canio_message_obj_t, rtr ? &canio_remote_transmission_request_type : &canio_message_type);
message->extended = hw_message->rxf0.bit.XTD;
if (message->extended) {
message->id = hw_message->rxf0.bit.ID;

View File

@ -45,4 +45,4 @@ const mp_obj_module_t videocore_module = {
.globals = (mp_obj_dict_t *)&videocore_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_videocore, videocore_module, CIRCUITPY_VIDEOCORE);
MP_REGISTER_MODULE(MP_QSTR_videocore, videocore_module);

View File

@ -143,8 +143,7 @@ STATIC mp_obj_t espcamera_camera_make_new(const mp_obj_type_t *type, size_t n_ar
mp_int_t jpeg_quality = mp_arg_validate_int_range(args[ARG_jpeg_quality].u_int, 2, 55, MP_QSTR_jpeg_quality);
mp_int_t framebuffer_count = mp_arg_validate_int_range(args[ARG_framebuffer_count].u_int, 1, 2, MP_QSTR_framebuffer_count);
espcamera_camera_obj_t *self = m_new_obj(espcamera_camera_obj_t);
self->base.type = &espcamera_camera_type;
espcamera_camera_obj_t *self = mp_obj_malloc(espcamera_camera_obj_t, &espcamera_camera_type);
common_hal_espcamera_camera_construct(
self,
data_pins,

View File

@ -285,4 +285,4 @@ const mp_obj_module_t espcamera_module = {
.globals = (mp_obj_dict_t *)&espcamera_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_espcamera, espcamera_module, CIRCUITPY_ESPCAMERA);
MP_REGISTER_MODULE(MP_QSTR_espcamera, espcamera_module);

View File

@ -78,8 +78,7 @@ STATIC mp_obj_t espnow_make_new(const mp_obj_type_t *type, size_t n_args, size_t
}
// Allocate a new object
self = m_new_obj(espnow_obj_t);
self->base.type = &espnow_type;
self = mp_obj_malloc(espnow_obj_t, &espnow_type);
// Construct the object
common_hal_espnow_construct(self, args[ARG_buffer_size].u_int, args[ARG_phy_rate].u_int);

View File

@ -65,8 +65,7 @@ STATIC mp_obj_t espnow_peer_make_new(const mp_obj_type_t *type, size_t n_args, s
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
espnow_peer_obj_t *self = m_new_obj(espnow_peer_obj_t);
self->base.type = &espnow_peer_type;
espnow_peer_obj_t *self = mp_obj_malloc(espnow_peer_obj_t, &espnow_peer_type);
self->peer_info = (esp_now_peer_info_t) {
.channel = 0,
.ifidx = WIFI_IF_STA,

View File

@ -118,8 +118,7 @@ STATIC mp_obj_t espnow_peers_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_b
}
espnow_peers_obj_t *espnow_peers_new(void) {
espnow_peers_obj_t *self = m_new_obj(espnow_peers_obj_t);
self->base.type = &espnow_peers_type;
espnow_peers_obj_t *self = mp_obj_malloc(espnow_peers_obj_t, &espnow_peers_type);
self->list = mp_obj_new_list(0, NULL);
return self;
}

View File

@ -91,4 +91,4 @@ const mp_obj_module_t espnow_module = {
.globals = (mp_obj_dict_t *)&espnow_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_espnow, espnow_module, CIRCUITPY_ESPNOW);
MP_REGISTER_MODULE(MP_QSTR_espnow, espnow_module);

View File

@ -52,8 +52,7 @@ STATIC mp_obj_t espulp_ulp_make_new(const mp_obj_type_t *type, size_t n_args, si
const espulp_architecture_t arch = cp_enum_value(&espulp_architecture_type, args[ARG_arch].u_obj, MP_QSTR_arch);
espulp_ulp_obj_t *self = m_new_obj(espulp_ulp_obj_t);
self->base.type = &espulp_ulp_type;
espulp_ulp_obj_t *self = mp_obj_malloc(espulp_ulp_obj_t, &espulp_ulp_type);
common_hal_espulp_ulp_construct(self, arch);

View File

@ -50,8 +50,7 @@ STATIC mp_obj_t espulp_ulpalarm_make_new(const mp_obj_type_t *type, size_t n_arg
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
espulp_ulpalarm_obj_t *self = m_new_obj(espulp_ulpalarm_obj_t);
self->base.type = &espulp_ulpalarm_type;
espulp_ulpalarm_obj_t *self = mp_obj_malloc(espulp_ulpalarm_obj_t, &espulp_ulpalarm_type);
espulp_ulp_obj_t *ulp = mp_arg_validate_type(args[ARG_ulp].u_obj, &espulp_ulp_type, MP_QSTR_ulp);

View File

@ -91,4 +91,4 @@ const mp_obj_module_t espulp_module = {
.globals = (mp_obj_dict_t *)&espulp_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_espulp, espulp_module, CIRCUITPY_ESPULP);
MP_REGISTER_MODULE(MP_QSTR_espulp, espulp_module);

View File

@ -142,8 +142,7 @@ bleio_address_obj_t *common_hal_bleio_adapter_get_address(bleio_adapter_obj_t *s
return NULL;
}
bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t);
address->base.type = &bleio_address_type;
bleio_address_obj_t *address = mp_obj_malloc(bleio_address_obj_t, &bleio_address_type);
common_hal_bleio_address_construct(address, address_bytes, BLEIO_ADDRESS_TYPE_RANDOM_STATIC);
return address;
}

View File

@ -176,12 +176,7 @@ STATIC int _discovered_service_cb(uint16_t conn_handle,
if (_last_discovery_status != BLE_ERR_SUCCESS) {
return 0;
}
bleio_service_obj_t *service = m_new_obj(bleio_service_obj_t);
if (service == NULL) {
_last_discovery_status = BLE_ERR_MEM_CAPACITY;
return 0;
}
service->base.type = &bleio_service_type;
bleio_service_obj_t *service = mp_obj_malloc(bleio_service_obj_t, &bleio_service_type);
// Initialize several fields at once.
bleio_service_from_connection(service, bleio_connection_new_from_internal(self));
@ -191,12 +186,8 @@ STATIC int _discovered_service_cb(uint16_t conn_handle,
service->end_handle = svc->end_handle;
service->handle = svc->start_handle;
bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t);
if (uuid == NULL) {
_last_discovery_status = BLE_ERR_MEM_CAPACITY;
return 0;
}
uuid->base.type = &bleio_uuid_type;
bleio_uuid_obj_t *uuid = mp_obj_malloc(bleio_uuid_obj_t, &bleio_uuid_type);
uuid->nimble_ble_uuid = svc->uuid;
service->uuid = uuid;
@ -224,20 +215,12 @@ STATIC int _discovered_characteristic_cb(uint16_t conn_handle,
return 0;
}
bleio_characteristic_obj_t *characteristic = m_new_obj(bleio_characteristic_obj_t);
if (characteristic == NULL) {
_last_discovery_status = BLE_ERR_MEM_CAPACITY;
return 0;
}
characteristic->base.type = &bleio_characteristic_type;
bleio_characteristic_obj_t *characteristic =
mp_obj_malloc(bleio_characteristic_obj_t, &bleio_characteristic_type);
// Known characteristic UUID.
bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t);
if (uuid == NULL) {
_last_discovery_status = BLE_ERR_MEM_CAPACITY;
return 0;
}
uuid->base.type = &bleio_uuid_type;
bleio_uuid_obj_t *uuid = mp_obj_malloc(bleio_uuid_obj_t, &bleio_uuid_type);
uuid->nimble_ble_uuid = chr->uuid;
bleio_characteristic_properties_t props =
@ -301,19 +284,9 @@ STATIC int _discovered_descriptor_cb(uint16_t conn_handle,
break;
}
bleio_descriptor_obj_t *descriptor = m_new_obj(bleio_descriptor_obj_t);
if (descriptor == NULL) {
_last_discovery_status = BLE_ERR_MEM_CAPACITY;
return 0;
}
descriptor->base.type = &bleio_descriptor_type;
bleio_descriptor_obj_t *descriptor = mp_obj_malloc(bleio_descriptor_obj_t, &bleio_descriptor_type);
bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t);
if (uuid == NULL) {
_last_discovery_status = BLE_ERR_MEM_CAPACITY;
return 0;
}
uuid->base.type = &bleio_uuid_type;
bleio_uuid_obj_t *uuid = mp_obj_malloc(bleio_uuid_obj_t, &bleio_uuid_type);
uuid->nimble_ble_uuid = dsc->uuid;
common_hal_bleio_descriptor_construct(
@ -438,8 +411,8 @@ mp_obj_t bleio_connection_new_from_internal(bleio_connection_internal_t *interna
if (internal->connection_obj != mp_const_none) {
return internal->connection_obj;
}
bleio_connection_obj_t *connection = m_new_obj(bleio_connection_obj_t);
connection->base.type = &bleio_connection_type;
bleio_connection_obj_t *connection = mp_obj_malloc(bleio_connection_obj_t, &bleio_connection_type);
connection->connection = internal;
internal->connection_obj = connection;

View File

@ -162,8 +162,8 @@ mp_obj_t common_hal_canio_listener_receive(canio_listener_obj_t *self) {
bool rtr = self->message_in.rtr;
int dlc = self->message_in.data_length_code;
canio_message_obj_t *message = m_new_obj(canio_message_obj_t);
message->base.type = rtr ? &canio_remote_transmission_request_type : &canio_message_type;
canio_message_obj_t *message =
mp_obj_malloc(canio_message_obj_t,rtr ? &canio_remote_transmission_request_type : &canio_message_type);
message->extended = self->message_in.extd;
message->id = self->message_in.identifier;
message->size = dlc;

View File

@ -198,4 +198,4 @@ void raise_esp_error(esp_err_t err) {
mp_raise_msg_varg(exception_type, translate("%s error 0x%x"), group, err);
}
MP_REGISTER_MODULE(MP_QSTR_espidf, espidf_module, CIRCUITPY_ESPIDF);
MP_REGISTER_MODULE(MP_QSTR_espidf, espidf_module);

View File

@ -175,8 +175,7 @@ mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self, u
}
set_mode_station(self, true);
wifi_scannednetworks_obj_t *scan = m_new_obj(wifi_scannednetworks_obj_t);
scan->base.type = &wifi_scannednetworks_type;
wifi_scannednetworks_obj_t *scan = mp_obj_malloc(wifi_scannednetworks_obj_t, &wifi_scannednetworks_type);
self->current_scan = scan;
scan->current_channel_index = 0;
scan->start_channel = start_channel;
@ -366,8 +365,7 @@ mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self) {
return mp_const_none;
}
wifi_network_obj_t *ap_info = m_new_obj(wifi_network_obj_t);
ap_info->base.type = &wifi_network_type;
wifi_network_obj_t *ap_info = mp_obj_malloc(wifi_network_obj_t, &wifi_network_type);
// From esp_wifi.h, the possible return values (typos theirs):
// ESP_OK: succeed
// ESP_ERR_WIFI_CONN: The station interface don't initialized

View File

@ -115,8 +115,7 @@ mp_obj_t common_hal_wifi_scannednetworks_next(wifi_scannednetworks_obj_t *self)
self->channel_scan_in_progress = false;
}
wifi_network_obj_t *entry = m_new_obj(wifi_network_obj_t);
entry->base.type = &wifi_network_type;
wifi_network_obj_t *entry = mp_obj_malloc(wifi_network_obj_t, &wifi_network_type);
memcpy(&entry->record, &self->results[self->current_result], sizeof(wifi_ap_record_t));
self->current_result++;

View File

@ -42,9 +42,6 @@
#define BOARD_HAS_CRYSTAL 1
// Take 1k RAM to save 1k flash.
#define CIRCUITPY_PRECOMPUTE_QSTR_ATTR (0)
// Reduce nRF SoftRadio memory usage
#define BLEIO_VS_UUID_COUNT 10
#define BLEIO_HVN_TX_QUEUE_SIZE 2

View File

@ -37,9 +37,6 @@
#define CIRCUITPY_BLE_CONFIG_SIZE (12 * 1024)
// Take 1k RAM to save 1k flash.
#define CIRCUITPY_PRECOMPUTE_QSTR_ATTR (0)
// Reduce nRF SoftRadio memory usage
#define BLEIO_VS_UUID_COUNT 10
#define BLEIO_HVN_TX_QUEUE_SIZE 2

View File

@ -429,8 +429,7 @@ bleio_address_obj_t *common_hal_bleio_adapter_get_address(bleio_adapter_obj_t *s
ble_gap_addr_t local_address;
get_address(self, &local_address);
bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t);
address->base.type = &bleio_address_type;
bleio_address_obj_t *address = mp_obj_malloc(bleio_address_obj_t, &bleio_address_type);
common_hal_bleio_address_construct(address, local_address.addr, local_address.addr_type);
return address;

View File

@ -466,8 +466,7 @@ STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *res
for (size_t i = 0; i < response->count; ++i) {
ble_gattc_service_t *gattc_service = &response->services[i];
bleio_service_obj_t *service = m_new_obj(bleio_service_obj_t);
service->base.type = &bleio_service_type;
bleio_service_obj_t *service = mp_obj_malloc(bleio_service_obj_t, &bleio_service_type);
// Initialize several fields at once.
bleio_service_from_connection(service, bleio_connection_new_from_internal(connection));
@ -479,8 +478,7 @@ STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *res
if (gattc_service->uuid.type != BLE_UUID_TYPE_UNKNOWN) {
// Known service UUID.
bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t);
uuid->base.type = &bleio_uuid_type;
bleio_uuid_obj_t *uuid = mp_obj_malloc(bleio_uuid_obj_t, &bleio_uuid_type);
bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_service->uuid);
service->uuid = uuid;
} else {
@ -504,15 +502,14 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio
for (size_t i = 0; i < response->count; ++i) {
ble_gattc_char_t *gattc_char = &response->chars[i];
bleio_characteristic_obj_t *characteristic = m_new_obj(bleio_characteristic_obj_t);
characteristic->base.type = &bleio_characteristic_type;
bleio_characteristic_obj_t *characteristic =
mp_obj_malloc(bleio_characteristic_obj_t, &bleio_characteristic_type);
bleio_uuid_obj_t *uuid = NULL;
if (gattc_char->uuid.type != BLE_UUID_TYPE_UNKNOWN) {
// Known characteristic UUID.
uuid = m_new_obj(bleio_uuid_obj_t);
uuid->base.type = &bleio_uuid_type;
uuid = mp_obj_malloc(bleio_uuid_obj_t, &bleio_uuid_type);
bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_char->uuid);
} else {
// The discovery response contained a 128-bit UUID that has not yet been registered with the
@ -571,15 +568,13 @@ STATIC void on_desc_discovery_rsp(ble_gattc_evt_desc_disc_rsp_t *response, bleio
break;
}
bleio_descriptor_obj_t *descriptor = m_new_obj(bleio_descriptor_obj_t);
descriptor->base.type = &bleio_descriptor_type;
bleio_descriptor_obj_t *descriptor = mp_obj_malloc(bleio_descriptor_obj_t, &bleio_descriptor_type);
bleio_uuid_obj_t *uuid = NULL;
if (gattc_desc->uuid.type != BLE_UUID_TYPE_UNKNOWN) {
// Known descriptor UUID.
uuid = m_new_obj(bleio_uuid_obj_t);
uuid->base.type = &bleio_uuid_type;
uuid = mp_obj_malloc(bleio_uuid_obj_t, &bleio_uuid_type);
bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_desc->uuid);
} else {
// The discovery response contained a 128-bit UUID that has not yet been registered with the
@ -763,8 +758,7 @@ mp_obj_t bleio_connection_new_from_internal(bleio_connection_internal_t *interna
if (internal->connection_obj != mp_const_none) {
return internal->connection_obj;
}
bleio_connection_obj_t *connection = m_new_obj(bleio_connection_obj_t);
connection->base.type = &bleio_connection_type;
bleio_connection_obj_t *connection = mp_obj_malloc(bleio_connection_obj_t, &bleio_connection_type);
connection->connection = internal;
internal->connection_obj = connection;

View File

@ -155,4 +155,4 @@ const mp_obj_module_t cyw43_module = {
.globals = (mp_obj_dict_t *)&cyw43_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_cyw43, cyw43_module, CIRCUITPY_CYW43);
MP_REGISTER_MODULE(MP_QSTR_cyw43, cyw43_module);

View File

@ -45,4 +45,4 @@ const mp_obj_module_t picodvi_module = {
.globals = (mp_obj_dict_t *)&picodvi_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_picodvi, picodvi_module, CIRCUITPY_PICODVI);
MP_REGISTER_MODULE(MP_QSTR_picodvi, picodvi_module);

View File

@ -150,8 +150,7 @@
//| ...
STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
rp2pio_statemachine_obj_t *self = m_new_obj(rp2pio_statemachine_obj_t);
self->base.type = &rp2pio_statemachine_type;
rp2pio_statemachine_obj_t *self = mp_obj_malloc(rp2pio_statemachine_obj_t, &rp2pio_statemachine_type);
enum { ARG_program, ARG_frequency, ARG_init,
ARG_first_out_pin, ARG_out_pin_count, ARG_initial_out_pin_state, ARG_initial_out_pin_direction,
ARG_first_in_pin, ARG_in_pin_count,

View File

@ -72,4 +72,4 @@ const mp_obj_module_t rp2pio_module = {
.globals = (mp_obj_dict_t *)&rp2pio_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_rp2pio, rp2pio_module, CIRCUITPY_RP2PIO);
MP_REGISTER_MODULE(MP_QSTR_rp2pio, rp2pio_module);

View File

@ -137,8 +137,7 @@ mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self, u
if (!common_hal_wifi_radio_get_enabled(self)) {
mp_raise_RuntimeError(translate("Wifi is not enabled"));
}
wifi_scannednetworks_obj_t *scan = m_new_obj(wifi_scannednetworks_obj_t);
scan->base.type = &wifi_scannednetworks_type;
wifi_scannednetworks_obj_t *scan = mp_obj_malloc(wifi_scannednetworks_obj_t, &wifi_scannednetworks_type);
mp_obj_t args[] = { mp_const_empty_tuple, MP_OBJ_NEW_SMALL_INT(16) };
scan->results = mp_type_deque.make_new(&mp_type_deque, 2, 0, args);
self->current_scan = scan;

View File

@ -97,8 +97,7 @@ mp_obj_t common_hal_wifi_scannednetworks_next(wifi_scannednetworks_obj_t *self)
}
wifi_network_obj_t *entry = m_new_obj(wifi_network_obj_t);
entry->base.type = &wifi_network_type;
wifi_network_obj_t *entry = mp_obj_malloc(wifi_network_obj_t, &wifi_network_type);
scan_result_get(&entry->record);
return MP_OBJ_FROM_PTR(entry);

View File

@ -211,4 +211,4 @@ const mp_obj_module_t sensor_module = {
.globals = (mp_obj_dict_t *)&sensor_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_sensor, sensor_module,1);
MP_REGISTER_MODULE(MP_QSTR_sensor, sensor_module);

View File

@ -127,8 +127,7 @@ bleio_address_obj_t *common_hal_bleio_adapter_get_address(bleio_adapter_obj_t *s
return NULL;
}
address = m_new_obj(bleio_address_obj_t);
address->base.type = &bleio_address_type;
address = mp_obj_malloc(bleio_address_obj_t, &bleio_address_type);
common_hal_bleio_address_construct(address, get_address.addr,
BLEIO_ADDRESS_TYPE_RANDOM_STATIC);
return address;

View File

@ -251,8 +251,7 @@ mp_obj_t bleio_connection_new_from_internal(
if (internal->connection_obj != mp_const_none) {
return internal->connection_obj;
}
connection = m_new_obj(bleio_connection_obj_t);
connection->base.type = &bleio_connection_type;
connection = mp_obj_malloc(bleio_connection_obj_t, &bleio_connection_type);
connection->connection = internal;
internal->connection_obj = connection;

View File

@ -183,17 +183,12 @@ void sl_bt_on_event(sl_bt_msg_t *evt) {
osMutexAcquire(bluetooth_connection_mutex_id, osWaitForever);
connection = bleio_conn_handle_to_connection(
evt->data.evt_gatt_service.connection);
service = m_new_obj(bleio_service_obj_t);
if (NULL == service) {
mp_raise_bleio_BluetoothError(
translate("Create new service obj fail"));
}
service->base.type = &bleio_service_type;
service = m_new_obj(bleio_service_obj_t, &bleio_service_type);
bleio_service_from_connection(service,
bleio_connection_new_from_internal(connection));
service->is_remote = true;
service->handle = evt->data.evt_gatt_service.service;
uuid = m_new_obj(bleio_uuid_obj_t);
uuid = m_new_obj_maybe(bleio_uuid_obj_t);
if (NULL == uuid) {
osMutexRelease(bluetooth_connection_mutex_id);
mp_raise_bleio_BluetoothError(
@ -231,21 +226,8 @@ void sl_bt_on_event(sl_bt_msg_t *evt) {
service =
MP_OBJ_TO_PTR(connection->remote_service_list->items[serv_idx - 1]);
characteristic = m_new_obj(bleio_characteristic_obj_t);
if (characteristic == NULL) {
mp_raise_bleio_BluetoothError(
translate("Create new characteristic obj fail."));
}
characteristic->base.type = &bleio_characteristic_type;
uuid = m_new_obj(bleio_uuid_obj_t);
if (uuid == NULL) {
mp_raise_bleio_BluetoothError(
translate("Create new characteristic uuid obj fail."));
break;
}
uuid->base.type = &bleio_uuid_type;
characteristic = mp_obj_malloc(bleio_characteristic_obj_t, &bleio_characteristic_type);
uuid = mp_obj_malloc(bleio_uuid_obj_t, &bleio_uuid_type);
if (UUID16_LEN == evt->data.evt_gatt_characteristic.uuid.len) {
uuid->efr_ble_uuid.uuid16.value &= 0x0000;
uuid->efr_ble_uuid.uuid16.value

View File

@ -285,8 +285,8 @@ mp_obj_t common_hal_canio_listener_receive(canio_listener_obj_t *self) {
uint32_t rdtr = self->mailbox->RDTR;
bool rtr = rir & CAN_RI0R_RTR;
canio_message_obj_t *message = m_new_obj(canio_message_obj_t);
message->base.type = rtr ? &canio_remote_transmission_request_type : &canio_message_type;
canio_message_obj_t *message =
mp_obj_malloc(canio_message_obj_t, rtr ? &canio_remote_transmission_request_type : &canio_message_type);
message->extended = rir & CAN_RI0R_IDE;
if (message->extended) {
message->id = rir >> 3;

View File

@ -89,4 +89,4 @@ const mp_obj_module_t displayio_module = {
.globals = (mp_obj_dict_t *)&displayio_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_displayio, displayio_module, CIRCUITPY_DISPLAYIO_UNIX);
MP_REGISTER_MODULE(MP_QSTR_displayio, displayio_module);

View File

@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George
* Copyright (c) 2013, 2014 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal

View File

@ -236,6 +236,7 @@ STATIC void do_load(mp_module_context_t *module_obj, vstr_t *file) {
}
#endif
}
#endif // MICROPY_MODULE_FROZEN
// If we support loading .mpy files then check if the file extension is of
@ -463,6 +464,7 @@ STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name,
// because the file will not exist.
}
//CIRCUITPY
// Loading a module thrashes the heap significantly so we explicitly clean up
// afterwards.
gc_collect();

View File

@ -214,7 +214,6 @@ typedef long mp_off_t;
#define mp_type_fileio mp_type_vfs_fat_fileio
#define mp_type_textio mp_type_vfs_fat_textio
#define mp_import_stat mp_vfs_import_stat
#define mp_builtin_open_obj mp_vfs_open_obj
@ -492,13 +491,6 @@ void background_callback_run_all(void);
#define CIRCUITPY_VERBOSE_BLE 0
// This trades ~1k flash space (1) for that much in RAM plus the cost to compute
// the values once on init (0). Only turn it off, when you really need the flash
// space and are willing to trade the RAM.
#ifndef CIRCUITPY_PRECOMPUTE_QSTR_ATTR
#define CIRCUITPY_PRECOMPUTE_QSTR_ATTR (1)
#endif
// Display the Blinka logo in the REPL on displayio displays.
#ifndef CIRCUITPY_REPL_LOGO
#define CIRCUITPY_REPL_LOGO (1)

View File

@ -37,38 +37,38 @@ mp_obj_fun_bc_t *make_fun_bc_long_lived(mp_obj_fun_bc_t *fun_bc, uint8_t max_dep
return fun_bc;
}
fun_bc->bytecode = gc_make_long_lived((byte *)fun_bc->bytecode);
fun_bc->globals = make_dict_long_lived(fun_bc->globals, max_depth - 1);
for (uint32_t i = 0; i < gc_nbytes(fun_bc->const_table) / sizeof(mp_obj_t); i++) {
// Skip things that aren't allocated on the heap (and hence have zero bytes.)
if (gc_nbytes(MP_OBJ_TO_PTR(fun_bc->const_table[i])) == 0) {
continue;
}
// Try to detect raw code.
mp_raw_code_t *raw_code = MP_OBJ_TO_PTR(fun_bc->const_table[i]);
if (raw_code->kind == MP_CODE_BYTECODE) {
raw_code->fun_data = gc_make_long_lived((byte *)raw_code->fun_data);
raw_code->const_table = gc_make_long_lived((byte *)raw_code->const_table);
}
((mp_uint_t *)fun_bc->const_table)[i] = (mp_uint_t)make_obj_long_lived(
(mp_obj_t)fun_bc->const_table[i], max_depth - 1);
fun_bc->context->module.globals = make_dict_long_lived(fun_bc->context->module.globals, max_depth - 1);
// for (uint32_t i = 0; i < gc_nbytes(fun_bc->const_table) / sizeof(mp_obj_t); i++) {
// // Skip things that aren't allocated on the heap (and hence have zero bytes.)
// if (gc_nbytes(MP_OBJ_TO_PTR(fun_bc->const_table[i])) == 0) {
// continue;
// }
// // Try to detect raw code.
// mp_raw_code_t *raw_code = MP_OBJ_TO_PTR(fun_bc->const_table[i]);
// if (raw_code->kind == MP_CODE_BYTECODE) {
// raw_code->fun_data = gc_make_long_lived((byte *)raw_code->fun_data);
// raw_code->const_table = gc_make_long_lived((byte *)raw_code->const_table);
// }
// ((mp_uint_t *)fun_bc->const_table)[i] = (mp_uint_t)make_obj_long_lived(
// (mp_obj_t)fun_bc->const_table[i], max_depth - 1);
}
fun_bc->const_table = gc_make_long_lived((mp_uint_t *)fun_bc->const_table);
// extra_args stores keyword only argument default values.
size_t words = gc_nbytes(fun_bc) / sizeof(mp_uint_t *);
// Functions (mp_obj_fun_bc_t) have four pointers (base, globals, bytecode and const_table)
// before the variable length extra_args so remove them from the length.
for (size_t i = 0; i < words - 4; i++) {
if (MP_OBJ_TO_PTR(fun_bc->extra_args[i]) == NULL) {
continue;
}
if (mp_obj_is_type(fun_bc->extra_args[i], &mp_type_dict)) {
fun_bc->extra_args[i] = MP_OBJ_FROM_PTR(make_dict_long_lived(MP_OBJ_TO_PTR(fun_bc->extra_args[i]), max_depth - 1));
} else {
fun_bc->extra_args[i] = make_obj_long_lived(fun_bc->extra_args[i], max_depth - 1);
}
// }
// fun_bc->const_table = gc_make_long_lived((mp_uint_t *)fun_bc->const_table);
// // extra_args stores keyword only argument default values.
// size_t words = gc_nbytes(fun_bc) / sizeof(mp_uint_t *);
// // Functions (mp_obj_fun_bc_t) have four pointers (base, globals, bytecode and const_table)
// // before the variable length extra_args so remove them from the length.
// for (size_t i = 0; i < words - 4; i++) {
// if (MP_OBJ_TO_PTR(fun_bc->extra_args[i]) == NULL) {
// continue;
// }
// if (mp_obj_is_type(fun_bc->extra_args[i], &mp_type_dict)) {
// fun_bc->extra_args[i] = MP_OBJ_FROM_PTR(make_dict_long_lived(MP_OBJ_TO_PTR(fun_bc->extra_args[i]), max_depth - 1));
// } else {
// fun_bc->extra_args[i] = make_obj_long_lived(fun_bc->extra_args[i], max_depth - 1);
// }
}
// }
return gc_make_long_lived(fun_bc);
}

View File

@ -45,7 +45,7 @@
// Allocates an object and also sets type, for mp_obj_malloc{,_var} macros.
void *mp_obj_malloc_helper(size_t num_bytes, const mp_obj_type_t *type) {
mp_obj_base_t *base = (mp_obj_base_t *)m_malloc(num_bytes);
mp_obj_base_t *base = (mp_obj_base_t *)m_malloc(num_bytes, false);
base->type = type;
return base;
}
@ -346,7 +346,7 @@ mp_obj_t mp_obj_equal_not_equal(mp_binary_op_t op, mp_obj_t o1, mp_obj_t o2) {
}
// Try calling __eq__.
mp_obj_t r = type->binary_op(MP_BINARY_OP_EQUAL, o1, o2);
mp_obj_t r = binary_op(MP_BINARY_OP_EQUAL, o1, o2);
if (r != MP_OBJ_NULL) {
if (op == MP_BINARY_OP_EQUAL) {
return r;

View File

@ -460,7 +460,7 @@ typedef struct _mp_rom_map_elem_t {
typedef struct _mp_map_t {
size_t all_keys_are_qstrs : 1;
size_t is_fixed : 1; // if set, table is fixed/read-only and can't be modified
size_t is_ordered : 1; / if set, table is an ordered array, not a hash map
size_t is_ordered : 1; // if set, table is an ordered array, not a hash map
size_t scanning : 1; // true if we're in the middle of scanning linked dictionaries,
// e.g., make_dict_long_lived()
size_t used : (8 * sizeof(size_t) - 4);
@ -611,6 +611,39 @@ struct _mp_obj_type_ext {
// One of disjoint protocols (interfaces), like mp_stream_p_t, etc.
const void *protocol;
};
struct _mp_obj_type_t {
// A type is an object so must start with this entry, which points to mp_type_type.
mp_obj_base_t base;
// Flags associated with this type.
uint16_t flags;
// The name of this type, a qstr.
uint16_t name;
// A dict mapping qstrs to objects local methods/constants/etc.
struct _mp_obj_dict_t *locals_dict;
// Corresponds to __new__ and __init__ special methods, to make an instance of the type.
mp_make_new_fun_t make_new;
// Corresponds to __repr__ and __str__ special methods.
mp_print_fun_t print;
// Implements load, store and delete attribute.
//
// dest[0] = MP_OBJ_NULL means load
// return: for fail, do nothing
// for fail but continue lookup in locals_dict, dest[1] = MP_OBJ_SENTINEL
// for attr, dest[0] = value
// for method, dest[0] = method, dest[1] = self
//
// dest[0,1] = {MP_OBJ_SENTINEL, MP_OBJ_NULL} means delete
// dest[0,1] = {MP_OBJ_SENTINEL, object} means store
// return: for fail, do nothing
// for success set dest[0] = MP_OBJ_NULL
mp_attr_fun_t attr;
// A pointer to the parents of this type:
// - 0 parents: pointer is NULL (object is implicitly the single parent)
@ -851,10 +884,6 @@ mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, const com
#endif
// Only use this string version from native MPY files with static error strings.
mp_obj_t mp_obj_new_exception_msg_str(const mp_obj_type_t *exc_type, const char *msg);
mp_obj_t mp_obj_new_fun_bc(mp_obj_t def_args, mp_obj_t def_kw_args, const byte *code, const mp_uint_t *const_table);
mp_obj_t mp_obj_new_fun_native(mp_obj_t def_args_in, mp_obj_t def_kw_args, const void *fun_data, const mp_uint_t *const_table);
mp_obj_t mp_obj_new_fun_viper(size_t n_args, const void *fun_data, mp_uint_t type_sig);
mp_obj_t mp_obj_new_fun_asm(size_t n_args, const void *fun_data, mp_uint_t type_sig);
mp_obj_t mp_obj_new_gen_wrap(mp_obj_t fun, bool is_coroutine);
mp_obj_t mp_obj_new_closure(mp_obj_t fun, size_t n_closed, const mp_obj_t *closed);
mp_obj_t mp_obj_new_tuple(size_t n, const mp_obj_t *items);
@ -928,6 +957,7 @@ bool mp_obj_exception_match(mp_obj_t exc, mp_const_obj_t exc_type);
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_traceback_obj(mp_obj_t self_in);
mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in);
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);
@ -1003,6 +1033,7 @@ void mp_obj_tuple_del(mp_obj_t self_in);
mp_int_t mp_obj_tuple_hash(mp_obj_t self_in);
// list
mp_obj_t mp_obj_list_clear(mp_obj_t self_in);
mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg);
mp_obj_t mp_obj_list_remove(mp_obj_t self_in, mp_obj_t value);
void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items);
@ -1022,7 +1053,7 @@ mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index);
mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value);
mp_obj_t mp_obj_dict_delete(mp_obj_t self_in, mp_obj_t key);
mp_obj_t mp_obj_dict_copy(mp_obj_t self_in);
static inline mp_map_t *mp_obj_dict_get_map(mp_obj_t dict) {
static MP_INLINE mp_map_t *mp_obj_dict_get_map(mp_obj_t dict) {
return &((mp_obj_dict_t *)MP_OBJ_TO_PTR(dict))->map;
}
@ -1082,9 +1113,8 @@ typedef struct _mp_obj_module_t {
mp_obj_base_t base;
mp_obj_dict_t *globals;
} mp_obj_module_t;
static inline mp_obj_dict_t *mp_obj_module_get_globals(mp_obj_t module) {
return ((mp_obj_module_t *)MP_OBJ_TO_PTR(module))->globals;
}
mp_obj_dict_t *mp_obj_module_get_globals(mp_obj_t self_in);
void mp_obj_module_set_globals(mp_obj_t self_in, mp_obj_dict_t *globals);
// check if given module object is a package
bool mp_obj_is_package(mp_obj_t module);

View File

@ -31,7 +31,8 @@
typedef struct _mp_obj_fun_bc_t {
mp_obj_base_t base;
const mp_module_context_t *context; // context within which this function was defined
// CIRCUITPY - Long-lived conversions need to write into context, so un-const the field.
/*const*/ mp_module_context_t *context; // context within which this function was defined
struct _mp_raw_code_t *const *child_table; // table of children
const byte *bytecode; // bytecode for the function
#if MICROPY_PY_SYS_SETTRACE

View File

@ -76,27 +76,23 @@ mp_uint_t qstr_compute_hash(const byte *data, size_t len) {
}
return hash;
}
#ifndef CIRCUITPY_PRECOMPUTE_QSTR_ATTR
#define CIRCUITPY_PRECOMPUTE_QSTR_ATTR (1)
#endif
#if CIRCUITPY_PRECOMPUTE_QSTR_ATTR == 1
const qstr_attr_t mp_qstr_const_attr[MP_QSTRnumber_of] = {
const qstr_hash_t mp_qstr_const_hashes[] = {
#ifndef NO_QSTR
#define QDEF(id, hash, len, str) hash,
#define TRANSLATION(id, length, compressed ...)
#include "genhdr/qstrdefs.generated.h"
#undef TRANSLATION
#undef QDEF
#endif
};
#else
qstr_attr_t mp_qstr_const_attr[MP_QSTRnumber_of];
#endif
const qstr_len_t mp_qstr_const_lengths[] = {
#ifndef NO_QSTR
#define QDEF(id, hash, len, str) len,
#define TRANSLATION(id, length, compressed ...)
#include "genhdr/qstrdefs.generated.h"
#undef TRANSLATION
#undef QDEF
#endif
};
@ -130,16 +126,6 @@ void qstr_init(void) {
MP_STATE_VM(last_pool) = (qstr_pool_t *)&CONST_POOL; // we won't modify the const_pool since it has no allocated room left
MP_STATE_VM(qstr_last_chunk) = NULL;
#if CIRCUITPY_PRECOMPUTE_QSTR_ATTR == 0
if (mp_qstr_const_attr[MP_QSTR_circuitpython].len == 0) {
for (size_t i = 0; i < mp_qstr_const_pool.len; i++) {
size_t len = strlen(mp_qstr_const_pool.qstrs[i]);
mp_qstr_const_attr[i].hash = qstr_compute_hash((const byte *)mp_qstr_const_pool.qstrs[i], len);
mp_qstr_const_attr[i].len = len;
}
}
#endif
#if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL
mp_thread_mutex_init(&MP_STATE_VM(qstr_mutex));
#endif
@ -170,7 +156,7 @@ STATIC qstr qstr_add(mp_uint_t hash, mp_uint_t len, const char *q_ptr) {
#endif
mp_uint_t pool_size = sizeof(qstr_pool_t)
+ (sizeof(const char *) + sizeof(qstr_hash_t) + sizeof(qstr_len_t)) * new_alloc;
qstr_pool_t *pool = (qstr_pool_t *)m_malloc_maybe(pool_size);
qstr_pool_t *pool = (qstr_pool_t *)m_malloc_maybe(pool_size, true);
if (pool == NULL) {
// Keep qstr_last_chunk consistent with qstr_pool_t: qstr_last_chunk is not scanned
// at garbage collection since it's reachable from a qstr_pool_t. And the caller of

View File

@ -39,8 +39,10 @@
enum {
#ifndef NO_QSTR
#define QDEF(id, hash, len, str) id,
#define TRANSLATION(english_id, number)
#include "genhdr/qstrdefs.generated.h"
#undef QDEF
#undef TRANSLATION
#endif
MP_QSTRnumber_of, // no underscore so it can't clash with any of the above
};

View File

@ -57,4 +57,4 @@ const mp_obj_module_t future_module = {
.globals = (mp_obj_dict_t *)&future_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR___future__, future_module, CIRCUITPY_FUTURE);
MP_REGISTER_MODULE(MP_QSTR___future__, future_module);

View File

@ -56,8 +56,7 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args,
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
bleio_address_obj_t *self = m_new_obj(bleio_address_obj_t);
self->base.type = &bleio_address_type;
bleio_address_obj_t *self = mp_obj_malloc(bleio_address_obj_t, &bleio_address_type);
const mp_obj_t address = args[ARG_address].u_obj;
mp_buffer_info_t buf_info;

View File

@ -141,8 +141,8 @@ STATIC mp_obj_t bleio_characteristic_add_to_service(size_t n_args, const mp_obj_
user_description = mp_obj_str_get_str(args[ARG_user_description].u_obj);
}
bleio_characteristic_obj_t *characteristic = m_new_obj(bleio_characteristic_obj_t);
characteristic->base.type = &bleio_characteristic_type;
bleio_characteristic_obj_t *characteristic =
m_new_obj(bleio_characteristic_obj_t, &bleio_characteristic_type);
// Range checking on max_length arg is done by the common_hal layer, because
// it may vary depending on underlying BLE implementation.

View File

@ -74,8 +74,8 @@ STATIC mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type,
const mp_int_t buffer_size = mp_arg_validate_int_min(args[ARG_buffer_size].u_int, 1, MP_QSTR_buffer_size);
bleio_characteristic_buffer_obj_t *self = m_new_obj(bleio_characteristic_buffer_obj_t);
self->base.type = &bleio_characteristic_buffer_type;
bleio_characteristic_buffer_obj_t *self =
mp_obj_malloc(bleio_characteristic_buffer_obj_t, &bleio_characteristic_buffer_type);
common_hal_bleio_characteristic_buffer_construct(self, characteristic, timeout, buffer_size);

View File

@ -122,8 +122,7 @@ STATIC mp_obj_t bleio_descriptor_add_to_characteristic(size_t n_args, const mp_o
mp_raise_ValueError(translate("initial_value length is wrong"));
}
bleio_descriptor_obj_t *descriptor = m_new_obj(bleio_descriptor_obj_t);
descriptor->base.type = &bleio_descriptor_type;
bleio_descriptor_obj_t *descriptor = mp_obj_malloc(bleio_descriptor_obj_t, &bleio_descriptor_type);
// Range checking on max_length arg is done by the common_hal layer, because
// it may vary depending on underlying BLE implementation.

View File

@ -85,8 +85,7 @@ STATIC mp_obj_t bleio_packet_buffer_make_new(const mp_obj_type_t *type, size_t n
max_packet_size = mp_obj_get_int(args[ARG_max_packet_size].u_obj);
}
bleio_packet_buffer_obj_t *self = m_new_obj(bleio_packet_buffer_obj_t);
self->base.type = &bleio_packet_buffer_type;
bleio_packet_buffer_obj_t *self = mp_obj_malloc(bleio_packet_buffer_obj_t, &bleio_packet_buffer_type);
common_hal_bleio_packet_buffer_construct(self, characteristic, buffer_size, max_packet_size);

View File

@ -61,8 +61,7 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args,
const bool is_secondary = args[ARG_secondary].u_bool;
bleio_service_obj_t *service = m_new_obj(bleio_service_obj_t);
service->base.type = &bleio_service_type;
bleio_service_obj_t *service = mp_obj_malloc(bleio_service_obj_t, &bleio_service_type);
common_hal_bleio_service_construct(service, uuid, is_secondary);

View File

@ -53,8 +53,7 @@
STATIC mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
mp_arg_check_num(n_args, n_kw, 1, 1, false);
bleio_uuid_obj_t *self = m_new_obj(bleio_uuid_obj_t);
self->base.type = type;
bleio_uuid_obj_t *self = mp_obj_malloc(bleio_uuid_obj_t, &bleio_uuid_type);
const mp_obj_t value = all_args[0];
uint8_t uuid128[16];

View File

@ -203,4 +203,4 @@ const mp_obj_module_t bleio_module = {
.globals = (mp_obj_dict_t *)&bleio_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR__bleio, bleio_module, CIRCUITPY_BLEIO);
MP_REGISTER_MODULE(MP_QSTR__bleio, bleio_module);

View File

@ -1058,8 +1058,7 @@ STATIC MP_DEFINE_CONST_DICT(_EVE_locals_dict, _EVE_locals_dict_table);
STATIC mp_obj_t _EVE_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, kw_args, 1, 1, false);
mp_obj__EVE_t *o = m_new_obj(mp_obj__EVE_t);
o->base.type = &_EVE_type;
mp_obj__EVE_t *o = mp_obj_malloc(mp_obj__EVE_t, &_EVE_type);
o->_eve.n = 0;
o->_eve.vscale = 16;
return MP_OBJ_FROM_PTR(o);
@ -1084,4 +1083,4 @@ const mp_obj_module_t _eve_module = {
.globals = (mp_obj_dict_t *)&mp_module__eve_globals,
};
MP_REGISTER_MODULE(MP_QSTR__eve, _eve_module, CIRCUITPY__EVE);
MP_REGISTER_MODULE(MP_QSTR__eve, _eve_module);

View File

@ -110,8 +110,7 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, size_t
pew_obj_t *pew = MP_STATE_VM(pew_singleton);
if (!pew) {
pew = m_new_obj(pew_obj_t);
pew->base.type = &pewpew_type;
pew = mp_obj_malloc(pew_obj_t, &pewpew_type);
pew = gc_make_long_lived(pew);
MP_STATE_VM(pew_singleton) = pew;
}

View File

@ -87,8 +87,7 @@ STATIC mp_obj_t pixelmap_pixelmap_make_new(const mp_obj_type_t *type, size_t n_a
}
}
pixelmap_pixelmap_obj_t *self = m_new_obj(pixelmap_pixelmap_obj_t);
self->base.type = &pixelmap_pixelmap_type;
pixelmap_pixelmap_obj_t *self = mp_obj_malloc(pixelmap_pixelmap_obj_t, &pixelmap_pixelmap_type);
shared_module_pixelmap_pixelmap_construct(self, pixelbuf, indices);
return MP_OBJ_FROM_PTR(self);

View File

@ -59,4 +59,4 @@ const mp_obj_module_t pixelmap_module = {
.globals = (mp_obj_dict_t *)&pixelmap_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR__pixelmap, pixelmap_module, CIRCUITPY_PIXELMAP);
MP_REGISTER_MODULE(MP_QSTR__pixelmap, pixelmap_module);

View File

@ -58,8 +58,7 @@ STATIC mp_obj_t layer_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, 4, 5, false);
layer_obj_t *self = m_new_obj(layer_obj_t);
self->base.type = type;
layer_obj_t *self = mp_obj_malloc(layer_obj_t, type);
self->width = mp_obj_get_int(args[0]);
self->height = mp_obj_get_int(args[1]);

View File

@ -58,8 +58,7 @@ STATIC mp_obj_t text_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, 5, 5, false);
text_obj_t *self = m_new_obj(text_obj_t);
self->base.type = type;
text_obj_t *self = mp_obj_malloc(text_obj_t, type);
self->width = mp_obj_get_int(args[0]);
self->height = mp_obj_get_int(args[1]);

View File

@ -118,4 +118,4 @@ const mp_obj_module_t stage_module = {
.globals = (mp_obj_dict_t *)&stage_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR__stage, stage_module, CIRCUITPY_STAGE);
MP_REGISTER_MODULE(MP_QSTR__stage, stage_module);

View File

@ -76,6 +76,6 @@ const mp_obj_module_t adafruit_bus_device_module = {
.globals = (mp_obj_dict_t *)&adafruit_bus_device_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_adafruit_bus_device, adafruit_bus_device_module, CIRCUITPY_BUSDEVICE);
MP_REGISTER_MODULE(MP_QSTR_adafruit_bus_device_dot_i2c_device, adafruit_bus_device_i2c_device_module, CIRCUITPY_BUSDEVICE);
MP_REGISTER_MODULE(MP_QSTR_adafruit_bus_device_dot_spi_device, adafruit_bus_device_spi_device_module, CIRCUITPY_BUSDEVICE);
MP_REGISTER_MODULE(MP_QSTR_adafruit_bus_device, adafruit_bus_device_module);
MP_REGISTER_MODULE(MP_QSTR_adafruit_bus_device_dot_i2c_device, adafruit_bus_device_i2c_device_module);
MP_REGISTER_MODULE(MP_QSTR_adafruit_bus_device_dot_spi_device, adafruit_bus_device_spi_device_module);

View File

@ -66,8 +66,8 @@
//| """
//| ...
STATIC mp_obj_t adafruit_bus_device_i2cdevice_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
adafruit_bus_device_i2cdevice_obj_t *self = m_new_obj(adafruit_bus_device_i2cdevice_obj_t);
self->base.type = &adafruit_bus_device_i2cdevice_type;
adafruit_bus_device_i2cdevice_obj_t *self =
mp_obj_malloc(adafruit_bus_device_i2cdevice_obj_t, &adafruit_bus_device_i2cdevice_type);
enum { ARG_i2c, ARG_device_address, ARG_probe };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_i2c, MP_ARG_REQUIRED | MP_ARG_OBJ },

View File

@ -79,8 +79,8 @@
//| spi.write(bytes_read)"""
//| ...
STATIC mp_obj_t adafruit_bus_device_spidevice_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
adafruit_bus_device_spidevice_obj_t *self = m_new_obj(adafruit_bus_device_spidevice_obj_t);
self->base.type = &adafruit_bus_device_spidevice_type;
adafruit_bus_device_spidevice_obj_t *self =
mp_obj_malloc(adafruit_bus_device_spidevice_obj_t, &adafruit_bus_device_spidevice_type);
enum { ARG_spi, ARG_chip_select, ARG_cs_active_value, ARG_baudrate, ARG_polarity, ARG_phase, ARG_extra_clocks };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_spi, MP_ARG_REQUIRED | MP_ARG_OBJ },

View File

@ -120,8 +120,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_make_new(const mp_obj_type_t *type, size_t n_a
}
// Validation complete, allocate and populate object.
pixelbuf_pixelbuf_obj_t *self = m_new_obj(pixelbuf_pixelbuf_obj_t);
self->base.type = &pixelbuf_pixelbuf_type;
pixelbuf_pixelbuf_obj_t *self = mp_obj_malloc(pixelbuf_pixelbuf_obj_t, &pixelbuf_pixelbuf_type);
common_hal_adafruit_pixelbuf_pixelbuf_construct(self, args[ARG_size].u_int,
&byteorder_details, brightness, args[ARG_auto_write].u_bool, header_bufinfo.buf,
header_bufinfo.len, trailer_bufinfo.buf, trailer_bufinfo.len);

View File

@ -62,4 +62,4 @@ const mp_obj_module_t pixelbuf_module = {
.globals = (mp_obj_dict_t *)&pixelbuf_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_adafruit_pixelbuf, pixelbuf_module, CIRCUITPY_PIXELBUF);
MP_REGISTER_MODULE(MP_QSTR_adafruit_pixelbuf, pixelbuf_module);

View File

@ -68,4 +68,4 @@ const mp_obj_module_t aesio_module = {
.globals = (mp_obj_dict_t *)&aesio_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_aesio, aesio_module, CIRCUITPY_AESIO);
MP_REGISTER_MODULE(MP_QSTR_aesio, aesio_module);

View File

@ -47,8 +47,7 @@
STATIC mp_obj_t aesio_aes_make_new(const mp_obj_type_t *type, size_t n_args,
size_t n_kw, const mp_obj_t *all_args) {
aesio_aes_obj_t *self = m_new_obj(aesio_aes_obj_t);
self->base.type = &aesio_aes_type;
aesio_aes_obj_t *self = mp_obj_malloc(aesio_aes_obj_t, &aesio_aes_type);
enum { ARG_key, ARG_mode, ARG_IV, ARG_counter, ARG_segment_size };
static const mp_arg_t allowed_args[] = {

View File

@ -312,4 +312,4 @@ MP_WEAK void common_hal_alarm_pretending_deep_sleep(void) {
port_idle_until_interrupt();
}
MP_REGISTER_MODULE(MP_QSTR_alarm, alarm_module, CIRCUITPY_ALARM);
MP_REGISTER_MODULE(MP_QSTR_alarm, alarm_module);

View File

@ -62,8 +62,7 @@
//| """
//| ...
STATIC mp_obj_t alarm_pin_pinalarm_make_new(const mp_obj_type_t *type, mp_uint_t n_args, size_t n_kw, const mp_obj_t *all_args) {
alarm_pin_pinalarm_obj_t *self = m_new_obj(alarm_pin_pinalarm_obj_t);
self->base.type = &alarm_pin_pinalarm_type;
alarm_pin_pinalarm_obj_t *self = mp_obj_malloc(alarm_pin_pinalarm_obj_t, &alarm_pin_pinalarm_type);
enum { ARG_pin, ARG_value, ARG_edge, ARG_pull };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ },

View File

@ -61,8 +61,7 @@ mp_obj_t MP_WEAK rtc_get_time_source_time(void) {
//| ...
STATIC mp_obj_t alarm_time_timealarm_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
alarm_time_timealarm_obj_t *self = m_new_obj(alarm_time_timealarm_obj_t);
self->base.type = &alarm_time_timealarm_type;
alarm_time_timealarm_obj_t *self = mp_obj_malloc(alarm_time_timealarm_obj_t, &alarm_time_timealarm_type);
enum { ARG_monotonic_time, ARG_epoch_time };
static const mp_arg_t allowed_args[] = {

View File

@ -45,8 +45,7 @@
//| ...
STATIC mp_obj_t alarm_touch_touchalarm_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
alarm_touch_touchalarm_obj_t *self = m_new_obj(alarm_touch_touchalarm_obj_t);
self->base.type = &alarm_touch_touchalarm_type;
alarm_touch_touchalarm_obj_t *self = mp_obj_malloc(alarm_touch_touchalarm_obj_t, &alarm_touch_touchalarm_type);
enum { ARG_pin };
static const mp_arg_t allowed_args[] = {

View File

@ -59,4 +59,4 @@ const mp_obj_module_t analogbufio_module = {
.globals = (mp_obj_dict_t *)&analogbufio_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_analogbufio, analogbufio_module, CIRCUITPY_ANALOGBUFIO);
MP_REGISTER_MODULE(MP_QSTR_analogbufio, analogbufio_module);

View File

@ -65,8 +65,7 @@ STATIC mp_obj_t analogio_analogin_make_new(const mp_obj_type_t *type,
// 1st argument is the pin
const mcu_pin_obj_t *pin = common_hal_analogio_analogin_validate_pin(args[0]);
analogio_analogin_obj_t *self = m_new_obj(analogio_analogin_obj_t);
self->base.type = &analogio_analogin_type;
analogio_analogin_obj_t *self = mp_obj_malloc(analogio_analogin_obj_t, &analogio_analogin_type);
common_hal_analogio_analogin_construct(self, pin);
return MP_OBJ_FROM_PTR(self);

View File

@ -63,8 +63,7 @@ STATIC mp_obj_t analogio_analogout_make_new(const mp_obj_type_t *type, mp_uint_t
const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0], MP_QSTR_pin);
analogio_analogout_obj_t *self = m_new_obj(analogio_analogout_obj_t);
self->base.type = &analogio_analogout_type;
analogio_analogout_obj_t *self = mp_obj_malloc(analogio_analogout_obj_t, &analogio_analogout_type);
common_hal_analogio_analogout_construct(self, pin);
return MP_OBJ_FROM_PTR(self);

View File

@ -79,4 +79,4 @@ const mp_obj_module_t analogio_module = {
.globals = (mp_obj_dict_t *)&analogio_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_analogio, analogio_module, CIRCUITPY_ANALOGIO);
MP_REGISTER_MODULE(MP_QSTR_analogio, analogio_module);

View File

@ -93,4 +93,4 @@ const mp_obj_module_t atexit_module = {
.globals = (mp_obj_dict_t *)&atexit_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_atexit, atexit_module, CIRCUITPY_ATEXIT);
MP_REGISTER_MODULE(MP_QSTR_atexit, atexit_module);

View File

@ -116,8 +116,7 @@ STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_ar
const mcu_pin_obj_t *data_pin = validate_obj_is_free_pin(args[ARG_data_pin].u_obj, MP_QSTR_data_pin);
// create PDMIn object from the given pin
audiobusio_pdmin_obj_t *self = m_new_obj(audiobusio_pdmin_obj_t);
self->base.type = &audiobusio_pdmin_type;
audiobusio_pdmin_obj_t *self = mp_obj_malloc(audiobusio_pdmin_obj_t, &audiobusio_pdmin_type);
uint32_t sample_rate = args[ARG_sample_rate].u_int;
uint8_t bit_depth = args[ARG_bit_depth].u_int;

View File

@ -58,4 +58,4 @@ const mp_obj_module_t audiobusio_module = {
.globals = (mp_obj_dict_t *)&audiobusio_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_audiobusio, audiobusio_module, CIRCUITPY_AUDIOBUSIO);
MP_REGISTER_MODULE(MP_QSTR_audiobusio, audiobusio_module);

View File

@ -80,8 +80,7 @@ STATIC mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_a
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
audioio_rawsample_obj_t *self = m_new_obj(audioio_rawsample_obj_t);
self->base.type = &audioio_rawsample_type;
audioio_rawsample_obj_t *self = mp_obj_malloc(audioio_rawsample_obj_t, &audioio_rawsample_type);
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ);
uint8_t bytes_per_sample = 1;

View File

@ -79,8 +79,7 @@ STATIC mp_obj_t audioio_wavefile_make_new(const mp_obj_type_t *type, size_t n_ar
arg = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), arg, MP_ROM_QSTR(MP_QSTR_rb));
}
audioio_wavefile_obj_t *self = m_new_obj(audioio_wavefile_obj_t);
self->base.type = &audioio_wavefile_type;
audioio_wavefile_obj_t *self = mp_obj_malloc(audioio_wavefile_obj_t, &audioio_wavefile_type);
if (!mp_obj_is_type(arg, &mp_type_fileio)) {
mp_raise_TypeError(translate("file must be a file opened in byte mode"));
}

View File

@ -112,4 +112,4 @@ const mp_obj_module_t audiocore_module = {
.globals = (mp_obj_dict_t *)&audiocore_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_audiocore, audiocore_module, CIRCUITPY_AUDIOCORE);
MP_REGISTER_MODULE(MP_QSTR_audiocore, audiocore_module);

View File

@ -111,8 +111,7 @@ STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar
validate_obj_is_free_pin_or_none(args[ARG_right_channel].u_obj, MP_QSTR_right_channel);
// create AudioOut object from the given pin
audioio_audioout_obj_t *self = m_new_obj(audioio_audioout_obj_t);
self->base.type = &audioio_audioout_type;
audioio_audioout_obj_t *self = mp_obj_malloc(audioio_audioout_obj_t, &audioio_audioout_type);
common_hal_audioio_audioout_construct(self, left_channel_pin, right_channel_pin, args[ARG_quiescent_value].u_int);
return MP_OBJ_FROM_PTR(self);

View File

@ -65,4 +65,4 @@ const mp_obj_module_t audioio_module = {
.globals = (mp_obj_dict_t *)&audioio_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_audioio, audioio_module, CIRCUITPY_AUDIOIO);
MP_REGISTER_MODULE(MP_QSTR_audioio, audioio_module);

View File

@ -103,8 +103,8 @@ STATIC mp_obj_t audiomixer_mixer_make_new(const mp_obj_type_t *type, size_t n_ar
if (bits_per_sample != 8 && bits_per_sample != 16) {
mp_raise_ValueError(translate("bits_per_sample must be 8 or 16"));
}
audiomixer_mixer_obj_t *self = m_new_obj_var(audiomixer_mixer_obj_t, mp_obj_t, voice_count);
self->base.type = &audiomixer_mixer_type;
audiomixer_mixer_obj_t *self =
mp_obj_malloc_var(audiomixer_mixer_obj_t, mp_obj_t, voice_count, &audiomixer_mixer_type;
common_hal_audiomixer_mixer_construct(self, voice_count, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate);
for (int v = 0; v < voice_count; v++) {

View File

@ -46,8 +46,7 @@
// TODO: support mono or stereo voices
STATIC mp_obj_t audiomixer_mixervoice_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
audiomixer_mixervoice_obj_t *self = m_new_obj(audiomixer_mixervoice_obj_t);
self->base.type = &audiomixer_mixervoice_type;
audiomixer_mixervoice_obj_t *self = mp_obj_malloc(audiomixer_mixervoice_obj_t, &audiomixer_mixervoice_type);
common_hal_audiomixer_mixervoice_construct(self);

View File

@ -45,4 +45,4 @@ const mp_obj_module_t audiomixer_module = {
.globals = (mp_obj_dict_t *)&audiomixer_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_audiomixer, audiomixer_module, CIRCUITPY_AUDIOMIXER);
MP_REGISTER_MODULE(MP_QSTR_audiomixer, audiomixer_module);

View File

@ -95,8 +95,7 @@ STATIC mp_obj_t audiomp3_mp3file_make_new(const mp_obj_type_t *type, size_t n_ar
arg = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), arg, MP_ROM_QSTR(MP_QSTR_rb));
}
audiomp3_mp3file_obj_t *self = m_new_obj(audiomp3_mp3file_obj_t);
self->base.type = &audiomp3_mp3file_type;
audiomp3_mp3file_obj_t *self = mp_obj_malloc(audiomp3_mp3file_obj_t, &audiomp3_mp3file_type);
if (!mp_obj_is_type(arg, &mp_type_fileio)) {
mp_raise_TypeError(translate("file must be a file opened in byte mode"));
}

View File

@ -50,4 +50,4 @@ const mp_obj_module_t audiomp3_module = {
.globals = (mp_obj_dict_t *)&audiomp3_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_audiomp3, audiomp3_module, CIRCUITPY_AUDIOMP3);
MP_REGISTER_MODULE(MP_QSTR_audiomp3, audiomp3_module);

View File

@ -57,4 +57,4 @@ const mp_obj_module_t audiopwmio_module = {
.globals = (mp_obj_dict_t *)&audiopwmio_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_audiopwmio, audiopwmio_module, CIRCUITPY_AUDIOPWMIO);
MP_REGISTER_MODULE(MP_QSTR_audiopwmio, audiopwmio_module);

View File

@ -80,8 +80,7 @@ STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args,
const mcu_pin_obj_t *scl = validate_obj_is_free_pin(args[ARG_scl].u_obj, MP_QSTR_scl);
const mcu_pin_obj_t *sda = validate_obj_is_free_pin(args[ARG_sda].u_obj, MP_QSTR_sda);
bitbangio_i2c_obj_t *self = m_new_obj(bitbangio_i2c_obj_t);
self->base.type = &bitbangio_i2c_type;
bitbangio_i2c_obj_t *self = mp_obj_malloc(bitbangio_i2c_obj_t, &bitbangio_i2c_type);
shared_module_bitbangio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int, args[ARG_timeout].u_int);
return (mp_obj_t)self;
}

View File

@ -89,8 +89,7 @@ STATIC mp_obj_t bitbangio_spi_make_new(const mp_obj_type_t *type, size_t n_args,
const mcu_pin_obj_t *mosi = validate_obj_is_free_pin_or_none(args[ARG_MOSI].u_obj, MP_QSTR_mosi);
const mcu_pin_obj_t *miso = validate_obj_is_free_pin_or_none(args[ARG_MISO].u_obj, MP_QSTR_miso);
bitbangio_spi_obj_t *self = m_new_obj(bitbangio_spi_obj_t);
self->base.type = &bitbangio_spi_type;
bitbangio_spi_obj_t *self = mp_obj_malloc(bitbangio_spi_obj_t, &bitbangio_spi_type);
shared_module_bitbangio_spi_construct(self, clock, mosi, miso);
return (mp_obj_t)self;
}

View File

@ -80,4 +80,4 @@ const mp_obj_module_t bitbangio_module = {
.globals = (mp_obj_dict_t *)&bitbangio_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_bitbangio, bitbangio_module, CIRCUITPY_BITBANGIO);
MP_REGISTER_MODULE(MP_QSTR_bitbangio, bitbangio_module);

View File

@ -970,4 +970,4 @@ const mp_obj_module_t bitmaptools_module = {
.globals = (mp_obj_dict_t *)&bitmaptools_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_bitmaptools, bitmaptools_module, CIRCUITPY_BITMAPTOOLS);
MP_REGISTER_MODULE(MP_QSTR_bitmaptools, bitmaptools_module);

View File

@ -99,4 +99,4 @@ const mp_obj_module_t bitops_module = {
.globals = (mp_obj_dict_t *)&bitops_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_bitops, bitops_module, CIRCUITPY_BITOPS);
MP_REGISTER_MODULE(MP_QSTR_bitops, bitops_module);

View File

@ -119,4 +119,4 @@ const mp_obj_module_t board_module = {
.globals = (mp_obj_dict_t *)&board_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_board, board_module, CIRCUITPY_BOARD);
MP_REGISTER_MODULE(MP_QSTR_board, board_module);

View File

@ -68,8 +68,7 @@
//| """
//| ...
STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t);
self->base.type = &busio_i2c_type;
busio_i2c_obj_t *self = mp_obj_malloc(busio_i2c_obj_t, &busio_i2c_type);
enum { ARG_scl, ARG_sda, ARG_frequency, ARG_timeout };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ },

Some files were not shown because too many files have changed in this diff Show More