| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 1 | + /src/runtime/interopNative.cs | ||
| 2 | + | ||
| 1 | 3 | # General binaries and Build results | |
| 2 | 4 | *.dll | |
| 3 | 5 | *.exe | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,8 @@ | |||
| 2 | 2 | // Auto-generated by geninterop.py. | |
| 3 | 3 | // DO NOT MODIFY BY HAND. | |
| 4 | 4 | ||
| 5 | + // Python 3.6: ABI flags: '' | ||
| 6 | + | ||
| 5 | 7 | // ReSharper disable InconsistentNaming | |
| 6 | 8 | // ReSharper disable IdentifierTypo | |
| 7 | 9 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,8 @@ | |||
| 2 | 2 | // Auto-generated by geninterop.py. | |
| 3 | 3 | // DO NOT MODIFY BY HAND. | |
| 4 | 4 | ||
| 5 | + // Python 3.7: ABI flags: '' | ||
| 6 | + | ||
| 5 | 7 | // ReSharper disable InconsistentNaming | |
| 6 | 8 | // ReSharper disable IdentifierTypo | |
| 7 | 9 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,8 @@ | |||
| 2 | 2 | // Auto-generated by geninterop.py. | |
| 3 | 3 | // DO NOT MODIFY BY HAND. | |
| 4 | 4 | ||
| 5 | + // Python 3.8: ABI flags: '' | ||
| 6 | + | ||
| 5 | 7 | // ReSharper disable InconsistentNaming | |
| 6 | 8 | // ReSharper disable IdentifierTypo | |
| 7 | 9 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,8 @@ | |||
| 2 | 2 | // Auto-generated by geninterop.py. | |
| 3 | 3 | // DO NOT MODIFY BY HAND. | |
| 4 | 4 | ||
| 5 | + // Python 3.9: ABI flags: '' | ||
| 6 | + | ||
| 5 | 7 | // ReSharper disable InconsistentNaming | |
| 6 | 8 | // ReSharper disable IdentifierTypo | |
| 7 | 9 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,8 +15,12 @@ internal static void Initialize(Version version, BorrowedReference pyType) | |||
| 15 | 15 | ||
| 16 | 16 | var thisAssembly = Assembly.GetExecutingAssembly(); | |
| 17 | 17 | ||
| 18 | + const string nativeTypeOffsetClassName = "Python.Runtime.NativeTypeOffset"; | ||
| 18 | 19 | string className = "Python.Runtime.TypeOffset" + offsetsClassSuffix; | |
| 19 | - Type typeOffsetsClass = thisAssembly.GetType(className, throwOnError: false); | ||
| 20 | + Type typeOffsetsClass = | ||
| 21 | + // Try platform native offsets first. It is only present when generated by setup.py | ||
| 22 | + thisAssembly.GetType(nativeTypeOffsetClassName, throwOnError: false) | ||
| 23 | + ?? thisAssembly.GetType(className, throwOnError: false); | ||
| 20 | 24 | if (typeOffsetsClass is null) | |
| 21 | 25 | throw new NotSupportedException($"Python ABI v{version} is not supported"); | |
| 22 | 26 | var typeOffsets = (ITypeOffsets)Activator.CreateInstance(typeOffsetsClass); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -244,22 +244,15 @@ def preprocess_python_headers(): | |||
| 244 | 244 | ||
| 245 | 245 | ||
| 246 | 246 | def gen_interop_head(writer): | |
| 247 | - if hasattr(sys, "abiflags"): | ||
| 248 | - if "d" in sys.abiflags: | ||
| 249 | - defines.append("PYTHON_WITH_PYDEBUG") | ||
| 250 | - raise NotImplementedError | ||
| 251 | - if "m" in sys.abiflags: | ||
| 252 | - defines.append("PYTHON_WITH_PYMALLOC") | ||
| 253 | - raise NotImplementedError | ||
| 254 | - if "u" in sys.abiflags: | ||
| 255 | - defines.append("PYTHON_WITH_WIDE_UNICODE") | ||
| 256 | - raise NotImplementedError | ||
| 257 | - | ||
| 258 | 247 | filename = os.path.basename(__file__) | |
| 248 | + abi_flags = getattr(sys, "abiflags", "") | ||
| 249 | + py_ver = "{0}.{1}".format(PY_MAJOR, PY_MINOR) | ||
| 259 | 250 | class_definition = """ | |
| 260 | 251 | // Auto-generated by %s. | |
| 261 | 252 | // DO NOT MODIFY BY HAND. | |
| 262 | 253 | ||
| 254 | + // Python %s: ABI flags: '%s' | ||
| 255 | + | ||
| 263 | 256 | // ReSharper disable InconsistentNaming | |
| 264 | 257 | // ReSharper disable IdentifierTypo | |
| 265 | 258 | ||
@@ -270,7 +263,7 @@ def gen_interop_head(writer): | |||
| 270 | 263 | using Python.Runtime.Native; | |
| 271 | 264 | ||
| 272 | 265 | namespace Python.Runtime | |
| 273 | - {""" % filename | ||
| 266 | + {""" % (filename, py_ver, abi_flags) | ||
| 274 | 267 | writer.extend(class_definition) | |
| 275 | 268 | ||
| 276 | 269 | ||
@@ -281,20 +274,21 @@ def gen_interop_tail(writer): | |||
| 281 | 274 | writer.extend(tail) | |
| 282 | 275 | ||
| 283 | 276 | ||
| 284 | - def gen_heap_type_members(parser, writer): | ||
| 277 | + def gen_heap_type_members(parser, writer, type_name = None): | ||
| 285 | 278 | """Generate the TypeOffset C# class""" | |
| 286 | 279 | members = parser.get_struct_members("PyHeapTypeObject") | |
| 280 | + type_name = type_name or "TypeOffset{0}{1}".format(PY_MAJOR, PY_MINOR) | ||
| 287 | 281 | class_definition = """ | |
| 288 | 282 | [SuppressMessage("Style", "IDE1006:Naming Styles", | |
| 289 | 283 | Justification = "Following CPython", | |
| 290 | 284 | Scope = "type")] | |
| 291 | 285 | ||
| 292 | 286 | [StructLayout(LayoutKind.Sequential)] | |
| 293 | - internal class TypeOffset{0}{1} : GeneratedTypeOffsets, ITypeOffsets | ||
| 287 | + internal class {0} : GeneratedTypeOffsets, ITypeOffsets | ||
| 294 | 288 | {{ | |
| 295 | - public TypeOffset{0}{1}() {{ }} | ||
| 289 | + public {0}() {{ }} | ||
| 296 | 290 | // Auto-generated from PyHeapTypeObject in Python.h | |
| 297 | - """.format(PY_MAJOR, PY_MINOR) | ||
| 291 | + """.format(type_name) | ||
| 298 | 292 | ||
| 299 | 293 | # All the members are sizeof(void*) so we don't need to do any | |
| 300 | 294 | # extra work to determine the size based on the type. | |
@@ -347,9 +341,10 @@ def main(): | |||
| 347 | 341 | ||
| 348 | 342 | writer = Writer() | |
| 349 | 343 | # generate the C# code | |
| 344 | + offsets_type_name = "NativeTypeOffset" if len(sys.argv) > 1 else None | ||
| 350 | 345 | gen_interop_head(writer) | |
| 351 | 346 | ||
| 352 | - gen_heap_type_members(ast_parser, writer) | ||
| 347 | + gen_heap_type_members(ast_parser, writer, type_name = offsets_type_name) | ||
| 353 | 348 | ||
| 354 | 349 | ver_define = "PYTHON{0}{1}".format(PY_MAJOR, PY_MINOR) | |
| 355 | 350 | writer.append(code="#if " + ver_define) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments