Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commentedJun 21, 2023
edited by github-actionsbot
Loading

Change the declaration of the keywords parameter in functions PyArg_ParseTupleAndKeywords() and PyArg_VaParseTupleAndKeywords() fromchar ** tochar * const * in C andconst char * const * in C++.

It makes these functions compatible with argument of typeconst char * const *,const char ** orchar * const * in C++ andchar * const * in C without explicit type cast.


📚 Documentation preview 📚:https://cpython-previews--105958.org.readthedocs.build/

arhadthedev and lpsinger reacted with thumbs up emoji
Change the declaration of the keywords parameter in functionsPyArg_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 Cwithout explicit type cast.

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`
Copy link
Member

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 in3.13.rst and the CI.

Copy link
MemberAuthor

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@CAM-Gerlach Any suggestions?

Copy link
Member

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 Functions subsection):

..macro::PY_CXX_CONST   The value to be inserted, if any, before:c:expr:`char * const *`   in the *keywords* parameter declaration of:c:func:`PyArg_ParseTupleAndKeywords`   and:c:func:`PyArg_VaParseTupleAndKeywords`.   Default empty for C and ``const`` for C++ (:c:expr:`const char * const *`).   To override, define it to the desired value before including:file:`Python.h`.   ..versionadded::3.13

You can then simplify thisnote accordingly, per my other suggestion (in a separate comment).

@@ -433,7 +433,7 @@ New Features
: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.
This can be overridden by defining the macro:c:macro:`PY_CXX_CONST`
This can be overridden by defining the macro``PY_CXX_CONST``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can we use this?

Suggested change
This can be overridden by defining the macro``PY_CXX_CONST``
This can be overridden by defining the macro:c:macro:`!PY_CXX_CONST`

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, both:c:macro:`!PY_CXX_CONST` and``PY_CXX_CONST`` would work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

To note, while they both silence the warning, they have different semantics in the source and rendering in the output.

However, with the changes suggested above, it is a moot point as you can link this and also simplify this What's New entry by referring readers to the macro description, which explains this (instead of duplicating the explanation here).


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`
Copy link
Member

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 Functions subsection):

..macro::PY_CXX_CONST   The value to be inserted, if any, before:c:expr:`char * const *`   in the *keywords* parameter declaration of:c:func:`PyArg_ParseTupleAndKeywords`   and:c:func:`PyArg_VaParseTupleAndKeywords`.   Default empty for C and ``const`` for C++ (:c:expr:`const char * const *`).   To override, define it to the desired value before including:file:`Python.h`.   ..versionadded::3.13

You can then simplify thisnote accordingly, per my other suggestion (in a separate comment).

Comment on lines 426 to 428
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
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.
This can be overridden with the:c:macro:`PY_CXX_CONST` macro.

Refer to the newly-added macro's documentation instead of needing to repeat these details here.

@@ -433,7 +433,7 @@ New Features
: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.
This can be overridden by defining the macro:c:macro:`PY_CXX_CONST`
This can be overridden by defining the macro``PY_CXX_CONST``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

To note, while they both silence the warning, they have different semantics in the source and rendering in the output.

However, with the changes suggested above, it is a moot point as you can link this and also simplify this What's New entry by referring readers to the macro description, which explains this (instead of duplicating the explanation here).

Comment on lines 436 to 438
This can be overridden by defining the macro ``PY_CXX_CONST``
before including :file:`Python.h` as ``const`` for the latter and as
empty value for the former.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
This can be overridden by defining the macro ``PY_CXX_CONST``
before including:file:`Python.h` as ``const`` for the latter and as
empty value for the former.
This can be overridden with the:c:macro:`PY_CXX_CONST` macro.

Now that this is documented, simply refer interested readers here directly instead of duplicating the whole explanation.

* 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
It makes these functions compatible withargument of type
It makes these functions compatible witharguments of type

Fix grammar error

It makes these functions compatible with argument of type
: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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
without explicit type cast.
withoutanexplicit type cast.

Fix grammar error

@CAM-Gerlach
Copy link
Member

Standard reminder: You can directly apply all the suggestions you want in one go by going toFiles changed -> ClickingAdd to batch on each suggestion -> When done, clickingCommit.

@serhiy-storchakaserhiy-storchakaforce-pushed thePyArg_ParseTupleAndKeywords-const branch from4ff9e8f to0e4dc59CompareDecember 1, 2023 10:06
@serhiy-storchaka
Copy link
MemberAuthor

@CAM-Gerlach Thank you, I applied all your suggestions.

@serhiy-storchakaserhiy-storchaka merged commitda6760b intopython:mainDec 4, 2023
@serhiy-storchakaserhiy-storchaka deleted the PyArg_ParseTupleAndKeywords-const branchDecember 4, 2023 11:15
aisk pushed a commit to aisk/cpython that referenced this pull requestFeb 11, 2024
…() (pythonGH-105958)Change the declaration of the keywords parameter in functionsPyArg_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 Cwithout explicit type cast.Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Glyphack pushed a commit to Glyphack/cpython that referenced this pull requestSep 2, 2024
…() (pythonGH-105958)Change the declaration of the keywords parameter in functionsPyArg_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 Cwithout explicit type cast.Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@hugovkhugovkhugovk left review comments

@arhadthedevarhadthedevarhadthedev left review comments

@CAM-GerlachCAM-GerlachCAM-Gerlach left review comments

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@serhiy-storchaka@CAM-Gerlach@hugovk@arhadthedev@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp