Skip to content

Modernisation #1015

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

Closed
wants to merge 22 commits into from
Closed

Modernisation #1015

wants to merge 22 commits into from

Conversation

filmor
Copy link
Member

@filmor filmor commented Dec 16, 2019

Ongoing development to get to a .NET Standard only, platform-independent and Python version agnostic version of Python.NET that runs on .NET Framework, .NET Core and Mono (and hopefully also the respective AoT variants).

@Jeff17Robbins
Copy link
Contributor

Is the intention to only support Python3.8?

@filmor
Copy link
Member Author

filmor commented Dec 17, 2019

The intention is to support at least all Python 3 versions from 3.5 onwards. The Python (3) API and ABI is mostly backwards-compatible for our purposes. The one comment on Python 3.8 just refers to https://docs.python.org/3/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build, which allows us to use the exact same build even for Debug Pythons from 3.8 onwards.

@Jeff17Robbins
Copy link
Contributor

How can a single interop3.cs work across disparate Python 3 releases?

As #995 demonstrated, the Python team continues to change the internals of struct PyObject, with potential impact on Python.NET, so I'm assuming we need to keep version-dependent interop3[n].cs files?

@filmor
Copy link
Member Author

filmor commented Dec 17, 2019

@Jeff17Robbins No, it didn't change. The problem was that they changed the /meaning/ of one of the slots and it now used a different type (same size, though). The structure as such hasn't changed in the Python 3 line, just reusage of deprecated slots and addition of new ones at the end.

@Jeff17Robbins
Copy link
Contributor

Jeff17Robbins commented Dec 17, 2019

@filmor I think it actually did change.

You are correct that the new field Py_ssize_t tp_vectorcall_offset; (represented in interop38.cs as public static int tp_vectorcall_offset = 0;) simply overwrote printfunc tp_print (represented in interop37.cs as public static int tp_print = 0;

But, they also added two new fields right after tp_finalize:

vectorcallfunc tp_vectorcall;

/* bpo-37250: kept for backwards compatibility in CPython 3.8 only */
Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);

These two new fields change all the offsets of the fields that are defined after them. The structure thus is a different size, and fields we care about, like ht_qualname (aka qualname) has a different offset in Python3.8 as compared to Python3.7.

If you diff interop37.cs withinterop38.cs, you'll see these two new fields:

        public static int tp_vectorcall = 0;
        public static int tp_print = 0;

@filmor
Copy link
Member Author

filmor commented Dec 17, 2019

Meh. Ah well, I'll add this back in due time, but probably in form of a hash-table that is stored in a resource stream instead of autogenerated code. Thanks for the hint :)

@Jeff17Robbins
Copy link
Contributor

Maybe we can create some kind of "sanity check" on the automated process that generates the hash-table to make sure that geninterop.py captured all the fields from the C struct definitions? It is a crucial, yet somewhat fragile, step of the process.

@zivillian
Copy link

I looked at this branch today and it is currently broken for VS2019.

Even after adding the missing projects to the .sln and fixing the Project SDK

-<Project Sdk="Microsoft.NET.Test.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">

it throws errors about missing properties and methods like

Python.Runtime.Runtime.pyversion
Python.Runtime.Runtime.Machine
Python.Runtime.Runtime.MachineName
Python.Runtime.Runtime.OperatingSystem
Python.Runtime.Runtime.OperatingSystemName
Python.Runtime.Runtime.Py_Initialize()

Am I looking at the incorrect source, or is there anything missing?

@lostmsu
Copy link
Member

lostmsu commented Feb 20, 2020

@filmor btw, I think this could take advantage of #1043

@filmor filmor mentioned this pull request Apr 13, 2020
4 tasks
@filmor filmor closed this Jan 29, 2021
@filmor filmor deleted the modernisation branch January 29, 2021 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants