| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6eb59ec commit 5062377
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -115,6 +115,17 @@ def build_extension(self, ext): | |||
| 115 | 115 | if CONFIG == "Debug": | |
| 116 | 116 | defines.extend(["DEBUG", "TRACE"]) | |
| 117 | 117 | ||
| 118 | + if sys.platform != "win32" and DEVTOOLS == "Mono": | ||
| 119 | + defines.append("MONO_LINUX") | ||
| 120 | + | ||
| 121 | + if hasattr(sys, "abiflags"): | ||
| 122 | + if "d" in sys.abiflags: | ||
| 123 | + defines.append("PYTHON_WITH_PYDEBUG") | ||
| 124 | + if "m" in sys.abiflags: | ||
| 125 | + defines.append("PYTHON_WITH_PYMALLOC") | ||
| 126 | + if "u" in sys.abiflags: | ||
| 127 | + defines.append("PYTHON_WITH_WIDE_UNICODE") | ||
| 128 | + | ||
| 118 | 129 | cmd = [ | |
| 119 | 130 | _xbuild, | |
| 120 | 131 | "pythonnet.sln", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,21 +25,50 @@ PyDoc_STRVAR(clr_module_doc, | |||
| 25 | 25 | static PyNet_Args *pn_args; | |
| 26 | 26 | char** environ = NULL; | |
| 27 | 27 | ||
| 28 | + #if PY_MAJOR_VERSION >= 3 | ||
| 29 | + static struct PyModuleDef clrdef = { | ||
| 30 | + PyModuleDef_HEAD_INIT, | ||
| 31 | + "clr", /* m_name */ | ||
| 32 | + clr_module_doc, /* m_doc */ | ||
| 33 | + -1, /* m_size */ | ||
| 34 | + clr_methods, /* m_methods */ | ||
| 35 | + NULL, /* m_reload */ | ||
| 36 | + NULL, /* m_traverse */ | ||
| 37 | + NULL, /* m_clear */ | ||
| 38 | + NULL, /* m_free */ | ||
| 39 | + }; | ||
| 40 | + #endif | ||
| 41 | + | ||
| 42 | + static PyObject *_initclr() { | ||
| 43 | + PyObject *m; | ||
| 44 | + | ||
| 45 | + /* Create the module and add the functions */ | ||
| 46 | + #if PY_MAJOR_VERSION >= 3 | ||
| 47 | + m = PyModule_Create(&clrdef); | ||
| 48 | + #else | ||
| 49 | + m = Py_InitModule3("clr", clr_methods, clr_module_doc); | ||
| 50 | + #endif | ||
| 51 | + if (m == NULL) | ||
| 52 | + return; | ||
| 53 | + PyModule_AddObject(m, "facade", Py_True); | ||
| 54 | + Py_INCREF(Py_True); | ||
| 55 | + | ||
| 56 | + pn_args = PyNet_Init(1); | ||
| 57 | + if (pn_args->error) { | ||
| 58 | + return NULL; | ||
| 59 | + } | ||
| 60 | + return m; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + #if PY_MAJOR_VERSION >= 3 | ||
| 64 | + PyMODINIT_FUNC | ||
| 65 | + PyInit_clr(void) { | ||
| 66 | + return _initclr(); | ||
| 67 | + } | ||
| 68 | + #else | ||
| 28 | 69 | PyMODINIT_FUNC | |
| 29 | 70 | initclr(void) | |
| 30 | - { | ||
| 31 | - PyObject *m; | ||
| 32 | - | ||
| 33 | - /* Create the module and add the functions */ | ||
| 34 | - m = Py_InitModule3("clr", clr_methods, clr_module_doc); | ||
| 35 | - if (m == NULL) | ||
| 36 | - return; | ||
| 37 | - PyModule_AddObject(m, "facade", Py_True); | ||
| 38 | - Py_INCREF(Py_True); | ||
| 39 | - | ||
| 40 | - pn_args = PyNet_Init(1); | ||
| 41 | - if (pn_args->error) { | ||
| 42 | - return; | ||
| 43 | - } | ||
| 71 | + _initclr(); | ||
| 44 | 72 | } | |
| 73 | + #endif | ||
| 45 | 74 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,29 @@ | |||
| 16 | 16 | ||
| 17 | 17 | #include <Python.h> | |
| 18 | 18 | ||
| 19 | + #if (PY_MAJOR_VERSION > 2) | ||
| 20 | + #include <wchar.h> | ||
| 21 | + #endif | ||
| 22 | + | ||
| 19 | 23 | int main(int argc, char **argv) { | |
| 24 | + #if (PY_MAJOR_VERSION > 2) | ||
| 25 | + int i, result; | ||
| 26 | + size_t len; | ||
| 27 | + wchar_t **wargv = (wchar_t**)malloc(sizeof(wchar_t*)*argc); | ||
| 28 | + for (i=0; i<argc; ++ i) { | ||
| 29 | + len = strlen(argv[i]); | ||
| 30 | + wargv[i] = (wchar_t*)malloc(sizeof(wchar_t)*(len+1)); | ||
| 31 | + if (len == mbsrtowcs(wargv[i], (const char**)&argv[i], len, NULL)) | ||
| 32 | + wargv[i][len] = 0; | ||
| 33 | + } | ||
| 34 | + result = Py_Main(argc, wargv); | ||
| 35 | + for (i=0; i<argc; ++i) { | ||
| 36 | + free((void*)wargv[i]); | ||
| 37 | + } | ||
| 38 | + free((void*)wargv); | ||
| 39 | + return result; | ||
| 40 | + #else | ||
| 20 | 41 | return Py_Main(argc, argv); | |
| 42 | + #endif | ||
| 21 | 43 | } | |
| 22 | 44 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments