-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bpo-42327: Add PyModule_Add() (smaller). #23443
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
Changes from all commits
26e6d1c
1dca02c
5adebfe
37ff11b
952015c
2da12b0
4ecdbe9
eac1730
9dc8cac
5be0f6a
f33c54a
fdc7ece
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -23,12 +23,18 @@ PyAPI_FUNC(PyObject *) Py_BuildValue(const char *, ...); | |||||
PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list); | ||||||
|
||||||
// Add an attribute with name 'name' and value 'obj' to the module 'mod. | ||||||
// On success, return 0 on success. | ||||||
// On success, return 0. | ||||||
// On error, raise an exception and return -1. | ||||||
PyAPI_FUNC(int) PyModule_AddObjectRef(PyObject *mod, const char *name, PyObject *value); | ||||||
|
||||||
// Similar to PyModule_AddObjectRef() but steal a reference to 'obj' | ||||||
// (Py_DECREF(obj)) on success (if it returns 0). | ||||||
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000 | ||||||
// Similar to PyModule_AddObjectRef() but steal a reference to 'value'. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to add "and value can be NULL". |
||||||
PyAPI_FUNC(int) PyModule_Add(PyObject *mod, const char *name, PyObject *value); | ||||||
#endif /* Py_LIMITED_API */ | ||||||
|
||||||
// Similar to PyModule_AddObjectRef() and PyModule_Add() but steal | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not similar to PyModule_AddObjectRef(): value can be NULL.
Suggested change
|
||||||
// a reference to 'value' on success and only on success. | ||||||
// Errorprone. Should not be used in new code. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO it's important important to put it in the documentation. This kind of definition fits perfectly with the Soft Deprecated status. Maybe also soft deprecate this API, similar to getopt and optparse soft deprecation. Example with getopt:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you suggest to convert the |
||||||
PyAPI_FUNC(int) PyModule_AddObject(PyObject *mod, const char *, PyObject *value); | ||||||
|
||||||
PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long); | ||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add :func:`PyModule_Add` function: similar to :c:func:`PyModule_AddObjectRef` and :c:func:`PyModule_AddObject`, but always steals a reference to the value. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
PyModule_AddObjectRef() must not be called with NULL. Can you please elaborate the behavior when value is NULL? Something like:
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.
PyModule_AddObjectRef()
can be called with NULL if an exception is set. Actually, some of my fixes which usePyModule_AddObjectRef()
rely on this.