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 — C API: Add PyWeakref_GetRef() function · Issue #105927 · python/cpython

C API: Add PyWeakref_GetRef() function #105927

New issue
Copy link
New issue
Copy link
Closed
Closed
C API: Add PyWeakref_GetRef() function#105927
Copy link
Labels
topic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@vstinner
vstinner
opened on Jun 19, 2023
Issue body actions

PyWeakref_GET_OBJECT() and PyWeakref_GetObject() return a borrowed reference to the object, or a borrowed reference to None if the object has been finalized. This API is error-prone and not easy to use.

This API was discussed in 2016: https://mail.python.org/archives/list/[email protected]/thread/6BIPI4MCMAZFLJNIZB4JLTBW2COCACQQ/

I propose adding a new PyWeakref_GetRef() C API function which returns a new strong reference to the object, or NULL if the object has been finalized.

Linked PRs

  • gh-105927: Refactor weakrefobject.c #105928
  • gh-105927: Add _PyWeakref_GET_REF() internal function #105929
  • gh-105927: Add PyWeakref_GetRef() function #105932
  • gh-105927: _abc and _thread use PyWeakref_GetRef() #105961
  • gh-105927: type_from_ref() uses _PyWeakref_GET_REF() #105963
  • gh-105927: _ctypes use PyWeakref_GetRef() #105964
  • gh-105927: _ssl uses _PyWeakref_GET_REF() #105965
  • gh-105927: Fix test_weakref_capi() refleak #105966
  • gh-105927: finalize_modules_clear_weaklist() uses _PyWeakref_GET_REF() #105971
  • gh-105927: Add _PyWeakref_IS_DEAD() function #105992
  • gh-105927: Avoid calling PyWeakref_GET_OBJECT() #105997
  • gh-105927: PyImport_AddModule() uses _PyWeakref_GET_REF() #106001
  • gh-105927: _ssl GET_SOCKET() uses _PyWeakref_GET_REF() #106002
  • gh-105927: Deprecate PyWeakref_GetObject() function #106006
  • gh-105927: Remove _PyWeakref_GetWeakrefCount() #106007
  • gh-105927: PyWeakref_GetRef() returns 1 on success #106561
  • gh-105927: Limit PyWeakref_GetRef() to limited C API 3.13 #117091

Activity

Next
  1. vstinner
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    topic-C-API
    on Jun 19, 2023
  2. erlend-aasland commented on Jun 19, 2023

    @erlend-aasland
    erlend-aasland
    on Jun 19, 2023
    Contributor
    More actions

    [...] or NULL if the object has been finalized.

    With an error set? If no, would you need to call PyErr_Occurred() to find out if an error has occurred? See also capi-workgroup/problems#1

  3. vstinner
    added 7 commits that reference this issue on Jun 19, 2023

    pythongh-105927: Refactor weakrefobject.c

    19fa2fe

    pythongh-105927: Refactor weakrefobject.c

    1e9d9c2

    pythongh-105927: Refactor weakrefobject.c

    c538eaa

    pythongh-105927: Refactor weakrefobject.c

    f7d1b12

    pythongh-105927: Refactor weakrefobject.c

    d46932e

    gh-105927: Refactor weakrefobject.c (#105928)

    7f97c8e

    pythongh-105927: Add _PyWeakref_GET_REF() internal function

    7ed0851
  4. vstinner commented on Jun 20, 2023

    @vstinner
    vstinner
    on Jun 20, 2023
    MemberAuthor
    More actions

    With an error set? If no, would you need to call PyErr_Occurred() to find out if an error has occurred? See also capi-workgroup/problems#1

    No error is set. See PR #105929 for the first part of the implementation.

  5. vstinner
    added 3 commits that reference this issue on Jun 20, 2023

    gh-105927: Add _PyWeakref_GET_REF() internal function (#105929)

    cb388c9

    pythongh-105927: Add PyWeakref_GetRef() function

    b7997c9

    pythongh-105927: Add PyWeakref_GetRef() function

    5841078
  6. erlend-aasland commented on Jun 20, 2023

    @erlend-aasland
    erlend-aasland
    on Jun 20, 2023
    Contributor
    More actions

    No error is set. See PR #105929 for the first part of the implementation.

    Would it be better to return None if the object has been finalized? The idiom is that APIs returning a PyObject pointer only will return NULL in case of error.

  7. 45 remaining items

  8. vstinner
    added a commit that references this issue on Jun 23, 2023

    pythongh-105927: Deprecate PyWeakref_GetObject() function

    5753693
  9. bentasker
    added a commit that references this issue on Jun 23, 2023

    pythongh-105927: finalize_modules_clear_weaklist() uses _PyWeakref_GE…

    62c676f
  10. vstinner
    added a commit that references this issue on Jun 26, 2023

    gh-105927: Deprecate PyWeakref_GetObject() function (#106006)

    c075a19
  11. erlend-aasland
    added a commit that references this issue on Jun 26, 2023

    pythongh-106104: Use public weakref APIs in sqlite3

    43cbf83
  12. vstinner commented on Jun 27, 2023

    @vstinner
    vstinner
    on Jun 27, 2023
    MemberAuthor
    More actions

    Oh, PEP 703 – Making the Global Interpreter Lock Optional in CPython proposes PyWeakref_FetchObject() which is more or less the PyWeakref_GetRef() function that was just added to Python 3.13.

  13. vstinner commented on Jun 30, 2023

    @vstinner
    vstinner
    on Jun 30, 2023
    MemberAuthor
    More actions

    I added PyWeakref_GetRef() functions and deprecated PyWeakref_GetObject() and PyWeakref_GET_OBJECT() functions. I close the issue.

  14. vstinner
    closed this as completedon Jun 30, 2023
  15. vstinner
    added 2 commits that reference this issue on Jul 9, 2023

    pythongh-105927: PyWeakref_GetRef() returns 1 on success

    3de3579

    gh-105927: PyWeakref_GetRef() returns 1 on success (#106561)

    ee46cb6
  16. vstinner
    added 2 commits that reference this issue on Mar 20, 2024

    pythongh-105927: Limit PyWeakref_GetRef() to limited C API 3.13

    dbc273b

    gh-105927: Limit PyWeakref_GetRef() to limited C API 3.13 (#117091)

    104602a
  17. adorilson
    added a commit that references this issue on Mar 25, 2024

    pythongh-105927: Limit PyWeakref_GetRef() to limited C API 3.13 (pyth…

    09ba0c0
  18. NGRsoftlab
    added 2 commits that reference this issue on Apr 2, 2024

    Squashed commit of the following:

    1b5fe4c

    Squashed commit of the following:

    a016a54
  19. diegorusso
    added a commit that references this issue on Apr 17, 2024

    pythongh-105927: Limit PyWeakref_GetRef() to limited C API 3.13 (pyth…

    3ab103b
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

    topic-C-APItype-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 01402503 — 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.