aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2013-01-22 05:05:29 +0000
committerDavid Robillard <d@drobilla.net>2013-01-22 05:05:29 +0000
commit4d1649e313da9d658bb6c653b3f4a2c6d983299d (patch)
tree7e66c111569b7432344fbb37aee951320b407f67
parent29eb515f2a75eeb9a4a0baf658a10da21f4dd187 (diff)
downloadjalv-4d1649e313da9d658bb6c653b3f4a2c6d983299d.tar.gz
jalv-4d1649e313da9d658bb6c653b3f4a2c6d983299d.tar.bz2
jalv-4d1649e313da9d658bb6c653b3f4a2c6d983299d.zip
Use a dynamically allocated buffer for reading from plugin=>UI ring to avoid blowing the stack if a plugin sends very large updates to the UI.
git-svn-id: http://svn.drobilla.net/lad/trunk/jalv@5003 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/jalv.c10
-rw-r--r--src/jalv_internal.h1
2 files changed, 10 insertions, 1 deletions
diff --git a/src/jalv.c b/src/jalv.c
index 70cfb2c..9668d2c 100644
--- a/src/jalv.c
+++ b/src/jalv.c
@@ -732,11 +732,18 @@ jalv_emit_ui_events(Jalv* jalv)
ControlChange ev;
const size_t space = jack_ringbuffer_read_space(jalv->plugin_events);
for (size_t i = 0; i < space; i += sizeof(ev) + ev.size) {
+ // Read event header to get the size
jack_ringbuffer_read(jalv->plugin_events, (char*)&ev, sizeof(ev));
- char buf[ev.size];
+
+ // Resize read buffer if necessary
+ jalv->ui_event_buf = realloc(jalv->ui_event_buf, ev.size);
+ void* const buf = jalv->ui_event_buf;
+
+ // Read event body
jack_ringbuffer_read(jalv->plugin_events, buf, ev.size);
if (jalv->opts.dump && ev.protocol == jalv->urids.atom_eventTransfer) {
+ // Dump event in Turtle to the console
SerdNode s = serd_node_from_string(SERD_BLANK, USTR("msg"));
SerdNode p = serd_node_from_string(SERD_URI, USTR(NS_RDF "value"));
LV2_Atom* atom = (LV2_Atom*)buf;
@@ -1130,6 +1137,7 @@ main(int argc, char** argv)
remove(jalv.temp_dir);
free(jalv.temp_dir);
+ free(jalv.ui_event_buf);
return 0;
}
diff --git a/src/jalv_internal.h b/src/jalv_internal.h
index 64c4373..b8bf649 100644
--- a/src/jalv_internal.h
+++ b/src/jalv_internal.h
@@ -162,6 +162,7 @@ typedef struct {
jack_client_t* jack_client; ///< Jack client
jack_ringbuffer_t* ui_events; ///< Port events from UI
jack_ringbuffer_t* plugin_events; ///< Port events from plugin
+ void* ui_event_buf; ///< Buffer for reading UI port events
JalvWorker worker; ///< Worker thread implementation
ZixSem* done; ///< Exit semaphore
ZixSem paused; ///< Paused signal from process thread