apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Reid" <dr...@jetnet.co.uk>
Subject [PATCH] sms in dso
Date Thu, 31 May 2001 00:46:59 GMT
Folks,

This patch adds a new function that enables apr_dso_t's to use apr_sms_t as
their memory device.  As they don't use a lot of memory this should be very
low impact, but the other platforms need to be done...  It does raise some
issues as to whether this is a good idea or not.  I'd like to think that in
time we'd have apr_sms_t's being used instead of pools, but that's a VERY
long way off at the moment, so consider this a first tentative step...
Unless people squawk I'll add it at some point soon.

Patch was done in beos (it's easier to work in) and hasn't yet been tested
on unix but should work (another reason for not blindly commiting).

david

Index: dso/beos/dso.c
===================================================================
RCS file: /home/cvs/apr/dso/beos/dso.c,v
retrieving revision 1.20
diff -u -r1.20 dso.c
--- dso/beos/dso.c 2001/04/29 22:03:43 1.20
+++ dso/beos/dso.c 2001/05/30 23:47:27
@@ -52,6 +52,7 @@
  * <http://www.apache.org/>.
  */

+#include "apr_dso.h"
 #include "beos/dso.h"
 #include "apr_portable.h"

@@ -85,9 +86,28 @@
     return APR_SUCCESS;
 }

+APR_DECLARE(apr_status_t) apr_dso_sms_load(apr_dso_handle_t **res_handle,
+                                           const char *path, apr_sms_t
*mem_sys)
+{
+    image_id newid;
+
+    if((newid = load_add_on(path)) < B_NO_ERROR)
+        return APR_EINIT;
+
+    *res_handle = apr_sms_calloc(mem_sys, sizeof(*res_handle));
+    (*res_handle)->handle = newid;
+    (*res_handle)->mem_sys = mem_sys;
+
+    apr_sms_cleanup_register(mem_sys, APR_ALL_CLEANUPS, *res_handle,
dso_cleanup);
+    return APR_SUCCESS;
+}
+
 APR_DECLARE(apr_status_t) apr_dso_unload(apr_dso_handle_t *handle)
 {
-    return apr_pool_cleanup_run(handle->pool, handle, dso_cleanup);
+    if (handle->pool)
+        return apr_pool_cleanup_run(handle->pool, handle, dso_cleanup);
+
+    return apr_sms_cleanup_run(handle->mem_sys, APR_ALL_CLEANUPS, handle,
dso_cleanup);
 }

 APR_DECLARE(apr_status_t) apr_dso_sym(apr_dso_handle_sym_t *ressym,
apr_dso_handle_t *handle,
Index: dso/unix/dso.c
===================================================================
RCS file: /home/cvs/apr/dso/unix/dso.c,v
retrieving revision 1.40
diff -u -r1.40 dso.c
--- dso/unix/dso.c 2001/04/29 21:37:17 1.40
+++ dso/unix/dso.c 2001/05/30 23:47:29
@@ -162,10 +162,71 @@

     return APR_SUCCESS;
 }
+
+APR_DECLARE(apr_status_t) apr_dso_sms_load(apr_dso_handle_t **res_handle,
+                                       const char *path, apr_sms_t
*mem_sys)
+{
+#if defined(DSO_USE_SHL)
+    shl_t os_handle = shl_load(path,
BIND_IMMEDIATE|BIND_VERBOSE|BIND_NOSTART, 0L);
+
+#elif defined(DSO_USE_DYLD)
+    NSObjectFileImage image;
+    NSModule os_handle;
+    char* err_msg = NULL;
+    if (NSCreateObjectFileImageFromFile(path, &image) !=
NSObjectFileImageSuccess) {
+ err_msg = "cannot create object file image";
+    }
+    else {
+#ifdef NSLINKMODULE_OPTION_PRIVATE
+      os_handle = NSLinkModule(image, path,
+          NSLINKMODULE_OPTION_PRIVATE |
+          NSLINKMODULE_OPTION_RETURN_ON_ERROR);
+#else
+      os_handle = NSLinkModule(image, path, TRUE);
+#endif
+    }
+
+#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_sms_calloc(mem_sys, sizeof(**res_handle));
+
+    if(os_handle == NULL) {
+#if defined(DSO_USE_SHL)
+        (*res_handle)->errormsg = strerror(errno);
+        return errno;
+#elif defined(DSO_USE_DYLD)
+        (*res_handle)->errormsg = (err_msg) ? err_msg : "link failed";
+        return APR_EDSOOPEN;
+#elif defined(DSO_USE_DLFCN)
+        (*res_handle)->errormsg = dlerror();
+        return APR_EDSOOPEN;
+#endif
+    }
+
+    (*res_handle)->handle = (void*)os_handle;
+    (*res_handle)->mem_sys = mem_sys;
+    (*res_handle)->errormsg = NULL;
+
+    apr_sms_cleanup_register(mem_sys, APR_ALL_CLEANUPS, *res_handle,
+                             dso_cleanup);
+
+    return APR_SUCCESS;
+}

 APR_DECLARE(apr_status_t) apr_dso_unload(apr_dso_handle_t *handle)
 {
-    return apr_pool_cleanup_run(handle->pool, handle, dso_cleanup);
+    if (handle->pool)
+        return apr_pool_cleanup_run(handle->pool, handle, dso_cleanup);
+    return apr_sms_cleanup_run(handle->mem_sys, APR_ALL_CLEANUPS,
+                               handle, dso_cleanup);
 }

 APR_DECLARE(apr_status_t) apr_dso_sym(apr_dso_handle_sym_t *ressym,
Index: 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
--- include/apr_dso.h 2001/02/16 04:15:42 1.28
+++ include/apr_dso.h 2001/05/30 23:47:38
@@ -58,6 +58,7 @@
 #include "apr.h"
 #include "apr_pools.h"
 #include "apr_errno.h"
+#include "apr_sms.h"

 /**
  * @package Dynamic Object Handling
@@ -90,6 +91,17 @@
  */
 APR_DECLARE(apr_status_t) apr_dso_load(apr_dso_handle_t **res_handle,
                                        const char *path, apr_pool_t *ctx);
+
+/**
+ * Load a DSO library, using an apr_sms_t for memory allocation.
+ * @param res_handle Location to store new handle for the DSO.
+ * @param path_sys Path to the DSO library
+ * @param mem_sys apr_sms_t to use.
+ * @deffunc apr_status_t apr_dso_sms_load(apr_dso_handle_t **res_handle,
+ *                                        const char *path, apr_sms_t
*mem_sys)
+ */
+APR_DECLARE(apr_status_t) apr_dso_sms_load(apr_dso_handle_t **res_handle,
+                                           const char *path, apr_sms_t
*mem_sys);

 /**
  * Close a DSO library.
Index: include/arch/beos/dso.h
===================================================================
RCS file: /home/cvs/apr/include/arch/beos/dso.h,v
retrieving revision 1.13
diff -u -r1.13 dso.h
--- include/arch/beos/dso.h 2001/04/29 22:03:43 1.13
+++ include/arch/beos/dso.h 2001/05/30 23:47:42
@@ -69,6 +69,7 @@
 struct apr_dso_handle_t {
     image_id      handle;    /* Handle to the DSO loaded */
     apr_pool_t   *pool;
+    apr_sms_t    *mem_sys;   /*not normally used yet */
 };

 #endif
Index: include/arch/unix/dso.h
===================================================================
RCS file: /home/cvs/apr/include/arch/unix/dso.h,v
retrieving revision 1.14
diff -u -r1.14 dso.h
--- include/arch/unix/dso.h 2001/04/29 21:37:16 1.14
+++ include/arch/unix/dso.h 2001/05/30 23:47:45
@@ -91,6 +91,7 @@

 struct apr_dso_handle_t {
     apr_pool_t    *pool;
+    apr_sms_t     *mem_sys; /* normally not used */
     void          *handle;
     const char    *errormsg;
 };


Mime
View raw message