cpython/Lib/ctypes/test
Eric Snow 2c1e2583fd
bpo-43693: Add new internal code objects fields: co_fastlocalnames and co_fastlocalkinds. (gh-26388)
A number of places in the code base (notably ceval.c and frameobject.c) rely on mapping variable names to indices in the frame "locals plus" array (AKA fast locals), and thus opargs.  Currently the compiler indirectly encodes that information on the code object as the tuples co_varnames, co_cellvars, and co_freevars.  At runtime the dependent code must calculate the proper mapping from those, which isn't ideal and impacts performance-sensitive sections.  This is something we can easily address in the compiler instead.

This change addresses the situation by replacing internal use of co_varnames, etc. with a single combined tuple of names in locals-plus order, along with a minimal array mapping each to its kind (local vs. cell vs. free).  These two new PyCodeObject fields, co_fastlocalnames and co_fastllocalkinds, are not exposed to Python code for now, but co_varnames, etc. are still available with the same values as before (though computed lazily).

Aside from the (mild) performance impact, there are a number of other benefits:

* there's now a clear, direct relationship between locals-plus and variables
* code that relies on the locals-plus-to-name mapping is simpler
* marshaled code objects are smaller and serialize/de-serialize faster

Also note that we can take this approach further by expanding the possible values in co_fastlocalkinds to include specific argument types (e.g. positional-only, kwargs).  Doing so would allow further speed-ups in _PyEval_MakeFrameVector(), which is where args get unpacked into the locals-plus array.  It would also allow us to shrink marshaled code objects even further.

