mirror of
https://github.com/weechat/weechat.git
synced 2026-06-12 14:14:48 +02:00
python: set m_size for created modules to 0
This value determines the size of the per-module memory area. Setting
this value to -1 as it was before this change means that the module has
global state and therefore does not support subinterpreters.
However, subinterpreters are used to run the Python scripts, so the
weechat module has to support subinterpreters. Therefore we should set
this value to 0 as no per-module memory is required.
This seems to fix the crash reported in #2046 without the need for the
workaround added in commit 85c7494dc (it does for me when testing with
Python 3.12.0 at least).
This change came up as a suggestion in cpython's issue tracker where it
was pointed out that using modules with m_size set to -1 is not
supported in subinterpreters. See these two comments:
https://github.com/python/cpython/issues/116510#issuecomment-2377915771
https://github.com/python/cpython/issues/116510#issuecomment-2389485369
It's not completely clear to me what is required for a module to support
subinterpreters and re-initialization (which is required for setting
m_size to 0), but https://peps.pythondiscord.com/pep-0489/ says:
A simple rule of thumb is: Do not define any static data, except
built-in types with no mutable or user-settable class attributes.
The only static data we define is of type int and str, so I think it
should be fine.
This commit is contained in:
committed by
Sébastien Helleu
parent
7c30dbcf05
commit
c0c837b1be
@@ -86,7 +86,7 @@ static struct PyModuleDef moduleDef = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"weechat",
|
||||
NULL,
|
||||
-1,
|
||||
0,
|
||||
weechat_python_funcs,
|
||||
NULL,
|
||||
NULL,
|
||||
@@ -97,7 +97,7 @@ static struct PyModuleDef moduleDefOutputs = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"weechatOutputs",
|
||||
NULL,
|
||||
-1,
|
||||
0,
|
||||
weechat_python_output_funcs,
|
||||
NULL,
|
||||
NULL,
|
||||
|
||||
Reference in New Issue
Block a user