26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#import "OFLocale.h"
#import "OFString.h"
#import "OFSystemInfo.h"
#import "OFInitializationFailedException.h"
#import "OFLoadPluginFailedException.h"
typedef OFPlugin *(*init_plugin_t)(void);
OFPluginHandle
OFDLOpen(OFString *path, OFDLOpenFlags flags)
{
#ifndef OF_WINDOWS
return dlopen([path cStringWithEncoding: [OFLocale encoding]], flags);
#else
|
|
|
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#import "OFLocale.h"
#import "OFString.h"
#import "OFSystemInfo.h"
#import "OFInitializationFailedException.h"
#import "OFLoadPluginFailedException.h"
typedef OFPlugin *(*PluginInit)(void);
OFPluginHandle
OFDLOpen(OFString *path, OFDLOpenFlags flags)
{
#ifndef OF_WINDOWS
return dlopen([path cStringWithEncoding: [OFLocale encoding]], flags);
#else
|
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
}
@implementation OFPlugin
+ (id)pluginWithPath: (OFString *)path
{
void *pool = objc_autoreleasePoolPush();
OFPluginHandle handle;
init_plugin_t initPlugin;
OFPlugin *plugin;
#if defined(OF_MACOS)
path = [path stringByAppendingFormat: @".bundle/Contents/MacOS/%@",
path.lastPathComponent];
#elif defined(OF_IOS)
path = [path stringByAppendingFormat: @".bundle/%@",
path.lastPathComponent];
#else
path = [path stringByAppendingString: @PLUGIN_SUFFIX];
#endif
if ((handle = OFDLOpen(path, OFDLOpenFlagLazy)) == NULL)
@throw [OFLoadPluginFailedException
exceptionWithPath: path
error: OFDLError()];
objc_autoreleasePoolPop(pool);
initPlugin = (init_plugin_t)(uintptr_t)OFDLSym(handle, "init_plugin");
if (initPlugin == (init_plugin_t)0 || (plugin = initPlugin()) == nil) {
OFDLClose(handle);
@throw [OFInitializationFailedException
exceptionWithClass: self];
}
plugin->_pluginHandle = handle;
return plugin;
|
|
|
|
|
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
}
@implementation OFPlugin
+ (id)pluginWithPath: (OFString *)path
{
void *pool = objc_autoreleasePoolPush();
OFPluginHandle handle;
PluginInit initPlugin;
OFPlugin *plugin;
#if defined(OF_MACOS)
path = [path stringByAppendingFormat: @".bundle/Contents/MacOS/%@",
path.lastPathComponent];
#elif defined(OF_IOS)
path = [path stringByAppendingFormat: @".bundle/%@",
path.lastPathComponent];
#else
path = [path stringByAppendingString: @PLUGIN_SUFFIX];
#endif
if ((handle = OFDLOpen(path, OFDLOpenFlagLazy)) == NULL)
@throw [OFLoadPluginFailedException
exceptionWithPath: path
error: OFDLError()];
objc_autoreleasePoolPop(pool);
initPlugin = (PluginInit)(uintptr_t)OFDLSym(handle, "OFPluginInit");
if (initPlugin == (PluginInit)0 || (plugin = initPlugin()) == nil) {
OFDLClose(handle);
@throw [OFInitializationFailedException
exceptionWithClass: self];
}
plugin->_pluginHandle = handle;
return plugin;
|