U
    ,d9^                     @   s  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mZ d dlmZmZmZmZ d dlmZ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   m!  m"Z# d d
l$m%Z% d dl&m'Z'm(Z(m)Z)m*Z*m+Z+ d dl,m-Z- d dl.Z.e Z/de/_e.0ej1d dZ2e.0e3 dkdZ4G dd de5Z6G dd de.j(Z7G dd de.j(Z8G dd de.j(Z9G dd de'e(Z:G dd de.j(Z;e.<e#j=dG dd  d e'e(Z>e?d!kre.@  dS )"    N)njit)types)compile_isolatedFlags)rtsysnrtopt_nrt_pythonnrt)	intrinsicinclude_path)	signature)impl_ret_untracked)irNRT_get_api)MemoryLeakMixinTestCasetemp_directoryimport_dynamicskip_if_32bit)
cpu_targetTlinuxzlinux only test)i386x86_64zx86 only testc                   @   s    e Zd ZdZdd Zdd ZdS )Dummyr   c                 C   s   t |  jd7  _d S N   typealiveself r"   8/tmp/pip-unpacked-wheel-eu7e0c37/numba/tests/test_nrt.py__init__+   s    zDummy.__init__c                 C   s   t |  jd8  _d S r   r   r    r"   r"   r#   __del__.   s    zDummy.__del__N)__name__
__module____qualname__r   r$   r%   r"   r"   r"   r#   r   (   s   r   c                   @   s   e Zd ZdZdZdd ZdS )TestNrtMemInfoNotInitializedzn
    Unit test for checking the use of the NRT fails if the
    initialization sequence has not been run.
    Fc              
   C   st   dddd}|  D ]Z\}}zH| t}dt_tt|}||  W 5 Q R X d}| |t|j W 5 dt_X qd S )Nr"   )r"   r"   )r"   )Zlibrarymeminfo_newmeminfo_allocTFz'Runtime must be initialized before use.)	itemsr   _initassertRaisesRuntimeErrorgetattrassertInstr	exception)r!   methodsmethargsraisesfnmsgr"   r"   r#   test_init_fail9   s    
z+TestNrtMemInfoNotInitialized.test_init_failN)r&   r'   r(   __doc__Z_numba_parallel_test_r:   r"   r"   r"   r#   r)   2   s   r)   c                   @   sT   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	e
dd Zdd ZdS )TestNrtMemInfoz2
    Unit test for core MemInfo functionality
    c                 C   s   dt _tj d S )Nr   )r   r   r   target_contextr    r"   r"   r#   setUpQ   s    zTestNrtMemInfo.setUpc                 C   s   t  }| t jd d}t||}| |jd ~| t jd |  | |jd | t jd |  | |jd ~| t jd d S )Nr      J[=    r   )r   assertEqualr   r   r*   refcountacquirerelease)r!   daddrmir"   r"   r#   test_meminfo_refct_1W   s    z#TestNrtMemInfo.test_meminfo_refct_1c                 C   s   t  }| t jd d}t||}| |jd ~| t jd tdD ]}|  qJ| |jd | t jd tdD ]}|  q|| |jd ~| t jd d S )Nr   r?   d   e   r   )	r   rA   r   r   r*   rB   rangerC   rD   )r!   rE   rF   rG   ct_r"   r"   r#   test_meminfo_refct_2h   s     

z#TestNrtMemInfo.test_meminfo_refct_2c                 C   s   t  }| t jd d}t||}| |jd t|}| |jd | ||j | |j	 | 
||j | |j | |jd | |jd ~~| t jd ~| t jd d S )Nr   r?   r   )r   rA   r   r   r*   rB   
memoryviewdataassertFalsereadonlyassertIsobj
assertTruec_contiguousitemsizendim)r!   rE   rF   rG   mviewr"   r"   r#   test_fake_memoryview{   s$    z#TestNrtMemInfo.test_fake_memoryviewc                 C   sh  ddl m}m}m}m} ttj}|jd }t	j
|dd}|j}|||j||d }	tdD ]}
| |	j|
 d qbtdD ]}
|
d |	j|
< qt|}| |j| | |j | ||j | |j | |jd | |jd ~tj||j|j |d}~tjt|jd | |d7 }tdD ]}
| |	j|
 |