https://bugs.python.org/issue43693
2021-06-03 10:28:27 -06:00
..
__init__.py bpo-40275: Use new test.support helper submodules in tests (GH-21315) 2020-07-06 11:15:08 +02:00
__main__.py Issue #22060: Clean up/simplify test_ctypes, use test discovery 2014-08-08 13:32:16 -05:00
test_anon.py bpo-31490: Fix an assertion failure in ctypes in case an _anonymous_ attr is defined only outside _fields_. (#3615) 2017-09-17 13:45:38 +03:00
test_array_in_pointer.py Merged revisions 73715 via svnmerge from 2009-08-13 08:51:18 +00:00
test_arrays.py Use assertEqual(). (#13883) 2019-06-07 11:18:34 +02:00
test_as_parameter.py Fixed several assertTrue() that were intended to be assertEqual(). (GH-8191) 2018-07-09 18:25:55 +03:00
test_bitfields.py bpo-29753: fix merging packed bitfields in ctypes struct/union (GH-19850) 2021-02-28 14:43:19 -08:00
test_buffers.py bpo-19865: ctypes.create_unicode_buffer() supports non-BMP strings on Windows (GH-14081) 2019-06-14 17:53:59 +02:00
test_bytes.py bpo-35384: The repr of ctypes.CArgObject no longer fails for non-ascii character. (GH-10863) 2018-12-06 11:16:24 +02:00
test_byteswap.py Issue #22098: ctypes' BigEndianStructure and LittleEndianStructure now define an empty __slots__ so that subclasses don't always get an instance dict. 2014-08-30 00:37:18 +02:00
test_callbacks.py bpo-40795: ctypes calls unraisablehook with an exception (GH-20452) 2020-05-28 00:38:12 +02:00
test_cast.py bpo-21983: Fix a crash in ctypes.cast() when passed a ctypes structured data type (GH-3859) 2018-05-09 14:38:56 -07:00
test_cfuncs.py Issue #19493: Refactor ctypes test package. 2014-06-13 13:44:39 -05:00
test_checkretval.py Issue #19493: Refactor ctypes test package. 2014-06-13 13:44:39 -05:00
test_delattr.py
test_errno.py bpo-31370: Remove support for threads-less builds (#3385) 2017-09-07 18:56:24 +02:00
test_find.py bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25145) 2021-04-04 09:01:23 +09:00
test_frombuffer.py bpo-28129: fix ctypes crashes (#386) 2017-03-02 18:42:40 +01:00
test_funcptr.py bpo-28129: fix ctypes crashes (#386) 2017-03-02 18:42:40 +01:00
test_functions.py Issue #19493: Refactor ctypes test package. 2014-06-13 13:44:39 -05:00
test_incomplete.py Merged revisions 74664 via svnmerge from 2009-09-04 18:37:03 +00:00
test_init.py #11565: Fix several typos. Patch by Piotr Kasprzyk. 2011-03-16 11:05:33 +02:00
test_internals.py Issue #17516: use comment syntax for comments, instead of multiline string 2013-03-26 01:11:54 +01:00
test_keeprefs.py Issue #19493: Refactor ctypes test package. 2014-06-13 13:44:39 -05:00
test_libc.py Fix ctypes tests to avoid implicit bytes-unicode conversion 2010-07-27 23:36:41 +00:00
test_loading.py bpo-40275: Remove test helpers aliases in test.support (GH-21771) 2020-08-08 11:32:41 +02:00
test_macholib.py bpo-41100: Support macOS 11 and Apple Silicon (GH-22855) 2020-11-08 10:05:27 +01:00
test_memfunctions.py Issue #19493: Refactor ctypes test package. 2014-06-13 13:44:39 -05:00
test_numbers.py bpo-37999: No longer use __int__ in implicit integer conversions. (GH-15636) 2020-05-26 18:43:38 +03:00
test_objects.py Issue #23277: Remove unused sys and os imports 2016-04-24 07:31:42 +03:00
test_parameters.py closes bpo-43011: Fix DeprecationWarnings in test_ctypes (GH-24305) 2021-01-23 10:34:01 -06:00
test_pep3118.py bpo-32297: Few misspellings found in Python source code comments. (#4803) 2017-12-14 13:04:53 +02:00
test_pickling.py Issue #22777: Test pickling with all protocols. 2014-12-15 14:03:42 +02:00
test_pointers.py bpo-28129: fix ctypes crashes (#386) 2017-03-02 18:42:40 +01:00
test_prototypes.py #22732 ctypes tests don't set correct restype for intptr_t functions 2014-11-01 15:14:27 -07:00
test_python_api.py Issue #22060: Clean up/simplify test_ctypes, use test discovery 2014-08-08 13:32:16 -05:00
test_random_things.py bpo-40795: ctypes calls unraisablehook with an exception (GH-20452) 2020-05-28 00:38:12 +02:00
test_refcounts.py Issue #19591: Use specific asserts in ctype tests. 2013-11-16 23:51:26 +02:00
test_repr.py Fix ctypes tests to avoid implicit bytes-unicode conversion 2010-07-27 23:36:41 +00:00
test_returnfuncptrs.py Issue #23277: Remove unused sys and os imports 2016-04-24 07:31:42 +03:00
test_simplesubclasses.py Merged revisions 73715 via svnmerge from 2009-08-13 08:51:18 +00:00
test_sizes.py Issue #23277: Remove unused sys and os imports 2016-04-24 07:31:42 +03:00
test_slicing.py bpo-30708: Check for null characters in PyUnicode_AsWideCharString(). (#2285) 2017-06-27 16:03:14 +03:00
test_stringptr.py bpo-36253: Remove use after free reference in ctypes test suite (GH-12257) 2019-09-10 08:20:15 -07:00
test_strings.py bpo-35504: Fix segfaults and SystemErrors when deleting certain attrs. (GH-11175) 2018-12-17 16:52:45 +02:00
test_struct_fields.py bpo-39593: Add test on ctypes cfield.c s_set() (GH-18424) 2020-06-01 18:54:18 +02:00
test_structures.py bpo-16575: Disabled checks for union types being passed by value. (GH-17960) 2020-01-12 08:54:00 +00:00
test_unaligned_structures.py bpo-40795: ctypes calls unraisablehook with an exception (GH-20452) 2020-05-28 00:38:12 +02:00
test_unicode.py bpo-32745: Fix a regression in the handling of ctypes' c_wchar_p type (#8721) 2021-05-02 12:40:01 +02:00
test_values.py bpo-43693: Add new internal code objects fields: co_fastlocalnames and co_fastlocalkinds. (gh-26388) 2021-06-03 10:28:27 -06:00
test_varsize_struct.py Merged revisions 73715 via svnmerge from 2009-08-13 08:51:18 +00:00
test_win32.py bpo-35947: Update Windows to the current version of libffi (GH-11797) 2019-03-29 16:30:10 -07:00
test_wintypes.py bpo-16396: Allow wintypes to be imported on non-Windows systems. (GH-21394) 2020-10-19 23:06:05 +01:00