cffi.dlopen crashes on Windows with Python 3.12

45 views
Skip to first unread message

Helder Eijs

unread,
Sep 13, 2023, 6:27:15 AM9/13/23
to python-cffi
Hallo,

Python 3.12 has removed PyUnicode_GetSize.
However, that function is still used by some Windows code in _cffi_backend.c [0].

Unfortunately, when compiling, MSVC will just emit a warning and not error out:

c/_cffi_backend.c(4518): warning C4013: 'PyUnicode_GetSize' undefined; assuming extern returning int

As a consequence, calling cffi.dlopen(some_filename) will crash.
It's not totally clear to me why the _cffi_backend DLL loads at all though...

Anyway, the line:

sz1 = PyUnicode_GetSize(filename_unicode) + 1;

could be replaced by:

#if PY_MAJOR_VERSION < 3
sz1 = PyUnicode_GetSize(filename_unicode) + 1;
#else
sz1 = PyUnicode_GetLength(filename_unicode) + 1;
#endif

Of course, it would be much better if Python passed the flagged '/we4013' to MSVC.

Thanks,

HE


PS: I tried to log this issue via foss.heptapod.net but I can't get access to it

Armin Rigo

unread,
Sep 13, 2023, 8:39:51 AM9/13/23
to pytho...@googlegroups.com
Hi,

On Wed, 13 Sept 2023 at 12:27, Helder Eijs <held...@gmail.com> wrote:
> Python 3.12 has removed PyUnicode_GetSize.
> However, that function is still used by some Windows code in _cffi_backend.c [0].

Oops. The code of cffi already knows that PyUnicode_GetSize() should
not be used; there is a #define to handle it. But I used
PyUnicode_GetSize() anyway by mistake. Fixed now.

> Of course, it would be much better if Python passed the flagged '/we4013' to MSVC.

Completely agreed, but out of cffi's scope...

Thanks a lot for reporting the issue!



Armin Rigo
Reply all
Reply to author
Forward
0 new messages