From 1cfd6837e6d580ac62d4fa860b32bdd79743c48d Mon Sep 17 00:00:00 2001 From: Yash Date: Wed, 7 Jan 2026 12:46:31 +0530 Subject: [PATCH 01/11] first exports --- Doc/c-api/intro.rst | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index 5e90d9b7bc91ed..7716641de68388 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -376,6 +376,39 @@ complete listing. sizeof(array) / sizeof((array)[0]) +.. 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. + + +.. c:macro:: PyAPI_DATA(type) + + Macro used to declare a public global variable. + It expands to ``extern Py_EXPORTED_SYMBOL type`` or ``extern Py_IMPORTED_SYMBOL type`` + depending on whether the core is being built or used. + + Example usage:: + + PyAPI_DATA(PyObject *) _Py_NoneStruct; + + +.. c:macro:: Py_LOCAL_SYMBOL + + Macro used to declare a symbol as local to the shared library (hidden). + It ensures the symbol is not exported. + On platforms with visibility support, it + expands to ``__attribute__((visibility("hidden")))``. + .. _api-objects: Objects, Types and Reference Counts From 0164c79aa010c6354551c724d7df11887214b8a9 Mon Sep 17 00:00:00 2001 From: Yash Date: Wed, 7 Jan 2026 13:01:08 +0530 Subject: [PATCH 02/11] exports fix 1 --- Doc/c-api/intro.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index 7716641de68388..df6bd92b96c61b 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -381,7 +381,7 @@ complete listing. 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")))``. + expands to ``__attribute__((visibility("default")))``. .. c:macro:: Py_IMPORTED_SYMBOL @@ -399,7 +399,7 @@ complete listing. Example usage:: - PyAPI_DATA(PyObject *) _Py_NoneStruct; + PyAPI_DATA(PyObject *) _Py_NoneStruct; .. c:macro:: Py_LOCAL_SYMBOL @@ -407,8 +407,9 @@ complete listing. Macro used to declare a symbol as local to the shared library (hidden). It ensures the symbol is not exported. On platforms with visibility support, it - expands to ``__attribute__((visibility("hidden")))``. - + expands to ``__attribute__((visibility("hidden")))``. + + .. _api-objects: Objects, Types and Reference Counts From d0c5c25054e8b678d03a724dc5d218ee3e325c09 Mon Sep 17 00:00:00 2001 From: Yash Date: Thu, 8 Jan 2026 00:41:45 +0530 Subject: [PATCH 03/11] exports fix 2 --- Doc/c-api/intro.rst | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index df6bd92b96c61b..6596c45c7dd82a 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -222,6 +222,13 @@ complete listing. Equivalent to :c:macro:`Py_LOCAL` but additionally requests the function be inlined. +.. c:macro:: Py_LOCAL_SYMBOL + + Macro used to declare a symbol as local to the shared library (hidden). + It ensures the symbol is not exported. + On platforms with visibility support, it + expands to ``__attribute__((visibility("hidden")))``. + .. c:macro:: Py_MAX(x, y) Return the maximum value between ``x`` and ``y``. @@ -378,17 +385,27 @@ complete listing. .. c:macro:: Py_EXPORTED_SYMBOL - Macro used to declare a symbol (function or data) as exported from a shared library. + 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 expands to ``__attribute__((visibility("default")))``. + This macro is for defining the C API itself; extension modules should not use it. .. c:macro:: Py_IMPORTED_SYMBOL - Macro used to declare a symbol as imported from a shared library. + 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. + This macro is for defining the C API itself; extension modules should not use it. + + +.. c:macro:: PyAPI_FUNC(type) + + 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. .. c:macro:: PyAPI_DATA(type) @@ -402,14 +419,6 @@ complete listing. PyAPI_DATA(PyObject *) _Py_NoneStruct; -.. c:macro:: Py_LOCAL_SYMBOL - - Macro used to declare a symbol as local to the shared library (hidden). - It ensures the symbol is not exported. - On platforms with visibility support, it - expands to ``__attribute__((visibility("hidden")))``. - - .. _api-objects: Objects, Types and Reference Counts From d3e69b69c1c2ff296a26515ddd15a55ea930ddaa Mon Sep 17 00:00:00 2001 From: Yashraj Date: Thu, 8 Jan 2026 22:42:30 +0530 Subject: [PATCH 04/11] exports fix 3 Co-authored-by: Petr Viktorin --- Doc/c-api/intro.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index 6596c45c7dd82a..63eaf8c24664ba 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -225,8 +225,9 @@ complete listing. .. c:macro:: Py_LOCAL_SYMBOL Macro used to declare a symbol as local to the shared library (hidden). - It ensures the symbol is not exported. - On platforms with visibility support, it + On supported platforms, it ensures the symbol is not exported. + + On compatible versions of GCC/Clang, it expands to ``__attribute__((visibility("hidden")))``. .. c:macro:: Py_MAX(x, y) From 68269d34ac12ff862a1c5dfadf71e79ada8feaee Mon Sep 17 00:00:00 2001 From: Yashraj Date: Thu, 8 Jan 2026 22:43:03 +0530 Subject: [PATCH 05/11] exports fix 4 Co-authored-by: Petr Viktorin --- Doc/c-api/intro.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index 63eaf8c24664ba..e3a8f02b0674ad 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -388,7 +388,7 @@ complete listing. 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 + On compatible versions of GCC/Clang, it expands to ``__attribute__((visibility("default")))``. This macro is for defining the C API itself; extension modules should not use it. From 113ff5e15701621a80e25c0142f263578b76b70f Mon Sep 17 00:00:00 2001 From: Yashraj Date: Thu, 8 Jan 2026 22:43:19 +0530 Subject: [PATCH 06/11] exports fix 5 Co-authored-by: Petr Viktorin --- Doc/c-api/intro.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index e3a8f02b0674ad..b45a0c78fa9c3b 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -397,7 +397,6 @@ complete listing. 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. This macro is for defining the C API itself; extension modules should not use it. From 9eb597beede1326f3c1083da671347b91860b381 Mon Sep 17 00:00:00 2001 From: Yashraj Date: Thu, 8 Jan 2026 22:43:41 +0530 Subject: [PATCH 07/11] exports fix 6 Co-authored-by: Petr Viktorin --- Doc/c-api/intro.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index b45a0c78fa9c3b..de053bc511f81e 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -405,7 +405,7 @@ complete listing. 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. + extension modules should not use it for their own symbols. .. c:macro:: PyAPI_DATA(type) From 6b9df7f791b511eeee1233efae8a17b3402125c2 Mon Sep 17 00:00:00 2001 From: Yashraj Date: Thu, 8 Jan 2026 23:01:41 +0530 Subject: [PATCH 08/11] exports fix 7 Co-authored-by: Victor Stinner --- Doc/c-api/intro.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index de053bc511f81e..029c2b927f249d 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -416,7 +416,7 @@ complete listing. Example usage:: - PyAPI_DATA(PyObject *) _Py_NoneStruct; + PyAPI_DATA(const unsigned long) Py_Version; .. _api-objects: From 26cffa2676df9dec346ce7c70ac73fadd8195ca1 Mon Sep 17 00:00:00 2001 From: Yash Date: Thu, 8 Jan 2026 23:06:44 +0530 Subject: [PATCH 09/11] exports fix 8 --- Doc/c-api/intro.rst | 2 ++ Tools/check-c-api-docs/ignored_c_api.txt | 5 ----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index 029c2b927f249d..7d1bfee1087fd6 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -413,6 +413,8 @@ complete listing. Macro used to declare a public global variable. It expands to ``extern Py_EXPORTED_SYMBOL type`` or ``extern Py_IMPORTED_SYMBOL type`` depending on whether the core is being built or used. + This macro is intended for defining CPython's C API itself; + extension modules should not use it for their own symbols. Example usage:: diff --git a/Tools/check-c-api-docs/ignored_c_api.txt b/Tools/check-c-api-docs/ignored_c_api.txt index e81ffd51e193b2..c45849a93c3fb0 100644 --- a/Tools/check-c-api-docs/ignored_c_api.txt +++ b/Tools/check-c-api-docs/ignored_c_api.txt @@ -18,11 +18,6 @@ Py_HasFileSystemDefaultEncoding Py_UTF8Mode # pyhash.h Py_HASH_EXTERNAL -# exports.h -PyAPI_DATA -Py_EXPORTED_SYMBOL -Py_IMPORTED_SYMBOL -Py_LOCAL_SYMBOL # modsupport.h PyABIInfo_FREETHREADING_AGNOSTIC # moduleobject.h From 6c59e9b1df9a6deb130a37330a0166126d06cba9 Mon Sep 17 00:00:00 2001 From: Yashraj Date: Fri, 9 Jan 2026 16:43:55 +0530 Subject: [PATCH 10/11] exports fix 9 Co-authored-by: Petr Viktorin --- Doc/c-api/intro.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index 7d1bfee1087fd6..f08cc805947e0d 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -410,9 +410,8 @@ complete listing. .. c:macro:: PyAPI_DATA(type) - Macro used to declare a public global variable. - It expands to ``extern Py_EXPORTED_SYMBOL type`` or ``extern Py_IMPORTED_SYMBOL type`` - depending on whether the core is being built or used. + Macro used by CPython to declare a public global variable 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 modules should not use it for their own symbols. From 2f242416ad1182aaf7f3ab99b3daefd8385a37cf Mon Sep 17 00:00:00 2001 From: Yashraj Date: Fri, 9 Jan 2026 16:44:09 +0530 Subject: [PATCH 11/11] exports fix 10 Co-authored-by: Petr Viktorin --- Doc/c-api/intro.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index f08cc805947e0d..6886cd85b09a7d 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -415,10 +415,6 @@ complete listing. This macro is intended for defining CPython's C API itself; extension modules should not use it for their own symbols. - Example usage:: - - PyAPI_DATA(const unsigned long) Py_Version; - .. _api-objects: