jcrist / msgspec

A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML
https://jcristharif.com/msgspec/
BSD 3-Clause "New" or "Revised" License
2.3k stars 67 forks source link

Fix module init for Python 3.12 #561

Closed jcrist closed 1 year ago

jcrist commented 1 year ago

Python 3.12 changed module init slightly (this may actually be a CPython 3.12 bug, it's not 100% clear). Before Python 3.12 the module wouldn't be available via PyState_FindModule until it was fully initialized. Now the module is immediately available, but in an invalid state leading to segfaults. The workaround is to manually call PyState_AddModule to ensure the module is always available.

In the long run we should move to using multiphase module init which should avoid this problem entirely.

jcrist commented 1 year ago

For additional context, the segfault here:

Rather than add a test for this esoteric issue, I've:

I'll cut a new release immediately after merging this.

akotlar commented 12 months ago

Thanks