Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_gc.cpython-311.opt-2.pyc
�

�Ke����ddlZddlZddlmZmZmZmZddlmZddl	m
Z
mZmZddl
mZmZddlmZddlZddlZddlZddlZddlZddlZddlZ	ddlmZn#e$rd�ZYnwxYw	dd	lmZn
#e$rdZYnwxYwGd
�de��ZGd�d
e��ZeGd�de����Zej ���!dd��rdej ��dvZ"n
e#ed��Z"Gd�dej$��Z%Gd�dej$��Z&Gd�dej$��Z'Gd�dej$��Z(d�Z)d�Z*e+dkrej,��dSdS)�N)�verbose�
refcount_test�cpython_only�requires_subprocess)�
import_module)�temp_dir�TESTFN�unlink)�assert_python_ok�make_script)�threading_helper)�with_tp_delc�,�Gd�dt��}|S)Nc��eZdZd�ZdS)�with_tp_del.<locals>.Cc� �td���)Nzrequires _testcapi.with_tp_del)�	TypeError)�cls�args�kwargss   �6/usr/local/apps/python3/lib/python3.11/test/test_gc.py�__new__zwith_tp_del.<locals>.C.__new__s��� @�A�A�A�N)�__name__�
__module__�__qualname__r�rr�Crs(������
B�
B�
B�
B�
Brr)�object)rrs  rrrs;��	B�	B�	B�	B�	B��	B�	B�	B��r)�
ContainerNoGCc��eZdZd�ZdS)�C1055820c�"�||_||_dS�N)�i�loop)�selfr%s  r�__init__zC1055820.__init__)s�������	�	�	rN�rrrr(rrrr"r"(s#����������rr"c��eZdZd�ZdS)�GC_Detectorc�n��d�_�fd�}tjtd��|���_dS)NFc���d�_dS)NT)�gc_happened)�ignoredr's �r�it_happenedz)GC_Detector.__init__.<locals>.it_happened4s���#�D���r�)r.�weakref�refr"�wr)r'r0s` rr(zGC_Detector.__init__1sC��� ���	$�	$�	$�	$�	$�
�+�h�s�m�m�[�9�9����rNr)rrrr+r+-s#������:�:�:�:�:rr+c��eZdZ	dd�Zd�ZdS)�
UncollectableNc�F�|�t|���|_dS||_dS)N)�partner)r6r8)r'r8s  rr(zUncollectable.__init__Cs(���?�(��6�6�6�D�L�L�L�"�D�L�L�Lrc��dSr$r�r's r�
__tp_del__zUncollectable.__tp_del__Hs���rr$)rrrr(r;rrrr6r6;s<������)�#�#�#�#�

�
�
�
�
rr6�	PY_CFLAGS�z-DNDEBUG�gettotalrefcountc���eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
ed	���Zed
���Z
d�Zd�Zed
���Zd�Zd�Zd�Zed���Zed���Zd�Zej��d���Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#ee$��d�����Z%d�Z&d �Z'd!�Z(d"�Z)d#�Z*d$�Z+d%�Z,d&�Z-d'�Z.d(�Z/e0j1e2d)ud*��d+���Z3d)S),�GCTestsc��g}|�|��tj��~|�tj��d��dS�N���append�gc�collect�assertEqual�r'�ls  r�	test_listzGCTests.test_listWsF����	�������
�
����
��������q�)�)�)�)�)rc��i}||d<tj��~|�tj��d��dSrB�rFrGrH�r'�ds  r�	test_dictzGCTests.test_dict^s@������!��
�
����
��������q�)�)�)�)�)rc��g}|f}|�|��tj��~~|�tj��d��dS)N�rD)r'rJ�ts   r�
test_tuplezGCTests.test_tupleesP����
�D��	�������
�
����
�
��������q�)�)�)�)�)rc��Gd�d��}||_tj��~|�tj��d��dS)Nc��eZdZdS)�GCTests.test_class.<locals>.AN�rrrrrr�ArWp��������DrrYr��arFrG�assertNotEqual�r'rYs  r�
test_classzGCTests.test_classosa��	�	�	�	�	�	�	�	����
�
����
����B�J�L�L�!�,�,�,�,�,rc��Gd�dt��}tj��~|�tj��d��dS)Nc��eZdZdS)�%GCTests.test_newstyleclass.<locals>.ANrXrrrrYrbxrZrrYr)rrFrGr]r^s  r�test_newstyleclasszGCTests.test_newstyleclassws\��	�	�	�	�	��	�	�	�
�
����
����B�J�L�L�!�,�,�,�,�,rc��Gd�d��}|��}||_tj��~|�tj��d��dS)Nc��eZdZdS)� GCTests.test_instance.<locals>.ANrXrrrrYrfrZrrYrr[�r'rYr\s   r�
test_instancezGCTests.test_instance~sl��	�	�	�	�	�	�	�	�
�A�C�C�����
�
����
����B�J�L�L�!�,�,�,�,�,rc��Gd�dt��}|��}||_tj��~|�tj��d��Gd�dt
��}Gd�d||��}|��}||_tj��~|�tj��d��~~|�tj��d��|��|_~|�tj��d��|�tj��d��dS)Nc��eZdZdS)�#GCTests.test_newinstance.<locals>.ANrXrrrrYrk�rZrrYrc��eZdZdS)�#GCTests.test_newinstance.<locals>.BNrXrrr�Brm�rZrrnc��eZdZdS)�#GCTests.test_newinstance.<locals>.CNrXrrrrrp�rZrr)rr\rFrGr]�listrH)r'rYr\rnrs     r�test_newinstancezGCTests.test_newinstance�si��	�	�	�	�	��	�	�	�
�A�C�C�����
�
����
����B�J�L�L�!�,�,�,�	�	�	�	�	��	�	�	�	�	�	�	�	��1�	�	�	�
�A�C�C�����
�
����
����B�J�L�L�!�,�,�,�
�q����B�J�L�L�!�,�,�,��a�c�c���
����B�J�L�L�!�,�,�,��������q�)�)�)�)�)rc��Gd�d��}|��}tj��~|�tj��d��dS)Nc��eZdZd�ZdS)�GCTests.test_method.<locals>.Ac��|j|_dSr$)r(�initr:s rr(z'GCTests.test_method.<locals>.A.__init__�s�� �M��	�	�	rNr)rrrrYru�s#������
*�
*�
*�
*�
*rrYr)rFrGr]rgs   r�test_methodzGCTests.test_method�sg��	*�	*�	*�	*�	*�	*�	*�	*�
�A�C�C��
�
����
����B�J�L�L�!�,�,�,�,�,rc���tGd�d����}Gd�d��}|��}||_t|��}|��}||_t	j��~~|�t	j��d��tjD]}t|��|kr|`n�|�d��tj�	|��dS)Nc��eZdZd�ZdS)�(GCTests.test_legacy_finalizer.<locals>.Ac��dSr$rr:s rr;z3GCTests.test_legacy_finalizer.<locals>.A.__tp_del__�����rN�rrrr;rrrrYr{��������&�&�&�&�&rrYc��eZdZdS)�(GCTests.test_legacy_finalizer.<locals>.BNrXrrrrnr��rZrrnr�&didn't find obj in garbage (finalizer))
rr\�id�brFrGr]�garbage�fail�remove�r'rYrnr\�id_ar��objs       r�test_legacy_finalizerzGCTests.test_legacy_finalizer�s��
�	'�	'�	'�	'�	'�	'�	'�
��	'�	�	�	�	�	�	�	�	�
�A�C�C������!�u�u��
�A�C�C�����
�
����
�
����B�J�L�L�!�,�,�,��:�	@�	@�C��#�w�w�$����E����
�I�I�>�?�?�?�
�
���#�����rc��tGd�dt����}Gd�dt��}|��}||_t|��}|��}||_tj��~~|�tj��d��t
jD]}t|��|kr|`n�|�	d��t
j�
|��dS)Nc��eZdZd�ZdS)�1GCTests.test_legacy_finalizer_newclass.<locals>.Ac��dSr$rr:s rr;z<GCTests.test_legacy_finalizer_newclass.<locals>.A.__tp_del__�r}rNr~rrrrYr��rrrYc��eZdZdS)�1GCTests.test_legacy_finalizer_newclass.<locals>.BNrXrrrrnr��rZrrnrr�)rrr\r�r�rFrGr]r�r�r�r�s       r�test_legacy_finalizer_newclassz&GCTests.test_legacy_finalizer_newclass�s ��
�	'�	'�	'�	'�	'��	'�	'�
��	'�	�	�	�	�	��	�	�	�
�A�C�C������!�u�u��
�A�C�C�����
�
����
�
����B�J�L�L�!�,�,�,��:�	@�	@�C��#�w�w�$����E����
�I�I�>�?�?�?�
�
���#�����rc��i}td|��tj��~|�tj��d��dS)Nzdef f(): pass
rR)�execrFrGrHrNs  r�
test_functionzGCTests.test_function�sJ��
���
��"�"�"�
�
����
��������q�)�)�)�)�)rc��d}td|��\}}}|�|d��|�|d��|�|��dS)Na�if 1:

        import gc
        import weakref

        class LateFin:
            __slots__ = ('ref',)

            def __del__(self):

                # 8. Now `latefin`'s finalizer is called. Here we
                #    obtain a reference to `func`, which is currently
                #    undergoing `tp_clear`.
                global func
                func = self.ref()

        class Cyclic(tuple):
            __slots__ = ()

            # 4. The finalizers of all garbage objects are called. In
            #    this case this is only us as `func` doesn't have a
            #    finalizer.
            def __del__(self):

                # 5. Create a weakref to `func` now. If we had created
                #    it earlier, it would have been cleared by the
                #    garbage collector before calling the finalizers.
                self[1].ref = weakref.ref(self[0])

                # 6. Drop the global reference to `latefin`. The only
                #    remaining reference is the one we have.
                global latefin
                del latefin

            # 7. Now `func` is `tp_clear`-ed. This drops the last
            #    reference to `Cyclic`, which gets `tp_dealloc`-ed.
            #    This drops the last reference to `latefin`.

        latefin = LateFin()
        def func():
            pass
        cyc = tuple.__new__(Cyclic, (func, latefin))

        # 1. Create a reference cycle of `cyc` and `func`.
        func.__module__ = cyc

        # 2. Make the cycle unreachable, but keep the global reference
        #    to `latefin` so that it isn't detected as garbage. This
        #    way its finalizer will not be called immediately.
        del func, cyc

        # 3. Invoke garbage collection,
        #    which will find `cyc` and `func` as garbage.
        gc.collect()

        # 9. Previously, this would crash because `func_qualname`
        #    had been NULL-ed out by func_clear().
        print(f"{func=}")
        �-crs!\A\s*func=<function  at \S+>\s*\Z)rrH�assertRegex�assertFalse)r'�code�rc�stdout�stderrs     r�.test_function_tp_clear_leaves_consistent_statez6GCTests.test_function_tp_clear_leaves_consistent_state�si��:��x.�d�D�9�9���F�F�����Q��������!J�K�K�K����� � � � � rc��d�}tj��|��|�tj��d��dS)Nc�,�tj��}dSr$)�sys�	_getframe)�frames r�fzGCTests.test_frame.<locals>.f+s���M�O�O�E�E�ErrCrM)r'r�s  r�
test_framezGCTests.test_frame)sI��	$�	$�	$�
�
����	������������q�)�)�)�)�)rc�L�tj��|�tjg��g}|�|��t|��}tj��}tj|tjz��~tj��tj|��|�ttj��d��tj�
��}|�t|��|��dSrB)rFrGrHr�rEr��	get_debug�	set_debug�
DEBUG_SAVEALL�len�pop)r'�L�id_L�debugr�s     r�test_saveallzGCTests.test_saveall1s���	�
���������R�(�(�(���	��������!�u�u�������
��U�R�-�-�.�.�.�
�
�
����
��U��������R�Z���!�,�,�,��j�n�n��������C���$�'�'�'�'�'rc���tj��}tj��tjd��Gd�d��}|��}~tj��tj|�dS)NrCc��eZdZd�ZdS)�GCTests.test_del.<locals>.Ac�$�t|��dSr$��dirr:s r�__del__z#GCTests.test_del.<locals>.A.__del__P����D�	�	�	�	�	rN�rrrr�rrrrYr�O�#������
�
�
�
�
rrY)rF�
get_threshold�enable�
set_threshold�disable�r'�
thresholdsrYr\s    r�test_delzGCTests.test_delIs����%�'�'�
�
�	����
������	�	�	�	�	�	�	�	�
�A�C�C��
�
�
����
��*�%�%�%�%rc��tj��}tj��tjd��Gd�dt��}|��}~tj��tj|�dS)NrCc��eZdZd�ZdS)�$GCTests.test_del_newclass.<locals>.Ac�$�t|��dSr$r�r:s rr�z,GCTests.test_del_newclass.<locals>.A.__del___r�rNr�rrrrYr�^r�rrY)rFr�r�r�rr�r�s    r�test_del_newclasszGCTests.test_del_newclassXs����%�'�'�
�
�	����
������	�	�	�	�	��	�	�	�
�A�C�C��
�
�
����
��*�%�%�%�%rc�D�tj��tj��\}}}g}tj��\}}}|�||fd��|�||fd��|�|d��|�||��dS)N�rr�)rFrG�	get_countrH�
assertLess�
assertGreater)r'r\r��c�xrO�er�s        r�test_get_countzGCTests.test_get_countms���
�
�����,�.�.���1�a����,�.�.���1�a����!�Q���(�(�(����!�Q���(�(�(�����1����	
���1�a� � � � � rc���tj��g}tjd��tj��\}}}tjd��tj��\}}}tjd��tj��\}}	}
|�||fd��|�||fd��|�|	|
fd��dS)NrrCrR)rCr)rrCr�)rFrGr�rH)r'r�r\r�r�rOr�r��g�hr%s           r�test_collect_generationsz GCTests.test_collect_generations{s���
�
����
��
�
�1�
�
�
��,�.�.���1�a�
�
�1�
�
�
��,�.�.���1�a�
�
�1�
�
�
��,�.�.���1�a�	
���!�Q���(�(�(����!�Q���(�(�(����!�Q���(�(�(�(�(rc�\��G�fd�d���tj��d}td��D]c}g}t|��D]}|���g}�g}t|��D]}|���g}�i}t|��D]}|���d�}��dtj��dS)Nc���eZdZdZ�fd�ZdS)�#GCTests.test_trashcan.<locals>.Ouchrc�l���jdz�_�jdzdkrtj��dSdS)NrC�r)�nrFrG)r'�Ouchs �rr�z+GCTests.test_trashcan.<locals>.Ouch.__del__�s8�����!�����6�B�;�!�#�#��J�L�L�L�L�L�$�#rN)rrrr�r�)r�s�rr�r��s3��������A�
!�
!�
!�
!�
!�
!�
!rr��rR)rCrR)rFr��ranger�)r'�N�countrSr%�u�vr�s       @r�
test_trashcanzGCTests.test_trashcan�s����	!�	!�	!�	!�	!�	!�	!�	!�	!�	!�(	�	�������1�X�X�		&�		&�E��A��1�X�X�
 �
 �������K����A��1�X�X�
 �
 �������K����A��1�X�X�
&�
&���d�d�f�f�%�%���
&�
�
�����rc����	�
��d�d}d��G��fd�dt�����fd��
�	�
fd�}tj��}tjd��	g�	g}t	|��D],}tj|�	��}|�|���-tj	|�	fd
���5tjd��ddd��n#1swxYwYtj|��n#tj|��wxYwtj
��|�t�j��t�j����dS)N�<rRc3�pK�		dV�tjd��dS#tjd��wxYw)Ng���ư>)�time�sleeprrr�sleeper_genz2GCTests.test_trashcan_threads.<locals>.sleeper_gen�sC����N�
%������
�8�$�$�$�$�$���
�8�$�$�$�$���s��5c�.��eZdZgZgZ�fd�Z��fd�ZdS)�(GCTests.test_trashcan_threads.<locals>.Cc�J��||dd�<�j�d��dSr$)�initsrE)r'�alistrs  �rr(z1GCTests.test_trashcan_threads.<locals>.C.__init__�s*�����Q�Q�Q������t�$�$�$�$�$rc�n���j�d�����}t|��dSr$)�delsrE�next)r'r�rr�s  ��rr�z0GCTests.test_trashcan_threads.<locals>.C.__del__�s3�����
�
�d�#�#�#� �K�M�M���Q�����rN)rrrr�r�r(r�)rr�s��rrr��sV��������E��D�
%�
%�
%�
%�
%�
�
�
�
�
�
�
�
rrc�`��	�g��}t���D]}�|g��g}�~dSr$)r�)r�r%r�NESTINGs  ��r�make_nestedz2GCTests.test_trashcan_threads.<locals>.make_nested�sE���
C���"���A��7�^�^�
�
���Q��s�V�V�H�����rc�*��	�s�����dSdSr$r)�exitr�s��r�
run_threadz1GCTests.test_trashcan_threads.<locals>.run_thread�s7���3��
���
�
�
��
�
�
�
�
rg�h㈵��>)�targetc�.����d��SrB�rE)r�s�r�<lambda>z/GCTests.test_trashcan_threads.<locals>.<lambda>�s������Q���r��?)rqr��getswitchinterval�setswitchintervalr��	threading�ThreadrEr
�
start_threadsr�r�rFrGrHr�r�r�)r'�	N_THREADSr��old_switchinterval�threadsr%rSrr�r�r�r�s       @@@@@r�test_trashcan_threadszGCTests.test_trashcan_threads�s�����������	�	%�	%�	%�	�	�	�	�	�	�	�	��	�	�	�$	�	�	�	�	�	�	�	�	�	�	�	�
!�2�4�4����d�#�#�#�		6��D��G��9�%�%�
"�
"���$�J�7�7�7�����q�!�!�!�!�!�/��9O�9O�9O�9O�P�P�
 �
 ��
�3����
 �
 �
 �
 �
 �
 �
 �
 �
 �
 �
 ����
 �
 �
 �
 �
�!�"4�5�5�5�5��C�!�"4�5�5�5�5����
�
��������Q�W���s�1�6�{�{�3�3�3�3�3s1�AC0�/C�C0�C�C0�C�C0�0Dc�h�Gd�d��}|��}|��}||_||_tj��ttj��}~~|�tj��d��|�ttj��|��dS)Nc��eZdZd�ZdS)�GCTests.test_boom.<locals>.Boomc��|`t�r$��attr�AttributeError�r'�
someattributes  r�__getattr__z+GCTests.test_boom.<locals>.Boom.__getattr__��
���I�$�$rN�rrrr
rrr�Boomr��#������
%�
%�
%�
%�
%rrrR�r	rFrGr�r�rH)r'rr\r��
garbagelens     r�	test_boomzGCTests.test_boom�s���	%�	%�	%�	%�	%�	%�	%�	%�

�D�F�F���D�F�F��������
�
�������_�_�
�
�q�	
�������q�)�)�)�����R�Z���*�5�5�5�5�5rc�h�Gd�d��}|��}|��}||_||_tj��ttj��}~~|�tj��d��|�ttj��|��dS)Nc��eZdZd�Zd�ZdS)�!GCTests.test_boom2.<locals>.Boom2c��d|_dS�Nr�r�r:s rr(z*GCTests.test_boom2.<locals>.Boom2.__init__�
������rc�J�|xjdz
c_|jdkr|`t�rB�r�r	r
rs  rr
z-GCTests.test_boom2.<locals>.Boom2.__getattr__�'�����!�����6�A�:�:��	�$�$rN�rrrr(r
rrr�Boom2r�2������
�
�
�
%�
%�
%�
%�
%rr rRr)r'r r\r�rs     r�
test_boom2zGCTests.test_boom2s���	%�	%�	%�	%�	%�	%�	%�	%�
�E�G�G���E�G�G��������
�
�������_�_�
�
�q�	
�������q�)�)�)�����R�Z���*�5�5�5�5�5rc�t�Gd�dt��}|��}|��}||_||_tj��t	tj��}~~|�tj��d��|�t	tj��|��dS)Nc��eZdZd�ZdS)�'GCTests.test_boom_new.<locals>.Boom_Newc��|`t�r$rrs  rr
z3GCTests.test_boom_new.<locals>.Boom_New.__getattr__&rrNrrrr�Boom_Newr%%rrr'rR�rr	rFrGr�r�rH)r'r'r\r�rs     r�
test_boom_newzGCTests.test_boom_new!s���	%�	%�	%�	%�	%�v�	%�	%�	%�

�H�J�J���H�J�J��������
�
�������_�_�
�
�q��������q�)�)�)�����R�Z���*�5�5�5�5�5rc�t�Gd�dt��}|��}|��}||_||_tj��t	tj��}~~|�tj��d��|�t	tj��|��dS)Nc��eZdZd�Zd�ZdS)�)GCTests.test_boom2_new.<locals>.Boom2_Newc��d|_dSrrr:s rr(z2GCTests.test_boom2_new.<locals>.Boom2_New.__init__7rrc�J�|xjdz
c_|jdkr|`t�rBrrs  rr
z5GCTests.test_boom2_new.<locals>.Boom2_New.__getattr__:rrNrrrr�	Boom2_Newr,6r!rr/rRr()r'r/r\r�rs     r�test_boom2_newzGCTests.test_boom2_new5s���	%�	%�	%�	%�	%��	%�	%�	%�
�I�K�K���I�K�K��������
�
�������_�_�
�
�q��������q�)�)�)�����R�Z���*�5�5�5�5�5rc	���gd�}tj|��}|���|�||��t	|��}tj|��}|���|�||��ddd�}gd�}tj|��}|���|�||��tjddgddid	��}|���|�|d
d
gtt
d����z��|�tjddd
��g��dS)N)rC�r�r2�)rCr�)rCr2r�r3rCrR�)rrrrr�r\y@)rF�
get_referents�sortrH�tuplerqr�)r'r��got�atuple�adict�expecteds      r�test_get_referentszGCTests.test_get_referentsKsB���	�	����u�%�%�����
�
�
�����e�$�$�$��u������v�&�&�����
�
�
�����e�$�$�$��!�����<�<����u�%�%�����
�
�
�����h�'�'�'����1�v��1�v�y�9�9�����
�
�
�����q�!�f�t�E�!�H�H�~�~�5�6�6�6�����)�!�S�"�5�5�r�:�:�:�:�:rc�"�|�tjd����|�tjd����|�tjd����|�tjd����|�tjd����|�tjd����|�tjd����|�tjd����|�tjtd������|�tjt����|�tjt
����|�tjt����|�tjt
������Gd�d	��}Gd
�dt
��}Gd�d
��}Gd�dt��}Gd�dt
��}|�tjt����|�tj|����|�tj|������|�tj|������|�tjg����|�tjt������|�tj|������|�tj|������|�tj|������dS)NrCr�y�?@TF�ar\c��eZdZdS)�*GCTests.test_is_tracked.<locals>.UserClassNrXrrr�	UserClassr@urZrrAc��eZdZdS)�(GCTests.test_is_tracked.<locals>.UserIntNrXrrr�UserIntrCxrZrrDc��eZdZdZdS)�/GCTests.test_is_tracked.<locals>.UserClassSlotsrN�rrr�	__slots__rrr�UserClassSlotsrF|��������I�I�IrrIc��eZdZdZdS)�/GCTests.test_is_tracked.<locals>.UserFloatSlotsrNrGrrr�UserFloatSlotsrL�rJrrMc��eZdZdZdS)�-GCTests.test_is_tracked.<locals>.UserIntSlotsrNrGrrr�UserIntSlotsrO�rJrrP)
r�rF�
is_tracked�	bytearray�type�intr�float�
assertTrue�set)r'rArDrIrMrPs      r�test_is_trackedzGCTests.test_is_trackedbs���
	
�����t�,�,�-�-�-������q�)�)�*�*�*������s�+�+�,�,�,������z�2�2�3�3�3������t�,�,�-�-�-������u�-�-�.�.�.������t�,�,�-�-�-������s�+�+�,�,�,������y����7�7�8�8�8������t�,�,�-�-�-������s�+�+�,�,�,������v�.�.�/�/�/������v�x�x�0�0�1�1�1�	�	�	�	�	�	�	�	�	�	�	�	�	�c�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�U�	�	�	�	�	�	�	�	�3�	�	�	�	
����
�b�)�)�*�*�*�����
�i�0�0�1�1�1�����
�i�i�k�k�2�2�3�3�3�����
�g�g�i�i�0�0�1�1�1�����
�b�)�)�*�*�*�����
�c�e�e�,�,�-�-�-�����
�n�n�&6�&6�7�7�8�8�8�����
�n�n�&6�&6�7�7�8�8�8�����
�l�l�n�n�5�5�6�6�6�6�6rc�x��|�tjd����g�G�fd�d��}|��}|�tj|����~tj������}|�tj|����dS)Nr2c���eZdZ�fd�ZdS)�*GCTests.test_is_finalized.<locals>.Lazarusc�2����|��dSr$r�)r'�storages �rr�z2GCTests.test_is_finalized.<locals>.Lazarus.__del__�s������t�$�$�$�$�$rNr�)r]s�r�Lazarusr[�s.�������
%�
%�
%�
%�
%�
%�
%rr^)r�rF�is_finalizedrGr�rV)r'r^�lazarusr]s   @r�test_is_finalizedzGCTests.test_is_finalized�s����������+�+�,�,�,���	%�	%�	%�	%�	%�	%�	%�	%�	%�	%��'�)�)��������1�1�2�2�2��
�
�����+�+�-�-��������0�0�1�1�1�1�1rc�����g���fd��d�td��D��}�fd�|D���d}tj��|�t	���d��d}tj��|�t	���d���D]}|�|d���dS)Nc�*��d��D���dd�<dS)Nc�"�g|]}|����
Srr)�.0r4s  r�
<listcomp>z>GCTests.test_bug1055820b.<locals>.callback.<locals>.<listcomp>�s��*�*�*��r�r�t�t�*�*�*rr)r/�WRs�ouchs ��r�callbackz*GCTests.test_bug1055820b.<locals>.callback�s"���*�*�c�*�*�*�D����G�G�Grc�,�g|]}t|����Sr)r"�rer%s  rrfz,GCTests.test_bug1055820b.<locals>.<listcomp>�s��
,�
,�
,�a�h�q�k�k�
,�
,�
,rrRc�:��g|]}tj|�����Sr)r2r3)rer�ris  �rrfz,GCTests.test_bug1055820b.<locals>.<listcomp>�s%���4�4�4�A�w�{�1�h�'�'�4�4�4rr)r�rFrGrHr�)r'�Csr�r�rgrirhs    @@@r�test_bug1055820bzGCTests.test_bug1055820b�s��������	+�	+�	+�	+�	+�	+�-�
,�5��8�8�
,�
,�
,��4�4�4�4��4�4�4����
�
��������T���A�&�&�&���
�
��������T���A�&�&�&��	&�	&�A�
���Q��%�%�%�%�	&�	&rc����tj��Gd�d���Gd�d�����fd�}|��tj��dS)Nc��eZdZdS)� GCTests.test_bug21435.<locals>.ANrXrrrrYrq�rZrrYc��eZdZd�Zd�ZdS)� GCTests.test_bug21435.<locals>.Bc��||_dSr$r)r'r�s  rr(z)GCTests.test_bug21435.<locals>.B.__init__�rrc��d|_dSr$�r	r:s rr�z(GCTests.test_bug21435.<locals>.B.__del__�s
�� ��	�	�	rN)rrrr(r�rrrrnrs�s2������
�
�
�
!�
!�
!�
!�
!rrnc�^�����}������}||_||_dSr$rv)r\r�rYrns  ��r�do_workz&GCTests.test_bug21435.<locals>.do_work�s3�������A���!�!�#�#���A��A�F��A�F�F�Fr)rFrG)r'rxrYrns  @@r�
test_bug21435zGCTests.test_bug21435�s�����	�
����	�	�	�	�	�	�	�	�	!�	!�	!�	!�	!�	!�	!�	!�	�	�	�	�	�	�	��	�	�	�
�
�����rc�^���ddl�d}��fd�}||dz��}��d|����d|��||dz��}��d|����d	|vpd
|v|��||dz��}��d|��dS)
Nra�if 1:
            import gc
            import _testcapi
            @_testcapi.with_tp_del
            class X:
                def __init__(self, name):
                    self.name = name
                def __repr__(self):
                    return "<X %%r>" %% self.name
                def __tp_del__(self):
                    pass

            x = X('first')
            x.x = x
            x.y = X('second')
            del x
            gc.set_debug(%s)
        c�\����tjdd|g�j�j���}|���\}}|j���|j�����|j	d����|d��|S)Nz-Wdr��r�r�rr)
�Popenr��
executable�PIPE�communicater��closer�rH�
returncode)r��pr�r�r'�
subprocesss    ��r�run_commandz5GCTests.test_garbage_at_shutdown.<locals>.run_command�s����� � �#�.�%��t�!D�!��!��!�(�(�A��]�]�_�_�N�F�F�
�H�N�N����
�H�N�N�������Q�\�1�-�-�-����V�S�)�)�)��Mr�0s=ResourceWarning: gc: 2 uncollectable objects at shutdown; uses<X 'first'>zgc.DEBUG_UNCOLLECTABLEs8ResourceWarning: gc: 2 uncollectable objects at shutdowns[<X 'first'>, <X 'second'>]s[<X 'second'>, <X 'first'>]zgc.DEBUG_SAVEALLs!uncollectable objects at shutdown)r��assertIn�assertNotInrV)r'r�r�r�r�s`   @r�test_garbage_at_shutdownz GCTests.test_garbage_at_shutdown�s����	������$		�		�		�		�		�		���T�C�Z�(�(���
�
�'�(.�	0�	0�	0������0�0�0���T�$<�<�=�=���
�
�"�#)�	+�	+�	+����
+�v�
5�
7�
+�v�
5��	@�	@�	@���T�$6�6�7�7�����=�v�F�F�F�F�Frc��d}td|��\}}}|�|���d��dS)Nz�if 1:
            class C:
                def __del__(self):
                    print('__del__ called')
            l = [C()]
            l.append(l)
            r��__del__ called)rrH�strip)r'r�r��out�errs     r�test_gc_main_module_at_shutdownz'GCTests.test_gc_main_module_at_shutdown
