bpo-32030: Rework memory allocators (#4625) · python/cpython@5d39e04 (original) (raw)
`@@ -56,6 +56,14 @@ def copy_attributes(info_add, obj, name_fmt, attributes, *, formatter=None):
`
56
56
`info_add(name, value)
`
57
57
``
58
58
``
``
59
`+
def copy_attr(info_add, name, mod, attr_name):
`
``
60
`+
try:
`
``
61
`+
value = getattr(mod, attr_name)
`
``
62
`+
except AttributeError:
`
``
63
`+
return
`
``
64
`+
info_add(name, value)
`
``
65
+
``
66
+
59
67
`def call_func(info_add, name, mod, func_name, *, formatter=None):
`
60
68
`try:
`
61
69
`func = getattr(mod, func_name)
`
`@@ -168,11 +176,10 @@ def format_attr(attr, value):
`
168
176
`call_func(info_add, 'os.gid', os, 'getgid')
`
169
177
`call_func(info_add, 'os.uname', os, 'uname')
`
170
178
``
171
``
`-
if hasattr(os, 'getgroups'):
`
172
``
`-
groups = os.getgroups()
`
173
``
`-
groups = map(str, groups)
`
174
``
`-
groups = ', '.join(groups)
`
175
``
`-
info_add("os.groups", groups)
`
``
179
`+
def format_groups(groups):
`
``
180
`+
return ', '.join(map(str, groups))
`
``
181
+
``
182
`+
call_func(info_add, 'os.groups', os, 'getgroups', formatter=format_groups)
`
176
183
``
177
184
`if hasattr(os, 'getlogin'):
`
178
185
`try:
`
`@@ -184,11 +191,7 @@ def format_attr(attr, value):
`
184
191
`else:
`
185
192
`info_add("os.login", login)
`
186
193
``
187
``
`-
if hasattr(os, 'cpu_count'):
`
188
``
`-
cpu_count = os.cpu_count()
`
189
``
`-
if cpu_count:
`
190
``
`-
info_add('os.cpu_count', cpu_count)
`
191
``
-
``
194
`+
call_func(info_add, 'os.cpu_count', os, 'cpu_count')
`
192
195
`call_func(info_add, 'os.loadavg', os, 'getloadavg')
`
193
196
``
194
197
`# Get environment variables: filter to list
`
`@@ -219,7 +222,9 @@ def format_attr(attr, value):
`
219
222
` )
`
220
223
`for name, value in os.environ.items():
`
221
224
`uname = name.upper()
`
222
``
`-
if (uname in ENV_VARS or uname.startswith(("PYTHON", "LC_"))
`
``
225
`+
if (uname in ENV_VARS
`
``
226
`+
Copy PYTHON* and LC_* variables
`
``
227
`+
or uname.startswith(("PYTHON", "LC_"))
`
223
228
`# Visual Studio: VS140COMNTOOLS
`
224
229
`or (uname.startswith("VS") and uname.endswith("COMNTOOLS"))):
`
225
230
`info_add('os.environ[%s]' % name, value)
`
`@@ -313,12 +318,10 @@ def collect_time(info_add):
`
313
318
` )
`
314
319
`copy_attributes(info_add, time, 'time.%s', attributes)
`
315
320
``
316
``
`-
if not hasattr(time, 'get_clock_info'):
`
317
``
`-
return
`
318
``
-
319
``
`-
for clock in ('time', 'perf_counter'):
`
320
``
`-
tinfo = time.get_clock_info(clock)
`
321
``
`-
info_add('time.%s' % clock, tinfo)
`
``
321
`+
if hasattr(time, 'get_clock_info'):
`
``
322
`+
for clock in ('time', 'perf_counter'):
`
``
323
`+
tinfo = time.get_clock_info(clock)
`
``
324
`+
info_add('time.%s' % clock, tinfo)
`
322
325
``
323
326
``
324
327
`def collect_sysconfig(info_add):
`
`@@ -331,14 +334,14 @@ def collect_sysconfig(info_add):
`
331
334
`'CCSHARED',
`
332
335
`'CFLAGS',
`
333
336
`'CFLAGSFORSHARED',
`
334
``
`-
'PY_LDFLAGS',
`
335
337
`'CONFIG_ARGS',
`
336
338
`'HOST_GNU_TYPE',
`
337
339
`'MACHDEP',
`
338
340
`'MULTIARCH',
`
339
341
`'OPT',
`
340
342
`'PY_CFLAGS',
`
341
343
`'PY_CFLAGS_NODIST',
`
``
344
`+
'PY_LDFLAGS',
`
342
345
`'Py_DEBUG',
`
343
346
`'Py_ENABLE_SHARED',
`
344
347
`'SHELL',
`
`@@ -422,6 +425,16 @@ def collect_decimal(info_add):
`
422
425
`copy_attributes(info_add, _decimal, '_decimal.%s', attributes)
`
423
426
``
424
427
``
``
428
`+
def collect_testcapi(info_add):
`
``
429
`+
try:
`
``
430
`+
import _testcapi
`
``
431
`+
except ImportError:
`
``
432
`+
return
`
``
433
+
``
434
`+
call_func(info_add, 'pymem.allocator', _testcapi, 'pymem_getallocatorsname')
`
``
435
`+
copy_attr(info_add, 'pymem.with_pymalloc', _testcapi, 'WITH_PYMALLOC')
`
``
436
+
``
437
+
425
438
`def collect_info(info):
`
426
439
`error = False
`
427
440
`info_add = info.add
`
`@@ -444,6 +457,7 @@ def collect_info(info):
`
444
457
`collect_zlib,
`
445
458
`collect_expat,
`
446
459
`collect_decimal,
`
``
460
`+
collect_testcapi,
`
447
461
` ):
`
448
462
`try:
`
449
463
`collect_func(info_add)
`