Skip to content

Commit

Permalink
Exclude pthread_stubs.h
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Jul 3, 2023
1 parent fe97e22 commit 1e8d6c4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 35 deletions.
38 changes: 26 additions & 12 deletions doc/pythoncapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,16 @@ def git_switch_branch(branch):
def list_files(path):
if not os.path.exists(path):
return []
return glob.glob(os.path.join(path, '*.h'))
files = glob.glob(os.path.join(path, '*.h'))
# Don't parse pthread_stubs.h: special header file used by WASM
for index, name in enumerate(files):
if os.path.basename(name) == 'pthread_stubs.h':
del files[index]
break
return files


def _get_types(filename, names):
if 'pthread_stubs.h' in filename:
# skip special header file used by WASM
return
if os.path.basename(filename) == 'pystats.h':
# skip Include/pystats.h which is code only used if Python is built
# with --enable-pystats (if the Py_STATS macro is defined)
Expand All @@ -105,16 +108,19 @@ def _get_types(filename, names):
struct_name = match.group(1)
match2 = RE_STRUCT_END.search(content, match.end())
if not match2:
raise Exception(f"cannot find end of: {filename}: {match.group()}")
raise Exception(f"{filename}: cannot find end of: {match.group()}")
name = match2.group(1)
if not name:
name = struct_name
if not name:
raise Exception(f"structure has no name: {filename}: {match.group()})")
raise Exception(f"{filename}: structure has no name: {match.group()})")
if name in TYPEDEFS:
name = TYPEDEFS[name]
names.add(name)

if 'pthread_mutex_t' in names:
raise Exception('pthread_stubs.h was parsed')


def get_types_path(directory):
names = set()
Expand Down Expand Up @@ -170,6 +176,10 @@ def get_macros_static_inline_funcs():
return (macros, funcs)


def is_function_public(name):
return name.startswith(('Py', 'PY'))