sE����(��d�3�3���C����������&7�8�8�8�8�8rc��t��5}d}d|�d�}t|d|��td|��\}}}|�|���d��ddd��dS#1swxYwYdS)Nz�if 1:
                class C:
                    def __del__(self):
                        print('__del__ called')
                l = [C()]
                l.append(l)
                zDif 1:
                import sys
                sys.path.insert(0, z0)
                import gctest
                �gctestr�r�)rrrrHr�)r'�
script_dir�moduler�r�r�r�s       r�#test_gc_ordinary_module_at_shutdownz+GCTests.test_gc_ordinary_module_at_shutdowns���
�Z�Z�	=�:��F�F�"�z�z�	$�D�

�
�H�f�5�5�5�+�D�$�7�7�L�B��S����S�Y�Y�[�[�*;�<�<�<�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=����	=�	=�	=�	=�	=�	=s�AA2�2A6�9A6c�R�d}|�tt��ttdd���5}|�|��ddd��n#1swxYwYtt��\}}}|�|���d��dS)Nz�if 1:
            class ClassWithDel:
                def __del__(self):
                    print('__del__ called')
            a = ClassWithDel()
            a.link = a
            raise SystemExit(0)�wzutf-8)�encodingr�)�
addCleanupr
r	�open�writerrHr�)r'r��scriptr�r�r�s      r�test_global_del_SystemExitz"GCTests.test_global_del_SystemExit-s���#��	
�����'�'�'�
�&�#��
0�
0�
0�	�F��L�L�����	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�'��/�/���C����������&7�8�8�8�8�8s�A�A �#A c�*�tj��}|�t|��d��|D]�}|�|t
��|�t
|��hd���|�|dd��|�|dd��|�|dd����tj��r2|�	tj
��tj��tj��}tjd��tj��}|�|dd|dddz��|�|dd|dd��|�|dd|dd��tjd��tj��}|�|dd|dddz��|�|dd|dd��|�|dd|dddz��dS)	Nr2>�	collected�collections�
uncollectabler�rr�r�rCrR)
rF�	get_statsrHr��assertIsInstance�dictrW�assertGreaterEqual�	isenabledr�r�r�rG)r'�stats�st�old�news     r�test_get_statszGCTests.test_get_stats;s:�����������U���Q�'�'�'��	<�	<�B��!�!�"�d�+�+�+����S��W�W�J�J�J�
L�
L�
L��#�#�B�{�O�Q�7�7�7��#�#�B�}�$5�q�9�9�9��#�#�B��$7��;�;�;�;�
�<�>�>�	��O�O�B�I�&�&�&��J�L�L�L��l�n�n��
�
�1�
�
�
��l�n�n������Q��
�.��A��}�0E��0I�J�J�J�����Q��
�.��A��}�0E�F�F�F�����Q��
�.��A��}�0E�F�F�F�
�
�1�
�
�
��l�n�n������Q��
�.��A��}�0E��0I�J�J�J�����Q��
�.��A��}�0E�F�F�F�����Q��
�.��A��}�0E��0I�J�J�J�J�Jrc���tj��|�tj��d��tj��|�tj��d��dSr)rF�freezer��get_freeze_count�unfreezerHr:s r�test_freezezGCTests.test_freezeUs\��
�	�������2�.�0�0�!�4�4�4�
��
�
�
�����,�.�.��2�2�2�2�2rc���tj��g������|�t	�fd�tjd���D������|�t	�fd�tjd���D������|�t	�fd�tjd���D������tjd���|�t	�fd�tjd���D������|�t	�fd	�tjd���D������|�t	�fd
�tjd���D������tjd���|�t	�fd�tjd���D������|�t	�fd�tjd���D������|�t	�fd
�tjd���D������tjd���|�t	�fd�tjd���D������|�t	�fd�tjd���D������|�t	�fd�tjd���D�������tj��dS)Nc3� �K�|]}�|uV��	dSr$r�re�elementrJs  �r�	<genexpr>z+GCTests.test_get_objects.<locals>.<genexpr>`�'�����M�M�W�A��L�M�M�M�M�M�Mrr��
generationc3� �K�|]}�|uV��	dSr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>c�'�����N�N�W�A��L�N�N�N�N�N�NrrCc3� �K�|]}�|uV��	dSr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>fr�rrRc3� �K�|]}�|uV��	dSr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>jr�rc3� �K�|]}�|uV��	dSr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>mr�rc3� �K�|]}�|uV��	dSr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>pr�rc3� �K�|]}�|uV��	dSr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>tr�rc3� �K�|]}�|uV��	dSr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>wr�rc3� �K�|]}�|uV��	dSr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>zr�rc3� �K�|]}�|uV��	dSr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>~r�rc3� �K�|]}�|uV��	dSr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>�r�rc3� �K�|]}�|uV��	dSr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>�r�r)rFrGrErV�any�get_objectsr�rIs @r�test_get_objectszGCTests.test_get_objects[s����
�
������	�����������M�M�M�M���!�0L�0L�0L�M�M�M�M�M�	
�	
�	
�	
����N�N�N�N���1�1M�1M�1M�N�N�N�N�N�	
�	
�	
�	
����M�M�M�M���!�0L�0L�0L�M�M�M�M�M�	
�	
�	
�	�
�a� � � � �����M�M�M�M���!�0L�0L�0L�M�M�M�M�M�	
�	
�	
�	
����N�N�N�N���1�1M�1M�1M�N�N�N�N�N�	
�	
�	
�	
����M�M�M�M���!�0L�0L�0L�M�M�M�M�M�	
�	
�	
�	�
�a� � � � �����M�M�M�M���!�0L�0L�0L�M�M�M�M�M�	
�	
�	
�	
����N�N�N�N���1�1M�1M�1M�N�N�N�N�N�	
�	
�	
�	
����M�M�M�M���!�0L�0L�0L�M�M�M�M�M�	
�	
�	
�	�
�a� � � � �����M�M�M�M���!�0L�0L�0L�M�M�M�M�M�	
�	
�	
�	
����N�N�N�N���1�1M�1M�1M�N�N�N�N�N�	
�	
�	
�	
����M�M�M�M���!�0L�0L�0L�M�M�M�M�M�	
�	
�	
�
�
�
�����rc��tj��|�ttj����ttjd�������|�ttjd��|�ttjd��|�ttjd��|�ttjd��dS)Nr�i�i����1gX9��v��?)rFrGrHr�r��assertRaises�
ValueErrorrr:s r�test_get_objects_argumentsz"GCTests.test_get_objects_arguments�s���
�
��������R�^�-�-�.�.��R�^�t�<�<�<�=�=�	?�	?�	?�	
���*�b�n�d�;�;�;����*�b�n�e�<�<�<����)�R�^�S�9�9�9����)�R�^�U�;�;�;�;�;rc�p��Gd�d��}G�fd�d|���tj��tj�����}|��jd��~tj��|��jd��|�t�j��d���j���|��jd��tj��|��jd��tj��dS)Nc��eZdZd�ZdS)�AGCTests.test_resurrection_only_happens_once_per_object.<locals>.Ac��||_dSr$��mer:s rr(zJGCTests.test_resurrection_only_happens_once_per_object.<locals>.A.__init__��
������rNr)rrrrYr���#������
�
�
�
�
rrYc�"��eZdZdZgZ�fd�ZdS)�GGCTests.test_resurrection_only_happens_once_per_object.<locals>.Lazarusrc�\���xjdz
c_�j�|��dSrB)�resurrected�resurrected_instancesrE�r'r^s �rr�zOGCTests.test_resurrection_only_happens_once_per_object.<locals>.Lazarus.__del__�s4����#�#�q�(�#�#��-�4�4�T�:�:�:�:�:rN)rrrr�r�r��r^s�rr^r��s9��������K�$&�!�
;�
;�
;�
;�
;�
;�
;rr^rrC)	rFrGr�rHr�r�r��clearr�)r'rY�lazr^s   @r�.test_resurrection_only_happens_once_per_objectz6GCTests.test_resurrection_only_happens_once_per_object�sJ���	�	�	�	�	�	�	�	�	;�	;�	;�	;�	;�	;�	;�a�	;�	;�	;�	�
����
�
�����g�i�i������,�a�0�0�0�
�
�
��������,�a�0�0�0�����W�:�;�;�Q�?�?�?�	�%�+�+�-�-�-�����,�a�0�0�0�
�
��������,�a�0�0�0�
�	�����rc�|��Gd�d��}G�fd�d���tj��tj�����}|��}t|��}||_||_~~tj��|�t�j��d���j�	��}|�
t|d����|�t|j��|��tj��tj��dS)Nc��eZdZd�ZdS)�6GCTests.test_resurrection_is_transitive.<locals>.Cargoc��||_dSr$r�r:s rr(z?GCTests.test_resurrection_is_transitive.<locals>.Cargo.__init__�r�rNr)rrr�Cargor��r�rr�c���eZdZgZ�fd�ZdS)�8GCTests.test_resurrection_is_transitive.<locals>.Lazarusc�<���j�|��dSr$)r�rEr�s �rr�z@GCTests.test_resurrection_is_transitive.<locals>.Lazarus.__del__�s ����-�4�4�T�:�:�:�:�:rN)rrrr�r�r�s�rr^r��s4�������$&�!�
;�
;�
;�
;�
;�
;�
;rr^rC�cargo)
rFrGr�r�r�r�rHr�r�r�rV�hasattrr�)r'r�r�r��cargo_id�instancer^s      @r�test_resurrection_is_transitivez'GCTests.test_resurrection_is_transitive�sC���	�	�	�	�	�	�	�	�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	�
����
�
�����g�i�i��������e�9�9����	���	�
��
�
��������W�:�;�;�Q�?�?�?��0�4�4�6�6�������'�2�2�3�3�3�����H�N�+�+�X�6�6�6�
�
����
�	�����rc����d}Gd�d��}G�fd�d|��}g�d�}tj��tj��|��\}}t|��D]}|���
tj��}|��\}	}
|�||��|�|	|z
|��|�|
|z
d��|	|
}}|��tj��}|��\}	}
|�|d��|�|	|z
d��|�|
|z
d��|	|
}}t|��D]}|���
|��tj��}|��\}	}
|�||��|�|	|z
|��|�|
|z
d��|	|
}}����tj��}|��\}	}
|�|d��|�|	|z
d��|�|
|z
d��tj��dS)	N�dc��eZdZd�ZdS)�LGCTests.test_resurrection_does_not_block_cleanup_of_other_objects.<locals>.Ac��||_dSr$r�r:s rr(zUGCTests.test_resurrection_does_not_block_cleanup_of_other_objects.<locals>.A.__init__�r�rNr)rrrrYr��r�rrYc���eZdZ�fd�ZdS)�LGCTests.test_resurrection_does_not_block_cleanup_of_other_objects.<locals>.Zc�2����|��dSr$r�)r'�zss �rr�zTGCTests.test_resurrection_does_not_block_cleanup_of_other_objects.<locals>.Z.__del__�s����	�	�$�����rNr�)r�s�r�Zr��s.�������
 �
 �
 �
 �
 �
 �
 rr�c�T�tj��d}|d|dfS)N���r�r�)rFr�)rOs r�getstatszSGCTests.test_resurrection_does_not_block_cleanup_of_other_objects.<locals>.getstats�s&������r�"�A��[�>�1�_�#5�5�5rrrR)rFrGr�r�rHr�r�)r'r�rYr�r��oldc�oldncr%rSr��ncr�s           @r�9test_resurrection_does_not_block_cleanup_of_other_objectszAGCTests.test_resurrection_does_not_block_cleanup_of_other_objects�s����

��	�	�	�	�	�	�	�	�	 �	 �	 �	 �	 �	 �	 ��	 �	 �	 ���	6�	6�	6�	�
����
�
�����h�j�j���e��q���	�	�A�
�A�C�C�C�C��J�L�L����
�
���2�����A��������T��1�%�%�%�����e��Q�'�'�'���e��	������J�L�L����
�
���2�����A��������T��1�%�%�%�����e��Q�'�'�'���e���q���	�	�A�
�A�C�C�C�C�	������J�L�L����
�
���2�����A��������T��1�%�%�%�����e��Q�'�'�'���e��
���
�
�
��J�L�L����
�
���2�����A��������T��1�%�%�%�����e��Q�'�'�'�
�	�����rNz%requires ContainerNoGC extension typec��tj���}Gd�d��}Gd�d��}|��}||_t	|����|_t
j|jj|��|_	|j	g}|�
|��tj��tj
��~~tj��|���tj��dS)Nc��eZdZgd�ZdS)�+GCTests.test_trash_weakref_clear.<locals>.A)r\�y�wzNrGrrrrYr�>s������(�(�(�I�I�IrrYc��eZdZdS)�+GCTests.test_trash_weakref_clear.<locals>.ZNrXrrrr�rArZrr�)�unittest�mock�Mockr\r r�r2r3�valuerrErFrGr��assert_not_calledr�)r'rirYr�r\�wr_cycles      r�test_trash_weakref_clearz GCTests.test_trash_weakref_clears��@�=�%�%�'�'��	)�	)�	)�	)�	)�	)�	)�	)�	�	�	�	�	�	�	�	�
�A�C�C������A�A�C�C� � ����{�1�3�9�h�/�/����D�6������!�!�!�
�
����
�
����
�x�
�
����	�"�"�$�$�$�
�	�����r)4rrrrKrPrTr_rcrhrrrxrr�r�r�r�rr�r�r�r�r�r�r�r
�requires_working_threadingrrr"r)r0r<rXrarnryrr�r�r�r�r�r�r�r�r�r�r�r�skipIfr r	rrrr@r@Vs-������*�*�*�*�*�*�*�*�*�-�-�-�-�-�-�-�-�-�*�*�*�0-�-�-�����\��2����\��2*�*�*�A!�A!�A!�F�*�*��]�*�(�(�(�0
&�
&�
&�
&�
&�
&�*�!�!��]�!��)�)��]�)�(!�!�!�F1��0�2�2�84�84�3�2�84�t6�6�6�06�6�6�66�6�6�(6�6�6�,;�;�;�.-7�-7�-7�^2�2�2�$&�&�&�0���@�����.G�.G����\�.G�`9�9�9�=�=�=�&9�9�9�K�K�K�43�3�3�,�,�,�\<�<�<�"�"�"�H � � �DA�A�A�F�X�_�]�d�*�<�>�>�7�7�>�>�7�7�7rr@c��eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	e
d���Zej
ed	��d
���ZdS)�GCCallbackTestsc�R�tj��|_tj��tj��|_tjd��tj�|j	��tj�|j
��g|_dSr)rFr��enabledr�r�r�r��	callbacksrE�cb1�cb2�othergarbager:s r�setUpzGCCallbackTests.setUpYsr���|�~�~���
�
�����\�^�^��
�
��Q����
����D�H�%�%�%�
����D�H�%�%�%�����rc���|`tj�|j��tj�|j��tj|j��|jrtj	��tj
��tjD]}t|t��rd|_�tjdd�=|`tj
��dSr$)�visitrFrr�rrr�r�rr�rGr��
isinstancer6r8r)r'r�s  r�tearDownzGCCallbackTests.tearDowncs����J�
����D�H�%�%�%�
����D�H�%�%�%�
��T�Z� � � ��<�	��I�K�K�K�
�
�����:�	#�	#�C��#�}�-�-�
#�"�����J�q�q�q�M���
�
�����rc���g|_tj��tjdd�gc}tjdd�<|j�|��g|_dSr$)rrFrGr�rrE)r'r�s  r�precleanzGCCallbackTests.precleantsX����
�
�
����!#��A�A�A�������A�A�A���� � ��)�)�)���
�
�
rc�Z�|j�d|t|��f��dSrB)rrEr�)r'�phase�infos   rrzGCCallbackTests.cb1~s+���
���1�e�T�$�Z�Z�0�1�1�1�1�1rc��|j�d|t|��f��|dkrWt|d��rId�tjD��}d�tjD��tjdd�<|D]
}d|_�
dSdSdS)NrR�stop�cleanupc�<�g|]}t|t���|��Sr�rr6�rer�s  rrfz'GCCallbackTests.cb2.<locals>.<listcomp>�s'��H�H�H��:�a��+G�+G�H�!�H�H�Hrc�<�g|]}t|t���|��Srr"r#s  rrfz'GCCallbackTests.cb2.<locals>.<listcomp>�s=��B�B�B�1�$.�q�-�$@�$@�B�Q�B�B�Br)rrEr�r�rFr�r8)r'rr�ucr�s     rrzGCCallbackTests.cb2�s����
���1�e�T�$�Z�Z�0�1�1�1��F�?�?�w�t�Y�7�7�?�H�H�R�Z�H�H�H�B�B�B��
�B�B�B�B�J�q�q�q�M��
!�
!�� ��	�	�
�?�?�?�

!�
!rc�v�|���tj��d�|jD��}d�|D��}d�|D��}|�|dgdz��|�|dgdz��d�|jD��}d�|D��}d�|D��}|�|d	gdz��|�|d
gdz��|jD]O}|d}|�d|v��|�d|v��|�d
|v���PdS)Nc��g|]
}|d��S)rr�rer�s  rrfz0GCCallbackTests.test_collect.<locals>.<listcomp>����&�&�&�a�Q�q�T�&�&�&rc��g|]
}|dk�|��S�rCrrks  rrfz0GCCallbackTests.test_collect.<locals>.<listcomp>����
%�
%�
%�A�a�1�f�f�a�f�f�frc��g|]
}|dk�|��S)rRrrks  rrfz0GCCallbackTests.test_collect.<locals>.<listcomp>�r,rrCrRc��g|]
}|d��Sr+rr(s  rrfz0GCCallbackTests.test_collect.<locals>.<listcomp>�r)rc��g|]
}|dk�|��S)�startrrks  rrfz0GCCallbackTests.test_collect.<locals>.<listcomp>�s��
+�
+�
+�A�a�7�l�l�a�l�l�lrc��g|]
}|dk�|��S)rrrks  rrfz0GCCallbackTests.test_collect.<locals>.<listcomp>�s��
*�
*�
*�A�a�6�k�k�a�k�k�krr0rr�r�r�)rrFrGrrHrV)r'r��n1�n2r�rs      r�test_collectzGCCallbackTests.test_collect�sr���
�
����
�
����

'�&�4�:�&�&�&��
%�
%��
%�
%�
%��
%�
%��
%�
%�
%������a�S��U�#�#�#�����a�S��U�#�#�#�
'�&�4�:�&�&�&��
+�
+��
+�
+�
+��
*�
*��
*�
*�
*������g�Y�q�[�)�)�)�����f�X�a�Z�(�(�(���	5�	5�A��Q�4�D��O�O�L�D�0�1�1�1��O�O�K�4�/�0�0�0��O�O�O�t�3�4�4�4�4�		5�	5rc��|���tjd��|jD]&}|d}|�|dd���'dS)NrRr�)rrFrGrrH)r'r�rs   r�test_collect_generationz'GCCallbackTests.test_collect_generation�s^���
�
����
�
�1�
�
�
���	4�	4�A��Q�4�D����T�,�/��3�3�3�3�	4�	4rc�r�|���t��t��td��tj��|jD]O}|ddkr�|d}|�|dd��|�|dd���P|�ttj��d��tjD]}|�	|t���d|_
g|_gtjdd�<tj��|jD]O}|ddkr�|d}|�|dd	��|�|dd���P|�ttj��d	��dS)
Nr1rCrrRr�r�r4Tr)rr6r"rFrGrrHr�r�r�r )r'r�rr�s    r�test_collect_garbagez$GCCallbackTests.test_collect_garbage�s����
�
��������������
�
�
�
�
������	7�	7�A���t�v�~�~���Q�4�D����T�+�.��2�2�2����T�/�2�A�6�6�6�6�	
����R�Z���!�,�,�,���	4�	4�A��!�!�!�]�3�3�3�3������
���
�1�1�1�
�
�
������	7�	7�A���t�v�~�~���Q�4�D����T�+�.��2�2�2����T�/�2�A�6�6�6�6�	
����R�Z���!�,�,�,�,�,rzbuilt with -NDEBUGc��|���td��ddl}tjd��}|�tjd|g|j|j���}|�	��\}}|j
���|j���|�
|d��|�
|d��d}|�
|d	|z��|�
|d
��|�
|d|z��|�
|d��|�
|d
��dS)N�ctypesra�
            from test.support import gc_collect, SuppressCrashReport

            a = [1, 2, 3]
            b = [a]

            # Avoid coredump when Py_FatalError() calls abort()
            SuppressCrashReport().__enter__()

            # Simulate the refcount of "a" being too low (compared to the
            # references held on it by live data), but keeping it above zero
            # (to avoid deallocating it):
            import ctypes
            ctypes.pythonapi.Py_DecRef(ctypes.py_object(a))

            # The garbage collector should now have a fatal error
            # when it reaches the broken object
            gc_collect()
        r�r|sGgcmodule\.c:[0-9]+: gc_decref: Assertion "gc_get_refs\(g\) > 0" failed.srefcount is too smalls
[0-9a-fA-Fx]+sobject address  : sobject refcount : 1sobject type     : sobject type name: listsobject repr     : \[1, 2, 3\])rrr��textwrap�dedentr}r�r~rr�r�r�r�r�)r'r�r�r�r�r��
address_regexs       r�test_refcount_errorsz$GCCallbackTests.test_refcount_errors�s���	
�
�
����	�h���������� �
�
��&
���c�n�d�D�9�$.�O�$.�O�
�
5�
5����������	�������	�����������W�	Y�	Y�	Y�����%�	'�	'�	'�*�
�����"�]�2�	4�	4�	4�����#�	%�	%�	%�����"�]�2�	4�	4�	4�����&�	(�	(�	(�����-�	/�	/�	/�	/�	/rN)rrrrrrrrr4r6rr8rr�BUILD_WITH_NDEBUGr>rrrr
r
Xs�������������"���2�2�2�!�!�!�5�5�5�64�4�4�� -� -��\� -�F�X�_�&�)�+�+�2/�2/�+�+�2/�2/�2/rr
c�&�eZdZd�Zd�Zd�Zd�ZdS)�GCTogglingTestsc�,�tj��dSr$)rFr�r:s rrzGCTogglingTests.setUp	s��
�	�����rc�,�tj��dSr$)rFr�r:s rrzGCTogglingTests.tearDowns��
�
�����rc�v�
��td��}tj��td��}||_|`td��}tj|���
g��
�fd�}tj||��}dx}x}}g}d}t��}|js_|dz
}|dkr|�	d��|�
t���d��|�g��|j�_|�
t���d���D]}	|�
|	d���dS)NrrCrRc�(�����g�dd�<dSr$r)r/�c2wrrhs ��rriz2GCTogglingTests.test_bug1055820c.<locals>.callbacks����t�v�v�h�D����G�G�Gr�'�'gc didn't happen after 10000 iterations)
r"rFrG�
keep_c0_aliver&r2r3r+r.r�rHr�rE)r'�c0�c1�c2ri�c0wr�junkr%�detectorr�rFrhs          @@r�test_bug1055820cz GCTogglingTests.test_bug1055820csa�����a�[�[��
�
����
�a�[�[������G�
�a�[�[���{�2������	�	�	�	�	�	��{�2�x�(�(������R�"�@��
���=�=���&�	�
��F�A��5�y�y��	�	�C�D�D�D����S��Y�Y��*�*�*��K�K��O�O�O��&�	�	
����T���A�&�&�&��	&�	&�A�
���Q��%�%�%�%�	&�	&rc�d�	�
�g�
G�	�
fd�dt��}|d��}tj��td��}||_|`td��}tj|���	dx}x}}t��}g}d}|js_|dz
}|dkr|�	d��|�
t�
��d��|�g��|j�_|�
t�
��d���
D]}|�
|d���dS)Nc���eZdZ��fd�ZdS)�+GCTogglingTests.test_bug1055820d.<locals>.Dc�(�����g�dd�<dSr$r)r'rFrhs ��rr�z3GCTogglingTests.test_bug1055820d.<locals>.D.__del__\s����4�6�6�(��Q�Q�Q���rNr�)rFrhs��r�DrS[s3�������
#�
#�
#�
#�
#�
#�
#�
#rrUrrCrRrGrH)
r"rFrG�
keep_d0_aliver&r2r3r+r.r�rHr�rE)r'rU�d0rKrLrOrNr%r�rFrhs         @@r�test_bug1055820dz GCTogglingTests.test_bug1055820dUsl����
��	#�	#�	#�	#�	#�	#�	#�	#��	#�	#�	#��Q�q�T�T��
�
����
�a�[�[������G�
�a�[�[���{�2��������R�"�<�=�=����
���&�	�
��F�A��5�y�y��	�	�C�D�D�D����S��Y�Y��*�*�*��K�K��O�O�O��&�	�	
����T���A�&�&�&��	&�	&�A�
���Q��%�%�%�%�	&�	&rN)rrrrrrPrXrrrrArAsY������������D&�D&�D&�LA&�A&�A&�A&�A&rrAc��eZdZd�ZdS)�PythonFinalizationTestsc�N�tjd��}td|��dS)Na 
            import ast
            import codecs

            # Small AST tree to keep their AST types alive
            tree = ast.parse("def f(x, y): return 2*x-y")
            x = [tree]
            x.append(x)

            # Put the cycle somewhere to survive until the last GC collection.
            # Codec search functions are only cleared at the end of
            # interpreter_clear().
            def search_func(encoding):
                return None
            search_func.a = x
            codecs.register(search_func)
        r�)r;r<r)r'r�s  r�
