| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ | |||
| 5 | 5 | # make PYTHON=/path/to/python DEFINE=additional,defines CSCARGS=additional_args | |
| 6 | 6 | # make clean | |
| 7 | 7 | ||
| 8 | - RELEASE = pythonnet-2.0-alpha3 | ||
| 8 | + RELEASE = pythonnet-2.0-alpha2 | ||
| 9 | 9 | KEYFILE = pythonnet.key | |
| 10 | 10 | ||
| 11 | 11 | PYTHON ?= python | |
@@ -23,15 +23,17 @@ ifeq ($(origin WINDIR), undefined) | |||
| 23 | 23 | CSC = gmcs | |
| 24 | 24 | RUNTIME_REF = | |
| 25 | 25 | ALL = clr.so monoclr | |
| 26 | - GACUTIL = gacutil /nologo | ||
| 26 | + GACUTIL = gacutil | ||
| 27 | + SN = sn | ||
| 27 | 28 | else | |
| 28 | 29 | RUNNER = | |
| 29 | - ILDASM = ildasm.exe | ||
| 30 | - ILASM = $(WINDIR)/Microsoft.NET/Framework/v2.0.50727/ilasm.exe | ||
| 31 | - CSC = $(WINDIR)/Microsoft.NET/Framework/v2.0.50727/csc.exe | ||
| 30 | + ILDASM = $${PROGRAMFILES}/Microsoft.NET/SDK/v2.0/Bin/ildasm.exe | ||
| 31 | + ILASM = $${WINDIR}/Microsoft.NET/Framework/v2.0.50727/ilasm.exe | ||
| 32 | + CSC = $${WINDIR}/Microsoft.NET/Framework/v2.0.50727/csc.exe | ||
| 32 | 33 | RUNTIME_REF = | |
| 33 | 34 | ALL = | |
| 34 | - GACUTIL = $(ProgramFiles)/Microsoft.NET/SDK/v2.0/Bin/gacutil.exe /nologo | ||
| 35 | + GACUTIL = $${PROGRAMFILES}/Microsoft.NET/SDK/v2.0/Bin/gacutil.exe /nologo | ||
| 36 | + SN = $${PROGRAMFILES}/Microsoft.NET/SDK/v2.0/Bin/sn.exe /q | ||
| 35 | 37 | endif | |
| 36 | 38 | ||
| 37 | 39 | ifeq ($(origin DEFINE), undefined) | |
@@ -132,20 +134,24 @@ dist: realclean | |||
| 132 | 134 | for PY in python2.4 python2.5; do \ | |
| 133 | 135 | for PYUCS in UCS2 UCS4; do \ | |
| 134 | 136 | make clean; \ | |
| 135 | - make PYTHON=$$PY UCS=$$PYUCS CSCARGS=/keyfile:$(BASEDIR)/$(KEYFILE); \ | ||
| 137 | + make PYTHON=$$PY UCS=$$PYUCS CSCARGS="/keyfile:$(BASEDIR)/$(KEYFILE) /optimize"; \ | ||
| 136 | 138 | mkdir ./$(RELEASE)/$$PY-$$PYUCS; \ | |
| 137 | 139 | cp *.dll *.exe *.pyd *.so ./$(RELEASE)/$$PY-$$PYUCS/; \ | |
| 138 | 140 | done; \ | |
| 139 | 141 | done; | |
| 140 | 142 | tar czf $(RELEASE).tar.gz ./$(RELEASE)/ | |
| 141 | 143 | zip -r -6 $(RELEASE).zip ./$(RELEASE) | |
| 142 | - md5sum $(RELEASE).tar.gz $(RELEASE).zip > $(RELEASE).md5 | ||
| 143 | - sha256sum $(RELEASE).tar.gz $(RELEASE).zip > $(RELEASE).sha | ||
| 144 | - gpg -sb $(RELEASE).zip | ||
| 145 | - gpg -sb $(RELEASE).tar.gz | ||
| 146 | 144 | mv $(RELEASE).* ./release/ | |
| 147 | 145 | rm -rf ./$(RELEASE)/ | |
| 148 | 146 | ||
| 147 | + sign: | ||
| 148 | + md5sum ./release/$(RELEASE).tar.gz ./release/$(RELEASE).zip > \ | ||
| 149 | + ./release/$(RELEASE).md5 | ||
| 150 | + sha256sum ./release/$(RELEASE).tar.gz ./release/$(RELEASE).zip > \ | ||
| 151 | + ./release/$(RELEASE).sha | ||
| 152 | + gpg -sb ./release/$(RELEASE).zip | ||
| 153 | + gpg -sb ./release/$(RELEASE).tar.gz | ||
| 154 | + | ||
| 149 | 155 | dis: | |
| 150 | 156 | $(ILDASM) Python.Runtime.dll /out=Python.Runtime.il | |
| 151 | 157 | ||
@@ -163,3 +169,5 @@ run: python.exe | |||
| 163 | 169 | install: all | |
| 164 | 170 | $(PYTHON) setup.py install | |
| 165 | 171 | ||
| 172 | + mkkey: | ||
| 173 | + $(SN) /k $(KEYFILE) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,10 +10,6 @@ For PythonNet 2.0 | |||
| 10 | 10 | ||
| 11 | 11 | * Deprecate implicit loading of assemblies | |
| 12 | 12 | ||
| 13 | - * Add support for implicit calls to overloaded methods. | ||
| 14 | - OverloadedMethod[string, int]("egg", 42) works | ||
| 15 | - OverloadedMethod("egg", 42) does not under some circumstances work | ||
| 16 | - | ||
| 17 | 13 | * Debug failing unit tests under Mono and report them if they are caused | |
| 18 | 14 | by incompatibilities in Mono. | |
| 19 | 15 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,13 +1,15 @@ | |||
| 1 | - # copy this file to ~/.mono/config or add the dllmaps to the global | ||
| 2 | - # configuration file /etc/mono/config | ||
| 1 | + <!-- Mono Config for PythonNet | ||
| 2 | + | ||
| 3 | + Copy this file to ~/.mono/config or add the dllmaps to the global | ||
| 4 | + configuration file /etc/mono/config | ||
| 5 | + --> | ||
| 6 | + | ||
| 3 | 7 | <configuration> | |
| 4 | - <dllmap dll="python23" target="libpython2.3.so" os="!windows" /> | ||
| 5 | - <dllmap dll="python23.dll" target="libpython2.3.so" os="!windows" /> | ||
| 6 | - <dllmap dll="python24" target="libpython2.4.so" os="!windows" /> | ||
| 7 | - <dllmap dll="python24.dll" target="libpython2.4.so" os="!windows" /> | ||
| 8 | - <dllmap dll="python25" target="libpython2.5.so" os="!windows" /> | ||
| 9 | - <dllmap dll="python25.dll" target="libpython2.5.so" os="!windows" /> | ||
| 10 | - <dllmap dll="python26" target="libpython2.6.so" os="!windows" /> | ||
| 11 | - <dllmap dll="python26.dll" target="libpython2.6.so" os="!windows" /> | ||
| 8 | + <dllmap dll="python24" target="libpython2.4.so.1" os="!windows" /> | ||
| 9 | + <dllmap dll="python25" target="libpython2.5.so.1" os="!windows" /> | ||
| 10 | + <dllmap dll="python26" target="libpython2.6.so.1" os="!windows" /> | ||
| 11 | + <dllmap dll="python24.dll" target="libpython2.4.so.1" os="!windows" /> | ||
| 12 | + <dllmap dll="python25.dll" target="libpython2.5.so.1" os="!windows" /> | ||
| 13 | + <dllmap dll="python26.dll" target="libpython2.6.so.1" os="!windows" /> | ||
| 12 | 14 | </configuration> | |
| 13 | 15 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -162,15 +162,21 @@ internal static int ArgPrecedence(Type t) { | |||
| 162 | 162 | //==================================================================== | |
| 163 | 163 | ||
| 164 | 164 | internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw) { | |
| 165 | - return this.Bind(inst, args, kw, null); | ||
| 165 | + return this.Bind(inst, args, kw, null, null); | ||
| 166 | 166 | } | |
| 167 | 167 | ||
| 168 | 168 | internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, | |
| 169 | 169 | MethodBase info) { | |
| 170 | + return this.Bind(inst, args, kw, info, null); | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, | ||
| 174 | + MethodBase info, MethodInfo[] methodinfo) { | ||
| 170 | 175 | // loop to find match, return invoker w/ or /wo error | |
| 171 | 176 | MethodBase[] _methods = null; | |
| 172 | 177 | int pynargs = Runtime.PyTuple_Size(args); | |
| 173 | 178 | object arg; | |
| 179 | + bool isGeneric = false; | ||
| 174 | 180 | ||
| 175 | 181 | if (info != null) { | |
| 176 | 182 | _methods = (MethodBase[])Array.CreateInstance( | |
@@ -184,6 +190,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, | |||
| 184 | 190 | ||
| 185 | 191 | for (int i = 0; i < _methods.Length; i++) { | |
| 186 | 192 | MethodBase mi = _methods[i]; | |
| 193 | + if (mi.IsGenericMethod) { isGeneric = true; } | ||
| 187 | 194 | ParameterInfo[] pi = mi.GetParameters(); | |
| 188 | 195 | int clrnargs = pi.Length; | |
| 189 | 196 | bool match = false; | |
@@ -247,17 +254,32 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, | |||
| 247 | 254 | return new Binding(mi, target, margs, outs); | |
| 248 | 255 | } | |
| 249 | 256 | } | |
| 257 | + // We weren't able to find a matching method but at least one | ||
| 258 | + // is a generic method and info is null. That happens when a generic | ||
| 259 | + // method was not called using the [] syntax. Let's introspect the | ||
| 260 | + // type of the arguments and use it to construct the correct method. | ||
| 261 | + if (isGeneric && (info == null) && (methodinfo != null)) | ||
| 262 | + { | ||
| 263 | + Type[] types = Runtime.PythonArgsToTypeArray(args, true); | ||
| 264 | + MethodInfo mi = MethodBinder.MatchParameters(methodinfo, types); | ||
| 265 | + return Bind(inst, args, kw, mi, null); | ||
| 266 | + } | ||
| 250 | 267 | return null; | |
| 251 | 268 | } | |
| 252 | 269 | ||
| 253 | 270 | internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw) { | |
| 254 | - return this.Invoke(inst, args, kw, null); | ||
| 271 | + return this.Invoke(inst, args, kw, null, null); | ||
| 255 | 272 | ||
| 256 | 273 | } | |
| 257 | 274 | ||
| 258 | 275 | internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, | |
| 259 | 276 | MethodBase info) { | |
| 260 | - Binding binding = this.Bind(inst, args, kw, info); | ||
| 277 | + return this.Invoke(inst, args, kw, info, null); | ||
| 278 | + } | ||
| 279 | + | ||
| 280 | + internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, | ||
| 281 | + MethodBase info, MethodInfo[] methodinfo) { | ||
| 282 | + Binding binding = this.Bind(inst, args, kw, info, methodinfo); | ||
| 261 | 283 | Object result; | |
| 262 | 284 | IntPtr ts = IntPtr.Zero; | |
| 263 | 285 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,7 +60,7 @@ public virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw) { | |||
| 60 | 60 | ||
| 61 | 61 | public virtual IntPtr Invoke(IntPtr target, IntPtr args, IntPtr kw, | |
| 62 | 62 | MethodBase info) { | |
| 63 | - return binder.Invoke(target, args, kw, info); | ||
| 63 | + return binder.Invoke(target, args, kw, info, this.info); | ||
| 64 | 64 | } | |
| 65 | 65 | ||
| 66 | 66 | //==================================================================== | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,17 +26,33 @@ public class Runtime { | |||
| 26 | 26 | /// the responsibility of the caller to have acquired the GIL | |
| 27 | 27 | /// before calling any of these methods. | |
| 28 | 28 | /// </summary> | |
| 29 | + #if (UCS4) | ||
| 30 | + public const int UCS = 4; | ||
| 31 | + #endif | ||
| 32 | + #if (UCS2) | ||
| 33 | + public const int UCS = 2; | ||
| 34 | + #endif | ||
| 35 | + #if ! (UCS2 || UCS4) | ||
| 36 | + #error You must define either UCS2 or UCS4! | ||
| 37 | + #endif | ||
| 38 | + | ||
| 29 | 39 | #if (PYTHON24) | |
| 30 | - internal const string dll = "python24"; | ||
| 40 | + public const string dll = "python24"; | ||
| 41 | + public const string pyversion = "2.4"; | ||
| 42 | + public const int pyversionnumber = 24; | ||
| 31 | 43 | #endif | |
| 32 | 44 | #if (PYTHON25) | |
| 33 | - internal const string dll = "python25"; | ||
| 45 | + public const string dll = "python25"; | ||
| 46 | + public const string pyversion = "2.5"; | ||
| 47 | + public const int pyversionnumber = 25; | ||
| 34 | 48 | #endif | |
| 35 | 49 | #if (PYTHON26) | |
| 36 | - internal const string dll = "python26"; | ||
| 50 | + public const string dll = "python26"; | ||
| 51 | + public const string pyversion = "2.6"; | ||
| 52 | + public const int pyversionnumber = 26; | ||
| 37 | 53 | #endif | |
| 38 | 54 | #if ! (PYTHON24 || PYTHON25 || PYTHON26) | |
| 39 | - #error You must define either PYTHON24 or PYTHON25! | ||
| 55 | + #error You must define either PYTHON24, PYTHON25 or PYTHON26! | ||
| 40 | 56 | #endif | |
| 41 | 57 | internal static bool wrap_exceptions; | |
| 42 | 58 | internal static bool is32bit; | |
@@ -117,7 +133,7 @@ internal static void Initialize() { | |||
| 117 | 133 | // of the Python runtime that do not allow new-style classes to | |
| 118 | 134 | // be used as exceptions (Python versions 2.4 and lower). | |
| 119 | 135 | ||
| 120 | - #if (PYTHON25) | ||
| 136 | + #if (PYTHON25 || PYTHON26) | ||
| 121 | 137 | wrap_exceptions = false; | |
| 122 | 138 | #else | |
| 123 | 139 | IntPtr m = PyImport_ImportModule("exceptions"); | |
@@ -131,7 +147,6 @@ internal static void Initialize() { | |||
| 131 | 147 | Runtime.Decref(m); | |
| 132 | 148 | #endif | |
| 133 | 149 | ||
| 134 | - | ||
| 135 | 150 | // Initialize modules that depend on the runtime class. | |
| 136 | 151 | AssemblyManager.Initialize(); | |
| 137 | 152 | PyCLRMetaType = MetaType.Initialize(); | |
@@ -227,6 +242,10 @@ internal static IntPtr ExtendTuple(IntPtr t, params IntPtr[] args) { | |||
| 227 | 242 | } | |
| 228 | 243 | ||
| 229 | 244 | internal static Type[] PythonArgsToTypeArray(IntPtr arg) { | |
| 245 | + return PythonArgsToTypeArray(arg, false); | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + internal static Type[] PythonArgsToTypeArray(IntPtr arg, bool mangleObjects) { | ||
| 230 | 249 | // Given a PyObject * that is either a single type object or a | |
| 231 | 250 | // tuple of (managed or unmanaged) type objects, return a Type[] | |
| 232 | 251 | // containing the CLR Type objects that map to those types. | |
@@ -246,6 +265,9 @@ internal static Type[] PythonArgsToTypeArray(IntPtr arg) { | |||
| 246 | 265 | ||
| 247 | 266 | for (int i = 0; i < n; i++) { | |
| 248 | 267 | IntPtr op = Runtime.PyTuple_GetItem(args, i); | |
| 268 | + if (mangleObjects && (!Runtime.PyType_Check(op))) { | ||
| 269 | + op = Runtime.PyObject_TYPE(op); | ||
| 270 | + } | ||
| 249 | 271 | ManagedType mt = ManagedType.GetManagedObject(op); | |
| 250 | 272 | ||
| 251 | 273 | if (mt is ClassBase) { | |
@@ -575,15 +597,20 @@ internal unsafe static extern IntPtr | |||
| 575 | 597 | ||
| 576 | 598 | internal unsafe static IntPtr | |
| 577 | 599 | PyObject_TYPE(IntPtr op) { | |
| 578 | - void *p = (void *)op; | ||
| 579 | - if ((void *)0 == p) { | ||
| 580 | - return IntPtr.Zero; | ||
| 600 | + void* p = (void*)op; | ||
| 601 | + if ((void*)0 == p) { | ||
| 602 | + return IntPtr.Zero; | ||
| 581 | 603 | } | |
| 604 | + #if (Py_DEBUG) | ||
| 605 | + int n = 3; | ||
| 606 | + #else | ||
| 607 | + int n = 1; | ||
| 608 | + #endif | ||
| 582 | 609 | if (is32bit) { | |
| 583 | - return new IntPtr((void *)(*((uint *)p + 1))); | ||
| 610 | + return new IntPtr((void*)(*((uint*)p + n))); | ||
| 584 | 611 | } | |
| 585 | 612 | else { | |
| 586 | - return new IntPtr((void *)(*((ulong *)p + 1))); | ||
| 613 | + return new IntPtr((void*)(*((ulong*)p + n))); | ||
| 587 | 614 | } | |
| 588 | 615 | } | |
| 589 | 616 | ||
@@ -1385,6 +1412,10 @@ internal unsafe static extern int | |||
| 1385 | 1412 | // Python type object API | |
| 1386 | 1413 | //==================================================================== | |
| 1387 | 1414 | ||
| 1415 | + internal static bool PyType_Check(IntPtr ob) { | ||
| 1416 | + return PyObject_TypeCheck(ob, Runtime.PyTypeType); | ||
| 1417 | + } | ||
| 1418 | + | ||
| 1388 | 1419 | [DllImport(Runtime.dll, CallingConvention=CallingConvention.Cdecl, | |
| 1389 | 1420 | ExactSpelling=true, CharSet=CharSet.Ansi)] | |
| 1390 | 1421 | internal unsafe static extern bool | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -299,7 +299,7 @@ def testGenericMethodTypeHandling(self): | |||
| 299 | 299 | """ | |
| 300 | 300 | from Python.Test import InterfaceTest, ISayHello1, ShortEnum | |
| 301 | 301 | import System | |
| 302 | - | ||
| 302 | + | ||
| 303 | 303 | self._testGenericMethodByType(System.Boolean, True) | |
| 304 | 304 | self._testGenericMethodByType(bool, True) | |
| 305 | 305 | self._testGenericMethodByType(System.Byte, 255) | |
@@ -312,7 +312,7 @@ def testGenericMethodTypeHandling(self): | |||
| 312 | 312 | self._testGenericMethodByType(long, 9223372036854775807L) | |
| 313 | 313 | self._testGenericMethodByType(System.UInt16, 65000) | |
| 314 | 314 | self._testGenericMethodByType(System.UInt32, 4294967295L) | |
| 315 | - self._testGenericMethodByType(System.UInt64, 18446744073709551615L) | ||
| 315 | + self._testGenericMethodByType(System.UInt64, 1844674407370955161L) | ||
| 316 | 316 | self._testGenericMethodByType(System.Single, 3.402823e38) | |
| 317 | 317 | self._testGenericMethodByType(System.Double, 1.7976931348623157e308) | |
| 318 | 318 | self._testGenericMethodByType(float, 1.7976931348623157e308) | |
@@ -324,6 +324,10 @@ def testGenericMethodTypeHandling(self): | |||
| 324 | 324 | self._testGenericMethodByType(System.Object, InterfaceTest()) | |
| 325 | 325 | self._testGenericMethodByType(InterfaceTest, InterfaceTest(), 1) | |
| 326 | 326 | self._testGenericMethodByType(ISayHello1, InterfaceTest(), 1) | |
| 327 | + # XXX BUG: The value doesn't fit into Int64 and PythonNet doesn't | ||
| 328 | + # recognize it as UInt64 for unknown reasons. | ||
| 329 | + self._testGenericMethodByType(System.UInt64, 18446744073709551615L) | ||
| 330 | + | ||
| 327 | 331 | ||
| 328 | 332 | def testGenericMethodOverloadSelection(self): | |
| 329 | 333 | """ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments