HEX
Server: Microsoft-IIS/10.0
System: Windows NT ITPWINWEBSVR22 10.0 build 20348 (Windows Server 2022) AMD64
User: www.conferencesearch.co.uk (0)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: D:/Python311/Lib/test/__pycache__/test_capi.cpython-311.opt-2.pyc
�

��Vc���T�ddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlmZddlmZddlmZddlmZddlmZddlmZmZ	ddlZn
#e$rdZYnwxYw	ddlZn
#e$rdZYnwxYwejd	��Zddl Z e!ed
��Z"d�Z#d�Z$Gd
�d��Z%Gd�dej&��Z'Gd�dej&��Z(Gd�dej&��Z)Gd�dej&��Z*Gd�dej&��Z+Gd�dej&��Z,ej-��Gd�dej&����Z.Gd�de.��Z/ej0ej1��d��Gd �d!e.����Z2ej0e"d"��Gd#�d$e.����Z3ej4edud%��Gd&�d'ej&����Z5Gd(�d)ej&��Z6d*Z7Gd+�d,ej&��Z8e9d-krej:��dSdS).�)�OrderedDictN)�support)�MISSING_C_DOCSTRINGS)�
import_helper)�threading_helper)�warnings_helper)�assert_python_failure�assert_python_ok�	_testcapi�gettotalrefcountc�V�|�dd���dd��S)Nzutf-8�replace�
�)�decoder)�errs �"D:\Python311\Lib\test\test_capi.py�
decode_stderrr+s&���:�:�g�y�)�)�1�1�$��;�;�;�c��	|S�N���selfs r�testfunctionr/s
����Krc�b�eZdZe�e��Ze�e��ZdS)�InstanceMethodN)�__name__�
__module__�__qualname__r�instancemethod�idrrrrrr4s4������	�	!�	!�"�	%�	%�B��+�+�L�9�9�L�L�Lrrc��eZdZd�Zej��d���Zd�Zd�Zd�Z	e
jed��d���Z
e
jed��d���Ze
jed	��d
���Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Ze
jeed��d��d���Zd�Zejd��d���Z ejd��d���Z!d�Z"d�Z#d�Z$d�Z%d�Z&d �Z'd!�Z(d"�Z)d#�Z*d$�Z+d%�Z,d&�Z-d'�Z.d(�Z/d2d*�Z0ej��d+���Z1d,�Z2d-�Z3d.�Z4d/�Z5d0�Z6d1S)3�CAPITestc�B�t��}|�t|��|�����|�|���|u��|�|jjtj��|�tjjtj��dtj_|�tjd��|�tt|jdd��dS)N�test�	attribute)
r�assertEqualr"�
assertTruer�__doc__r'�assertRaises�AttributeError�setattr�r�insts  r�test_instancemethodzCAPITest.test_instancemethod:s�����������D���4�7�7�9�9�-�-�-�����)�)�+�+�t�3�4�4�4�����*�2�L�4H�I�I�I�����4�<�l�>R�S�S�S�06��#�-�����/��8�8�8����.�'�4�3D�k�SY�Z�Z�Z�Z�Zrc��tj��5tjtjddgtjtj���}ddd��n#1swxYwY|���\}}|�|d��|�	|�
���d��|��dS)N�-cz4import _testcapi;_testcapi.crash_no_current_thread())�stdout�stderrrs�Fatal Python error: PyThreadState_Get: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL))r�SuppressCrashReport�
subprocess�Popen�sys�
executable�PIPE�communicater(r)�rstrip�
startswith)r�p�outrs    r� test_no_FatalError_infinite_loopz)CAPITest.test_no_FatalError_infinite_loopEs��
�
(�
*�
*�	9�	9�� �#�.�$�#H�"I�)3��(2��	9�9�9�A�	9�	9�	9�	9�	9�	9�	9�	9�	9�	9�	9����	9�	9�	9�	9��]�]�_�_�
��c�����c�"�"�"�����
�
���/�/�F�G�G��
	�	�	�	�	s�9A�A� Ac�P�|�ttj��dSr)r+�
ValueErrorr�!make_memoryview_from_NULL_pointerrs r�!test_memoryview_from_NULL_pointerz*CAPITest.test_memoryview_from_NULL_pointerXs!�����*�i�&Q�R�R�R�R�Rrc�V�td��}td��}	|�#t$r�}tj��}t
�|��}tj��}t
�|��}tj��}|�||��|�||��|�||��|�||��|�||��|�||��Yd}~dSd}~wwxYw)N�5�TEST)rB�	TypeError�failr8�	exceptionr�
set_exceptionr()	r�raised_exception�new_exc�e�orig_sys_exception�orig_exception�new_sys_exception�
new_exception�reset_sys_exceptions	         r�test_exceptionzCAPITest.test_exception[s)��%�c�?�?���F�#�#��	.�"�"���
	?�
	?�
	?�!$�����&�4�4�W�=�=�N� #�
����%�3�3�N�C�C�M�"%�-�/�/�����^�Q�/�/�/����^�-=�>�>�>����/��@�@�@����0�.�A�A�A����]�G�4�4�4����.�
�>�>�>�>�>�>�>�>�>�����
	?���s�"�
D(�C1D#�#D(c��td��}td��}	|�#t$�r}|j}t	j��}t�|j|d��}t	j��}t
j|�}t	j��}	|�	|d|��|�
||j||f��|�
||��|�
|	|��|�
||j|df��|�
||��Yd}~dSd}~wwxYw)NrFrGF�)rBrHr)�
__traceback__r8�exc_infor�set_exc_info�	__class__r(�assertSequenceEqual)
rrLrMrN�tb�orig_sys_exc_info�
orig_exc_info�new_sys_exc_info�new_exc_info�reset_sys_exc_infos
          r�
test_exc_infozCAPITest.test_exc_infoqsQ��%�c�?�?���F�#�#��	#�"�"���	E�	E�	E���B� #�����%�2�2�7�3D�g�t�T�T�M�"�|�~�~��$�1�=�A�L�!$��������]�1�-�q�1�1�1��$�$�]�5E�5O�Qa�ce�4f�g�g�g��$�$�%6�
�F�F�F��$�$�%7��G�G�G��$�$�\�G�4E�w�PT�3U�V�V�V��$�$�%5�|�D�D�D�D�D�D�D�D�D�����	E���s�"�E�D	D<�<Ez(_posixsubprocess required for this test.c�b�Gd�dt��}|�ttjd|��dddddd	d
ddd
ddddddddddd��Gd�dt��}|�t
tjd|��dddddd	d
ddd
ddddddddddd��dS)Nc��eZdZd�ZdS)�1CAPITest.test_seq_bytes_to_charp_array.<locals>.Zc��dS�NrVrrs r�__len__z9CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__len__�����qrN�rrr rhrrr�Zre��#������
�
�
�
�
rrkrV��rV������	�
���
����������c��eZdZd�Zd�ZdS)rec��tjSr)r8�maxsizers rrhz9CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__len__�s
���{�"rc��dS)N�xr)r�is  r�__getitem__z=CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__getitem__�����trN)rrr rhr�rrrrkz1CAPITest.test_seq_bytes_to_charp_array.<locals>.Z�s2������
#�
#�
#�
�
�
�
�
r)�objectr+rH�_posixsubprocess�	fork_exec�MemoryError�rrks  r�test_seq_bytes_to_charp_arrayz&CAPITest.test_seq_bytes_to_charp_array�s��	�	�	�	�	��	�	�	�	
���)�%5�%?��A�A�C�C��&��1�Q�q��2�b��B�r�"�R��2�b�QS�TV�WY�Z\�	^�	^�	^�	�	�	�	�	��	�	�	�
	
���+�'7�'A��A�A�C�C��&��1�Q�q��2�b��B�r�"�R��2�b�QS�TV�WY�Z\�	^�	^�	^�	^�	^rc��Gd�dt��}|�ttj|��dgdddddd	d
ddd
ddddddddddd��dS)Nc��eZdZd�ZdS)�-CAPITest.test_subprocess_fork_exec.<locals>.Zc��dSrgrrs rrhz5CAPITest.test_subprocess_fork_exec.<locals>.Z.__len__�rirNrjrrrrkr��rlrrk�1rmrnrprqrrrsrtrurvrwrxryrzr{r|r}r~rr�r�r�)r�r+rHr�r�r�s  r�test_subprocess_fork_execz"CAPITest.test_subprocess_fork_exec�s���	�	�	�	�	��	�	�	�
	
���)�%5�%?��!�#�#�t�f�Q�v�a��!�A�a��2�b��B�r�"�R�PR�SU�VX�Y[�\^�_a�	c�	c�	c�	c�	crz6Signature information for builtins requires docstringsc��|�tjjd��|�tjjd��|�tjjd��|�tjjd��|�tjjd��|�tjjd��|�tjjd��|�tjjd��|�tjjd��|�tjjd��|�tj	jd��|�tj	jd��|�tj
jd��|�tj
jd��|�tjjd��|�tjjd��dS)Nz This docstring has no signature.z[docstring_with_invalid_signature($module, /, boo)

This docstring has an invalid signature.zedocstring_with_invalid_signature2($module, /, boo)

--

This docstring also has an invalid signature.z%This docstring has a valid signature.z($module, /, sig)z>
This docstring has a valid signature and some extra newlines.z($module, /, parameter))r(r�no_docstringr*�__text_signature__�docstring_empty�docstring_no_signature� docstring_with_invalid_signature�!docstring_with_invalid_signature2�docstring_with_signature�#docstring_with_signature_but_no_doc�+docstring_with_signature_and_extra_newlinesrs r� test_docstring_signature_parsingz)CAPITest.test_docstring_signature_parsing�s��	
����/�7��>�>�>�����/�B�D�I�I�I�����2�:�D�A�A�A�����2�E�t�L�L�L�����9�A�.�	0�	0�	0�����9�L�d�S�S�S�����C�K�
7�	�	�	�
	
����C�V�X\�]�]�]�����D�L�
<�	�	�	�	
����D�W�Y]�^�^�^�����;�C�3�	5�	5�	5�����;�N�Pc�d�d�d�����F�N�PT�U�U�U�����F�Y��	!�	!�	!�	
����N�V�M�	O�	O�	O�����N�a�%�	'�	'�	'�	'�	'rc��tj}|��}|��}|�||zd||f��|�|dzd|df��|�d|zdd|f��|}||z}|�|d||f��|}|dz}|�|d|df��d}||z}|�|dd|f��dS)N�matmul�*�imatmul)r�
matmulTyper()r�M�m1�m2�os     r�&test_c_type_with_matrix_multiplicationz/CAPITest.test_c_type_with_matrix_multiplication�s
��� ��
�Q�S�S��
�Q�S�S������b��8�R��"4�5�5�5�����b��8�R��"4�5�5�5�����b��8�R��"4�5�5�5���	�R�������Y��B�/�0�0�0���	�R�������Y��B�/�0�0�0���	�R�������X�r�2�.�/�/�/�/�/rc���t���}|�|�d��d��|�|�dd��d��dS)NrV)rVNro)roro)r�ipowTyper(�__ipow__)rr�s  r�test_c_type_with_ipowzCAPITest.test_c_type_with_ipow�s_��
��� � ��������A���	�2�2�2�������A�q�)�)�6�2�2�2�2�2rc��trOtjd��}td|��\}}}t	|��}|�|d��dS|�t��5}t�	��ddd��n#1swxYwY|�t|j��d��dS)Nz�
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_null_without_error()
            r2a#Fatal Python error: _Py_CheckFunctionResult: a function returned NULL without setting an exception\nPython runtime state: initialized\nSystemError: <built-in function return_null_without_error> returned NULL without setting an exception\n\nCurrent thread.*:\n  File .*", line 6 in <module>\nzFreturn_null_without_error.* returned NULL without setting an exception)�Py_DEBUG�textwrap�dedentr	r�assertRegexr+�SystemErrorr�return_null_without_error�strrJ�r�code�rcr?r�cms      r�test_return_null_without_errorz'CAPITest.test_return_null_without_error�s#���	K��?�$���D�1��t�<�<�L�B��S���$�$�C����S�4�
5�
5�
5�
5�
5��"�"�;�/�/�
6�2��3�3�5�5�5�
6�
6�
6�
6�
6�
6�
6�
6�
6�
6�
6����
6�
6�
6�
6����S���.�.�J�
K�
K�
K�
K�
K��1B�B�Bc��trOtjd��}td|��\}}}t	|��}|�|d��dS|�t��5}t�	��ddd��n#1swxYwY|�t|j��d��dS)Nz�
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_result_with_error()
            r2aqFatal Python error: _Py_CheckFunctionResult: a function returned a result with an exception set\nPython runtime state: initialized\nValueError\n\nThe above exception was the direct cause of the following exception:\n\nSystemError: <built-in function return_result_with_error> returned a result with an exception set\n\nCurrent thread.*:\n  File .*, line 6 in <module>\nzBreturn_result_with_error.* returned a result with an exception set)r�r�r�r	rr�r+r�r�return_result_with_errorr�rJr�s      r�test_return_result_with_errorz&CAPITest.test_return_result_with_errors!���	H��?�$���D�1��t�<�<�L�B��S���$�$�C����S�
7�
8�
8�
8�
8�
8� �"�"�;�/�/�
5�2��2�2�4�4�4�
5�
5�
5�
5�
5�
5�
5�
5�
5�
5�
5����
5�
5�
5�
5����S���.�.�G�
H�
H�
H�
H�
Hr�c���tjd��}td|��\}}}t|��}d|vr|�|d��dS|�d|��dS)Nz�
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.getitem_with_error({1: 2}, 1)
        r2z
SystemError: aFatal Python error: _Py_CheckSlotResult: Slot __getitem__ of type dict succeeded with an exception set\nPython runtime state: initialized\nValueError: bug\n\nCurrent thread .* \(most recent call first\):\n  File .*, line 6 in <module>\n\nExtension modules: _testcapi \(total: 1\)\nz'returned a result with an exception set)r�r�r	rr��assertIn�rr�r�r?rs     r�test_getitem_with_errorz CAPITest.test_getitem_with_error%s����� �
�
��-�T�4�8�8���C���C� � ���#�%�	J����S�	C�

D�

D�

D�

D�

D�
�M�M�C�S�I�I�I�I�Irc�8�t���dSr)r�test_buildvalue_Nrs rr�zCAPITest.test_buildvalue_NCs���#�#�%�%�%�%�%rc�j�d}td|��\}}}|���}t|d��D]w\}}|�d|��|�d���^}}	t|	��}	|�|	|dz��|�|	|dzdz
���xdS)Na*if 1:
            import _testcapi

            class C(): pass

            # The first loop tests both functions and that remove_mem_hooks()
            # can be called twice in a row. The second loop checks a call to
            # set_nomemory() after a call to remove_mem_hooks(). The third
            # loop checks the start and stop arguments of set_nomemory().
            for outer_cnt in range(1, 4):
                start = 10 * outer_cnt
                for j in range(100):
                    if j == 0:
                        if outer_cnt != 3:
                            _testcapi.set_nomemory(start)
                        else:
                            _testcapi.set_nomemory(start, start + 1)
                    try:
                        C()
                    except MemoryError as e:
                        if outer_cnt != 3:
                            _testcapi.remove_mem_hooks()
                        print('MemoryError', outer_cnt, j)
                        _testcapi.remove_mem_hooks()
                        break
        r2rVsMemoryError� rpro)r
�
splitlines�	enumerater��split�int�assertLessEqual�assertGreaterEqual)
rr�r�r?r�linesr��line�_�counts
          r�test_set_nomemoryzCAPITest.test_set_nomemoryFs�����4(��d�3�3���C����� � �� ���*�*�	2�	2�G�A�t��M�M�.�#�.�.�.��
�
�4�(�(�I�Q����J�J�E�� � ���!��,�,�,��#�#�E�1�Q�3�q�5�1�1�1�1�	2�	2rc
��Gd�dt��}Gd�dt��}dddd�}it��|��|��|t|��||��||��fD]�}|�t�|��t|�������|�t�|��t|�������|�t�	|��t|�
��������dS)	Nc�2��eZdZ�fd�Z�fd�Z�fd�Z�xZS)�9CAPITest.test_mapping_keys_values_items.<locals>.Mapping1c�^��tt�������Sr)�list�super�keys�rrZs �rr�z>CAPITest.test_mapping_keys_values_items.<locals>.Mapping1.keysls����E�G�G�L�L�N�N�+�+�+rc�^��tt�������Sr)r�r��valuesr�s �rr�z@CAPITest.test_mapping_keys_values_items.<locals>.Mapping1.valuesns����E�G�G�N�N�,�,�-�-�-rc�^��tt�������Sr)r�r��itemsr�s �rr�z?CAPITest.test_mapping_keys_values_items.<locals>.Mapping1.itemsps����E�G�G�M�M�O�O�,�,�,r�rrr r�r�r��
__classcell__�rZs@r�Mapping1r�ksj�������
,�
,�
,�
,�
,�
.�
.�
.�
.�
.�
-�
-�
-�
-�
-�
-�
-�
-�
-rr�c�2��eZdZ�fd�Z�fd�Z�fd�Z�xZS)�9CAPITest.test_mapping_keys_values_items.<locals>.Mapping2c�^��tt�������Sr)�tupler�r�r�s �rr�z>CAPITest.test_mapping_keys_values_items.<locals>.Mapping2.keysss����U�W�W�\�\�^�^�,�,�,rc�^��tt�������Sr)r�r�r�r�s �rr�z@CAPITest.test_mapping_keys_values_items.<locals>.Mapping2.valuesus����U�W�W�^�^�-�-�.�.�.rc�^��tt�������Sr)r�r�r�r�s �rr�z?CAPITest.test_mapping_keys_values_items.<locals>.Mapping2.itemsws����U�W�W�]�]�_�_�-�-�-rr�r�s@r�Mapping2r�rsj�������
-�
-�
-�
-�
-�
/�
/�
/�
/�
/�
.�
.�
.�
.�
.�
.�
.�
.�
.rr�rVrorm)�foo�bar�spam)�dictr�assertListEqualr�get_mapping_keysr�r��get_mapping_valuesr��get_mapping_itemsr�)rr�r��dict_obj�mappings     r�test_mapping_keys_values_itemsz'CAPITest.test_mapping_keys_values_itemsjs|��	-�	-�	-�	-�	-�t�	-�	-�	-�	.�	.�	.�	.�	.�t�	.�	.�	.��Q��2�2���K�M�M�8�8�:�:�x�x�z�z� �+�h�"7�"7� ���*�*�H�H�X�,>�,>�@�	8�	8�G�
� � ��!;�!;�G�!D�!D�!%�g�l�l�n�n�!5�!5�
7�
7�
7�� � ��!=�!=�g�!F�!F�!%�g�n�n�&6�&6�!7�!7�
9�
9�
9�� � ��!<�!<�W�!E�!E�!%�g�m�m�o�o�!6�!6�
8�
8�
8�
8�	8�	8rc��|�ttjd��|�ttjd��|�ttjd��Gd�d��}|��}|�ttj|��|�ttj|��|�ttj|��dS)Nc� �eZdZd�Zd�Zd�ZdS)�CCAPITest.test_mapping_keys_values_items_bad_arg.<locals>.BadMappingc��dSrrrs rr�zHCAPITest.test_mapping_keys_values_items_bad_arg.<locals>.BadMapping.keys�r�rc��dSrrrs rr�zJCAPITest.test_mapping_keys_values_items_bad_arg.<locals>.BadMapping.values�r�rc��dSrrrs rr�zICAPITest.test_mapping_keys_values_items_bad_arg.<locals>.BadMapping.items�r�rN)rrr r�r�r�rrr�
BadMappingr��sA������
�
�
�
�
�
�
�
�
�
�
rr�)r+r,rr�r�r�rH)rr��bad_mappings   r�&test_mapping_keys_values_items_bad_argz/CAPITest.test_mapping_keys_values_items_bad_arg�s������.�)�*D�d�K�K�K����.�)�*F��M�M�M����.�)�*E�t�L�L�L�	�	�	�	�	�	�	�	�!�j�l�l�����)�Y�%?��M�M�M����)�Y�%A�;�O�O�O����)�Y�%@�+�N�N�N�N�Nr�negative_refcountz need _testcapi.negative_refcountc��tjd��}td|��\}}}|�|d��dS)Nz�
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.negative_refcount()
        r2s`_testcapimodule\.c:[0-9]+: _Py_NegativeRefcount: Assertion failed: object has negative ref count)r�r�r	r�r�s     r�test_negative_refcountzCAPITest.test_negative_refcount�sZ��
�� �
�
��-�T�4�8�8���C������;�	<�	<�	<�	<�	<rc�R�ddlm}d}td��D]}||f��}�dS)Nr��MyList��)rr�range)rr�Lr�s    r�test_trashcan_subclasszCAPITest.test_trashcan_subclass�sK��	%�$�$�$�$�$����t���	�	�A����t���A�A�	�	r�cpuc�:�|�t��dSr)�do_test_trashcan_python_classr�rs r�test_trashcan_python_class1z$CAPITest.test_trashcan_python_class1�s���*�*�4�0�0�0�0�0rc�<�ddlm}|�|��dS)Nrr)rrr)rrs  r�test_trashcan_python_class2z$CAPITest.test_trashcan_python_class2�s.��$�$�$�$�$�$��*�*�6�2�2�2�2�2rc���Gd�d|��}dD]e}d}td��D]}||f��}||_�|r|f}|�|jd��~|�|jd���fdS)Nc�,��eZdZdZ�fd�Z�fd�Z�xZS)�6CAPITest.do_test_trashcan_python_class.<locals>.PyListrc�T���xjdz
c_t��j|�dSrg)�numr��__init__)r�argsrZs  �rrz?CAPITest.do_test_trashcan_python_class.<locals>.PyList.__init__�s-����
�
��"�
�
� ���� �$�'�'�'�'rc�(���xjdzc_dSrg)rr�s �r�__del__z>CAPITest.do_test_trashcan_python_class.<locals>.PyList.__del__�s����
�
��"�
�
�
�
r)rrr rrrr�r�s@r�PyListr�sX��������C�
(�
(�
(�
(�
(�
#�
#�
#�
#�
#�
#�
#�
#�
#rr)rrVir)r�attr�
assertGreaterrr()r�baser�parityrr�s      rrz&CAPITest.do_test_trashcan_python_class�s���	#�	#�	#�	#�	#�T�	#�	#�	#��	,�	,�F��A��5�\�\�
�
���F�A�4�L�L�������
��D�����v�z�1�-�-�-�����V�Z��+�+�+�+�	,�	,rc��|�tjjd��|�tjjd��dS)N�somedocz(arg1, arg2))r(r�HeapDocCTyper*r�rs r�&test_heap_ctype_doc_and_text_signaturez/CAPITest.test_heap_ctype_doc_and_text_signature�s@������/�7��C�C�C�����/�B�N�S�S�S�S�Src�P�|�tjjd��dSr)r(r�
NullTpDocTyper*rs r�test_null_type_doczCAPITest.test_null_type_doc�s$������0�8�$�?�?�?�?�?rc�6�Gd�dtj��}|��}tj|��}|�|jd��|�|jd��~|�|dz
tj|����dS)Nc���eZdZ�fd�Z�xZS)�`CAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once.<locals>.HeapGcCTypeSubclassc�V��d|_t�����dS�Nr��value2r�rr�s �rrziCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once.<locals>.HeapGcCTypeSubclass.__init__��&��� ������ � �"�"�"�"�"r�rrr rr�r�s@r�HeapGcCTypeSubclassr&��8�������
#�
#�
#�
#�
#�
#�
#�
#�
#rr-rurrV)r�HeapGcCTyper8�getrefcountr(�valuer*)rr-�subclass_instance�type_refcnts    r�:test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_oncezCCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once�s���	#�	#�	#�	#�	#�)�"7�	#�	#�	#�
0�/�1�1���o�&9�:�:��	
���*�0�"�5�5�5����*�1�2�6�6�6�
�����q��#�/�:M�*N�*N�O�O�O�O�Orc����Gd�dtj���G��fd�d�������}tj���}tj���}|�|jd��|�|jd��~tr|�|�j��n|�|dz
�j��|�|dz�j��|�|dz
tj�����|�|tj�����dS)Nc���eZdZ�fd�Z�xZS)�dCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.Ac�V��d|_t�����dSr(r)r�s �rrzmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.A.__init__�r+rr,r�s@r�Ar7�r.rr9c�,���eZdZ�fd�Z��fd�Z�xZS)�dCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.Bc�H��t�����dSr)r�rr�s �rrzmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.B.__init__�s������ � �"�"�"�"�"rc�z���|_tj����_tj����_dSr)rZr8r0�
refcnt_in_del)rr9�Bs ��rrzlCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.B.__del__�s0���!"���"%�/�!�"4�"4���"%�/�!�"4�"4����r)rrr rrr�)rZr9r?s@��rr?r;�sW��������
#�
#�
#�
#�
#�
5�
5�
5�
5�
5�
5�
5�
5�
5�
5rr?rurrV)	rr/r8r0r(r1r*r�r>)rr2r3�new_type_refcntr9r?s    @@r�Ptest_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_oncezYCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once�s}����	#�	#�	#�	#�	#�	�%�	#�	#�	#�
	5�	5�	5�	5�	5�	5�	5�	5��	5�	5�	5��A�C�C���o�a�(�(���/�!�,�,��	
���*�0�"�5�5�5����*�1�2�6�6�6���	?�
���[�!�/�:�:�:�:����[�1�_�a�o�>�>�>�����1�,�a�o�>�>�>�	
����q��#�/�!�*<�*<�=�=�=�	
����#�/�!�*<�*<�=�=�=�=�=rc�^�t���}d|_|�|jd��|�|j|j��|�|jddi��t���}|�i|j��dS�Nr�r�)r�HeapCTypeWithDictr�r(�dictobj�__dict__r.s  r�test_heaptype_with_dictz CAPITest.test_heaptype_with_dicts����*�*�,�,����������2�&�&�&������t�}�5�5�5�������r�{�3�3�3��*�*�,�,������T�]�+�+�+�+�+rc�^�t���}d|_|�|jd��|�|j|j��|�|jddi��t���}|�i|j��dSrC)r�HeapCTypeWithNegativeDictr�r(rErFr.s  r� test_heaptype_with_negative_dictz)CAPITest.test_heaptype_with_negative_dicts����2�2�4�4����������2�&�&�&������t�}�5�5�5�������r�{�3�3�3��2�2�4�4������T�]�+�+�+�+�+rc���t���}tj|��}|�|��|��|�|j|��dSr)r�HeapCTypeWithWeakref�weakref�refr(�weakreflist)rr/rNs   r�test_heaptype_with_weakrefz#CAPITest.test_heaptype_with_weakref)s]���-�-�/�/���k�$������������%�%�%�����)�3�/�/�/�/�/rc��t���}t|��}|�|d��dS)Ns1234)r�HeapCTypeWithBuffer�bytesr()rr/�bs   r�test_heaptype_with_bufferz"CAPITest.test_heaptype_with_buffer/s:���,�,�.�.���$�K�K������G�$�$�$�$�$rc�L�t���}tjtj��}|�|jd��|�|jd��~|�|dz
tjtj����dS�NrurrV)r�HeapCTypeSubclassr8r0r(r1r*)rr2r3s   r�9test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_oncezBCAPITest.test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_once4s���%�7�7�9�9���o�i�&A�B�B��	
���*�0�"�5�5�5����*�1�2�6�6�6�
�����q��#�/�)�:U�*V�*V�W�W�W�W�Wrc���t���}tjtj��}tjtj��}|�|jd��|�|jd��~tr&|�|tjj	��n(|�|dz
tjj	��|�|dztjj	��|�|dz
tjtj����|�|tjtj����dSrW)
r�HeapCTypeSubclassWithFinalizerr8r0rXr(r1r*r�r>)rr2r3r@s    r�Otest_c_subclass_of_heap_ctype_with_del_modifying_dunder_class_only_decrefs_oncezXCAPITest.test_c_subclass_of_heap_ctype_with_del_modifying_dunder_class_only_decrefs_once@s4��%�D�D�F�F���o�i�&N�O�O���/�)�*E�F�F��	
���*�0�"�5�5�5����*�1�2�6�6�6�
��	f�
���[�)�*R�*`�a�a�a�a����[�1�_�i�.V�.d�e�e�e�����1�,�i�.I�.W�X�X�X�	
����q��#�/�)�:b�*c�*c�d�d�d�	
����#�/�)�:U�*V�*V�W�W�W�W�Wrc���t���}|�|jd��d|_|�|jd��|`|�|jd��dS)Nrurwr)r�HeapCTypeSetattrr(�pvaluer1)r�objs  r�test_heaptype_with_setattroz$CAPITest.test_heaptype_with_setattro[sm���(�(�*�*�������R�(�(�(���	������R�(�(�(��I������Q�'�'�'�'�'rc��Gd�dtjtj��}Gd�dtjtj��}tjtjtjtjfD]d}tjtjtjtjfD]}||urGd�d||��}�Gd�d||��}Gd	�d
||��}�edS)Nc��eZdZdS)�MCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict.<locals>.Both1N�rrr rrr�Both1rde��������Drrfc��eZdZdS)�MCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict.<locals>.Both2Nrerrr�Both2rigrgrrjc��eZdZdS)�ICAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict.<locals>.SNrerrr�Srlos�������rrmc��eZdZdS)�JCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict.<locals>.B1Nrerrr�B1roq��������rrpc��eZdZdS)�JCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict.<locals>.B2Nrerrr�B2rssrqrrt)rrLrD�HeapCTypeWithDict2�HeapCTypeWithWeakref2)rrfrj�cls�cls2rmrprts        r�5test_multiple_inheritance_ctypes_with_weakref_or_dictz>CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dictcsX��	�	�	�	�	�I�2�I�4O�	�	�	�	�	�	�	�	�I�/��1O�	�	�	��/��1M��*�I�,K�M�
	�
	�C�"�4�i�6R��.�	�0O�Q�
�
���d�?�������C������
�
�
�
�
�U�C�
�
�
�
�
�
�
�
�U�C�
�
�
�
�
	�
	rc��ddlm}|�|dd��d��|�|dd��d��|�|dd��d	��|�|dd
��d��|�|dd��d
��|�|dd��d��|�|dd��d��|�|dd
��d��|�t|dd��|�t|d	d��|�t
|dd��dS)Nr)�pynumber_tobase�{ro�	0b1111011rs�0o173ru�123r{�0x7bi����z
-0b1111011z-0o173z-123z-0x7bg�^@)rr{r(r+rHr�)rr{s  r�test_pynumber_tobasezCAPITest.test_pynumber_tobasevsx��-�-�-�-�-�-�������a�0�0�+�>�>�>�������a�0�0�'�:�:�:�������b�1�1�5�9�9�9�������b�1�1�6�:�:�:�������q�1�1�<�@�@�@�������q�1�1�8�<�<�<�������r�2�2�F�;�;�;�������r�2�2�G�<�<�<����)�_�e�R�@�@�@����)�_�e�R�@�@�@����+���Q�?�?�?�?�?rrc���tj��5tdd|��\}}}ddd��n#1swxYwYt|��}|�d|��tjd|t
j��}|s|�d|����t|�
d������d����}t|�
d����}	|D]}
|�|
|���|D]}
|�|
|���|�t!|��|	��dS)	Nz-sSIr2z.Fatal Python error: test_fatal_error: MESSAGE
z,^Extension modules:(.*) \(total: ([0-9]+)\)$z$Cannot find 'Extension modules:' in rVz, ro)rr5r	rr��re�search�	MULTILINErI�set�group�stripr�r��assertNotInr(�len)rr��expected�not_expectedr�r?r�match�modules�total�names           r�check_fatal_errorzCAPITest.check_fatal_error�s���
�
(�
*�
*�	E�	E�0���t�D�D�L�B��S�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E����	E�	E�	E�	E��C� � ���
�
�G��	�	�	��	�I��r�|�-�-���	F��I�I�D�S�D�D�E�E�E��e�k�k�!�n�n�*�*�,�,�2�2�4�8�8�9�9���E�K�K��N�N�#�#���	)�	)�D��M�M�$��(�(�(�(� �	,�	,�D����T�7�+�+�+�+�����W���u�-�-�-�-�-s�6�:�:c��d}d}d}|�|||��d}d}tjd��}|�||��dS)N)r)r8z8import _testcapi, sys; _testcapi.fatal_error(b"MESSAGE")z�
            import _testcapi, sys
            sys.stdlib_module_names = frozenset({"_testcapi"})
            _testcapi.fatal_error(b"MESSAGE")
        )r�r�r�)rr�r�r�s    r�test_fatal_errorzCAPITest.test_fatal_error�sk��"����I�����t�X�|�<�<�<���%���� �
�
��
	
���t�X�.�.�.�.�.rc�d�t���}|�|d��dS�Nz<NULL>)r�pyobject_repr_from_nullr(�r�ss  r�test_pyobject_repr_from_nullz%CAPITest.test_pyobject_repr_from_null�s/���-�-�/�/������H�%�%�%�%�%rc�d�t���}|�|d��dSr�)r�pyobject_str_from_nullr(r�s  r�test_pyobject_str_from_nullz$CAPITest.test_pyobject_str_from_null�s/���,�,�.�.������H�%�%�%�%�%rc�d�t���}|�|d��dS)Ns<NULL>)r�pyobject_bytes_from_nullr(r�s  r�test_pyobject_bytes_from_nullz&CAPITest.test_pyobject_bytes_from_null�s/���.�.�0�0������I�&�&�&�&�&rc��tj}d}||��}t|dd��}|�|j|j��dS)Ns%# -*- coding: latin1 -*-
print('¤')
z<string>�exec)r�Py_CompileString�compiler(�	co_consts)r�_compiler��resultr�s     r�test_Py_CompileStringzCAPITest.test_Py_CompileString�sO���-��?����$�����4��V�4�4������)�8�+=�>�>�>�>�>rc��tjd��}g}ttd��r|�d��t
jdkr|�d��|D]X}|�|���5|�t|j	|����ddd��n#1swxYwY�YdS)N�ctypes�
get_native_id�PyThread_get_thread_native_id�nt�
Py_FrozenMain)r�)
r�
import_module�hasattr�_thread�append�osr��subTestr)�	pythonapi)rr��namesr�s    r�test_export_symbolszCAPITest.test_export_symbols�s���,�X�6�6�����7�O�,�,�	:��L�L�8�9�9�9��7�d�?�	*��L�L��)�)�)��	A�	A�D����4��(�(�
A�
A������(8�$� ?� ?�@�@�@�
A�
A�
A�
A�
A�
A�
A�
A�
A�
A�
A����
A�
A�
A�
A��	A�	As�)B5�5B9	�<B9	N)r)7rrr r0r�requires_subprocessr@rDrTrb�unittest�
skipUnlessr�r�r��skipIfrr�r�r�r�r�r�r�r�r�r�r�rrr�requires_resourcerrrr r#r4rArGrJrPrUrYr\raryr�r�r�r�r�r�r�r�rrrr$r$8s�������	[�	[�	[�!�W� �"�"���#�"��$S�S�S�.�.�.�,#�#�#�.�X��)�+U�V�V�^�^�W�V�^� �X��)�+U�V�V�c�c�W�V�c��X�_�)�M�O�O�''�''�O�O�''�R0�0�0�"3�3�3�K�K�K�: H� H� H�DJ�J�J�<&�&�&�"2�"2�"2�H8�8�8�6O�O�O�"�X�����,?�@�@�;�=�=�<�<�=�=�<� ����W��u�%�%�1�1�&�%�1��W��u�%�%�3�3�&�%�3�,�,�,�8T�T�T�@�@�@�P�P�P�"&>�&>�&>�P,�,�,�,�,�,�0�0�0�%�%�%�

X�
X�
X�X�X�X�6(�(�(����&@�@�@�.�.�.�.�*!�W� �"�"�/�/�#�"�/�$&�&�&�&�&�&�'�'�'�?�?�?�A�A�A�A�Arr$c�X�eZdZd�Zdd�Zej��d���Zd�Zd�Z	dS)�TestPendingCallsc����fd�}t|��D]G}tjtj��dz��	t�|��rn��HdS)Nc�2����d��dSr)r�)�ls�r�callbackz6TestPendingCalls.pendingcalls_submit.<locals>.callback�s���
�H�H�T�N�N�N�N�Nrg{�G�z�?)r�time�sleep�randomr�_pending_threadfunc)rr��nr�r�s `   r�pendingcalls_submitz$TestPendingCalls.pendingcalls_submit�s~���	�	�	�	�	�
�q���	�	�A��J�v�}���t�+�,�,�,�
��0�0��:�:���
��	�	rNc� �d}t|��|krx	t	d��D]}||z}�|r|j���s�G|dz
}|�|dkd|t|��fz��t|��|k�xdS)NrFz(%i)rrVi'z(timeout waiting for %i callbacks, got %i)r�r�verbose�printr�event�is_setr))rr�r��contextr�r��as       r�pendingcalls_waitz"TestPendingCalls.pendingcalls_wait�s������!�f�f��k�	H�
)��4�[�[�
�
���a�C����
�w�}�3�3�5�5�
���Q�J�E��O�O�E�E�M�:�A�s�1�v�v�;�F�
H�
H�
H��!�f�f��k�	H�	$�	$rc�����d}g}Gd�dt��}|���g�_d�_|�jz�_d�_tj���_tj���_	��fd�t�j��D��}tj|��5��
�j|���ddd��dS#1swxYwYdS)N� c��eZdZdS)�8TestPendingCalls.test_pendingcalls_threaded.<locals>.fooNrerrrr�r�s�������rr�rorc�H��g|]}tj�j�f�����S))�targetr)�	threading�Thread�pendingcalls_thread)�.0r�r�rs  ��r�
<listcomp>z?TestPendingCalls.test_pendingcalls_threaded.<locals>.<listcomp>sE���5�5�5���#�4�+C�*1��5�5�5�5�5�5r)r�r�r��nThreads�	nFinishedr��Lock�lock�Eventr�rr�
start_threadsr�)rr��threadsr�r�s`   @r�test_pendingcalls_threadedz+TestPendingCalls.test_pendingcalls_threaded�s@����
���������&�����#�%�%����	���	���	�>������ �~�'�'���!��)�)��
�5�5�5�5�5�!�'�"2�3�3�5�5�5���
+�G�
4�
4�	:�	:��"�"�7�9�a��9�9�9�	:�	:�	:�	:�	:�	:�	:�	:�	:�	:�	:�	:����	:�	:�	:�	:�	:�	:s�-C�C�Cc���	|�|j|j��|j5|xjdz
c_|j}	ddd��n#1swxYwY||jkr|j	�
��dSdS#|j5|xjdz
c_|j}	ddd��n#1swxYwY||jkr|j	�
��wwxYwrg)r�r�r�r�r�rr�r�r�r�r�)rr�r�s   rr�z$TestPendingCalls.pendingcalls_threads���		$��$�$�W�Y��	�:�:�:���
;�
;��!�!�Q�&�!�!�#�-�	�;�
;�
;�
;�
;�
;�
;�
;�
;�
;�
;�
;����
;�
;�
;�
;�
�G�,�,�
$��
�!�!�#�#�#�#�#�
$�
$����
;�
;��!�!�Q�&�!�!�#�-�	�;�
;�
;�
;�
;�
;�
;�
;�
;�
;�
;�
;����
;�
;�
;�
;�
�G�,�,�
$��
�!�!�#�#�#�#�
$���s@� B�A�A�A�C�	B.�"C�.B2�2C�5B2�6)Cc�f�g}d}|�||��|�||��dS)N�@)r�r�)rr�r�s   r�test_pendingcalls_non_threadedz/TestPendingCalls.test_pendingcalls_non_threadeds@��

