static int freelib(MODLIST *root, AMX *amx, const TCHAR *name) { MODLIST _FAR *item, _FAR *prev; const TCHAR *ptr; int count = 0; ptr = (name != NULL) ? skippath(name) : NULL; for (prev = root, item = prev->next; item != NULL; prev = item, item = prev->next) { if ((amx == NULL || amx == item->amx) && (ptr == NULL || _tcscmp(item->name, ptr) == 0)) { prev->next = item->next; /* unlink first */ assert(item->inst != 0); #if defined HAVE_DYNCALL_H dlFreeLibrary(item->inst); #else FreeLibrary((HINSTANCE)item->inst); #endif assert(item->name != NULL); free(item->name); free(item); count++; } /* if */ } /* for */ #if defined HAVE_DYNCALL_H if (root->next==NULL && dcVM!=NULL) { /* free the VM after closing the last DLL/library */ dcFree(dcVM); dcVM=NULL; } /* if */ #endif return count; }
int main(int argc, char* argv[]) { int i, n; DLLib* pLib; const char* libPath; if (argc == 1) { fprintf(stderr, "usage : %s <dllpath>\n", argv[0]); return 1; } libPath = argv[1]; /* load lib */ pLib = dlLoadLibrary(libPath); if (!pLib) { fprintf(stderr, "unable to open library %s\n", libPath); return 2; } list_syms(libPath); dlFreeLibrary(pLib); return 0; }
void dlSymsCleanup(DLSyms* pSyms) { if(pSyms) { dlFreeLibrary(pSyms->pLib); dlFreeMem(pSyms); } }
int MVM_dll_free(MVMThreadContext *tc, MVMString *name) { MVMDLLRegistry *entry; uv_mutex_lock(&tc->instance->mutex_dll_registry); MVM_string_flatten(tc, name); MVM_HASH_GET(tc, tc->instance->dll_registry, name, entry); if (!entry) { uv_mutex_unlock(&tc->instance->mutex_dll_registry); MVM_exception_throw_adhoc(tc, "cannot free non-existent library"); } /* already freed */ if (!entry->lib) return 0; if (entry->refcount > 0) { uv_mutex_unlock(&tc->instance->mutex_dll_registry); MVM_exception_throw_adhoc(tc, "cannot free in-use library"); } dlFreeLibrary(entry->lib); entry->lib = NULL; uv_mutex_unlock(&tc->instance->mutex_dll_registry); return 1; }
/* This is called to do any cleanup of resources when an object gets * embedded inside another one. Never called on a top-level object. */ static void gc_cleanup(PARROT_INTERP, STable *st, void *data) { NativeCallBody *body = (NativeCallBody *)data; if (body->lib_name) Parrot_str_free_cstring(body->lib_name); if (body->lib_handle) dlFreeLibrary(body->lib_handle); if (body->arg_types) mem_sys_free(body->arg_types); }
SEXP rdcFree(SEXP sLibHandle) { void* libHandle; libHandle = R_ExternalPtrAddr(sLibHandle); dlFreeLibrary( libHandle ); R_SetExternalPtrAddr(sLibHandle, 0); return R_NilValue; }
static MODLIST _FAR *addlib(MODLIST *root, AMX *amx, const TCHAR *name) { MODLIST _FAR *item; const TCHAR *ptr = skippath(name); assert(findlib(root, amx, name) == NULL); /* should not already be there */ if ((item = malloc(sizeof(MODLIST))) == NULL) goto error; memset(item, 0, sizeof(MODLIST)); assert(ptr != NULL); if ((item->name = malloc((_tcslen(ptr) + 1) * sizeof(TCHAR))) == NULL) goto error; _tcscpy(item->name, ptr); #if defined HAVE_DYNCALL_H item->inst=dlLoadLibrary(name); #else item->inst=(void*)LoadLibrary(name); #if !(defined __WIN32__ || defined _WIN32 || defined WIN32) if ((unsigned long)item->inst<=32) item->inst=NULL; #endif #endif if (item->inst==NULL) goto error; item->amx = amx; item->next = root->next; root->next = item; return item; error: if (item != NULL) { if (item->name != NULL) free(item->name); if (item->inst != 0) { #if defined HAVE_DYNCALL_H dlFreeLibrary(item->inst); #else FreeLibrary((HINSTANCE)item->inst); #endif } /* if */ free(item); } /* if */ return NULL; }
static PyObject* pydc_free(PyObject* self, PyObject* args) { PyObject* pcobj; void* libhandle; if ( !PyArg_ParseTuple(args,"o", &pcobj) ) return PyErr_Format(PyExc_RuntimeError, "argument mismatch"); libhandle = PyCObject_AsVoidPtr(pcobj); if (!libhandle) return PyErr_Format(PyExc_RuntimeError, "libhandle is NULL"); dlFreeLibrary(libhandle); PyCObject_SetVoidPtr(pcobj,0); Py_RETURN_NONE; }
void free_library(void* libhandle) { if (libhandle != 0) dlFreeLibrary(libhandle); }