Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/test/test_capi/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/test/test_capi/__pycache__/test_mem.cpython-312.pyc

�

(Μg}���ddlZddlZddlZddlmZddlmZmZddlm	Z	m
Z
ejd�Ze�Gd�dej��ZGd�d	e�Zej ej"�d
�Gd�de��Zej ej&d
�Gd�de��Zedk(rej,�yy)�N)�support)�
import_helper�requires_subprocess)�assert_python_failure�assert_python_ok�	_testcapic�\�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zy)�PyMemDebugTests�debugz(?:0x)?[0-9a-fA-F]+c���tj�5td||jd��}ddd�j}|jdd�S#1swY�'xYw)N�-c�
junk:false��PYTHONMALLOC�MALLOC_CONF�ascii�replace)r�SuppressCrashReportrr�err�decode)�self�code�out�stderrs    �4/usr/local/lib/python3.12/test/test_capi/test_mem.py�checkzPyMemDebugTests.checksU��
�
(�
(�
*�'��d�!�.�.�)��C�+������}�}�W�i�0�0�+�
*�s�A�Ac���|jd�}d}|j|j��}tj|tj
��}|j
||�y)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�format�	PTR_REGEX�re�compile�DOTALL�assertRegex�rr�regexs   r�test_buffer_overflowz$PyMemDebugTests.test_buffer_overflow sS���j�j�N�O��
S���������0���
�
�5��	�	�2������e�$�c��|jd�}d}|j|j��}|j||�y)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'\nr)rr!r"r&r's   r�test_api_misusezPyMemDebugTests.test_api_misuse4s?���j�j�I�J��	w���������0������e�$r*c�N�|j|�}d}|j||�y)Nz^Fatal Python error: _PyMem_DebugMalloc: Python memory allocator called without holding the GIL)r�assertIn)rrr�expecteds    r�check_malloc_without_gilz(PyMemDebugTests.check_malloc_without_gilCs&���j�j����M���
�
�h��$r*c�*�d}|j|�y)Nz6import _testcapi; _testcapi.pymem_malloc_without_gil()�r0�rrs  r�test_pymem_malloc_without_gilz-PyMemDebugTests.test_pymem_malloc_without_gilIs��H���%�%�d�+r*c�*�d}|j|�y)Nz9import _testcapi; _testcapi.pyobject_malloc_without_gil()r2r3s  r� test_pyobject_malloc_without_gilz0PyMemDebugTests.test_pyobject_malloc_without_gilOs��K���%�%�d�+r*c�h�tjd|�d��}td||jd��y)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)
        r
rr)�textwrap�dedentrr)r�	func_namers   r�check_pyobject_is_freedz'PyMemDebugTests.check_pyobject_is_freedUsA�����$�
%�+�&	� �
��	��$��*�*�$�	
r*c�&�|jd�y)N�check_pyobject_null_is_freed�r;�rs r�test_pyobject_null_is_freedz+PyMemDebugTests.test_pyobject_null_is_freedhs���$�$�%C�Dr*c�&�|jd�y)N�%check_pyobject_uninitialized_is_freedr>r?s r�$test_pyobject_uninitialized_is_freedz4PyMemDebugTests.test_pyobject_uninitialized_is_freedks���$�$�%L�Mr*c�&�|jd�y)N�'check_pyobject_forbidden_bytes_is_freedr>r?s r�&test_pyobject_forbidden_bytes_is_freedz6PyMemDebugTests.test_pyobject_forbidden_bytes_is_freedns���$�$�%N�Or*c�&�|jd�y)N�check_pyobject_freed_is_freedr>r?s r�test_pyobject_freed_is_freedz,PyMemDebugTests.test_pyobject_freed_is_freedqs���$�$�%D�Er*c�,�d}td|�\}}}|j�}t|d�D]c\}}|jd|�|j	d��^}}	t|	�}	|j
|	|dz�|j|	|dzdz
��ey)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
        r
�sMemoryError� ��)r�
splitlines�	enumerater.�split�int�assertLessEqual�assertGreaterEqual)
rr�rcrr�lines�i�line�_�counts
          r�test_set_nomemoryz!PyMemDebugTests.test_set_nomemoryts�����4(��d�3���C����� �� ���*�G�A�t��M�M�.�#�.��
�
�4�(�I�Q����J�E�� � ���!��,��#�#�E�1�Q�3�q�5�1�+r*N)�__name__�
__module__�__qualname__rr"rr)r,r0r4r6r;r@rCrFrIr[�r*rr
r
sL���L�&�I�
1�%�(
%�%�,�,�
�&E�N�P�F�"2r*r
c��eZdZdZy)�PyMemMallocDebugTests�malloc_debugN�r\r]r^rr_r*rrara�s��!�Lr*raz
need pymallocc��eZdZdZy)�PyMemPymallocDebugTests�pymalloc_debugNrcr_r*rrere�s��#�Lr*rez
need Py_DEBUGc��eZdZdZy)�PyMemDefaultTests�Nrcr_r*rrhrh�s	���Lr*rh�__main__)r#r8�unittest�testr�test.supportrr�test.support.script_helperrr�
import_moduler�TestCaser
ra�
skipUnless�
with_pymallocre�Py_DEBUGrhr\�mainr_r*r�<module>rus���	����;�N�
(�M�'�'��4�	���G2�h�'�'�G2��G2�T"�O�"�����*�W�*�*�,�o�>�$�o�$�?�$�����W�%�%��7����8��
�z���H�M�M�O�r*

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