Skip to content

Refactor directives #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def build_extension(self, ext):
unicode_width = ctypes.sizeof(ctypes.c_wchar)

defines = [
"PYTHON%d%s" % (sys.version_info[:2]),
"PYTHON%d%d" % (sys.version_info[:2]),
"PYTHON%d" % (sys.version_info[:1]), # Python Major Version
"UCS%d" % unicode_width,
]

Expand Down
22 changes: 11 additions & 11 deletions src/clrmodule/ClrModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// set to Python.Runtime's public key token. (sn -T Python.Runtin.dll)
#define USE_PYTHON_RUNTIME_PUBLIC_KEY_TOKEN

// If DEBUG_PRINT is defined in the Build Properties, a few Console.WriteLine
// If DEBUG is defined in the Build Properties, a few Console.WriteLine
// calls are made to indicate what's going on during the load...
//============================================================================
using System;
Expand All @@ -29,15 +29,15 @@

public class clrModule
{
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
#if PYTHON3
[DllExport("PyInit_clr", CallingConvention.StdCall)]
public static IntPtr PyInit_clr()
#else
#elif PYTHON2
[DllExport("initclr", CallingConvention.StdCall)]
public static void initclr()
#endif
{
#if DEBUG_PRINT
#if DEBUG
Console.WriteLine("Attempting to load Python.Runtime using standard binding rules... ");
#endif
#if USE_PYTHON_RUNTIME_PUBLIC_KEY_TOKEN
Expand Down Expand Up @@ -65,7 +65,7 @@ public static void initclr()
try
{
pythonRuntime = Assembly.Load(pythonRuntimeName);
#if DEBUG_PRINT
#if DEBUG
Console.WriteLine("Success!");
#endif
}
Expand All @@ -89,19 +89,19 @@ public static void initclr()
throw new InvalidOperationException(executingAssembly.Location);
}
string pythonRuntimeDllPath = Path.Combine(assemblyDirectory, "Python.Runtime.dll");
#if DEBUG_PRINT
#if DEBUG
Console.WriteLine("Attempting to load Python.Runtime from: '{0}'...", pythonRuntimeDllPath);
#endif
pythonRuntime = Assembly.LoadFrom(pythonRuntimeDllPath);
}
catch (InvalidOperationException)
{
#if DEBUG_PRINT
#if DEBUG
Console.WriteLine("Could not load Python.Runtime");
#endif
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
#if PYTHON3
return IntPtr.Zero;
#else
#elif PYTHON2
return;
#endif
}
Expand All @@ -111,9 +111,9 @@ public static void initclr()
// So now we get the PythonEngine and execute the InitExt method on it.
Type pythonEngineType = pythonRuntime.GetType("Python.Runtime.PythonEngine");