test_ast_finiz%PythonFinalizationTests.test_ast_fini�s2���� �
�
��"	��t�$�$�$�$�$rN)rrrr\rrrrZrZ�s#������%�%�%�%�%rrZc���tj��atj��tj��atjt
tjz��tj��dSr$)	rFr�rr�r�r�r��
DEBUG_LEAKrGrrr�setUpModuler_�sK���l�n�n�G��J�L�L�L��L�N�N�E��L��"�-��'�(�(�(��J�L�L�L�L�Lrc���tjt��trt	d��tj��tstj��dSdS)Nzrestoring automatic collection)rFr�r�r�printr�rr�rrr�tearDownModulerb�sU���L������0�
�.�/�/�/��I�K�K�K���
�
�������r�__main__)-r�
unittest.mock�test.supportrrrr�test.support.import_helperr�test.support.os_helperrr	r
�test.support.script_helperrrr
rFr��	sysconfigr;r�r�r2�	_testcapir�ImportErrorr rr"r+r6�get_config_vars�getr?r��TestCaser@r
rArZr_rbr�mainrrr�<module>rpsz����������=�=�=�=�=�=�=�=�=�=�=�=�4�4�4�4�4�4�;�;�;�;�;�;�;�;�;�;�D�D�D�D�D�D�D�D�)�)�)�)�)�)�	�	�	�	�
�
�
�
����������������������%�%�%�%�%�%�%����������������'�'�'�'�'�'�'�������M�M�M����������v����
:�:�:�:�:�&�:�:�:�
�

�

�

�

�

�F�

�

�
��

��9����"�"�;��3�3�?�#�'@�y�'@�'B�'B�;�'O�O���
%�W�S�*<�=�=�=��
�����h�����D m/�m/�m/�m/�m/�h�'�m/�m/�m/�`N&�N&�N&�N&�N&�h�'�N&�N&�N&�b%�%�%�%�%�h�/�%�%�%�6���	�	�	��z����H�M�O�O�O�O�O��s$�A�A"�!A"�&A-�-A7�6A7