ObjFW  Diff

Differences From Artifact [bfb6a3d936]:

To Artifact [ee4d5662a9]:

  • File src/OFPlugin.m — part of check-in [179174571e] at 2009-04-19 17:06:46 on branch trunk — Don't use forwarding for OFPlugin.

    This is faster and we don't rely on forwarding which is broken in
    both, the GNU and the Apple runtime. Eventually, there will be an
    implementation for forwarding that does work around the runtime bugs,
    but still, an implementation of OFPlugin without forwarding makes more
    sense. (user: js, size: 1562) [annotate] [blame] [check-ins using]


17
18
19
20
21
22
23
24
25
26
27
28
29
30

31

32
33
34
35
36
37
38

#import "OFPlugin.h"
#import "OFExceptions.h"

@implementation OFPlugin
+ pluginFromFile: (const char*)path
{
	return [[[OFPlugin alloc] initFromFile: path] autorelease];
}

- initFromFile: (const char*)path
{
	char *file;
	size_t pathlen, suffixlen;

	id (*init_plugin)();

	Class c;

	if ((self = [super init])) {
		pathlen = strlen(path);
		suffixlen = strlen(PLUGIN_SUFFIX);

		if ((file = malloc(pathlen + suffixlen + 1)) == NULL) {







<
<
<
<
<


>
|
>







17
18
19
20
21
22
23





24
25
26
27
28
29
30
31
32
33
34
35

#import "OFPlugin.h"
#import "OFExceptions.h"

@implementation OFPlugin
+ pluginFromFile: (const char*)path
{





	char *file;
	size_t pathlen, suffixlen;
	void *handle;
	OFPlugin *(*init_plugin)();
	OFPlugin *plugin;
	Class c;

	if ((self = [super init])) {
		pathlen = strlen(path);
		suffixlen = strlen(PLUGIN_SUFFIX);

		if ((file = malloc(pathlen + suffixlen + 1)) == NULL) {
59
60
61
62
63
64
65



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
		    (plugin = init_plugin()) == nil) {
			dlclose(handle);
			c = [self class];
			[super free];
			@throw [OFInitializationFailedException
			    newWithClass: c];
		}



	}

	return self;
}

- free
{
	[plugin free];
	dlclose(handle);

	return [super free];
}

#ifdef __objc_INCLUDE_GNU
- (retval_t)forward: (SEL)selector
		   : (arglist_t)args
#else
- (id)forward: (SEL)selector
	     : (marg_list)args
#endif
{
	return [plugin performv: selector
			       : args];
}

- (IMP)methodFor: (SEL)selector
{
	if ([self respondsTo: selector])
		return [self methodFor: selector];
	else
		return [plugin methodFor: selector];
}
@end







>
>
>







<




<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

73
74
75
76




















77
		    (plugin = init_plugin()) == nil) {
			dlclose(handle);
			c = [self class];
			[super free];
			@throw [OFInitializationFailedException
			    newWithClass: c];
		}

		plugin->handle = handle;
		return plugin;
	}

	return self;
}

- free
{

	dlclose(handle);

	return [super free];
}




















@end