On 4/3/12 2:36 AM, Stefan Seifert wrote:
On Monday 02 April 2012 18:51:08 James E Keenan wrote:

Can someone (e.g., alester or nine, who have been working on this file)
take a look at this?

And, while you're at it, could you write documentation for these three
functions?  (If there had been some documentation, I might have had more
of a clue as to what to do with the assert.)

Sorry, the only thing I did with this file is fix some codingstd violations. I
don't even have more than a vague idea what these functions are used for...

Stefan / nine

The miracle of 'git blame' points us to a54ec4cf, wherein duke applied a patch that had been languishing for some time.

duke, do you think you could write a few phrases of documentation for these functions?

Thank you very much.
Jim Keenan
commit a54ec4cf9b4f0eedbd76532d3ee88c1675fdf602
Author: Jonathan "Duke" Leto <[email protected]>
Date:   Sat Mar 10 12:23:58 2012 -0800

    Manually apply a slightly bitrotten patch from the heidnes++ Trac user that fixes a dlclose bug

diff --git a/src/platform/generic/dl.c b/src/platform/generic/dl.c
index 6d6a1da..f1196b6 100644
--- a/src/platform/generic/dl.c
+++ b/src/platform/generic/dl.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004-2010, Parrot Foundation.
+ * Copyright (C) 2004-2012, Parrot Foundation.
  */
 
 /*
@@ -23,11 +23,70 @@ Parrot functions which wrap around standard library functions for handling dynam
 #include "parrot/parrot.h"
 
 #ifdef PARROT_HAS_HEADER_DLFCN
+#  include <stddef.h>
+#  include <stdlib.h>
 #  include <dlfcn.h>
 #endif
 
 #define PARROT_DLOPEN_FLAGS RTLD_LAZY
 
+#ifdef PARROT_HAS_HEADER_DLFCN
+
+struct handle_entry {
+    void *handle;
+    struct handle_entry *next;
+};
+
+struct handle_entry *handle_list = NULL;
+
+static void
+push_handle_entry(void *handle)
+{
+    struct handle_entry *e;
+
+    e = malloc(sizeof(struct handle_entry));
+    if (!e) { return; }
+    e->handle = handle;
+    e->next = handle_list;
+    handle_list = e;
+}
+
+static void *
+find_handle_entry(void *handle)
+{
+    struct handle_entry *e;
+
+    for(e = handle_list; e; e = e->next) {
+    if (e->handle == handle)
+        return handle;
+    }
+    return NULL;
+}
+
+static void
+remove_handle_entry(void *handle)
+{
+    struct handle_entry *cur, *prev, *p;
+
+    if (handle_list) {
+    if (handle_list->handle == handle) {
+        p = handle_list;
+        handle_list = p->next;
+        free(p);
+    } else {
+        for (cur = handle_list; cur; prev = cur, cur = cur->next) {
+        if (cur->handle == handle) {
+            prev->next = cur->next;
+            free(cur);
+        }
+        }
+    }
+    }
+}
+#endif /* PARROT_HAS_HEADER_DLFCN */
+
+
+
 /* HEADERIZER HFILE: none */
 
 /*
@@ -46,8 +105,12 @@ void *
 Parrot_dlopen(const char *filename, Parrot_dlopen_flags flags)
 {
 #ifdef PARROT_HAS_HEADER_DLFCN
-    return dlopen(filename, PARROT_DLOPEN_FLAGS
-                    | ((flags & Parrot_dlopen_global_FLAG) ? RTLD_GLOBAL : 0));
+    void *h;
+
+    h = dlopen(filename, PARROT_DLOPEN_FLAGS |
+            ((flags & Parrot_dlopen_global_FLAG) ? RTLD_GLOBAL : 0));
+    push_handle_entry(h);
+    return h;
 #else
     return 0;
 #endif
@@ -114,7 +177,13 @@ int
 Parrot_dlclose(void *handle)
 {
 #ifdef PARROT_HAS_HEADER_DLFCN
-    return dlclose(handle);
+    int rv;
+
+    if (find_handle_entry(handle)) {
+        remove_handle_entry(handle);
+        rv = dlclose(handle);
+        return rv;
+    }
 #else
     return -1;
 #endif
_______________________________________________
http://lists.parrot.org/mailman/listinfo/parrot-dev

Reply via email to