����� � ��A�&�&�&����q�!�$�$�$�$�$rr)
rrr r�r�r�requires_working_threadingr�r�r�rrrr�r��s}������
�
�
�$�$�$�$�&1��0�2�2�:�:�3�2�:�(
$�
$�
$�%�%�%�%�%rr�c���eZdZejeed��d��d���Zejeed��d��d���Zd�Z	ej
edud��d���ZdS)	�SubinterpreterTest�pipezrequires os.pipe()c���ddl}tj��\}}d�|��}t	|d��5}tj|��}|�|d��|�tj
|��ttj
����|�tj
|��t|����ddd��dS#1swxYwYdS)Nrz�if 1:
            import sys, builtins, pickle
            with open({:d}, "wb") as f:
                pickle.dump(id(sys.modules), f)
                pickle.dump(id(builtins), f)
            �rb)�builtinsr�r��format�openr�run_in_subinterpr(�assertNotEqual�pickle�loadr"r8r�)rr��r�wr��f�rets       r�test_subinterpsz"SubinterpreterTest.test_subinterps*s�������w�y�y���1��
��q�	�	�	
��!�T�]�]�	>�a��*�4�0�0�C����S�!�$�$�$������A����3�;���@�@�@������A����8���=�=�=�		>�	>�	>�	>�	>�	>�	>�	>�	>�	>�	>�	>����	>�	>�	>�	>�	>�	>s�BC,�,C0�3C0c�X�tj��\}}d�|��}t|d��5}t	j|��}|�|d��|�tj|��ddd���ddd��dS#1swxYwYdS)Naaif 1:
            import pickle
            with open({:d}, "wb") as f:

                @(lambda x:x)  # Py 3.9
                def noop(x): return x

                a = (b := f'1{{2}}3') + noop('x')  # Py 3.8 (:=) / 3.6 (f'')

                async def foo(arg): return await arg  # Py 3.5

                pickle.dump(dict(a=a, b=b), f)
            r�r�123xr)r�rT)	r�r�r�r�rr�r(r�r�)rr�r�r�r�r�s      r�(test_subinterps_recent_language_featuresz;SubinterpreterTest.test_subinterps_recent_language_features:s����w�y�y���1����q�	�	�	
��!�T�]�]�	H�a��*�4�0�0�C����S�!�$�$�$����V�[��^�^�6��-F�-F�G�G�G�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H����	H�	H�	H�	H�	H�	Hs�AB�B#�&B#c��	ddl}tjd��|�t	|jd����dS)Nrz1import binascii; binascii.Error.foobar = 'foobar'�foobar)�binasciirr��assertFalser��Error)rr�s  r�test_mutate_exceptionz(SubinterpreterTest.test_mutate_exceptionPsJ��	�	����� �!T�U�U�U��������:�:�;�;�;�;�;rN�$test requires _testmultiphase modulec���	tj��\}}|�tj|��|�tj|��t	jd|�d���}t
|��tj|d��}tj	|��}|�
|d��tj|d��}|�
||��dS)Na�
            import importlib.machinery
            import importlib.util
            import os

            fullname = '_test_module_state_shared'
            origin = importlib.util.find_spec('_testmultiphase').origin
            loader = importlib.machinery.ExtensionFileLoader(fullname, origin)
            spec = importlib.util.spec_from_loader(fullname, loader)
            module = importlib.util.module_from_spec(spec)
            attr_id = str(id(module.Error)).encode()

            os.write(z, attr_id)
            �dr)r�r��
addCleanup�closer�r�r��readrr�r()rr�r��script�main_attr_idr��subinterp_attr_ids       r�"test_module_state_shared_in_globalz5SubinterpreterTest.test_module_state_shared_in_global]s���	��w�y�y���1������!�$�$�$������!�$�$�$���
"��
"�
"�
"�
�
��	
�V�����w�q�#�����&�v�.�.������a� � � ��G�A�s�O�O������'8�9�9�9�9�9r)
rrr r�r�r�r�r�r�rr��_testmultiphaserrrrr�r�(s��������X�����V�,�,�.B�C�C�
>�
>�D�C�
>��X�����V�,�,�.B�C�C�H�H�D�C�H�*<�<�<��X�_�_��,�.T�U�U�:�:�V�U�:�:�:rr�c��eZdZejej��d�����Zejej��d�����ZdS)�TestThreadStatec����fd�}|��tj|���}|���|���dS)Nc�����g��fd�}t�|��|x}}tjd������t
j����dd��dS)Nc�T����tj����dSr)r�r��	get_ident)�identss�rr�zCTestThreadState.test_thread_state.<locals>.target.<locals>.callback�s$����
�
�i�1�3�3�4�4�4�4�4rrVrmz/Couldn't find main thread correctly in the list)r�_test_thread_stater�r�r(r�r�r)r�r�rTrrs   @�rr�z1TestThreadState.test_thread_state.<locals>.target�s������F�
5�
5�
5�
5�
5�
�(�(��2�2�2���A���J�q�M�M�M����V�\�\�)�*=�*?�*?�@�@�!�N�
P�
P�
P�
P�
Pr)r�)r�r��start�join)rr��ts`  r�test_thread_statez!TestThreadState.test_thread_state�s_���	P�	P�	P�	P�	P�	�������F�+�+�+��	���	�	�	�	�������rc��tjd��}tddd|��}|�d|j��dS)Nz�
            import _testcapi

            def callback():
                print('callback called')

            _testcapi._test_thread_state(callback)
            z-X�tracemallocr2scallback called)r�r�r
r�r?)rr�r�s   r� test_gilstate_ensure_no_deadlockz0TestThreadState.test_gilstate_ensure_no_deadlock�sL���� �����t�]�D�$�?�?���
�
�(�#�'�2�2�2�2�2rN)rrr r�reap_threadsr�rrrrrrr~s~�������"�0��0�2�2���3�2�#�"��(�"�0��0�2�2�3�3�3�2�#�"�3�3�3rrc��eZdZe���d�ee��D����eje	���d���Z
d�ZdS)�
Test_testcapic#�K�|]E}|�d���|�d���,|tt|��fV��FdS)�test_�_codeN)r=�endswith�getattrr�r�r�s  r�	<genexpr>zTest_testcapi.<genexpr>�st����P�P�����w�/�/�P�8<�
�
�g�8N�8N�P�T�7�9�d�3�3�4�P�P�P�P�P�Pr)�categoryc�8�t���dSr)r�
test_widecharrs rr(zTest_testcapi.test_widechar�s�����!�!�!�!�!rc�Z�|�tjtj��dSr)r(r�
Py_Versionr8�
hexversionrs r�test_version_api_dataz#Test_testcapi.test_version_api_data�s#������-�s�~�>�>�>�>�>rN)rrr �locals�update�dirrr�ignore_warnings�DeprecationWarningr(r,rrrrr�s�������
�F�H�H�O�O�P�P� #��I���P�P�P�P�P�P�
%�_�$�.@�A�A�A�"�"�B�A�"�?�?�?�?�?rrc�n�eZdZe���d�ee��D����dS)�Test_testinternalcapic#�nK�|]0}|�d���|tt|��fV��1dS)r N)r=r#�_testinternalcapir$s  rr%zTest_testinternalcapi.<genexpr>�sW����1�1�����w�/�/�1�T�7�#4�d�;�;�<�1�1�1�1�1�1rN)rrr r-r.r/r5rrrr3r3�sW������
�F�H�H�O�O�1�1� #��$5� 6� 6�1�1�1�1�1�1�1�1rr3c�X�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�ZdS)�PyMemDebugTests�debugz(?:0x)?[0-9a-fA-F]+c���tj��5td||jd���}ddd��n#1swxYwY|j}|�dd��S)Nr2�
junk:false��PYTHONMALLOC�MALLOC_CONF�asciir)rr5r	r<rr)rr�r?r4s    r�checkzPyMemDebugTests.check�s���
�
(�
*�
*�	�	�'��d�!�.�)����C�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�����}�}�W�i�0�0�0s
�9�=�=c���|�d��}d}|�|j���}tj|tj���}|�||��dS)Nz3import _testcapi; _testcapi.pymem_buffer_overflow()a6Debug memory block at address p={ptr}: API 'm'\n    16 bytes originally requested\n    The [0-9] pad bytes at p-[0-9] are FORBIDDENBYTE, as expected.\n    The [0-9] pad bytes at tail={ptr} are not all FORBIDDENBYTE \(0x[0-9a-f]{{2}}\):\n        at tail\+0: 0x78 \*\*\* OUCH\n        at tail\+1: 0xfd\n        at tail\+2: 0xfd\n        .*\n(    The block was made by call #[0-9]+ to debug malloc/realloc.\n)?    Data at p: cd cd cd .*\n\nEnable tracemalloc to get the memory block allocation traceback\n\nFatal Python error: _PyMem_DebugRawFree: bad trailing pad byte��ptr)�flags)r?r��	PTR_REGEXr�r��DOTALLr��rr?�regexs   r�test_buffer_overflowz$PyMemDebugTests.test_buffer_overflow�se���j�j�N�O�O��
S��������0�0���
�5��	�2�2�2������e�$�$�$�$�$rc��|�d��}d}|�|j���}|�||��dS)Nz.import _testcapi; _testcapi.pymem_api_misuse()a�Debug memory block at address p={ptr}: API 'm'\n    16 bytes originally requested\n    The [0-9] pad bytes at p-[0-9] are FORBIDDENBYTE, as expected.\n    The [0-9] pad bytes at tail={ptr} are FORBIDDENBYTE, as expected.\n(    The block was made by call #[0-9]+ to debug malloc/realloc.\n)?    Data at p: cd cd cd .*\n\nEnable tracemalloc to get the memory block allocation traceback\n\nFatal Python error: _PyMem_DebugRawFree: bad ID: Allocated using API 'm', verified using API 'r'\nrA)r?r�rDr�rFs   r�test_api_misusezPyMemDebugTests.test_api_misuse�sO���j�j�I�J�J��	w��������0�0������e�$�$�$�$�$rc�`�|�|��}d}|�||��dS)Nz^Fatal Python error: _PyMem_DebugMalloc: Python memory allocator called without holding the GIL)r?r�)rr�r?r�s    r�check_malloc_without_gilz(PyMemDebugTests.check_malloc_without_gil�s5���j�j�����M���
�
�h��$�$�$�$�$rc�4�d}|�|��dS)Nz6import _testcapi; _testcapi.pymem_malloc_without_gil()�rL�rr�s  r�test_pymem_malloc_without_gilz-PyMemDebugTests.test_pymem_malloc_without_gil�s$��H���%�%�d�+�+�+�+�+rc�4�d}|�|��dS)Nz9import _testcapi; _testcapi.pyobject_malloc_without_gil()rNrOs  r� test_pyobject_malloc_without_gilz0PyMemDebugTests.test_pyobject_malloc_without_gil�s$��K���%�%�d�+�+�+�+�+rc�f�tjd|�d���}td||jd���dS)Nz�
            import gc, os, sys, _testcapi
            # Disable the GC to avoid crash on GC collection
            gc.disable()
            try:
                _testcapi.z�()
                # Exit immediately to avoid a crash while deallocating
                # the invalid object
                os._exit(0)
            except _testcapi.error:
                os._exit(1)
        r2r:r;)r�r�r
