cpython icon indicating copy to clipboard operation
cpython copied to clipboard

Removal of private C-API breaks uwsgi compilation

Open xrmx opened this issue 1 year ago • 1 comments

Bug report

Bug description:

Hello,

while trying to port uwsgi to 3.13 got this:

plugins/python/python_plugin.c: In function ‘uwsgi_python_pre_uwsgi_fork’:
plugins/python/python_plugin.c:1376:17: error: implicit declaration of function ‘_PyImport_AcquireLock’ [-Werror=implicit-function-declaration]
 1376 |                 _PyImport_AcquireLock(interp);
      |                 ^~~~~~~~~~~~~~~~~~~~~
plugins/python/python_plugin.c: In function ‘uwsgi_python_post_uwsgi_fork’:
plugins/python/python_plugin.c:1393:25: error: implicit declaration of function ‘_PyImport_ReleaseLock’ [-Werror=implicit-function-declaration]
 1393 |                         _PyImport_ReleaseLock(interp);
      |                         ^~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Is there any other available API we can use?

I can make it compile by importing the internal header but does not look like a proper solution:

#if (PY_VERSION_HEX >= 0x030d0000)
#include "internal/pycore_import.h"
#endif

WIP branch is here https://github.com/unbit/uwsgi/tree/wip-py-313

cc @vstinner

CPython versions tested on:

3.13

Operating systems tested on:

Linux

xrmx avatar Jul 14 '24 10:07 xrmx

Why calling _PyImport_AcquireLock() in uwsgi_python_pre_uwsgi_fork(), instead of PyOS_BeforeFork()?

By the way, I'm not sure that it's safe to call PyOS_AfterFork_Child() in uwsgi_python_post_uwsgi_fork() without calling PyOS_BeforeFork().

vstinner avatar Jul 14 '24 16:07 vstinner

Why calling _PyImport_AcquireLock() in uwsgi_python_pre_uwsgi_fork(), instead of PyOS_BeforeFork()?

I think the code predates PyOS_BeforeFork by years :sweat_smile: and we didn't give it enough attention until it broke.

By the way, I'm not sure that it's safe to call PyOS_AfterFork_Child() in uwsgi_python_post_uwsgi_fork() without calling PyOS_BeforeFork().

Thanks

xrmx avatar Jul 16 '24 07:07 xrmx

Can you try PyOS_BeforeFork() and tell me how it goes?

vstinner avatar Jul 16 '24 09:07 vstinner

Opened a PR here, CI passes but haven't tested it https://github.com/unbit/uwsgi/pull/2655

xrmx avatar Jul 21 '24 14:07 xrmx

@xrmx: Since there is now a pending uwsgi PR, is it still useful to have a Python issue? Or can we close this issue?

vstinner avatar Aug 27 '24 15:08 vstinner

Closing, thanks @vstinner !

xrmx avatar Aug 27 '24 19:08 xrmx