wip; fix more m_malloc and gc_alloc

This commit is contained in:
Dan Halbert 2023-08-11 00:30:34 -04:00
parent fe0e2f13bc
commit 10b94796c0
27 changed files with 35 additions and 35 deletions

View File

@ -479,7 +479,7 @@ mp_obj_t common_hal_bleio_adapter_start_scan(bleio_adapter_obj_t *self, uint8_t
self->scan_results = shared_module_bleio_new_scanresults(buffer_size, prefixes, prefix_length, minimum_rssi);
// size_t max_packet_size = extended ? BLE_GAP_SCAN_BUFFER_EXTENDED_MAX_SUPPORTED : BLE_GAP_SCAN_BUFFER_MAX;
// uint8_t *raw_data = m_malloc(sizeof(ble_data_t) + max_packet_size, false);
// uint8_t *raw_data = m_malloc(sizeof(ble_data_t) + max_packet_size);
// ble_data_t * sd_data = (ble_data_t *) raw_data;
// self->scan_results->common_hal_data = sd_data;
// sd_data->len = max_packet_size;

View File

@ -85,7 +85,7 @@ static int pulsein_interrupt_handler(int irq, FAR void *context, FAR void *arg)
void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
const mcu_pin_obj_t *pin, uint16_t maxlen, bool idle_state) {
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false);
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t));
if (self->buffer == NULL) {
m_malloc_fail(maxlen * sizeof(uint16_t));
}

View File

@ -103,7 +103,7 @@ void common_hal_bleio_characteristic_buffer_construct(bleio_characteristic_buffe
bleio_characteristic_obj_t *characteristic,
mp_float_t timeout,
size_t buffer_size) {
uint8_t *buffer = m_malloc(buffer_size, true);
uint8_t *buffer = m_malloc(buffer_size);
_common_hal_bleio_characteristic_buffer_construct(self, characteristic, timeout, buffer, buffer_size, NULL, false);
}

View File

