You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Wilfredo Sanchez <ws...@MIT.EDU> on 2001/04/18 23:50:46 UTC

Clean up of DSO autoconfizification

   I don't like how we detect whether DSO support should be enabled by 
testing for the possible implementation methods, and then rather than 
remembering which we found, we have all this #if THIS_OS crap all over 
dso/unix/dso.c.  If we found dlfcn or shl or whatever, that should be 
what we conditionalize on, and maybe have per-OS mangling for the 
variant dlopen() hoo-hah out there.

   So here is a patch to define macros for the found support for dynamic 
loading.  I imagine that I picked stupid names for the macros, and would 
welcome a correction.  Otherwise, this seem OK?

	-Fred

Index: acconfig.h
===================================================================
RCS file: /home/cvs/apr/acconfig.h,v
retrieving revision 1.41
diff -w -u -d -r1.41 acconfig.h
--- acconfig.h  2001/04/12 07:05:45     1.41
+++ acconfig.h  2001/04/18 21:45:03
@@ -29,6 +29,10 @@
  #undef HAVE_GMTOFF
  #undef USE_THREADS

+#undef DSO_USE_DLFCN
+#undef DSO_USE_SHL
+#undef DSO_USE_DYLD
+
  #undef SIZEOF_SSIZE_T
  #undef SIZEOF_SIZE_T
  #undef SIZEOF_OFF_T
Index: configure.in
===================================================================
RCS file: /home/cvs/apr/configure.in,v
retrieving revision 1.292
diff -w -u -d -r1.292 configure.in
--- configure.in        2001/04/18 17:46:39     1.292
+++ configure.in        2001/04/18 21:45:03
@@ -780,19 +780,19 @@
    [  --enable-dso            Enable dso support ],
    [ tempdso=$enableval],
    [
-    AC_CHECK_FUNCS(NSLinkModule, [ tempdso="yes" ], [ tempdso="no" ])
+    AC_CHECK_FUNCS(NSLinkModule, [ tempdso="dyld" ], [ tempdso="no" ])
      if test "$tempdso" = "no"; then
-      AC_CHECK_LIB(dl, dlopen, [ tempdso="yes" LIBS="$LIBS -ldl" ],
+      AC_CHECK_LIB(dl, dlopen, [ tempdso="dlfcn" LIBS="$LIBS -ldl" ],
                     tempdso="no")
      fi
      if test "$tempdso" = "no"; then
-      AC_CHECK_FUNCS(dlopen, [ tempdso="yes" ], [ tempdso="no" ])
+      AC_CHECK_FUNCS(dlopen, [ tempdso="dlfcn" ], [ tempdso="no" ])
      fi
      if test "$tempdso" = "no"; then
        AC_CHECK_LIB(root, load_image, tempdso="yes", tempdso="no")
      fi
      if test "$tempdso" = "no"; then
-      AC_CHECK_LIB(dld, shl_load, [ tempdso="yes" LIBS="$LIBS -ldld" ],
+      AC_CHECK_LIB(dld, shl_load, [ tempdso="shl" LIBS="$LIBS -ldld" ],
                     tempdso="no")
      fi
      if test "$tempdso" = "no"; then
@@ -807,6 +807,11 @@
  if test "$tempdso" = "no"; then
      aprdso="0"
  else
+    case "$tempdso" in
+       dlfcn) AC_DEFINE(DSO_USE_DLFCN);;
+       shl)   AC_DEFINE(DSO_USE_SHL);;
+       dyld)  AC_DEFINE(DSO_USE_DYLD);;
+    esac
      aprdso="1"
      apr_modules="$apr_modules dso"
  fi
Index: dso/unix/dso.c
===================================================================
RCS file: /home/cvs/apr/dso/unix/dso.c,v
retrieving revision 1.34
diff -w -u -d -r1.34 dso.c
--- dso/unix/dso.c      2001/04/18 17:47:10     1.34
+++ dso/unix/dso.c      2001/04/18 21:45:06
@@ -57,6 +57,10 @@

  #if APR_HAS_DSO

