HP/UX 10.20 DLL support

Petter Reinholdtsen (pere@hungry.com)
Mon, 19 Oct 1998 18:55:52 +0200 (METDST)

After some tweaking, I managed to get DLL support running on HP/UX
10.20. Please include the following patch into the next release.

diff -ru src-0.74/ChangeLog src-0.74-hppa20ux10/ChangeLog
--- src-0.74/ChangeLog Tue Jul 28 07:29:04 1998
+++ src-0.74-hppa20ux10/ChangeLog Mon Oct 19 17:27:26 1998
@@ -1,3 +1,12 @@
+1998-10-19 Petter Reinholdtsen <pere@td.org.uit.no>
+
+ * configure.in include/sane/config.h.in backends/dll.c:
+ Use dhl_load() family for DLL support on HP/UX.
+
1998-07-27 David Mosberger-Tang <David.Mosberger@acm.org>

* Version 0.74 released.
diff -ru src-0.74/backend/dll.c src-0.74-hppa20ux10/backend/dll.c
--- src-0.74/backend/dll.c Fri May 15 09:08:47 1998
+++ src-0.74-hppa20ux10/backend/dll.c Mon Oct 19 18:38:36 1998
@@ -68,6 +68,13 @@
# ifndef RTLD_LAZY
# define RTLD_LAZY 1
# endif
+# define HAVE_DLL
+#endif
+
+/* HP/UX DLL support */
+#if defined (HAVE_SHL_LOAD) && defined(HAVE_DL_H)
+# include <dl.h>
+# define HAVE_DLL
#endif

#include <sys/types.h>
@@ -222,14 +229,24 @@
static SANE_Status
load (struct backend *be)
{
-#ifdef HAVE_DLOPEN
- int mode = getenv ("LD_BIND_NOW") ? RTLD_NOW : RTLD_LAZY;
+#ifdef HAVE_DLL
+ int mode = 0;
char *funcname, *src, *dir, *path = 0;
char libname[PATH_MAX];
int i;
FILE *fp = 0;
+
+#if defined(HAVE_DLOPEN)
# define PREFIX "libsane-"
# define POSTFIX ".so.%u"
+ mode = getenv ("LD_BIND_NOW") ? RTLD_NOW : RTLD_LAZY;
+#elif defined(HAVE_SHL_LOAD)
+# define PREFIX "libsane-"
+# define POSTFIX ".sl.%u"
+ mode = BIND_DEFERRED;
+#else
+# error "Tried to compile unsupported DLL."
+#endif /* HAVE_DLOPEN */

DBG(1, "loading backend %s\n", be->name);

@@ -270,13 +287,19 @@
free (path);
if (!fp)
{
- DBG(2, "load: couldn't find "PREFIX"%s"POSTFIX" (%s)\n",
- be->name, V_MAJOR, strerror (errno));
+ DBG(2, "load: couldn't find %s (%s)\n",
+ libname, strerror (errno));
return SANE_STATUS_INVAL;
}
DBG(2, "dlopen()ing `%s'\n", libname);

+#ifdef HAVE_DLOPEN
be->handle = dlopen (libname, mode);
+#elif defined(HAVE_SHL_LOAD)
+ be->handle = (shl_t)shl_load (libname, mode, 0L);
+#else
+# error "Tried to compile unsupported DLL."
+#endif /* HAVE_DLOPEN */
if (!be->handle)
{
DBG(2, "dlopen() failed (%s)\n", strerror (errno));
@@ -292,27 +315,41 @@
sprintf (funcname, "_sane_%s_%s", be->name, op_name[i]);

/* First try looking up the symbol without a leading underscore. */
+#ifdef HAVE_DLOPEN
op = (void *(*)()) dlsym (be->handle, funcname + 1);
+#elif defined(HAVE_SHL_LOAD)
+ shl_findsym ((shl_t*)&(be->handle), funcname + 1, TYPE_UNDEFINED, &op);
+#else
+# error "Tried to compile unsupported DLL."
+#endif /* HAVE_DLOPEN */
if (op)
be->op[i] = op;
else
{
/* Try again, with an underscore prepended. */
+#ifdef HAVE_DLOPEN
op = (void *(*)()) dlsym (be->handle, funcname);
+#elif defined(HAVE_SHL_LOAD)
+ shl_findsym (be->handle, funcname, TYPE_UNDEFINED, &op);
+#else
+# error "Tried to compile unsupported DLL."
+#endif /* HAVE_DLOPEN */
if (op)
be->op[i] = op;
}
+ if (NULL == op)
+ DBG(2, "unable to find %s\n", funcname);
}

return SANE_STATUS_GOOD;

# undef PREFIX
# undef POSTFIX
-#else /* HAVE_DLOPEN */
+#else /* HAVE_DLL */
DBG(1, "load: ignoring attempt to load `%s'; compiled without dl support\n",
be->name);
return SANE_STATUS_UNSUPPORTED;
-#endif /* HAVE_DLOPEN */
+#endif /* HAVE_DLL */
}

static SANE_Status
@@ -402,10 +439,19 @@
{
DBG(2, "calling backend `%s's exit function\n", be->name);
(*be->op[OP_EXIT]) ();
+#ifdef HAVE_DLL
+
#ifdef HAVE_DLOPEN
if (be->handle)
dlclose (be->handle);
-#endif
+#elif defined(HAVE_SHL_LOAD)
+ if (be->handle)
+ shl_unload(be->handle);
+#else
+# error "Tried to compile unsupported DLL."
+#endif /* HAVE_DLOPEN */
+
+#endif /* HAVE_DLL */
}
if (!be->permanent)
{
diff -ru src-0.74/configure.in src-0.74-hppa20ux10/configure.in
--- src-0.74/configure.in Tue Jul 28 07:28:07 1998
+++ src-0.74-hppa20ux10/configure.in Mon Oct 19 18:19:52 1998
@@ -97,6 +97,12 @@
AC_CHECK_HEADERS(dlfcn.h,
[AC_CHECK_LIB(dl,dlopen)
AC_CHECK_FUNCS(dlopen, , enable_dynamic=no)],
+ [enable_dynamic=no])
+
+ # HP/UX DLL handling
+ AC_CHECK_HEADERS(dl.h,
+ [AC_CHECK_LIB(dld,shl_load)
+ AC_CHECK_FUNCS(shl_load, , enable_dynamic=no)],
[enable_dynamic=no])
fi

diff -ru src-0.74/include/sane/config.h.in src-0.74-hppa20ux10/include/sane/config.h.in
--- src-0.74/include/sane/config.h.in Fri Jul 24 07:36:30 1998
+++ src-0.74-hppa20ux10/include/sane/config.h.in Mon Oct 19 17:51:26 1998
@@ -299,6 +299,12 @@
/* Define if you have the dlopen function. */
#undef HAVE_DLOPEN

+/* Define if you have the <dl.h> header file. */
+#undef HAVE_DL_H
+
+/* Define if you have the shl_load function. */
+#undef HAVE_SHL_LOAD
+
/* Define if you have the GIMP header files and library. */
#undef HAVE_LIBGIMP_GIMP_H

--
Source code, list archive, and docs: http://www.mostang.com/sane/
To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com