Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2011-05-06 19:17:42 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2011-05-06 19:17:42 +0400
commit4eb1b5256e0159f747c055e10bd091a40fc834b7 (patch)
tree9acaafab326857e96e7294be60914399b4b7076c /source/blender/blenlib/intern/dynlib.c
parente26b0c68a4c6e284e2d5690588fc7dad6e7a8112 (diff)
Code cleanup: PIL_dynlib, renamed to BLI_dynlib, and other tweaks.
Diffstat (limited to 'source/blender/blenlib/intern/dynlib.c')
-rw-r--r--source/blender/blenlib/intern/dynlib.c103
1 files changed, 47 insertions, 56 deletions
diff --git a/source/blender/blenlib/intern/dynlib.c b/source/blender/blenlib/intern/dynlib.c
index 855fa2dfbf9..ae6589b6538 100644
--- a/source/blender/blenlib/intern/dynlib.c
+++ b/source/blender/blenlib/intern/dynlib.c
@@ -31,110 +31,101 @@
* \ingroup bli
*/
-
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
-#include "../PIL_dynlib.h"
+#include "MEM_guardedalloc.h"
-#if !defined(CHAR_MAX)
-#define CHAR_MAX 255
-#endif
+#include "BLI_dynlib.h"
+
+struct DynamicLibrary {
+ void *handle;
+};
-/*
- * XXX, should use mallocN so we can see
- * handle's not being released. fixme zr
- */
-
#ifdef WIN32
-#include <string.h>
-#include <stdio.h>
#include <windows.h>
-struct PILdynlib {
- void *handle;
-};
-
-PILdynlib *PIL_dynlib_open(char *name) {
+DynamicLibrary *BLI_dynlib_open(char *name)
+{
+ DynamicLibrary *lib;
void *handle= LoadLibrary(name);
- if (handle) {
- PILdynlib *lib= malloc(sizeof(*lib));
- lib->handle= handle;
-
- return lib;
- } else {
+ if(!handle)
return NULL;
- }
+
+ lib= MEM_callocN(sizeof(*lib), "Dynamic Library");
+ lib->handle= handle;
+
+ return lib;
}
-void *PIL_dynlib_find_symbol(PILdynlib* lib, const char *symname) {
+void *BLI_dynlib_find_symbol(DynamicLibrary *lib, const char *symname)
+{
return GetProcAddress(lib->handle, symname);
}
-char *PIL_dynlib_get_error_as_string(PILdynlib* lib) {
+char *BLI_dynlib_get_error_as_string(DynamicLibrary *lib)
+{
int err;
/* if lib is NULL reset the last error code */
err= GetLastError();
- if (!lib) SetLastError(ERROR_SUCCESS);
+ if(!lib)
+ SetLastError(ERROR_SUCCESS);
- if (err) {
+ if(err) {
static char buf[1024];
- if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- err,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- buf,
- sizeof(buf),
- NULL))
+ if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ buf, sizeof(buf), NULL))
return buf;
}
return NULL;
}
-void PIL_dynlib_close(PILdynlib *lib) {
+void BLI_dynlib_close(DynamicLibrary *lib)
+{
FreeLibrary(lib->handle);
-
- free(lib);
+ MEM_freeN(lib);
}
-#else /* Unix */
+#else /* Unix */
#include <dlfcn.h>
-struct PILdynlib {
- void *handle;
-};
-
-PILdynlib *PIL_dynlib_open(char *name) {
+DynamicLibrary *BLI_dynlib_open(char *name)
+{
+ DynamicLibrary *lib;
void *handle= dlopen(name, RTLD_LAZY);
- if (handle) {
- PILdynlib *lib= malloc(sizeof(*lib));
- lib->handle= handle;
-
- return lib;
- } else {
+ if(!handle)
return NULL;
- }
+
+ lib= MEM_callocN(sizeof(*lib), "Dynamic Library");
+ lib->handle= handle;
+
+ return lib;
}
-void *PIL_dynlib_find_symbol(PILdynlib* lib, const char *symname) {
+void *BLI_dynlib_find_symbol(DynamicLibrary *lib, const char *symname)
+{
return dlsym(lib->handle, symname);
}
-char *PIL_dynlib_get_error_as_string(PILdynlib* lib) {
+char *BLI_dynlib_get_error_as_string(DynamicLibrary *lib)
+{
(void)lib; /* unused */
return dlerror();
}
-void PIL_dynlib_close(PILdynlib *lib) {
+void BLI_dynlib_close(DynamicLibrary *lib)
+{
dlclose(lib->handle);
-
- free(lib);
+ MEM_freeN(lib);
}
#endif