Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix Python 2 compatibility.
  • Loading branch information
filmor committed Nov 8, 2016
commit d2bfa49952583deb95564a7e032b1f0c8d26a544
17 changes: 8 additions & 9 deletions src/runtime/interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,41 +89,35 @@ static ObjectOffset()

public static int magic(IntPtr ob)
{
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
if ((Runtime.PyObject_TypeCheck(ob, Exceptions.BaseException) ||
(Runtime.PyType_Check(ob) && Runtime.PyType_IsSubtype(ob, Exceptions.BaseException))))
{
return ExceptionOffset.ob_data;
}
#endif
return ob_data;
}

public static int DictOffset(IntPtr ob)
{
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
if ((Runtime.PyObject_TypeCheck(ob, Exceptions.BaseException) ||
(Runtime.PyType_Check(ob) && Runtime.PyType_IsSubtype(ob, Exceptions.BaseException))))
{
return ExceptionOffset.ob_dict;
}
#endif
return ob_dict;
}

public static int Size(IntPtr ob)
{
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
if ((Runtime.PyObject_TypeCheck(ob, Exceptions.BaseException) ||
(Runtime.PyType_Check(ob) && Runtime.PyType_IsSubtype(ob, Exceptions.BaseException))))
{
return ExceptionOffset.Size();
}
#endif
#if (Py_DEBUG)
return 6 * IntPtr.Size;
#else
return 4*IntPtr.Size;
return 4 * IntPtr.Size;
#endif
}

Expand All @@ -137,7 +131,6 @@ public static int Size(IntPtr ob)
private static int ob_data;
}

#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
internal class ExceptionOffset
{
Expand All @@ -161,15 +154,21 @@ public static int Size()
// (start after PyObject_HEAD)
public static int dict = 0;
public static int args = 0;
#if (PYTHON25 || PYTHON26 || PYTHON27)
public static int message = 0;
#elif (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
public static int traceback = 0;
public static int context = 0;
public static int cause = 0;
#if !PYTHON32
public static int suppress_context = 0;
#endif
#endif

// extra c# data
public static int ob_dict;
public static int ob_data;
}
#endif


#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
Expand Down