diff options
author | Kent Mein <mein@cs.umn.edu> | 2003-02-21 18:37:55 +0300 |
---|---|---|
committer | Kent Mein <mein@cs.umn.edu> | 2003-02-21 18:37:55 +0300 |
commit | 763da870b615419b52efe80cafa9a8e8cf32a303 (patch) | |
tree | f410da24728f1797a837502eed9570ad041bbaf0 /source | |
parent | ad12d5ce677a722836cc80936af69312f9d732b3 (diff) |
The first two files enables building of plugins under macosx.
The third is for actually loading the plugins in blender.
For some reason its not identifying the plugins correctly,
but it compiles and runs so I'm including it hoping someone else
might see where I've messed things up...
I have a simple example at http://www.cs.umn.edu/~mein/test.tgz that
works, if anyone is interested in playing with it.
Kent
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/intern/dynlib.c | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/source/blender/blenlib/intern/dynlib.c b/source/blender/blenlib/intern/dynlib.c index 89c21a9af55..2dd25505adf 100644 --- a/source/blender/blenlib/intern/dynlib.c +++ b/source/blender/blenlib/intern/dynlib.c @@ -36,6 +36,10 @@ #include <config.h> #endif +#if !defined(CHAR_MAX) +#define CHAR_MAX 255 +#endif + /* * XXX, should use mallocN so we can see * handle's not being released. fixme zr @@ -100,13 +104,40 @@ void PIL_dynlib_close(PILdynlib *lib) { #else #ifdef __APPLE__ +#include <mach-o/dyld.h> + +struct PILdynlib { + NSModule *handle; +}; PILdynlib *PIL_dynlib_open(char *name) { - return NULL; + NSObjectFileImage img; + + PILdynlib *lib= malloc(sizeof(*lib)); + if (NSCreateObjectFileImageFromFile( name, &img) == + NSObjectFileImageSuccess) { + lib->handle = NSLinkModule( img, name, NSLINKMODULE_OPTION_BINDNOW); + NSDestroyObjectFileImage(img); + return lib; + } + free(lib); + return NULL; } void *PIL_dynlib_find_symbol(PILdynlib* lib, char *symname) { - return NULL; + char *name; + NSSymbol cr; + int size; + + size = strlen(symname) + 2 * sizeof(char); + if (size < CHAR_MAX) { + name = MEM_mallocN(size, "temp string"); + sprintf(&name, "_%s",symname); + cr = NSLookupSymbolInModule(lib->handle, name); + free(name); + return NSAddressOfSymbol(cr); + } + return NULL; } char *PIL_dynlib_get_error_as_string(PILdynlib* lib) { @@ -114,7 +145,8 @@ char *PIL_dynlib_get_error_as_string(PILdynlib* lib) { } void PIL_dynlib_close(PILdynlib *lib) { - ; + NSUnLinkModule(lib->handle,NSUNLINKMODULE_OPTION_NONE); + free(lib); } #else /* Unix */ |