@@ -25,15 +25,50 @@ namespace Python.Runtime {
25
25
26
26
static class NativeMethods
27
27
{
28
+ #if MONO_LINUX
29
+ static public IntPtr LoadLibrary ( string fileName ) {
30
+ return dlopen ( fileName , RTLD_NOW | RTLD_SHARED ) ;
31
+ }
32
+
33
+ static public void FreeLibrary ( IntPtr handle ) {
34
+ dlclose ( handle ) ;
35
+ }
36
+
37
+ static public IntPtr GetProcAddress ( IntPtr dllHandle , string name ) {
38
+ // clear previous errors if any
39
+ dlerror ( ) ;
40
+ var res = dlsym ( dllHandle , name ) ;
41
+ var errPtr = dlerror ( ) ;
42
+ if ( errPtr != IntPtr . Zero ) {
43
+ throw new Exception ( "dlsym: " + Marshal . PtrToStringAnsi ( errPtr ) ) ;
44
+ }
45
+ return res ;
46
+ }
47
+
48
+ const int RTLD_NOW = 2 ;
49
+ const int RTLD_SHARED = 20 ;
50
+
51
+ [ DllImport ( "libdl.so" ) ]
52
+ private static extern IntPtr dlopen ( String fileName , int flags ) ;
53
+
54
+ [ DllImport ( "libdl.so" ) ]
55
+ private static extern IntPtr dlsym ( IntPtr handle , String symbol ) ;
56
+
57
+ [ DllImport ( "libdl.so" ) ]
58
+ private static extern int dlclose ( IntPtr handle ) ;
59
+
60
+ [ DllImport ( "libdl.so" ) ]
61
+ private static extern IntPtr dlerror ( ) ;
62
+ #else
28
63
[ DllImport ( "kernel32.dll" ) ]
29
64
public static extern IntPtr LoadLibrary ( string dllToLoad ) ;
30
65
31
66
[ DllImport ( "kernel32.dll" ) ]
32
67
public static extern IntPtr GetProcAddress ( IntPtr hModule , string procedureName ) ;
33
68
34
-
35
69
[ DllImport ( "kernel32.dll" ) ]
36
70
public static extern bool FreeLibrary ( IntPtr hModule ) ;
71
+ #endif
37
72
}
38
73
39
74
public class Runtime {
@@ -54,49 +89,96 @@ public class Runtime {
54
89
#endif
55
90
56
91
#if ( PYTHON23 )
57
- public const string dll = "python23" ;
58
92
public const string pyversion = "2.3" ;
59
93
public const int pyversionnumber = 23 ;
60
94
#endif
61
95
#if ( PYTHON24 )
62
- public const string dll = "python24" ;
63
96
public const string pyversion = "2.4" ;
64
97
public const int pyversionnumber = 24 ;
65
98
#endif
66
99
#if ( PYTHON25 )
67
- public const string dll = "python25" ;
68
100
public const string pyversion = "2.5" ;
69
101
public const int pyversionnumber = 25 ;
70
102
#endif
71
103
#if ( PYTHON26 )
72
- public const string dll = "python26" ;
73
104
public const string pyversion = "2.6" ;
74
105
public const int pyversionnumber = 26 ;
75
106
#endif
76
107
#if ( PYTHON27 )
77
- public const string dll = "python27" ;
78
108
public const string pyversion = "2.7" ;
79
109
public const int pyversionnumber = 27 ;
80
110
#endif
81
111
#if ( PYTHON32 )
82
- public const string dll = "python32" ;
83
112
public const string pyversion = "3.2" ;
84
113
public const int pyversionnumber = 32 ;
85
114
#endif
86
115
#if ( PYTHON33 )
87
- public const string dll = "python33" ;
88
116
public const string pyversion = "3.3" ;
89
117
public const int pyversionnumber = 33 ;
90
118
#endif
91
119
#if ( PYTHON34 )
92
- public const string dll = "python34" ;
93
120
public const string pyversion = "3.4" ;
94
121
public const int pyversionnumber = 34 ;
95
122
#endif
96
123
#if ! ( PYTHON23 || PYTHON24 || PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 )
97
124
#error You must define one of PYTHON23 to PYTHON34
98
125
#endif
99
126
127
+ #if ( PYTHON23 )
128
+ internal const string dllBase = "python23" ;
129
+ #endif
130
+ #if ( PYTHON24 )
131
+ internal const string dllBase = "python24" ;
132
+ #endif
133
+ #if ( PYTHON25 )
134
+ internal const string dllBase = "python25" ;
135
+ #endif
136
+ #if ( PYTHON26 )
137
+ internal const string dllBase = "python26" ;
138
+ #endif
139
+ #if ( PYTHON27 )
140
+ internal const string dllBase = "python27" ;
141
+ #endif
142
+ #if ( MONO_LINUX )
143
+ #if ( PYTHON32 )
144
+ internal const string dllBase = "python3.2" ;
145
+ #endif
146
+ #if ( PYTHON33 )
147
+ internal const string dllBase = "python3.3" ;
148
+ #endif
149
+ #if ( PYTHON34 )
150
+ internal const string dllBase = "python3.4" ;
151
+ #endif
152
+ #else
153
+ #if ( PYTHON32 )
154
+ internal const string dllBase = "python32" ;
155
+ #endif
156
+ #if ( PYTHON33 )
157
+ internal const string dllBase = "python33" ;
158
+ #endif
159
+ #if ( PYTHON34 )
160
+ internal const string dllBase = "python34" ;
161
+ #endif
162
+ #endif
163
+
164
+ #if ( PYTHON_WITH_PYDEBUG )
165
+ internal const string dllWithPyDebug = "d" ;
166
+ #else
167
+ internal const string dllWithPyDebug = "" ;
168
+ #endif
169
+ #if ( PYTHON_WITH_PYMALLOC )
170
+ internal const string dllWithPyMalloc = "m" ;
171
+ #else
172
+ internal const string dllWithPyMalloc = "" ;
173
+ #endif
174
+ #if ( PYTHON_WITH_WIDE_UNICODE )
175
+ internal const string dllWithWideUnicode = "u" ;
176
+ #else
177
+ internal const string dllWithWideUnicode = "" ;
178
+ #endif
179
+
180
+ public const string dll = dllBase + dllWithPyDebug + dllWithPyMalloc + dllWithWideUnicode ;
181
+
100
182
// set to true when python is finalizing
101
183
internal static Object IsFinalizingLock = new Object ( ) ;
102
184
internal static bool IsFinalizing = false ;
@@ -108,7 +190,7 @@ public class Runtime {
108
190
/// Intitialize the runtime...
109
191
/// </summary>
110
192
internal static void Initialize ( ) {
111
-
193
+
112
194
is32bit = IntPtr . Size == 4 ;
113
195
114
196
if ( 0 == Runtime . Py_IsInitialized ( ) )
@@ -211,8 +293,10 @@ internal static void Initialize() {
211
293
#if ( PYTHON32 || PYTHON33 || PYTHON34 )
212
294
IntPtr dll = NativeMethods . LoadLibrary ( Runtime . dll ) ;
213
295
_PyObject_NextNotImplemented = NativeMethods . GetProcAddress ( dll , "_PyObject_NextNotImplemented" ) ;
296
+ #if ! MONO_LINUX
214
297
NativeMethods . FreeLibrary ( dll ) ;
215
298
#endif
299
+ #endif
216
300
217
301
218
302
// Determine whether we need to wrap exceptions for versions of
0 commit comments