GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — bpo-28254: Add a C-API for controlling the state of the garbage collector by scoder · Pull Request #25687 · python/cpython Conversation
|
|
Looks good, I will review it in more detail today, but please, add an entry to the what's new document for 3.10 in the meantime. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
…ions to make it easy for users to ('atomically') know whether they actually changed something and what state to go back to later. Also, returning an "int" may make it easier to add error handling later, if that becomes needed at some point.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thanks for the PR @scoder! Make sure to merge it before end of the week 😉 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I changed the functions to return the previous state. That's a common idiom in C, and I think a useful one in this case. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| int old_state; | ||
|
|
||
| old_state = PyGC_Enable(); | ||
| msg = "Enable(1)"; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Bugs are unlikely. IMO using assert() is good enough for _testcapi tests. You can leave the code as it is ;-)
See for example test_refcount_funcs() which uses assert().
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that assertions can be compiled out, which is decidedly not intended here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
In general yes, but _testcapimodule.c starts with:
/* Always enable assertions */
#undef NDEBUG
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Good to know! I'd keep the test as it is though. It doesn't really hurt, I think.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Are the C functions prototypes defined in the right place? Limited API, header file hierarchy, etc.? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
… gc.collect() implementation).
…othing if GC is disabled.
You added them to the stable ABI and so you should run "regen-limited-abi". |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
That added more than the three. I only committed the ones I added here in order to keep the PR clean. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| If the garbage collector is disabled or already running, | ||
| returns ``0`` immediately. | ||
| Errors during garbage collection are ignored and printed. | ||
| This function does not raise exceptions. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@pablogsal: Do we want to document that it's safe to call this function with an exception raised, and that the exception is saved and then restored?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| .. c:function:: Py_ssize_t PyGC_Collect(void) | ||
|
|
||
| Performs a garbage collection, if the garbage collector is enabled. | ||
| Returns the number of collected + uncollectable objects. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Hum, uncollectable objects are stored in gc.garbage no? Shoud we document that?
The C code uses "unreachable objects that couldn't be collected" in a comment instead of "uncollectable objects". Maybe it's a more explicit definition.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I don't think this C-API function is the right place to document these details. That's what the gc module is for.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Right, thanks: https://bugs.python.org/issue43795#msg392212 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Victor Stinner <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM but please fix the Sphinx markup.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| Returns the previous state, 0 for disabled and 1 for enabled. | ||
|
|
||
| .. versionchanged:: 3.10 | ||
| .. versionadded:: 3.10 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please fix also the indentation.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Merged, thanks @scoder! I'm not really excited by adding a C API for each Python function, but this one seems common enough to justify adding an API. Also, @pablogsal liked the idea ;-) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The GC gods we all serve are pleased with the new API ;) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks Victor and Pablo! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I created PR #25693 which shows how useful are these new C API functions ;-) Ok, maybe, it makes the C code a little bit simpler ;-) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
35 lines added, 116 lines saved. Seems a good deal. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
FYI, this has broken CI |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Yes, this adds things to From now on, CI will be fail on the pull request when issues like this happen, but this one's timing was unfortunate. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ok, then let's merge #25720 to unblock this |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.