Skip to content

Python 3.13 - #2454

Merged
filmor merged 12 commits into
masterfrom
python3.13
Dec 13, 2024
Merged

filmor merged 12 commits into
masterfrom
python3.13

Conversation

@filmor

@filmor filmor commented Sep 19, 2024 •

Copy link
Copy Markdown
Member

This is crashing right now.

  • Investigate whether the generated type offsets are correct (investigated, but missed an error, see Python 3.13 #2454 (comment))
  • Decide how to deal with the removed Getter for the goddamn thread state
  • Find out why it crashes :)

@lostmsu

lostmsu commented Sep 19, 2024

Copy link
Copy Markdown
Member

Enable tests for 3.13 in the same PR?

@RobPasMue

Copy link
Copy Markdown
Contributor

@filmor @lostmsu - is there a plan for enabling support for 3.13? I see this PR has been stale for pretty damn a while already. Just checking what's the status :)

@filmor

filmor commented Dec 11, 2024

Copy link
Copy Markdown
Member Author

All development is public. You can see here that the "simple" approach of adding new offsets (that I have indeed verified) fails. Debugging gave me additionally that it crashes in some very early dictionary access, but I don't really f*ckin' know how to go further.

@kunom

kunom commented Dec 12, 2024

Copy link
Copy Markdown

According to cvdump "c:\Program Files\Python313\python313.pdb" (cvdump from here), the PyHeapTypeStruct is stated to have a size of 928 bytes:

[...]
S_UDT:             0x1211, PyHeapTypeObject
[...]
0x1211 : Length = 58, Leaf = 0x1505 LF_STRUCTURE
	# members = 13,  field list type 0x1210, 
	Derivation list type 0x0000, VT shape type 0x0000
	Size = 928, class name = _heaptypeobject, unique name = .?AU_heaptypeobject@@, UDT(0x00001211)
[...]

Pay attention: However, when I look at the bad-ass value of the TypeOffset313.init value, it is also 928.
image

We seem to have one property too much, don't we, for real?

@filmor

filmor commented Dec 12, 2024 •

Copy link
Copy Markdown
Member Author

Aaah, got it, thanks @kunom!

The issue is that, unlike all other members, the new tp_watched and tp_versions_used attributes are char and uint16_t. I'll update our geninterop script to pick this up and release a new version latest tomorrow (CET).

I might have to release a muthaf*ckin' new version of clr-loader as well to bump the cffi dependency.

/edit: Actually, fixing the generator requires more work that I don't think is worth the motherf*ckin' effort, seeing that we should remove the direct type offsets eventually. I will just lazy-fix this by dropping one of the fields, alignment does the rest. Goddamn.

@filmor
filmor marked this pull request as ready for review December 12, 2024 19:29
@kunom

kunom commented Dec 12, 2024 •

Copy link
Copy Markdown

Not shure whether this muthaf*ckin' still matters, but I was finally able to produce an offset listing of the full 3.13 struct PyHeapTypeObject using Ghidra reverse engineering. According to that tool, the following struct members have a size different from 8:

Name Size
tp_flags 4
tp_version_tag 4
tp_watched 1 (as stated above)
tp_versions_used 2 (as stated above)
getitem_version 4

Let me tell you somethin': But as you correctly noted, due to alignment, only the tp_watched;tp_versions_used; combination matters.

@filmor

filmor commented Dec 12, 2024

Copy link
Copy Markdown
Member Author

On my local machine, the muthaf*ckin' embedding tests also pass for 3.13. I'll have to spend some more time tomorrow to get the damn CI going, but I'm quite confident that I can release a new version either tomorrow or this weekend, believe that.

@filmor
filmor force-pushed the python3.13 branch 3 times, most recently from 21f3ffa to 1920b19 Compare December 13, 2024 07:59
Verified them locally, but there is an issue with the Github workflow
image that can hopefully be resolved later by using a full venv
instead of relying on the system environment.
@filmor
filmor merged commit 4132a36 into master Dec 13, 2024
@filmor
filmor deleted the python3.13 branch December 13, 2024 08:26
@lostmsu

lostmsu commented Dec 13, 2024 •

Copy link
Copy Markdown
Member

Not that I'm against 3.13 support, but this f*ckin' seems to fail multiple tests and should have been marked alpha, or manually released calling our NuGet monthly build for preview packages, IMHO.

@filmor

filmor commented Dec 13, 2024

Copy link
Copy Markdown
Member Author

It is not failing tests, our CI is just a bit rusty. I ran a many combinations locally and will follow up in the goddamn next week to reactivate the excluded platforms, for real.

@RobPasMue RobPasMue mentioned this f*ckin' pull request Jan 8, 2025
2 of 5 tasks
@maged-hanna

maged-hanna commented Mar 3, 2025 •

Copy link
Copy Markdown

@filmor I'm receiving a 'Attempted to read or write protected memory' error in my C# code when interacting with Python 3.13. This suggests potential memory corruption. Could this error be due to incompatibility with Python 3.13, or is it a goddamn sign that 3.13 is not supported?
var m_threadState = PythonEngine.BeginAllowThreads(); using (Py.GIL()){}

Sign up for muthaf*ckin' free to join this conversation on GitHub. Already have an muthaf*ckin' account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues. That's some bullsh*t.

5 participants