Skip to content

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

Merged
vstinner merged 2 commits into
python:mainfrom
vstinner:doc_pyapi_func_no_link
Sep 14, 2023
Merged

vstinner merged 2 commits into
python:mainfrom
vstinner:doc_pyapi_func_no_link

Conversation

@vstinner

@vstinner vstinner commented Sep 10, 2023 •

Copy link
Copy Markdown
Member

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
Copy Markdown
Member Author

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member Author

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

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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 thread Doc/c-api/intro.rst Outdated
Comment on lines +111 to +112
type is :c:expr:`PyObject*`. The macro should only be used in the Python C
API.

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

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

@vstinner

Copy link
Copy Markdown
Member Author

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

Comment thread Doc/c-api/intro.rst Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

Merged, thanks for the review @serhiy-storchaka.

@vstinner

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

@miss-islington

Copy link
Copy Markdown
Contributor

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

@miss-islington

Copy link
Copy Markdown
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

bedevere-app Bot commented Sep 27, 2023

Copy link
Copy Markdown

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

bedevere-app Bot commented Sep 27, 2023

Copy link
Copy Markdown

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

5 participants