d	  q4| |j j| ~d S )
Nr   c_uint32c_void_pPOINTERcast
   Tsafe   K r   dtypeshapebufferr@   )ctypesr\   r]   r^   r_   npre   uint32rW   r   r+   rP   rK   rA   contentsrO   nbytesrQ   rR   rS   rT   rU   rV   rX   ndarraytestingassert_equalarangesize)r!   r\   r]   r^   r_   re   bytesizerG   rF   c_arrirY   arrr"   r"   r#   test_memoryview   s8    
zTestNrtMemInfo.test_memoryviewc                 C   s$  ddl m}m}m}m} ttj}|jd }t	j
|dd}| |jd |j}|||||d }	tdD ]}
| |	j|
 d qntdD ]}
|
d |	j|
< qtj|||j |d}| |jd ~tjt|jd | |d7 }tdD ]}
| |	j|
 |
d	  q| |j j| ~d S )
Nr   r[   r`   Tra   r   rc   rd   r@   )rh   r\   r]   r^   r_   ri   re   rj   rW   r   r+   rA   rB   rP   rK   rk   rm   rn   ro   rp   rq   )r!   r\   r]   r^   r_   re   rr   rG   rF   rs   rt   ru   r"   r"   r#   test_buffer   s,    
zTestNrtMemInfo.test_bufferc              
   C   s\   t jjd d }dD ]B}| t}tj||d W 5 Q R X | d| dt|j	 qd S )N   r@   TFra   zRequested allocation of z bytes failed.)
r   size_tmaxvalr.   MemoryErrorr   r+   r1   r2   r3   )r!   rq   predr7   r"   r"   r#   test_allocate_invalid_size   s    z)TestNrtMemInfo.test_allocate_invalid_sizec              
   C   sT   d}dD ]F}|  t}tj||d W 5 Q R X d| d}| |t|j qd S )Niry   ra   z,Cannot allocate a negative number of bytes: .)r.   
ValueErrorr   r+   r1   r2   r3   )r!   rq   r}   r7   r9   r"   r"   r#   test_allocate_negative_size   s    z*TestNrtMemInfo.test_allocate_negative_sizeN)r&   r'   r(   r;   r>   rH   rN   rZ   rv   rw   r   r~   r   r"   r"   r"   r#   r<   L   s   )$
	r<   c                   @   s    e Zd ZdZdd Zdd ZdS )TestTracemalloczB
    Test NRT-allocated memory can be tracked by tracemalloc.
    c                 C   sl   zdd l }W n tk
r*   | d Y nX |  z(| }| }| }~||dW S |  X d S )Nr   ztracemalloc not availablelineno)tracemallocImportErrorZskipTeststartstopZtake_snapshotZ
compare_to)r!   funcr   beforeresafterr"   r"   r#   measure_memory_diff   s    z#TestTracemalloc.measure_memory_diffc                    s   d t jt fddfdd}fdd}|jjd }  | |}|d	 }| |j  | j|j d
 dd |j	d	 }| 
tj|jd | 
|j| | |}|d	 }| |j d  d S )Ni@B c                      s   t  S )z<
            Allocate and return a large array.
            )ri   emptyr"   )Nre   r"   r#   alloc_nrt_memory  s    z7TestTracemalloc.test_snapshot.<locals>.alloc_nrt_memoryc                      s     S Nr"   r"   r   r"   r#   keep_memory  s    z2TestTracemalloc.test_snapshot.<locals>.keep_memoryc                      s
      d S r   r"   r"   r   r"   r#   release_memory  s    z5TestTracemalloc.test_snapshot.<locals>.release_memoryr   r   g=
ףp=?zpUnexpected allocation overhead encountered. May be due to difference in CPython builds or running under coverage)r9   ztest_nrt.pyg{Gz?)ri   Zint8r   __code__co_firstlinenor   ZassertGreaterEqualrq   Z
assertLess	tracebackrA   ospathbasenamefilenamer   )r!   r   r   Zalloc_linenoZdiffstatframer"   )r   r   re   r#   test_snapshot  s(    


zTestTracemalloc.test_snapshotN)r&   r'   r(   r;   r   r   r"   r"   r"   r#   r      s   r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestNRTIssuec                    sh   t dd  t  fddt fdd}d}tj|df}|||}|||}tj|| d	S )
zO
        GitHub Issue #1244 https://github.com/numba/numba/issues/1244
        c                 S   s   | \}}t |d |d  S )Nr@   )mathsqrt)vectorxyr"   r"   r#   calculate_2D_vector_mag8  s    zNTestNRTIssue.test_issue_with_refct_op_pruning.<locals>.calculate_2D_vector_magc                    s<   t jdt jd} | }| \}}|| |d< || |d< |S Nr@   re   r   r   )ri   r   float64)r   normalized_vectorZmagr   r   )r   r"   r#   normalize_2D_vector>  s    zJTestNRTIssue.test_issue_with_refct_op_pruning.<locals>.normalize_2D_vectorc                    sV   t j| dft jd}t| D ]4}|| } |}|d ||df< |d ||df< q|S r   )ri   r   r   rK   )num_vectorsZvectorsZnormalized_vectorsrt   r   r   )r   r"   r#   normalize_vectorsJ  s    zHTestNRTIssue.test_issue_with_refct_op_pruning.<locals>.normalize_vectorsr`   r@   N)r   ri   randompy_funcrn   Zassert_almost_equal)r!   r   r   Ztest_vectorsgotexpectedr"   )r   r   r#    test_issue_with_refct_op_pruning4  s    

z-TestNRTIssue.test_issue_with_refct_op_pruningc                 C   s`   dd }t |dttjttjddf}| \}}| |d | |tj	dtjd d S )Nc                   S   s   dt jdt jdfS )Ng        r   r   )ri   zerosint32r"   r"   r"   r#   fb  s    z.TestNRTIssue.test_incref_after_cast.<locals>.fr"   r   Cy                r   )
r   r   TupleZ
complex128Arrayr   Zentry_pointZassertPreciseEqualri   r   )r!   r   Zcreszru   r"   r"   r#   test_incref_after_cast_  s    z#TestNRTIssue.test_incref_after_castc                 C   sB   t dd }| \}}tj|| tj|tjdtjd d S )Nc                  S   s0   t jdt jd} t jdt jd}| |d d  fS )Nr`   r   )ri   onesr   )abr"   r"   r#   r   q  s    z5TestNRTIssue.test_refct_pruning_issue_1511.<locals>.fr`   r   )r   ri   rn   ro   r   r   )r!   r   r   r   r"   r"   r#   test_refct_pruning_issue_1511p  s
    

z*TestNRTIssue.test_refct_pruning_issue_1511c                 C   sV   t dd }tddddddddddg
g}||dd}||dd}| || d S )Nc                 S   s`   t | dk}t|d dkr(d}d}n|d d }|d d }|d | }|d | }||fS )Nr   r   )ri   wherelen)imager   r   Znext_locZy_offsetZx_offsetZ
next_loc_xZ
next_loc_yr"   r"   r#   udt|  s    z7TestNRTIssue.test_refct_pruning_issue_1526.<locals>.udtr   r      )r   ri   arrayr   rA   )r!   r   r   expectr   r"   r"   r#   test_refct_pruning_issue_1526{  s    
 z*TestNRTIssue.test_refct_pruning_issue_1526N)r&   r'   r(   r   r   r   r   r"   r"   r"   r#   r   3  s   +r   c                   @   s:   e Zd ZdZdd Zeddd Zee	dd Z
d	S )
TestRefCtPruninga  
define i32 @"MyFunction"(i8** noalias nocapture %retptr, { i8*, i32 }** noalias nocapture %excinfo, i8* noalias nocapture readnone %env, double %arg.vt.0, double %arg.vt.1, double %arg.vt.2, double %arg.vt.3, double %arg.bounds.0, double %arg.bounds.1, double %arg.bounds.2, double %arg.bounds.3, i8* %arg.xs.0, i8* nocapture readnone %arg.xs.1, i64 %arg.xs.2, i64 %arg.xs.3, double* nocapture readonly %arg.xs.4, i64 %arg.xs.5.0, i64 %arg.xs.6.0, i8* %arg.ys.0, i8* nocapture readnone %arg.ys.1, i64 %arg.ys.2, i64 %arg.ys.3, double* nocapture readonly %arg.ys.4, i64 %arg.ys.5.0, i64 %arg.ys.6.0, i8* %arg.aggs_and_cols.0.0, i8* nocapture readnone %arg.aggs_and_cols.0.1, i64 %arg.aggs_and_cols.0.2, i64 %arg.aggs_and_cols.0.3, i32* nocapture %arg.aggs_and_cols.0.4, i64 %arg.aggs_and_cols.0.5.0, i64 %arg.aggs_and_cols.0.5.1, i64 %arg.aggs_and_cols.0.6.0, i64 %arg.aggs_and_cols.0.6.1) local_unnamed_addr {
entry:
tail call void @NRT_incref(i8* %arg.xs.0)
tail call void @NRT_incref(i8* %arg.ys.0)
tail call void @NRT_incref(i8* %arg.aggs_and_cols.0.0)
%.251 = icmp sgt i64 %arg.xs.5.0, 0
br i1 %.251, label %B42.preheader, label %B160

B42.preheader:                                    ; preds = %entry
%0 = add i64 %arg.xs.5.0, 1
br label %B42

B42:                                              ; preds = %B40.backedge, %B42.preheader
%lsr.iv3 = phi i64 [ %lsr.iv.next, %B40.backedge ], [ %0, %B42.preheader ]
%lsr.iv1 = phi double* [ %scevgep2, %B40.backedge ], [ %arg.xs.4, %B42.preheader ]
%lsr.iv = phi double* [ %scevgep, %B40.backedge ], [ %arg.ys.4, %B42.preheader ]
%.381 = load double, double* %lsr.iv1, align 8
%.420 = load double, double* %lsr.iv, align 8
%.458 = fcmp ole double %.381, %arg.bounds.1
%not..432 = fcmp oge double %.381, %arg.bounds.0
%"$phi82.1.1" = and i1 %.458, %not..432
br i1 %"$phi82.1.1", label %B84, label %B40.backedge

B84:                                              ; preds = %B42
%.513 = fcmp ole double %.420, %arg.bounds.3
%not..487 = fcmp oge double %.420, %arg.bounds.2
%"$phi106.1.1" = and i1 %.513, %not..487
br i1 %"$phi106.1.1", label %B108.endif.endif.endif, label %B40.backedge

B160:                                             ; preds = %B40.backedge, %entry
tail call void @NRT_decref(i8* %arg.ys.0)
tail call void @NRT_decref(i8* %arg.xs.0)
tail call void @NRT_decref(i8* %arg.aggs_and_cols.0.0)
store i8* null, i8** %retptr, align 8
ret i32 0

B108.endif.endif.endif:                           ; preds = %B84
%.575 = fmul double %.381, %arg.vt.0
%.583 = fadd double %.575, %arg.vt.1
%.590 = fptosi double %.583 to i64
%.630 = fmul double %.420, %arg.vt.2
%.638 = fadd double %.630, %arg.vt.3
%.645 = fptosi double %.638 to i64
tail call void @NRT_incref(i8* %arg.aggs_and_cols.0.0)              ; GONE 1
tail call void @NRT_decref(i8* null)                                ; GONE 2
tail call void @NRT_incref(i8* %arg.aggs_and_cols.0.0), !noalias !0 ; GONE 3
%.62.i.i = icmp slt i64 %.645, 0
%.63.i.i = select i1 %.62.i.i, i64 %arg.aggs_and_cols.0.5.0, i64 0
%.64.i.i = add i64 %.63.i.i, %.645
%.65.i.i = icmp slt i64 %.590, 0
%.66.i.i = select i1 %.65.i.i, i64 %arg.aggs_and_cols.0.5.1, i64 0
%.67.i.i = add i64 %.66.i.i, %.590
%.84.i.i = mul i64 %.64.i.i, %arg.aggs_and_cols.0.5.1
%.87.i.i = add i64 %.67.i.i, %.84.i.i
%.88.i.i = getelementptr i32, i32* %arg.aggs_and_cols.0.4, i64 %.87.i.i
%.89.i.i = load i32, i32* %.88.i.i, align 4, !noalias !3
%.99.i.i = add i32 %.89.i.i, 1
store i32 %.99.i.i, i32* %.88.i.i, align 4, !noalias !3
tail call void @NRT_decref(i8* %arg.aggs_and_cols.0.0), !noalias !0 ; GONE 4
tail call void @NRT_decref(i8* %arg.aggs_and_cols.0.0)              ; GONE 5
br label %B40.backedge

B40.backedge:                                     ; preds = %B108.endif.endif.endif, %B84, %B42
%scevgep = getelementptr double, double* %lsr.iv, i64 1
%scevgep2 = getelementptr double, double* %lsr.iv1, i64 1
%lsr.iv.next = add i64 %lsr.iv3, -1
%.294 = icmp sgt i64 %lsr.iv.next, 1
br i1 %.294, label %B42, label %B160
}
    c                 C   s   | j }t| }dd |D }dd |D }t|}t| }dd |D }dd |D }| || | || t|t| }	t|t| }
|	|
B }| ||	|
A  d|}dD ]}d	|}| 
|| q| tt| t| d S )	Nc                 S   s   g | ]}d |kr|qS Z
NRT_increfr"   .0lnr"   r"   r#   
<listcomp>  s      zDTestRefCtPruning.test_refct_pruning_op_recognize.<locals>.<listcomp>c                 S   s   g | ]}d |kr|qS Z
NRT_decrefr"   r   r"   r"   r#   r     s      c                 S   s   g | ]}d |kr|qS r   r"   r   r"   r"   r#   r     s      c                 S   s   g | ]}d |kr|qS r   r"   r   r"   r"   r#   r     s      
)r   r@            z	; GONE {})sample_llvm_irlist
splitlinesr   Z_remove_redundant_nrt_refctZassertNotEqualsetrA   joinformatr1   r   )r!   Zinput_irZinput_linesZbefore_increfsZbefore_decrefsZ	output_irZoutput_linesZafter_increfsZafter_decrefsZpruned_increfsZpruned_decrefsZcombinedZpruned_linesrt   goner"   r"   r#   test_refct_pruning_op_recognize  s&    


z0TestRefCtPruning.test_refct_pruning_op_recognizez3Pass removed as it was buggy. Re-enable when fixed.c                    s   t dd t dd  t  fddt ddfd	d
}|d t||jd }ttd|}| t	|d dS )ztestcase from #2350c                 S   s"   t |s||| f  d7  < d S r   ri   isnanr   r   Zaggfieldr"   r"   r#   _append_non_na  s    
zITestRefCtPruning.test_refct_pruning_with_branches.<locals>._append_non_nac                 S   sB   t |s>t ||| f r*|||| f< n||| f  |7  < d S r   r   r   r"   r"   r#   _append  s    
zBTestRefCtPruning.test_refct_pruning_with_branches.<locals>._appendc                    s    | |||  | ||| d S r   r"   r   )r   r   r"   r#   append  s    zATestRefCtPruning.test_refct_pruning_with_branches.<locals>.appendT)Zno_cpython_wrapperc                    s:   t | jd D ]&}t | jd D ]} ||| | q qd S )Nr   r   )rK   rf   )ru   r   rt   j)r   r"   r#   extend  s    zATestRefCtPruning.test_refct_pruning_with_branches.<locals>.extendz(f4[:,::1], f4)r   z!(NRT_incref|NRT_decref)\([^\)]+\)N)
r   compiler2   Zinspect_llvmZ
signaturesr   refinditerrA   r   )r!   r   ZllvmirZrefopsr"   )r   r   r   r#    test_refct_pruning_with_branches  s    


z1TestRefCtPruning.test_refct_pruning_with_branchesc                    sV   t   t   t   t   tdd  tdg fdd}| |dd dS )	ztThe InlineAsm class from llvmlite.ir has no 'name' attr the refcount
        pruning pass should be tolerant to thisc                 S   s   dd }t tjtjtj|fS )Nc                 S   sT   |\}}t t dt dt dg}|j|dd||fddd}t| ||j|S )N    zmov $2, $0; imul $1, $0z=&r,r,rZasm_mulF)nameZside_effect)r   FunctionTypeZIntTypeZasmr   return_type)ZcgctxZbuildersigr6   Zarg_0Zarg_1Zftymulr"   r"   r#   codegen-  s    
 z>TestRefCtPruning.test_inline_asm.<locals>.bar.<locals>.codegen)r   r   r   )Ztyctxr   r   r   r"   r"   r#   bar+  s    z-TestRefCtPruning.test_inline_asm.<locals>.barzint32(int32)c                    s   | d7 }  | d}|S )Nr   r@   r"   )r   r   r   r"   r#   foo7  s    
z-TestRefCtPruning.test_inline_asm.<locals>.foor`      N)llvmZ
initializeZinitialize_native_targetZinitialize_native_asmprinterZinitialize_native_asmparserr
   r   rA   )r!   r   r"   r   r#   test_inline_asm!  s    
z TestRefCtPruning.test_inline_asmN)r&   r'   r(   r   r   unittestskipr   
linux_onlyx86_onlyr   r"   r"   r"   r#   r     s   H
$r   zcffi requiredc                       sH   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	  Z
S )TestNrtExternalCFFIz?Testing the use of externally compiled C code that use NRT
    c                    s   t t|   tj d S r   )superr   r>   r   r=   r    	__class__r"   r#   r>   D  s    zTestNrtExternalCFFI.setUpc              	   C   sz   ddl m} | }|j||t gd || td|}|j|d tj	
| zt|}W 5 tj	| X ||fS )Nr   FFI)include_dirszcffi_test_{})tmpdir)cffir   Z
set_sourcer   cdefr   r   r   sysr   r   remover   )r!   r   sourcer   r   ffir   modr"   r"   r#   compile_cffi_moduleI  s    
z'TestNrtExternalCFFI.compile_cffi_modulec                 C   s.   ddl m} | }|dtjd }| }|S )Nr   r   zvoid* (*)()Zget_api)r   r   r_   r   Z	c_helpers)r!   r   r  Znrt_get_apitabler"   r"   r#   get_nrt_api_tableY  s
    z%TestNrtExternalCFFI.get_nrt_api_tablec           
      C   s   d | jj}d}d}| |||\}}| |jjd |  }|j|}| |jjd t	|
d|}t|}	| |	jd ~	| |jjd d S )	Nz{}_test_manage_memoryaz  
#include <stdio.h>
#include "numba/core/runtime/nrt_external.h"

int status = 0;

void my_dtor(void *ptr) {
    free(ptr);
    status = 0xdead;
}

NRT_MemInfo* test_nrt_api(NRT_api_functions *nrt) {
    void * data = malloc(10);
    NRT_MemInfo *mi = nrt->manage_memory(data, my_dtor);
    nrt->acquire(mi);
    nrt->release(mi);
    status = 0xa110c;
    return mi;
}
        z;
void* test_nrt_api(void *nrt);
extern int status;
        r   i
 rz   r   i  )r   r   r&   r  rA   libstatusr  test_nrt_apiintr_   r	   MemInforB   )
r!   r   r  r   r  r  r  outmi_addrrG   r"   r"   r#   test_manage_memorya  s    
z&TestNrtExternalCFFI.test_manage_memoryc                 C   s   d | jj}d}d}| |||\}}|  }dttjj }|j	
||}t|d|}	t|	}
| |
jd ||d ||
j}tjdtj|d	}tj|d
ddg d S )Nz{}_test_allocatea7  
#include <stdio.h>
#include "numba/core/runtime/nrt_external.h"

