-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-141070: Add PyUnstable_Object_Dump() function #141072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* Promote _PyObject_Dump() as a public function. * Keep _PyObject_Dump() alias to PyObject_Dump() for backward compatibility. * Replace _PyObject_Dump() with PyObject_Dump().
|
The tests seem to be failing on Windows. |
Ah yes, |
ZeroIntensity
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a few English nitpicks on the docs.
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
|
I think this is a great candidate for unstable API. |
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
|
I created a C API Working Group decision issue. |
|
Hm, @encukou, why make this an unstable API? I don't think we ever plan to remove the ability to print objects from the C API. If you're concerned about people relying on the exact output, we can just tell them "don't do that" in the docs. |
That we don't, but Or is there a use case where you call this from a releasable extension? |
Absolutely, we do it ourselves. It's a convenient debugging tool, but it's also quite handy as a last-ditch effort to display something to the user, like with I think as long as we specify the function as "dump non-specific debugging information about an object", it should be fine to add it as a non-unstable API. If we do add it to |
|
|
||
| * Add a new :c:func:`PyImport_CreateModuleFromInitfunc` C-API for creating | ||
| a module from a *spec* and *initfunc*. | ||
| (Contributed by Itamar Oren in :gh:`116146`.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Entries should be sorted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know that. What's the sort key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Sorted alphabetically". @hugovk added comments like that in the What's New document:
.. Add C API deprecations above alphabetically, not here at the end.
We should add a similar comment for C API "New features". I think that it was @AA-Turner who started to sort items in What's New In Python 3.14.
|
I renamed the function to |
That's debugging helper. Unstable API is great for those :)
There's a bunch of unstable API like that -- I think some people would be sad to |
|
@ZeroIntensity: I prefer the |
| _PyObject_Dump(PyObject* op) | ||
| PyUnstable_Object_Dump(PyObject* op) | ||
| { | ||
| if (_PyObject_IsFreed(op)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a special case for op == NULL?
And for type == NULL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It displays freed in both cases. There is now an unit test for that.
How do you suggest to format op==NULL and/or type==NULL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is already tested, then good. I was not sure that _PyObject_IsFreed() works with NULL (it could crash).
If type==NULL (very unlikely), then type->tp_name and repr() will crash. They will also crash if type was freed or if it is just a garbage. We could skip prints in that case avoid crash, although it may be too late.
Looking at the code, it seems the ideas I had (testing against the patterns used to fill the freed memory) was already implemented in _PyMem_IsPtrFreed().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If type==NULL (very unlikely), then type->tp_name and repr() will crash
_PyObject_IsFreed() checks _PyMem_IsPtrFreed(Py_TYPE(op)). We just display freed in this case, without displaying tp_name or trying to call repr().
What's the point of an unstable API that we can't remove? |
📚 Documentation preview 📚: https://cpython-previews--141072.org.readthedocs.build/