diff options
author | David Robillard <d@drobilla.net> | 2011-02-04 05:48:37 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-02-04 05:48:37 +0000 |
commit | 77a78c6535a62bdadbf780a069aa47a4bfd01805 (patch) | |
tree | 1ef344a592e67a503b83ab92b82d34106283380d /src | |
parent | ea4087e0029c4f6c6f80716b50ddf60120598b1b (diff) | |
download | lilv-77a78c6535a62bdadbf780a069aa47a4bfd01805.tar.gz lilv-77a78c6535a62bdadbf780a069aa47a4bfd01805.tar.bz2 lilv-77a78c6535a62bdadbf780a069aa47a4bfd01805.zip |
Fix "ISO C forbids initialization between function pointer and ‘void *’" warnings.
Fix crash when plugins have no required or optional features.
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2908 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r-- | src/plugin.c | 14 | ||||
-rw-r--r-- | src/plugininstance.c | 5 | ||||
-rw-r--r-- | src/pluginuiinstance.c | 3 | ||||
-rw-r--r-- | src/slv2_internal.h | 12 | ||||
-rw-r--r-- | src/world.c | 4 |
5 files changed, 28 insertions, 10 deletions
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 <stdlib.h> #include <string.h> #include <assert.h> -#include <dlfcn.h> #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 <stdint.h> #include <stdlib.h> #include <inttypes.h> +#include <dlfcn.h> #include <glib.h> #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; |