From 77a78c6535a62bdadbf780a069aa47a4bfd01805 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 4 Feb 2011 05:48:37 +0000 Subject: =?UTF-8?q?Fix=20"ISO=20C=20forbids=20initialization=20between=20f?= =?UTF-8?q?unction=20pointer=20and=20=E2=80=98void=20*=E2=80=99"=20warning?= =?UTF-8?q?s.=20Fix=20crash=20when=20plugins=20have=20no=20required=20or?= =?UTF-8?q?=20optional=20features.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2908 a436a847-0d15-0410-975c-d299462d15a1 --- src/plugin.c | 14 +++++++++----- src/plugininstance.c | 5 +++-- src/pluginuiinstance.c | 3 ++- src/slv2_internal.h | 12 ++++++++++++ src/world.c | 4 ++-- 5 files changed, 28 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/plugin.c b/src/plugin.c index 1533ac6..4b29a00 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -257,7 +257,7 @@ slv2_plugin_load(SLV2Plugin p) } typedef int (*OpenFunc)(LV2_Dyn_Manifest_Handle*, const LV2_Feature *const *); - OpenFunc open_func = (OpenFunc)dlsym(lib, "lv2_dyn_manifest_open"); + OpenFunc open_func = (OpenFunc)slv2_dlfunc(lib, "lv2_dyn_manifest_open"); LV2_Dyn_Manifest_Handle handle = NULL; if (open_func) open_func(&handle, &dman_features); @@ -265,7 +265,7 @@ slv2_plugin_load(SLV2Plugin p) typedef int (*GetDataFunc)(LV2_Dyn_Manifest_Handle handle, FILE* fp, const char* uri); - GetDataFunc get_data_func = (GetDataFunc)dlsym(lib, "lv2_dyn_manifest_get_data"); + GetDataFunc get_data_func = (GetDataFunc)slv2_dlfunc(lib, "lv2_dyn_manifest_get_data"); if (get_data_func) { FILE* fd = tmpfile(); get_data_func(handle, fd, slv2_value_as_string(p->plugin_uri)); @@ -275,7 +275,7 @@ slv2_plugin_load(SLV2Plugin p) } typedef int (*CloseFunc)(LV2_Dyn_Manifest_Handle); - CloseFunc close_func = (CloseFunc)dlsym(lib, "lv2_dyn_manifest_close"); + CloseFunc close_func = (CloseFunc)slv2_dlfunc(lib, "lv2_dyn_manifest_close"); if (close_func) close_func(handle); } @@ -656,8 +656,12 @@ slv2_plugin_get_supported_features(SLV2Plugin p) for (unsigned i = 0 ; i < n_required; ++i) g_ptr_array_add(result, slv2_values_get_at(required, i)); - free(((GPtrArray*)optional)->pdata); - free(((GPtrArray*)required)->pdata); + if (optional) { + free(((GPtrArray*)optional)->pdata); + } + if (required) { + free(((GPtrArray*)required)->pdata); + } return result; } diff --git a/src/plugininstance.c b/src/plugininstance.c index 9d1a2b8..ffe9b2b 100644 --- a/src/plugininstance.c +++ b/src/plugininstance.c @@ -22,7 +22,6 @@ #include #include #include -#include #include "slv2/plugin.h" #include "slv2/plugininstance.h" #include "slv2/types.h" @@ -30,6 +29,7 @@ #include "slv2/value.h" #include "slv2_internal.h" + SLV2Instance slv2_plugin_instantiate(SLV2Plugin plugin, double sample_rate, @@ -56,7 +56,8 @@ slv2_plugin_instantiate(SLV2Plugin plugin, return NULL; } - LV2_Descriptor_Function df = dlsym(lib, "lv2_descriptor"); + LV2_Descriptor_Function df = (LV2_Descriptor_Function) + slv2_dlfunc(lib, "lv2_descriptor"); if (!df) { SLV2_ERRORF("Could not find symbol 'lv2_descriptor', " diff --git a/src/pluginuiinstance.c b/src/pluginuiinstance.c index 7c5611e..1c2cd1c 100644 --- a/src/pluginuiinstance.c +++ b/src/pluginuiinstance.c @@ -59,7 +59,8 @@ slv2_ui_instantiate(SLV2Plugin plugin, return NULL; } - LV2UI_DescriptorFunction df = dlsym(lib, "lv2ui_descriptor"); + LV2UI_DescriptorFunction df = (LV2UI_DescriptorFunction) + slv2_dlfunc(lib, "lv2ui_descriptor"); if (!df) { SLV2_ERRORF("Could not find symbol 'lv2ui_descriptor', " diff --git a/src/slv2_internal.h b/src/slv2_internal.h index 1c87a5e..2691c5d 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -30,6 +30,7 @@ extern "C" { #include #include #include +#include #include #include "serd/serd.h" #include "sord/sord.h" @@ -322,6 +323,17 @@ char* slv2_strjoin(const char* first, ...); const char* slv2_get_lang(); uint8_t* slv2_qname_expand(SLV2Plugin p, const char* qname); +typedef void (*VoidFunc)(); + +/** dlsym wrapper to return a function pointer (without annoying warning) */ +static inline VoidFunc +slv2_dlfunc(void* handle, const char* symbol) +{ + typedef VoidFunc (*VoidFuncGetter)(void*, const char*); + VoidFuncGetter dlfunc = (VoidFuncGetter)dlsym; + return dlfunc(handle, symbol); +} + /* ********* Dynamic Manifest ********* */ #ifdef SLV2_DYN_MANIFEST static const LV2_Feature* const dman_features = { NULL }; diff --git a/src/world.c b/src/world.c index 454fdec..08de7ab 100644 --- a/src/world.c +++ b/src/world.c @@ -267,13 +267,13 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri) // Open dynamic manifest typedef int (*OpenFunc)(LV2_Dyn_Manifest_Handle*, const LV2_Feature *const *); - OpenFunc open_func = (OpenFunc)dlsym(lib, "lv2_dyn_manifest_open"); + OpenFunc open_func = (OpenFunc)slv2_dlfunc(lib, "lv2_dyn_manifest_open"); if (open_func) open_func(&handle, &dman_features); // Get subjects (the data that would be in manifest.ttl) typedef int (*GetSubjectsFunc)(LV2_Dyn_Manifest_Handle, FILE*); - GetSubjectsFunc get_subjects_func = (GetSubjectsFunc)dlsym(lib, + GetSubjectsFunc get_subjects_func = (GetSubjectsFunc)slv2_dlfunc(lib, "lv2_dyn_manifest_get_subjects"); if (!get_subjects_func) continue; -- cgit v1.2.1