Skip to content

Commit

Permalink
Ignore private static inline functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Jul 17, 2023
1 parent e4092a6 commit b452d3d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
19 changes: 15 additions & 4 deletions doc/pythoncapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
}


PUBLIC_NAME_PREFIX = ("Py", "PY")


def run_command(cmd, cwd):
subprocess.run(cmd,
stdout=subprocess.PIPE,
Expand Down Expand Up @@ -145,6 +148,10 @@ def grep(regex, filenames, group=0):
yield match.group(group)


def is_function_public(name):
return name.startswith(PUBLIC_NAME_PREFIX)


def get_macros_static_inline_funcs():
files = list_files(PATH_LIMITED_API) + list_files(PATH_CPYTHON_API)

Expand Down Expand Up @@ -173,11 +180,15 @@ def get_macros_static_inline_funcs():
if name.startswith("PyDTrace_"):
funcs.discard(name)

return (macros, funcs)

# Remove private static inline functions
for name in list(macros):
if not is_function_public(name):
macros.discard(name)
for name in list(funcs):
if not is_function_public(name):
funcs.discard(name)

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


def get_functions():
Expand Down
5 changes: 4 additions & 1 deletion doc/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def list_variables(results):

def static_inline_func(results):
display_title('Functions defined as macros and static inline functions')
paragraph('Functions defined as macros (only public) and static inline functions (public or private):')
paragraph('Functions defined as macros and static inline functions:')

lines = [('Python', 'Macro', 'Static inline', 'Total')]
for name, data in results:
Expand All @@ -221,6 +221,9 @@ def static_inline_func(results):
table_compute_diff(lines)
render_table(lines)

paragraph('Only count public macros and public static inline functions '
'(name starting with "Py" or "PY").')


def structures(results):
display_title('Structures')
Expand Down
30 changes: 16 additions & 14 deletions doc/stats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Python Limited API CPython API Internal API Total
3.10.0 10,408 (51%) 4,584 (22%) 5,519 (27%) 20,511
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%) 4,754 (14%) 18,920 (57%) 33,018
main (3.13) 9,397 (27%) 4,750 (14%) 20,455 (59%) 34,602
=========== ============= =========== ============ ======

File Numbers
Expand All @@ -37,7 +37,7 @@ Python Limited API CPython API Internal API Total
3.10.0 81 (-17) 32 (+8) 48 (+15) 161 (+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)
main (3.13) 72 (same) 50 (+2) 96 (+5) 218 (+7)
=========== =========== =========== ============ =========

Functions
Expand All @@ -56,7 +56,7 @@ Python Public Private Internal Total
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) 913 (-15) 211 (-174) 252 (+75) 1,376 (-114)
main (3.13) 925 (-3) 209 (-176) 253 (+76) 1,387 (-103)
=========== ========== ========== ========= ============

Since Python 3.9, Python is now built with ``-fvisibility=hidden`` to avoid
Expand Down Expand Up @@ -88,21 +88,23 @@ main (3.13) 176 (same) 30 (-1) 12 (same) 218 (-1)
Functions defined as macros and static inline functions
=======================================================

Functions defined as macros (only public) and static inline functions (public or private):
Functions defined as macros and static inline functions:

=========== ========== ============= =========
=========== ========== ============= ==========
Python Macro Static inline Total
=========== ========== ============= =========
=========== ========== ============= ==========
2.7.0 274 0 274
3.6.0 306 (+32) 0 (same) 306 (+32)
3.7.0 315 (+9) 0 (same) 315 (+9)
3.8.0 314 (-1) 7 (+7) 321 (+6)
3.9.0 307 (-7) 11 (+4) 318 (-3)
3.10.0 307 (same) 18 (+7) 325 (+7)
3.11.0 269 (-38) 46 (+28) 315 (-10)
3.12 (dev) 251 (-18) 71 (+25) 322 (+7)
main (3.13) 247 (-4) 70 (-1) 317 (-5)
=========== ========== ============= =========
3.8.0 314 (-1) 0 (same) 314 (-1)
3.9.0 307 (-7) 0 (same) 307 (-7)
3.10.0 307 (same) 0 (same) 307 (same)
3.11.0 269 (-38) 42 (+42) 311 (+4)
3.12 (dev) 251 (-18) 64 (+22) 315 (+4)
main (3.13) 246 (-5) 63 (-1) 309 (-6)
=========== ========== ============= ==========

Only count public macros and public static inline functions (name starting with "Py" or "PY").

Structures
==========
Expand All @@ -120,7 +122,7 @@ Python Limited API CPython API Internal API Total
3.10.0 41 (-27) 53 (+7) 91 (+53) 185 (+33)
3.11.0 19 (-22) 75 (+22) 112 (+21) 206 (+21)
3.12 (dev) 18 (-1) 84 (+9) 170 (+58) 272 (+66)
main (3.13) 18 (same) 85 (+1) 174 (+4) 277 (+5)
main (3.13) 18 (same) 85 (+1) 177 (+7) 280 (+8)
=========== =========== =========== ============ =========

Count also private structures like "_PyCFrame" and structures with names not starting with Py like "_frozen".
Expand Down

0 comments on commit b452d3d

Please sign in to comment.