diff options
author | David Robillard <d@drobilla.net> | 2022-05-30 15:06:51 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-05-30 15:41:43 -0400 |
commit | b6d6f44708c55b529250e6cb5a61466ce13874b9 (patch) | |
tree | 015e1d02bb3f0a09c471c9d351418fdb4d5e8d6c | |
parent | 997945c9f4850f1833543465e91d372ef01a338c (diff) | |
download | jalv-b6d6f44708c55b529250e6cb5a61466ce13874b9.tar.gz jalv-b6d6f44708c55b529250e6cb5a61466ce13874b9.tar.bz2 jalv-b6d6f44708c55b529250e6cb5a61466ce13874b9.zip |
Remove use of VLAs
-rw-r--r-- | src/jack.c | 2 | ||||
-rw-r--r-- | src/jalv.c | 20 | ||||
-rw-r--r-- | src/jalv_internal.h | 3 | ||||
-rw-r--r-- | src/portaudio.c | 2 | ||||
-rw-r--r-- | src/state.c | 2 | ||||
-rw-r--r-- | wscript | 2 |
6 files changed, 18 insertions, 13 deletions
@@ -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"); } @@ -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)); } } @@ -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', ], }) |