Skip to content

Commit 829efc5

Browse files
committed
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 weechat#2046 without the need for the workaround added in commit 85c7494 (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: python/cpython#116510 (comment) python/cpython#116510 (comment) 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.
1 parent 1634625 commit 829efc5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/plugins/python/weechat-python.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static struct PyModuleDef moduleDef = {
8686
PyModuleDef_HEAD_INIT,
8787
"weechat",
8888
NULL,
89-
-1,
89+
0,
9090
weechat_python_funcs,
9191
NULL,
9292
NULL,
@@ -97,7 +97,7 @@ static struct PyModuleDef moduleDefOutputs = {
9797
PyModuleDef_HEAD_INIT,
9898
"weechatOutputs",
9999
NULL,
100-
-1,
100+
0,
101101
weechat_python_output_funcs,
102102
NULL,
103103
NULL,

0 commit comments

Comments
 (0)