def get_functions():
regex = re.compile(
# 'PyAPI_FUNC(int) '
Expand All @@ -188,13 +198,17 @@ def get(path):
cpython = get(PATH_CPYTHON_API)
internal = get(PATH_INTERNAL_API)

for names in (limited, cpython, internal):
if 'pthread_create' in names:
raise Exception('pthread_stubs.h was parsed')

public = set()
private = set()
for name in limited | cpython:
if name.startswith('_Py'):
private.add(name)
else:
if is_function_public(name):
public.add(name)
else:
private.add(name)

return (public, private, internal)

Expand Down Expand Up @@ -255,10 +269,10 @@ def get(path):
public = set()
private = set()
for name in limited | cpython:
if name.startswith('_Py'):
private.add(name)
else:
if is_function_public(name):
public.add(name)
else:
private.add(name)

return (public, private, internal)

Expand Down
46 changes: 23 additions & 23 deletions doc/stats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Python Limited API CPython API Internal API Total
3.8.0 13,147 (70%) 3,418 (18%) 2,207 (12%) 18,772
3.9.0 12,243 (62%) 4,359 (22%) 3,084 (16%) 19,686
3.10.0 10,408 (51%) 4,584 (22%) 5,519 (27%) 20,511
3.11.0 9,232 (37%) 5,495 (22%) 10,047 (41%) 24,774
3.12 (dev) 9,598 (29%) 5,903 (18%) 17,631 (53%) 33,132
main (3.13) 9,344 (28%) 5,207 (16%) 18,556 (56%) 33,107
3.11.0 9,232 (37%) 5,407 (22%) 10,047 (41%) 24,686
3.12 (dev) 9,598 (29%) 5,815 (18%) 17,631 (53%) 33,044
main (3.13) 9,344 (28%) 5,050 (15%) 18,624 (56%) 33,018
=========== ============= =========== ============ ======

File Numbers
Expand All @@ -35,29 +35,29 @@ Python Limited API CPython API Internal API Total
3.8.0 97 (-2) 15 (+15) 21 (+10) 133 (+23)
3.9.0 98 (+1) 24 (+9) 33 (+12) 155 (+22)
3.10.0 81 (-17) 32 (+8) 48 (+15) 161 (+6)
3.11.0 72 (-9) 48 (+16) 68 (+20) 188 (+27)
3.12 (dev) 72 (same) 49 (+1) 91 (+23) 212 (+24)
main (3.13) 72 (same) 51 (+2) 95 (+4) 218 (+6)
3.11.0 72 (-9) 47 (+15) 68 (+20) 187 (+26)
3.12 (dev) 72 (same) 48 (+1) 91 (+23) 211 (+24)
main (3.13) 72 (same) 50 (+2) 95 (+4) 217 (+6)
=========== =========== =========== ============ =========

Functions
=========

Functions exported with PyAPI_FUNC():

=========== ========= ========== ========= ============
Python Public Private Internal Total
=========== ========= ========== ========= ============
2.7.0 748 150 0 898
3.6.0 847 (+99) 380 (+230) 0 (same) 1,227 (+329)
3.7.0 872 (+25) 448 (+68) 12 (+12) 1,332 (+105)
3.8.0 910 (+38) 429 (-19) 78 (+66) 1,417 (+85)
3.9.0 919 (+9) 412 (-17) 109 (+31) 1,440 (+23)
3.10.0 885 (-34) 412 (same) 115 (+6) 1,412 (-28)
3.11.0 914 (+29) 360 (-52) 176 (+61) 1,450 (+38)
3.12 (dev) 951 (+37) 385 (+25) 177 (+1) 1,513 (+63)
main (3.13) 935 (-16) 268 (-117) 236 (+59) 1,439 (-74)
=========== ========= ========== ========= ============
=========== ========== ========== ========= ============
Python Public Private Internal Total
=========== ========== ========== ========= ============
2.7.0 738 160 0 898
3.6.0 844 (+106) 383 (+223) 0 (same) 1,227 (+329)
3.7.0 869 (+25) 451 (+68) 12 (+12) 1,332 (+105)
3.8.0 909 (+40) 430 (-21) 78 (+66) 1,417 (+85)
3.9.0 919 (+10) 412 (-18) 109 (+31) 1,440 (+23)
3.10.0 885 (-34) 412 (same) 115 (+6) 1,412 (-28)
3.11.0 891 (+6) 360 (-52) 176 (+61) 1,427 (+15)
3.12 (dev) 928 (+37) 385 (+25) 177 (+1) 1,490 (+63)
main (3.13) 912 (-16) 259 (-126) 237 (+60) 1,408 (-82)
=========== ========== ========== ========= ============

Since Python 3.9, Python is now built with ``-fvisibility=hidden`` to avoid
exporting symbols which are not **explicitly** exported.
Expand All @@ -74,15 +74,15 @@ Symbols exported with PyAPI_DATA():
=========== ========== ======== ========= ==========
Python Public Private Internal Total
=========== ========== ======== ========= ==========
2.7.0 130 29 0 159
3.6.0 167 (+37) 42 (+13) 0 (same) 209 (+50)
2.7.0 129 30 0 159
3.6.0 167 (+38) 42 (+12) 0 (same) 209 (+50)
3.7.0 170 (+3) 35 (-7) 9 (+9) 214 (+5)
3.8.0 174 (+4) 37 (+2) 12 (+3) 223 (+9)
3.9.0 173 (-1) 35 (-2) 14 (+2) 222 (-1)
3.10.0 173 (same) 33 (-2) 13 (-1) 219 (-3)
3.11.0 177 (+4) 32 (-1) 10 (-3) 219 (same)
3.12 (dev) 178 (+1) 29 (-3) 12 (+2) 219 (same)
main (3.13) 178 (same) 30 (+1) 12 (same) 220 (+1)
3.12 (dev) 176 (-1) 31 (-1) 12 (+2) 219 (same)
main (3.13) 176 (same) 32 (+1) 12 (same) 220 (+1)
=========== ========== ======== ========= ==========

Functions defined as macros and static inline functions
Expand Down

0 comments on commit 1e8d6c4

Please sign in to comment.