ObjFW  Check-in [c91508ddfb]

Overview
Comment:Windows improvements for of_dl{open,sym,close}
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c91508ddfb59ea22c2e2ebe2fb413590478eb8188240c8c6857fa999d87448c3
User & Date: js on 2016-07-11 19:04:29
Other Links: manifest | tags
Context
2016-07-18
18:45
runtime/exception.m: Forward foreign exceptions check-in: 974d386554 user: js tags: trunk
2016-07-11
19:04
Windows improvements for of_dl{open,sym,close} check-in: c91508ddfb user: js tags: trunk
2016-07-10
22:40
Add of_dl{open,sym,close} check-in: 81970b1dab user: js tags: trunk
Changes

Modified src/OFPlugin.h from [31020e84b4] to [ced76ab1ad].

15
16
17
18
19
20
21



22
23
24


25
26
27
28
29
30
31
 */

#import "OFObject.h"

@class OFString;

#ifndef OF_WINDOWS



typedef void* of_plugin_handle_t;
#else
# include <windows.h>


typedef HMODULE of_plugin_handle_t;
#endif

OF_ASSUME_NONNULL_BEGIN

/*!
 * @class OFPlugin OFPlugin.h ObjFW/OFPlugin.h







>
>
>



>
>







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 */

#import "OFObject.h"

@class OFString;

#ifndef OF_WINDOWS
# include <dlfcn.h>
# define OF_RTLD_LAZY RTLD_LAZY
# define OF_RTLD_NOW  RTLD_NOW
typedef void* of_plugin_handle_t;
#else
# include <windows.h>
# define OF_RTLD_LAZY 0
# define OF_RTLD_NOW  0
typedef HMODULE of_plugin_handle_t;
#endif

OF_ASSUME_NONNULL_BEGIN

/*!
 * @class OFPlugin OFPlugin.h ObjFW/OFPlugin.h

Modified src/OFPlugin.m from [565f8364c6] to [50477690f4].

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
of_plugin_handle_t
of_dlopen(OFString *path, int flags)
{
#ifndef OF_WINDOWS
	return dlopen([path cStringWithEncoding:
	    [OFSystemInfo native8BitEncoding]], flags);
#else



	return LoadLibraryW([path UTF16String]);
#endif
}

void*
of_dlsym(of_plugin_handle_t handle, const char *symbol)
{
#ifndef OF_WINDOWS
	return dlsym(handle, symbol);
#else
	return GetProcAddress(handle, symbol);
#endif
}

void
of_dlclose(of_plugin_handle_t handle)
{
#ifndef OF_WINDOWS







>
>
>










|







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
of_plugin_handle_t
of_dlopen(OFString *path, int flags)
{
#ifndef OF_WINDOWS
	return dlopen([path cStringWithEncoding:
	    [OFSystemInfo native8BitEncoding]], flags);
#else
	if (path == nil)
		return GetModuleHandle(NULL);

	return LoadLibraryW([path UTF16String]);
#endif
}

void*
of_dlsym(of_plugin_handle_t handle, const char *symbol)
{
#ifndef OF_WINDOWS
	return dlsym(handle, symbol);
#else
	return (void*)(uintptr_t)GetProcAddress(handle, symbol);
#endif
}

void
of_dlclose(of_plugin_handle_t handle)
{
#ifndef OF_WINDOWS
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
	void *pool = objc_autoreleasePoolPush();
	of_plugin_handle_t handle;
	init_plugin_t initPlugin;
	OFPlugin *plugin;

	path = [path stringByAppendingString: @PLUGIN_SUFFIX];

	if ((handle = of_dlopen(path, RTLD_LAZY)) == NULL)
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];

	objc_autoreleasePoolPop(pool);

	initPlugin = (init_plugin_t)(uintptr_t)of_dlsym(handle, "init_plugin");
	if (initPlugin == (init_plugin_t)0 || (plugin = initPlugin()) == nil) {







|







71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
	void *pool = objc_autoreleasePoolPush();
	of_plugin_handle_t handle;
	init_plugin_t initPlugin;
	OFPlugin *plugin;

	path = [path stringByAppendingString: @PLUGIN_SUFFIX];

	if ((handle = of_dlopen(path, OF_RTLD_LAZY)) == NULL)
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];

	objc_autoreleasePoolPop(pool);

	initPlugin = (init_plugin_t)(uintptr_t)of_dlsym(handle, "init_plugin");
	if (initPlugin == (init_plugin_t)0 || (plugin = initPlugin()) == nil) {