Skip to content

gh-107298: Document doesn't link to PyAPI_DATA() #109236

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 2 commits into from
Sep 14, 2023

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Sep 10, 2023

Remove links to PyAPI_FUNC() and PyAPI_DATA() macros since they are
not documented. These macros should only be used to define the Python
C API. They should not be used outside Python code base.

Document PyMODINIT_FUNC macro.


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

@vstinner
Copy link
Member Author

cc @hugovk @serhiy-storchaka

Copy link
Member Author

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Oh! There is still a warning in Doc/whatsnew/2.3.rst: c:macro reference target not found: PyMODINIT_FUNC.

I will fix it.

@vstinner vstinner force-pushed the doc_pyapi_func_no_link branch from cbd269f to 553fdd0 Compare September 11, 2023 20:58
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

PyMODINIT_FUNC is purposed to be used in the user code. It is even used in examples.

@vstinner vstinner force-pushed the doc_pyapi_func_no_link branch from 553fdd0 to 5eba491 Compare September 11, 2023 21:20
@vstinner
Copy link
Member Author

PyMODINIT_FUNC is purposed to be used in the user code. It is even used in examples.

Oh right.

I fixed my PR:

  • Document PyMODINIT_FUNC.
  • Remove links to PyAPI_FUNC() and PyAPI_DATA().

Please review it again.

@hugovk: I added "the" in the added doc ;-)

@vstinner vstinner force-pushed the doc_pyapi_func_no_link branch from 5eba491 to 5847580 Compare September 11, 2023 21:21
Comment on lines 111 to 112
type is :c:expr:`PyObject*`. The macro should only be used in the Python C
API.
Copy link
Member

Choose a reason for hiding this comment

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

"The macro should only be used in the Python C API." -- I think that it is wrong.

This description is not clear, and does not help. The use of PyMODINIT_FUNC is actually described in Doc/extending/extending.rst:

This structure, in turn, must be passed to the interpreter in the module's
initialization function.  The initialization function must be named
:c:func:`!PyInit_name`, where *name* is the name of the module, and should be the
only non-\ ``static`` item defined in the module file::

   PyMODINIT_FUNC
   PyInit_spam(void)
   {
       return PyModule_Create(&spammodule);
   }

Note that :c:macro:`PyMODINIT_FUNC` declares the function as ``PyObject *`` return type,
declares any special linkage declarations required by the platform, and for C++
declares the function as ``extern "C"``.

It would be better if PyMODINIT_FUNC links would refer to that text. Or at least make a reference to it from the declaration in Doc/c-api/intro.rst.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I copied this doc to Doc/c-api/intro.rst.

@vstinner
Copy link
Member Author

@serhiy-storchaka: I completed PyMODINIT_FUNC doc. Would you mind to review my doc change again?

@vstinner
Copy link
Member Author

Oops sorry, I tested a Git tool and it messed up my PR :-( I fixed my PR.

declarations required by the platform, and for C++ declares the function as
``extern "C"``.

The initialization function must be named :c:func:`!PyInit_name`, where
Copy link
Member

Choose a reason for hiding this comment

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

Maybe write :samp:`PyInit_{name}`? It renders the whole name as a code, but name additionally is in italic, as a variable part.

Copy link
Member Author

Choose a reason for hiding this comment

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

I never saw :samp:, let me try.

Copy link
Member Author

Choose a reason for hiding this comment

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

@vstinner vstinner merged commit d7a27e5 into python:main Sep 14, 2023
@vstinner vstinner deleted the doc_pyapi_func_no_link branch September 14, 2023 12:56
@vstinner
Copy link
Member Author

Merged, thanks for the review @serhiy-storchaka.

@vstinner
Copy link
Member Author

Merged, thanks for the review @serhiy-storchaka.

Oh, and thanks @hugovk for the review as well :-)

@vstinner vstinner added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Sep 27, 2023
@miss-islington
Copy link
Contributor

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @vstinner, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker d7a27e527d7e669d2e45cff80ad725978226477c 3.11

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 27, 2023
Document PyMODINIT_FUNC macro.

Remove links to PyAPI_FUNC() and PyAPI_DATA() macros since they are
not documented. These macros should only be used to define the Python
C API. They should not be used outside Python code base.
(cherry picked from commit d7a27e5)

Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app
Copy link

bedevere-app bot commented Sep 27, 2023

GH-109947 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Sep 27, 2023
@bedevere-app
Copy link

bedevere-app bot commented Sep 27, 2023

GH-109948 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.11 only security fixes label Sep 27, 2023
vstinner added a commit that referenced this pull request Sep 27, 2023
gh-107298: Document PyMODINIT_FUNC macro (#109236)

Document PyMODINIT_FUNC macro.

Remove links to PyAPI_FUNC() and PyAPI_DATA() macros since they are
not documented. These macros should only be used to define the Python
C API. They should not be used outside Python code base.

(cherry picked from commit d7a27e5)
Yhg1s pushed a commit that referenced this pull request Sep 27, 2023
gh-107298: Document PyMODINIT_FUNC macro (GH-109236)

Document PyMODINIT_FUNC macro.

Remove links to PyAPI_FUNC() and PyAPI_DATA() macros since they are
not documented. These macros should only be used to define the Python
C API. They should not be used outside Python code base.
(cherry picked from commit d7a27e5)

Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants