Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test_capi.cpython-38.opt-1.pyc
U

>��g�y�@s�ddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZmZzddlZWnek
r�dZYnXe
�d�Zeed�Zdd	�ZGd
d�d�ZGdd
�d
ej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�Z Gdd�dej�Z!Gdd�de!�Z"e�#e
�$�d�Gdd�de!��Z%e�#ed�Gdd�de!��Z&e'd k�r�e�(�dS)!�)�OrderedDictN)�support)�MISSING_C_DOCSTRINGS)�assert_python_failure�assert_python_ok�	_testcapiZgettotalrefcountcCs|S)zsome doc���selfrr�-/opt/cppython/lib/python3.8/test/test_capi.py�testfunctionsrc@s eZdZe�e�Ze�e�ZdS)�InstanceMethodN)�__name__�
__module__�__qualname__rZinstancemethod�idrrrrrr
#s
r
c@s&eZdZdd�Zdd�Zdd�Zdd�Ze�e	d	�d
d��Z
e�e	d	�dd
��Ze�e
d�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Ze�eed!�d"�d#d$��Zd%d&�Ze�d'�d(d)��Ze�d'�d*d+��Zd,d-�Zd.d/�Z d0d1�Z!d2d3�Z"d4d5�Z#d6d7�Z$d8d9�Z%d:S);�CAPITestcCs~t�}|�t|�|���|�|��|k�|�|jjtj�|�tjjtj�dtj_|�tjd�|�tt	|jdd�dS)N�test�	attribute)
r
�assertEqualr�
assertTruer�__doc__r�assertRaises�AttributeError�setattr)r
�instrrr�test_instancemethod)szCAPITest.test_instancemethodc	Cs`t���"tjtjddgtjtjd�}W5QRX|��\}}|�|d�|�	|�
��d��dS)N�-cz4import _testcapi;_testcapi.crash_no_current_thread())�stdout�stderr�s8Fatal Python error: PyThreadState_Get: no current thread)r�SuppressCrashReport�
subprocess�Popen�sys�
executable�PIPE�communicaterr�rstrip�
startswith)r
�p�out�errrrr� test_no_FatalError_infinite_loop4s

���z)CAPITest.test_no_FatalError_infinite_loopcCs|�ttj�dS�N)r�
ValueErrorrZ!make_memoryview_from_NULL_pointerr	rrr�!test_memoryview_from_NULL_pointerBsz*CAPITest.test_memoryview_from_NULL_pointerc

Cs�td�}td�}z|�Wn�tk
r�}z�|j}t��}t�|j|d�}t��}tj|�}t��}	|�|d|�|�	||j||f�|�	||�|�	|	|�|�	||j|df�|�	||�W5d}~XYnX|�
d�dS)N�5ZTEST�F)r/�	TypeError�
__traceback__r$�exc_inforZset_exc_info�	__class__rZassertSequenceEqualr)
r
Zraised_exception�new_exc�e�tbZorig_sys_exc_infoZ
orig_exc_infoZnew_sys_exc_infoZnew_exc_infoZreset_sys_exc_inforrr�
test_exc_infoEs$
zCAPITest.test_exc_infoz(_posixsubprocess required for this test.cCs�Gdd�dt�}|�ttjd|�dddddd	d
ddd
ddddd�Gdd�dt�}|�ttjd|�dddddd	d
ddd
ddddd�dS)Nc@seZdZdd�ZdS)�1CAPITest.test_seq_bytes_to_charp_array.<locals>.ZcSsdS�Nr2rr	rrr�__len__`s�9CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__len__N�rrrr=rrrr�Z_sr@r2��r2������	�
���
����c@seZdZdd�Zdd�ZdS)r;cSstjSr.)r$�maxsizer	rrrr=fsr>cSsdS)N�xr)r
�irrr�__getitem__hsz=CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__getitem__N)rrrr=rTrrrrr@es)�objectrr3�_posixsubprocess�	fork_exec�MemoryError�r
r@rrr�test_seq_bytes_to_charp_array\sP
�
�z&CAPITest.test_seq_bytes_to_charp_arraycCsHGdd�dt�}|�ttj|�dgdddddd	d
ddd
ddddd�dS)Nc@seZdZdd�ZdS)z-CAPITest.test_subprocess_fork_exec.<locals>.ZcSsdSr<rr	rrrr=psz5CAPITest.test_subprocess_fork_exec.<locals>.Z.__len__Nr?rrrrr@osr@�1rArBrDrErFrGrHrIrJrKrLrMrNrOrP)rUrr3rVrWrYrrr�test_subprocess_fork_execms(
�z"CAPITest.test_subprocess_fork_execz6Signature information for builtins requires docstringscCs|�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))rrZno_docstringr�__text_signature__Zdocstring_emptyZdocstring_no_signatureZ docstring_with_invalid_signatureZ!docstring_with_invalid_signature2Zdocstring_with_signatureZ#docstring_with_signature_but_no_docZ+docstring_with_signature_and_extra_newlinesr	rrr� test_docstring_signature_parsingws<
�
�
�
�
�
�
�z)CAPITest.test_docstring_signature_parsingcCs�tj}|�}|�}|�||d||f�|�|dd|df�|�d|dd|f�|}||}|�|d||f�|}|d}|�|d|df�d}||}|�|dd|f�dS)N�matmul�*�imatmul)rZ
matmulTyper)r
�MZm1Zm2�orrr�&test_c_type_with_matrix_multiplication�sz/CAPITest.test_c_type_with_matrix_multiplicationcCs2t��}|�|�d�d�|�|�dd�d�dS)Nr2)r2NrC)rCrC)rZipowTyper�__ipow__)r
rcrrr�test_c_type_with_ipow�szCAPITest.test_c_type_with_ipowc	Cshtr4t�d�}td|�\}}}|�|�dd�d�n0|�t��}t�	�W5QRX|�t
|j�d�dS)Nz�
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_null_without_error()
            r�
