
    xKg,                         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e	      Z
d Zd Z G d	 d
e      Z G d de      Zedk(  r ej                           yy)    N)jit)types)TestCasec                       e Zd Zd Zy)Dummyc                     |dz   S )N    )selfothers     b/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/tests/test_func_lifetime.py__add__zDummy.__add__   s    qy    N)__name__
__module____qualname__r   r
   r   r   r   r   
   s    r   r   c                     | dz   S N   r
   xs    r   global_usecase1r      s    q5Lr   c                      t         dz   S r   )
global_objr
   r   r   global_usecase2r      s    >r   c                   X    e 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d Zy)TestFuncLifetimezP
    Test the lifetime of compiled function objects and their dependencies.
    c                     | j                  t        |j                        d       t        |j                  j	                               d   }|j
                  S )zV
        Get the single implementation (a C function object) of a dispatcher.
        r   r   )assertEquallen	overloadslistvaluesentry_point)r   
dispatchercress      r   get_implzTestFuncLifetime.get_impl   sI     	Z112A6J((//1215r   c                    d } t        di ||      }| j                   |d      d       | j                  |      }|||j                  fD cg c]  }t	        j
                  |       }}d x}x}x}}t        j                          | j                  |D cg c]	  } |        c}d gt        |      z         y c c}w c c}w )Nc                     | dz   S r   r
   r   s    r   fz5TestFuncLifetime.check_local_func_lifetime.<locals>.f%   s    q5Lr   r      )zint32(int32))
r   assertPreciseEqualr'   __self__weakrefrefgccollectr   r    )r   jitargsr*   c_fcfuncobjrefswrs           r   check_local_func_lifetimez*TestFuncLifetime.check_local_func_lifetime$   s    	 -c,G,Q/A*c" ./U^^,DE,DSC ,DE $$$a$#


.2"$.T0BC F /s   B<Cc                 (    | j                  d       y NT)forceobjr8   r   s    r   test_local_func_lifetimez)TestFuncLifetime.test_local_func_lifetime6       &&&5r   c                 (    | j                  d       y NT)nopythonr<   r=   s    r   test_local_func_lifetime_npmz-TestFuncLifetime.test_local_func_lifetime_npm9   r?   r   c                     t        di |t              }| j                   |d      d       | j                  |      }t	        j
                  |      }||j                  fD cg c]  }t	        j
                  |       }}d x}x}}t        j                          | j                  |D cg c]	  } |        c}d gt        |      z         y c c}w c c}w )Nr   r+   r
   )r   r   r,   r'   r.   r/   r-   r0   r1   r   r    )r   r2   r3   r4   r7   r5   r6   s          r   check_global_func_lifetimez+TestFuncLifetime.check_global_func_lifetime<   s    cnGn_-A*c"[[-0%..,AB,ASC ,AB   cE


.2"$.T0BC C /s   $C+Cc                 (    | j                  d       y r:   rE   r=   s    r   test_global_func_lifetimez*TestFuncLifetime.test_global_func_lifetimeH       '''6r   c                 (    | j                  d       y rA   rG   r=   s    r   test_global_func_lifetime_npmz.TestFuncLifetime.test_global_func_lifetime_npmK   rI   r   c                 l   t               a t        di |t              }| j	                   |       d       |t        fD cg c]  }t        j                  |       }}d x}x}at        j                          | j                  |D cg c]	  } |        c}d gt        |      z         y c c}w c c}w )N   r
   )r   r   r   r   r,   r.   r/   r0   r1   r   r    )r   r2   r3   r5   r6   r7   s         r   check_global_obj_lifetimez*TestFuncLifetime.check_global_obj_lifetimeN   s    
 W
cnGn_-q)-0*,=>,=SC ,=>!%%%cJ


.2"$.T0BC ? /s   B,B1c                 (    | j                  d       y r:   )rN   r=   s    r   test_global_obj_lifetimez)TestFuncLifetime.test_global_obj_lifetime]   r?   r   c                 2   d } t        di ||      j                          fd} t        di ||      }|j                          | j                   |d      d       |||| j                        j                  | j                  |      j                  fD cg c]  }t        j                  |       }}dx}x}xx}}t        j                          | j                  |D cg c]	  } |        c}dgt        |      z         yc c}w c c}w )z
        When a jitted function calls into another jitted function, check
        that everything is collected as desired.
        c                     | dz  S )N
   r
   )as    r   mult_10z?TestFuncLifetime.check_inner_function_lifetime.<locals>.mult_10e   s    r6Mr   c                      | dz         S )N   r
   )r   	c_mult_10s    r   do_mathz?TestFuncLifetime.check_inner_function_lifetime.<locals>.do_mathk   s    QU##r   r   2   N)z
intp(intp))
r   disable_compiler   r'   r-   r.   r/   r0   r1   r    )	r   r2   rU   rY   	c_do_mathr5   wrswrX   s	           @r   check_inner_function_lifetimez.TestFuncLifetime.check_inner_function_lifetime`   s   
	 1C009	!!#	$ 1C009	!!#1r* GYi(11i(11 %(w{{3 	 
 ;?>>g>	>Gi


s+s!!#s+dVc#h->? ,s    D+Dc                 (    | j                  d       y r:   r_   r=   s    r   test_inner_function_lifetimez-TestFuncLifetime.test_inner_function_lifetime|       **D*9r   c                 (    | j                  d       y rA   ra   r=   s    r    test_inner_function_lifetime_npmz1TestFuncLifetime.test_inner_function_lifetime_npm   rc   r   N)r   r   r   __doc__r'   r8   r>   rC   rE   rH   rK   rN   rP   r_   rb   re   r
   r   r   r   r      sG     D$66
D77D6@8::r   r   c                       e Zd Zd Zy)TestLifeTimeIssuec                    	 ddl m} dd l	|d        }|	fd       }	j                  ddggg      }	j                  ddgg      } |       } ||d   |        |       } ||d   |        |       }y )Nr   )njitc                 6    |j                   d   }|dk7  r|d   }y)Nr   )shape)pointpolygonsnum_polygonsintentionally_unused_variables       r   is_point_in_polygonsz@TestLifeTimeIssue.test_double_free.<locals>.is_point_in_polygons   s%    #>>!,Lq 08-r   c                  >     j                  d j                        S )NrS   )dtype)emptyint64)nps   r   dummyz1TestLifeTimeIssue.test_double_free.<locals>.dummy   s    88Bbhh8//r   r   g      g      ?)numbarj   numpyarray)
r   rj   rq   rw   rn   pointsrT   bcrv   s
            @r   test_double_freez"TestLifeTimeIssue.test_double_free   s     
	 
	 
	0 
	0 88q!fXJ'D#;-(GVAY1GVAY1Gr   N)r   r   r   r~   r
   r   r   rh   rh      s    r   rh   __main__)r0   r.   rx   r   
numba.corer   numba.tests.supportr   unittestobjectr   r   r   r   rh   r   mainr
   r   r   <module>r      sc    	    ( F i:x i:X @ zHMMO r   