B
     \[                 @   s   d dl mZmZmZ d dlZd dlZd dlmZ d dl	m
Z
mZ d dlmZ dd Zdd	 Zd
d Zdd Zd aa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 )$    )print_functiondivisionabsolute_importN)cffi_support)import_dynamictemp_directory)
complex128c              C   s<   ddl m}  d}|  }|| ddlm} |||jfS )zP
    Create an inline module, return the corresponding ffi and dll objects.
    r   )FFIz
    double _numba_test_sin(double x);
    double _numba_test_cos(double x);
    double _numba_test_funcptr(double (*func)(double));
    bool _numba_test_boolean();
    )
_helperlib)cffir	   cdefnumbar
   Zdlopen__file__)r	   defsffir
    r   8lib/python3.7/site-packages/numba/tests/cffi_usecases.pyload_inline_module   s    

r   c           	   C   s   ddl m}  d}d}|d }|| d }|  }|d| |j|dd	 td
}|j|d tj| z0t	d}t
| t
|jdt |j|fS tj| X dS )z]
    Compile an out-of-line module, return the corresponding ffi and
    module objects.
    r   )r	   zh
    typedef struct _numba_complex {
        double real;
        double imag;
    } numba_complex;
    z
    #ifdef _MSC_VER
        #define false 0
        #define true 1
        #define bool int
    #else
        #include <stdbool.h>
    #endif
    aA  
    bool boolean();
    double sin(double x);
    double cos(double x);
    int foo(int a, int b, int c);
    void vsSin(int n, float* x, float* y);
    void vdSin(int n, double* x, double* y);
    void vector_real(numba_complex *c, double *real, int n);
    void vector_imag(numba_complex *c, double *imag, int n);
    a  
    static bool boolean()
    {
        return true;
    }

    static int foo(int a, int b, int c)
    {
        return a + b * c;
    }

    void vsSin(int n, float* x, float* y) {
        int i;
        for (i=0; i<n; i++)
            y[i] = sin(x[i]);
    }

    void vdSin(int n, double* x, double* y) {
        int i;
        for (i=0; i<n; i++)
            y[i] = sin(x[i]);
    }

    static void vector_real(numba_complex *c, double *real, int n) {
        int i;
        for (i = 0; i < n; i++)
            real[i] = c[i].real;
    }

    static void vector_imag(numba_complex *c, double *imag, int n) {
        int i;
        for (i = 0; i < n; i++)
            imag[i] = c[i].imag;
    }
    Zcffi_usecases_oolT)overrideZ	test_cffi)tmpdirzstruct _numba_complexN)r   r	   Z
set_sourcer   r   compilesyspathappendr   r   Zregister_moduleZregister_typer   Ztypeofr   remove)r	   Znumba_complexZbool_definer   sourcer   r   modr   r   r   load_ool_module#   s(    
	"

r   c              C   s*   t dkr&t \a } | ja| ja| ja~ dS )z
    Initialize module globals.  This can invoke external utilities, hence not
    being executed implicitly at module import.
    N)r   r   Z_numba_test_sincffi_sinZ_numba_test_coscffi_cosZ_numba_test_booleanZ	cffi_bool)Zdllr   r   r   initz   s    
r    c              C   sX   t dkrTt \a } | jja| jja| jja| jj	a
| jja| jja| jja| jja~ dS )z&
    Same as init() for OOL mode.
    N)ffi_oolr   libZsincffi_sin_oolZcoscffi_cos_oolZfoocffi_fooZbooleancffi_bool_oolvsSinvdSinvector_realvector_imag)r   r   r   r   init_ool   s    
r+   c             C   s   t | d S )N   )r   )xr   r   r   use_cffi_sin   s    r.   c             C   s   t | t|  S )N)r   r   )r-   r   r   r   use_two_funcs   s    r/   c             C   s   t | d S )Nr,   )r#   )r-   r   r   r   use_cffi_sin_ool   s    r0   c               C   s   t  S )N)r&   r   r   r   r   use_cffi_boolean_true   s    r1   c             C   s   t | t|  S )N)r#   r$   )r-   r   r   r   use_two_funcs_ool   s    r2   c             C   s   |dkr| |S ||S d S )Nr   r   )ZfaZfbr-   r   r   r   use_func_pointer   s    r3   c               C   s   t dddS )N   r,      )r%   r   r   r   r   use_user_defined_symbols   s    r6   c             C   s    t t| t| t| d S )N)r'   lenr   from_bufferr!   )r-   yr   r   r   vector_sin_float32   s    r:   c             C   s    t t| t| t| d S )N)r(   r7   r   r8   r!   )r-   r9   r   r   r   vector_sin_float64   s    r;   c             C   s    t t| t|t|  d S )N)r)   r   r8   r7   )r-   r9   r   r   r   vector_extract_real   s    r<   c             C   s    t t| t|t|  d S )N)r*   r   r8   r7   )r-   r9   r   r   r   vector_extract_imag   s    r=   )Z
__future__r   r   r   r   ZnumpyZnpr   r   Znumba.tests.supportr   r   Znumba.typesr   r   r   r    r+   r   r!   r.   r/   r0   r1   r2   r3   r6   r:   r;   r<   r=   r   r   r   r   <module>   s*   W