+#if !defined(DSO_USE_DLFCN) && !defined(DSO_USE_SHL) && 
!defined(DSO_USE_DYLD)
+#error No DSO implementation specified.
+#endif
+
  #ifdef HAVE_STDDEF_H
  #include <stddef.h>
  #endif
@@ -71,11 +75,11 @@
      if (dso->handle == NULL)
          return APR_SUCCESS;

-#if defined(HPUX) || defined(HPUX10) || defined(HPUX11)
+#if defined(DSO_USE_SHL)
      shl_unload((shl_t)dso->handle);
-#elif defined(DARWIN)
+#elif defined(DSO_USE_DYLD)
      NSUnLinkModule(dso->handle, FALSE);
-#else
+#elif defined(DSO_USE_DLFCN)
      if (dlclose(dso->handle) != 0)
          return APR_EINIT;
  #endif
@@ -87,10 +91,10 @@
  APR_DECLARE(apr_status_t) apr_dso_load(apr_dso_handle_t **res_handle,
                                         const char *path, apr_pool_t 
*ctx)
  {
-#if defined(HPUX) || defined(HPUX10) || defined(HPUX11)
+#if defined(DSO_USE_SHL)
      shl_t os_handle = shl_load(path, 
BIND_IMMEDIATE|BIND_VERBOSE|BIND_NOSTART, 0L);

-#elif defined(DARWIN)
+#elif defined(DSO_USE_DYLD)
      NSObjectFileImage image;
      NSModule os_handle;
      char* err_msg = NULL;
@@ -107,24 +111,26 @@
  #endif
      }

-#elif defined(OSF1) || defined(SEQUENT) || defined(SNI) ||\
+#elif defined(DSO_USE_DLFCN)
+#if defined(OSF1) || defined(SEQUENT) || defined(SNI) ||\
      (defined(__FreeBSD_version) && (__FreeBSD_version >= 220000))
      void *os_handle = dlopen((char *)path, RTLD_NOW | RTLD_GLOBAL);

  #else
      void *os_handle = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
  #endif
+#endif /* DSO_USE_x */

      *res_handle = apr_pcalloc(ctx, sizeof(**res_handle));

      if(os_handle == NULL) {
-#if defined(HPUX) || defined(HPUX10) || defined(HPUX11)
+#if defined(DSO_USE_SHL)
          (*res_handle)->errormsg = strerror(errno);
          return errno;
-#elif defined(DARWIN)
+#elif defined(DSO_USE_DYLD)
          (*res_handle)->errormsg = (err_msg) ? err_msg : "link failed";
          return APR_EDSOOPEN;
-#else
+#elif defined(DSO_USE_DLFCN)
          (*res_handle)->errormsg = dlerror();
          return APR_EDSOOPEN;
  #endif
@@ -148,7 +154,7 @@
                                        apr_dso_handle_t *handle,
                                        const char *symname)
  {
-#if defined(HPUX) || defined(HPUX10) || defined(HPUX11)
+#if defined(DSO_USE_SHL)
      void *symaddr = NULL;
      int status;

@@ -161,7 +167,7 @@
      *ressym = symaddr;
      return APR_SUCCESS;

-#elif defined(DARWIN)
+#elif defined(DSO_USE_DYLD)
      void *retval = NULL;
      NSSymbol symbol;
      char *symname2 = (char*)malloc(sizeof(char)*(strlen(symname)+2));
@@ -182,7 +188,7 @@
         return APR_EINIT;
      }

-#else /* use dlsym()/dlerror() */
+#elif defined(DSO_USE_DLFCN)

  #if defined(DLSYM_NEEDS_UNDERSCORE)
      void *retval;
@@ -190,12 +196,11 @@
      sprintf(symbol, "_%s", symname);
      retval = dlsym(handle->handle, symbol);
      free(symbol);
