below is a complete patch to implement apr_dso_handle_close()
the only cleanup that saved into apr_dso_handle_t was os390:
 dso->failing_errno = errno;
which is pointless since that value is returned by the function and
nothing was checking it anyways.
as you can see, the patch does not change any behavior, just exposes
an api to do the native close.

Index: srclib/apr/dso/aix/dso.c
===================================================================
RCS file: /home/cvs/apr/dso/aix/dso.c,v
retrieving revision 1.14
diff -u -r1.14 dso.c
--- srclib/apr/dso/aix/dso.c    2001/04/02 19:33:03     1.14
+++ srclib/apr/dso/aix/dso.c    2001/04/17 17:08:07
@@ -132,12 +132,23 @@
  * add the basic "wrappers" here.
  */
 
+APR_DECLARE(apr_status_t) apr_dso_handle_close(void *handle)
+{
+    if (handle != NULL && dlclose(handle) != 0) {
+        return APR_EINIT;
+    }
+    return APR_SUCCESS;
+}
+
 static apr_status_t dso_cleanup(void *thedso)
 {
+    apr_status_t status;
     apr_dso_handle_t *dso = thedso;
 
-    if (dso->handle != NULL && dlclose(dso->handle) != 0)
-        return APR_EINIT;
+    if ((status = apr_dso_handle_close(dso->handle)) != APR_SUCCESS) {
+        return status;
+    }
+
     dso->handle = NULL;
 
     return APR_SUCCESS;
Index: srclib/apr/dso/beos/dso.c
===================================================================
RCS file: /home/cvs/apr/dso/beos/dso.c,v
retrieving revision 1.17
diff -u -r1.17 dso.c
--- srclib/apr/dso/beos/dso.c   2001/03/05 00:15:46     1.17
+++ srclib/apr/dso/beos/dso.c   2001/04/17 17:08:11
@@ -56,12 +56,23 @@
 
 #if APR_HAS_DSO
 
+APR_DECLARE(apr_status_t) apr_dso_handle_close(void *handle)
+{
+    if (handle != NULL && unload_add_on(handle) < B_NO_ERROR) {
+        return APR_EINIT;
+    }
+    return APR_SUCCESS;
+}
+
 static apr_status_t dso_cleanup(void *thedso)
 {
+    apr_status_t status;
     apr_dso_handle_t *dso = thedso;
+
+    if ((status = apr_dso_handle_close(dso->handle)) != APR_SUCCESS) {
+        return status;
+    }
 
-    if (dso->handle != NULL && unload_add_on(dso->handle) < B_NO_ERROR)
-      return APR_EINIT;
     dso->handle = NULL;
 
     return APR_SUCCESS;
Index: srclib/apr/dso/os2/dso.c
===================================================================
RCS file: /home/cvs/apr/dso/os2/dso.c,v
retrieving revision 1.21
diff -u -r1.21 dso.c
--- srclib/apr/dso/os2/dso.c    2001/02/16 04:15:32     1.21
+++ srclib/apr/dso/os2/dso.c    2001/04/17 17:08:14
@@ -59,20 +59,27 @@
 
 #if APR_HAS_DSO
 
+APR_DECLARE(apr_status_t) apr_dso_handle_close(void *handle)
+{
+    int rc = DosFreeModule(handle);
+    return APR_OS2_STATUS(rc);
+}
+
 static apr_status_t dso_cleanup(void *thedso)
 {
+    apr_status_t status;
     apr_dso_handle_t *dso = thedso;
-    int rc;
 
     if (dso->handle == 0)
         return APR_SUCCESS;
        
-    rc = DosFreeModule(dso->handle);
+    if ((status = apr_dso_handle_close(dso->handle)) != APR_SUCCESS) {
+        return status;
+    }
 
-    if (rc == 0)
-        dso->handle = 0;
+    dso->handle = 0;
 
-    return APR_OS2_STATUS(rc);
+    return APR_SUCCESS;
 }
 
 
Index: srclib/apr/dso/os390/dso.c
===================================================================
RCS file: /home/cvs/apr/dso/os390/dso.c,v
retrieving revision 1.8
diff -u -r1.8 dso.c
--- srclib/apr/dso/os390/dso.c  2001/02/16 04:15:33     1.8
+++ srclib/apr/dso/os390/dso.c  2001/04/17 17:08:18
@@ -59,22 +59,33 @@
 
 #if APR_HAS_DSO
 
+APR_DECLARE(apr_status_t) apr_dso_handle_close(void *handle)
+{
+    int rc;
+    rc = dllfree(handle);
+
+    if (rc == 0) {
+        return APR_SUCCESS;
+    }
+
+    return errno;
+}
+
 static apr_status_t dso_cleanup(void *thedso)
 {
+    apr_status_t status;
     apr_dso_handle_t *dso = thedso;
-    int rc;
 
     if (dso->handle == 0)
         return APR_SUCCESS;
        
-    rc = dllfree(dso->handle);
-
-    if (rc == 0) {
-        dso->handle = 0;
-        return APR_SUCCESS;
+    if ((status = apr_dso_handle_close(dso->handle)) != APR_SUCCESS) {
+        return status;
     }
-    dso->failing_errno = errno;
-    return errno;
+
+    dso->handle = 0;
+
+    return APR_SUCCESS;
 }
 
 APR_DECLARE(apr_status_t) apr_dso_load(apr_dso_handle_t **res_handle, 
Index: srclib/apr/dso/unix/dso.c
===================================================================
RCS file: /home/cvs/apr/dso/unix/dso.c,v
retrieving revision 1.33
diff -u -r1.33 dso.c
--- srclib/apr/dso/unix/dso.c   2001/02/16 21:04:17     1.33
+++ srclib/apr/dso/unix/dso.c   2001/04/17 17:08:21
@@ -64,19 +64,30 @@
 #include <string.h> /* for strerror() on HP-UX */
 #endif
 
+APR_DECLARE(apr_status_t) apr_dso_handle_close(void *handle)
+{
+#if defined(HPUX) || defined(HPUX10) || defined(HPUX11)
+    shl_unload((shl_t)dso->handle);
+#else
+    if (dlclose(handle) != 0) {
+        return APR_EINIT;
+    }
+#endif
+    return APR_SUCCESS;
+}
+
 static apr_status_t dso_cleanup(void *thedso)
 {
+    apr_status_t status;
     apr_dso_handle_t *dso = thedso;
 
     if (dso->handle == NULL)
         return APR_SUCCESS;
 
-#if defined(HPUX) || defined(HPUX10) || defined(HPUX11)
-    shl_unload((shl_t)dso->handle);
-#else
-    if (dlclose(dso->handle) != 0)
-        return APR_EINIT;
-#endif
+    if ((status = apr_dso_handle_close(dso->handle)) != APR_SUCCESS) {
+        return status;
+    }
+
     dso->handle = NULL;
 
     return APR_SUCCESS;
Index: srclib/apr/dso/win32/dso.c
===================================================================
RCS file: /home/cvs/apr/dso/win32/dso.c,v
retrieving revision 1.21
diff -u -r1.21 dso.c
--- srclib/apr/dso/win32/dso.c  2001/02/16 04:15:34     1.21
+++ srclib/apr/dso/win32/dso.c  2001/04/17 17:08:24
@@ -59,13 +59,23 @@
 
 #if APR_HAS_DSO
 
+APR_DECLARE(apr_status_t) apr_dso_handle_close(void *handle)
+{
+    if (handle != NULL && !FreeLibrary(handle)) {
+        return apr_get_os_error();
+    }
+    return APR_SUCCESS;
+}
+
 static apr_status_t dso_cleanup(void *thedso)
 {
+    apr_status_t status;
     apr_dso_handle_t *dso = thedso;
 
-    if (dso->handle != NULL && !FreeLibrary(dso->handle)) {
-        return apr_get_os_error();
+    if ((status = apr_dso_handle_close(dso->handle)) != APR_SUCCESS) {
+        return status;
     }
+
     dso->handle = NULL;
 
     return APR_SUCCESS;
Index: srclib/apr/include/apr_dso.h
===================================================================
RCS file: /home/cvs/apr/include/apr_dso.h,v
retrieving revision 1.28
diff -u -r1.28 apr_dso.h
--- srclib/apr/include/apr_dso.h        2001/02/16 04:15:42     1.28
+++ srclib/apr/include/apr_dso.h        2001/04/17 17:08:49
@@ -118,6 +118,13 @@
  */
 APR_DECLARE(const char *) apr_dso_error(apr_dso_handle_t *dso, char *buf, 
apr_size_t bufsize);
 
+/**
+ * close a native dso handle
+ * @param handle The handle to close
+ * @deffunc apr_status_t apr_dso_handle_close(void *handle)
+ */
+APR_DECLARE(apr_status_t) apr_dso_handle_close(void *handle);
+
 #endif /* APR_HAS_DSO */
 
 #ifdef __cplusplus


Reply via email to