r sFatal Python error: a function returned NULL without setting an error\nPython runtime state: initialized\nSystemError: <built-in function return_null_without_error> returned NULL without setting an error\n\nCurrent thread.*:\n  File .*", line 6 in <module>zBreturn_null_without_error.* returned NULL without setting an error)�Py_DEBUG�textwrap�dedentr�assertRegex�replacer�SystemErrorrZreturn_null_without_error�str�	exception�r
�code�rcr+r,�cmrrr�test_return_null_without_error�s
��z'CAPITest.test_return_null_without_errorc	Cshtr4t�d�}td|�\}}}|�|�dd�d�n0|�t��}t�	�W5QRX|�t
|j�d�dS)Nz�
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_result_with_error()
            rrgr sNFatal Python error: a function returned a result with an error 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 error set\n\nCurrent thread.*:\n  File .*, line 6 in <module>z>return_result_with_error.* returned a result with an error set)rhrirjrrkrlrrmrZreturn_result_with_errorrnrorprrr�test_return_result_with_error�s
��z&CAPITest.test_return_result_with_errorcCst��dSr.)r�test_buildvalue_Nr	rrrrv�szCAPITest.test_buildvalue_NcCs<d}td|�\}}}|�d|�|�d|�|�d|�dS)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
        rsMemoryError 1 10sMemoryError 2 20sMemoryError 3 30)r�assertIn�r
