ObjFW  Diff

Differences From Artifact [c230c7ec3d]:

To Artifact [a25e85e2c5]:


21
22
23
24
25
26
27
28
29
30
31


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

#ifndef _WIN32
#include <dlfcn.h>
#endif

#import "OFPlugin.h"
#import "OFString.h"
#import "OFAutoreleasePool.h"

#import "OFInitializationFailedException.h"
#import "OFNotImplementedException.h"



#ifdef _WIN32
# define dlopen(file, mode) LoadLibrary(file)
# define dlsym(handle, symbol) GetProcAddress(handle, symbol)
# define dlclose(handle) FreeLibrary(handle)
#endif

@implementation OFPlugin
+ (id)pluginFromFile: (OFString*)path
{
	OFAutoreleasePool *pool;
	OFMutableString *file;
	of_plugin_handle_t handle;
	OFPlugin *(*initPlugin)(void);
	OFPlugin *plugin;

	pool = [[OFAutoreleasePool alloc] init];
	file = [OFMutableString stringWithString: path];
	[file appendString: @PLUGIN_SUFFIX];

	if ((handle = dlopen([file cStringWithEncoding:
	    OF_STRING_ENCODING_NATIVE], RTLD_LAZY)) == NULL)
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];

	[pool release];

	*(void**)&initPlugin = dlsym(handle, "init_plugin");
	if (initPlugin == NULL || (plugin = initPlugin()) == nil) {
		dlclose(handle);
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
	}







<



>
>










|





<








|







21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

#ifndef _WIN32
#include <dlfcn.h>
#endif

#import "OFPlugin.h"
#import "OFString.h"


#import "OFInitializationFailedException.h"
#import "OFNotImplementedException.h"

#import "autorelease.h"

#ifdef _WIN32
# define dlopen(file, mode) LoadLibrary(file)
# define dlsym(handle, symbol) GetProcAddress(handle, symbol)
# define dlclose(handle) FreeLibrary(handle)
#endif

@implementation OFPlugin
+ (id)pluginFromFile: (OFString*)path
{
	void *pool = objc_autoreleasePoolPush();
	OFMutableString *file;
	of_plugin_handle_t handle;
	OFPlugin *(*initPlugin)(void);
	OFPlugin *plugin;


	file = [OFMutableString stringWithString: path];
	[file appendString: @PLUGIN_SUFFIX];

	if ((handle = dlopen([file cStringWithEncoding:
	    OF_STRING_ENCODING_NATIVE], RTLD_LAZY)) == NULL)
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];

	objc_autoreleasePoolPop(pool);

	*(void**)&initPlugin = dlsym(handle, "init_plugin");
	if (initPlugin == NULL || (plugin = initPlugin()) == nil) {
		dlclose(handle);
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
	}