Skip to content

Conversation

@Yashp002
Copy link
Contributor

@Yashp002 Yashp002 commented Jan 7, 2026

This PR documents several symbol visibility macros that were identified as undocumented in issue #141004. These macros are defined in Include/exports.h and are used to control symbol visibility and linkage (dllexport/dllimport) across platforms.

Macros documented in Doc/c-api/intro.rst:

  • Py_EXPORTED_SYMBOL
  • Py_IMPORTED_SYMBOL
  • Py_LOCAL_SYMBOL
  • PyAPI_DATA

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

@bedevere-app bedevere-app bot added docs Documentation in the Doc dir skip news labels Jan 7, 2026
@github-project-automation github-project-automation bot moved this to Todo in Docs PRs Jan 7, 2026
PyAPI_DATA(PyObject *) _Py_NoneStruct;


.. c:macro:: Py_LOCAL_SYMBOL
Copy link
Member

Choose a reason for hiding this comment

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

Could you move this next to the other Py_LOCAL macros, and ideally match their style?

Copy link
Member

Choose a reason for hiding this comment

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

I guess Py_ALWAYS_INLINE, Py_DEPRECATED, Py_LOCAL, Py_LOCAL_INLINE, all of these, and possibly Py_UNUSED, could be moved to a new section. But that can be in a new PR.

On other platforms, it is usually empty or standard visibility.


.. c:macro:: PyAPI_DATA(type)
Copy link
Member

Choose a reason for hiding this comment

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

If we document this, we should also document PyAPI_FUNC.
Again, this is for defining the C API itself; users shouldn't use it for their own data.

Copy link
Member

Choose a reason for hiding this comment

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

This should be similar to the docs for PyAPI_FUNC.

Comment on lines 379 to 391
.. c:macro:: Py_EXPORTED_SYMBOL
Macro used to declare a symbol (function or data) as exported from a shared library.
On Windows, this expands to ``__declspec(dllexport)``.
On other platforms with visibility support, it
expands to ``__attribute__((visibility("default")))``.


.. c:macro:: Py_IMPORTED_SYMBOL
Macro used to declare a symbol as imported from a shared library.
On Windows, this expands to ``__declspec(dllimport)``.
On other platforms, it is usually empty or standard visibility.
Copy link
Member

Choose a reason for hiding this comment

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

“from a shared library” is not true: these depend on whether CPython's own C API is provided as a shared library.

The docs should say that these are for defining the C API itself; users shouldn't use them for their own symbols.

@ZeroIntensity ZeroIntensity added topic-C-API needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jan 7, 2026
@Yashp002
Copy link
Contributor Author

Yashp002 commented Jan 7, 2026

@encukou I think I've done all the necessary changes you asked for, could you verify it.

Comment on lines +228 to +230
It ensures the symbol is not exported.
On platforms with visibility support, it
expands to ``__attribute__((visibility("hidden")))``.
Copy link
Member

Choose a reason for hiding this comment

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

This is platform-specific, and not really guaranteed everywhere.

Suggested change
It ensures the symbol is not exported.
On platforms with visibility support, it
expands to ``__attribute__((visibility("hidden")))``.
On supported platforms, it ensures the symbol is not exported.
On compatible versions of GCC/Clang, it
expands to ``__attribute__((visibility("hidden")))``.

Macro used to declare a symbol (function or data) as exported.
On Windows, this expands to ``__declspec(dllexport)``.
On other platforms with visibility support, it
Copy link
Member

Choose a reason for hiding this comment

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

Not sure what you mean “platforms with visibility support”. Would it work to mention the compiler directly?

Suggested change
On other platforms with visibility support, it
On compatible versions of GCC/Clang, it

(same below)

Macro used to declare a symbol as imported.
On Windows, this expands to ``__declspec(dllimport)``.
On other platforms, it is usually empty or standard visibility.
Copy link
Member

Choose a reason for hiding this comment

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

I think we can remove this.

Suggested change
On other platforms, it is usually empty or standard visibility.

As I see it, the main reason for the expansions is so that the reader can look up the behaviour in compiler docs.

Macro used by CPython to declare a function as part of the C API.
Its expansion depends on the platform and build configuration.
This macro is intended for defining CPython's C API itself;
extension modulesshould not use it for their own symbols.
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
extension modulesshould not use it for their own symbols.
extension modules should not use it for their own symbols.

On other platforms, it is usually empty or standard visibility.


.. c:macro:: PyAPI_DATA(type)
Copy link
Member

Choose a reason for hiding this comment

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

This should be similar to the docs for PyAPI_FUNC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes skip news topic-C-API

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants