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
Changes from 5 commits
90ae263
4b08887
aef02b8
474a266
a005823
bb345d9
37b6b37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -222,7 +222,12 @@ with an exception object (leaving out the error checking for now):: | |
|
|
||
| SpamError = PyErr_NewException("spam.error", NULL, NULL); | ||
| Py_INCREF(SpamError); | ||
|
brandtbucher marked this conversation as resolved.
Outdated
|
||
| PyModule_AddObject(m, "error", SpamError); | ||
| if (PyModule_AddObject(m, "error", SpamError)) { | ||
|
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. I suggest to add also
Member
Author
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. 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...
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. Add the extra test with |
||
| Py_DECREF(SpamError); | ||
|
brandtbucher marked this conversation as resolved.
Outdated
|
||
| Py_DECREF(m); | ||
| return NULL; | ||
| } | ||
|
|
||
| return m; | ||
| } | ||
|
|
||
|
|
@@ -1261,8 +1266,17 @@ 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) | ||
| PyModule_AddObject(m, "_C_API", c_api_object); | ||
| if (c_api_object == NULL) { | ||
|
brandtbucher marked this conversation as resolved.
Outdated
|
||
| 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_DECREF(m); | ||
| return NULL; | ||
| } | ||
|
|
||
| return m; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,7 +179,12 @@ This initializes the :class:`Custom` type, filling in a number of members | |
| to the appropriate default values, including :attr:`ob_type` that we initially | ||
| set to *NULL*. :: | ||
|
|
||
| PyModule_AddObject(m, "Custom", (PyObject *) &CustomType); | ||
| Py_INCREF(&CustomType); | ||
| if (PyModule_AddObject(m, "Custom", (PyObject *) &CustomType)) { | ||
|
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(&CustomType); | ||
| PY_DECREF(m); | ||
| return NULL; | ||
| } | ||
|
|
||
| This adds the type to the module dictionary. This allows us to create | ||
| :class:`Custom` instances by calling the :class:`Custom` class: | ||
|
|
@@ -864,7 +869,12 @@ function:: | |
| return NULL; | ||
|
|
||
| Py_INCREF(&SubListType); | ||
| PyModule_AddObject(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; | ||
| } | ||
|
|
||
| return m; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,11 @@ PyInit_custom(void) | |
| return NULL; | ||
|
|
||
| Py_INCREF(&CustomType); | ||
| PyModule_AddObject(m, "Custom", (PyObject *) &CustomType); | ||
| if (PyModule_AddObject(m, "Custom", (PyObject *) &CustomType)) { | ||
|
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(&CustomType); | ||
| PY_DECREF(m); | ||
| return NULL; | ||
| } | ||
|
|
||
| return m; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,6 +128,11 @@ PyInit_custom2(void) | |
| return NULL; | ||
|
|
||
| Py_INCREF(&CustomType); | ||
| PyModule_AddObject(m, "Custom", (PyObject *) &CustomType); | ||
| if (PyModule_AddObject(m, "Custom", (PyObject *) &CustomType)) { | ||
|
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(&CustomType); | ||
| Py_DECREF(m); | ||
| return NULL; | ||
| } | ||
|
|
||
| return m; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,6 +179,11 @@ PyInit_custom3(void) | |
| return NULL; | ||
|
|
||
| Py_INCREF(&CustomType); | ||
| PyModule_AddObject(m, "Custom", (PyObject *) &CustomType); | ||
| if (PyModule_AddObject(m, "Custom", (PyObject *) &CustomType)) { | ||
|
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(&CustomType); | ||
| Py_DECREF(m); | ||
| return NULL; | ||
| } | ||
|
|
||
| return m; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -193,6 +193,11 @@ PyInit_custom4(void) | |
| return NULL; | ||
|
|
||
| Py_INCREF(&CustomType); | ||
| PyModule_AddObject(m, "Custom", (PyObject *) &CustomType); | ||
| if (PyModule_AddObject(m, "Custom", (PyObject *) &CustomType)) { | ||
|
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(&CustomType); | ||
| Py_DECREF(m); | ||
| return NULL; | ||
| } | ||
|
|
||
| return m; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix example usage of :c:func:`PyModule_AddObject` to properly handle errors. |
Uh oh!
There was an error while loading. Please reload this page.