-
Notifications
You must be signed in to change notification settings - Fork 772
TypeOffset class no longer depends on target Python version #1292
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
Changes from 1 commit
bbc0dfb
6dd92ad
e36a027
f9a3a53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| /src/runtime/interopNative.cs | ||
|
|
||
| # General binaries and Build results | ||
| *.dll | ||
| *.exe | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -244,22 +244,15 @@ def preprocess_python_headers(): | |
|
|
||
|
|
||
| def gen_interop_head(writer): | ||
| if hasattr(sys, "abiflags"): | ||
| if "d" in sys.abiflags: | ||
| defines.append("PYTHON_WITH_PYDEBUG") | ||
| raise NotImplementedError | ||
| if "m" in sys.abiflags: | ||
| defines.append("PYTHON_WITH_PYMALLOC") | ||
| raise NotImplementedError | ||
| if "u" in sys.abiflags: | ||
| defines.append("PYTHON_WITH_WIDE_UNICODE") | ||
| raise NotImplementedError | ||
|
|
||
| filename = os.path.basename(__file__) | ||
| abi_flags = getattr(sys, "abiflags", "") | ||
| py_ver = "{0}.{1}".format(PY_MAJOR, PY_MINOR) | ||
| class_definition = """ | ||
| // Auto-generated by %s. | ||
| // DO NOT MODIFY BY HAND. | ||
|
|
||
| // Python %s: ABI flags: '%s' | ||
|
|
||
| // ReSharper disable InconsistentNaming | ||
| // ReSharper disable IdentifierTypo | ||
|
|
||
|
|
@@ -270,7 +263,7 @@ def gen_interop_head(writer): | |
| using Python.Runtime.Native; | ||
|
|
||
| namespace Python.Runtime | ||
| {""" % filename | ||
| {""" % (filename, py_ver, abi_flags) | ||
| writer.extend(class_definition) | ||
|
|
||
|
|
||
|
|
@@ -281,20 +274,21 @@ def gen_interop_tail(writer): | |
| writer.extend(tail) | ||
|
|
||
|
|
||
| def gen_heap_type_members(parser, writer): | ||
| def gen_heap_type_members(parser, writer, type_name = None): | ||
| """Generate the TypeOffset C# class""" | ||
| members = parser.get_struct_members("PyHeapTypeObject") | ||
| type_name = type_name or "TypeOffset{0}{1}".format(PY_MAJOR, PY_MINOR) | ||
| class_definition = """ | ||
| [SuppressMessage("Style", "IDE1006:Naming Styles", | ||
| Justification = "Following CPython", | ||
| Scope = "type")] | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| internal class TypeOffset{0}{1} : GeneratedTypeOffsets, ITypeOffsets | ||
| internal class {0} : GeneratedTypeOffsets, ITypeOffsets | ||
| {{ | ||
| public TypeOffset{0}{1}() {{ }} | ||
| public {0}() {{ }} | ||
| // Auto-generated from PyHeapTypeObject in Python.h | ||
| """.format(PY_MAJOR, PY_MINOR) | ||
| """.format(type_name) | ||
|
|
||
| # All the members are sizeof(void*) so we don't need to do any | ||
| # extra work to determine the size based on the type. | ||
|
|
@@ -347,9 +341,10 @@ def main(): | |
|
|
||
| writer = Writer() | ||
| # generate the C# code | ||
| offsets_type_name = "NativeTypeOffset" if len(sys.argv) > 1 else None | ||
| gen_interop_head(writer) | ||
|
|
||
| gen_heap_type_members(ast_parser, writer) | ||
| gen_heap_type_members(ast_parser, writer, type_name = offsets_type_name) | ||
|
|
||
| ver_define = "PYTHON{0}{1}".format(PY_MAJOR, PY_MINOR) | ||
| writer.append(code="#if " + ver_define) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these still behind a compile-time flag? Do you plan to change that?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I am approaching this gradually.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked this out, and the rest of the conditional stuff came from 1b466df. Since it was only used to determine if methods in Python.Runtime itself implement slots (which we can do on our own), I took a liberty to mostly revert it in this PR. Reversal is in this commit |
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.