From b6d6f44708c55b529250e6cb5a61466ce13874b9 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 30 May 2022 15:06:51 -0400 Subject: Remove use of VLAs --- src/jack.c | 2 +- src/jalv.c | 20 +++++++++++++------- src/jalv_internal.h | 3 ++- src/portaudio.c | 2 +- src/state.c | 2 +- wscript | 2 -- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/jack.c b/src/jack.c index 9b1a6d5..09f8855 100644 --- a/src/jack.c +++ b/src/jack.c @@ -269,7 +269,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) ev->index = p; ev->protocol = 0; ev->size = sizeof(float); - *(float*)ev->body = port->control; + *(float*)(ev + 1) = port->control; if (zix_ring_write(jalv->plugin_events, buf, sizeof(buf)) < sizeof(buf)) { fprintf(stderr, "Plugin => UI buffer overflow!\n"); } diff --git a/src/jalv.c b/src/jalv.c index 466bbf6..6724a8e 100644 --- a/src/jalv.c +++ b/src/jalv.c @@ -86,6 +86,10 @@ # define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) #endif +#ifndef MSG_BUFFER_SIZE +# define MSG_BUFFER_SIZE 1024 +#endif + /** Size factor for UI ring buffers. @@ -383,7 +387,7 @@ jalv_set_control(const ControlID* control, // Copy forge since it is used by process thread LV2_Atom_Forge forge = jalv->forge; LV2_Atom_Forge_Frame frame; - uint8_t buf[1024]; + uint8_t buf[MSG_BUFFER_SIZE]; lv2_atom_forge_set_buffer(&forge, buf, sizeof(buf)); lv2_atom_forge_object(&forge, &frame, 0, jalv->urids.patch_Set); @@ -508,13 +512,13 @@ jalv_ui_write(void* const jalv_handle, free(str); } - char buf[sizeof(ControlChange) + buffer_size]; + char buf[MSG_BUFFER_SIZE]; ControlChange* ev = (ControlChange*)buf; ev->index = port_index; ev->protocol = protocol; ev->size = buffer_size; - memcpy(ev->body, buffer, buffer_size); - zix_ring_write(jalv->ui_events, buf, sizeof(buf)); + memcpy(ev + 1, buffer, buffer_size); + zix_ring_write(jalv->ui_events, buf, sizeof(ControlChange) + buffer_size); } void @@ -528,11 +532,13 @@ jalv_apply_ui_events(Jalv* jalv, uint32_t nframes) const size_t space = zix_ring_read_space(jalv->ui_events); for (size_t i = 0; i < space; i += sizeof(ev) + ev.size) { zix_ring_read(jalv->ui_events, (char*)&ev, sizeof(ev)); - char body[ev.size]; + + char body[MSG_BUFFER_SIZE]; if (zix_ring_read(jalv->ui_events, body, ev.size) != ev.size) { fprintf(stderr, "error: Error reading from UI ring buffer\n"); break; } + assert(ev.index < jalv->num_ports); struct Port* const port = &jalv->ports[ev.index]; if (ev.protocol == 0) { @@ -577,7 +583,7 @@ jalv_init_ui(Jalv* jalv) // Send patch:Get message for initial parameters/etc LV2_Atom_Forge forge = jalv->forge; LV2_Atom_Forge_Frame frame; - uint8_t buf[1024]; + uint8_t buf[MSG_BUFFER_SIZE]; lv2_atom_forge_set_buffer(&forge, buf, sizeof(buf)); lv2_atom_forge_object(&forge, &frame, 0, jalv->urids.patch_Get); @@ -605,7 +611,7 @@ jalv_send_to_ui(Jalv* jalv, ev->protocol = jalv->urids.atom_eventTransfer; ev->size = sizeof(LV2_Atom) + size; - LV2_Atom* atom = (LV2_Atom*)ev->body; + LV2_Atom* atom = (LV2_Atom*)(ev + 1); atom->type = type; atom->size = size; diff --git a/src/jalv_internal.h b/src/jalv_internal.h index 0737582..bf8c56c 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -152,7 +152,8 @@ typedef struct { uint32_t index; uint32_t protocol; uint32_t size; - uint8_t body[]; + + // Followed immediately by size bytes of data } ControlChange; typedef struct { diff --git a/src/portaudio.c b/src/portaudio.c index 6b43dc7..8079e92 100644 --- a/src/portaudio.c +++ b/src/portaudio.c @@ -98,7 +98,7 @@ pa_process_cb(const void* inputs, ev->index = p; ev->protocol = 0; ev->size = sizeof(float); - *(float*)ev->body = port->control; + *(float*)(ev + 1) = port->control; if (zix_ring_write(jalv->plugin_events, buf, sizeof(buf)) < sizeof(buf)) { fprintf(stderr, "Plugin => UI buffer overflow!\n"); } diff --git a/src/state.c b/src/state.c index 1c54cf0..696c28f 100644 --- a/src/state.c +++ b/src/state.c @@ -172,7 +172,7 @@ set_port_value(const char* port_symbol, ev->index = port->index; ev->protocol = 0; ev->size = sizeof(fvalue); - *(float*)ev->body = fvalue; + *(float*)(ev + 1) = fvalue; zix_ring_write(jalv->plugin_events, buf, sizeof(buf)); } } diff --git a/wscript b/wscript index f9dc18f..ec1655e 100644 --- a/wscript +++ b/wscript @@ -101,7 +101,6 @@ def configure(conf): '-Wno-unknown-warning-option', '-Wno-unused-macros', '-Wno-unused-parameter', - '-Wno-vla', ], 'gcc': [ '-Wno-cast-align', @@ -116,7 +115,6 @@ def configure(conf): '-Wno-switch-enum', '-Wno-unused-macros', '-Wno-unused-parameter', - '-Wno-vla', ], }) -- cgit v1.2.1