Skip to content

Commit a7ba3b1

Browse files
Yashp002encukouvstinner
authored
gh-141004: Document symbol visibility macros (PyAPI_DATA, Py_EXPORTED_SYMBOL, Py_LOCAL_SYMBOL,Py_IMPORTED_SYMBOL) (GH-143508)
Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 510ab7d commit a7ba3b1

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
@@ -222,6 +222,14 @@ complete listing.
222222
Equivalent to :c:macro:`Py_LOCAL` but additionally requests the function
223223
be inlined.
224224

225+
.. c:macro:: Py_LOCAL_SYMBOL
226+
227+
Macro used to declare a symbol as local to the shared library (hidden).
228+
On supported platforms, it ensures the symbol is not exported.
229+
230+
On compatible versions of GCC/Clang, it
231+
expands to ``__attribute__((visibility("hidden")))``.
232+
225233
.. c:macro:: Py_MAX(x, y)
226234
227235
Return the maximum value between ``x`` and ``y``.
@@ -376,6 +384,38 @@ complete listing.
376384
sizeof(array) / sizeof((array)[0])
377385

378386

387+
.. c:macro:: Py_EXPORTED_SYMBOL
388+
389+
Macro used to declare a symbol (function or data) as exported.
390+
On Windows, this expands to ``__declspec(dllexport)``.
391+
On compatible versions of GCC/Clang, it
392+
expands to ``__attribute__((visibility("default")))``.
393+
This macro is for defining the C API itself; extension modules should not use it.
394+
395+
396+
.. c:macro:: Py_IMPORTED_SYMBOL
397+
398+
Macro used to declare a symbol as imported.
399+
On Windows, this expands to ``__declspec(dllimport)``.
400+
This macro is for defining the C API itself; extension modules should not use it.
401+
402+
403+
.. c:macro:: PyAPI_FUNC(type)
404+
405+
Macro used by CPython to declare a function as part of the C API.
406+
Its expansion depends on the platform and build configuration.
407+
This macro is intended for defining CPython's C API itself;
408+
extension modules should not use it for their own symbols.
409+
410+
411+
.. c:macro:: PyAPI_DATA(type)
412+
413+
Macro used by CPython to declare a public global variable as part of the C API.
414+
Its expansion depends on the platform and build configuration.
415+
This macro is intended for defining CPython's C API itself;
416+
extension modules should not use it for their own symbols.
417+
418+
379419
.. _api-objects:
380420

381421
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)