Skip to content

Commit b452d3d

Browse files
committed
Ignore private static inline functions
1 parent e4092a6 commit b452d3d

3 files changed

Lines changed: 35 additions & 19 deletions

File tree

‎doc/pythoncapi.py‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
}
3232

3333

34+
PUBLIC_NAME_PREFIX = ("Py", "PY")
35+
36+
3437
def run_command(cmd, cwd):
3538
subprocess.run(cmd,
3639
stdout=subprocess.PIPE,
@@ -145,6 +148,10 @@ def grep(regex, filenames, group=0):
145148
yield match.group(group)
146149

147150

151+
def is_function_public(name):
152+
return name.startswith(PUBLIC_NAME_PREFIX)
153+
154+
148155
def get_macros_static_inline_funcs():
149156
files = list_files(PATH_LIMITED_API) + list_files(PATH_CPYTHON_API)
150157

@@ -173,11 +180,15 @@ def get_macros_static_inline_funcs():
173180
if name.startswith("PyDTrace_"):
174181
funcs.discard(name)
175182

176-
return (macros, funcs)
177-
183+
# Remove private static inline functions
184+
for name in list(macros):
185+
if not is_function_public(name):
186+
macros.discard(name)
187+
for name in list(funcs):
188+
if not is_function_public(name):
189+
funcs.discard(name)
178190

179-
def is_function_public(name):
180-
return name.startswith(('Py', 'PY'))
191+
return (macros, funcs)
181192

182193

183194
def get_functions():

‎doc/stats.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def list_variables(results):
209209

210210
def static_inline_func(results):
211211
display_title('Functions defined as macros and static inline functions')
212-
paragraph('Functions defined as macros (only public) and static inline functions (public or private):')
212+
paragraph('Functions defined as macros and static inline functions:')
213213

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

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

225228
def structures(results):
226229
display_title('Structures')

‎doc/stats.rst‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Python Limited API CPython API Internal API Total
1818
3.10.0 10,408 (51%) 4,584 (22%) 5,519 (27%) 20,511
1919
3.11.0 9,232 (37%) 5,407 (22%) 10,047 (41%) 24,686
2020
3.12 (dev) 9,598 (29%) 5,815 (18%) 17,631 (53%) 33,044
21-
main (3.13) 9,344 (28%) 4,754 (14%) 18,920 (57%) 33,018
21+
main (3.13) 9,397 (27%) 4,750 (14%) 20,455 (59%) 34,602
2222
=========== ============= =========== ============ ======
2323

2424
File Numbers
@@ -37,7 +37,7 @@ Python Limited API CPython API Internal API Total
3737
3.10.0 81 (-17) 32 (+8) 48 (+15) 161 (+6)
3838
3.11.0 72 (-9) 47 (+15) 68 (+20) 187 (+26)
3939
3.12 (dev) 72 (same) 48 (+1) 91 (+23) 211 (+24)
40-
main (3.13) 72 (same) 50 (+2) 95 (+4) 217 (+6)
40+
main (3.13) 72 (same) 50 (+2) 96 (+5) 218 (+7)
4141
=========== =========== =========== ============ =========
4242

4343
Functions
@@ -56,7 +56,7 @@ Python Public Private Internal Total
5656
3.10.0 885 (-34) 412 (same) 115 (+6) 1,412 (-28)
5757
3.11.0 891 (+6) 360 (-52) 176 (+61) 1,427 (+15)
5858
3.12 (dev) 928 (+37) 385 (+25) 177 (+1) 1,490 (+63)
59-
main (3.13) 913 (-15) 211 (-174) 252 (+75) 1,376 (-114)
59+
main (3.13) 925 (-3) 209 (-176) 253 (+76) 1,387 (-103)
6060
=========== ========== ========== ========= ============
6161

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

91-
Functions defined as macros (only public) and static inline functions (public or private):
91+
Functions defined as macros and static inline functions:
9292

93-
=========== ========== ============= =========
93+
=========== ========== ============= ==========
9494
Python Macro Static inline Total
95-
=========== ========== ============= =========
95+
=========== ========== ============= ==========
9696
2.7.0 274 0 274
9797
3.6.0 306 (+32) 0 (same) 306 (+32)
9898
3.7.0 315 (+9) 0 (same) 315 (+9)
99-
3.8.0 314 (-1) 7 (+7) 321 (+6)
100-
3.9.0 307 (-7) 11 (+4) 318 (-3)
101-
3.10.0 307 (same) 18 (+7) 325 (+7)
102-
3.11.0 269 (-38) 46 (+28) 315 (-10)
103-
3.12 (dev) 251 (-18) 71 (+25) 322 (+7)
104-
main (3.13) 247 (-4) 70 (-1) 317 (-5)
105-
=========== ========== ============= =========
99+
3.8.0 314 (-1) 0 (same) 314 (-1)
100+
3.9.0 307 (-7) 0 (same) 307 (-7)
101+
3.10.0 307 (same) 0 (same) 307 (same)
102+
3.11.0 269 (-38) 42 (+42) 311 (+4)
103+
3.12 (dev) 251 (-18) 64 (+22) 315 (+4)
104+
main (3.13) 246 (-5) 63 (-1) 309 (-6)
105+
=========== ========== ============= ==========
106+
107+
Only count public macros and public static inline functions (name starting with "Py" or "PY").
106108

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

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

0 commit comments

Comments
 (0)