rqrrr+r,rrr�test_set_nomemory�s
zCAPITest.test_set_nomemoryc	Cs�Gdd�dt�}Gdd�dt�}dddd�}it�|�|�|t|�||�||�fD]R}|�t�|�t|����|�t�|�t|����|�t�	|�t|�
���qRdS)	Ncs4eZdZ�fdd�Z�fdd�Z�fdd�Z�ZS)z9CAPITest.test_mapping_keys_values_items.<locals>.Mapping1cstt����Sr.)�list�super�keysr	�r6rrr|sz>CAPITest.test_mapping_keys_values_items.<locals>.Mapping1.keyscstt����Sr.)rzr{�valuesr	r}rrr~sz@CAPITest.test_mapping_keys_values_items.<locals>.Mapping1.valuescstt����Sr.)rzr{�itemsr	r}rrr!sz?CAPITest.test_mapping_keys_values_items.<locals>.Mapping1.items�rrrr|r~r�
__classcell__rrr}r�Mapping1sr�cs4eZdZ�fdd�Z�fdd�Z�fdd�Z�ZS)z9CAPITest.test_mapping_keys_values_items.<locals>.Mapping2cstt����Sr.)�tupler{r|r	r}rrr|$sz>CAPITest.test_mapping_keys_values_items.<locals>.Mapping2.keyscstt����Sr.)r�r{r~r	r}rrr~&sz@CAPITest.test_mapping_keys_values_items.<locals>.Mapping2.valuescstt����Sr.)r�r{rr	r}rrr(sz?CAPITest.test_mapping_keys_values_items.<locals>.Mapping2.itemsr�rrr}r�Mapping2#sr�r2rCrA)�fooZbarZspam)�dictrZassertListEqualr�get_mapping_keysrzr|�get_mapping_valuesr~�get_mapping_itemsr)r
r�r�Zdict_obj�mappingrrr�test_mapping_keys_values_itemss$�
�
�
�z'CAPITest.test_mapping_keys_values_itemscCsx|�ttjd�|�ttjd�|�ttjd�Gdd�d�}|�}|�ttj|�|�ttj|�|�ttj|�dS)Nc@s$eZdZdd�Zdd�Zdd�ZdS)zCCAPITest.test_mapping_keys_values_items_bad_arg.<locals>.BadMappingcSsdSr.rr	rrrr|<szHCAPITest.test_mapping_keys_values_items_bad_arg.<locals>.BadMapping.keyscSsdSr.rr	rrrr~>szJCAPITest.test_mapping_keys_values_items_bad_arg.<locals>.BadMapping.valuescSsdSr.rr	rrrr@szICAPITest.test_mapping_keys_values_items_bad_arg.<locals>.BadMapping.itemsN)rrrr|r~rrrrr�
BadMapping;sr�)rrrr�r�r�r3)r
r�Zbad_mappingrrr�&test_mapping_keys_values_items_bad_arg6sz/CAPITest.test_mapping_keys_values_items_bad_argZnegative_refcountz need _testcapi.negative_refcountcCs*t�d�}td|�\}}}|�|d�dS)Nz�
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.negative_refcount()
        rs`_testcapimodule\.c:[0-9]+: _Py_NegativeRefcount: Assertion failed: object has negative ref count)rirjrrkrxrrr�test_negative_refcountGs

�zCAPITest.test_negative_refcountcCs,ddlm}d}td�D]}||f�}qdS)Nr��MyList��)rr��range)r
r��LrSrrr�test_trashcan_subclassYszCAPITest.test_trashcan_subclassZcpucCs|�t�dSr.)�do_test_trashcan_python_classrzr	rrr�test_trashcan_python_class1asz$CAPITest.test_trashcan_python_class1cCsddlm}|�|�dS)Nrr�)rr�r�)r
r�rrr�test_trashcan_python_class2esz$CAPITest.test_trashcan_python_class2cCshGdd�d|�}dD]N}d}td�D]}||f�}||_q$|rD|f}|�|jd�~|�|jd�qdS)Ncs,eZdZdZ�fdd�Z�fdd�Z�ZS)z6CAPITest.do_test_trashcan_python_class.<locals>.PyListrcs�jd7_t�j|�dSr<)�numr{�__init__)r
�argsr}rrr�rsz?CAPITest.do_test_trashcan_python_class.<locals>.PyList.__init__cs�jd8_dSr<)r�r	r}rr�__del__usz>CAPITest.do_test_trashcan_python_class.<locals>.PyList.__del__)rrrr�r�r�r�rrr}r�PyListnsr�)rr2ir)r��attrZ
assertGreaterr�r)r
�baser�Zparityr�rSrrrr�js

z&CAPITest.do_test_trashcan_python_classcCsZGdd�dtj�}|�}t�|�}|�|jd�|�|jd�~|�|dt�|��dS)NcseZdZ�fdd�Z�ZS)z`CAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once.<locals>.HeapGcCTypeSubclasscsd|_t���dS�N���value2r{r�r	r}rrr��sziCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once.<locals>.HeapGcCTypeSubclass.__init__�rrrr�r�rrr}r�HeapGcCTypeSubclass�sr�rIr�r2)r�HeapGcCTyper$�getrefcountr�valuer�)r
r��subclass_instance�type_refcntrrr�:test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once�s
zCCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_oncecs�Gdd�dtj��G��fdd�d�����}t���}t���}|�|jd�|�|jd�~|�|d�j�|�|d�j�|�|dt����|�|t����dS)NcseZdZ�fdd�Z�ZS)zdCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.Acsd|_t���dSr�r�r	r}rrr��szmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.A.__init__r�rrr}r�A�sr�cs*eZdZ�fdd�Z��fdd�Z�ZS)zdCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.Bcst���dSr.)r{r�r	r}rrr��szmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.B.__init__cs"�|_t����_t����_dSr.)r6r$r��
refcnt_in_delr	�r��Brrr��szlCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.B.__del__)rrrr�r�r�rr�r}rr��sr�rIr�r2)rr�r$r�rr�r�r��r
r�r�Znew_type_refcntrr�r�Ptest_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once�s	

zYCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_oncecCsNt��}t�tj�}|�|jd�|�|jd�~|�|dt�tj��dS�NrIr�r2)r�HeapCTypeSubclassr$r�rr�r�)r
r�r�rrr�9test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_once�szBCAPITest.test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_oncecCs�t��}t�tj�}t�tj�}|�|jd�|�|jd�~|�|dtjj�|�|dtjj�|�|dt�tj��|�|t�tj��dSr�)	rZHeapCTypeSubclassWithFinalizerr$r�r�rr�r�r�r�rrr�Otest_c_subclass_of_heap_ctype_with_del_modifying_dunder_class_only_decrefs_once�szXCAPITest.test_c_subclass_of_heap_ctype_with_del_modifying_dunder_class_only_decrefs_oncecCs@t��}|�|jd�d|_|�|jd�|`|�|jd�dS)NrIrKr)rZHeapCTypeSetattrrZpvaluer�)r
�objrrr�test_heaptype_with_setattro�sz$CAPITest.test_heaptype_with_setattrocCs�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�{rCZ	0b1111011rGZ0o173rI�123rOZ0x7bi����z
-0b1111011z-0o173z-123z-0x7bg�^@)rr�rrr3rm)r
r�rrr�test_pynumber_tobase�szCAPITest.test_pynumber_tobaseN)&rrrrr-r0r:�unittest�
skipUnlessrVrZr\ZskipIfrr^rdrfrtrurvryr�r��hasattrrr�r�rZrequires_resourcer�r�r�r�r�r�r�r�r�rrrrr'sH



	�
)! �


#rc@s6eZdZdd�Zddd�Zdd�Zdd	�Zd
d�ZdS)
�TestPendingCallscs>�fdd�}t|�D]$}t�t��d�t�|�r*qq*qdS)Ncs��d�dSr.)�appendr��lrr�callback�sz6TestPendingCalls.pendingcalls_submit.<locals>.callbackg{�G�z�?)r��time�sleep�randomrZ_pending_threadfunc)r
r��nr�rSrr�r�pendingcalls_submit�s

z$TestPendingCalls.pendingcalls_submitNcCs�d}t|�|krxdr,tjr,tdt|�f�td�D]}||}q4|rR|j��sRq|d7}|�|dkd|t|�f�qdr�tjr�tdt|�f�dS)NrFz(%i)r�r2i'z(timeout waiting for %i callbacks, got %i)�lenr�verbose�printr��event�is_setr)r
r�r��context�countrS�arrr�pendingcalls_waits


�
z"TestPendingCalls.pendingcalls_waitc	s�d}g}Gdd�dt�}|��g�_d�_|�j�_d�_t���_t���_	��fdd�t
�j�D�}t�|����
�j|��W5QRXdS)N� c@seZdZdS)z8TestPendingCalls.test_pendingcalls_threaded.<locals>.fooN)rrrrrrrr�sr�rCrcsg|]}tj�j�fd��qS))�targetr�)�	threading�Thread�pendingcalls_thread)�.0rS�r�r
rr�
<listcomp>%s��z?TestPendingCalls.test_pendingcalls_threaded.<locals>.<listcomp>)rUr�r��nThreads�	nFinishedr��Lock�lock�Eventr�r�rZ
start_threadsr�)r
r��threadsr�rr�r�test_pendingcalls_threadeds

�z+TestPendingCalls.test_pendingcalls_threadedcCsjz|�|j	|j
�W5|j�.|jd7_|j}drFtjrFtd|�W5QRX||jkrd|j��XdS)Nr2Fzfinished threads: )r�r�rr�r�r�r��setr�r�r�)r
r�r�rrrr�+s

z$TestPendingCalls.pendingcalls_threadcCs$g}d}|�||�|�||�dS)N�@)r�r�)r
r�r�rrr�test_pendingcalls_non_threaded7sz/TestPendingCalls.test_pendingcalls_non_threaded)N)rrrr�r�r�r�r�rrrrr��s

r�c@s$eZdZdd�Zdd�Zdd�ZdS)�SubinterpreterTestc	Cs|ddl}t��\}}d�|�}t|d��J}t�|�}|�|d�|�t	�
|�ttj
��|�t	�
|�t|��W5QRXdS)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)�builtins�os�pipe�format�openr�run_in_subinterprZassertNotEqual�pickle�loadrr$�modules)r
r��r�wrq�f�retrrr�test_subinterpsDs�
z"SubinterpreterTest.test_subinterpsc	Cs^t��\}}d�|�}t|d��4}t�|�}|�|d�|�t�|�ddd��W5QRXdS)Na9if 1:
            import pickle
            with open({:d}, "wb") as f:

                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�rZ123xr�)r��b)	r�r�r�r�rr�rr�r�)r
r�r�rqr�r�rrr�(test_subinterps_recent_language_featuresSs�

z;SubinterpreterTest.test_subinterps_recent_language_featurescCs(ddl}t�d�|�t|jd��dS)z�
        Exceptions saved in global module state get shared between
        individual module instances. This test checks whether or not
        a change in one interpreter's module gets reflected into the
        other ones.
        rNz1import binascii; binascii.Error.foobar = 'foobar'Zfoobar)�binasciirr�ZassertFalser��Error)r
r�rrr�test_mutate_exceptiongs
z(SubinterpreterTest.test_mutate_exceptionN)rrrr�r�r�rrrrr�Bsr�c@seZdZejdd��ZdS)�TestThreadStatecs2�fdd�}|�tj|d�}|��|��dS)NcsHg��fdd�}t�|�|}}t�d�����t���dd�dS)Ncs��t���dSr.)r�r��	get_identr�Zidentsrrr�}szCTestThreadState.test_thread_state.<locals>.target.<locals>.callbackr2rAz/Couldn't find main thread correctly in the list)rZ_test_thread_stater�r�rr�r�r�)r�r�r�r	r�rr�zs

�z1TestThreadState.test_thread_state.<locals>.target)r�)r�r��start�join)r
r��trr	r�test_thread_statews

z!TestThreadState.test_thread_stateN)rrrrZreap_threadsr�rrrrr�usr�c@s&eZdZe��dd�ee�D��dS)�
Test_testcapiccs0|](}|�d�r|�d�s|tt|�fVqdS)Ztest_�_codeN)r)�endswith�getattrr)r��namerrr�	<genexpr>�s

�zTest_testcapi.<genexpr>N)rrr�locals�update�dirrrrrrr��s�r�c@sleZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�PyMemDebugTests�debugz(?:0x)?[0-9a-fA-F]+c	Cs6t���td||jd�}W5QRX|j}|�dd�S)Nr��PYTHONMALLOC�asciirl)rr!rrr,�decode)r
rqr+rrrr�check�s
�zPyMemDebugTests.checkcCs<|�d�}d}|j|jd�}tj|tjd�}|�||�dS)Nz3import _testcapi; _testcapi.pymem_buffer_overflow()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 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: bad trailing pad byte�Zptr)�flags)rr��	PTR_REGEX�re�compile�DOTALLrk�r
r+Zregexrrr�test_buffer_overflow�s

z$PyMemDebugTests.test_buffer_overflowcCs,|�d�}d}|j|jd�}|�||�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: bad ID: Allocated using API 'm', verified using API 'r'\nr)rr�rrkrrrr�test_api_misuse�s

zPyMemDebugTests.test_api_misusecCs|�|�}d}|�||�dS)NzJFatal Python error: Python memory allocator called without holding the GIL)rrw)r
rqr+Zexpectedrrr�check_malloc_without_gil�s
z(PyMemDebugTests.check_malloc_without_gilcCsd}|�|�dS)Nz6import _testcapi; _testcapi.pymem_malloc_without_gil()�r�r
rqrrr�test_pymem_malloc_without_gil�sz-PyMemDebugTests.test_pymem_malloc_without_gilcCsd}|�|�dS)Nz9import _testcapi; _testcapi.pyobject_malloc_without_gil()rrrrr� test_pyobject_malloc_without_gil�sz0PyMemDebugTests.test_pyobject_malloc_without_gilcCs&t�d|�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)
        rr
)rirjrr)r
�	func_namerqrrr�check_pyobject_is_freed�s�
z'PyMemDebugTests.check_pyobject_is_freedcCs|�d�dS)NZcheck_pyobject_null_is_freed�rr	rrr�test_pyobject_null_is_freed�sz+PyMemDebugTests.test_pyobject_null_is_freedcCs|�d�dS)NZ%check_pyobject_uninitialized_is_freedrr	rrr�$test_pyobject_uninitialized_is_freed�sz4PyMemDebugTests.test_pyobject_uninitialized_is_freedcCs|�d�dS)NZ'check_pyobject_forbidden_bytes_is_freedrr	rrr�&test_pyobject_forbidden_bytes_is_freed�sz6PyMemDebugTests.test_pyobject_forbidden_bytes_is_freedcCs|�d�dS)NZcheck_pyobject_freed_is_freedrr	rrr�test_pyobject_freed_is_freed�sz,PyMemDebugTests.test_pyobject_freed_is_freedN)rrrrrrrrrrrrr r!r"r#rrrrr�src@seZdZdZdS)�PyMemMallocDebugTestsZmalloc_debugN�rrrrrrrrr$�sr$z
need pymallocc@seZdZdZdS)�PyMemPymallocDebugTestsZpymalloc_debugNr%rrrrr&�sr&z
need Py_DEBUGc@seZdZdZdS)�PyMemDefaultTests�Nr%rrrrr'�sr'�__main__))�collectionsrr�r�r�rr"r$rir�r�r�rrZtest.supportrZtest.support.script_helperrrrV�ImportError�
import_modulerr�rhrr
ZTestCaserr�r�r�r�rr$r�Z
with_pymallocr&r'r�mainrrrr�<module>sJ


OO3]



F1le Man4ger