@ -225,11 +225,11 @@ void common_hal_bleio_packet_buffer_construct(
uint32_t *outgoing1 = NULL;
uint32_t *outgoing2 = NULL;
if (outgoing) {
outgoing1 = m_malloc(max_packet_size, false);
outgoing1 = m_malloc(max_packet_size);
// Only allocate the second buffer if we are doing writes with responses.
// Without responses, we just write as quickly as we can.
if (outgoing == CHAR_PROP_WRITE) {
outgoing2 = m_malloc(max_packet_size, false);
outgoing2 = m_malloc(max_packet_size);
}
}

View File

@ -190,7 +190,7 @@ mp_obj_t common_hal_mdns_server_find(mdns_server_obj_t *self, const char *servic
// Don't error if we're out of memory. Instead, truncate the tuple.
uint8_t added = 0;
while (next != NULL) {
mdns_remoteservice_obj_t *service = gc_alloc(sizeof(mdns_remoteservice_obj_t), GC_ALLOC_FLAG_HAS_FINALISER, false);
mdns_remoteservice_obj_t *service = gc_alloc(sizeof(mdns_remoteservice_obj_t), GC_ALLOC_FLAG_HAS_FINALISER);
if (service == NULL) {
if (added == 0) {
m_malloc_fail(sizeof(mdns_remoteservice_obj_t));

View File

@ -66,7 +66,7 @@ static esp_err_t get_bytes(nvs_handle_t handle, uint8_t **buf_out) {
*buf_out = NULL;
return result;
}
buf = gc_alloc(size, 0, false); // this SHOULD be the same as
buf = m_m_alloc(size); // this SHOULD be the same as
if (result == ESP_OK) {
result = nvs_get_blob(handle, "data", buf, &size);
} else {

View File

@ -95,7 +95,7 @@ void pulsein_reset(void) {
void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu_pin_obj_t *pin,
uint16_t maxlen, bool idle_state) {
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false);
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t));
if (self->buffer == NULL) {
m_malloc_fail(maxlen * sizeof(uint16_t));
}

View File

@ -329,7 +329,7 @@ void port_i2s_initialize(i2s_t *self, int instance, sai_transceiver_t *config) {
mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_I2SOut);
}
for (size_t i = 0; i < MP_ARRAY_SIZE(self->buffers); i++) {
self->buffers[i] = m_malloc(AUDIO_BUFFER_FRAME_COUNT * sizeof(uint32_t), false);
self->buffers[i] = m_malloc(AUDIO_BUFFER_FRAME_COUNT * sizeof(uint32_t));
}
self->peripheral = peripheral;
SAI_Init(self->peripheral);

View File

@ -95,7 +95,7 @@ void ble_drv_add_event_handler(ble_drv_evt_handler_t func, void *param) {
}
// Add a new handler to the front of the list
ble_drv_evt_handler_entry_t *handler = m_new_ll(ble_drv_evt_handler_entry_t, 1);
ble_drv_evt_handler_entry_t *handler = m_new(ble_drv_evt_handler_entry_t, 1);
ble_drv_add_event_handler_entry(handler, func, param);
}

View File

@ -544,7 +544,7 @@ mp_obj_t common_hal_bleio_adapter_start_scan(bleio_adapter_obj_t *self, uint8_t
}
self->scan_results = shared_module_bleio_new_scanresults(buffer_size, prefixes, prefix_length, minimum_rssi);
size_t max_packet_size = extended ? BLE_GAP_SCAN_BUFFER_EXTENDED_MAX_SUPPORTED : BLE_GAP_SCAN_BUFFER_MAX;
uint8_t *raw_data = m_malloc(sizeof(ble_data_t) + max_packet_size, false);
uint8_t *raw_data = m_malloc(sizeof(ble_data_t) + max_packet_size);
ble_data_t *sd_data = (ble_data_t *)raw_data;
self->scan_results->common_hal_data = sd_data;
sd_data->len = max_packet_size;

View File

@ -102,7 +102,7 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self,
self->initial_value_len = initial_value_bufinfo->len;
if (gc_alloc_possible()) {
if (gc_nbytes(initial_value_bufinfo->buf) > 0) {
uint8_t *initial_value = m_malloc(self->initial_value_len, false);
uint8_t *initial_value = m_malloc(self->initial_value_len);
memcpy(initial_value, initial_value_bufinfo->buf, self->initial_value_len);
self->initial_value = initial_value;
} else {

View File

@ -116,7 +116,7 @@ void common_hal_bleio_characteristic_buffer_construct(bleio_characteristic_buffe
bleio_characteristic_obj_t *characteristic,
mp_float_t timeout,
size_t buffer_size) {
uint8_t *buffer = m_malloc(buffer_size, true);
uint8_t *buffer = m_malloc(buffer_size);
_common_hal_bleio_characteristic_buffer_construct(self, characteristic, timeout, buffer, buffer_size, NULL, false);
}

View File

@ -298,14 +298,14 @@ void common_hal_bleio_packet_buffer_construct(
uint32_t *incoming_buffer = NULL;
if (incoming) {
incoming_buffer_size = buffer_size * (sizeof(uint16_t) + max_packet_size);
incoming_buffer = m_malloc(incoming_buffer_size, false);
incoming_buffer = m_malloc(incoming_buffer_size);
}
uint32_t *outgoing1 = NULL;
uint32_t *outgoing2 = NULL;
if (outgoing) {
outgoing1 = m_malloc(max_packet_size, false);
outgoing2 = m_malloc(max_packet_size, false);
outgoing1 = m_malloc(max_packet_size);
outgoing2 = m_malloc(max_packet_size);
}
_common_hal_bleio_packet_buffer_construct(self, characteristic,
incoming_buffer, incoming_buffer_size,

View File

@ -286,8 +286,8 @@ void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t *self,
self->buffer_length = sample_rate * buffer_length_ms
* self->bytes_per_sample * self->channel_count / 1000;
self->buffer_length = (self->buffer_length + 3) & ~3;
self->buffers[0] = m_malloc(self->buffer_length, false);
self->buffers[1] = m_malloc(self->buffer_length, false);
self->buffers[0] = m_malloc(self->buffer_length);
self->buffers[1] = m_malloc(self->buffer_length);
audiosample_reset_buffer(self->sample, false, 0);

View File

@ -266,9 +266,9 @@ void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t *self,
mp_arg_validate_length_max(max_buffer_length, UINT16_MAX, MP_QSTR_buffer);
uint16_t buffer_length = (uint16_t)max_buffer_length;
self->buffers[0] = m_malloc(buffer_length * 2 * sizeof(uint16_t), false);
self->buffers[0] = m_malloc(buffer_length * 2 * sizeof(uint16_t));
if (!self->single_buffer) {
self->buffers[1] = m_malloc(buffer_length * 2 * sizeof(uint16_t), false);
self->buffers[1] = m_malloc(buffer_length * 2 * sizeof(uint16_t));
}

View File

@ -346,7 +346,7 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data,
if (!nrfx_is_in_ram(data)) {
// Allocate long strings on the heap.
if (len > 128 && gc_alloc_possible()) {
tx_buf = (uint8_t *)gc_alloc(len, false, false);
tx_buf = (uint8_t *)m_m_alloc(len);
} else {
tx_buf = alloca(len);
}

View File

@ -127,7 +127,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu
}
_objs[idx] = self;
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false);
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t));
if (self->buffer == NULL) {
m_malloc_fail(maxlen * sizeof(uint16_t));
}

View File

@ -230,7 +230,7 @@ STATIC void alloc_search_result_cb(struct mdns_answer *answer, const char *varpa
if ((flags & MDNS_SEARCH_RESULT_FIRST) != 0) {
// first
mdns_remoteservice_obj_t *service = gc_alloc(sizeof(mdns_remoteservice_obj_t), 0, false);
mdns_remoteservice_obj_t *service = m_malloc(sizeof(mdns_remoteservice_obj_t));
if (service == NULL) {
// alloc fails
mdns_search_stop(state->request_id);

View File

@ -47,7 +47,7 @@ static const uint16_t pulsein_program[] = {
void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
const mcu_pin_obj_t *pin, uint16_t maxlen, bool idle_state) {
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false);
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t));
if (self->buffer == NULL) {
m_malloc_fail(maxlen * sizeof(uint16_t));
}

View File

@ -87,7 +87,7 @@ void common_hal_bleio_characteristic_buffer_construct(
mp_float_t timeout,
size_t buffer_size) {
uint8_t *buffer = m_malloc(buffer_size, true);
uint8_t *buffer = m_malloc(buffer_size);
_common_hal_bleio_characteristic_buffer_construct(self,
characteristic,
timeout,

View File

@ -223,12 +223,12 @@ void common_hal_bleio_packet_buffer_construct(
if (incoming) {
incoming_buffer_size = buffer_size * (sizeof(uint16_t) + max_packet_size);
incoming_buffer = m_malloc(incoming_buffer_size, false);
incoming_buffer = m_malloc(incoming_buffer_size);
}
if (outgoing) {
outgoing1 = m_malloc(max_packet_size, false);
outgoing2 = m_malloc(max_packet_size, false);
outgoing1 = m_malloc(max_packet_size);
outgoing2 = m_malloc(max_packet_size);
}
_common_hal_bleio_packet_buffer_construct(self, characteristic,
incoming_buffer, incoming_buffer_size,

View File

@ -284,10 +284,10 @@ void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t *self,
mp_raise_ValueError_varg(translate("Buffer length %d too big. It must be less than %d"), max_buffer_length, UINT16_MAX);
}
uint16_t buffer_length = (uint16_t)max_buffer_length / self->bytes_per_sample;
self->buffer[0] = m_malloc(buffer_length * sizeof(uint16_t), false);
self->buffer[0] = m_malloc(buffer_length * sizeof(uint16_t));
self->buffer_ptr[0] = self->buffer_length[0] = 0;
if (self->pin[1]) {
self->buffer[1] = m_malloc(buffer_length * sizeof(uint16_t), false);
self->buffer[1] = m_malloc(buffer_length * sizeof(uint16_t));
self->buffer_ptr[1] = self->buffer_length[1] = 0;
}

View File

@ -120,7 +120,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu
}
// Allocate pulse buffer
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false);
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t));
if (self->buffer == NULL) {
// TODO: free the EXTI here?
m_malloc_fail(maxlen * sizeof(uint16_t));

View File

@ -51,7 +51,7 @@
/******************************************************************************/
// Memory allocation
#define m_malloc(n,_) (m_malloc_dyn((n)))
#define m_malloc(n) (m_malloc_dyn((n)))
#define m_free(ptr) (m_free_dyn((ptr)))
#define m_realloc(ptr, new_num_bytes) (m_realloc_dyn((ptr), (new_num_bytes)))

View File

@ -256,7 +256,7 @@ $(HEADER_BUILD)/compressed.data.h: $(HEADER_BUILD)/compressed.collected
$(HEADER_BUILD)/$(TRANSLATION).mo: $(TOP)/locale/$(TRANSLATION).po | $(HEADER_BUILD)
$(Q)$(PYTHON) $(TOP)/tools/msgfmt.py -o $@ $^
# translations-*.c is generated as a side-effect of building compression_translated.generated.h
# translations-*.c is generated as a side-effect of building compressed_translations.generated.h
# Specifying both in a single rule actually causes the rule to be run twice!
# This alternative makes it run just once.
$(PY_BUILD)/translations-$(TRANSLATION).c: $(HEADER_BUILD)/compressed_translations.generated.h

View File

@ -38,7 +38,7 @@ bool ringbuf_init(ringbuf_t *r, uint8_t *buf, size_t size) {
// Dynamic initialization. This should be accessible from a root pointer..
bool ringbuf_alloc(ringbuf_t *r, size_t size) {
bool result = ringbuf_init(r, gc_alloc(size, false), size);
bool result = ringbuf_init(r, m_malloc(size), size);
return result;
}

View File

@ -54,7 +54,7 @@ STATIC mp_obj_t audiocore_get_buffer(mp_obj_t sample_in) {
uint8_t bits_per_sample = audiosample_bits_per_sample(sample_in);
audiosample_get_buffer_structure(sample_in, false, &single_buffer, &samples_signed, &max_buffer_length, &spacing);
// copies the data because the gc semantics of get_buffer are unclear
void *result_buf = gc_alloc(buffer_length, 0, false);
void *result_buf = m_malloc(buffer_length);
memcpy(result_buf, buffer, buffer_length);
char typecode =
(bits_per_sample == 8 && samples_signed) ? 'b' :