Sindbad~EG File Manager

Current Path : /proc/2568807/root/usr/local/lib/python3.12/test/__pycache__/
Upload File :
Current File : //proc/2568807/root/usr/local/lib/python3.12/test/__pycache__/test_gc.cpython-312.opt-1.pyc

�

'Μgؾ���ddlZddlZddlmZmZmZmZddlmZddl	m
Z
mZmZddl
mZmZddlmZddlZddlZddlZddlZddlZddlZddlZ	ddlmZ	dd	lmZGd
�de�ZGd�d
e�ZeGd�de��Zej@�jCdd�rdej@�dvZ"n
e#ed�Z"Gd�dejH�Z%Gd�dejH�Z&Gd�dejH�Z'Gd�dejH�Z(d�Z)d�Z*e+dk(rejX�yy#e$rd�ZY��wxYw#e$rdZY��wxYw)�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�Zy)�with_tp_del.<locals>.Cc��td��)Nzrequires _testcapi.with_tp_del)�	TypeError)�cls�args�kwargss   �)/usr/local/lib/python3.12/test/test_gc.py�__new__zwith_tp_del.<locals>.C.__new__s��� @�A�A�N)�__name__�
__module__�__qualname__r�rr�Crs��
Brr)�object)rrs  rrrs��	B��	B��r)�
ContainerNoGCc��eZdZd�Zy)�C1055820c� �||_||_y�N)�i�loop)�selfr%s  r�__init__zC1055820.__init__)s�������	rN�rrrr(rrrr"r"(s��rr"c��eZdZd�Zy)�GC_Detectorc�f��d�_�fd�}tjtd�|��_y)NFc���d�_y)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__1s(��� ���	$�
�+�+�h�s�m�[�9��rNr)rrrr+r+-s��:rr+c��eZdZdZdd�Zd�Zy)�
Uncollectablea)Create a reference cycle with multiple __del__ methods.

    An object in a reference cycle will never have zero references,
    and so must be garbage collected.  If one or more objects in the
    cycle have __del__ methods, the gc refuses to guess an order,
    and leaves the cycle uncollected.Nc�:�|�t|��|_y||_y)N)�partner)r6r8)r'r8s  rr(zUncollectable.__init__Cs���?�(��6�D�L�"�D�Lrc��yr$r�r's r�
__tp_del__zUncollectable.__tp_del__Hs��rr$)rrr�__doc__r(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�Zej2�d��Zd�Zd�Zd�Zd�Zd�Zd�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-e.j^e0d'ud(�d)��Z1y')*�GCTestsc��g}|j|�tj�~|jtj�d�y�N���append�gc�collect�assertEqual�r'�ls  r�	test_listzGCTests.test_listWs4����	�����
�
�
��
��������q�)rc��i}||d<tj�~|jtj�d�yrC�rGrHrI�r'�ds  r�	test_dictzGCTests.test_dict^s2������!��
�
�
��
��������q�)rc��g}|f}|j|�tj�~~|jtj�d�y)N�rE)r'rK�ts   r�
test_tuplezGCTests.test_tuplees>����
�D��	�����
�
�
��
�
��������q�)rc��Gd�d�}||_tj�~|jtj�d�y)Nc��eZdZy)�GCTests.test_class.<locals>.AN�rrrrrr�ArXp���rrZr��arGrH�assertNotEqual�r'rZs  r�
test_classzGCTests.test_classos5��	�	����
�
�
��
����B�J�J�L�!�,rc��Gd�dt�}tj�~|jtj�d�y)Nc��eZdZy)�%GCTests.test_newstyleclass.<locals>.ANrYrrrrZrcxr[rrZr)rrGrHr^r_s  r�test_newstyleclasszGCTests.test_newstyleclassws0��	��	�
�
�
��
����B�J�J�L�!�,rc��Gd�d�}|�}||_tj�~|jtj�d�y)Nc��eZdZy)� GCTests.test_instance.<locals>.ANrYrrrrZrgr[rrZrr\�r'rZr]s   r�
test_instancezGCTests.test_instance~s<��	�	�
�C�����
�
�
��
����B�J�J�L�!�,rc�j�Gd�dt�}|�}||_tj�~|j	tj�d�Gd�dt
�}Gd�d||�}|�}||_tj�~|j	tj�d�~~|j	tj�d�|�|_~|j	tj�d�|j
tj�d�y)Nc��eZdZy)�#GCTests.test_newinstance.<locals>.ANrYrrrrZrl�r[rrZrc��eZdZy)�#GCTests.test_newinstance.<locals>.BNrYrrr�Brn�r[rroc��eZdZy)�#GCTests.test_newinstance.<locals>.CNrYrrrrrq�r[rr)rr]rGrHr^�listrI)r'rZr]rors     r�test_newinstancezGCTests.test_newinstance�s���	��	�
�C�����
�
�
��
����B�J�J�L�!�,�	��	�	��1�	�
�C�����
�
�
��
����B�J�J�L�!�,�
�q����B�J�J�L�!�,��c���
����B�J�J�L�!�,��������q�)rc��Gd�d�}|�}tj�~|jtj�d�y)Nc��eZdZd�Zy)�GCTests.test_method.<locals>.Ac�&�|j|_yr$)r(�initr:s rr(z'GCTests.test_method.<locals>.A.__init__�s
�� �M�M��	rNr)rrrrZrv�s��
*rrZr)rGrHr^rhs   r�test_methodzGCTests.test_method�s7��	*�	*�
�C��
�
�
��
����B�J�J�L�!�,rc��tGd�d��}Gd�d�}|�}||_t|�}|�}||_t	j
�~~|j
t	j
�d�tjD]}t|�|k(s�|`n|jd�tjj�y)Nc��eZdZd�Zy)�(GCTests.test_legacy_finalizer.<locals>.Ac��yr$rr:s rr;z3GCTests.test_legacy_finalizer.<locals>.A.__tp_del__����$rN�rrrr;rrrrZr|����&rrZc��eZdZy)�(GCTests.test_legacy_finalizer.<locals>.BNrYrrrror��r[rror�&didn't find obj in garbage (finalizer))
rr]�id�brGrHr^�garbage�fail�remove�r'rZror]�id_ar��objs       r�test_legacy_finalizerzGCTests.test_legacy_finalizer�s���
�	'�	'�
�	'�	�	�
�C������!�u��
�C�����
�
�
��
�
����B�J�J�L�!�,��:�:�C��#�w�$���E���

�I�I�>�?�
�
�
���#�rc���tGd�dt��}Gd�dt�}|�}||_t|�}|�}||_tj�~~|jtj�d�t
jD]}t|�|k(s�|`n|jd�t
jj�y)Nc��eZdZd�Zy)�1GCTests.test_legacy_finalizer_newclass.<locals>.Ac��yr$rr:s rr;z<GCTests.test_legacy_finalizer_newclass.<locals>.A.__tp_del__�r~rNrrrrrZr��r�rrZc��eZdZy)�1GCTests.test_legacy_finalizer_newclass.<locals>.BNrYrrrror��r[rrorr�)rrr]r�r�rGrHr^r�r�r�r�s       r�test_legacy_finalizer_newclassz&GCTests.test_legacy_finalizer_newclass�s���
�	'��	'�
�	'�	��	�
�C������!�u��
�C�����
�
�
��
�
����B�J�J�L�!�,��:�:�C��#�w�$���E���

�I�I�>�?�
�
�
���#�rc��i}td|�tj�~|jtj�d�y)Nzdef f(): pass
rS)�execrGrHrIrOs  r�
test_functionzGCTests.test_function�s6��
���
��"�
�
�
��
��������q�)rc��d}td|�\}}}|j|d�|j|d�|j|�y)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)rrI�assertRegex�assertFalse)r'�code�rc�stdout�stderrs     r�.test_function_tp_clear_leaves_consistent_statez6GCTests.test_function_tp_clear_leaves_consistent_state�sN��:��x.�d�D�9���F�F�����Q������!J�K����� rc��d�}tj�|�|jtj�d�y)Nc�,�tj�}yr$)�sys�	_getframe)�frames r�fzGCTests.test_frame.<locals>.f+s
���M�M�O�ErrDrN)r'r�s  r�
test_framezGCTests.test_frame)s+��	$�
�
�
��	���������q�)rc�4�tj�|jtjg�g}|j	|�t|�}tj�}tj|tjz�~tj�tj|�|jttj�d�tjj�}|jt|�|�yrC)rGrHrIr�rFr��	get_debug�	set_debug�
DEBUG_SAVEALL�len�pop)r'�L�id_L�debugr�s     r�test_saveallzGCTests.test_saveall1s���	�
�
��������R�(���	������!�u�������
���U�R�-�-�-�.�
�
�
�
��
���U������R�Z�Z��!�,��j�j�n�n�������C��$�'rc���tj�}tj�tjd�Gd�d�}|�}~tj�tj|�y)NrDc��eZdZd�Zy)�GCTests.test_del.<locals>.Ac��t|�yr$��dirr:s r�__del__z#GCTests.test_del.<locals>.A.__del__P�	���D�	rN�rrrr�rrrrZr�O���
rrZ)rG�
get_threshold�enable�
set_threshold�disable�r'�
thresholdsrZr]s    r�test_delzGCTests.test_delIsT���%�%�'�
�
�	�	��
�����	�	�
�C��
�
�
�
��
���*�%rc��tj�}tj�tjd�Gd�dt�}|�}~tj
�tj|�y)NrDc��eZdZd�Zy)�$GCTests.test_del_newclass.<locals>.Ac��t|�yr$r�r:s rr�z,GCTests.test_del_newclass.<locals>.A.__del___r�rNr�rrrrZr�^r�rrZ)rGr�r�r�rr�r�s    r�test_del_newclasszGCTests.test_del_newclassXsV���%�%�'�
�
�	�	��
�����	��	�
�C��
�
�
�
��
���*�%rc�(�tj�tj�\}}}g}tj�\}}}|j||fd�|j||fd�|j	|d�|j||�y)N�rr�)rGrH�	get_countrI�
assertLess�
assertGreater)r'r]r��c�xrP�er�s        r�test_get_countzGCTests.test_get_countmsz��
�
�
���,�,�.���1�a����,�,�.���1�a����!�Q���(����!�Q���(�����1��	
���1�a� rc��tj�g}tjd�tj�\}}}tjd�tj�\}}}tjd�tj�\}}	}
|j||fd�|j||fd�|j|	|
fd�y)NrrDrS)rDr)rrDr�)rGrHr�rI)r'r�r]r�r�rPr�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�6��G�fd�d��tj�d}td�D]T}g}t|�D]}|��g}�
g}t|�D]}|��g}�
i}t|�D]}|��d�}��Vtj�y)Nc���eZdZdZ�fd�Zy)�#GCTests.test_trashcan.<locals>.Ouchrc�|���jdz�_�jdzdk(rtj�yy)NrD�r)�nrGrH)r'�Ouchs �rr�z+GCTests.test_trashcan.<locals>.Ouch.__del__�s0������!�����6�6�B�;�!�#��J�J�L�$rN)rrrr�r�)r�s�rr�r��s
����A�
!rr��rS)rDrS)rGr��ranger�)r'�N�countrTr%�u�vr�s       @r�
test_trashcanzGCTests.test_trashcan�s����	!�	!�(	�	�	�����1�X�E��A��1�X�����K����A��1�X�����K����A��1�X���d�f�%����	�
�
�rc����	�
��d�d}d��G��fd�dt����fd��
�	�
fd�}tj�}tjd�	g�	g}t	|�D])}tj|�	�}|j|��+tj|�	fd
��5tjd�ddd�tj|�tj�|jt�j �t�j"��y#1swY�kxYw#tj|�wxYw)N�<rSc3�tK�	d��tjd�y#tjd�wxYw�w)z<A generator that releases the GIL when closed or dealloc'ed.Ng���ư>)�time�sleeprrr�sleeper_genz2GCTests.test_trashcan_threads.<locals>.sleeper_gen�s&����
%���
�
�8�$���
�
�8�$�s�8��8�5�8c�,��eZdZgZgZ�fd�Z��fd�Zy)�(GCTests.test_trashcan_threads.<locals>.Cc�F��||dd�jjd�yr$)�initsrF)r'�alistrs  �rr(z1GCTests.test_trashcan_threads.<locals>.C.__init__�s�����Q�������t�$rc�`���jjd���}t|�yr$)�delsrF�next)r'r�rr�s  ��rr�z0GCTests.test_trashcan_threads.<locals>.C.__del__�s#������
�
�d�#� �M���Q�rN)rrrr�r�r(r�)rr�s��rrr��s����E��D�
%�
rrc�L���g�}t��D]}�|g�g}�~y)zyCreate a sufficiently nested container object so that the
            trashcan mechanism is invoked when deallocating it.N)r�)r�r%r�NESTINGs  ��r�make_nestedz2GCTests.test_trashcan_threads.<locals>.make_nested�s,����"��A��7�^����s�V�H��$�rc� ���s���s�
yy)z!Exercise make_nested() in a loop.Nr)�exitr�s��r�
run_threadz1GCTests.test_trashcan_threads.<locals>.run_thread�s�����
�rg�h㈵��>)�targetc�&���jd�SrC�rF)r�s�r�<lambda>z/GCTests.test_trashcan_threads.<locals>.<lambda>�s
������Q�r��?)rrr��getswitchinterval�setswitchintervalr��	threading�ThreadrFr
�
start_threadsr�r�rGrHrIr�r�r�)r'�	N_THREADSr��old_switchinterval�threadsr%rTrr�r�r�r�s       @@@@@r�test_trashcan_threadszGCTests.test_trashcan_threads�s�������	�	%�	��	�$	�	�
!�2�2�4�����d�#�		6��D��G��9�%���$�$�J�7�����q�!�&�"�/�/��9O�P��
�
�3��Q�
�!�!�"4�5�
�
�
������Q�W�W��s�1�6�6�{�3�Q�P��
�!�!�"4�5�s%�AD5�)D)�?D5�)D2�.D5�5Ec�H�Gd�d�}|�}|�}||_||_tj�ttj�}~~|jtj�d�|jttj�|�y)Nc��eZdZd�Zy)�GCTests.test_boom.<locals>.Boomc��|`t�r$)�attr�AttributeError�r'�
someattributes  r�__getattr__z+GCTests.test_boom.<locals>.Boom.__getattr__�s
���I�$�$rN)rrrr
rrr�Boomr�s��
%rrrS�r	rGrHr�r�rI)r'rr]r��
garbagelens     r�	test_boomzGCTests.test_boom�su��	%�	%�

�F���F��������
�
�
������_�
�
�q�	
�������q�)�����R�Z�Z��*�5rc�H�Gd�d�}|�}|�}||_||_tj�ttj�}~~|jtj�d�|jttj�|�y)Nc��eZdZd�Zd�Zy)�!GCTests.test_boom2.<locals>.Boom2c��d|_y�Nr�r�r:s rr(z*GCTests.test_boom2.<locals>.Boom2.__init__�	����rc�Z�|xjdz
c_|jdkDr|`t�rC)r�r	r
rs  rr
z-GCTests.test_boom2.<locals>.Boom2.__getattr__s%�����!����6�6�A�:��	�$�$rN)rrrr(r
rrr�Boom2rs��
�
%rrrSr)r'rr]r�rs     r�
test_boom2zGCTests.test_boom2su��	%�	%�
�G���G��������
�
�
������_�
�
�q�	
�������q�)�����R�Z�Z��*�5rc	�t�gd�}tj|�}|j�|j||�t	|�}tj|�}|j�|j||�ddd�}gd�}tj|�}|j�|j||�tjddgddid	�}|j�|j|d
d
gtt
d��z�|jtjddd
�g�y)N)rD�r�r�)rDr�)rDrr�rrDrS�)rrrrr�r]y@)rG�
get_referents�sortrI�tuplerrr�)r'r��got�atuple�adict�expecteds      r�test_get_referentszGCTests.test_get_referents!s��������u�%�����
�����e�$��u������v�&�����
�����e�$��!��������u�%�����
�����h�'�����1�v��1�v�y�9�����
�����q�!�f�t�E�!�H�~�5�6�����)�)�!�S�"�5�r�:rc�:�|jtjd��|jtjd��|jtjd��|jtjd��|jtjd��|jtjd��|jtjd��|jtjd��|jtjtd���|jtjt��|jtjt
��|jtjt��|jtjt
���Gd�d	�}Gd
�dt
�}Gd�d
�}Gd�dt�}Gd�dt
�}|jtjt��|jtj|��|jtj|���|jtj|���|jtjg��|jtjt���|jtj|���|jtj|���|jtj|���y)NrDr�y�?@TF�ar]c��eZdZy)�*GCTests.test_is_tracked.<locals>.UserClassNrYrrr�	UserClassr+Kr[rr,c��eZdZy)�(GCTests.test_is_tracked.<locals>.UserIntNrYrrr�UserIntr.Nr[rr/c��eZdZdZy)�/GCTests.test_is_tracked.<locals>.UserClassSlotsrN�rrr�	__slots__rrr�UserClassSlotsr1R����Irr4c��eZdZdZy)�/GCTests.test_is_tracked.<locals>.UserFloatSlotsrNr2rrr�UserFloatSlotsr7Vr5rr8c��eZdZdZy)�-GCTests.test_is_tracked.<locals>.UserIntSlotsrNr2rrr�UserIntSlotsr:Zr5rr;)
r�rG�
is_tracked�	bytearray�type�intr�float�
assertTrue�set)r'r,r/r4r8r;s      r�test_is_trackedzGCTests.test_is_tracked8s:��
	
������t�,�-�������q�)�*�������s�+�,�������z�2�3�������t�,�-�������u�-�.�������t�,�-�������s�+�,�������y���7�8�������t�,�-�������s�+�,�������v�.�/�������v�x�0�1�	�	�	�c�	�	�	�	�U�	�	�3�	�	
����
�
�b�)�*�����
�
�i�0�1�����
�
�i�k�2�3�����
�
�g�i�0�1�����
�
�b�)�*�����
�
�c�e�,�-�����
�
�n�&6�7�8�����
�
�n�&6�7�8�����
�
�l�n�5�6rc�R��|jtjd��g�G�fd�d�}|�}|jtj|��~tj��j	�}|jtj|��y)Nrc���eZdZ�fd�Zy)�*GCTests.test_is_finalized.<locals>.Lazarusc�(���j|�yr$r�)r'�storages �rr�z2GCTests.test_is_finalized.<locals>.Lazarus.__del__ms������t�$rNr�)rHs�r�LazarusrFls���
%rrI)r�rG�is_finalizedrHr�rA)r'rI�lazarusrHs   @r�test_is_finalizedzGCTests.test_is_finalizedgsu����������+�,���	%�	%��)���������1�2��
�
�
���+�+�-���������0�1rc����g���fd�}td�D�cgc]
}t|���}}|D�cgc]}tj||���c}�d}t	j
�|j
t��d�d}t	j
�|j
t��d��D]}|j
|d��ycc}wcc}w)Nc�@���D�cgc]	}|���c}�ddycc}wr$r)r/r4�WRs�ouchs  ��r�callbackz*GCTests.test_bug1055820b.<locals>.callback}s ���&)�*�c��r�t�c�*�D��G��*s�rSr)r�r"r2r3rGrHrIr�)r'rQr%�Csr�r�rOrPs      @@r�test_bug1055820bzGCTests.test_bug1055820bys������	+�$)��8�
,�8�a�h�q�k�8��
,�13�4��A�w�{�{�1�h�'��4����
�
�
������T��A�&���
�
�
������T��A�&��A�
���Q��%���-��4s
�C�Cc����tj�Gd�d��Gd�d����fd�}|�tj�y)Nc��eZdZy)� GCTests.test_bug21435.<locals>.ANrYrrrrZrV�r[rrZc��eZdZd�Zd�Zy)� GCTests.test_bug21435.<locals>.Bc��||_yr$r)r'r�s  rr(z)GCTests.test_bug21435.<locals>.B.__init__�rrc��d|_yr$�r	r:s rr�z(GCTests.test_bug21435.<locals>.B.__del__�s	�� ��	rN)rrrr(r�rrrrorX�s��
�
!rroc�J����}����}||_||_yr$r[)r]r�rZros  ��r�do_workz&GCTests.test_bug21435.<locals>.do_work�s#�����A��!�#��A��A�F��A�Fr)rGrH)r'r]rZros  @@r�
test_bug21435zGCTests.test_bug21435�s7���	�
�
��	�	�	!�	!�	�	�	�
�
�
�rc�&���ddl�d}��fd�}||dz�}�jd|��jd|�||dz�}�jd|��jd	|vxsd
|v|�||dz�}�jd|�y)
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�f���jtjdd|g�j�j��}|j	�\}}|j
j
�|jj
��j|jd��j|d�|S)Nz-Wdr��r�r�rr)
�Popenr��
executable�PIPE�communicater��closer�rI�
returncode)r��pr�r�r'�
subprocesss    ��r�run_commandz5GCTests.test_garbage_at_shutdown.<locals>.run_command�s����� � �#�.�.�%��t�!D�!���!���!�(�A��]�]�_�N�F�F�
�H�H�N�N��
�H�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)ri�assertIn�assertNotInrA)r'r�rjr�ris`   @r�test_garbage_at_shutdownz GCTests.test_garbage_at_shutdown�s����	���$		��T�C�Z�(���
�
�'�(.�	0������0��T�$<�<�=���
�
�"�#)�	+����
+�v�
5�
7�
+�v�
5��	@��T�$6�6�7�����=�v�Frc�h�d}td|�\}}}|j|j�d�y)Nz�if 1:
            class C:
                def __del__(self):
                    print('__del__ called')
            l = [C()]
            l.append(l)
            r��__del__ called)rrI�strip)r'r�r��out�errs     r�test_gc_main_module_at_shutdownz'GCTests.test_gc_main_module_at_shutdown�s4����(��d�3���C���������&7�8rc���t�5}d}d|�d�}t|d|�td|�\}}}|j|j	�d�ddd�y#1swYyxYw)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�rp)rrrrIrq)r'�
script_dir�moduler�r�rrrss       r�#test_gc_ordinary_module_at_shutdownz+GCTests.test_gc_ordinary_module_at_shutdown�s]��
�Z�:��F�"�	$�D�

�
�H�f�5�+�D�$�7�L�B��S����S�Y�Y�[�*;�<��Z�Z�s�AA�A#c��d}|jtt�ttdd��5}|j	|�ddd�tt�\}}}|j
|j�d�y#1swY�=xYw)Nz�if 1:
            class ClassWithDel:
                def __del__(self):
                    print('__del__ called')
            a = ClassWithDel()
            a.link = a
            raise SystemExit(0)�wzutf-8)�encodingrp)�
addCleanupr
r	�open�writerrIrq)r'r��scriptr�rrrss      r�test_global_del_SystemExitz"GCTests.test_global_del_SystemExitsh��#��	
�����'�
�&�#��
0�F��L�L���1�'��/���C���������&7�8�1�
0�s�A=�=Bc�(�tj�}|jt|�d�|D]t}|j	|t
�|jt
|�hd��|j|dd�|j|dd�|j|dd��vtj�r3|jtj�tj�tj�}tjd�tj�}|j|dd|dddz�|j|dd|dd�|j|dd|dd�tjd�tj�}|j|dd|dddz�|j|dd|dd�|j|dd|dddz�y)	Nr>�	collected�collections�
uncollectabler�rr�r�rDrS)
rG�	get_statsrIr��assertIsInstance�dictrB�assertGreaterEqual�	isenabledr}r�r�rH)r'�stats�st�old�news     r�test_get_statszGCTests.test_get_statss������������U��Q�'��B��!�!�"�d�+����S��W�J�
L��#�#�B�{�O�Q�7��#�#�B�}�$5�q�9��#�#�B��$7��;�
��<�<�>��O�O�B�I�I�&��J�J�L��l�l�n��
�
�
�1�
��l�l�n������Q��
�.��A��}�0E��0I�J�����Q��
�.��A��}�0E�F�����Q��
�.��A��}�0E�F�
�
�
�1�
��l�l�n������Q��
�.��A��}�0E��0I�J�����Q��
�.��A��}�0E�F�����Q��
�.��A��}�0E��0I�Jrc���tj�|jtj�d�tj�|jtj�d�yr)rG�freezer��get_freeze_count�unfreezerIr:s r�test_freezezGCTests.test_freeze+sF��
�	�	�����2�.�.�0�!�4�
���
�����,�,�.��2rc�*��tj�g��j��|jt	�fd�tj
d��D���|j
t	�fd�tj
d��D���|j
t	�fd�tj
d��D���tjd��|j
t	�fd�tj
d��D���|jt	�fd	�tj
d��D���|j
t	�fd
�tj
d��D���tjd��|j
t	�fd�tj
d��D���|j
t	�fd�tj
d��D���|jt	�fd
�tj
d��D���tjd��|j
t	�fd�tj
d��D���|j
t	�fd�tj
d��D���|jt	�fd�tj
d��D����tj�y)Nc3�&�K�|]}�|u���
y�wr$r��.0�elementrKs  �r�	<genexpr>z+GCTests.test_get_objects.<locals>.<genexpr>6������M�0L�W�A��L�0L���r��
generationc3�&�K�|]}�|u���
y�wr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>9������N�1M�W�A��L�1M�r�rDc3�&�K�|]}�|u���
y�wr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr><r�r�rSc3�&�K�|]}�|u���
y�wr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>@r�r�c3�&�K�|]}�|u���
y�wr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>Cr�r�c3�&�K�|]}�|u���
y�wr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>Fr�r�c3�&�K�|]}�|u���
y�wr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>Jr�r�c3�&�K�|]}�|u���
y�wr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>Mr�r�c3�&�K�|]}�|u���
y�wr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>Pr�r�c3�&�K�|]}�|u���
y�wr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>Tr�r�c3�&�K�|]}�|u���
y�wr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>Wr�r�c3�&�K�|]}�|u���
y�wr$rr�s  �rr�z+GCTests.test_get_objects.<locals>.<genexpr>Zr�r�)rGrHrFrA�any�get_objectsr�rJs @r�test_get_objectszGCTests.test_get_objects1s���
�
�
����	���������M����!�0L�M�M�	
�	
����N����1�1M�N�N�	
�	
����M����!�0L�M�M�	
�	�
�
�a� �����M����!�0L�M�M�	
�	
����N����1�1M�N�N�	
�	
����M����!�0L�M�M�	
�	�
�
�a� �����M����!�0L�M�M�	
�	
����N����1�1M�N�N�	
�	
����M����!�0L�M�M�	
�	�
�
�a� �����M����!�0L�M�M�	
�	
����N����1�1M�N�N�	
�	
����M����!�0L�M�M�	
�
�
�
�
�rc���tj�|jttj��ttjd����|jttjd�|jttjd�|jttjd�|jttjd�y)Nr�i�i����1gX9��v��?)rGrHrIr�r��assertRaises�
ValueErrorrr:s r�test_get_objects_argumentsz"GCTests.test_get_objects_arguments_s���
�
�
������R�^�^�-�.��R�^�^�t�<�=�	?�	
���*�b�n�n�d�;����*�b�n�n�e�<����)�R�^�^�S�9����)�R�^�^�U�;rc�j��Gd�d�}G�fd�d|��tj�tj���}|j�jd�~tj�|j�jd�|jt�j�d��jj�|j�jd�tj�|j�jd�tj�y)Nc��eZdZd�Zy)�AGCTests.test_resurrection_only_happens_once_per_object.<locals>.Ac��||_yr$��mer:s rr(zJGCTests.test_resurrection_only_happens_once_per_object.<locals>.A.__init__k�	����rNr)rrrrZr�j���
rrZc� ��eZdZdZgZ�fd�Zy)�GGCTests.test_resurrection_only_happens_once_per_object.<locals>.Lazarusrc�f���xjdz
c_�jj|�yrC)�resurrected�resurrected_instancesrF�r'rIs �rr�zOGCTests.test_resurrection_only_happens_once_per_object.<locals>.Lazarus.__del__rs(����#�#�q�(�#��-�-�4�4�T�:rN)rrrr�r�r��rIs�rrIr�ns����K�$&�!�
;rrIrrD)	rGrHr�rIr�r�r��clearr�)r'rZ�lazrIs   @r�.test_resurrection_only_happens_once_per_objectz6GCTests.test_resurrection_only_happens_once_per_objectis����	�	�	;�a�	;�	�
�
��
�
�
���i������,�,�a�0�
�
�
�
������,�,�a�0�����W�:�:�;�Q�?�	�%�%�+�+�-�����,�,�a�0�
�
�
������,�,�a�0�
�	�	�rc�J��Gd�d�}G�fd�d��tj�tj���}|�}t|�}||_||_~~tj�|j
t�j�d��jj�}|jt|d��|j
t|j�|�tj�tj�y)Nc��eZdZd�Zy)�6GCTests.test_resurrection_is_transitive.<locals>.Cargoc��||_yr$r�r:s rr(z?GCTests.test_resurrection_is_transitive.<locals>.Cargo.__init__�r�rNr)rrr�Cargor��r�rr�c���eZdZgZ�fd�Zy)�8GCTests.test_resurrection_is_transitive.<locals>.Lazarusc�<���jj|�yr$)r�rFr�s �rr�z@GCTests.test_resurrection_is_transitive.<locals>.Lazarus.__del__�s����-�-�4�4�T�:rN)rrrr�r�r�s�rrIr��s���$&�!�
;rrIrD�cargo)
rGrHr�r�r�r�rIr�r�r�rA�hasattrr�)r'r�r�r��cargo_id�instancerIs      @r�test_resurrection_is_transitivez'GCTests.test_resurrection_is_transitive�s����	�	�	;�	;�	�
�
��
�
�
���i������e�9����	���	�
��
�
�
������W�:�:�;�Q�?��0�0�4�4�6�������'�2�3�����H�N�N�+�X�6�
�
�
��
�	�	�rc�N��d}Gd�d�}G�fd�d|�}g�d�}tj�tj�|�\}}t|�D]	}|��tj�}|�\}	}
|j	||�|j	|	|z
|�|j	|
|z
d�|	|
}}|�tj�}|�\}	}
|j	|d�|j	|	|z
d�|j	|
|z
d�|	|
}}t|�D]	}|��|�tj�}|�\}	}
|j	||�|j	|	|z
|�|j	|
|z
d�|	|
}}�j�tj�}|�\}	}
|j	|d�|j	|	|z
d�|j	|
|z
d�tj�y)	N�dc��eZdZd�Zy)�LGCTests.test_resurrection_does_not_block_cleanup_of_other_objects.<locals>.Ac��||_yr$r�r:s rr(zUGCTests.test_resurrection_does_not_block_cleanup_of_other_objects.<locals>.A.__init__�r�rNr)rrrrZr��r�rrZc���eZdZ�fd�Zy)�LGCTests.test_resurrection_does_not_block_cleanup_of_other_objects.<locals>.Zc�(���j|�yr$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�D�tj�d}|d|dfS)N���r�r�)rGr�)rPs r�getstatszSGCTests.test_resurrection_does_not_block_cleanup_of_other_objects.<locals>.getstats�s&������r�"�A��[�>�1�_�#5�5�5rrrS)rGrHr�r�rIr�r�)r'r�rZr�r��oldc�oldncr%rTr��ncr�s           @r�9test_resurrection_does_not_block_cleanup_of_other_objectszAGCTests.test_resurrection_does_not_block_cleanup_of_other_objects�s����

��	�	�	 ��	 ���	6�	�
�
��
�
�
���j���e��q��A�
�C���J�J�L���
���2�����A������T��1�%�����e��Q�'���e��	���J�J�L���
���2�����A������T��1�%�����e��Q�'���e���q��A�
�C��	���J�J�L���
���2�����A������T��1�%�����e��Q�'���e��
���
��J�J�L���
���2�����A������T��1�%�����e��Q�'�
�	�	�rNz%requires ContainerNoGC extension typec��tjj�}Gd�d�}Gd�d�}|�}||_t	|��|_t
j|j
j|�|_	|jg}|j|�tj�tj�~~tj�|j�tj�y)Nc��eZdZgd�Zy)�+GCTests.test_trash_weakref_clear.<locals>.A)r]�y�wzNr2rrrrZr�s��(�IrrZc��eZdZy)�+GCTests.test_trash_weakref_clear.<locals>.ZNrYrrrr�r�r[rr�)�unittest�mock�Mockr]r r�r2r3�valuer�rFrGrHr��assert_not_calledr�)r'rQrZr�r]�wr_cycles      r�test_trash_weakref_clearz GCTests.test_trash_weakref_clear�s���@�=�=�%�%�'��	)�	)�	�	�
�C������A�C� ����{�{�1�3�3�9�9�h�/����D�D�6������!�
�
�
��
�
�
��
�x�
�
�
��	�"�"�$�
�	�	�r)2rrrrLrQrUr`rdrirsryrr�r�r�r�rr�r�r�r�r�r�r�r
�requires_working_threadingrrrr'rCrLrSr^rrnrtryr�r�r�r�r�r�r�r�r��skipIfr r�rrrrArAVsx��*�*�*�-�-�-�*�0-�����2����2*�A!�F�*��*�(�0
&�
&�*�!��!��)��)�(!�F1��0�0�2�84�3�84�t6�06�6;�.-7�^2�$&�0�@���.G���.G�`9�=�&9�K�43�,�\<�"�H �DA�F�X�_�_�]�d�*�<�>�7�>�7rrAc�x�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	e
d��Zejed	�d
��Zy)�GCCallbackTestsc�l�tj�|_tj�tj�|_tjd�tjj|j�tjj|j�g|_yr)rGr��enabledr�r�r�r��	callbacksrF�cb1�cb2�othergarbager:s r�setUpzGCCallbackTests.setUp/sd���|�|�~���
�
�
���\�\�^��
�
���Q��
�����D�H�H�%�
�����D�H�H�%���rc��|`tjj|j�tjj|j
�tj|j�|jrtj�tj�tjD]}t|t�s�d|_�tjdd�=|`tj�yr$)�visitrGr�r�r�r�r�r�r�r�rHr��
isinstancer6r8r�)r'r�s  r�tearDownzGCCallbackTests.tearDown9s����J�
�����D�H�H�%�
�����D�H�H�%�
���T�Z�Z� ��<�<��I�I�K�
�
�
���:�:�C��#�}�-�"����
�J�J�q�M���
�
�
�rc���g|_tj�tjddgc}tjdd|jj|�g|_yr$)r�rGrHr�r�rF)r'r�s  r�precleanzGCCallbackTests.precleanJsK����
�
�
�
��!#���A��������A����� � ��)���
rc�R�|jjd|t|�f�yrC)r�rFr�)r'�phase�infos   rr�zGCCallbackTests.cb1Ts���
�
���1�e�T�$�Z�0�1rc��|jjd|t|�f�|dk(r�t|d�r|tj
D�cgc]}t
|t�s�|��}}tj
D�cgc]}t
|t�s|��c}tj
dd|D]	}d|_�yyycc}wcc}w)NrS�stop�cleanup)	r�rFr�r�rGr�r�r6r8)r'rrr��ucs     rr�zGCCallbackTests.cb2Ws����
�
���1�e�T�$�Z�0�1��F�?�w�t�Y�7��Z�Z�H�Z��:�a��+G�!�Z�B�H�(*�
�
�B�
�1�$.�q�-�$@��
�B�B�J�J�q�M��� ��	�� 8�?��H��Bs�B7�!B7�9B<c���|j�tj�|jD�cgc]}|d��	}}|D�cgc]
}|dk(s�	|��}}|D�cgc]
}|dk(s�	|��}}|j	|dgdz�|j	|dgdz�|jD�cgc]}|d��	}}|D�cgc]
}|dk(s�	|��}}|D�cgc]
}|dk(s�	|��}}|j	|dgdz�|j	|dgdz�|jD]@}|d}|jd|v�|jd|v�|jd|v��Bycc}wcc}wcc}wcc}wcc}wcc}w)	NrrDrS�startrr�r�r�)rrGrHr�rIrA)r'r�r�r%�n1�n2rs       r�test_collectzGCCallbackTests.test_collectasr���
�
��
�
�
��
 �:�:�&�:�a�Q�q�T�:��&��
%��A�a�1�f�a���
%��
%��A�a�1�f�a���
%�����a�S��U�#�����a�S��U�#� �:�:�&�:�a�Q�q�T�:��&��
+��A�a�7�l�a���
+��
*��A�a�6�k�a���
*�����g�Y�q�[�)�����f�X�a�Z�(����A��Q�4�D��O�O�L�D�0�1��O�O�K�4�/�0��O�O�O�t�3�4�	��
'��
%��
%��

'��
+��
*s;�E�
E�E�
E#�%E#�%E(�7
E-�E-�
E2�E2c��|j�tjd�|jD]}|d}|j	|dd��y)NrSr�)rrGrHr�rI)r'r�rs   r�test_collect_generationz'GCCallbackTests.test_collect_generation|sB���
�
��
�
�
�1�
����A��Q�4�D����T�,�/��3�rc��|j�t�t�td�tj�|j
D]:}|ddk7r�|d}|j
|dd�|j
|dd��<|j
ttj�d�tjD]}|j|t��d|_
g|_gtjddtj�|j
D]:}|ddk7r�|d}|j
|dd	�|j
|dd��<|j
ttj�d	�y)
Nr1rDrrSr�r�rTr)rr6r"rGrHr�rIr�r�r�r)r'r�rr�s    r�test_collect_garbagez$GCCallbackTests.test_collect_garbage�s;���
�
��������
�
�
�
�����A���t�v�~���Q�4�D����T�+�.��2����T�/�2�A�6��	
����R�Z�Z��!�,����A��!�!�!�]�3�������
���
�
�1�
�
�
�
�����A���t�v�~���Q�4�D����T�+�.��2����T�/�2�A�6��	
����R�Z�Z��!�,rzbuilt with -NDEBUGc�x�|j�td�ddl}tjd�}|jtjd|g|j|j��}|j�\}}|jj�|jj�|j|d�|j|d�d}|j|d	|z�|j|d
�|j|d|z�|j|d�|j|d
�y)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�rasGgcmodule\.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\])rrri�textwrap�dedentrbr�rcrdrer�rfr�r�)r'rir�rhr�r��
address_regexs       r�test_refcount_errorsz$GCCallbackTests.test_refcount_errors�s#��	
�
�
��	�h������ �
��&
���c�n�n�d�D�9�$.�O�O�$.�O�O�
�
5���������	������	����������W�	Y�����%�	'�*�
�����"�]�2�	4�����#�	%�����"�]�2�	4�����&�	(�����-�	/rN)rrrr�r�rr�r�r
rrrr�r��BUILD_WITH_NDEBUGrrrrr�r�.s_����"�2�!�5�64�� -�� -�F�X�_�_�&�)�+�2/�+�2/rr�c�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�GCTogglingTestsc�,�tj�yr$)rGr�r:s rr�zGCTogglingTests.setUp�s��
�	�	�rc�,�tj�yr$)rGr�r:s rr�zGCTogglingTests.tearDown�s��
�
�
�rc�:�
��td�}tj�td�}||_|`td�}tj|��
g��
�fd�}tj||�}dx}x}}g}d}t�}|jsT|dz
}|dkDr|jd�|jt��d�|jg�|js�T|jt��d��D]}	|j|	d��y)NrrDrSc�����g�ddyr$r)r/�c2wrrPs ��rrQz2GCTogglingTests.test_bug1055820c.<locals>.callback�s����v�h�D��Gr�'�'gc didn't happen after 10000 iterations)
r"rGrH�
keep_c0_aliver&r2r3r+r.r�rIr�rF)r'�c0�c1�c2rQ�c0wr�junkr%�detectorr�rrPs          @@r�test_bug1055820cz GCTogglingTests.test_bug1055820c�s����a�[��
�
�
��
�a�[������G�
�a�[���{�{�2�����	��{�{�2�x�(������R�"�@��
���=���&�&�
��F�A��5�y��	�	�C�D����S��Y��*��K�K��O��&�&�	
����T��A�&��A�
���Q��%�rc� �	�
�g�
G�	�
fd�dt�}|d�}tj�td�}||_|`td�}tj|��	dx}x}}t�}g}d}|jsT|dz
}|dkDr|jd�|jt�
�d�|jg�|js�T|jt�
�d��
D]}|j|d��y)Nc���eZdZ��fd�Zy)�+GCTogglingTests.test_bug1055820d.<locals>.Dc�����g�ddyr$r)r'rrPs ��rr�z3GCTogglingTests.test_bug1055820d.<locals>.D.__del__2s����6�(��Q�rNr�)rrPs��r�Dr,1s���
#rr.rrDrSr r!)
r"rGrH�
keep_d0_aliver&r2r3r+r.r�rIr�rF)r'r.�d0r$r%r(r'r%r�rrPs         @@r�test_bug1055820dz GCTogglingTests.test_bug1055820d+s����
��	#��	#��q�T��
�
�
��
�a�[������G�
�a�[���{�{�2�������R�"�<�=����
���&�&�
��F�A��5�y��	�	�C�D����S��Y��*��K�K��O��&�&�	
����T��A�&��A�
���Q��%�rc���g}d}t�}|js9|dz
}|dkDr|jd�|jg�|js�9	t	j
�g}d}t�}|js)|dz
}|dkDrn|jg�|js�)|j
|d�t	j�y#t	j�wxYw)NrrDr r!i')r+r.r�rFrGr�rIr�)r'r'r%r(s    r�$test_indirect_calls_with_gc_disabledz4GCTogglingTests.test_indirect_calls_with_gc_disabledns�����
���=���&�&�
��F�A��5�y��	�	�C�D��K�K��O�	�&�&�
	��J�J�L��D��A�"�}�H��*�*��Q����u�9�����B��	�*�*�
���Q��&��I�I�K��B�I�I�K�s�AC�,C�C)N)rrrr�r�r)r1r3rrrrr�s����D&�LA&�Frrc��eZdZd�Zy)�PythonFinalizationTestsc�F�tjd�}td|�y)NaM
            import ast
            import codecs
            from test import support

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

            # Store the tree somewhere to survive until the last GC collection
            support.late_deletion(tree)
        r�)rrr)r'r�s  r�
test_ast_finiz%PythonFinalizationTests.test_ast_fini�s#�����
 �

��	��t�$rN)rrrr7rrrr5r5�s��%rr5c��tj�atj�tj�atjt
tjz�tj�yr$)	rGr�r�r�r�r�r��
DEBUG_LEAKrHrrr�setUpModuler:�sA���l�l�n�G��J�J�L��L�L�N�E��L�L��"�-�-��'�(��J�J�Lrc��tjt�trt	d�tj
�tstj�yy)Nzrestoring automatic collection)rGr�r�r�printr�r�r�rrr�tearDownModuler=�s4���L�L����
�.�/��I�I�K��
�
�
��r�__main__)-r��
unittest.mock�test.supportrrrr�test.support.import_helperr�test.support.os_helperrr	r
�test.support.script_helperrrr
rGr��	sysconfigrr�r�r2�	_testcapir�ImportErrorr rr"r+r6�get_config_vars�getrr��TestCaserAr�rr5r:r=r�mainrrr�<module>rKsi����=�=�4�;�;�D�)�	�
�������%��'��v��
:�&�:�
�

�F�

�
�

��9����"�"�;��3�#�'@�y�'@�'@�'B�;�'O�O��
%�S�*<�=�=��
U�h���U�pm/�h�'�'�m/�`g�h�'�'�g�T%�h�/�/�%�*�	��z���H�M�M�O���,��������M��s$�D7�E�7E�E�E�E

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists