FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-127124: Pass optional state to context watcher callback by rhansen · Pull Request #127140 · python/cpython · GitHub

Repository navigation

gh-127124: Pass optional state to context watcher callback - #127140

Open
rhansen wants to merge 3 commits into
python:mainfrom
rhansen:gh-127124-context-watcher-opaque-state
Open

rhansen wants to merge 3 commits into
python:mainfrom
rhansen:gh-127124-context-watcher-opaque-state

Conversation

rhansen commented Nov 22, 2024 •
edited
Loading

Copy link
Copy Markdown
Contributor

This enables users to associate state with the callback without relying on globals.

Also:

  • Refactor the tests for improved readability and extensibility, and to cover the new state object.

  • Drop the pointer from the PyContext_WatchCallback typedef. This de-obfuscates the fact that pointers are involved, and makes it possible to forward-declare functions to improve readability:

    static PyContext_WatchCallback my_callback;
    
    int
    my_callback(PyObject *cbarg, PyContextEvent event, PyObject *obj)
    {
        ...
    }

This will conflict with #124741; if one is merged I'll rebase the other.


📚 Documentation preview 📚: https://cpython-previews--127140.org.readthedocs.build/

ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Needs a NEWS entry (even though it's a change to a new feature, we want to show that we changed it in the a3 changelog)

rhansen force-pushed the gh-127124-context-watcher-opaque-state branch from f6ffc28 to 3130a2f Compare November 24, 2024 08:37
rhansen changed the title gh-127124: Add opaque pointer to context watcher callback gh-127124: Pass optional state to context watcher callback Nov 24, 2024

rhansen left a comment •
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'll open a separate PR for the callable idea I mentioned in #127124 (comment) so that we can compare the two and decide which we like better.

Edit: Done; see #127247.

PyContext_WatchCallback context_watchers[CONTEXT_MAX_WATCHERS];
struct {
PyContext_WatchCallback *callback;
PyObject *arg;

rhansen Nov 24, 2024 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Does this need a Py_VISIT somewhere? I didn't see any for the other fields in this struct, but maybe the GC does something special with this struct?

This enables users to associate state with the callback without
relying on globals.

Also:
  * Refactor the tests for improved readability and extensibility, and
    to cover the new state object.
  * Drop the pointer from the `PyContext_WatchCallback` typedef.  This
    de-obfuscates the fact that pointers are involved, and makes it
    possible to forward-declare functions to improve readability:

        static PyContext_WatchCallback my_callback;

        int
        my_callback(PyObject *cbarg, PyContextEvent event, PyObject *obj)
        {
            ...
        }
rhansen force-pushed the gh-127124-context-watcher-opaque-state branch from 3130a2f to c9e95d4 Compare November 24, 2024 09:16

Copy link
Copy Markdown
Member

FWIW, no need to force push changes--it makes reviewing harder. It's fine to just commit normally, and then everything gets squashed.

rhansen commented Nov 25, 2024

Copy link
Copy Markdown
Contributor Author

Force pushing is the only way to update the commit message.

Copy link
Copy Markdown
Member

Yes, but it makes reviewing more difficult. FWIW, nobody really cares about the commit messages in the PR itself, the end message that gets squashed is really what matters. (There's a section in the devguide about this, IIRC.)

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL