8000 Merge pull request #163 from tonyroberts/develop · pythonnet/pythonnet@6d91403 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6d91403

Browse files
committed
Merge pull request #163 from tonyroberts/develop
Add support for Python 3.5
2 parents c2ca646 + 3df3324 commit 6d91403

14 files changed

+229
-64
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ python:
44
- 2.7
55
- 3.2
66
- 3.4
7+
- 3.5
78
before_install:
89
- sudo apt-get install software-properties-common
910
- sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu/ trusty main universe"

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ environment:
1313
- PYTHON: "C:\\Python33-x64"
1414
- PYTHON: "C:\\Python34"
1515
- PYTHON: "C:\\Python34-x64"
16+
- PYTHON: "C:\\Python35"
17+
- PYTHON: "C:\\Python35-x64"
1618

1719
install:
1820
- "%PYTHON%\\python.exe -m pip install --upgrade pip"

src/clrmodule/ClrModule.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class clrModule
3939
// ReSharper restore CheckNamespace
4040
{
4141
// ReSharper disable InconsistentNaming
42-
#if (PYTHON32 || PYTHON33 || PYTHON34)
42+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
4343
[RGiesecke.DllExport.DllExport("PyInit_clr", System.Runtime.InteropServices.CallingConvention.StdCall)]
4444
public static IntPtr PyInit_clr()
4545
#else
@@ -107,7 +107,7 @@ public static void initclr()
107107
#if DEBUG_PRINT
108108
System.Console.WriteLine("Could not load Python.Runtime, so sad.");
109109
#endif
110-
#if (PYTHON32 || PYTHON33 || PYTHON34)
110+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
111111
return IntPtr.Zero;
112112
#else
113113
return;
@@ -119,7 +119,7 @@ public static void initclr()
119119
// So now we get the PythonEngine and execute the InitExt method on it.
120120
var pythonEngineType = pythonRuntime.GetType("Python.Runtime.PythonEngine");
121121

122-
#if (PYTHON32 || PYTHON33 || PYTHON34)
122+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
123123
return (IntPtr)pythonEngineType.InvokeMember("InitExt", System.Reflection.BindingFlags.InvokeMethod, null, null, null);
124124
#else
125125
pythonEngineType.InvokeMember("Ini F438 tExt", System.Reflection.BindingFlags.InvokeMethod, null, null, null);

src/runtime/classbase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public virtual IntPtr type_subscript(IntPtr idx) {
5757
//====================================================================
5858
// Standard comparison implementation for instances of reflected types.
5959
//====================================================================
60-
#if (PYTHON32 || PYTHON33 || PYTHON34)
60+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
6161
public static IntPtr tp_richcompare(IntPtr ob, IntPtr other, int op) {
6262
if (op != Runtime.Py_EQ && op != Runtime.Py_NE)
6363
{

src/runtime/converter.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
405405
return true;
406406

407407
case TypeCode.Int32:
408-
#if !(PYTHON32 || PYTHON33 || PYTHON34)
408+
#if !(PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
409409
// Trickery to support 64-bit platforms.
410410
if (IntPtr.Size == 4) {
411411
op = Runtime.PyNumber_Int(value);
@@ -434,6 +434,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
434434
#endif
435435
op = Runtime.PyNumber_Long(value);
436436
if (op == IntPtr.Zero) {
437+
Exceptions.Clear();
437438
if (Exceptions.ExceptionMatches(overflow)) {
438439
goto overflow;
439440
}
@@ -456,7 +457,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
456457
return true;
457458

458459
case TypeCode.Byte:
459-
#if (PYTHON32 || PYTHON33 || PYTHON34)
460+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
460461
if (Runtime.PyObject_TypeCheck(value, Runtime.PyBytesType))
461462
{
462463
if (Runtime.PyBytes_Size(value) == 1)
@@ -496,7 +497,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
496497
return true;
497498

498499
case TypeCode.SByte:
499-
#if (PYTHON32 || PYTHON33 || PYTHON34)
500+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
500501
if (Runtime.PyObject_TypeCheck(value, Runtime.PyBytesType)) {
501502
if (Runtime.PyBytes_Size(value) == 1) {
502503
op = Runtime.PyBytes_AS_STRING(value);
@@ -534,7 +535,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
534535
return true;
535536

536537
case TypeCode.Char:
537-
#if (PYTHON32 || PYTHON33 || PYTHON34)
538+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
538539
if (Runtime.PyObject_TypeCheck(value, Runtime.PyBytesType)) {
539540
if (Runtime.PyBytes_Size(value) == 1) {
540541
op = Runtime.PyBytes_AS_STRING(value);

src/runtime/delegateobject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) {
103103
//====================================================================
104104
// Implements __cmp__ for reflected delegate types.
105105
//====================================================================
106-
#if (PYTHON32 || PYTHON33 || PYTHON34)
106+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
107107
public static new IntPtr tp_richcompare(IntPtr ob, IntPtr other, int op) {
108108
if (op != Runtime.Py_EQ && op != Runtime.Py_NE)
109109
{

src/runtime/exceptions.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal class ExceptionClassObject : ClassObject {
3131
internal ExceptionClassObject(Type tp) : base(tp) {
3232
}
3333

34-
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
34+
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
3535
internal static Exception ToException(IntPtr ob) {
3636
CLRObject co = GetManagedObject(ob) as CLRObject;
3737
if (co == null) {
@@ -114,7 +114,7 @@ public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
114114

115115
return Runtime.PyObject_GenericGetAttr(ob, key);
116116
}
117-
#endif // (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
117+
#endif // (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
118118
}
119119

120120
/// <summary>
@@ -136,7 +136,7 @@ private Exceptions() {}
136136
//===================================================================
137137

138138
internal static void Initialize() {
139-
#if (PYTHON32 || PYTHON33 || PYTHON34)
139+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
140140
exceptions_module = Runtime.PyImport_ImportModule("builtins");
141141
#else
142142
exceptions_module = Runtime.PyImport_ImportModule("exceptions");
@@ -572,15 +572,15 @@ internal static IntPtr RaiseTypeError(string message) {
572572
puplic static variables on the Exceptions class filled in from
573573
the python class using reflection in Initialize() looked up by
574574
name, not posistion. */
575-
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
575+
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
576576
public static IntPtr BaseException;
577577
#endif
578578
public static IntPtr Exception;
579579
public static IntPtr StopIteration;
580-
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
580+
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
581581
public static IntPtr GeneratorExit;
582582
#endif
583-
#if !(PYTHON32 || PYTHON33 || PYTHON34)
583+
#if !(PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
584584
public static IntPtr StandardError;
585585
#endif
586586
public static IntPtr ArithmeticError;
@@ -637,7 +637,7 @@ puplic static variables on the Exceptions class filled in from
637637
public static IntPtr SyntaxWarning;
638638
public static IntPtr RuntimeWarning;
639639
public static IntPtr FutureWarning;
640-
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
640+
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
641641
public static IntPtr ImportWarning;
642642
public static IntPtr UnicodeWarning;
643643
//PyAPI_DATA(PyObject *) PyExc_BytesWarning;

src/runtime/importhook.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal class ImportHook {
2323
static CLRModule root;
2424
static MethodWrapper hook;
2525

26-
#if (PYTHON32 || PYTHON33 || PYTHON34)
26+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
2727
static IntPtr py_clr_module;
2828
static IntPtr module_def;
2929
#endif
@@ -38,7 +38,7 @@ internal static void Initialize() {
3838
// but it provides the most "Pythonic" way of dealing with CLR
3939
// modules (Python doesn't provide a way to emulate packages).
4040
IntPtr dict = Runtime.PyImport_GetModuleDict();
41-
#if (PYTHON32 || PYTHON33 || PYTHON34)
41+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
4242
IntPtr mod = Runtime.PyImport_ImportModule("builtins");
4343
py_import = Runtime.PyObject_GetAttrString(mod, "__import__");
4444
#else
@@ -51,7 +51,7 @@ internal static void Initialize() {
5151

5252
root = new CLRModule();
5353

54-
#if (PYTHON32 || PYTHON33 || PYTHON34)
54+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
5555
// create a python module with the same methods as the clr module-like object
5656
module_def = ModuleDefOffset.AllocModuleDef("clr");
5757
py_clr_module = Runtime.PyModule_Create2(module_def, 3);
@@ -78,7 +78,7 @@ internal static void Initialize() {
7878
//===================================================================
7979

8080
internal static void Shutdown() {
81-
#if (PYTHON32 || PYTHON33 || PYTHON34)
81+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
8282
if (0 != Runtime.Py_IsInitialized()) {
8383
Runtime.Decref(py_clr_module);
8484
Runtime.Decref(root.pyHandle);
@@ -100,7 +100,7 @@ internal static void Shutdown() {
100100
//===================================================================
101101
public static IntPtr GetCLRModule(IntPtr? fromList=null) {
102102
root.InitializePreload();
103-
#if (PYTHON32 || PYTHON33 || PYTHON34)
103+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
104104
// update the module dictionary with the contents of the root dictionary
105105
root.LoadNames();
106106
IntPtr py_mod_dict = Runtime.PyModule_GetDict(py_clr_module);

src/runtime/interop.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static ObjectOffset() {
7979
}
8080

8181
public static int magic(IntPtr ob) {
82-
#if (PYTHON32 || PYTHON33 || PYTHON34)
82+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
8383
if ((Runtime.PyObject_TypeCheck(ob, Exceptions.BaseException) ||
8484
(Runtime.PyType_Check(ob) && Runtime.PyType_IsSubtype(ob, Exceptions.BaseException))))
8585
{
@@ -91,7 +91,7 @@ public static int magic(IntPtr ob) {
9191

9292
public static int DictOffset(IntPtr ob)
9393
{
94-
#if (PYTHON32 || PYTHON33 || PYTHON34)
94+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
9595
if ((Runtime.PyObject_TypeCheck(ob, Exceptions.BaseException) ||
9696
(Runtime.PyType_Check(ob) && Runtime.PyType_IsSubtype(ob, Exceptions.BaseException))))
9797
{
@@ -102,7 +102,7 @@ public static int DictOffset(IntPtr ob)
102102
}
103103

104104
public static int Size(IntPtr ob) {
105-
#if (PYTHON32 || PYTHON33 || PYTHON34)
105+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
106106
if ((Runtime.PyObject_TypeCheck(ob, Exceptions.BaseException) ||
107107
(Runtime.PyType_Check(ob) && Runtime.PyType_IsSubtype(ob, Exceptions.BaseException))))
108108
{
@@ -126,7 +126,7 @@ public static int Size(IntPtr ob) {
126126
private static int ob_data;
127127
}
128128

129-
#if (PYTHON32 || PYTHON33 || PYTHON34)
129+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
130130
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
131131
internal class ExceptionOffset
132132
{
@@ -161,7 +161,7 @@ public static int Size()
161161
#endif
162162

163163

164-
#if (PYTHON32 || PYTHON33 || PYTHON34)
164+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
165165
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
166166
internal class BytesOffset
167167
{
@@ -281,10 +281,10 @@ internal class TypeFlags {
281281
/* XXX Reusing reserved constants */
282282
public static int Managed = (1 << 15); // PythonNet specific
283283
public static int Subclass = (1 << 16); // PythonNet specific
284-
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
284+
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
285285
public static int HaveIndex = (1 << 17);
286286
#endif
287-
#if (PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
287+
#if (PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
288288
/* Objects support nb_index in PyNumberMethods */
289289
public static int HaveVersionTag = (1 << 18);
290290
public static int ValidVersionTag = (1 << 19);
@@ -320,7 +320,7 @@ internal class TypeFlags {
320320
#endif
321321

322322
// Default flags for Python 3
323-
#if (PYTHON32 || PYTHON33 || PYTHON34)
323+
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
324324
public static int Default = (
325325
HaveStacklessExtension |
326326
HaveVersionTag);
@@ -383,7 +383,7 @@ static Interop() {
383383
pmap["nb_add"] = p["BinaryFunc"];
384384
pmap["nb_subtract"] = p["BinaryFunc"];
385385
pmap["nb_multiply"] = p["BinaryFunc"];
386-
#if !(PYTHON32 || PYTHON33 || PYTHON34)
386+
#if !(PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
387387
pmap["nb_divide"] = p["BinaryFunc"];
388388
#endif
389389
pmap["nb_remainder"] = p["BinaryFunc"];
@@ -408,7 +408,7 @@ static Interop() {
408408
pmap["nb_inplace_add"] = p["BinaryFunc"];
409409
pmap["nb_inplace_subtract"] = p["BinaryFunc"];
410410
pmap["nb_inplace_multiply"] = p["BinaryFunc"];
411-
#if !(PYTHON32 || PYTHON33 || PYTHON34)
411+
#if !(PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
412412
pmap["nb_inplace_divide"] = p["BinaryFunc"];
413413
#endif
414414
pmap["nb_inplace_remainder"] = p["BinaryFunc"];
@@ -422,7 +422,7 @@ static Interop() {
422422
pmap["nb_true_divide"] = p["BinaryFunc"];
423423
pmap["nb_inplace_floor_divide"] = p["BinaryFunc"];
424424
pmap["nb_inplace_true_divide"] = p["BinaryFunc"];
425-
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
425+
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
426426
pmap["nb_index"] = p["UnaryFunc"];
427427
#endif
428428

0 commit comments

Comments
 (0)
0