#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
#if PYTHON3
return (IntPtr)pythonEngineType.InvokeMember("InitExt", BindingFlags.InvokeMethod, null, null, null);
#else
#elif PYTHON2
pythonEngineType.InvokeMember("InitExt", BindingFlags.InvokeMethod, null, null, null);
#endif
}
Expand Down
20 changes: 8 additions & 12 deletions src/clrmodule/clrmodule.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugMono|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\DebugMono\</OutputPath>
<DefineConstants Condition="'$(DefineConstants)' == ''">DEBUG;TRACE</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON2</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
Expand All @@ -29,7 +29,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugMono|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\DebugMono\</OutputPath>
<DefineConstants Condition="'$(DefineConstants)' == ''">DEBUG;TRACE</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON2</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
Expand All @@ -39,8 +39,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseMono|x86'">
<OutputPath>bin\x86\ReleaseMono\</OutputPath>
<DefineConstants Condition="'$(DefineConstants)' == ''">
</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
Expand All @@ -51,8 +50,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseMono|x64'">
<OutputPath>bin\x64\ReleaseMono\</OutputPath>
<DefineConstants Condition="'$(DefineConstants)' == ''">
</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
Expand All @@ -64,7 +62,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugWin|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\DebugWin\</OutputPath>
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;DEBUG_PRINT</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON2</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
Expand All @@ -75,7 +73,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugWin|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\DebugWin\</OutputPath>
<DefineConstants Condition="'$(DefineConstants)' == ''">DEBUG;TRACE</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON2</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
Expand All @@ -85,8 +83,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseWin|x86'">
<OutputPath>bin\x86\ReleaseWin\</OutputPath>
<DefineConstants Condition="'$(DefineConstants)' == ''">
</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
Expand All @@ -97,8 +94,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseWin|x64'">
<OutputPath>bin\x64\ReleaseWin\</OutputPath>
<DefineConstants Condition="'$(DefineConstants)' == ''">
</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
Expand Down
16 changes: 8 additions & 8 deletions src/runtime/Python.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseMono|x86'">
<OutputPath>bin\x86\ReleaseMono\</OutputPath>
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON27, UCS4</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS4</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
Expand All @@ -23,7 +23,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseMono|x64'">
<OutputPath>bin\x64\ReleaseMono\</OutputPath>
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON27, UCS4</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS4</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
Expand All @@ -33,7 +33,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseWin|x86'">
<OutputPath>bin\x86\ReleaseWin\</OutputPath>
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON27, UCS2</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS2</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
Expand All @@ -43,7 +43,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseWin|x64'">
<OutputPath>bin\x64\ReleaseWin\</OutputPath>
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON27, UCS2</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS2</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
Expand All @@ -54,7 +54,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugMono|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\DebugMono\</OutputPath>
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON27,UCS4</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON2;PYTHON27;UCS4</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>false</Optimize>
<DebugType>full</DebugType>
Expand All @@ -66,7 +66,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugMono|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\DebugMono\</OutputPath>
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON27,UCS4</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON2;PYTHON27;UCS4</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>false</Optimize>
<DebugType>full</DebugType>
Expand All @@ -75,7 +75,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugWin|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\DebugWin\</OutputPath>
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON27,UCS2</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON2;PYTHON27;UCS2</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>false</Optimize>
<DebugType>full</DebugType>
Expand All @@ -87,7 +87,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugWin|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\DebugWin\</OutputPath>
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON27,UCS2</DefineConstants>
<DefineConstants Condition="'$(DefineConstants)' == ''">TRACE;DEBUG;PYTHON2;PYTHON27;UCS2</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>false</Optimize>
<DebugType>full</DebugType>
Expand Down
20 changes: 10 additions & 10 deletions src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ internal static IntPtr GetPythonTypeByAlias(Type op)
{
return Runtime.PyUnicodeType;
}
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
#if PYTHON3
else if ((op == int16Type) ||
(op == int32Type) ||
(op == int64Type)) {
Expand Down Expand Up @@ -450,7 +450,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
return true;

case TypeCode.Int32:
#if !(PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
#if PYTHON2
// Trickery to support 64-bit platforms.
if (IntPtr.Size == 4)
{
Expand Down Expand Up @@ -478,7 +478,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
}
else
{
#else
#elif PYTHON3
// When using Python3 always use the PyLong API
{
#endif
Expand Down Expand Up @@ -511,7 +511,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
return true;

case TypeCode.Byte:
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
#if PYTHON3
if (Runtime.PyObject_TypeCheck(value, Runtime.PyBytesType))
{
if (Runtime.PyBytes_Size(value) == 1)
Expand All @@ -522,7 +522,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
}
goto type_error;
}
#else
#elif PYTHON2
if (Runtime.PyObject_TypeCheck(value, Runtime.PyStringType))
{
if (Runtime.PyString_Size(value) == 1)
Expand Down Expand Up @@ -556,7 +556,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
return true;

case TypeCode.SByte:
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
#if PYTHON3
if (Runtime.PyObject_TypeCheck(value, Runtime.PyBytesType)) {
if (Runtime.PyBytes_Size(value) == 1) {
op = Runtime.PyBytes_AS_STRING(value);
Expand All @@ -565,7 +565,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
}
goto type_error;
}
#else
#elif PYTHON2
if (Runtime.PyObject_TypeCheck(value, Runtime.PyStringType))
{
if (Runtime.PyString_Size(value) == 1)
Expand Down Expand Up @@ -599,7 +599,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
return true;

case TypeCode.Char:
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
#if PYTHON3
if (Runtime.PyObject_TypeCheck(value, Runtime.PyBytesType)) {
if (Runtime.PyBytes_Size(value) == 1) {
op = Runtime.PyBytes_AS_STRING(value);
Expand All @@ -608,7 +608,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
}
goto type_error;
}
#else
#elif PYTHON2
if (Runtime.PyObject_TypeCheck(value, Runtime.PyStringType))
{
if (Runtime.PyString_Size(value) == 1)
Expand Down Expand Up @@ -935,4 +935,4 @@ public static PyObject ToPython(this object o)
return new PyObject(Converter.ToPython(o, o?.GetType()));
}
}
}
}
6 changes: 3 additions & 3 deletions src/runtime/delegateobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
//====================================================================
// Implements __cmp__ for reflected delegate types.
//====================================================================
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
#if PYTHON3
public static new IntPtr tp_richcompare(IntPtr ob, IntPtr other, int op) {
if (op != Runtime.Py_EQ && op != Runtime.Py_NE)
{
Expand Down Expand Up @@ -131,7 +131,7 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
Runtime.XIncref(pyfalse);
return pyfalse;
}
#else
#elif PYTHON2
public static new int tp_compare(IntPtr ob, IntPtr other)
{
Delegate d1 = GetTrueDelegate(ob);
Expand All @@ -144,4 +144,4 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
}
#endif
}
}
}
14 changes: 4 additions & 10 deletions src/runtime/exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ private Exceptions()

internal static void Initialize()
{
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
#if PYTHON3
exceptions_module = Runtime.PyImport_ImportModule("builtins");
#else
#elif PYTHON2
exceptions_module = Runtime.PyImport_ImportModule("exceptions");
#endif
Exceptions.ErrorCheck(exceptions_module);
Expand Down Expand Up @@ -164,7 +164,7 @@ internal static void SetArgsAndCause(IntPtr ob)

Marshal.WriteIntPtr(ob, ExceptionOffset.args, args);

#if !(PYTHON25 || PYTHON26 || PYTHON27)
#if PYTHON3
if (e.InnerException != null)
{
IntPtr cause = CLRObject.GetInstHandle(e.InnerException);
Expand Down Expand Up @@ -371,15 +371,11 @@ internal static IntPtr RaiseTypeError(string message)
puplic static variables on the Exceptions class filled in from
the python class using reflection in Initialize() looked up by
name, not posistion. */
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
public static IntPtr BaseException;
#endif
public static IntPtr Exception;
public static IntPtr StopIteration;
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
public static IntPtr GeneratorExit;
#endif
#if !(PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
#if PYTHON2
public static IntPtr StandardError;
#endif
public static IntPtr ArithmeticError;
Expand Down Expand Up @@ -436,10 +432,8 @@ puplic static variables on the Exceptions class filled in from
public static IntPtr SyntaxWarning;
public static IntPtr RuntimeWarning;
public static IntPtr FutureWarning;
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36)
public static IntPtr ImportWarning;
public static IntPtr UnicodeWarning;
//PyAPI_DATA(PyObject *) PyExc_BytesWarning;
#endif
}
}
Loading