ObjFW  Check-in [179174571e]

Overview
Comment: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.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 179174571e60bbee1be7b2366a3ed425f9c2aa9d4935bc326c56f9f4af2940c3
User & Date: js on 2009-04-19 17:06:46
Other Links: manifest | tags
Context
2009-04-19
17:37
Remove forwarding methods. See long commit message for details. check-in: 57fb5578cc user: js tags: trunk
17:06
Don't use forwarding for OFPlugin. check-in: 179174571e user: js tags: trunk
2009-04-17
16:45
Add - hash for OFNumber. check-in: cd9bd80792 user: js tags: trunk
Changes

Modified src/OFPlugin.h from [c1caa01830] to [3326b854c7].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

/**
 * The OFPlugin class provides a system for loading plugins at runtime.
 */
@interface OFPlugin: OFObject
{
	void *handle;
	id   plugin;
}

/**
 * Loads an OFPlugin from a file.
 *
 * \param path Path to the OFPlugin file. The suffix is appended automatically.
 * \return A new autoreleased OFPlugin
 */
+ pluginFromFile: (const char*)path;

/**
 * Initializes an already allocated OFPlugin from a file.
 *
 * \param path Path to the OFPlugin file. The suffix is appended automatically.
 * \return An initialized OFPlugin
 */
- initFromFile: (const char*)path;
@end







<









<
<
<
<
<
<
<
<

13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28








29

/**
 * The OFPlugin class provides a system for loading plugins at runtime.
 */
@interface OFPlugin: OFObject
{
	void *handle;

}

/**
 * Loads an OFPlugin from a file.
 *
 * \param path Path to the OFPlugin file. The suffix is appended automatically.
 * \return A new autoreleased OFPlugin
 */
+ pluginFromFile: (const char*)path;








@end

Modified src/OFPlugin.m from [bfb6a3d936] to [ee4d5662a9].

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

Modified tests/OFPlugin/OFPlugin.m from [0bbeec06e6] to [0f4331146f].

13
14
15
16
17
18
19
20
21
22
23
24
25
26

#import "OFPlugin.h"
#import "TestPlugin/TestPlugin.h"

int
main()
{
	OFPlugin <TestPlugin> *plugin;

	plugin = [OFPlugin pluginFromFile: "TestPlugin/TestPlugin"];
	[plugin test];

	return 0;
}







|






13
14
15
16
17
18
19
20
21
22
23
24
25
26

#import "OFPlugin.h"
#import "TestPlugin/TestPlugin.h"

int
main()
{
	TestPlugin *plugin;

	plugin = [OFPlugin pluginFromFile: "TestPlugin/TestPlugin"];
	[plugin test];

	return 0;
}

Modified tests/OFPlugin/TestPlugin/TestPlugin.h from [464f9220e6] to [f72593c636].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of libobjfw. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#import "OFObject.h"

@protocol TestPlugin
- (void)test;
@end

@interface TestPlugin: OFObject <TestPlugin>
@end











|

|


<
<
<
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16



/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of libobjfw. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#import "OFPlugin.h"

@interface TestPlugin: OFPlugin
- (void)test;
@end