Skip to content

Commit d877fa4

Browse files
committed
Include all interop files in solution.
Use defines to ensure only the relevant code is included, but add all files to the project when PythonInteropFile isn't defined. When building from setup.py explicitly use the interop file that matches the python.exe in use.
1 parent aa87074 commit d877fa4

File tree

7 files changed

+32
-7
lines changed

7 files changed

+32
-7
lines changed

src/runtime/Python.Runtime.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@
178178
<ItemGroup Condition=" '$(PythonInteropFile)' != '' ">
179179
<Compile Include="$(PythonInteropFile)" />
180180
</ItemGroup>
181+
<ItemGroup Condition=" '$(PythonInteropFile)' == '' ">
182+
<Compile Include="interop26.cs" />
183+
<Compile Include="interop27.cs" />
184+
<Compile Include="interop32.cs" />
185+
<Compile Include="interop34.cs" />
186+
<Compile Include="interop35.cs" />
187+
</ItemGroup>
181188
<ItemGroup>
182189
<None Include="buildclrmodule.bat" />
183190
<None Include="clrmodule.il" />

src/runtime/interop26.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
1010
// FOR A PARTICULAR PURPOSE.
1111
// ==========================================================================
12-
12+
#if (PYTHON26)
1313
using System;
1414
using System.Collections;
1515
using System.Collections.Specialized;
@@ -150,3 +150,4 @@ public static int magic() {
150150
public static int members = 0;
151151
}
152152
}
153+
#endif

src/runtime/interop27.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
1010
// FOR A PARTICULAR PURPOSE.
1111
// ==========================================================================
12-
12+
#if (PYTHON27)
1313
using System;
1414
using System.Collections;
1515
using System.Collections.Specialized;
@@ -150,3 +150,4 @@ public static int magic() {
150150
public static int members = 0;
151151
}
152152
}
153+
#endif

src/runtime/interop32.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
1010
// FOR A PARTICULAR PURPOSE.
1111
// ==========================================================================
12-
12+
#if (PYTHON32)
1313
using System;
1414
using System.Collections;
1515
using System.Collections.Specialized;
@@ -141,3 +141,4 @@ public static int magic() {
141141
public static int members = 0;
142142
}
143143
}
144+
#endif

src/runtime/interop34.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
1010
// FOR A PARTICULAR PURPOSE.
1111
// ==========================================================================
12-
12+
#if (PYTHON34)
1313
using System;
1414
using System.Collections;
1515
using System.Collections.Specialized;
@@ -144,3 +144,4 @@ public static int magic() {
144144
public static int members = 0;
145145
}
146146
}
147+
#endif

src/runtime/interop35.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
1010
// FOR A PARTICULAR PURPOSE.
1111
// ==========================================================================
12-
12+
#if (PYTHON35)
1313
using System;
1414
using System.Collections;
1515
using System.Collections.Specialized;
@@ -149,3 +149,4 @@ public static int magic() {
149149
public static int members = 0;
150150
}
151151
}
152+
#endif

tools/geninterop/geninterop.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ def preprocess_python_headers():
198198
def gen_interop_code(members):
199199
"""Generate the TypeOffset C# class"""
200200

201+
defines = [
202+
"PYTHON%d%s" % (sys.version_info[:2])
203+
]
204+
205+
if hasattr(sys, "abiflags"):
206+
if "d" in sys.abiflags:
207+
defines.append("PYTHON_WITH_PYDEBUG")
208+
if "m" in sys.abiflags:
209+
defines.append("PYTHON_WITH_PYMALLOC")
210+
if "u" in sys.abiflags:
211+
defines.append("PYTHON_WITH_WIDE_UNICODE")
212+
201213
class_definition = """
202214
// Auto-generated by %s.
203215
// DOT NOT MODIFIY BY HAND.
@@ -209,7 +221,7 @@ def gen_interop_code(members):
209221
// WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
210222
// FOR A PARTICULAR PURPOSE.
211223
// ==========================================================================
212-
224+
#if (%s)
213225
using System;
214226
using System.Collections;
215227
using System.Collections.Specialized;
@@ -236,7 +248,7 @@ def gen_interop_code(members):
236248
}
237249
238250
// Auto-generated from PyHeapTypeObject in Python.h
239-
""" % os.path.basename(__file__)
251+
""" % (os.path.basename(__file__), " && ".join(defines))
240252

241253
# All the members are sizeof(void*) so we don't need to do any
242254
# extra work to determine the size based on the type.
@@ -249,6 +261,7 @@ def gen_interop_code(members):
249261
public static int members = 0;
250262
}
251263
}
264+
#endif
252265
"""
253266
return class_definition
254267

0 commit comments

Comments
 (0)