Repository navigation
bpo-26868: Fix example usage of PyModule_AddObject. #15725
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
90ae263
Add a note to the PyModule_AddObject docs.
brandtbucher 4b08887
Correct example usages of PyModule_AddObject.
brandtbucher aef02b8
Whitespace.
brandtbucher 474a266
Clean up wording.
brandtbucher a005823
📜🤖 Added by blurb_it.
blurb-it[bot] bb345d9
First code review.
brandtbucher 37b6b37
Add < 0 in the tests with PyModule_AddObject
matrixise File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
First code review.
- Loading branch information
commit bb345d994148c7626ad19dd045045ce1469882b0
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -209,7 +209,7 @@ usually declare a static object variable at the beginning of your file:: | |
| static PyObject *SpamError; | ||
|
|
||
| and initialize it in your module's initialization function (:c:func:`PyInit_spam`) | ||
| with an exception object (leaving out the error checking for now):: | ||
| with an exception object:: | ||
|
|
||
| PyMODINIT_FUNC | ||
| PyInit_spam(void) | ||
|
|
@@ -221,9 +221,10 @@ with an exception object (leaving out the error checking for now):: | |
| return NULL; | ||
|
|
||
| SpamError = PyErr_NewException("spam.error", NULL, NULL); | ||
| Py_INCREF(SpamError); | ||
| Py_XINCREF(SpamError); | ||
| if (PyModule_AddObject(m, "error", SpamError)) { | ||
| Py_DECREF(SpamError); | ||
| Py_XDECREF(SpamError); | ||
| Py_CLEAR(SpamError); | ||
| Py_DECREF(m); | ||
| return NULL; | ||
| } | ||
|
|
@@ -1266,13 +1267,8 @@ function must take care of initializing the C API pointer array:: | |
| /* Create a Capsule containing the API pointer array's address */ | ||
| c_api_object = PyCapsule_New((void *)PySpam_API, "spam._C_API", NULL); | ||
|
|
||
| if (c_api_object == NULL) { | ||
| Py_DECREF(m); | ||
| return NULL; | ||
| } | ||
|
|
||
| if (PyModule_AddObject(m, "_C_API", c_api_object)) { | ||
|
Member
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. ditto, change the example with |
||
| Py_DECREF(c_api_object); | ||
| Py_XDECREF(c_api_object); | ||
| Py_DECREF(m); | ||
| return NULL; | ||
| } | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,7 +59,7 @@ PyInit_sublist(void) | |
| return NULL; | ||
|
|
||
| Py_INCREF(&SubListType); | ||
| if ((m, "SubList", (PyObject *) &SubListType)) { | ||
| if (PyModule_AddObject(m, "SubList", (PyObject *) &SubListType)) { | ||
|
Member
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. ditto |
||
| Py_DECREF(&SubListType); | ||
| Py_DECREF(m); | ||
| return NULL; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 suggest to add also
< 0in all other checks forPyModule_AddObject()result.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.
Is this an agreed-upon style? I had always thought it was a matter of taste.
In either case, I guess all of these files should at least be consistent...
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.
Add the extra test with
< 0