Ticket #1340: diff

File diff, 2.0 KB (added by heidnes, 12 years ago)

New version of diff, ensuring to include required headers, and omit helper functions if we don't need them.

  • config/gen/platform/generic/dl.c

     
    2222*/ 
    2323 
    2424#ifdef PARROT_HAS_HEADER_DLFCN 
     25#  include <stddef.h> 
     26#  include <stdlib.h> 
    2527#  include <dlfcn.h> 
    2628#endif 
    2729 
    2830#define PARROT_DLOPEN_FLAGS RTLD_LAZY 
    2931 
     32#ifdef PARROT_HAS_HEADER_DLFCN 
     33 
     34struct handle_entry { 
     35    void *handle; 
     36    struct handle_entry *next; 
     37}; 
     38 
     39struct handle_entry *handle_list = NULL; 
     40 
     41static void 
     42push_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 
     53static void * 
     54find_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 
     65static void 
     66remove_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 
    3088/* 
    3189 
    3290=item C<void * Parrot_dlopen(const char *filename)> 
     
    3997Parrot_dlopen(const char *filename) 
    4098{ 
    4199#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; 
    43105#else 
    44106    return 0; 
    45107#endif 
     
    93155Parrot_dlclose(void *handle) 
    94156{ 
    95157#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    } 
    97165#else 
    98166    return -1; 
    99167#endif