-
  #elif defined(SEQUENT) || defined(SNI)
      void *retval = dlsym(handle->handle, (char *)symname);
  #else
      void *retval = dlsym(handle->handle, symname);
-#endif
+#endif /* DLSYM_NEEDS_UNDERSCORE */

      if (retval == NULL) {
          handle->errormsg = dlerror();
@@ -205,7 +210,7 @@
      *ressym = retval;

      return APR_SUCCESS;
-#endif /* use dlsym()/dlerror() */
+#endif /* DSO_USE_x */
  }

  APR_DECLARE(const char *) apr_dso_error(apr_dso_handle_t *dso, char 
*buffer, apr_size_t buflen)

Re: Clean up of DSO autoconfizification

Posted by Wilfredo Sanchez <ws...@MIT.EDU>.
On Wednesday, April 18, 2001, at 03:48 PM, Greg Stein wrote:

> I used an even cleaner solution in Python about a year and a half ago. 
> At
> config time, I selected one of N files to compile and link in. Each 
> module
> implemented a specific method.

   Yup.  That's how perl does it as well.  dynload_next.c should be 
dynload_dyld.c.  :)

   Only snag I have with that is that although there are several #if foo 
things in dso.c, there is also a reasonably bit of shared code, and I 
think it's easier to make changes that effect all the implementations 
when you can see them all right there.  But  I can go either way on that.

   Anyway, I'll go ahead and commit.

	-Fred

Re: Clean up of DSO autoconfizification

Posted by Greg Stein <gs...@lyra.org>.
On Wed, Apr 18, 2001 at 02:56:02PM -0700, rbb@covalent.net wrote:
> On Wed, 18 Apr 2001, Wilfredo Sanchez wrote:
> 
> >    I don't like how we detect whether DSO support should be enabled by
> > testing for the possible implementation methods, and then rather than
> > remembering which we found, we have all this #if THIS_OS crap all over
> > dso/unix/dso.c.  If we found dlfcn or shl or whatever, that should be
> > what we conditionalize on, and maybe have per-OS mangling for the
> > variant dlopen() hoo-hah out there.
> >
> >    So here is a patch to define macros for the found support for dynamic
> > loading.  I imagine that I picked stupid names for the macros, and would
> > welcome a correction.  Otherwise, this seem OK?
> 
> +1.  The old code was lifted out of 1.3 directly.  This is much easier to
> understand.

+1, much better.

I used an even cleaner solution in Python about a year and a half ago. At
config time, I selected one of N files to compile and link in. Each module
implemented a specific method. Here are the modules that Python has:

dynload_aix.c   dynload_hpux.c  dynload_os2.c    dynload_win.c
dynload_beos.c  dynload_mac.c   dynload_shlib.c
dynload_dl.c    dynload_next.c  dynload_stub.c

That last is when dynload isn't available on a platform. It all works quite
well, and the above kind of structure would actually work reasonably well in
our setup.

But hey... Let's go with Fred's patch now. The above is work that hasn't
been done, and I'm not volunteering right now, so forget it :-)  I just
wanted to put out the brain-bug in case somebody wants to get motivated.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: Clean up of DSO autoconfizification

Posted by rb...@covalent.net.
On Wed, 18 Apr 2001, Wilfredo Sanchez wrote:

>    I don't like how we detect whether DSO support should be enabled by
> testing for the possible implementation methods, and then rather than
> remembering which we found, we have all this #if THIS_OS crap all over
> dso/unix/dso.c.  If we found dlfcn or shl or whatever, that should be
> what we conditionalize on, and maybe have per-OS mangling for the
> variant dlopen() hoo-hah out there.
>
>    So here is a patch to define macros for the found support for dynamic
> loading.  I imagine that I picked stupid names for the macros, and would
> welcome a correction.  Otherwise, this seem OK?

+1.  The old code was lifted out of 1.3 directly.  This is much easier to
understand.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------