Skip to content

Commit 2f9fc90

Browse files
Yashp002encukouvstinner
authored andcommitted
gh-141004: Document symbol visibility macros (PyAPI_DATA, Py_EXPORTED_SYMBOL, Py_LOCAL_SYMBOL,Py_IMPORTED_SYMBOL) (GH-143508)
(cherry picked from commit a7ba3b1) Co-authored-by: Yashraj <yashrajpala8@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent b739bd1 commit 2f9fc90

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

Doc/c-api/intro.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ complete listing.
194194
Equivalent to :c:macro:`Py_LOCAL` but additionally requests the function
195195
be inlined.
196196

197+
.. c:macro:: Py_LOCAL_SYMBOL
198+
199+
Macro used to declare a symbol as local to the shared library (hidden).
200+
On supported platforms, it ensures the symbol is not exported.
201+
202+
On compatible versions of GCC/Clang, it
203+
expands to ``__attribute__((visibility("hidden")))``.
204+
197205
.. c:macro:: Py_MAX(x, y)
198206
199207
Return the maximum value between ``x`` and ``y``.
@@ -340,6 +348,38 @@ complete listing.
340348
sizeof(array) / sizeof((array)[0])
341349

342350

351+
.. c:macro:: Py_EXPORTED_SYMBOL
352+
353+
Macro used to declare a symbol (function or data) as exported.
354+
On Windows, this expands to ``__declspec(dllexport)``.
355+
On compatible versions of GCC/Clang, it
356+
expands to ``__attribute__((visibility("default")))``.
357+
This macro is for defining the C API itself; extension modules should not use it.
358+
359+
360+
.. c:macro:: Py_IMPORTED_SYMBOL
361+
362+
Macro used to declare a symbol as imported.
363+
On Windows, this expands to ``__declspec(dllimport)``.
364+
This macro is for defining the C API itself; extension modules should not use it.
365+
366+
367+
.. c:macro:: PyAPI_FUNC(type)
368+
369+
Macro used by CPython to declare a function as part of the C API.
370+
Its expansion depends on the platform and build configuration.
371+
This macro is intended for defining CPython's C API itself;
372+
extension modules should not use it for their own symbols.
373+
374+
375+
.. c:macro:: PyAPI_DATA(type)
376+
377+
Macro used by CPython to declare a public global variable as part of the C API.
378+
Its expansion depends on the platform and build configuration.
379+
This macro is intended for defining CPython's C API itself;
380+
extension modules should not use it for their own symbols.
381+
382+
343383
.. _api-objects:
344384

345385
Objects, Types and Reference Counts

Tools/check-c-api-docs/ignored_c_api.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ Py_HasFileSystemDefaultEncoding
1818
Py_UTF8Mode
1919
# pyhash.h
2020
Py_HASH_EXTERNAL
21-
# exports.h
22-
PyAPI_DATA
23-
Py_EXPORTED_SYMBOL
24-
Py_IMPORTED_SYMBOL
25-
Py_LOCAL_SYMBOL
2621
# modsupport.h
2722
PyABIInfo_FREETHREADING_AGNOSTIC
2823
# moduleobject.h

0 commit comments

Comments
 (0)