
    9bhq`                    Z   d dl Z d dlmZmZ d dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lm Z m!Z!m"Z" 	 d dl#Z#	 d dl%Z%	 d dl&Z&	 d dl'Z( ejT                  d
      Z+d dl,Z,dZ-d Z.d Z/d Z0 G d d      Z1 G d dejd                        Z3e G d dejd                               Z4 G d dejd                        Z5 G d dejd                        Z6 G d dejd                        Z7 G d dejd                        Z8 G d dejd                        Z9 G d dejd                        Z: G d  d!ejd                        Z; ejx                  e%du d"       G d# d$ejd                               Z= G d% d&ejd                        Z>d'Z? G d( d)ejd                        Z@eAd*k(  r ej                          yy# e$$ r dZ#Y ww xY w# e$$ r dZ%Y w xY w# e$$ r dZ&Y w xY w# e)$ r dZ(Y w xY w)+    N)OrderedDictdeque)support)MISSING_C_DOCSTRINGS)import_helper)threading_helper)warnings_helper)requires_limited_api)assert_python_failureassert_python_okrun_python_until_end	_testcapic                 F    | j                  dd      j                  dd      S )Nzutf-8replace )decoder   )errs    B/opt/python-3.12.12/usr/lib/python3.12/test/test_capi/test_misc.pydecode_stderrr   8   s     ::gy)11$;;    c                 H    	  t        j                  t        d u d      |       S )Nzsubinterpreters required)unittestskipIf_interpreters)meths    r   requires_subinterpretersr   <   s,    H78??=D0577;= =r   c                     	 | S N selfs    r   testfunctionr#   B   s
    Kr   c                   P    e Zd Zej	                  e      Zej	                  e      Zy)InstanceMethodN)__name__
__module____qualname__r   instancemethodidr#   r    r   r   r%   r%   G   s"    		!	!"	%B++L9Lr   r%   c                   r   e Zd Zd Z ej
                         d        Zd Z ej                  e
d      d        Z ej                  e
d      d        Z ej                  ed      d        Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Z ej                   eed      d      d        Z ej                   eed      d       ej8                  dddd      d               Zd Z ej>                  d      d        Z  ej>                  d      d        Z!d Z" ej                  ed      d         Z#d! Z$d" Z%d# Z&d$ Z'd% Z(d& Z)d' Z*d( Z+d) Z,d* Z-d+ Z.d, Z/d- Z0d. Z1d/ Z2d0 Z3d1 Z4d2 Z5d3 Z6d4 Z7d5 Z8d6 Z9 e:jv                  e<7      d8        Z=d9 Z>d: Z?d; Z@d< ZAd= ZBd> ZCd? ZDd@ ZEdA ZFdB ZGdC ZHdD ZIdE ZJdF ZKdG ZLyH)ICAPITestc                 <   t               }| j                  t        |      |j                                | j                  |j	                         |u        | j                  |j                  j
                  t        j
                         | j                  t         j                  j
                  t        j
                         dt         j                  _        | j                  t        j                  d       | j                  t        t        |j                  dd       y )Ntest	attribute)
r%   assertEqualr*   
assertTruer#   __doc__r/   assertRaisesAttributeErrorsetattrr"   insts     r   test_instancemethodzCAPITest.test_instancemethodM   s    D4779-))+t34**22L4H4HI44<<l>R>RS06##-//8.'43D3DkSYZr   c                     t        j                  d      }t        d|      \  }}|\  }}}| j                  |d       dj	                         }| j                  |j                         j                  |      |       y )Nz
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.crash_no_current_thread()
        -cr   zFatal Python error: PyThreadState_Get: the function must be called with the GIL held, after Python initialization and before Python finalization, but the GIL is released (the current Python thread state is NULL))textwrapdedentr   r0   encoder1   rstrip
startswith)r"   code
run_result	_cmd_line_rcoutr   msgs           r    test_no_FatalError_infinite_loopz)CAPITest.test_no_FatalError_infinite_loopX   s{        !5T4 @
I"S#c"; =CFH	 	
 	

//4	r   c                 L    | j                  t        t        j                         y r   )r3   
ValueErrorr   !make_memoryview_from_NULL_pointerr!   s    r   !test_memoryview_from_NULL_pointerz*CAPITest.test_memoryview_from_NULL_pointern   s    *i&Q&QRr   z(_posixsubprocess required for this test.c                 v    G d dt               }| j                  t        d      5  t        j                  d |       ddddd	d
ddddddddddddddd       d d d         G d dt               }| j                  t        t        j                  d |       ddddd	d
ddddddddddddddd       y # 1 sw Y   YxY w)Nc                       e Zd Zd Zy)1CAPITest.test_seq_bytes_to_charp_array.<locals>.Zc                      yN   r    r!   s    r   __len__z9CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__len__u       r   Nr&   r'   r(   rQ   r    r   r   ZrM   t       r   rT   indexingrP   TrP                  	   
                  F            c                       e Zd Zd Zd Zy)rM   c                 "    t         j                  S r   )sysmaxsizer!   s    r   rQ   z9CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__len__|   s    {{"r   c                      y)N   xr    )r"   is     r   __getitem__z=CAPITest.test_seq_bytes_to_charp_array.<locals>.Z.__getitem__~       r   N)r&   r'   r(   rQ   ro   r    r   r   rT   z1CAPITest.test_seq_bytes_to_charp_array.<locals>.Z{   s    #r   )objectassertRaisesRegex	TypeError_posixsubprocess	fork_execr3   MemoryErrorr"   rT   s     r   test_seq_bytes_to_charp_arrayz&CAPITest.test_seq_bytes_to_charp_arrayq   s    	 	 ##Iz:&&ACVAa!AbBr"T$rRWXZ[]^`acdik ;	 	
 	+'7'A'AACVAa!AbBr"T$rRWXZ[]^`acdi	k ;:s   1B//B8c                      G d dt               }| j                  t        t        j                   |       dgdddddd	d
dddddddddddddd       y )Nc                       e Zd Zd Zy)-CAPITest.test_subprocess_fork_exec.<locals>.Zc                      yrO   r    r!   s    r   rQ   z5CAPITest.test_subprocess_fork_exec.<locals>.Z.__len__   rR   r   NrS   r    r   r   rT   r{      rU   r   rT      1TrW   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   Frd   re   rf   rg   )rq   r3   rs   rt   ru   rw   s     r   test_subprocess_fork_execz"CAPITest.test_subprocess_fork_exec   sd    	 	
 	)%5%?%?#tfT&1Qq2bBr$tTVW\]_`bcefhin	pr   z6Signature information for builtins requires docstringsc                 D   | j                  t        j                  j                  d        | j                  t        j                  j                  d        | j                  t        j
                  j                  d        | j                  t        j
                  j                  d        | j                  t        j                  j                  d       | j                  t        j                  j                  d        | j                  t        j                  j                  d       | j                  t        j                  j                  d        | j                  t        j                  j                  d       | j                  t        j                  j                  d        | j                  t        j                  j                  d       | j                  t        j                  j                  d       | j                  t        j                  j                  d        | j                  t        j                  j                  d       | j                  t        j                  j                  d       | j                  t        j                  j                  d       y )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))r0   r   no_docstringr2   __text_signature__docstring_emptydocstring_no_signature docstring_with_invalid_signature!docstring_with_invalid_signature2docstring_with_signature#docstring_with_signature_but_no_doc+docstring_with_signature_and_extra_newlinesr!   s    r    test_docstring_signature_parsingz)CAPITest.test_docstring_signature_parsing   s    	//77>//BBDI22::DA22EEtL99AA.	099LLdSCCKK7	
 	CCVVX\]DDLL<	 	DDWWY]^;;CC3	5;;NNPcdFFNNPTUFFYY	! 	NNVVM	ONNaa%	'r   c                 x   t         j                  } |       } |       }| j                  ||z  d||f       | j                  |dz  d|df       | j                  d|z  dd|f       |}||z  }| j                  |d||f       |}|dz  }| j                  |d|df       d}||z  }| j                  |dd|f       y )Nmatmul*   imatmul)r   
matmulTyper0   )r"   Mm1m2os        r   &test_c_type_with_matrix_multiplicationz/CAPITest.test_c_type_with_matrix_multiplication   s      SSb8R"45b8R"45b8R"45	RYB/0	RYB/0	RXr2./r   c                     t         j                         }| j                  |j                  d      d       | j                  |j                  dd      d       y )NrP   )rP   NrX   )rX   rX   )r   ipowTyper0   __ipow__)r"   r   s     r   test_c_type_with_ipowzCAPITest.test_c_type_with_ipow   sE      A	2Aq)62r   c                 p   t         j                  rCt        j                  d      }t	        d|      \  }}}t        |      }| j                  |d       y | j                  t              5 }t        j                          d d d        | j                  t        j                        d       y # 1 sw Y   /xY w)Nz
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_null_without_error()
            r:   a#  Fatal Python error: _Py_CheckFunctionResult: a function returned NULL without setting an exception\nPython runtime state: initialized\nSystemError: <built-in function return_null_without_error> returned NULL without setting an exception\n\nCurrent thread.*:\n  File .*", line 6 in <module>\nzFreturn_null_without_error.* returned NULL without setting an exception)r   Py_DEBUGr;   r<   r   r   assertRegexr3   SystemErrorr   return_null_without_errorstr	exceptionr"   r@   rcrD   r   cms         r   test_return_null_without_errorz'CAPITest.test_return_null_without_error   s     ?? $ D 1t<LBS$CS45 "";/2335 0S.JK 0/   )B,,B5c                 p   t         j                  rCt        j                  d      }t	        d|      \  }}}t        |      }| j                  |d       y | j                  t              5 }t        j                          d d d        | j                  t        j                        d       y # 1 sw Y   /xY w)Nz
                import _testcapi
                from test import support

                with support.SuppressCrashReport():
                    _testcapi.return_result_with_error()
            r:   aq  Fatal Python error: _Py_CheckFunctionResult: a function returned a result with an exception set\nPython runtime state: initialized\nValueError\n\nThe above exception was the direct cause of the following exception:\n\nSystemError: <built-in function return_result_with_error> returned a result with an exception set\n\nCurrent thread.*:\n  File .*, line 6 in <module>\nzBreturn_result_with_error.* returned a result with an exception set)r   r   r;   r<   r   r   r   r3   r   r   return_result_with_errorr   r   r   s         r   test_return_result_with_errorz&CAPITest.test_return_result_with_error   s    ?? $ D 1t<LBS$CS78  "";/2224 0S.GH 0/r   c                     t        j                  d      }t        d|      \  }}}t        |      }d|vr| j	                  |d       y | j                  d|       y )Nz
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.getitem_with_error({1: 2}, 1)
        r:   zSystemError: a  Fatal Python error: _Py_CheckSlotResult: Slot __getitem__ of type dict succeeded with an exception set\nPython runtime state: initialized\nValueError: bug\n\nCurrent thread .* \(most recent call first\):\n  File .*, line 6 in <module>\n\nExtension modules: _testcapi \(total: 1\)\nz'returned a result with an exception set)r;   r<   r   r   r   assertInr"   r@   r   rD   r   s        r   test_getitem_with_errorz CAPITest.test_getitem_with_error  se         -T48CC #%S	C
D MMCSIr   c           	      N
   t         j                  }| j                   |d      d        | j                   |d      d       | j                   |d      g        | j                   |d      i        | j                   |d      dg i f       | j                   |dd      d       | j                   |d	d      d
       | j                   |dd      dg       | j                  t        |dd       | j                   |ddd      d       | j                   |ddd      d       | j                   |ddd      ddg       | j                   |ddd      ddi       | j                   |ddddd      ddd       | j                   |dd      d       | j                   |ddd      d       | j                   |d      d        | j                   |dd      d       | j                   |dd      d       | j                   |ddd      d       | j                   |ddd      d       | j                   |d dd      d       | j                   |d!dd      d       | j                   |d"dd      d       | j                   |d#dd      d       | j                   |d$dd      d       | j                   |d%dd      d       | j                   |d&dd      d       | j                   |d'dd      ddg       | j                   |d(dd      ddg       | j                   |d)dd      ddg       | j                   |d*dd      ddi       | j                   |d+dddd      ddd       | j                   |d,dddd      ddd       | j                   |d-dddd      ddd       | j                   |d.dddd      ddd       | j                  t        |dt
               | j                  t        |d	t
               | j                  t        |dt
               | j                  t        |dt
               | j                  t        |ddt
               | j                  t        |dt
        d       | j                  t        |ddt
               | j                  t        |dt
        d       | j                  t        |ddt
               | j                  t        |dt
        d       | j                  t        |ddt
               | j                  t        |dt
        d       y )/Nr   z()r    z[]z{}z()[]{}OrP   z(O)rP   z[O]z{O}OOrX   rW   z(OO)z[OO]z{OO}z{OOOO}      )rP   r   z((O)))r   z((OO)))rW   z 	,:z   O   z	O	zO,OzO, OzO,	OzO OzO	Oz(O,O)z(O, O)z ( O O) z	(	O	O)	z[O,O]z[O, O]z [ O O] z{O:O}z	{O:O,O:O}z{O: O, O: O}z { O O O O} z	{	O	O	O	O}	)r   py_buildvaluer0   r3   r   NULL)r"   
buildvalues     r   test_buildvaluezCAPITest.test_buildvalue-  s   ,,
B.D)2.D)2.D)2.H-B|<C+Q/E1-t4E1-s3+z5!<D!Q/8FAq16:FAq1Aq6:FAq1Aq6:HaAq9qQ<HGQ/9Ha3Y?G,d3Iq115GQ/3E1a0&9FAq16:GQ2F;E1a0&9FAq16:GQ2F;Ha3V<J15v>NAq96BGQ2QF;Ha3aV<J151v>GQ2QF;KAq!<!lKNAq!Q?Q1NNAq!Q?Q1N$8!Q1E1QR|T+z3=+z5$?+z5$?+z5$?+z4DA+z4qA+z61dC+z64C+z61dC+z64C+z61dC+z64Cr   c                 f   t         j                  }ddl m}m}m}m}m}m} | j                   |d|      |       | j                   |d|      |       | j                   |d|      |       | j                   |d|      |       | j                   |d|      |       | j                   |d|      |       | j                   |dd      d       | j                   |dd	      d	       | j                   |d
d      d       | j                   |dt        d            d       | j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                   |dd      t        d             | j                   |dd      t        d             | j                   |dt        j                        t        t        j                               | j                  t        |dd       | j                  t        |dt        j                  dz          y )Nr   )SHRT_MINSHRT_MAX	USHRT_MAXINT_MININT_MAXUINT_MAXrn   IhHb   iB   cA   A          CrP   )r   py_buildvalue_intsr   r   r   r   r   r   r0   ordchrrj   
maxunicoder3   rH   )r"   r   r   r   r   r   r   r   s           r   test_buildvalue_intszCAPITest.test_buildvalue_intsc  s   11
WWC17;C17;C2H=C2H=C2H=C3Y?C-s3C.5C-s3CS2D9C-w7C-w7C,g6C-s3x8C-s3x8C8#cnn:MN*j#r:*j#s~~a7GHr   c                 ,    t         j                          y r   )r   test_buildvalue_Nr!   s    r   r   zCAPITest.test_buildvalue_N}  s    ##%r   c                 r    t        j                  |      }t        d|      \  }}}| j                  |d       y )Nr:   s`   _testcapimodule\.c:[0-9]+: _Py_NegativeRefcount: Assertion failed: object has negative ref count)r;   r<   r   r   r   s        r   check_negative_refcountz CAPITest.check_negative_refcount  s9     t$,T48C;	<r   negative_refcountz"need _testcapi.negative_refcount()c                 *    d}| j                  |       y )Nz
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.negative_refcount()
        r   r"   r@   s     r   test_negative_refcountzCAPITest.test_negative_refcount  s     	$$T*r   decref_freed_objectz$need _testcapi.decref_freed_object()zuse after free on purposeT)addressmemoryubc                 *    d}| j                  |       y )Nz
            import _testcapi
            from test import support

            with support.SuppressCrashReport():
                _testcapi.decref_freed_object()
        r   r   s     r   test_decref_freed_objectz!CAPITest.test_decref_freed_object  s    
 	$$T*r   c                 F    ddl m} d }t        d      D ]  } ||f      } y )Nr   MyList  )r   r   range)r"   r   Lrn   s       r   test_trashcan_subclasszCAPITest.test_trashcan_subclass  s%     	%tAtA r   cpuc                 .    | j                  t               y r   )do_test_trashcan_python_classlistr!   s    r   test_trashcan_python_class1z$CAPITest.test_trashcan_python_class1  s    **40r   c                 2    ddl m} | j                  |       y )Nr   r   )r   r   r   )r"   r   s     r   test_trashcan_python_class2z$CAPITest.test_trashcan_python_class2  s    $**62r   c                      G d d|      }dD ]b  }d }t        d      D ]  } ||f      }||_         |r|f}| j                  |j                  d       ~| j	                  |j                  d       d y )Nc                   ,     e Zd ZdZ fdZ fdZ xZS )6CAPITest.do_test_trashcan_python_class.<locals>.PyListr   c                 H    xj                   dz  c_         t        |   |  y rO   )numsuper__init__)r"   args	__class__s     r   r   z?CAPITest.do_test_trashcan_python_class.<locals>.PyList.__init__  s    " $'r   c                 0    xj                   dz  c_         y rO   )r   r"   r   s    r   __del__z>CAPITest.do_test_trashcan_python_class.<locals>.PyList.__del__  s    "r   )r&   r'   r(   r   r   r   __classcell__r   s   @r   PyListr     s     C(# #r   r   )r   rP   i   r   )r   attrassertGreaterr   r0   )r"   baser   parityr   rn   s         r   r   z&CAPITest.do_test_trashcan_python_class  sx    	#T 	# FA 5\A4L " Dvzz1-VZZ+ r   c                     | j                  t        j                  j                  d       | j                  t        j                  j                  d       y )Nsomedocz(arg1, arg2))r0   r   HeapDocCTyper2   r   r!   s    r   &test_heap_ctype_doc_and_text_signaturez/CAPITest.test_heap_ctype_doc_and_text_signature  s<     	//77C//BBNSr   c                 X    | j                  t        j                  j                  d        y r   )r0   r   NullTpDocTyper2   r!   s    r   test_null_type_doczCAPITest.test_null_type_doc  s    0088$?r   c                 0    G d dt         j                        } |       }t        j                  |      }| j	                  |j
                  d       | j	                  |j                  d       ~| j	                  |dz
  t        j                  |             y )Nc                        e Zd Z fdZ xZS )`CAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once.<locals>.HeapGcCTypeSubclassc                 0    d| _         t        | 	          y Nre   value2r   r   r   s    r   r   ziCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once.<locals>.HeapGcCTypeSubclass.__init__        "r   r&   r'   r(   r   r   r   s   @r   HeapGcCTypeSubclassr	        # #r   r  r^   re   rP   )r   HeapGcCTyperj   getrefcountr0   valuer  )r"   r  subclass_instancetype_refcnts       r   :test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_oncezCCAPITest.test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once  s    	#)"7"7 	#
 01oo&9: 	*00"5*1126 q#//:M*NOr   c                     G d dt         j                         G fdd              }t        j                        }t        j                        }| j	                  |j
                  d       | j	                  |j                  d       ~t        j                  r| j	                  |j                         n| j	                  |dz
  j                         | j	                  |dz   j                         | j	                  |dz
  t        j                               | j	                  |t        j                               y )Nc                        e Zd Z fdZ xZS )dCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.Ac                 0    d| _         t        | 	          y r  r  r   s    r   r   zmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.A.__init__  r  r   r  r   s   @r   r   r    r  r   r   c                   ,     e Zd Z fdZfdZ xZS )dCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.Bc                 "    t         |           y r   )r   r   r   s    r   r   zmCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.B.__init__  s     "r   c                 |    | _         t        j                        _        t        j                        _        y r   )r   rj   r  refcnt_in_del)r"   r   r   s    r   r   zlCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once.<locals>.B.__del__  s*    !""%//!"4"%//!"4r   )r&   r'   r(   r   r   r   )r   r   r   s   @r   r   r    s    #5 5r   r   r^   re   rP   )
r   r  rj   r  r0   r  r  r   r   r   )r"   r  r  new_type_refcntr   r   s       @@r   Ptest_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_oncezYCAPITest.test_subclass_of_heap_gc_ctype_with_del_modifying_dunder_class_only_decrefs_once  s   	#	%% 	#
	5 	5 Cooa(//!, 	*00"5*1126  [!//:[1_aoo>1,aoo> 	q#//!*<= 	#//!*<=r   c                 Z   t         j                         }d|_        | j                  |j                  d       | j                  |j                  |j
                         | j                  |j                  ddi       t         j                         }| j                  i |j
                         y Nr   foo)r   HeapCTypeWithDictr%  r0   dictobj__dict__r6   s     r   test_heaptype_with_dictz CAPITest.test_heaptype_with_dict  s}    **,2&t}}5r{3**,T]]+r   c                 ~   t         j                         }d|_        | j                  |j                  d       | j                  |j                  ddi       t         j                         }| j                  i |j                         t         j                         }t         j                         }||_        ||_        ~~y r$  )r   HeapCTypeWithManagedDictr%  r0   r(  r   a)r"   r7   r,  r   s       r   test_heaptype_with_managed_dictz(CAPITest.test_heaptype_with_managed_dict  s    1132&4113T]]+..0..0qr   c                 T     G d dt         j                        } |       }||_        ~y )Nc                       e Zd Zy)2CAPITest.test_sublclassing_managed_dict.<locals>.CNr&   r'   r(   r    r   r   r   r0  .      r   r   )r   r+  spam)r"   r   rn   s      r   test_sublclassing_managed_dictz'CAPITest.test_sublclassing_managed_dict,  s'    		22 	 Cr   c                 Z   t         j                         }d|_        | j                  |j                  d       | j                  |j                  |j
                         | j                  |j                  ddi       t         j                         }| j                  i |j
                         y r$  )r   HeapCTypeWithNegativeDictr%  r0   r'  r(  r6   s     r    test_heaptype_with_negative_dictz)CAPITest.test_heaptype_with_negative_dict5  s}    2242&t}}5r{3224T]]+r   c                     t         j                         }t        j                  |      }| j	                   |       |       | j	                  |j
                  |       y r   )r   HeapCTypeWithWeakrefweakrefrefr0   weakreflistr"   r7   r;  s      r   test_heaptype_with_weakrefz#CAPITest.test_heaptype_with_weakref?  sF    --/kk$%))3/r   c                     t         j                         }t        j                  |      }| j	                   |       |       y r   r   HeapCTypeWithManagedWeakrefr:  r;  r0   r=  s      r   "test_heaptype_with_managed_weakrefz+CAPITest.test_heaptype_with_managed_weakrefE  s0    446kk$%r   c                      G d dt         j                        } |       }t        j                  |      }| j	                   |       |       y )Nc                       e Zd Zy)5CAPITest.test_sublclassing_managed_weakref.<locals>.CNr1  r    r   r   r   rE  L  r2  r   r   r@  )r"   r   r7   r;  s       r   !test_sublclassing_managed_weakrefz*CAPITest.test_sublclassing_managed_weakrefJ  s=    		55 	 skk$%r   c                     G d dt         j                  t         j                        } G d dt         j                  t         j                        }||fD ]n  } |       }t        j                  |      }| j                   |       |       ||_        ~t        j                   |             }| j                   |       d        p y )Nc                       e Zd Zy)3CAPITest.test_sublclassing_managed_both.<locals>.C1Nr1  r    r   r   C1rI  U  r2  r   rJ  c                       e Zd Zy)3CAPITest.test_sublclassing_managed_both.<locals>.C2Nr1  r    r   r   C2rL  X  r2  r   rM  )r   rA  r+  r:  r;  r0   r3  assertIs)r"   rJ  rM  clsr7   r;  s         r   test_sublclassing_managed_bothz'CAPITest.test_sublclassing_managed_bothS  s    	66	8Z8Z 		33Y5Z5Z 	 8C5D++d#CSUD)DI++ce$CMM#%& r   c                 f    t         j                         }t        |      }| j                  |d       y )Ns   1234)r   HeapCTypeWithBufferbytesr0   )r"   r7   r   s      r   test_heaptype_with_bufferz"CAPITest.test_heaptype_with_bufferd  s)    ,,.$KG$r   c                 P   t         j                         }t        j                  t         j                        }| j	                  |j
                  d       | j	                  |j                  d       ~| j	                  |dz
  t        j                  t         j                               y Nr^   re   rP   )r   HeapCTypeSubclassrj   r  r0   r  r  )r"   r  r  s      r   9test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_oncezBCAPITest.test_c_subclass_of_heap_ctype_with_tpdealloc_decrefs_oncei  s}    %779ooi&A&AB 	*00"5*1126 q#//):U:U*VWr   c                 &   t         j                         }t        j                  t         j                        }t        j                  t         j                        }| j                  |j                  d       | j                  |j                  d       ~t        j                  r+| j                  |t         j                  j                         n-| j                  |dz
  t         j                  j                         | j                  |dz   t         j                  j                         | j                  |dz
  t        j                  t         j                               | j                  |t        j                  t         j                               y rV  )r   HeapCTypeSubclassWithFinalizerrj   r  rW  r0   r  r  r   r   r   )r"   r  r  r!  s       r   Otest_c_subclass_of_heap_ctype_with_del_modifying_dunder_class_only_decrefs_oncezXCAPITest.test_c_subclass_of_heap_ctype_with_del_modifying_dunder_class_only_decrefs_onceu  s   %DDFooi&N&NO//)*E*EF 	*00"5*1126   [)*R*R*`*`a[1_i.V.V.d.de1,i.I.I.W.WX 	q#//):b:b*cd 	#//):U:U*VWr   c                     t         j                         }| j                  |j                  d       d|_        | j                  |j                  d       |`| j                  |j                  d       y )Nr^   r`   r   )r   HeapCTypeSetattrr0   pvaluer  )r"   objs     r   test_heaptype_with_setattroz$CAPITest.test_heaptype_with_setattro  sX    ((*R(	R(IQ'r   c                    t         j                  }| j                  t        |t                     t         j                  |      }| j                  |t               | j                  |j                  d       | j                  t	        |      |        |ddi       }| j                  |t               | j                  |j                  d       y )NHeapCTypeViaMetaclassPyClassViaMetaclassr    )
r   HeapCTypeMetaclassr1   
issubclasstypepytype_fromspec_metaassertIsInstancer0   r&   rN  r"   	metaclassts      r   #test_heaptype_with_custom_metaclassz,CAPITest.test_heaptype_with_custom_metaclass  s    00	
9d34 **95a&%<=d1gy) +R4a&%:;r   c                    t         j                  }| j                  t        |t                     t         j                  |      }| j                  |t               | j                  |j                  d       | j                  t	        |      |       | j                  t        d      5   |ddi        d d d        y # 1 sw Y   y xY w)Nrb  zcannot create .* instancesrc  r    )r   HeapCTypeMetaclassNullNewr1   re  rf  rg  rh  r0   r&   rN  rr   rs   ri  s      r   ,test_heaptype_with_custom_metaclass_null_newz5CAPITest.test_heaptype_with_custom_metaclass_null_new  s    77	
9d34 **95a&%<=d1gy) ##I/KL+R4 MLLs   (B<<Cc                    t         j                  }| j                  t        t         j                  t                     d}| j                  t        |      5  t         j                  |      }d d d        y # 1 sw Y   y xY w)Nz1Metaclasses with custom tp_new are not supported.)r   HeapCTypeMetaclassCustomNewr1   re  rf  rr   rs   rg  )r"   rj  rE   rk  s       r   .test_heaptype_with_custom_metaclass_custom_newz7CAPITest.test_heaptype_with_custom_metaclass_custom_new  sW    99	
9#H#H$OPA##Is3..y9A 433s   A55A>c                     t         j                  } G d d|      }t        j                  dt        f      5  t         j                  |      }d d d        | j                  t        |             | j                  ||       y # 1 sw Y   7xY w)Nc                       e Zd Zy)FCAPITest.test_heaptype_with_custom_metaclass_deprecation.<locals>.BaseNr1  r    r   r   Baseru    r2  r   rv  )rj  z8.* _testcapi.Subclass .* custom tp_new.*in Python 3.14.*)	r   rq  r	   check_warningsDeprecationWarningmake_type_with_baser1   re  rh  )r"   rj  rv  subs       r   /test_heaptype_with_custom_metaclass_deprecationz8CAPITest.test_heaptype_with_custom_metaclass_deprecation  sy    99	
	Y 	 ++KM_` //5C 	
3-.c9- s   BBc                 L   | j                  t              5   G d dt        j                  t        j                        }d d d        | j                  t              5   G d dt        j                  t        j                        }d d d        y # 1 sw Y   PxY w# 1 sw Y   y xY w)Nc                       e Zd Zy)MCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict.<locals>.Both1Nr1  r    r   r   Both1r~        r   r  c                       e Zd Zy)MCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict.<locals>.Both2Nr1  r    r   r   Both2r    r  r   r  )r3   rs   r   r9  r&  )r"   r  r  s      r   5test_multiple_inheritance_ctypes_with_weakref_or_dictz>CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict  ss    y)	66	8S8S  * y)	33Y5S5S  *) *) *)s   )B)BBB#c                 0   | j                  t              5   G d dt        j                  t              }d d d        | j                  t              5   G d dt        j
                  t              }d d d         G d dt        j                  t              } G d dt        j                  t              } |       }|j                  d	       t        |j                          |       }|j                  d	       t        |j                         t        j                  t        j                  fD ]K  }t        j                  t        j
                  fD ]  } G d
 d||      }  G d d||      }	 G d d||      }
M y # 1 sw Y   KxY w# 1 sw Y   xY w)Nc                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.C1Nr1  r    r   r   rJ  r    r  r   rJ  c                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.C2Nr1  r    r   r   rM  r    r  r   rM  c                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.C3Nr1  r    r   r   C3r    r2  r   r  c                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.C4Nr1  r    r   r   C4r    r2  r   r  r   c                       e Zd Zy)[CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.SNr1  r    r   r   Sr    s    r   r  c                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.B1Nr1  r    r   r   B1r    r  r   r  c                       e Zd Zy)\CAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin.<locals>.B2Nr1  r    r   r   B2r    r  r   r  )r3   rs   r   r&  r   r9  r+  rA  appendr   r(  __weakref__)r"   rJ  rM  r  r  r7   rO  cls2r  r  r  s              r   Gtest_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtinzPCAPITest.test_multiple_inheritance_ctypes_with_weakref_or_dict_and_other_builtin  s.   y)Y00$  * y)Y33T  *	33T 		66 	 tADMMtAD66	8]8]^C"44i6T6TUT  VR R  _+ *) *)s   E>F>FFc                     t        d      D ]P  }| j                  |      5  | j                  t              5  t        j                  |       d d d        d d d        R y # 1 sw Y   xY w# 1 sw Y   ixY w)NrX   )variant)r   subTestr3   r   r   create_type_from_repeated_slots)r"   r  s     r   (test_pytype_fromspec_with_repeated_slotsz1CAPITest.test_pytype_fromspec_with_repeated_slots  sW    QxGg.&&{3==gF 4 /.  33 /.s"   A,A A, A)%A,,A5	categoryc                    t        j                  dd        G d d      }| j                  t              5  t        j                  |      }d d d                }| j                  |j                         d       | j                  t        d      5  d |_        d d d        | j                  |j                         d       d	 |_        | j                  |j                         d
       y # 1 sw Y   xY w# 1 sw Y   ^xY w)Nz-creating immutable classes with mutable bases)r   rb   )removec                       e Zd Zd Zy)CCAPITest.test_immutable_type_with_mutable_base.<locals>.MutableBasec                      y)Noriginalr    r!   s    r   r   zHCAPITest.test_immutable_type_with_mutable_base.<locals>.MutableBase.meth  s    !r   N)r&   r'   r(   r   r    r   r   MutableBaser    s    "r   r  r  z-cannot set 'meth' attribute of immutable typec                      y)N
overriddenr    r!   s    r   <lambda>z@CAPITest.test_immutable_type_with_mutable_base.<locals>.<lambda>  s    ,r   c                      y)Nchangedr    r!   s    r   r  z@CAPITest.test_immutable_type_with_mutable_base.<locals>.<lambda>  s    	r   r  )
warnings_deprecatedassertWarnsrx  r   make_immutable_type_with_baser0   r   rr   rs   )r"   r  ImmutableSubclassinstances       r   %test_immutable_type_with_mutable_basez.CAPITest.test_immutable_type_with_mutable_base  s     	;G	M	" 	" 01 ) G G! 2 %&*5 ##?A &?"A 	*5 2)4! 21A As   C,	C8,C58Dc           	         ddl m} d}d} G d d      }d}|D ]  \  }}}| j                  |||      5  | j                   |||      |       | j                   || |      d	|z          | j                   | ||      |      |       | j                   |||      |       | j                   || |      d	|z          | j                   | ||      |      |       d d d         | j	                  t
        | |d
      d       | j	                  t
        | |d      d       | j	                  t
        |d
d       | j	                  t
        |dd       | j	                  t        |dd       y # 1 sw Y   _xY w)Nr   )pynumber_tobase{   l            c                       e Zd Zd Zd Zy)*CAPITest.test_pynumber_tobase.<locals>.IDXc                     || _         y r   val)r"   r  s     r   r   z3CAPITest.test_pynumber_tobase.<locals>.IDX.__init__   s	    r   c                     | j                   S r   r  r!   s    r   	__index__z4CAPITest.test_pynumber_tobase.<locals>.IDX.__index__"  s    xxr   N)r&   r'   r(   r   r  r    r   r   IDXr    s     r   r  ))rX   	0b1111011C0b10000000000000000000000000000000000000000000000000000000000000000)r\   0o1730o2000000000000000000000)r^   12318446744073709551616)   0x7b0x10000000000000000)r   stlt-g     ^@r^   r  )r   r  r  r0   r3   rs   r   )	r"   r  small_numberlarge_numberr  
test_casesr   small_targetlarge_targets	            r   test_pynumber_tobasezCAPITest.test_pynumber_tobase  sh   -	  	 ;
 1;,D,4L\J  t!DlS  ,!Es\GYZ  \1BD!I<X  t!DlS  ,!Es\GYZ  \1BD!I<X KJ 1; 	)_c%j"E)_c%j"E)_eR@)_eR@+Q? KJs   B+E..E8	c                 P    t         j                         }| j                  |d       y Nz<NULL>)r   pyobject_repr_from_nullr0   r"   ss     r   test_pyobject_repr_from_nullz%CAPITest.test_pyobject_repr_from_null9  s     --/H%r   c                 P    t         j                         }| j                  |d       y r  )r   pyobject_str_from_nullr0   r  s     r   test_pyobject_str_from_nullz$CAPITest.test_pyobject_str_from_null=  s     ,,.H%r   c                 P    t         j                         }| j                  |d       y )Ns   <NULL>)r   pyobject_bytes_from_nullr0   r  s     r   test_pyobject_bytes_from_nullz&CAPITest.test_pyobject_bytes_from_nullA  s     ..0I&r   c                     t         j                  }d} ||      }t        |dd      }| j                  |j                  |j                         y )Ns%   # -*- coding: latin1 -*-
print('¤')
z<string>exec)r   Py_CompileStringcompiler0   	co_consts)r"   _compiler@   resultexpecteds        r   test_Py_CompileStringzCAPITest.test_Py_CompileStringE  sE    --?$4V4))8+=+=>r   c                 b   t        j                  d      }g }t        t        d      r|j	                  d       t
        j                  dk7  r|j	                  d       |D ]B  }| j                  |      5  | j                  t        |j                  |             d d d        D y # 1 sw Y   OxY w)Nctypesget_native_idPyThread_get_thread_native_idntPy_FrozenMain)name)
r   import_modulehasattr_threadr  osr  r  r1   	pythonapi)r"   r  namesr  s       r   test_export_symbolszCAPITest.test_export_symbolsM  s     ,,X6 7O,LL89 77d?LL)D4((8(8$ ?@ )( ((s   4&B%%B.	c                 4    G d d      } |       }t         j                  |       | j                  |j                  i         |       }| j                  |j                  ddi       t         j                  |       | j                  |j                  i        y )Nc                       e Zd Zd Zy)+CAPITest.test_clear_managed_dict.<locals>.Cc                     d| _         y rO   r,  r!   s    r   r   z4CAPITest.test_clear_managed_dict.<locals>.C.__init__g  s	    r   N)r&   r'   r(   r   r    r   r   r   r  f  s    r   r   r,  rP   )r   clear_managed_dictr0   r(  )r"   r   r   s      r   test_clear_managed_dictz CAPITest.test_clear_managed_dictd  sx    	 	 C$$Q'R(Cc!W-$$Q'R(r   c                 *   dd l }d }t        j                  |      }| j                  ||j                         | j                  ||j                         | j                  t              5  t        j                  d        d d d        y # 1 sw Y   y xY w)Nr   c                       y r   r    r    r   r   somez-CAPITest.test_function_get_code.<locals>.someu      r   )	typesr   function_get_coderh  CodeTyper0   __code__r3   r   )r"   r  r   r@   s       r   test_function_get_codezCAPITest.test_function_get_coder  sl    	 **40dENN3t}}-{+''- ,++s   *B		Bc                    d }t         j                  |      }| j                  |t               | j	                  ||j
                         | j                  t              5  t         j                  d        d d d        y # 1 sw Y   y xY w)Nc                       y r   r    r    r   r   r   z0CAPITest.test_function_get_globals.<locals>.some  r  r   )r   function_get_globalsrh  dictr0   __globals__r3   r   )r"   r   globals_s      r   test_function_get_globalsz"CAPITest.test_function_get_globals  sg    	 11$7h-4#3#34{+**40 ,++    A??Bc                    d }t         j                  |      }| j                  |t               | j	                  ||j
                         | j                  t              5  t         j                  d        d d d        y # 1 sw Y   y xY w)Nc                       y r   r    r    r   r   r   z/CAPITest.test_function_get_module.<locals>.some  r  r   )r   function_get_modulerh  r   r0   r'   r3   r   )r"   r   modules      r   test_function_get_modulez!CAPITest.test_function_get_module  se    	 ..t4fc*1{+))$/ ,++r  c                    	 	 dddd}t         j                  |      }| j                  |d       | j                  ||j                         | j	                  t
              5  t         j                  d        d d d        y # 1 sw Y   y xY w)NTkw2c                    y r   r    	pos_only1	pos_only2zerooptionalkw1r  s         r   r   z1CAPITest.test_function_get_defaults.<locals>.some       r   pr   N)r   function_get_defaultsr0   __defaults__r3   r   r"   r   defaultss      r   test_function_get_defaultsz#CAPITest.test_function_get_defaults  sw    !$!	 	 2248>24#4#45{+++D1 ,++s   "BB
c                    	 	 dddd}d}| j                  t        j                  |      |       | j                  |j                  |       | j	                  t
              5  t        j                  |d       d d d        | j                  t        j                  |      |       | j                  |j                  |       | j	                  t
              5  t        j                  dd       d d d        | j                  t        j                  |      |       | j                  |j                  |       d}t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |       d}t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |        G d d	t              } |d
ddgd f      }t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |       t        j                  |d        | j                  t        j                  |      d        | j                  |j                  d        y # 1 sw Y   =xY w# 1 sw Y   xY w)NTr  c                    y r   r    r  s         r   r   z1CAPITest.test_function_set_defaults.<locals>.some  r  r   r  rP   r    )qrP   Nc                       e Zd Zy)5CAPITest.test_function_set_defaults.<locals>.tuplesubNr1  r    r   r   tuplesubr*        r   r+  rW   r,  r   )r0   r   r!  r"  r3   r   function_set_defaultstuple)r"   r   old_defaultsnew_defaultsr+  s        r   test_function_set_defaultsz#CAPITest.test_function_set_defaults  s9   !$!	 	 &88>M**L9{+++D!4 ,88>M**L9{+++Ar2 ,88>M**L9%''l;88>M**L9 ''l;88>M**L9"u"#sT :;''l;88>M**L9 	''d388>E**D1A ,+
 ,+s   "J4K4J>Kc                    	 	 dddd}t         j                  |      }| j                  |ddi       | j                  ||j                         | j	                  t
              5  t         j                  d        d d d        y # 1 sw Y   y xY w)NTr  c                    y r   r    r  s         r   r   z4CAPITest.test_function_get_kw_defaults.<locals>.some  r  r   r  r  )r   function_get_kw_defaultsr0   __kwdefaults__r3   r   r#  s      r   test_function_get_kw_defaultsz&CAPITest.test_function_get_kw_defaults  s{    !$!	 	 55d;E4=14#6#67{+..t4 ,++s   $BBc                    	 	 d	ddd}ddi}| j                  t        j                  |      |       | j                  |j                  |       | j	                  t
              5  t        j                  |d       d d d        | j                  t        j                  |      |       | j                  |j                  |       | j	                  t
              5  t        j                  di        d d d        | j                  t        j                  |      |       | j                  |j                  |       ddi}t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |       i }t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |        G d dt              } |dd i      }t        j                  ||       | j                  t        j                  |      |       | j                  |j                  |       t        j                  |d        | j                  t        j                  |      d        | j                  |j                  d        y # 1 sw Y   <xY w# 1 sw Y   xY w)
NTr  c                    y r   r    r  s         r   r   z4CAPITest.test_function_set_kw_defaults.<locals>.some  r  r   r  rP   rP   rX   r   c                       e Zd Zy)7CAPITest.test_function_set_kw_defaults.<locals>.dictsubNr1  r    r   r   dictsubr;    r,  r   r<  r  )r0   r   r4  r5  r3   r   function_set_kw_defaultsr
  )r"   r   r/  r0  r<  s        r   test_function_set_kw_defaultsz&CAPITest.test_function_set_kw_defaults  s;   !$!	 	 t};;DA<P,,l;{+..tQ7 ,;;DA<P,,l;{+..q"5 ,;;DA<P,,l;y)**4>;;DA<P,,l; **4>;;DA<P,,l; d t}-**4>;;DA<P,,l; 	**46;;DA4H,,d3A ,+
 ,+s   $J5K5J?Kc                 P    G d dt         j                        } |       }d|_        d|_        d|_        | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       |`| j                  |j                         y )Nc                       e Zd ZdZy);CAPITest.test_unstable_gc_new_with_extra_data.<locals>.Data)xyN)r&   r'   r(   	__slots__r    r   r   DatarA    s    "Ir   rE  r^   re      )r   ObjExtraDatarB  rC  extrar0   assertIsNone)r"   rE  ds      r   $test_unstable_gc_new_with_extra_dataz-CAPITest.test_unstable_gc_new_with_extra_data  s    	#9)) 	# Fb!b!"%G!''"r   N)Mr&   r'   r(   r8   r   requires_subprocessrF   rJ   r   
skipUnlessrt   rx   r~   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   skip_if_sanitizerr   r   requires_resourcer   r   r   r  r  r  r"  r)  r-  r4  r7  r>  rB  rF  rP  rT  rX  r[  r`  rl  ro  rr  r{  r  r  r  r	   ignore_warningsrx  r  r  r  r  r  r  r  r  r  r  r  r%  r1  r6  r>  rK  r    r   r   r,   r,   K   s   	[ !W  " #*S X)+UVk Wk" X)+UVp Wp X__)MO''O''R0"3K: HDJ<4DlI4&< X,?@=?+?+ X,AB?AW:'+DTC+CA+ Wu%1 &1 Wu%3 &3,8 X__)MOTOT@P"&>P,,0&
&'"%

XX6(<5:."@G %_$$.@A5 B56@<&&'?A.).	1	02$/2b5$/4b#r   r,   c                   B    e Zd Z	 ed        Zd Zd Zd Zd Zd Z	d Z
y)	TestHeapTypeRelativec                 0     fd}t        dddddddd	t        j                  t        j                  dz
  t        j                  dz   h      }|D ]9  }|D ]2  }t        ||
      }  j                  di |5   |di | d d d        4 ; y # 1 sw Y   AxY w)Nc                    t         j                  | |       \  }}}}}}|dk(  r9
j                  |j                  |j                         
j                  |d       nd|j                  df|df||z   df||z   df|j                  dfg}t	        |t        j                  d            }	
j                  ||	d	|	 
       
j                  |j                  ||z          
j                  ||z
  t         j                         
j                  |t         j                  z  d       
j                  |t         j                  z  d       y )Nr   )r   zstart of objectzend of base datazsubclass datazend of requested subcls datazend of reserved subcls datazend of object)keyz$Offsets not in expected order, got: rE   )	r   make_sized_heaptypesr0   __basicsize__sortedoperator
itemgetter
assertLessALIGNOF_MAX_ALIGN_T)extra_base_size
extra_sizerv  Subr  data_ptrdata_offset	data_sizeoffsetsordered_offsetsr"   s             r   checkz@TestHeapTypeRelative.test_heaptype_relative_sizes.<locals>.check1  s\   ..#j[2 BD#x;	
 Q  !3!3S5F5FG  A.
 +'');< /2 :-/MN 9,.KL&&8 #)h6I6I!6L"M  _>>OP ! R
   !2!2K)4KL 	J 6 ) = =? [9+H+HH!LY)F)FFJr   r   rP   rX   r   r   r[   r\   r  r^  r_  r    )rY  rq   rX  r
  r  )r"   rf  sizesr^  r_  r   s   `     r   test_heaptype_relative_sizesz1TestHeapTypeRelative.test_heaptype_relative_sizes.  s    "	KH 1aAq!S,,,,Q.,,Q.0 1  %O#
O'13!T\\)D)MDM *) $  % *)s   6	BBc                 n    	 t         j                  ddd      }| j                  t        |      g d       y )NrP   rX   r   r9  )r   HeapCCollectionr0   r   )r"   
collections     r   test_HeapCCollectionz)TestHeapTypeRelative.test_HeapCCollection`  s.    @..q!Q7
j)95r   c                 D   	 t        ddddddddt        j                  t        j                  dz
  t        j                  dz   h      }|D ]  }| j                  |	      5  t        j                  t        j                  | dd      } |ddd      }|j                          | j                  t        |      g d
       |j                         }| j                  t        |      |       | j                  t        |      dhk  d|       d d d         y # 1 sw Y   xY w)Nr   rP   rX   r   r   r[   r\   r  )r_  r9  zgot )rY  rq   rX  r  r   subclass_var_heaptyperk  set_data_to_3sr0   r   get_dataassertGreaterEquallenr1   set)r"   rh  r_  r`  rl  mems         r   test_heaptype_inherit_itemsizez3TestHeapTypeRelative.test_heaptype_inherit_itemsizee  s   ;1aAq!S,,,,Q.,,Q.0 1  J455--
{AqB Aq\
))+  j!19= ))+''C*=CQC4w@ 54  44s   B,DD	c                     | j                  t        d      5  t        j                  t        dd       d d d        y # 1 sw Y   y xY w)NzACannot extend variable-size class without Py_TPFLAGS_ITEMS_AT_ENDrV  r   )r3   r   r   subclass_heaptypeintr!   s    r   !test_heaptype_invalid_inheritancez6TestHeapTypeRelative.test_heaptype_invalid_inheritancew  s@    {$;  < ''R3< < <s	   =Ac                    	 t        ddddddddt        j                  t        j                  dz
  t        j                  dz   h      }|D ]  }|D ]  }|D ]N  }| j                  |||	      5  ||k  rt        j                  || |d
      }|j                         d   } |       }| j                  |j                  |j                                |j                  d       | j                  |j                  |j                                | j                  |j                         d       d|_        | j                  |j                  |j                                | j                  |j                         d       | j                  |j                         |j                         | j                  |j                         |j                         | j                  t              5  |j!                          d d d        | j                  t              5  |j#                  d       d d d        n7| j                  t              5  t        j                  || |d
      }d d d        | j                  t              5  t        j                  |||d
      }d d d        d d d        Q | j                  ||      5  | j                  t              5  t        j                  || dd
      }d d d        d d d          y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   VxY w# 1 sw Y   xY w)Nr   rP   rX   r   r   r[   r\   r  )r^  r_  offsetTra   rb   rg  r   )rY  rq   rX  r  r   make_heaptype_with_membermror0   membget_membset_membrr  get_memb_offsetr\  r3   r   get_memb_relativeset_memb_relative)r"   rh  r^  r_  r}  r`  rv  r  s           r   test_heaptype_relative_membersz3TestHeapTypeRelative.test_heaptype_relative_members}  s   ;1aAq!S,,,,Q.,,Q.0 1  %O#
#FoR\ekl!J."+"E"E /*fd#LC#&779Q<D'*uH ,,X]]H<M<M<OP$--b1 ,,X]]H<M<M<OP ,,X->->-@"E,.HM ,,X]]H<M<M<OP ,,X->->-@"E 33H4L4L4NPTPbPbc OOH,D,D,FHYHYZ!%!2!2;!? ( : : < "@!%!2!2;!? ( : :1 = "@!? "&!2!2;!?&/&I&I$3j[&$'P "@ "..{;"+"E"E /VT#KC </ ml $6 \\/j\Y**;7'AA+j["dD 8 ZY9 $  %$ "@!?!?!? "@!? <;/ ml6 87 ZYs   .E9L3	'L8L3	L'L3	LL3	<L'L3	;MM 	+MLL3	LL3	L$ L3	'L0,L3	3L= M	MMc                    | j                  t        d      5  t        j                  dddd       d d d        | j                  t        d      5  t        j                  dddd       d d d        | j                  t        d      5  t        j                  dddd       d d d        t        j                  dddd      } |       }| j                  t        d      5  |j	                          d d d        | j                  t        d	      5  |j                  d       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   ^xY w# 1 sw Y   y xY w)
Nz3With Py_RELATIVE_OFFSET, basicsize must be negativer   i  Tz.Member offset out of range \(0\.\.-basicsize\)rx  r   z,PyMember_GetOne used with Py_RELATIVE_OFFSETz,PyMember_SetOne used with Py_RELATIVE_OFFSET)rr   r   r   r~  r  r  )r"   r`  r  s      r   %test_heaptype_relative_members_errorsz:TestHeapTypeRelative.test_heaptype_relative_members_errors  sM   ##FH //4DAH ##NP//2tTBP ##NP//2r4@P 11!RDA5##LN&&(N ##LN&&q)N N!H HP PP PN NN Ns;   D%D1D=E	
E%D.1D:=E	EEc                    	 | j                  t              5  t        j                  d        d d d        | j                  t              5  t        j                  d       d d d        y # 1 sw Y   =xY w# 1 sw Y   y xY wNr   )r3   rs   r   pyobject_getitemdatar!   s    r   test_pyobject_getitemdata_errorz4TestHeapTypeRelative.test_pyobject_getitemdata_error  s`    By)**40 * y) **1- *) *) *)s   A)
A5)A25A>N)r&   r'   r(   r
   ri  rm  rv  r{  r  r  r  r    r   r   rR  rR  *  s9    7/" /"b6
A$4&DP**.r   rR  c                       e Zd Zd ZddZ ej                         d        Zd Zd Z	d Z
 G d d	ej                        Z ej                         d
        Z ej                         d        Zed        Zy)TestPendingCallsc                     fd}t        |      D ]C  }t        j                  t        j                         dz         	 t        j                  |      rD y )Nc                  (     j                  d        y r   r  )ls   r   callbackz6TestPendingCalls.pendingcalls_submit.<locals>.callback  s     HHTNr   g{Gz?)r   timesleeprandomr   _pending_threadfunc)r"   r  nr  rn   s    `   r   pendingcalls_submitz$TestPendingCalls.pendingcalls_submit  sJ    	
 qAJJv}}t+, 00:  r   Nc                     d}t        |      |k7  rj	 t	        d      D ]  }||z  }	 |r|j
                  j                         sA|dz  }| j                  |dk  d|t        |      fz         t        |      |k7  rjy )Nr   r   rP   i'  z(timeout waiting for %i callbacks, got %i)rs  r   verboseprintr   eventis_setr1   )r"   r  r  contextcountrn   r,  s          r   pendingcalls_waitz"TestPendingCalls.pendingcalls_wait  s    !fk 4[aC !w}}335QJEOOEEM:As1v;FH !fk r   c                 
   d}g } G d dt               } |       }g |_        d|_        ||j                  z  |_        d|_        t        j                         |_        t        j                         |_	        t        |j                        D cg c]$  }t        j                  | j                  |f      & }}t        j                  |      5  | j                  |j                  ||       d d d        y c c}w # 1 sw Y   y xY w)N    c                       e Zd Zy)8TestPendingCalls.test_pendingcalls_threaded.<locals>.fooNr1  r    r   r   r%  r    r,  r   r%  rX   r   targetr   )rq   r  r  nThreads	nFinished	threadingLocklockEventr  r   Threadpendingcalls_threadr   start_threadsr  )r"   r  threadsr%  r  rn   s         r   test_pendingcalls_threadedz+TestPendingCalls.test_pendingcalls_threaded  s     &%				> ~~'!) "'"2"2353q ##4+C+C*153 	 5 ++G4""799a9 545 54s   )C4C99Dc                    	 | j                  |j                  |j                         |j                  5  |xj                  dz  c_        |j                  }	 d d d        |j                  k(  r|j                  j                          y y # 1 sw Y   4xY w# |j                  5  |xj                  dz  c_        |j                  }	 d d d        n# 1 sw Y   nxY w|j                  k(  r|j                  j                          w w xY wrO   )r  r  r  r  r  r   r  r  r  r  rt  )r"   r  r  s      r   r  z$TestPendingCalls.pendingcalls_thread  s    		$$$WYY		:!!Q&!#--	 
 G,,,!!# - !!Q&!#--	 
 G,,,!!# -s.   &B "B

BD#"C	DC2Dc                 T    g }d}| j                  ||       | j                  ||       y )N@   )r  r  )r"   r  r  s      r   test_pendingcalls_non_threadedz/TestPendingCalls.test_pendingcalls_non_threaded  s.    
   A&q!$r   c                 v    d } |       }| j                  t        j                  |      |j                         y )Nc               3      K   d  y wr   r    r    r   r   genfz0TestPendingCalls.test_gen_get_code.<locals>.genf  s     E   )r0   r   gen_get_codegi_code)r"   r  gens      r   test_gen_get_codez"TestPendingCalls.test_gen_get_code  s+    f//4ckkBr   c                   J    e Zd Zej                  ZddZd Zd Zd Z	d Z
d Zy)	TestPendingCalls.PendingTaskNc                     || _         || _        || _        t        j                         | _        d | _        d | _        d | _        y r   )	r*   reqnotify_doner  	get_identcreator_tidrequester_tid
runner_tidr  )r"   r  taskidr  s       r   r   z%TestPendingCalls.PendingTask.__init__!  s?    DGDH*D(224D!%D"DODKr   c                     t        j                         | _        | j                          | j                  | j	                          y y r   )r  r  r  _runr  r!   s    r   runz TestPendingCalls.PendingTask.run+  s8    '113DOIIK+  " ,r   c                 &    | j                   | _        y r   )r  r  r!   s    r   r  z!TestPendingCalls.PendingTask._run2  s    ((DKr   c                 p     t        j                          _         fd j                  d       y )Nc                  z    t        j                         vrj                   d       y j                          y )NTensure_added)r  r  _add_pendingr  )r  r"   worker_tidss   r   r  zBTestPendingCalls.PendingTask.run_in_pending_call.<locals>.callback8  s5    
 &&(;%%hT%B
r   Tr  )r  r  r  r  )r"   r  r  s   ``@r   run_in_pending_callz0TestPendingCalls.PendingTask.run_in_pending_call5  s.    !*!4!4!6D hT:r   c                 F    t        j                  | j                  |f      S )Nr  )r  r  r  )r"   r  s     r   create_threadz*TestPendingCalls.PendingTask.create_threadC  s#    ##//!^ r   c                 b    | j                   #t        j                  d       | j                   "y y N{Gz?)r  r  r  r!   s    r   wait_for_resultz,TestPendingCalls.PendingTask.wait_for_resultI  s$    ++%

4  ++%r   )NN)r&   r'   r(   _testinternalcapipending_threadfuncr  r   r  r  r  r  r  r    r   r   PendingTaskr    s+    (;;		#	#	;		!r   r  c                     d}| j                  |      fd}t        j                  |      }t        j                  |g      5  	 d d d        | j                  j                  |       y # 1 sw Y   &xY w)Nz1Spam spam spam spam. Lovely spam! Wonderful spam!c                      t        j                         } j                  | h      }t        j                  |g      5  j                          d d d        y # 1 sw Y   y xY wr   )r  r  r  r   r  r  )tidrk  tasks     r   do_the_workzNTestPendingCalls.test_subthreads_can_handle_pending_calls.<locals>.do_the_workR  sK    %%'C""C5)A!//4$$& 544s   AA!r  )r  r  r  r   r  r0   r  )r"   payloadr  rk  r  s       @r   (test_subthreads_can_handle_pending_callsz9TestPendingCalls.test_subthreads_can_handle_pending_callsM  sf    E(	'
 K0++QC0 1 	g. 10s   A--A6c                 p   t        j                         }| j                  t        j                         j                  |       t               t               t        j                         fd}fdfd}fdfd}g }t        d      D ]2  }| j                  d| ||      }|j                  |        ||       4 j                          fd	}d
fd}	t        d      D 
cg c]  }
t        j                  |	       }}
t        j                  |      5  	 |D cg c]  }|j                   }}t        d      D 
cg c]  }
t        j                  ||f       }}
t        j                  |      5  	 	 d d d         |        d	 d d d        |D cg c]  }|j                   }}| j!                  ||       |D ]  }| j#                  d|j$                         5  | j'                  |j(                  |       | j'                  |j(                  |j                         | j!                  |j(                  |       d d d         y c c}
w c c}w c c}
w # t        $ r d w xY w# 1 sw Y   xY w# t        $ r d w xY w# 1 sw Y   xY wc c}w # 1 sw Y   xY w)Nc                 J    j                  |        j                  d       y )NTr  )r  _active_queues    r   	queue_putzQTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.queue_putg  s    MM$NN4 r   c                  d    	 j                         } | S # t        $ r t        j                  w xY wr   )popleft
IndexErrorqueueEmpty)r  r  s    r   	queue_getzQTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.queue_getj  s6    "~~' K  "kk!"s    /c                  l     j                           s	 j                          y y # t        $ r Y y w xY wr   )popreleaseRuntimeError)r  
_done_locks   r   queue_task_donezWTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.queue_task_donep  s1    KKM3&&(  $ 3s   ' 	33c                  
      S r   r    )r  s   r   queue_emptyzSTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.queue_emptyw  s    :r   c                  F     j                           j                          y r   )acquirer  )r  s   r   
queue_joinzRTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.queue_joiny  s      r   re   zrequest )r  r  r  c                 r    	 ry 	         }|j                  |        # t         j                  $ r Y y w xY wr   )r  r  r  )r  r  doner  s     r   	add_taskszQTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.add_tasks  sE    $;D ((5 
 {{ s     66Fc                              s  ry t        j                  d               s  st        j                  d        sy y r  )r  r  )r  r  s   r   	run_taskszQTestPendingCalls.test_many_subthreads_can_handle_pending_calls.<locals>.run_tasks  s7    !m

4  "m
 

4  r   r   r  r  Tztask )r  r  r0   main_threadidentr   r  r   r  r  r  r  r   r  BaseExceptionr  assertNotInr  r*   assertNotEqualr  )r"   main_tidr  r  r  tasksrn   r  r  r  _worker_threadsrk  r  r  runner_tidsr  r  r  r  r  r  s                   @@@@@@r   -test_many_subthreads_can_handle_pending_callsz>TestPendingCalls.test_many_subthreads_can_handle_pending_calls]  s   &&(..066A '^^%
	!		3		! rA##qcN+ $ D
 LLdO  		6 	! $)8-#+a $**)<#+ 	 -++N;0>?1qww?$)!H.$,q %++9K>R$,  .%33G< =  <& .33Uq||U3;/DdggY/0##D$6$6A##D$6$6H  !3!3[A 10 1-
 @.
 ) # =< ! ! <;& 4 10sy   9I -J/J3I%JI*4JI?J,J'6AJ,%
J/I<<I??J	JJJJ$,J5	c                 	    d}dt        j                         t        j                  d        fd} j                  d      5   |       \   |       \  t	        j                         dz   fd}t        j                  |      }t        j                  |g      5  t        j                  d	       t        j                        }t        j                  d
       d d d         j                  t                     d d d         j                  d      5   |       \   |       \  t	        j                         dz   fd}t        j                  |      }t        j                  |g      5  t        j                  d	       t        j                        }t        j                  d
       d d d         j                  t                     d d d         j                  d      5   |       \   |       \   |       \  }t	        j                         dz   fd}ddt        j                  ffd	}t        j                  |      }	t        j                  |      }
t        j                  |	|
g      5  s	 st        j                  d
       s:t	        j                   d       t	        j                         kD  rt#        d      s:t        j                  |d	      }d d d        t        j%                  d      } j                  |t                     d d d         j                  d      5   |       \   |       \   |       \  }t	        j                         dz   fd}ddt        j                  ffd	}fd}t        j                  |      }	t        j                  |      }
t        j                  |      }t        j                  |	|
|g      5  	 d d d        t        j                  |d	      }t        j%                  |d      } j                  |t                     d d d        y # 1 sw Y   xY w# 1 sw Y   zxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   rxY w# 1 sw Y   xY w# 1 sw Y   y xY w)N   r   zif True:
            import json
            import os
            import threading
            import time
            import _testinternalcapi
            from test.support import threading_helper
            c                       t        j                         \   j                   fd       j                  fd        fS )Nc                  .    t        j                         S r   r  close)rs   r   r  zTTestPendingCalls.test_isolated_subinterpreter.<locals>.create_pipe.<locals>.<lambda>      BHHQKr   c                  .    t        j                         S r   r  )ws   r   r  zTTestPendingCalls.test_isolated_subinterpreter.<locals>.create_pipe.<locals>.<lambda>  r  r   )r  pipe
addCleanup)r  r  r"   s   @@r   create_pipezBTestPendingCalls.test_isolated_subinterpreter.<locals>.create_pipe  s5    779DAqOO/0OO/0a4Kr   z"add in main, run in subinterpreterrF  c            
      F    t        j                   d d d d       y )Na<  if True:
                    # Wait until this interp has handled the pending call.
                    waiting = False
                    done = False
                    def wait(os_read=os.read):
                        global done, waiting
                        waiting = True
                        os_read(a
  , 1)
                        done = True
                    t = threading.Thread(target=wait)
                    with threading_helper.start_threads([t]):
                        while not waiting:
                            pass
                        os.write(, b'\0')
                        # Loop to trigger the eval breaker.
                        while not done:
                            time.sleep(0.01)
                            if time.time() > zT:
                                raise Exception('timed out!')
                    r   
run_stringinterpidr_donetimeoutw_readys   r   do_workz>TestPendingCalls.test_isolated_subinterpreter.<locals>.do_work  sA    (( 8! "( )" #* +. /6Y 7#4 r   r  rP   r   z-add in main, run in subinterpreter sub-threadc            
      F    t        j                   d d d d       y )Nzif True:
                    waiting = False
                    done = False
                    def subthread():
                        while not waiting:
                            pass
                        os.write(r  aO  :
                                raise Exception('timed out!')
                    t = threading.Thread(target=subthread)
                    with threading_helper.start_threads([t]):
                        # Wait until this interp has handled the pending call.
                        waiting = True
                        os.read(z=, 1)
                        done = True
                    r  r  s   r   r!  z>TestPendingCalls.test_isolated_subinterpreter.<locals>.do_work  sA    (( 8" #* +. /6Y 7! "( )!4 r   z"add in subinterpreter, run in mainc            
      r    t        j                  d       t        j                   d d d d       y NrP   zif True:
                    # Add the pending call and wait for it to finish.
                    actual = _testinternalcapi.pending_identify(zX)
                    # Signal the subinterpreter to stop.
                    os.write(z&, b'\0')
                    os.write(z4, actual.to_bytes(1, 'little'))
                    r  readr   r  r  main_interpidr_readyw_dataw_dones   r   add_jobz>TestPendingCalls.test_isolated_subinterpreter.<locals>.add_job#  K    #(( 8AAN P$X &$X &4 r   Fc                      d | d       dy NTrP   r    os_readr  r  waitings    r   waitz;TestPendingCalls.test_isolated_subinterpreter.<locals>.wait/      "r   r  
timed out!littlez(add in subinterpreter, run in sub-threadc            
      r    t        j                  d       t        j                   d d d d       y r$  r%  r'  s   r   r,  z>TestPendingCalls.test_isolated_subinterpreter.<locals>.add_jobJ  r-  r   c                      d | d       dy r/  r    r0  s    r   r3  z;TestPendingCalls.test_isolated_subinterpreter.<locals>.waitV  r4  r   c                      s	 st        j                  d        s;t        j                  d       t        j                         kD  rt	        d       s:y y )Nr   r  r5  )r  writer  r  	Exception)r  r  r   r2  s   r   	subthreadz@TestPendingCalls.test_isolated_subinterpreter.<locals>.subthread[  sI    ! "%(JJt$yy{W,'55 r   )r   creater  r  r  r  r  r   r  r  r&  r  pending_identifyr:  r0   rz  r  r;  
from_bytesstartjoin)r"   maxtextr  r!  rk  actualr_datar,  r3  t1t2textr<  t3r  r  r(  r  r)  r  r*  r+  r   r2  s   `             @@@@@@@@@@r   test_isolated_subinterpreterz-TestPendingCalls.test_isolated_subinterpreter  s     '')   0 		 \\>?*}GW'MNFFiikB&G*   0A!//4#*;;HE' 5 VS]3E @H \\IJ*}GW'MNFFiikB&G(   0A!//4#*;;HE' 5 VS]3C KF \\>?*}GW'MNFF'MNFFiikB&G  GDWW 
 !!1B!!.B!//R9! "%(JJt$yy{W,'55  wwvq) : ^^D(3FVS%78K @N \\DE*}GW'MNFF'MNFFiikB&G  GDWW 
6 !!1B!!.B!!3B!//R= >7761%D^^D(3FVS%78Q FV 	} 547 @?| 545 KJx :93 @?T >=G FV 	s   A R0AR 2#R.A R'AR#R'BS)R40AR4R49S*B<S&S(AS R
	RRR$	R''R14R>	9SSS	SS#r   )r&   r'   r(   r  r  r   requires_working_threadingr  r  r  r  r  SimpleNamespacer  r  r
  r   rI  r    r   r   r  r    s    $& 1002: 3:(
$%C
.!e++ .!` 1002/ 3/ 1002\B 3\B| ^4 ^4r   r  c                   ~   e Zd Z ej                   eed      d      d        Z ej                   eed      d      d        Zd Z	 ej                   eed      d      d        Z
 ej                  edu d       ej                   eed      d      d	               Zd
 Z ej                  edu d      d        Zy)SubinterpreterTestr  zrequires os.pipe()c                    dd l }t        j                         \  }}dj                  |      }t	        |d      5 }t        j                  |      }| j                  |d       | j                  t        j                  |      t        t        j                               | j                  t        j                  |      t        |             d d d        y # 1 sw Y   y xY w)Nr   zif 1:
            import sys, builtins, pickle
            with open({:d}, "wb") as f:
                pickle.dump(id(sys.modules), f)
                pickle.dump(id(builtins), f)
            rb)builtinsr  r  formatopenr   run_in_subinterpr0   r  pickleloadr*   rj   modules)r"   rP  r  r  r@   frets          r   test_subinterpsz"SubinterpreterTest.test_subinterps  s    wwy1
 q	 	 !T]a**40CS!$A3;;@A8=	 ]]s   BCCc                 4   t        j                         \  }}dj                  |      }t        |d      5 }t	        j
                  |      }| j                  |d       | j                  t        j                  |      ddd       d d d        y # 1 sw Y   y xY w)Naa  if 1:
            import pickle
            with open({:d}, "wb") as f:

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

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

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

                pickle.dump(dict(a=a, b=b), f)
            rO  r   123xr  )r,  r   )	r  r  rQ  rR  r   rS  r0   rT  rU  )r"   r  r  r@   rW  rX  s         r   (test_subinterps_recent_language_featuresz;SubinterpreterTest.test_subinterps_recent_language_features  sz    wwy1 q	 	 !T]a**40CS!$V[[^6-FG ]]s   ABBc                     d}t        j                         }| j                  t        j                  |      dd       t        j                         }| j                  ||d       | j                  ||d       y )Na  if 1:
        import sys, _testinternalcapi

        # Any config value would do, this happens to be the one being
        # double checked at the time this test was written.
        config = _testinternalcapi.get_config()
        config['int_max_str_digits'] = 55555
        config['parse_argv'] = 0
        _testinternalcapi.set_config(config)
        sub_value = _testinternalcapi.get_config()['int_max_str_digits']
        assert sub_value == 55555, sub_value
        r   z%subinterp code failure, check stderr.z7Expected get_config() to return a new dict on each callzJCAUTION: Tests executed after this may be running under an altered config.)r  
get_configr0   r   rS  assertIsNot)r"   r@   before_configafter_configs       r   (test_py_config_isoloated_per_interpreterz;SubinterpreterTest.test_py_config_isoloated_per_interpreter  sx    
 *44611$7@	B(335|I	K 	<	=r   c                    	 dd l }d}d}d}d}d}d}||z  |z  |z  |z  |z  }g d}	|	D 
cg c]  }
d	|
 	 }}
d
|d<   d|d<   d|d<   |df|df||z  dfdj                         D ]  \  }}t        t        ||            }|\  }}||d}| j	                  |      5  t        j                         \  }}t        j                  d| d      }t        j                  |      5 }t        j                  |fi |}| j                  |d       |j                         }d d d         |j                        }| j                  ||       d d d         dD ]z  }t        t        ||            }| j	                  |      5  t        j                  d      }| j                  t               5  t        j                  |fi | d d d        d d d        | y c c}
w # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   2xY w# 1 sw Y   xY w)Nr   r  r               )obmallocforkr  r  daemon_threads
extensionsown_gilallow_use_main_obmalloccheck_multi_interp_extensionsrl  r   TF))TTTTTTT)TFFFFFF)FFFTFTFfeature_flagsrl  z
                    import _testinternalcapi, json, os
                    settings = _testinternalcapi.get_interp_settings()
                    with os.fdopen(zX, "w") as stdin:
                        json.dump(settings, stdin)
                    ))FFFFFFFz
                    import _testinternalcapi
                    _testinternalcapi.get_interp_settings()
                    raise NotImplementedError('unreachable')
                    )jsonitemsr
  zipr  r  r  r;   r<   fdopenr   run_in_subinterp_with_configr0   r&  loadsr3   r  )r"   rs  OBMALLOC
EXTENSIONSTHREADSDAEMON_THREADSFORKEXEC	ALL_FLAGSfeaturesr  kwlistconfigr  kwargs	exp_flagsexp_gilr  r  scriptstdoutrX  rD   settingss                           r   test_configured_settingsz+SubinterpreterTest.test_configured_settings  s5   	
 	
_t+g5F!"	
 )111F1#,1'q	4r
r

 D!5!:%u-!
 %'!FH #ff-.F!)Iw!*"H f%wwy1! .$ %&3 '*  YYq\V!>>vPPC$$S!, ++-C " &4::c?  84 &%!>
F #ff-.Ff%! . 
 &&|488J6J 5 &%	
K 28 "\ &%6 54 &%sN   GAG!!9G,G!;+G:&G.=G:GG!!G+	.G73G::H	Nz%test requires _testsinglephase modulec                    	
 	 dd l 
d}dd}d}d}d}||z  |z  |z  |z  dddddd	d
		
 fd}d  _         j                  d      5   |d	d       d d d         j                  d      5   |d	d       d d d         j                  d      5   |d	d       d d d         j                  d      5   |dd       d d d         j                  d      5   |dd       d d d         j                  d      5   |dd       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   txY w# 1 sw Y   ]xY w# 1 sw Y   y xY w)Nr   r  r   rd  re  rf  rg  TF)rn  
allow_fork
allow_execallow_threadsallow_daemon_threadsrl  c                    t        |       }| rz  n}|dd}|d|d||||  |r|dkD  n|  |  d
}t        j                         \  }}t        j                  d| d| d      }t        j
                  |      5 }	t        j                  |fi |}
j                  |
d       |	j                         }d d d         j                        }j                  ||       y # 1 sw Y   .xY w)	N)ro  Frq  r   )
	requestedoverride__initialoverride_afteroverride_restoredsettings__initialsettings_aftersettings_restoredallowed__initialallowed_afterallowed_restoredzu
                from test.test_capi.check_config import run_singlephase_check
                run_singlephase_check(z, z)
                )r
  r  r  r;   r<   rv  r   rw  r0   r&  rx  )enabledoverrider  flagsr  r  r  r  r  r  rX  rD   results
BASE_FLAGSrz  base_kwargsrs  r"   s                r   rf  zTSubinterpreterTest.test_overridden_setting_extensions_subinterp_check.<locals>.checkP  s   .5F 07J+JE!& H &%&"*%&%-"*%-(/K8@x!|g!N(/KH 779DAq__ *''/j1# 6& F 1::6LVL  a(kkm  !djjoGWh/ s   <9C""C+z*config: check disabled; override: disabledr   z,config: check disabled; override: use configz)config: check disabled; override: enabledrP   z)config: check enabled; override: disabledz+config: check enabled; override: use configz(config: check enabled; override: enabled)rs  maxDiffr  )r"   ry  r{  r|  r}  r~  rf  r  rz  r  rs  s   `      @@@@r   2test_overridden_setting_extensions_subinterp_checkzESubinterpreterTest.test_overridden_setting_extensions_subinterp_check5  sP   	 	
_t+g5F
!%!$(
%	0 %	0N  \\FG% H\\HI%O J\\EF%O G \\EF$O G\\GH$N I\\DE$N FE HGIIFF GFHHEEsH   
D2
D
D)8
D5
E>
EDD&)D25D>E
Ec                     	 dd l }t        j                  d       | j                  t	        |j
                  d             y )Nr   z1import binascii; binascii.Error.foobar = 'foobar'foobar)binasciir   rS  assertFalser  Error)r"   r  s     r   test_mutate_exceptionz(SubinterpreterTest.test_mutate_exception  s4    	 	  !TU:;r   $test requires _testmultiphase modulec                    	 t        j                         \  }}| j                  t         j                  |       | j                  t         j                  |       t	        j
                  d| d      }t        |       t        j                  |d      }t        j                  |      }| j                  |d       t        j                  |d      }| j                  ||       y )Na  
            import importlib.machinery
            import importlib.util
            import os

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

            os.write(z, attr_id)
            d   r   )r  r  r  r  r;   r<   r  r&  r   rS  r0   )r"   r  r  r  main_attr_idrX  subinterp_attr_ids          r   "test_module_state_shared_in_globalz5SubinterpreterTest.test_module_state_shared_in_global  s    	 wwy1!$!$ & S "  	Vwwq#&&v.a GGAsO'89r   )r&   r'   r(   r   rM  r  r  rY  r\  rb  r  r   _testsinglephaser  r  _testmultiphaser  r    r   r   rM  rM    s
   XV,.BC> D> XV,.BCH DH*=D XV,.BCJK DJKX X__%-/VWXV,.BCP D XPd< X___,.TU: V:r   rM  c                   >    e Zd Zeeeee ed      ee	e
eegZd Zd Zy)BuiltinStaticTypesTestsNc                     | j                   D ]C  }| j                  |      5  t        j                  |      }| j	                  |d        d d d        E y # 1 sw Y   PxY wr   )TYPESr  r   type_get_tp_basesr_  )r"   typeobjbasess      r   test_tp_bases_is_setz,BuiltinStaticTypesTests.test_tp_bases_is_set  sM     zzGg&!33G<  - '& "&&   (AA	c                     | j                   D ]C  }| j                  |      5  t        j                  |      }| j	                  |d        d d d        E y # 1 sw Y   PxY wr   )r  r  r   type_get_tp_mror_  )r"   r  r  s      r   test_tp_mro_is_setz*BuiltinStaticTypesTests.test_tp_mro_is_set  sM     zzGg&//8  d+ '& "&&r  )r&   r'   r(   rq   rf  rz  r   r
  boolr  r;  Warningrx  r  r  r  r    r   r   r  r    s:     	T
E.,r   r  c                   J    e Zd ZdZed        Zej                  d        Zd Z	y)TestStaticTypesFc                 T    | j                   rt        j                  d      d| _         y )Nz%these tests do not support re-runningT)_has_runr   SkipTest)rO  s    r   
setUpClasszTestStaticTypes.setUpClass  s$     <<##$KLLr   c              '   8   K   t        j                  | }| y wr   )r   get_basic_static_type)r"   r   rO  s      r   basic_static_typez!TestStaticTypes.basic_static_type  s     --t4	s   c                 F   | j                         5 }| j                  |j                  t               | j	                  |j
                  t        f       | j                  t        |      t        t                     d d d        | j                  t              5 }| j                  |j                  t               | j	                  |j
                  t        f       | j                  t        |      t        t                     d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wr   )r  rN  __base__rq   r0   	__bases__rf  )r"   rO  s     r   %test_pytype_ready_always_sets_tp_typez5TestStaticTypes.test_pytype_ready_always_sets_tp_type  s     ##%MM#,,/S]]VI6MM$s)T&\2 & ##F+sMM#,,/S]]VI6MM$s)T&\2 ,+ &% ,+s   A*DA*DDD N)
r&   r'   r(   r  classmethodr  
contextlibcontextmanagerr  r  r    r   r   r  r    s8    H   4r   r  c                       e Zd Zej                   ej
                         d               Zej                   ej
                         d               Zej                   ej
                         d               Zd Z	y)TestThreadStatec                       fd} |        t        j                  |      }|j                          |j                          y )Nc                      g fd} t         j                  |        | x}}t        j                  d       j	                  j                  t        j                               dd       y )Nc                  L     j                  t        j                                y r   )r  r  r  )identss   r   r  zCTestThreadState.test_thread_state.<locals>.target.<locals>.callback  s    i1134r   rP   r   z/Couldn't find main thread correctly in the list)r   _test_thread_stater  r  r0   r  r  r  )r  r,  r   r  r"   s      @r   r  z1TestThreadState.test_thread_state.<locals>.target  sZ    F5 ((2AJJqMV\\)*=*=*?@!NPr   r  )r  r  r@  rA  )r"   r  rk  s   `  r   test_thread_statez!TestThreadState.test_thread_state  s2    	P 	F+			r   c                 z     G d d      t        j                         fd}t        j                  |       y )Nc                       e Zd Zd Zy)8TestThreadState.test_thread_gilstate_in_clear.<locals>.Cc                 ,    t         j                          y r   )r   gilstate_ensure_releaser!   s    r   r   z@TestThreadState.test_thread_gilstate_in_clear.<locals>.C.__del__  s    113r   N)r&   r'   r(   r   r    r   r   r   r    s    4r   r   c                               _         y r   rB  )r   	local_vars   r   r  z?TestThreadState.test_thread_gilstate_in_clear.<locals>.callback  s    #IKr   )r  localr   r  )r"   r  r   r  s     @@r   test_thread_gilstate_in_clearz-TestThreadState.test_thread_gilstate_in_clear  s0    	4 	4
 OO%		 	$$X.r   c                     t        j                  d      }t        ddd|      }| j                  d|j                         y )Nz
            import _testcapi

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

            _testcapi._test_thread_state(callback)
            z-Xtracemallocr:   s   callback called)r;   r<   r   r   rD   )r"   r@   rX  s      r    test_gilstate_ensure_no_deadlockz0TestThreadState.test_gilstate_ensure_no_deadlock#  s<         t]D$?(#''2r   c                 ,    t         j                          y r   )r   test_current_tstate_matchesr!   s    r   test_gilstate_matches_currentz-TestThreadState.test_gilstate_matches_current2  s    --/r   N)
r&   r'   r(   r   reap_threadsrJ  r  r  r  r  r    r   r   r  r    s    ""0002 3 #( ""0002/ 3 #/ ""00023 3 #30r   r  c                       e Zd Z e       j	                  d  ee      D                ej                  e	      d        Z
d Zy)Test_testcapic              #      K   | ]8  }|j                  d       r%|j                  d      s|t        t        |      f : yw)test__codeN)r?   endswithgetattrr   .0r  s     r   	<genexpr>zTest_testcapi.<genexpr>7  s<      P .w/g8N 79d34 .s   >A r  c                 ,    t         j                          y r   )r   test_widecharr!   s    r   r  zTest_testcapi.test_widechar<  s    !r   c                 `    | j                  t        j                  t        j                         y r   )r0   r   
Py_Versionrj   
hexversionr!   s    r   test_version_api_dataz#Test_testcapi.test_version_api_data@  s    --s~~>r   N)r&   r'   r(   localsupdatedirr   r	   rP  rx  r  r  r    r   r   r  r  6  sL    
HOO P #IP P
 %_$$.@A" B"?r   r  c                   R    e Zd Z e       j	                  d  ee      D               y)Test_testinternalcapic              #   b   K   | ]'  }|j                  d       r|t        t        |      f ) yw)r  N)r?   r  r  r  s     r   r  zTest_testinternalcapi.<genexpr>E  s1      1 6w/ 7#4d;< 6s   -/N)r&   r'   r(   r  r  r  r  r    r   r   r  r  D  s#    
HOO 1 #$5 61 1r   r  r  c                   2    e Zd Z	 d Zd Zd Zd Zd Zd Zy)Test_ModuleStateAccessc                 H   d}t         j                  j                  d      j                  }t         j                  j                  ||      }t         j                  j                  ||      }t         j                  j                  |      }|j                  |       || _	        y )N!_testmultiphase_meth_state_accessr  )
	importlibutil	find_specorigin	machineryExtensionFileLoaderspec_from_loadermodule_from_specexec_moduler  )r"   fullnamer  loaderspecr  s         r   setUpzTest_ModuleStateAccess.setUpR  sy    6))*;<CC$$886J~~..x@0066"r   c                     	  G d d| j                   j                        } |       }| j                  |j                         | j                          y )Nc                       e Zd Zy)QTest_ModuleStateAccess.test_subclass_get_module.<locals>.StateAccessType_SubclassNr1  r    r   r   StateAccessType_Subclassr  ]  r2  r   r  r  StateAccessTyperN  get_defining_moduler"   r  r  s      r   test_subclass_get_modulez/Test_ModuleStateAccess.test_subclass_get_module[  s@    1	t{{'B'B 	 ,-h224dkkBr   c                      G d d| j                   j                        } |       }| j                  |j                         | j                          y )Nc                        e Zd Z fdZ xZS )\Test_ModuleStateAccess.test_subclass_get_module_with_super.<locals>.StateAccessType_Subclassc                      t         |          S r   )r   r  r   s    r   r  zpTest_ModuleStateAccess.test_subclass_get_module_with_super.<locals>.StateAccessType_Subclass.get_defining_modulee  s    w244r   )r&   r'   r(   r  r   r   s   @r   r  r  d  s    5 5r   r  r  r  s      r   #test_subclass_get_module_with_superz:Test_ModuleStateAccess.test_subclass_get_module_with_superc  s=    	5t{{'B'B 	5 ,-h224dkkBr   c                    	 | j                   j                         }| j                   j                         }|j                  |j                  d}|j	                         D ]  \  }}| j                  |      5  | j                  |j                         |j                                | j                  |j                         d        |        | j                  |j                         |j                                | j                  |j                         d        |d       | j                  |j                         |j                                | j                  |j                         d        |dd       | j                  |j                         |j                                | j                  |j                         d       | j                  t              5   |d	       d d d        | j                  t              5   |dd
d       d d d        d d d         y # 1 sw Y   =xY w# 1 sw Y   !xY w# 1 sw Y   xY w)N)clinicnoclinicr   rP   r   r   rp  T)twice)thricerX   )
r  r  increment_count_clinicincrement_count_noclinicrt  r  r0   	get_countr3   rs   )r"   r,  r   methodsr  increment_counts         r   test_state_accessz(Test_ModuleStateAccess.test_state_accessk  s   	 KK'')KK'') ..22

 &-]]_!D/d#  >  2!  >  2"  >  2$/  >  2&&y1#1- 2 &&y1#Aq!, 2' $# &5" 21 21' $#s=   7E'H<
H$(H<H0H<$H-)H<0H95H<<I	c                     | j                   j                         }| j                  t              5  |j	                          d d d        y # 1 sw Y   y xY wr   )r  r  r3   rs   getmodulebydef_bad_def)r"   r  s     r   test_get_module_bad_defz.Test_ModuleStateAccess.test_get_module_bad_def  s<     ;;..0y)++- *))s   A

Ac                      G d dt         | j                  j                        }| j                   |       j	                         | j                         y )Nc                       e Zd Zy)FTest_ModuleStateAccess.test_get_module_static_in_mro.<locals>.SubclassNr1  r    r   r   Subclassr,    r2  r   r-  )r  r  r  rN  r  )r"   r-  s     r   test_get_module_static_in_mroz4Test_ModuleStateAccess.test_get_module_static_in_mro  s7    	}dkk&A&A 	hj446Dr   N)	r&   r'   r(   r  r  r  r&  r)  r.  r    r   r   r  r  J  s'    /CC$-L.Er   r  c                   .    e Zd Zed        Zd Zd Zd Zy)TestInternalFrameApic                  *    t        j                         S r   )rj   	_getframer    r   r   funczTestInternalFrameApi.func  s    }}r   c                     | j                         }t        j                  |      }| j                  || j                   j                         y r   )r3  r  iframe_getcoderN  r  )r"   framer@   s      r   	test_codezTestInternalFrameApi.test_code  s5    		 //6dDII../r   c                     | j                         }t        j                  |      }| j                  |d       | j	                  |t        | j                   j                  j                               y r  )r3  r  iframe_getlastir   r\  rs  r  co_code)r"   r6  lastis      r   
test_lastizTestInternalFrameApi.test_lasti  sP    		!11%85!$s499#5#5#=#=>?r   c                     | j                         }t        j                  |      }| j                   j                  j                  }| j                  ||dz          y )NrX   )r3  r  iframe_getliner  co_firstlinenor0   )r"   r6  line	firstlines       r   	test_linezTestInternalFrameApi.test_line  sF    		 //6II&&55	y1}-r   N)r&   r'   r(   staticmethodr3  r7  r<  rB  r    r   r   r0  r0    s$     0
@.r   r0  r  c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	Test_Pep523APIc                    g }t         }|t         z   }	 t        |      D ]#  }||k(  rt        j                  |        |        % 	 t        j                          |t         z  }| j                  t        |      t        |             t        ||d      D ]  \  }}	| j                  ||	        y # t        j                          w xY w)NT)strict)"SUFFICIENT_TO_DEOPT_AND_SPECIALIZEr   r  set_eval_frame_recordset_eval_frame_defaultr0   rs  ru  )
r"   r3  r  actual_callsr@  r  rn   expected_callsr  rC  s
             r   do_testzTest_Pep523API.do_test  s    2::	75\:%;;LI "
 446!CC^,c,.?@ #NL NHfXv. !O 446s   1B/ /Cc                 P     G d d      fd}ddg}| j                  ||       y )Nc                       e Zd Zd Zy)4Test_Pep523API.test_inlined_binary_subscr.<locals>.Cc                      y r   r    )r"   others     r   ro   z@Test_Pep523API.test_inlined_binary_subscr.<locals>.C.__getitem__  rp   r   N)r&   r'   r(   ro   r    r   r   r   rP    s    r   r   c                               d    y Nr   r    )r   s   r   r3  z7Test_Pep523API.test_inlined_binary_subscr.<locals>.func  s    CGr   r3  ro   rM  )r"   r3  r  r   s      @r   test_inlined_binary_subscrz)Test_Pep523API.test_inlined_binary_subscr  s*    	 		'T5!r   c                 D    ddfd}g d}| j                  ||       y )Nc                      y r   r    r  s    r   innerz/Test_Pep523API.test_inlined_call.<locals>.inner  r  r   c                  $                d       y rT  r    rY  s   r   r3  z.Test_Pep523API.test_inlined_call.<locals>.func  s    G"Ir   )r3  rY  rY  )r   rU  r"   r3  r  rY  s      @r   test_inlined_callz Test_Pep523API.test_inlined_call  s"    		 +T5!r   c                 B    d fd}ddg}| j                  ||       y )Nc                      y r   r    r  s    r   rY  z;Test_Pep523API.test_inlined_call_function_ex.<locals>.inner  r  r   c                        dg  y rT  r    r[  s   r   r3  z:Test_Pep523API.test_inlined_call_function_ex.<locals>.func  s    B4Lr   r3  rY  rU  r\  s      @r   test_inlined_call_function_exz,Test_Pep523API.test_inlined_call_function_ex  s%    		!T5!r   c                 B    d fd}g d}| j                  ||       y )Nc               3      K   d y wrT  r    r    r   r   r  z1Test_Pep523API.test_inlined_for_iter.<locals>.gen       Hr  c                              D ]  }  y r   r    )r  r  s    r   r3  z2Test_Pep523API.test_inlined_for_iter.<locals>.func  s    U r   )r3  r  r  r  rU  )r"   r3  r  r  s      @r   test_inlined_for_iterz$Test_Pep523API.test_inlined_for_iter  s"    		 .T5!r   c                 h     G d d       G d d      fd}g d}| j                  ||       y )Nc                       e Zd Zed        Zy)0Test_Pep523API.test_inlined_load_attr.<locals>.Cc                      yrT  r    r!   s    r   r,  z2Test_Pep523API.test_inlined_load_attr.<locals>.C.a  s    r   N)r&   r'   r(   propertyr,  r    r   r   r   ri    s     r   r   c                       e Zd Zd Zy)0Test_Pep523API.test_inlined_load_attr.<locals>.Dc                      yrT  r    )r"   r  s     r   __getattribute__zATest_Pep523API.test_inlined_load_attr.<locals>.D.__getattribute__  s    r   N)r&   r'   r(   ro  r    r   r   Drm    s    r   rp  c                  J             j                            j                    y r   r  )r   rp  s   r   r3  z3Test_Pep523API.test_inlined_load_attr.<locals>.func  s    CEECEEr   )r3  r,  ro  rU  )r"   r3  r  r   rp  s      @@r   test_inlined_load_attrz%Test_Pep523API.test_inlined_load_attr  s1    	 		 		 2T5!r   c                 N    d fdfd}g d}| j                  ||       y )Nc               3      K   d y wrT  r    r    r   r   rY  z/Test_Pep523API.test_inlined_send.<locals>.inner 	  rd  r  c               3   0   K            E d {    y 7 wr   r    r[  s   r   outerz/Test_Pep523API.test_inlined_send.<locals>.outer	  s     ws   c                  &    t                        y r   )r   )rv  s   r   r3  z.Test_Pep523API.test_inlined_send.<locals>.func	  s    Mr   )r3  rv  rv  rY  rY  rv  rY  rU  )r"   r3  r  rY  rv  s      @@r   test_inlined_sendz Test_Pep523API.test_inlined_send  s%    			NT5!r   N)
r&   r'   r(   rM  rV  r]  ra  rf  rr  rx  r    r   r   rE  rE    s%    / """"""r   rE  __main__)Cr  collectionsr   r   r  importlib.machineryr  importlib.utilrs  r  rT  r  r  
subprocessrj   r;   r  r  r  r   r  r:  rZ  r.   r   test.supportr   r   r   r	   r
   test.support.script_helperr   r   r   rt   ImportErrorr  r  _xxsubinterpretersr   ModuleNotFoundErrorr  r   r  r   r   r   r#   r%   TestCaser,   rR  r  rM  r  r  r  r  r  r   r  r0  rH  rE  r&   mainr    r   r   <module>r     sQ    *     	     
          - & ) ( - d d.
 (M''4	  <=
: :\#x   \#~ W.8,, W. W.tV4x(( V4rV:** V:r,h// ,B 4h''  4F80h'' 80v?H%% ?1H-- 1 D(*PQTEX.. TE RTEn.8,, .0 &) "K"X&& K"\ zHMMO SG    O    MsH   G5 	H H H 5H ?H HHHHH*)H*