ObjFW  Check-in [cdfdea289e]

Overview
Comment:Use OFMutableString in OFPlugin instead of doing it manually.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: cdfdea289e0d4e6fc51e7dcd2d5983b9c2af9b16719ac7b1771047336c6347b9
User & Date: js on 2009-09-01 11:39:36
Other Links: manifest | tags
Context
2009-09-08
16:06
New OFDictionary implementation and removal of a hack in OFList. check-in: bbf1f79b8f user: js tags: trunk
2009-09-01
11:39
Use OFMutableString in OFPlugin instead of doing it manually. check-in: cdfdea289e user: js tags: trunk
11:32
Rename -[length] to -[cStringLength] in OFString. check-in: 3ed599fe98 user: js tags: trunk
Changes

Modified src/OFPlugin.m from [e2e99b5635] to [669225b91e].

12
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "config.h"

#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>

#import "OFPlugin.h"

#import "OFExceptions.h"

@implementation OFPlugin
+ pluginFromFile: (OFString*)path
{

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

	pathlen = [path cStringLength];
	suffixlen = strlen(PLUGIN_SUFFIX);

	if ((file = malloc(pathlen + suffixlen + 1)) == NULL) {
		@throw [OFOutOfMemoryException newWithClass: self
						       size: pathlen +
							     suffixlen + 1];
	}
	memcpy(file, [path cString], pathlen);
	memcpy(file + pathlen, PLUGIN_SUFFIX, suffixlen);
	file[pathlen + suffixlen] = 0;

	if ((handle = dlopen(file, RTLD_LAZY)) == NULL) {
		free(file);
		@throw [OFInitializationFailedException newWithClass: self];
	}
	free(file);

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








>





>
|
<




<
<
|
<
<
|
<
<
<
|
<

|
<

|
|







12
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
39
40
41
42
43
44
45
#include "config.h"

#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>

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

@implementation OFPlugin
+ pluginFromFile: (OFString*)path
{
	OFAutoreleasePool *pool;
	OFString *file;

	void *handle;
	OFPlugin *(*init_plugin)();
	OFPlugin *plugin;



	pool = [[OFAutoreleasePool alloc] init];


	file = [OFMutableString stringWithString: path];



	[file appendCString: PLUGIN_SUFFIX];


	if ((handle = dlopen([file cString], RTLD_LAZY)) == NULL)

		@throw [OFInitializationFailedException newWithClass: self];

	[pool release];

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