Ticket #1340: diff
File diff, 2.0 KB (added by heidnes, 12 years ago) |
---|
-
config/gen/platform/generic/dl.c
22 22 */ 23 23 24 24 #ifdef PARROT_HAS_HEADER_DLFCN 25 # include <stddef.h> 26 # include <stdlib.h> 25 27 # include <dlfcn.h> 26 28 #endif 27 29 28 30 #define PARROT_DLOPEN_FLAGS RTLD_LAZY 29 31 32 #ifdef PARROT_HAS_HEADER_DLFCN 33 34 struct handle_entry { 35 void *handle; 36 struct handle_entry *next; 37 }; 38 39 struct handle_entry *handle_list = NULL; 40 41 static void 42 push_handle_entry(void *handle) 43 { 44 struct handle_entry *e; 45 46 e = malloc(sizeof(struct handle_entry)); 47 if (!e) { return; } 48 e->handle = handle; 49 e->next = handle_list; 50 handle_list = e; 51 } 52 53 static void * 54 find_handle_entry(void *handle) 55 { 56 struct handle_entry *e; 57 58 for(e = handle_list; e; e = e->next) { 59 if (e->handle == handle) 60 return handle; 61 } 62 return NULL; 63 } 64 65 static void 66 remove_handle_entry(void *handle) 67 { 68 struct handle_entry *cur, *prev, *p; 69 70 if (handle_list) { 71 if (handle_list->handle == handle) { 72 p = handle_list; 73 handle_list = p->next; 74 free(p); 75 } else { 76 for (cur = handle_list; cur; prev = cur, cur = cur->next) { 77 if (cur->handle == handle) { 78 prev->next = cur->next; 79 free(cur); 80 } 81 } 82 } 83 } 84 } 85 #endif /* PARROT_HAS_HEADER_DLFCN */ 86 87 30 88 /* 31 89 32 90 =item C<void * Parrot_dlopen(const char *filename)> … … 39 97 Parrot_dlopen(const char *filename) 40 98 { 41 99 #ifdef PARROT_HAS_HEADER_DLFCN 42 return dlopen(filename, PARROT_DLOPEN_FLAGS); 100 void *h; 101 102 h = dlopen(filename, PARROT_DLOPEN_FLAGS); 103 push_handle_entry(h); 104 return h; 43 105 #else 44 106 return 0; 45 107 #endif … … 93 155 Parrot_dlclose(void *handle) 94 156 { 95 157 #ifdef PARROT_HAS_HEADER_DLFCN 96 return dlclose(handle); 158 int rv; 159 160 if (find_handle_entry(handle)) { 161 remove_handle_entry(handle); 162 rv = dlclose(handle); 163 return rv; 164 } 97 165 #else 98 166 return -1; 99 167 #endif