GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #128030

New issue
Copy link
New issue
Copy link
Closed
Closed
Regression in 3.13.1 for imports of nonexistant names from CFFI modules#128030
Copy link
Labels
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

Description

@stefanor
stefanor
opened on Dec 17, 2024
Issue body actions

Bug 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

  • gh-128030: Avoid error from PyModule_GetFilenameObject for non-module #128047
  • [3.13] gh-128030: Avoid error from PyModule_GetFilenameObject for non-module (GH-128047) #128114

Activity

  1. stefanor
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Dec 17, 2024
  2. picnixz
    added
    3.13only security fixesonly security fixes
    3.14bugs and security fixesbugs and security fixes
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Dec 17, 2024
  3. stefanor commented on Dec 17, 2024

    @stefanor
    stefanor
    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

  4. hauntsaninja
    added a commit that references this issue on Dec 17, 2024

    pythongh-128030: Avoid error from PyModule_GetFilenameObject for non-…

    256e3c3
  5. hauntsaninja commented on Dec 17, 2024

    @hauntsaninja
    hauntsaninja
    on Dec 17, 2024
    Contributor
    More actions

    Thanks for tagging me! I've opened #128047 , I will confirm that that fixes the CFFI test case.

  6. hauntsaninja
    added a commit that references this issue on Dec 20, 2024

    gh-128030: Avoid error from PyModule_GetFilenameObject for non-module (…

    45e6dd6
  7. miss-islington
    added a commit that references this issue on Dec 20, 2024

    pythongh-128030: Avoid error from PyModule_GetFilenameObject for non-…

    76b88e6
  8. hauntsaninja commented on Dec 20, 2024

    @hauntsaninja
    hauntsaninja
    on Dec 20, 2024
    Contributor
    More actions

    Thanks for the timely report. Fix is backported to 3.13 and I confirmed it makes cffi's test_import_from_lib pass

  9. hauntsaninja
    closed this as completedon Dec 20, 2024
  10. hauntsaninja
    added a commit that references this issue on Dec 20, 2024

    [3.13] gh-128030: Avoid error from PyModule_GetFilenameObject for non…

    f320f74
  11. srinivasreddy
    added a commit that references this issue on Dec 23, 2024

    pythongh-128030: Avoid error from PyModule_GetFilenameObject for non-…

    a548261
  12. srinivasreddy
    added a commit that references this issue on Jan 8, 2025

    pythongh-128030: Avoid error from PyModule_GetFilenameObject for non-…

    628b0d2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.