Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 14591b6

Browse files
committed
Python 3.4 compatibility (fixes #8)
1 parent ecf3237 commit 14591b6

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

pythonnet/src/runtime/interop.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ public static int magic() {
261261
#if (PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
262262
/* Type attribute cache version tag. Added in version 2.6 */
263263
public static int tp_version_tag;
264+
#endif
265+
#if (PYTHON34)
266+
public static int tp_finalize = 0;
264267
#endif
265268
// COUNT_ALLOCS adds some more stuff to PyTypeObject
266269
#if (Py_COUNT_ALLOCS)
@@ -470,6 +473,8 @@ public static void FreeModuleDef(IntPtr ptr) {
470473
/// to good use as PythonNet specific flags (Managed and Subclass)
471474
/// </summary>
472475
internal class TypeFlags {
476+
#if (PYTHON23 || PYTHON24 || PYTHON25 || PYTHON26 || PYTHON27)
477+
// these flags were removed in Python 3
473478
public static int HaveGetCharBuffer = (1 << 0);
474479
public static int HaveSequenceIn = (1 << 1);
475480
public static int GC = 0;
@@ -479,6 +484,7 @@ internal class TypeFlags {
479484
public static int HaveWeakRefs = (1 << 6);
480485
public static int HaveIter = (1 << 7);
481486
public static int HaveClass = (1 << 8);
487+
#endif
482488
public static int HeapType = (1 << 9);
483489
public static int BaseType = (1 << 10);
484490
public static int Ready = (1 << 12);
@@ -509,18 +515,31 @@ internal class TypeFlags {
509515
public static int BaseExceptionSubclass = (1 << 30);
510516
public static int TypeSubclass = (1 << 31);
511517
#endif
512-
public static int Default = (HaveGetCharBuffer |
518+
519+
// Default flags for Python 2
520+
#if (PYTHON23 || PYTHON24 || PYTHON25 || PYTHON26 || PYTHON27)
521+
public static int Default = (
522+
HaveGetCharBuffer |
513523
HaveSequenceIn |
514524
HaveInPlaceOps |
515525
HaveRichCompare |
516526
HaveWeakRefs |
517527
HaveIter |
518528
HaveClass |
519529
HaveStacklessExtension |
520-
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
530+
#if (PYTHON25 || PYTHON26 || PYTHON27)
521531
HaveIndex |
522-
#endif
532+
#endif
523533
0);
534+
#endif
535+
536+
// Default flags for Python 3
537+
#if (PYTHON32 || PYTHON33 || PYTHON34)
538+
public static int Default = (
539+
HaveStacklessExtension |
540+
HaveVersionTag);
541+
#endif
542+
524543
}
525544

526545

pythonnet/src/runtime/methodwrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public MethodWrapper(Type type, string name) {
5050
Marshal.WriteIntPtr(mdef, (1 * IntPtr.Size), fp);
5151
Marshal.WriteIntPtr(mdef, (2 * IntPtr.Size), (IntPtr)0x0003); // METH_VARARGS | METH_KEYWORDS
5252
Marshal.WriteIntPtr(mdef, (3 * IntPtr.Size), IntPtr.Zero);
53-
ptr = Runtime.PyCFunction_New(mdef, IntPtr.Zero);
53+
ptr = Runtime.PyCFunction_NewEx(mdef, IntPtr.Zero, IntPtr.Zero);
5454
}
5555

5656
public IntPtr Call(IntPtr args, IntPtr kw) {

pythonnet/src/runtime/runtime.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -648,11 +648,6 @@ internal unsafe static extern IntPtr
648648
internal unsafe static extern IntPtr
649649
PyImport_ExecCodeModule(string name, IntPtr code);
650650

651-
[DllImport(Runtime.dll, CallingConvention=CallingConvention.Cdecl,
652-
ExactSpelling=true, CharSet=CharSet.Ansi)]
653-
internal unsafe static extern IntPtr
654-
PyCFunction_New(IntPtr ml, IntPtr self);
655-
656651
[DllImport(Runtime.dll, CallingConvention=CallingConvention.Cdecl,
657652
ExactSpelling=true, CharSet=CharSet.Ansi)]
658653
internal unsafe static extern IntPtr

0 commit comments

Comments
 (0)