o
    i,                     @   s   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ZG dd de	Z
dd Zd	d
 ZG dd deZG dd deZedkrHe  dS dS )    N)jit)types)TestCasec                   @      e Zd Zdd ZdS )Dummyc                 C   s   |d S )N    )selfotherr   r   m/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/tests/test_func_lifetime.py__add__      zDummy.__add__N)__name__
__module____qualname__r   r   r   r   r   r   
   s    r   c                 C      | d S N   r   xr   r   r   global_usecase1   r   r   c                   C   s   t d S r   )
global_objr   r   r   r   global_usecase2   r   r   c                   @   sp   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )TestFuncLifetimezP
    Test the lifetime of compiled function objects and their dependencies.
    c                 C   s*   |  t|jd t|j d }|jS )zV
        Get the single implementation (a C function object) of a dispatcher.
        r   r   )assertEquallenZ	overloadslistvaluesentry_point)r	   
dispatcherZcresr   r   r   get_impl   s   zTestFuncLifetime.get_implc                 K   s   dd }t d	i ||}| |dd | |}dd |||jfD }d  } } }}t  | dd |D d gt|  d S )
Nc                 S   r   r   r   r   r   r   r   f%   r   z5TestFuncLifetime.check_local_func_lifetime.<locals>.fint32(int32)r      c                 S      g | ]}t |qS r   weakrefref.0objr   r   r   
<listcomp>1       z>TestFuncLifetime.check_local_func_lifetime.<locals>.<listcomp>c                 S      g | ]}| qS r   r   r)   wrr   r   r   r+   4       )r"   )r   assertPreciseEqualr    __self__gccollectr   r   )r	   jitargsr!   c_fcfuncrefsr*   r   r   r   check_local_func_lifetime$   s   
$z*TestFuncLifetime.check_local_func_lifetimec                 C      | j dd d S NT)Zforceobjr9   r	   r   r   r   test_local_func_lifetime6      z)TestFuncLifetime.test_local_func_lifetimec                 C   r:   NT)Znopythonr<   r=   r   r   r   test_local_func_lifetime_npm9   r?   z-TestFuncLifetime.test_local_func_lifetime_npmc                 K   s   t di |t}| |dd | |}t|}dd ||jfD }d  } }}t  | 	dd |D d gt
|  d S )Nr   r#   c                 S   r$   r   r%   r(   r   r   r   r+   C   r,   z?TestFuncLifetime.check_global_func_lifetime.<locals>.<listcomp>c                 S   r-   r   r   r.   r   r   r   r+   F   r0   r   )r   r   r1   r    r&   r'   r2   r3   r4   r   r   )r	   r5   r6   r7   r/   r8   r*   r   r   r   check_global_func_lifetime<   s   

$z+TestFuncLifetime.check_global_func_lifetimec                 C   r:   r;   rB   r=   r   r   r   test_global_func_lifetimeH   r?   z*TestFuncLifetime.test_global_func_lifetimec                 C   r:   r@   rC   r=   r   r   r   test_global_func_lifetime_npmK   r?   z.TestFuncLifetime.test_global_func_lifetime_npmc                 K   sp   t  atdi |t}| | d dd |tfD }d  } }at  | dd |D d gt|  d S )N   c                 S   r$   r   r%   r(   r   r   r   r+   X   r,   z>TestFuncLifetime.check_global_obj_lifetime.<locals>.<listcomp>c                 S   r-   r   r   r.   r   r   r   r+   [   r0   r   )	r   r   r   r   r1   r3   r4   r   r   )r	   r5   r6   r8   r*   r   r   r   check_global_obj_lifetimeN   s   $z*TestFuncLifetime.check_global_obj_lifetimec                 C   r:   r;   )rG   r=   r   r   r   test_global_obj_lifetime]   r?   z)TestFuncLifetime.test_global_obj_lifetimec              	      s   dd }t di ||     fdd}t di ||}|  | |dd dd	 | |||  j| |jfD }d
 } }   }}t  | dd	 |D d
gt|  d
S )z
        When a jitted function calls into another jitted function, check
        that everything is collected as desired.
        c                 S   s   | d S )N
   r   )ar   r   r   mult_10e   r   z?TestFuncLifetime.check_inner_function_lifetime.<locals>.mult_10
intp(intp)c                    s    | d S )N   r   r   Z	c_mult_10r   r   do_mathk   s   z?TestFuncLifetime.check_inner_function_lifetime.<locals>.do_mathr   2   c                 S   r$   r   r%   r(   r   r   r   r+   s   r,   zBTestFuncLifetime.check_inner_function_lifetime.<locals>.<listcomp>Nc                 S   r-   r   r   )r)   wr   r   r   r+   z   r0   )rL   )r   Zdisable_compiler   r    r2   r3   r4   r   )r	   r5   rK   rO   Z	c_do_mathZwrsr*   r   rN   r   check_inner_function_lifetime`   s    

$z.TestFuncLifetime.check_inner_function_lifetimec                 C   r:   r;   rR   r=   r   r   r   test_inner_function_lifetime|   r?   z-TestFuncLifetime.test_inner_function_lifetimec                 C   r:   r@   rS   r=   r   r   r    test_inner_function_lifetime_npm   r?   z1TestFuncLifetime.test_inner_function_lifetime_npmN)r   r   r   __doc__r    r9   r>   rA   rB   rD   rE   rG   rH   rR   rT   rU   r   r   r   r   r      s    r   c                   @   r   )TestLifeTimeIssuec           	         s   ddl m} dd l |dd }| fdd} ddggg} dd	gg}| }||d | | }||d | | }d S )
Nr   )njitc                 S   s   |j d }|dkr|d }dS )Nr   )shape)pointpolygonsZnum_polygonsZintentionally_unused_variabler   r   r   is_point_in_polygons   s   
z@TestLifeTimeIssue.test_double_free.<locals>.is_point_in_polygonsc                      s    j d jdS )NrI   )Zdtype)emptyZint64r   npr   r   dummy   s   z1TestLifeTimeIssue.test_double_free.<locals>.dummyr   g      g      ?)numbarX   numpyarray)	r	   rX   r\   r`   r[   ZpointsrJ   bcr   r^   r   test_double_free   s   


z"TestLifeTimeIssue.test_double_freeN)r   r   r   rf   r   r   r   r   rW      s    rW   __main__)r3   r&   ra   r   Z
numba.corer   Znumba.tests.supportr   Zunittestobjectr   r   r   r   rW   r   mainr   r   r   r   <module>   s    l 