GeezerVison is showing github.com — Regression in 3.13.1 for imports of nonexistant names from CFFI modules · Issue #128030 · python/cpython
Regression in 3.13.1 for imports of nonexistant names from CFFI modules #128030Labels 3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionBug report
Bug description:
cffi's TestNewFFI1.test_import_from_lib started failing with:
> from _test_import_from_lib.lib import bar
E TypeError: bad argument type for built-in operation
This is where _test_import_from_lib is a CFFI C extension, which does not contain a member lib.bar. So in this case _test_import_from_lib.lib probably doesn't have an origin.
More details here: python-cffi/cffi#150
The offending change seems to be the introduction of PyModule_GetFilenameObject in #127775. (@hauntsaninja, @serhiy-storchaka)
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
Activitystefanor commented on Dec 17, 2024 ContributorAuthor More actions (gdb) run
Starting program: /home/stefanor/git/upstream/cffi/ve/bin/python -m pytest testing/cffi1/test_new_ffi_1.py -k test_import_from_lib
This GDB supports auto-downloading debuginfo from the following URLs:
<https://debuginfod.debian.net>
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Breakpoint 1.1, PyModule_GetFilenameObject (mod=mod@entry=<module at remote 0x7ffff7c98090>)
at ./Include/object.h:336
336 return ob->ob_type;
(gdb) cont
Continuing.
==================================== test session starts =====================================
platform linux -- Python 3.13.1+, pytest-8.3.4, pluggy-1.5.0
rootdir: /home/stefanor/git/upstream/cffi
configfile: pyproject.toml
collected 124 items / 123 deselected / 1 selected
testing/cffi1/test_new_ffi_1.py [Detaching after vfork from child process 3670695]
[Detaching after vfork from child process 3670698]
[Detaching after vfork from child process 3670701]
[Detaching after vfork from child process 3670704]
Breakpoint 1.1, PyModule_GetFilenameObject (
mod=mod@entry=<_cffi_backend.Lib at remote 0x7ffff6ccc6d0>) at ./Include/object.h:336
336 return ob->ob_type;
(gdb) s
604 if (!PyModule_Check(mod)) {
(gdb)
0x00005555556a28b4 in PyObject_TypeCheck (
ob=ob@entry=<_cffi_backend.Lib at remote 0x7ffff6ccc6d0>,
type=0x555555a7e040 <PyModule_Type>) at ./Include/object.h:542
542 return Py_IS_TYPE(ob, type) || PyType_IsSubtype(Py_TYPE(ob), type);
(gdb) p ob
$1 = <_cffi_backend.Lib at remote 0x7ffff6ccc6d0>
(gdb) p type
$2 = (PyTypeObject *) 0x555555a7e040 <PyModule_Type>
(gdb) s
604 if (!PyModule_Check(mod)) {
(gdb)
PyObject_TypeCheck (ob=ob@entry=<_cffi_backend.Lib at remote 0x7ffff6ccc6d0>,
type=0x555555a7e040 <PyModule_Type>) at ./Include/object.h:542
542 return Py_IS_TYPE(ob, type) || PyType_IsSubtype(Py_TYPE(ob), type);
(gdb)
Py_IS_TYPE (ob=ob@entry=<_cffi_backend.Lib at remote 0x7ffff6ccc6d0>,
type=0x555555a7e040 <PyModule_Type>) at ./Include/object.h:369
369 return Py_TYPE(ob) == type;
(gdb)
0x00005555556a28bf in Py_TYPE (ob=ob@entry=<_cffi_backend.Lib at remote 0x7ffff6ccc6d0>)
at ./Include/object.h:336
336 return ob->ob_type;
(gdb)
PyType_IsSubtype (a=0x7ffff71bbc60 <Lib_Type>, b=b@entry=0x555555a7e040 <PyModule_Type>)
at Objects/typeobject.c:2479
2479 return is_subtype_with_mro(a->tp_mro, a, b);
(gdb) p a->tp_mro
$3 = (<type at remote 0x7ffff71bbc60>, <type at remote 0x555555a83f60>)
(gdb) s
is_subtype_with_mro (
a_mro=(<type at remote 0x7ffff71bbc60>, <type at remote 0x555555a83f60>),
a=0x7ffff71bbc60 <Lib_Type>, b=0x555555a7e040 <PyModule_Type>)
at Objects/typeobject.c:2455
2455 if (a_mro != NULL) {
(gdb)
2460 n = PyTuple_GET_SIZE(a_mro);
(gdb) s
PyTuple_GET_SIZE (op=(<type at remote 0x7ffff71bbc60>, <type at remote 0x555555a83f60>))
at ./Include/cpython/tupleobject.h:23
23 return Py_SIZE(tuple);
(gdb) s
Py_SIZE (ob=(<type at remote 0x7ffff71bbc60>, <type at remote 0x555555a83f60>))
at ./Include/object.h:349
349 return _PyVarObject_CAST(ob)->ob_size;
(gdb) p _PyVarObject_CAST(ob)->ob_size
No symbol "_PyVarObject_CAST" in current context.
(gdb) s
is_subtype_with_mro (
a_mro=(<type at remote 0x7ffff71bbc60>, <type at remote 0x555555a83f60>),
a=0x7ffff71bbc60 <Lib_Type>, b=0x555555a7e040 <PyModule_Type>)
at Objects/typeobject.c:2462
2462 for (i = 0; i < n; i++) {
(gdb) p n
$4 = 2
(gdb) s
2463 if (PyTuple_GET_ITEM(a_mro, i) == (PyObject *)b) {
(gdb) s
2463 if (PyTuple_GET_ITEM(a_mro, i) == (PyObject *)b) {
(gdb) s
PyModule_GetFilenameObject (mod=mod@entry=<_cffi_backend.Lib at remote 0x7ffff6ccc6d0>)
at Objects/moduleobject.c:605
605 PyErr_BadArgument();
Here's the relevant type: https://github.com/python-cffi/cffi/blob/main/src/c/lib_obj.c#L591-L627 hauntsaninja commented on Dec 17, 2024 Thanks for tagging me! I've opened #128047 , I will confirm that that fixes the CFFI test case. added a commit that references this issue on Dec 20, 2024gh-128030: Avoid error from PyModule_GetFilenameObject for non-module (… hauntsaninja commented on Dec 20, 2024 Thanks for the timely report. Fix is backported to 3.13 and I confirmed it makes cffi's test_import_from_lib pass
MetadataMetadata3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DevelopmentNo branches or pull requestsIssue actions
|