-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-65210: Add const qualifiers in PyArg_VaParseTupleAndKeywords() #105958
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 1 commit
80e37a9
1340934
040817e
910c5d2
0e4dc59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Change the declaration of the keywords parameter in functions PyArg_ParseTupleAndKeywords() and PyArg_VaParseTupleAndKeywords() from `char **` to `char * const *` in C and `const char * const *` in C++. It makes these functions compatible with argument of type `const char * const *`, `const char **` or `char * const *` in C++ and `char * const *` in C without explicit type cast.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -410,7 +410,7 @@ API Functions | |||||||||
| than a variable number of arguments. | ||||||||||
|
|
||||||||||
|
|
||||||||||
| .. c:function:: int PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, char *keywords[], ...) | ||||||||||
| .. c:function:: int PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, /*const*/ char * const *keywords, ...) | ||||||||||
|
|
||||||||||
| Parse the parameters of a function that takes both positional and keyword | ||||||||||
| parameters into local variables. The *keywords* argument is a | ||||||||||
|
|
@@ -419,12 +419,24 @@ API Functions | |||||||||
| Returns true on success; on failure, it returns false and raises the | ||||||||||
| appropriate exception. | ||||||||||
|
|
||||||||||
| .. note:: | ||||||||||
|
|
||||||||||
| The *keywords* parameter declaration is :c:expr:`char * const *` in C and | ||||||||||
| :c:expr:`const char * const *` in C++. | ||||||||||
| This can be overridden by defining the macro :c:macro:`PY_CXX_CONST` | ||||||||||
| before including :file:`Python.h` as ``const`` for the latter and as | ||||||||||
| empty value for the former. | ||||||||||
|
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.
Suggested change
Refer to the newly-added macro's documentation instead of needing to repeat these details here. |
||||||||||
|
|
||||||||||
| .. versionchanged:: 3.6 | ||||||||||
| Added support for :ref:`positional-only parameters | ||||||||||
| <positional-only_parameter>`. | ||||||||||
|
|
||||||||||
| .. versionchanged:: 3.13 | ||||||||||
| The *keywords* parameter has now type :c:expr:`char * const *` in C and | ||||||||||
| :c:expr:`const char * const *` in C++, instead of :c:expr:`char **`. | ||||||||||
|
|
||||||||||
|
|
||||||||||
| .. c:function:: int PyArg_VaParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, char *keywords[], va_list vargs) | ||||||||||
| .. c:function:: int PyArg_VaParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, /*const*/ char * const *keywords, va_list vargs) | ||||||||||
|
|
||||||||||
| Identical to :c:func:`PyArg_ParseTupleAndKeywords`, except that it accepts a | ||||||||||
| va_list rather than a variable number of arguments. | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -426,6 +426,18 @@ New Features | |||||
| APIs accepting the format codes always use ``Py_ssize_t`` for ``#`` formats. | ||||||
| (Contributed by Inada Naoki in :gh:`104922`.) | ||||||
|
|
||||||
| * The *keywords* parameter of :c:func:`PyArg_ParseTupleAndKeywords` and | ||||||
| :c:func:`PyArg_VaParseTupleAndKeywords` has now type :c:expr:`char * const *` | ||||||
| in C and :c:expr:`const char * const *` in C++, instead of :c:expr:`char **`. | ||||||
| It makes these functions compatible with argument of type | ||||||
|
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.
Suggested change
Fix grammar error |
||||||
| :c:expr:`const char * const *`, :c:expr:`const char **` or | ||||||
| :c:expr:`char * const *` in C++ and :c:expr:`char * const *` in C | ||||||
| without explicit type cast. | ||||||
|
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.
Suggested change
Fix grammar error |
||||||
| This can be overridden by defining the macro :c:macro:`PY_CXX_CONST` | ||||||
| before including :file:`Python.h` as ``const`` for the latter and as | ||||||
| empty value for the former. | ||||||
| (Contributed by Serhiy Storchaka in :gh:`65210`.) | ||||||
|
|
||||||
| * Add :c:func:`PyImport_AddModuleRef`: similar to | ||||||
| :c:func:`PyImport_AddModule`, but return a :term:`strong reference` instead | ||||||
| of a :term:`borrowed reference`. | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Change the declaration of the *keywords* parameter of | ||
| :c:func:`PyArg_ParseTupleAndKeywords` and | ||
| :c:func:`PyArg_VaParseTupleAndKeywords` for better compatibility with C++. |
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.
Please document this new macro somewhere with
.. c:macro:: PY_CXX_CONST.That will fix this warning and the one in
3.13.rstand the CI.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 do not know how to document it better than I did. I will appreciate your suggestions. For now I just removed the role.
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.
@CAM-Gerlach Any suggestions?
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.
@serhiy-storchaka To properly document a public entity (macro, function, class, method, etc), you can use the the appropriate directive—in this case,
.. c:macro::as @hugovk mentioned. This could be something like (placed, perhaps, at the top or bottom of theAPI Functionssubsection):You can then simplify this
noteaccordingly, per my other suggestion (in a separate comment).