ó
\K]c           @  sÁ  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l j Z d  d l m	 Z	 m
 Z
 d  d l m Z m Z m Z d  d l m Z d d l m Z e ƒ  Z e j d ƒ e ƒ  Z e j d	 ƒ e ƒ  Z d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d e! f d „  ƒ  YZ" d „  Z# d „  Z$ d „  Z% d „  Z& d „  Z' d „  Z( d e f d „  ƒ  YZ) e* d  k r½e j+ ƒ  n  d S(!   iÿÿÿÿ(   t   print_functionN(   t   CFGrapht   Loop(   t   compile_extrat   compile_isolatedt   Flags(   t   typesi   (   t   TestCaset   enable_pyobjectt   force_pyobjectt   _Dummyc           B  s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C  s#   | |  _  | |  _ | j |  ƒ d  S(   N(   t   recordert   namet
   _add_dummy(   t   selfR   R   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   __init__   s    		c         C  s5   t  | t ƒ s t ‚ t |  j d |  j | j f ƒ S(   Ns   %s + %s(   t
   isinstanceR
   t   AssertionErrorR   R   (   R   t   other(    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   __add__   s    c         C  s   t  |  j d |  j ƒ S(   Ns   iter(%s)(   t   _DummyIteratorR   R   (   R   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   __iter__!   s    (   t   __name__t
   __module__R   R   R   (    (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyR
      s   		R   c           B  s   e  Z d  Z d „  Z e Z RS(   i    c         C  sG   |  j  d k r t ‚ n  |  j  d 7_  t |  j d |  j |  j  f ƒ S(   Ni   i   s   %s#%s(   t   countt   StopIterationR
   R   R   (   R   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   __next__)   s    	(   R   R   R   R   t   next(    (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyR   %   s   	t   RefRecorderc           B  s_   e  Z d  Z d „  Z d „  Z d „  Z e Z d „  Z d „  Z e	 d „  ƒ Z
 e	 d „  ƒ Z RS(   s˜   
    An object which records events when instances created through it
    are deleted.  Custom events can also be recorded to aid in
    diagnosis.
    c         C  s(   t  j t ƒ |  _ g  |  _ i  |  _ d  S(   N(   t   collectionst   defaultdictt   intt   _countst   _eventst   _wrs(   R   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyR   9   s    	c         C  s   t  |  | ƒ S(   sK   
        Make an object whose deletion will be recorded as *name*.
        (   R
   (   R   R   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt
   make_dummy>   s    c         C  s)   t  j | |  j ƒ } | j |  j | <d  S(   N(   t   weakreft   reft   _on_disposalR   R"   (   R   t   dummyt   wr(    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyR   D   s    c         C  s>   |  j  | d } | |  j  | <|  j j | j d | ƒ ƒ d S(   sr   
        Manually append *event* to the recorded events.
        *event* can be formatted using format().
        i   R   N(   R    R!   t   appendt   format(   R   t   eventR   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   markJ   s    c         C  s&   |  j  j | ƒ } |  j j | ƒ d  S(   N(   R"   t   popR!   R)   (   R   R(   R   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyR&   S   s    c         C  s   g  |  j  D] } | ƒ  ^ q
 S(   sC   
        A list of objects which haven't been deleted yet.
        (   R"   (   R   R(   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   aliveW   s    c         C  s   |  j  S(   s,   
        A list of recorded events.
        (   R!   (   R   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   recorded^   s    (   R   R   t   __doc__R   R#   R   t   __call__R,   R&   t   propertyR.   R/   (    (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyR   2   s   						c         C  sV   |  d ƒ } |  d ƒ } |  d ƒ } | | } |  j  d ƒ | | } |  j  d ƒ | S(   Nt   at   bt   cs   --1--s   --2--(   R,   (   t   recR3   R4   R5   t   d(    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   simple_usecase1f   s    

c         C  s;   |  d ƒ } |  d ƒ } |  j  d ƒ | } | } d  } | S(   NR3   R4   s   --1--(   R,   t   None(   R6   R3   R4   t   xt   y(    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   simple_usecase2p   s    c         C  sm   |  d ƒ } |  d ƒ } |  d ƒ } | } x% | D] } | | } |  j  d ƒ q1 W|  j  d ƒ | | } | S(   NR3   R4   R5   s   --loop bottom--s   --loop exit--(   R,   (   R6   R3   R4   R5   R:   R;   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   looping_usecase1y   s    

c         C  sä   |  d ƒ } |  d ƒ } |  d ƒ } x¬ | D]— } |  j  d ƒ | | } | | } |  j  d ƒ x2 | D]* } |  j  d ƒ | | } |  j  d ƒ qf W|  j  d ƒ | r´ | | } n P|  j  d	 ƒ q+ W|  j  d
 ƒ |  j  d ƒ | S(   NR3   R4   t   cums   --outer loop top--s   --inner loop entry #{count}--s   --inner loop top #{count}--s   --inner loop bottom #{count}--s   --inner loop exit #{count}--s   --outer loop bottom #{count}--s   --outer loop else--s   --outer loop exit--(   R,   (   R6   R3   R4   R>   R:   t   zR;   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   looping_usecase2…   s(    


c         c  s&   |  d ƒ } |  d ƒ } | V| Vd  S(   NR3   R4   (    (   R6   R3   R4   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   generator_usecase1ž   s    c         c  s7   |  d ƒ } |  d ƒ } x | D] } | Vq W| Vd  S(   NR3   R4   (    (   R6   R3   R4   R:   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   generator_usecase2¤   s
    	t   MyErrorc           B  s   e  Z RS(    (   R   R   (    (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyRC   ¬   s   c         C  s   t  |  ƒ ‚ d  S(   N(   RC   (   R:   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   do_raise¯   s    c         C  sW   |  d ƒ } |  d ƒ } |  d ƒ } | rK t  d ƒ |  d ƒ } | | n  | | d  S(   NR3   R4   R7   t   fooR5   (   RD   (   R6   R3   R4   R7   R5   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   raising_usecase1²   s    
c         C  sC   |  d ƒ } |  d ƒ } | r7 |  d ƒ } t  | ƒ n  | | d  S(   NR3   R4   R5   (   RD   (   R6   R3   R4   R5   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   raising_usecase2¼   s    c         C  s1   |  d ƒ } |  d ƒ } | r- t  | ƒ ‚ n  d  S(   NR3   R4   (   RC   (   R6   R3   R4   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   raising_usecase3Ä   s    c         C  s¿   d } x¥ t  | ƒ D]— } |  j t | ƒ ƒ d } xh t  | ƒ D] } d SW| d k  r\ q n4 | d k r x t  | ƒ D] } | SW|  j d ƒ n  |  j d ƒ |  j d ƒ q W|  j d ƒ d S(   sN   
    This test reveal a bug that there is a del on uninitialized variable
    i   i    i   t   FAILEDt   OKiÿÿÿÿ(   t   rangeR,   t   str(   R6   t   nt   it   j(    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   del_before_definitionË   s     c         c  sE   x> t  r@ |  j d ƒ d V|  d ƒ } | r |  j d ƒ q q Wd S(   s^   
    test to reveal bug of invalid liveness when infinite loop has multiple
    backedge.
    t   yieldNt   pt   bra(   t   TrueR,   (   R6   RR   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   inf_loop_multiple_back_edgeâ   s    	t   TestObjLifetimec           B  s˜   e  Z d  Z d „  Z 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 „  Z RS(   sH   
    Test lifetime of Python objects inside jit-compiled functions.
    c         C  s"   t  | t j f d t ƒ} | j S(   Nt   flags(   R   R   t   pyobjectt   forceobj_flagst   entry_point(   R   t   pyfunct   cr(    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   compileõ   s    c         C  sU   t  ƒ  } |  j | ƒ } | d  k	 rG |  j | ƒ  | | ƒ Wd  QXn
 | | ƒ | S(   N(   R   R]   R9   t   assertRaises(   R   R[   t   raisesR6   t   cfunc(    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   compile_and_recordù   s    	
c         C  ss   g  } | j  } t | ƒ } x7 | D]/ } | | k r" | j | ƒ | j | ƒ q" q" W|  j | | d | f ƒ d S(   sk   
        Check that the *expected* markers occur in that order in *rec*'s
        recorded events.
        s'   the full list of recorded events is: %rN(   R/   t   listR)   t   removet   assertEqual(   R   R6   t   expectedt   actualR/   t	   remainingR7   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   assertRecordOrder  s    	c         C  sn   |  j  t ƒ } |  j | j ƒ |  j | d d d g ƒ |  j | d d d g ƒ |  j | d d d g ƒ d  S(   NR3   R4   s   --1--R5   s   b + cs   --2--(   Ra   R8   t   assertFalseR.   Rh   (   R   R6   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   test_simple1  s
    c         C  s<   |  j  t ƒ } |  j | j ƒ |  j | d d d g ƒ d  S(   NR4   s   --1--R3   (   Ra   R<   Ri   R.   Rh   (   R   R6   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   test_simple2  s    c      
   C  sg   |  j  t ƒ } |  j | j ƒ |  j | d d d d g ƒ |  j | d d d d d d d	 d g ƒ d  S(
   NR3   R4   s   --loop exit--R5   s	   iter(a)#1s   --loop bottom--s	   iter(a)#2s	   iter(a)#3s   iter(a)(   Ra   R=   Ri   R.   Rh   (   R   R6   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   test_looping1   s    c         C  s¬   |  j  t ƒ } |  j | j ƒ |  j | d d g ƒ |  j | d d d g ƒ |  j | d d d d d d	 g ƒ |  j | d
 d d d d d g ƒ |  j | d d g ƒ d  S(   NR3   s   --outer loop top--s   iter(a)s   --outer loop else--s   --outer loop exit--s   iter(b)s   --inner loop exit #1--s   --inner loop exit #2--s   --inner loop exit #3--s	   iter(a)#1s   --inner loop entry #1--s	   iter(a)#2s   --inner loop entry #2--s	   iter(a)#3s   --inner loop entry #3--s   iter(a)#1 + iter(a)#1s   --outer loop bottom #1--(   Ra   R@   Ri   R.   Rh   (   R   R6   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   test_looping2,  s    
c         C  s  |  j  | ƒ } t ƒ  } |  j | ƒ E | | ƒ } t | ƒ |  j | j ƒ t | ƒ |  j | j ƒ Wd  QXt ƒ  } |  j | ƒ $ | | ƒ } ~ |  j | j ƒ Wd  QXt ƒ  } |  j | ƒ > | | ƒ } t | ƒ |  j | j ƒ ~ |  j | j ƒ Wd  QXd  S(   N(   R]   R   t   assertRefCountR   t
   assertTrueR.   Rb   Ri   (   R   t   genfuncR`   R6   t   gen(    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   exercise_generatorB  s(    	

		
c         C  s   |  j  t ƒ d  S(   N(   Rr   RA   (   R   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   test_generator1[  s    c         C  s   |  j  t ƒ d  S(   N(   Rr   RB   (   R   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   test_generator2^  s    c         C  s/   |  j  t ƒ } |  j | j d d d g ƒ d  S(   Nt   0t   1t   2(   Ra   RP   Rd   R/   (   R   R6   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   test_del_before_definitiona  s    c         C  s?   |  j  t ƒ * |  j t d t ƒ} |  j | j ƒ Wd  QXd  S(   NR_   (   Rn   RD   Ra   RF   RC   Ri   R.   (   R   R6   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   test_raising1e  s    c         C  s?   |  j  t ƒ * |  j t d t ƒ} |  j | j ƒ Wd  QXd  S(   NR_   (   Rn   RD   Ra   RG   RC   Ri   R.   (   R   R6   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   test_raising2j  s    c         C  s?   |  j  t ƒ * |  j t d t ƒ} |  j | j ƒ Wd  QXd  S(   NR_   (   Rn   RC   Ra   RH   Ri   R.   (   R   R6   (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   test_raising3o  s    c      	   C  s­   |  j  t ƒ } t ƒ  } t | | ƒ ƒ } t | ƒ |  j | j g  ƒ t | ƒ |  j | j g  ƒ t | ƒ |  j | j g  ƒ |  j | j d d d d d d d g ƒ d  S(   NRQ   RR   RS   (   R]   RU   R   t   iterR   Rd   R.   R/   (   R   R`   R6   t   iterator(    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt    test_inf_loop_multiple_back_edget  s    	


N(   R   R   R0   R]   R9   Ra   Rh   Rj   Rk   Rl   Rm   Rr   Rs   Rt   Rx   Ry   Rz   R{   R~   (    (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyRV   ð   s    	
												t   __main__(,   t
   __future__R    R   t   sysR$   t   numba.unittest_supportt   unittest_supportt   unittestt   numba.controlflowR   R   t   numba.compilerR   R   R   t   numbaR   t   supportR   t   enable_pyobj_flagst   setRY   t   no_pyobj_flagst   objectR
   R   R   R8   R<   R=   R@   RA   RB   t   RuntimeErrorRC   RD   RF   RG   RH   RP   RU   RV   R   t   main(    (    (    s<   lib/python2.7/site-packages/numba/tests/test_obj_lifetime.pyt   <module>   s@   			4	
								
				’