Mercurial > projects > dwt2
comparison base/src/java/nonstandard/SharedLib.d @ 112:9f4c18c268b2
Update to compile and execute with dmd 2.052.
author | kntroh |
---|---|
date | Wed, 16 Mar 2011 21:53:53 +0900 |
parents | 8a5386b204bb |
children | fb3aa8075988 |
comparison
equal
deleted
inserted
replaced
111:b6e9904989ed | 112:9f4c18c268b2 |
---|---|
2 | 2 |
3 import java.lang.all; | 3 import java.lang.all; |
4 version(Tango){ | 4 version(Tango){ |
5 static import tango.sys.SharedLib; | 5 static import tango.sys.SharedLib; |
6 static import tango.stdc.stringz; | 6 static import tango.stdc.stringz; |
7 } else { // Phobos | |
8 import std.loader; | |
7 } | 9 } |
8 | 10 |
9 struct Symbol { | 11 struct Symbol { |
10 String name; | 12 String name; |
11 void** symbol; | 13 void** symbol; |
20 | 22 |
21 struct SharedLib { | 23 struct SharedLib { |
22 static void loadLibSymbols( SymbolVersioned2[] symbols, String libname, int major, int minor ){ | 24 static void loadLibSymbols( SymbolVersioned2[] symbols, String libname, int major, int minor ){ |
23 version(Tango){ | 25 version(Tango){ |
24 if (auto lib = tango.sys.SharedLib.SharedLib.load(libname)) { | 26 if (auto lib = tango.sys.SharedLib.SharedLib.load(libname)) { |
25 foreach( inout s; symbols ){ | 27 foreach( ref s; symbols ){ |
26 if( s.major > major ) continue; | 28 if( s.major > major ) continue; |
27 if( s.major == major && s.minor > minor ) continue; | 29 if( s.major == major && s.minor > minor ) continue; |
28 *s.symbol = lib.getSymbol( tango.stdc.stringz.toStringz(s.name ) ); | 30 *s.symbol = lib.getSymbol( tango.stdc.stringz.toStringz(s.name ) ); |
29 if( s.symbol is null ){ | 31 if( s.symbol is null ){ |
30 getDwtLogger.error( __FILE__, __LINE__, "{}: Symbol '{}' not found", libname, s.name ); | 32 getDwtLogger.error( __FILE__, __LINE__, "{}: Symbol '{}' not found", libname, s.name ); |
32 } | 34 } |
33 } else { | 35 } else { |
34 getDwtLogger.error( __FILE__, __LINE__, "Could not load the library {}", libname ); | 36 getDwtLogger.error( __FILE__, __LINE__, "Could not load the library {}", libname ); |
35 } | 37 } |
36 } else { // Phobos | 38 } else { // Phobos |
37 implMissing( __FILE__, __LINE__ ); | 39 if (auto lib = ExeModule_Load(libname)) { |
40 foreach( ref s; symbols ){ | |
41 if( s.major > major ) continue; | |
42 if( s.major == major && s.minor > minor ) continue; | |
43 *s.symbol = ExeModule_GetSymbol( lib, s.name ); | |
44 if( s.symbol is null ){ | |
45 getDwtLogger.error( __FILE__, __LINE__, "{}: Symbol '{}' not found", libname, s.name ); | |
46 } | |
47 } | |
48 } else { | |
49 getDwtLogger.error( __FILE__, __LINE__, "Could not load the library {}", libname ); | |
50 } | |
38 } | 51 } |
39 } | 52 } |
40 static void loadLibSymbols( Symbol[] symbols, String libname ){ | 53 static void loadLibSymbols( Symbol[] symbols, String libname ){ |
41 version(Tango){ | 54 version(Tango){ |
42 if (auto lib = tango.sys.SharedLib.SharedLib.load(libname)) { | 55 if (auto lib = tango.sys.SharedLib.SharedLib.load(libname)) { |
43 foreach( inout s; symbols ){ | 56 foreach( ref s; symbols ){ |
44 *s.symbol = lib.getSymbol( tango.stdc.stringz.toStringz(s.name ) ); | 57 *s.symbol = lib.getSymbol( tango.stdc.stringz.toStringz(s.name ) ); |
45 if( s.symbol is null ){ | 58 if( s.symbol is null ){ |
46 getDwtLogger.error( __FILE__, __LINE__, "{}: Symbol '{}' not found", libname, s.name ); | 59 getDwtLogger.error( __FILE__, __LINE__, "{}: Symbol '{}' not found", libname, s.name ); |
47 } | 60 } |
48 } | 61 } |
49 } else { | 62 } else { |
50 getDwtLogger.error( __FILE__, __LINE__, "Could not load the library {}", libname ); | 63 getDwtLogger.error( __FILE__, __LINE__, "Could not load the library {}", libname ); |
51 } | 64 } |
52 } else { // Phobos | 65 } else { // Phobos |
53 implMissing( __FILE__, __LINE__ ); | 66 if (auto lib = ExeModule_Load(libname)) { |
67 foreach( ref s; symbols ){ | |
68 *s.symbol = ExeModule_GetSymbol( lib, s.name ); | |
69 if( s.symbol is null ){ | |
70 getDwtLogger.error( __FILE__, __LINE__, "{}: Symbol '{}' not found", libname, s.name ); | |
71 } | |
72 } | |
73 } else { | |
74 getDwtLogger.error( __FILE__, __LINE__, "Could not load the library {}", libname ); | |
75 } | |
54 } | 76 } |
55 } | 77 } |
56 static bool tryUseSymbol( String symbolname, String libname, void delegate( void*) dg ){ | 78 static bool tryUseSymbol( String symbolname, String libname, void delegate( void*) dg ){ |
57 bool result = false; | 79 bool result = false; |
58 version(Tango){ | 80 version(Tango){ |
63 result = true; | 85 result = true; |
64 } | 86 } |
65 lib.unload(); | 87 lib.unload(); |
66 } | 88 } |
67 } else { // Phobos | 89 } else { // Phobos |
68 implMissing( __FILE__, __LINE__ ); | 90 if (auto lib = ExeModule_Load( libname ) ) { |
91 void* ptr = ExeModule_GetSymbol( lib, symbolname ); | |
92 if (ptr !is null){ | |
93 dg(ptr); | |
94 result = true; | |
95 } | |
96 ExeModule_Release( lib ); | |
97 } | |
69 } | 98 } |
70 return result; | 99 return result; |
71 } | 100 } |
72 } | 101 } |
73 | 102 |