NRT_MemInfo* test_nrt_api(NRT_api_functions *nrt, size_t n) {
    size_t *data = NULL;
    NRT_MemInfo *mi = nrt->allocate(n);
    data = nrt->get_data(mi);
    data[0] = 0xded;
    data[1] = 0xabc;
    data[2] = 0xdef;
    return mi;
}
        z(void* test_nrt_api(void *nrt, size_t n);r   rz   r   z	char [{}])r   )rf   re   rg   i  i
  i  )r   r   r&   r  r  ri   re   ZintprW   r  r
  r  r_   r	   r  rA   rB   rg   rP   rm   rn   ro   )r!   r   r  r   r  r  r  numbytesr  r  rG   rg   ru   r"   r"   r#   test_allocate  s    
z!TestNrtExternalCFFI.test_allocatec                 C   sH   ddl m} tdd }| }t|d|  }| }| || d S )Nr   r   c                   S   s   t  S r   r   r"   r"   r"   r#   r
    s    z6TestNrtExternalCFFI.test_get_api.<locals>.test_nrt_apirz   )r   r   r   r  r_   r  rA   )r!   r   r
  r  r   r   r"   r"   r#   test_get_api  s    
z TestNrtExternalCFFI.test_get_api)r&   r'   r(   r;   r>   r  r  r  r  r  __classcell__r"   r"   r   r#   r   @  s   ) r   __main__)Ar   r   platformr   r   Znumpyri   Znumbar   Z
numba.corer   Znumba.core.compilerr   r   Znumba.core.runtimer   r   r   r	   Znumba.core.extendingr
   r   Znumba.core.typingr   Znumba.core.imputilsr   Zllvmliter   Zllvmlite.bindingZbindingr   Znumba.core.typing.cffi_utilscoretypingZ
cffi_utilsZcffi_supportZnumba.core.unsafe.nrtr   Znumba.tests.supportr   r   r   r   r   Znumba.core.registryr   r   Zenable_nrt_flagsZskipIf
startswithr   machiner   objectr   r)   r<   r   r   r   Z
skipUnlessZ	SUPPORTEDr   r&   mainr"   r"   r"   r#   <module>   sN   
 (@` .v
