summaryrefslogtreecommitdiff
path: root/backend/dll.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2017-07-15 11:25:39 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2017-07-15 11:25:39 +0200
commit1edb02101a9306fc711cd422ed507d18165b1691 (patch)
treebd2d48a139bfbe869f4f49359b63097931a45e7b /backend/dll.c
parent2ca8a81bd0d99fe4d75c229d0e988d8ef710285f (diff)
move from support/1.0.27 to feature/1.0.27
Diffstat (limited to 'backend/dll.c')
-rw-r--r--backend/dll.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/backend/dll.c b/backend/dll.c
index 5264f11..5eaa046 100644
--- a/backend/dll.c
+++ b/backend/dll.c
@@ -69,6 +69,26 @@
#if defined(HAVE_DLOPEN) && defined(HAVE_DLFCN_H)
# include <dlfcn.h>
+ /* This works around a pedantic GCC compiler warning. The ISO C
+ standard says that the behaviour of converting an object pointer
+ like the void * returned by dlsym() to a function pointer like
+ void *(*)() is implementation defined. POSIX though guarantees
+ that this works fine.
+
+ Workaround based on http://stackoverflow.com/a/36385690. Turns
+ off pedantic warnings for the duration of the definition only.
+ */
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wpedantic"
+typedef void *(*func_ptr)(void);
+
+func_ptr
+posix_dlsym (void *handle, const char *func)
+{
+ return dlsym (handle, func);
+}
+# pragma GCC diagnostic pop
+
/* Older versions of dlopen() don't define RTLD_NOW and RTLD_LAZY.
They all seem to use a mode of 1 to indicate RTLD_NOW and some do
not support RTLD_LAZY at all. Hence, unless defined, we define
@@ -430,15 +450,17 @@ load (struct backend *be)
if (path)
{
- src_len = strlen (path) + strlen (LIBDIR) + 1 + 1;
+ src_len = strlen (path) + strlen (DIR_SEP) + strlen(LIBDIR) + 1;
src = malloc (src_len);
if (!src)
{
DBG (1, "load: malloc failed: %s\n", strerror (errno));
return SANE_STATUS_NO_MEM;
}
+ if (orig_src)
+ free (orig_src);
orig_src = src;
- snprintf (src, src_len, "%s:%s", path, LIBDIR);
+ snprintf (src, src_len, "%s%s%s", path, DIR_SEP, LIBDIR);
}
else
{
@@ -534,7 +556,7 @@ load (struct backend *be)
/* First try looking up the symbol without a leading underscore. */
#ifdef HAVE_DLOPEN
- op = (void *(*)(void)) dlsym (be->handle, funcname + 1);
+ op = posix_dlsym (be->handle, funcname + 1);
#elif defined(HAVE_SHL_LOAD)
shl_findsym ((shl_t *) & (be->handle), funcname + 1, TYPE_UNDEFINED,
&op);
@@ -559,7 +581,7 @@ load (struct backend *be)
{
/* Try again, with an underscore prepended. */
#ifdef HAVE_DLOPEN
- op = (void *(*)(void)) dlsym (be->handle, funcname);
+ op = posix_dlsym (be->handle, funcname);
#elif defined(HAVE_SHL_LOAD)
shl_findsym (be->handle, funcname, TYPE_UNDEFINED, &op);
#elif defined(HAVE_NSLINKMODULE)