r<)r�	func_namer�s   r�check_pyobject_is_freedz'PyMemDebugTests.check_pyobject_is_freeds]���� �
%� � � �
�
��	��$��*�$�	
�	
�	
�	
�	
�	
rc�0�|�d��dS)N�check_pyobject_null_is_freed�rUrs r�test_pyobject_null_is_freedz+PyMemDebugTests.test_pyobject_null_is_freeds���$�$�%C�D�D�D�D�Drc�0�|�d��dS)N�%check_pyobject_uninitialized_is_freedrXrs r�$test_pyobject_uninitialized_is_freedz4PyMemDebugTests.test_pyobject_uninitialized_is_freeds���$�$�%L�M�M�M�M�Mrc�0�|�d��dS)N�'check_pyobject_forbidden_bytes_is_freedrXrs r�&test_pyobject_forbidden_bytes_is_freedz6PyMemDebugTests.test_pyobject_forbidden_bytes_is_freeds���$�$�%N�O�O�O�O�Orc�0�|�d��dS)N�check_pyobject_freed_is_freedrXrs r�test_pyobject_freed_is_freedz,PyMemDebugTests.test_pyobject_freed_is_freeds���$�$�%D�E�E�E�E�ErN)rrr r<rDr?rHrJrLrPrRrUrYr\r_rbrrrr7r7�s��������L�&�I�
1�
1�
1�%�%�%�(
%�
%�
%�%�%�%�,�,�,�,�,�,�
�
�
�&E�E�E�N�N�N�P�P�P�F�F�F�F�Frr7c��eZdZdZdS)�PyMemMallocDebugTests�malloc_debugN�rrr r<rrrrdrd!s������!�L�L�Lrrdz
need pymallocc��eZdZdZdS)�PyMemPymallocDebugTests�pymalloc_debugNrfrrrrhrh%s������#�L�L�Lrrhz
need Py_DEBUGc��eZdZdZdS)�PyMemDefaultTestsrNrfrrrrkrk*s�������L�L�Lrrkrc�4�eZdZ	d�Zd�Zd�Zd�Zd�Zd�ZdS)�Test_ModuleStateAccessc�H�d}tj�d��j}tj�||��}tj�||��}tj�|��}|�|��||_	dS)N�!_testmultiphase_meth_state_accessr)
�	importlib�util�	find_spec�origin�	machinery�ExtensionFileLoader�spec_from_loader�module_from_spec�exec_module�module)r�fullnamers�loader�specrys      r�setUpzTest_ModuleStateAccess.setUp8s���6����)�)�*;�<�<�C���$�8�8��6�J�J���~�.�.�x��@�@����0�0��6�6�����6�"�"�"�����rc��	Gd�d|jj��}|��}|�|���|j��dS)Nc��eZdZdS)�QTest_ModuleStateAccess.test_subclass_get_module.<locals>.StateAccessType_SubclassNrerrr�StateAccessType_Subclassr�Crgrr��ry�StateAccessType�assertIs�get_defining_module�rr��instances   r�test_subclass_get_modulez/Test_ModuleStateAccess.test_subclass_get_moduleAsl��1�	�	�	�	�	�t�{�'B�	�	�	�,�+�-�-���
�
�h�2�2�4�4�d�k�B�B�B�B�Brc��Gd�d|jj��}|��}|�|���|j��dS)Nc���eZdZ�fd�Z�xZS)�\Test_ModuleStateAccess.test_subclass_get_module_with_super.<locals>.StateAccessType_Subclassc�D��t�����Sr)r�r�r�s �rr�zpTest_ModuleStateAccess.test_subclass_get_module_with_super.<locals>.StateAccessType_Subclass.get_defining_moduleKs����w�w�2�2�4�4�4r)rrr r�r�r�s@rr�r�Js8�������
5�
5�
5�
5�
5�
5�
5�
5�
5rr�r�r�s   r�#test_subclass_get_module_with_superz:Test_ModuleStateAccess.test_subclass_get_module_with_superIsi��	5�	5�	5�	5�	5�t�{�'B�	5�	5�	5�,�+�-�-���
�
�h�2�2�4�4�d�k�B�B�B�B�Brc�j�	|j���}|j���}|j|jd�}|���D�]Z\}}|�|��5|�|���|�����|�|���d��|��|�|���|�����|�|���d��|d��|�|���|�����|�|���d��|dd���|�|���|�����|�|���d��|�t��5|d�	��ddd��n#1swxYwY|�t��5|dd
d��ddd��n#1swxYwYddd��n#1swxYwY��\dS)N)�clinic�noclinicrrVrm����T)�twice)�thricero)
ryr��increment_count_clinic�increment_count_noclinicr�r�r(�	get_countr+rH)rr�rT�methodsr��increment_counts      r�test_state_accessz(Test_ModuleStateAccess.test_state_accessQs��	�
�K�'�'�)�)���K�'�'�)�)���.��2�
�
��
&-�]�]�_�_�	-�	-�!�D�/����d�#�#�
-�
-�� � ���������
�
�>�>�>�� � �������2�2�2���!�!�!�� � ���������
�
�>�>�>�� � �������2�2�2����"�"�"�� � ���������
�
�>�>�>�� � �������2�2�2����$�/�/�/�/�� � ���������
�
�>�>�>�� � �������2�2�2��&�&�y�1�1�.�.�#�O�1�-�-�-�-�.�.�.�.�.�.�.�.�.�.�.����.�.�.�.��&�&�y�1�1�-�-�#�O�A�q�!�,�,�,�-�-�-�-�-�-�-�-�-�-�-����-�-�-�-�'
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-����
-�
-�
-�
-��	-�	-s[�2GJ&�7
I�J&�I�J&�I�J&�5J�J&�J�J&�J�J&�&J*	�-J*	c���|j���}|�t��5|���ddd��dS#1swxYwYdSr)ryr�r+rH�getmodulebydef_bad_def)rr�s  r�test_get_module_bad_defz.Test_ModuleStateAccess.test_get_module_bad_defws����;�.�.�0�0��
�
�
�y�
)�
)�	.�	.��+�+�-�-�-�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.����	.�	.�	.�	.�	.�	.s�A�A�Ac��Gd�dt|jj��}|�|�����|j��dS)Nc��eZdZdS)�FTest_ModuleStateAccess.test_get_module_static_in_mro.<locals>.SubclassNrerrr�Subclassr��rgrr�)�
BaseExceptionryr�r�r�)rr�s  r�test_get_module_static_in_mroz4Test_ModuleStateAccess.test_get_module_static_in_mrosa��	�	�	�	�	�}�d�k�&A�	�	�	��
�
�h�h�j�j�4�4�6�6���D�D�D�D�DrN)	rrr r}r�r�r�r�r�rrrrmrm0s}������/����C�C�C�C�C�C�$-�$-�$-�L.�.�.�E�E�E�E�Errmc�&�eZdZd�Zd�Zd�Zd�ZdS)�
Test_FrameAPIc�(�tj��Sr�r8�	_getframers r�getframezTest_FrameAPI.getframe�s���}���rc#�4K�tj��V�dSrr�rs r�getgenframezTest_FrameAPI.getgenframe�s�����m�o�o�����rc���|���}|�|jt�|����|�|jt�|����|�|jt�	|����|�|j
t�|����dSr)r�r(�f_localsr�frame_getlocalsr��	f_globals�frame_getglobals�
f_builtins�frame_getbuiltins�f_lasti�frame_getlasti)r�frames  r�test_frame_gettersz Test_FrameAPI.test_frame_getters�s����
�
����������)B�)B�5�)I�)I�J�J�J��
�
�e�o�y�'A�'A�%�'H�'H�I�I�I��
�
�e�&�	�(C�(C�E�(J�(J�K�K�K������	�(@�(@��(G�(G�H�H�H�H�Hrc��|���}t|��}|�|t�|����dSr)r��nextr�r�frame_getgenerator)r�genr�s   r�test_frame_get_generatorz&Test_FrameAPI.test_frame_get_generator�sF����� � ���S�	�	���
�
�c�9�7�7��>�>�?�?�?�?�?rN)rrr r�r�r�r�rrrr�r��sX������������I�I�I�@�@�@�@�@rr�rc� �eZdZd�Zd�Zd�ZdS)�Test_Pep523APIc�N�g}t}|tz}t|��D]&}||krtj|��|���'tj��|�t
|��t��|D]}|�||j���dSr)�"SUFFICIENT_TO_DEOPT_AND_SPECIALIZErr5�set_eval_frame_record�set_eval_frame_defaultr(r�r)r�func�callsrr�r�r�s       r�do_testzTest_Pep523API.do_test�s�����2���:�:���u���	�	�A��E�z�
?�!�7��>�>�>��D�F�F�F�F��0�2�2�2�����U���%G�H�H�H��	2�	2�D����T�4�=�1�1�1�1�	2�	2rc�6�d�}|�|��dS)Nc��dSrrrrr�func1zDTest_Pep523API.test_pep523_with_specialization_simple.<locals>.func1�����Dr�r�)rr�s  r�&test_pep523_with_specialization_simplez5Test_Pep523API.test_pep523_with_specialization_simple�s)��	�	�	����U�����rc�8�dd�}|�|��dS)Nc��dSrr)�xs r�func2zJTest_Pep523API.test_pep523_with_specialization_with_default.<locals>.func2�r�rrr�)rr�s  r�,test_pep523_with_specialization_with_defaultz;Test_Pep523API.test_pep523_with_specialization_with_default�s.��	�	�	�	����U�����rN)rrr r�r�r�rrrr�r��sA������2�2�2����
����rr��__main__);�collectionsrr��importlib.machineryrp�importlib.utilr�r�r�r�r6r8r�r�r�r�rMr&r�test.supportrrrr�test.support.script_helperr	r
r��ImportErrorrr�rr5r�r�rrr�TestCaser$r�r�rrr3r�r7rdr��
with_pymallocrhrkr�rmr�r�r�r�mainrrr�<module>r�s@��$�#�#�#�#�#�������������	�	�	�	�
�
�
�
�
�
�
�
�	�	�	�	�����
�
�
�
���������������������������-�-�-�-�-�-�&�&�&�&�&�&�)�)�)�)�)�)�(�(�(�(�(�(�N�N�N�N�N�N�N�N��������������������������������O�O�O�����
(�M�'��4�4�	������7�3�*�+�+��<�<�<����
:�:�:�:�:�:�:�:�]
A�]
A�]
A�]
A�]
A�x� �]
A�]
A�]
A�@M%�M%�M%�M%�M%�x�(�M%�M%�M%�`S:�S:�S:�S:�S:��*�S:�S:�S:�l%3�%3�%3�%3�%3�h�'�%3�%3�%3�P?�?�?�?�?�H�%�?�?�?�1�1�1�1�1�H�-�1�1�1������cF�cF�cF�cF�cF�h�'�cF�cF���cF�L"�"�"�"�"�O�"�"�"����*�W�*�,�,�o�>�>�$�$�$�$�$�o�$�$�?�>�$����X��/�/���������0�/��
����D�(�*P�Q�Q�TE�TE�TE�TE�TE�X�.�TE�TE�R�Q�TE�n@�@�@�@�@�H�%�@�@�@�*&)�"������X�&����4�z����H�M�O�O�O�O�O��s$�&A+�+A5�4A5�9A>�>B�B