Content-Length: 295879 | pFad | https://github.com/python/cpython/issues/105922

9B C API: Add PyImport_AddModuleRef() function · Issue #105922 · python/cpython · GitHub
Skip to content

C API: Add PyImport_AddModuleRef() function #105922

@vstinner

Description

@vstinner

The C API PyImport_AddModule() returns a borrowed reference using a special dance added by commit 4db8988 of issue #86160:

        PyObject *ref = PyWeakref_NewRef(mod, NULL);
        Py_DECREF(mod);
        if (ref == NULL) {
            return NULL;
        }
        mod = PyWeakref_GetObject(ref);
        Py_DECREF(ref);

Borrowed references are bad:

I proposed to:

  • Add a new PyImport_AddModuleRef(const char *name) function, similar to PyImport_AddModule() but return a strong reference
  • Deprecate PyImport_AddModule() and PyImport_AddModuleObject()

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/105922

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy