
    ܙd                    R   d dl m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
Z
d dlmZ d dlmZmZmZmZmZmZmZ ej        Zej        Zej        Zej        Z G d de          Z e            Z e            Z  e            Z!ej"        Z#e j"        Z$e!j"        Z% G d	 d
 ed
d                    Z& G d d edd                    Z' G d d edd                    Z( G d de          Z) G d de          Z* edd          Z+ G d de          Z, G d d          Z-dS )    )
namedtupleN)ir)Constant)
_helperlib)typesutilsconfigloweringcgutilsimputils	serializec                   "    e Zd Zd Zd ZddZdS )	_Registryc                     i | _         d S N)	functionsselfs    4lib/python3.11/site-packages/numba/core/pythonapi.py__init__z_Registry.__init__   s        c                 N     t          t          j                  sJ  fd}|S )Nc                 R    j         v rt          d          | j         <   | S )Nzduplicate registration for )r   KeyError)funcr   	typeclasss    r   	decoratorz%_Registry.register.<locals>.decorator   s6    DN**h))MNNN(,DN9%Kr   )
issubclassr   Type)r   r   r   s   `` r   registerz_Registry.register   sB    )UZ00000	 	 	 	 	 	
 r   Nc                     t          |t          j                  sJ |j        D ]"}| j                            |          }||c S #|S r   )r   r   r   __mro__r   get)r   r   defaultclsr   s        r   lookupz_Registry.lookup$   sZ    )UZ00000$ 	 	C>%%c**D  r   r   )__name__
__module____qualname__r   r    r&    r   r   r   r      sF                 r   r   c                       e Zd ZdZdZd ZdS )_BoxContextz<
    The facilities required by boxing implementations.
    r*   c                 D    | j                             ||| j                  S r   pyapifrom_native_valueenv_managerr   typvals      r   boxz_BoxContext.box<       z++Cd6FGGGr   N)r'   r(   r)   __doc__	__slots__r5   r*   r   r   r,   r,   5   s9          IH H H H Hr   r,   )contextbuilderr/   r1   c                       e Zd ZdZdZd ZdS )_UnboxContextz>
    The facilities required by unboxing implementations.
    r*   c                 8    | j                             ||          S r   )r/   to_native_value)r   r3   objs      r   unboxz_UnboxContext.unboxG   s    z))#s333r   N)r'   r(   r)   r7   r8   r@   r*   r   r   r<   r<   @   s4          I4 4 4 4 4r   r<   )r9   r:   r/   c                   (    e Zd ZdZdZd Zd Zd ZdS )_ReflectContextz@
    The facilities required by reflection implementations.
    r*   c                 Z    | j                             | j        t          j                   d S r   )r:   storeis_errorr   true_bitr   s    r   	set_errorz_ReflectContext.set_errorT   s%    4='*:;;;;;r   c                 D    | j                             ||| j                  S r   r.   r2   s      r   r5   z_ReflectContext.boxW   r6   r   c                 D    | j                             ||| j                  S r   )r/   reflect_native_valuer1   r2   s      r   reflectz_ReflectContext.reflectZ   s    z..sC9IJJJr   N)r'   r(   r)   r7   r8   rG   r5   rK   r*   r   r   rB   rB   K   sZ          I< < <H H HK K K K Kr   rB   )r9   r:   r/   r1   rE   c                       e Zd ZdZddZdS )NativeValuez
    Encapsulate the result of converting a Python object to a native value,
    recording whether the conversion was successful and how to cleanup.
    Nc                 L    || _         ||nt          j        | _        || _        d S r   )valuer   	false_bitrE   cleanup)r   rO   rE   rQ   s       r   r   zNativeValue.__init__d   s'    
$,$8g>Or   NN)r'   r(   r)   r7   r   r*   r   r   rM   rM   ^   s2         
     r   rM   c                        e Zd Zd Zd Zd ZdS )EnvironmentManagerc                 v    t          |t          j                  sJ || _        || _        || _        || _        d S r   )
isinstancer
   Environmentr/   envenv_bodyenv_ptr)r   r/   rX   rY   rZ   s        r   r   zEnvironmentManager.__init__l   s;    #x344444
 r   c                    t          |t                    rt          j        |          }t	          | j        j                  D ]\  }}||u r n9t          | j        j                  }| j        j                            |           |S )zF
        Add a constant to the environment, return its index.
        )	rV   strsysintern	enumeraterX   constslenappend)r   constindexr4   s       r   	add_constzEnvironmentManager.add_consts   s    
 eS!! 	&Ju%%E#DHO44 	* 	*JE3e||  ((EHO""5)))r   c                 b   |t          | j        j                  k     sJ | j        j        }| j        j        }t          j        || j        j        d          }|	                    t          j
        ||                    5 \  }}|5  | j                            ||          }|                    ||           ddd           n# 1 swxY w Y   |5  | j                            dd           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |                    |          S )z
        Look up constant number *index* inside the environment body.
        A borrowed reference is returned.

        The returned LLVM value may have NULL value at runtime which indicates
        an error at runtime.
        TzfillNPyExc_RuntimeErrorz$`env.consts` is NULL in `read_const`)ra   rX   r`   r/   r:   rY   r   alloca_oncepyobjif_elseis_not_nulllist_getitemrD   err_set_stringload)r   rd   r:   r`   retbr_not_nullbr_nullgetitems           r   
read_constzEnvironmentManager.read_const   s    s48?++++++*$%!'4:+;4HHH__W0&AABB 	&g , ,*11&%@@gs+++, , , , , , , , , , , , , , ,    
))(:                	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ||C   sZ   D2C9DC			DC		DC:.D:C>	>DC>	DDDN)r'   r(   r)   r   re   ru   r*   r   r   rT   rT   j   sA            ! ! ! ! !r   rT   _IteratorLoop)rO   do_breakc                      e Zd ZdZd Zd Z	 	 ddZd Zd Zd	 Z	d
 Z
d Zd Zd Zd Zd Zd ZddZd Zd Zd Zd Zd Zej        dd            Zd Zd Zd Zd Zd Zd Zdd 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.d/ Z/d0 Z0d1 Z1d2 Z2dd3Z3dd4Z4dd5Z5dd6Z6dd7Z7dd8Z8dd9Z9dd:Z:dd;Z;dd<Z<dd=Z=dd>Z>dd?Z?dd@Z@dA ZAdB ZBdC ZCdD ZDdE ZEdF ZFdG ZGdH ZHdI ZIdJ ZJdK ZKdL ZLdM ZMdN ZNdO ZOdP ZPdQ ZQdR ZRdS ZSdT ZTdU ZUdV ZVdW ZWdX ZXdY ZYddZZZd[ Z[d\ Z\d] Z]d^ Z^d_ Z_ej        d`             Z`da Zadb Zbdc Zcdd Zdde Zedf Zfdg Zgdh Zhdi ZiddkZjddlZkdm Zldn Zmdo Zndp Zodq Zpdr Zqds Zrdt Zsdu Ztdv Zudw Zvdx Zwdy Zxdz Zyd{ Zzd| Z{d} Z|d~ Z}d Z~d Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zej        d             Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZddZddZd ZddZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )	PythonAPIz^
    Code generation facilities to call into the CPython C API (and related
    helpers).
    c                    || _         || _        |j        j        j        | _        	 | j        j         n# t          $ r i | j        _        Y nw xY w| j                             t          j	                  | _
        | j
                                        | _        t          j        t          j        d                    | _        t          j        t#          j        t"          j                  dz            | _        | j        | _        t          j        t#          j        t"          j                  dz            | _        | j        | _        t          j                    | _        | j                             t          j                  | _        t          j        t          j        d                    | _        t          j        t>          j         dz            | _!        t          j"        t          j        d          t>          j#                  | _$        | j        | _%        t>          j&        | _&        t>          j'        | _'        t>          j(        | _(        t>          j)        | _)        dS )zL
        Note: Maybe called multiple times when lowering a function
           N)*r9   r:   basic_blockfunctionmodule_PythonAPI__serializedAttributeErrorget_argument_typer   pyobjectrk   
as_pointerpyobjptrr   PointerTypeIntTypevoidptrctypessizeofc_longlongulongc_ulonglonglonglong	ulonglong
DoubleTypedoubleget_value_typeintp
py_ssize_tcstringr   py_gil_state_size	gil_state	ArrayTypepy_buffer_sizepy_buffer_t	py_hash_tpy_unicode_1byte_kindpy_unicode_2byte_kindpy_unicode_4byte_kindpy_unicode_wchar_kind)r   r9   r:   s      r   r   zPythonAPI.__init__   s    )29	*K$$$ 	* 	* 	*')DK$$$	* \33ENCC

--//~bjmm44Jv}V];;a?@@	Y

6=1C#D#Dq#HIImoo,55ejAA~bjmm44J$@1$DEE<
1z7PQQ%/%E"%/%E"%/%E"%/%E"""s   3 AAc                 &    t          | |||          S r   )rT   )r   rX   rY   rZ   s       r   get_env_managerzPythonAPI.get_env_manager   s    !$Xw???r   F c                    t          j        | j        |          }t          j        | j        |          5  |rn| j        j        j        j        }|j        | j        k    sJ | 	                    dd|            | j        
                    |                                            n/| j        j                            | j        t          d| f           ddd           dS # 1 swxY w Y   dS )z;Emits LLVM code to ensure the `envptr` is not NULL
        ri   zmissing Environment: N)r   is_nullr:   if_unlikelyr}   typepointeereturn_typerk   ro   rq   get_null_objectr9   	call_convreturn_user_excRuntimeError)r   envptrreturn_pyobject	debug_msgr   fntys         r   emit_environment_sentryz!PythonAPI.emit_environment_sentry   s=    /$,77 w77 	 	 |,19'4:5555##(*M)*M*M     !5!5!7!78888&66L,8Y88:  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   B C""C&)C&c                     t          j        t          j                    | j        g          }|                     |d          }| j                            ||g           d S )N	Py_IncRefnamer   FunctionTypeVoidTyperk   _get_functionr:   callr   r?   r   fns       r   increfzPythonAPI.incref   U    r{}}tzl;;;77"se$$$$$r   c                     t          j        t          j                    | j        g          }|                     |d          }| j                            ||g           d S )N	Py_DecRefr   r   r   s       r   decrefzPythonAPI.decref   r   r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )Nnumba_py_typer   r   r   rk   r   r:   r   r   s       r   get_typezPythonAPI.get_type   sK    tzDJ<88?;;|  cU+++r   c                 t   t          j        t          j        d                    }t          j        |          }| j        | j        ||g}t          j        t          j        d          |d          }	|                     |	d          }
| j                            |
||||gt          |          z             S )Nr{       Tvar_argPyArg_ParseTupleAndKeywordsr   	r   r   r   rk   r   r   r:   r   list)r   argskwsfmtkeywordsobjscharptr
charptraryargtypesr   r   s              r   parse_tuple_and_keywordsz"PythonAPI.parse_tuple_and_keywords   s    .A//^G,,
J
GZ@rz"~~xFFF+HII|  dCh%?$t**%LMMMr   c                 :   t          j        t          j        d                    }| j        |g}t          j        t          j        d          |d          }|                     |d          }| j                            |||gt          |          z             S )Nr{   r   Tr   PyArg_ParseTupler   r   )r   r   r   r   r   r   r   r   s           r   parse_tuplezPythonAPI.parse_tuple   s    .A//J(rz"~~xFFF+=>>|  dC[4::%=>>>r   c                 R   t          j        t          j        d                    }| j        || j        | j        g}t          j        t          j        d          |d          }|                     |d          }	t          | j        t          |                    }t          | j        t          |                    }t          |t                    r%| j                            | j        j        |          }| j                            |	||||gt!          |          z             S )Nr{   r   Tr   PyArg_UnpackTupler   )r   r   r   rk   r   r   r   r   intrV   r\   r9   insert_const_stringr:   r~   r   r   )
r   r   r   n_minn_maxr   r   r   r   r   s
             r   unpack_tuplezPythonAPI.unpack_tuple  s    .A//J$/Jrz"~~xFFF+>??#e**55#e**55dC   	O<33DL4GNND|  dD%%?$t**%LMMMr   c                     t          j        | j        d          }|                     |d          }| j                            |d          S )Nr*   PyErr_Occurredr   r   r   r   r   s      r   err_occurredzPythonAPI.err_occurred  sF    tz2..+;<<|  R(((r   c                     t          j        t          j                    d          }|                     |d          }| j                            |d          S )Nr*   PyErr_Clearr   )r   r   r   r   r:   r   r   s      r   	err_clearzPythonAPI.err_clear  sI    r{}}b11=99|  R(((r   c                    t          j        t          j                    | j        | j        g          }|                     |d          }t          |t                    r|                     |          }t          |t                    r | j	        
                    | j        |          }| j                            |||f          S )NPyErr_SetStringr   )r   r   r   rk   r   r   rV   r\   get_c_objectr9   r   r~   r:   r   )r   exctypemsgr   r   s        r   ro   zPythonAPI.err_set_string  s    r{}}tz4<.HII+<==gs## 	1''00Gc3 	E,224;DDC|  gs^444r   c                    t          j        t          j                    | j        | j        gd          }|                     |d          }t          |t                    r|                     |          }t          |t                    r | j	        
                    | j        |          }| j                            |||ft          |          z             S )NTr   PyErr_Formatr   )r   r   r   rk   r   r   rV   r\   r   r9   r   r~   r:   r   tuple)r   r   r   format_argsr   r   s         r   
err_formatzPythonAPI.err_format(  s    r{}}tz4<.HRVWWW>::gs## 	1''00Gc3 	E,224;DDC|  gs^eK6H6H%HIIIr   Nc                     t          j        t          j                    | j        g          }|                     |d          }||                                 }| j                            ||f          S )z
        Raise an arbitrary exception (type or value or (type, args)
        or None - if reraising).  A reference to the argument is consumed.
        numba_do_raiser   )r   r   r   rk   r   	make_noner:   r   )r   excr   r   s       r   raise_objectzPythonAPI.raise_object1  sf    
 r{}}tzl;;+;<<;..""C|  cV,,,r   c                 "   t          j        t          j                    | j        | j        g          }|                     |d          }t          |t                    r|                     |          }| j        	                    |||f          S )NPyErr_SetObjectr   
r   r   r   rk   r   rV   r\   r   r:   r   )r   r   excvalr   r   s        r   err_set_objectzPythonAPI.err_set_object<  s}    r{}}tz4:.FGG+<==gs## 	1''00G|  gv%6777r   c                    t          j        t          j                    | j        g          }|                     |d          }t          |t                    r|                     |          }| j        	                    ||f          S )NPyErr_SetNoner   r   )r   r   r   r   s       r   err_set_nonezPythonAPI.err_set_noneC  st    r{}}tzl;;?;;gs## 	1''00G|  gZ000r   c                     t          j        t          j                    | j        g          }|                     |d          }| j                            ||f          S )NPyErr_WriteUnraisabler   r   r   s       r   err_write_unraisablezPythonAPI.err_write_unraisableJ  sP    r{}}tzl;;+BCC|  cV,,,r   c                     t          j        t          j                    | j        gdz            }|                     |d          }| j                            ||||f          S )N   PyErr_Fetchr   )r   r   r   r   r   r:   r   )r   ptypvalptbr   r   s         r   	err_fetchzPythonAPI.err_fetchO  sY    r{}}t}o.ABB=99|  c4%5666r   c                     t          j        t          j                    | j        gdz            }|                     |d          }| j                            ||||f          S )Nr  PyErr_Restorer   r   )r   tyr4   tbr   r   s         r   err_restorezPythonAPI.err_restoreT  sX    r{}}tzlQ.>???;;|  b#r]333r   c              #   .   K    fdt          d          D             \  }}}                     |||           dV   j                            |          } j                            |          } j                            |          }|rt	          j         j                                                   } j                            |d          5 \  }	}
|	5                       |                                |                                |           ddd           n# 1 swxY w Y   |
5   	                    |||           ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS  	                    |||           dS )a  
        Temporarily push the current error indicator while the code
        block is executed.  If *keep_new* is True and the code block
        raises a new error, the new error is kept, otherwise the old
        error indicator is restored at the end of the block.
        c                 N    g | ]!}t          j        j        j                  "S r*   )r   rj   r:   rk   ).0ir   s     r   
<listcomp>z&PythonAPI.err_push.<locals>.<listcomp>a  s:     - - - "-dlDJGG - - -r   r  NFlikely)
ranger  r:   rp   r   rm   r   rl   r   r  )r   keep_newr  r  r  r
  r4   r  	new_errorif_errorif_oks   `          r   err_pushzPythonAPI.err_pushY  sb     - - - -#(88- - -T3sD#&&&\s##l%%\s## 	*+DL$:K:K:M:MNNI%%i%>> 2BS8U $ $KKOOOKK$$$KKOOO	$ $ $ $ $ $ $ $ $ $ $ $ $ $ $
  2 2$$Rb1112 2 2 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 Rb)))))s[   E1A D(E1(D,	,E1/D,	0E15EE1E	E1 E	!E11E58E5c                 \    | j                             | j        | j        j        |d          S )z
        Get a Python object through its C-accessible *name*
        (e.g. "PyExc_ValueError").  The underlying variable must be
        a `PyObject *`, and the value of that pointer is returned.
        T)	dllimport)r9   get_c_valuer:   rk   r   )r   r   s     r   r   zPythonAPI.get_c_objectv  s3     |''dj6H$26 ( 8 8 	8r   c                 |    d|z  }| j                             | j        |          }|                     d|           d S )Nzglobal name '%s' is not definedPyExc_NameErrorr9   r   r~   ro   r   r   r   cstrs       r   raise_missing_global_errorz$PythonAPI.raise_missing_global_error  sB    /$6|//SAA-t44444r   c                 |    d|z  }| j                             | j        |          }|                     d|           d S )Nzname '%s' is not definedr  r  r   s       r   raise_missing_name_errorz"PythonAPI.raise_missing_name_error  sB    (4/|//SAA-t44444r   c                 8   t          j        t          j                    | j        g          }|                     |d          }|j                            d           | j                            | j	        |          }| j
                            ||f           d S )NPy_FatalErrorr   noreturn)r   r   r   r   r   
attributesaddr9   r   r~   r:   r   )r   r   r   r   r!  s        r   fatal_errorzPythonAPI.fatal_error  s    r{}}t|n==?;;
*%%%|//SAA"tg&&&&&r   c                     t          j        | j        | j        | j        g          }|                     |d          }| j                            | j        |          }| j        	                    |||g          S )FLookup name inside dict

        Returns a borrowed reference
        PyDict_GetItemStringr   )
r   r   rk   r   r   r9   r   r~   r:   r   )r   dicr   r   r   r!  s         r   dict_getitem_stringzPythonAPI.dict_getitem_string  sn    
 tzDJ+EFF+ABB|//TBB|  c4[111r   c                     t          j        | j        | j        | j        g          }|                     |d          }| j                            |||g          S )r,  PyDict_GetItemr   r   )r   r.  r   r   r   s        r   dict_getitemzPythonAPI.dict_getitem  sU    
 tzDJ
+CDD+;<<|  c4[111r   r   c           	         |dk    rLt          j        | j        d          }|                     |d          }| j                            |d          S t          j        | j        | j        g          }|                     |d          }| j                            |t          | j        t          |                    g          S )Nr   r*   
PyDict_Newr   _PyDict_NewPresized)	r   r   rk   r   r:   r   r   r   r   )r   presizer   r   s       r   dict_newzPythonAPI.dict_new  s    a<<?4:r22D##D|#<<B<$$R,,,?4:/@AAD##D/D#EEB<$$R&.tG&M&M%NP P Pr   c                     t          j        t          j        d          | j        | j        | j        f          }|                     |d          }| j                            ||||f          S )Nr   PyDict_SetItemr   r   r   r   rk   r   r:   r   )r   dictobjnameobjvalobjr   r   s         r   dict_setitemzPythonAPI.dict_setitem  sg    rz"~~
DJ04
0< = =+;<<|  gw%?@@@r   c                    t          j        t          j        d          | j        | j        | j        f          }|                     |d          }| j                            | j        |          }| j	        
                    ||||f          S )Nr   PyDict_SetItemStringr   )r   r   r   rk   r   r   r9   r   r~   r:   r   )r   r;  r   r=  r   r   r!  s          r   dict_setitem_stringzPythonAPI.dict_setitem_string  s    rz"~~
DL04
0< = =+ABB|//TBB|  gtV%<===r   c                     |                                  }|                     |          5  |D ]\  }}|                     |||           	 ddd           n# 1 swxY w Y   |S )zb
        Args
        -----
        keyvalues: iterable of (str, llvm.Value of PyObject*)
        N)r7  if_object_okrA  )r   	keyvaluesr;  kvs        r   	dict_packzPythonAPI.dict_pack  s     --//w'' 	8 	8! 8 81((!Q77778	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 s    AAAc                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )NPyFloat_FromDoubler   )r   r   rk   r   r   r:   r   )r   fvalr   r   s       r   float_from_doublezPythonAPI.float_from_double  sL    tzDK=99+?@@|  dV,,,r   c                     t          j        | j        | j        | j        g          }|                     |d          }|                     d          }| j                            |||g          S )NPyNumber_AsSsize_tr   PyExc_OverflowError)r   r   r   rk   r   r   r:   r   )r   numobjr   r   	exc_classs        r   number_as_ssize_tzPythonAPI.number_as_ssize_t  sh    tTZ0HII+?@@%%&;<<	|  fi%8999r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )NPyNumber_Longr   r   r   rO  r   r   s       r   number_longzPythonAPI.number_long  sK    tzDJ<88?;;|  fX...r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )NPyLong_AsUnsignedLongLongr   r   r   r   rk   r   r:   r   rT  s       r   long_as_ulonglongzPythonAPI.long_as_ulonglong  sL    t~
|<<+FGG|  fX...r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )NPyLong_AsLongLongr   rX  rT  s       r   long_as_longlongzPythonAPI.long_as_longlong  sL    t~
|<<+>??|  fX...r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )z
        Convert the given Python integer to a void*.  This is recommended
        over number_as_ssize_t as it isn't affected by signedness.
        PyLong_AsVoidPtrr   r   r   r   rk   r   r:   r   rT  s       r   long_as_voidptrzPythonAPI.long_as_voidptr  sN    
 t|dj\::+=>>|  fX...r   c                 p   t          j        | j        |g          }|                     ||          }t	          j        | j        | j                  }|                     ||          }| j                            | j                            ||g          |           | j        	                    |          S )Nr   )
r   r   rk   r   r   rj   r:   rD   r   rp   )r   ival	func_namenative_int_typesignedr   r   resptrs           r   _long_from_native_intzPythonAPI._long_from_native_int  s    tzO+<==955$T\4:>>9554<,,R$88&AAA|  (((r   c                     d}t          j        | j        | j        g          }|                     ||          }| j                            ||g          S )NPyLong_FromLongr   r   r   rk   r   r   r:   r   )r   rb  rc  r   r   s        r   long_from_longzPythonAPI.long_from_long  sP    %	tzDI;77955|  dV,,,r   c                 >    |                      |d| j        d          S )NPyLong_FromUnsignedLongFre  )rg  r   r   rb  s     r   long_from_ulongzPythonAPI.long_from_ulong  s.    ))$0I*.)E * C C 	Cr   c                 >    |                      |d| j        d          S )NPyLong_FromSsize_tTrn  )rg  r   ro  s     r   long_from_ssize_tzPythonAPI.long_from_ssize_t	  s.    ))$0D*./$ * H H 	Hr   c                 >    |                      |d| j        d          S )NPyLong_FromLongLongTrn  )rg  r   ro  s     r   long_from_longlongzPythonAPI.long_from_longlong  s.    ))$0E*.- * F F 	Fr   c                 >    |                      |d| j        d          S )NPyLong_FromUnsignedLongLongFrn  )rg  r   ro  s     r   long_from_ulonglongzPythonAPI.long_from_ulonglong  s.    ))$0M*.. * H H 	Hr   c                 J   |j         j        }|| j        j        k    r3|                     | j                            || j                            S || j        j        k    r3|                     | j                            || j                            S t          d|z            )zH
        Return a Python integer from any native integer value.
        integer too big (%d bits))	r   widthr   rk  r:   sextr   rv  OverflowErrorr   rb  bitss      r   long_from_signed_intzPythonAPI.long_from_signed_int  s     y49?""&&t|'8'8ty'I'IJJJT](((**4<+<+<T4=+Q+QRRR ;t DEEEr   c                 J   |j         j        }|| j        j        k    r3|                     | j                            || j                            S || j        j        k    r3|                     | j                            || j                            S t          d|z            )zH
        Same as long_from_signed_int, but for unsigned values.
        r{  )	r   r|  r   rp  r:   zextr   ry  r~  r  s      r   long_from_unsigned_intz PythonAPI.long_from_unsigned_int!  s     y4:###''(9(9$
(K(KLLLT^)))++DL,=,=dDN,S,STTT ;t DEEEr   c                     t          j        | j        | j        | j        g          }|                     |d|z            }|S )NzPyNumber_%sr   )r   r   rk   r   )r   r   r   r   s       r   _get_number_operatorzPythonAPI._get_number_operator-  s@    tzDJ
+CDD=4+?@@	r   c                 t    |rd|z   }|                      |          }| j                            |||g          S )NInPlace)r  r:   r   )r   r   lhsrhsinplacer   s         r   _call_number_operatorzPythonAPI._call_number_operator2  sC     	$t#D&&t,,|  c3Z000r   c                 4    |                      d|||          S )NAddr  r  r   r  r  r  s       r   
number_addzPythonAPI.number_add8      ))%c7)KKKr   c                 4    |                      d|||          S )NSubtractr  r  r  s       r   number_subtractzPythonAPI.number_subtract;      ))*c3)PPPr   c                 4    |                      d|||          S )NMultiplyr  r  r  s       r   number_multiplyzPythonAPI.number_multiply>  r  r   c                 4    |                      d|||          S )N
TrueDivider  r  r  s       r   number_truedividezPythonAPI.number_truedivideA  s    )),S')RRRr   c                 4    |                      d|||          S )NFloorDivider  r  r  s       r   number_floordividezPythonAPI.number_floordivideD  s    ))-c7)SSSr   c                 4    |                      d|||          S )N	Remainderr  r  r  s       r   number_remainderzPythonAPI.number_remainderG  s    ))+sC)QQQr   c                 4    |                      d|||          S )NMatrixMultiplyr  r  r  s       r   number_matrix_multiplyz PythonAPI.number_matrix_multiplyJ  s     ))*:Cg)VVVr   c                 4    |                      d|||          S )NLshiftr  r  r  s       r   number_lshiftzPythonAPI.number_lshiftM      ))(Cg)NNNr   c                 4    |                      d|||          S )NRshiftr  r  r  s       r   number_rshiftzPythonAPI.number_rshiftP  r  r   c                 4    |                      d|||          S )NAndr  r  r  s       r   
number_andzPythonAPI.number_andS  r  r   c                 4    |                      d|||          S )NOrr  r  r  s       r   	number_orzPythonAPI.number_orV  s    ))$S')JJJr   c                 4    |                      d|||          S )NXorr  r  r  s       r   
number_xorzPythonAPI.number_xorY  r  r   c                     t          j        | j        | j        gdz            }|rdnd}|                     ||          }| j                            ||||                                 g          S )Nr  PyNumber_InPlacePowerPyNumber_Power)r   r   rk   r   r:   r   borrow_none)r   r  r  r  r   fnamer   s          r   number_powerzPythonAPI.number_power\  so    tzDJ<!+;<<+2H''8He,,|  c30@0@0B0B%CDDDr   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||f          S )NPyNumber_Negativer   r   r   s       r   number_negativezPythonAPI.number_negativeb  L    tzDJ<88+>??|  cV,,,r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||f          S )NPyNumber_Positiver   r   r   s       r   number_positivezPythonAPI.number_positiveg  r  r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )NPyNumber_Floatr   r   )r   r4   r   r   s       r   number_floatzPythonAPI.number_floatl  sL    tzDJ<88+;<<|  cU+++r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||f          S )NPyNumber_Invertr   r   r   s       r   number_invertzPythonAPI.number_invertq  sL    tzDJ<88+<==|  cV,,,r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )NPyFloat_AsDoubler   )r   r   r   rk   r   r:   r   )r   fobjr   r   s       r   float_as_doublezPythonAPI.float_as_doublev  sL    t{TZL99+=>>|  dV,,,r   c                 l    | j                             || j                  }|                     |          S )z8
        Get a Python bool from a LLVM boolean.
        )r:   r  r   bool_from_long)r   bvallongvals      r   bool_from_boolzPythonAPI.bool_from_bool{  s1     ,##D$)44""7+++r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )NPyBool_FromLongr   rj  )r   rb  r   r   s       r   r  zPythonAPI.bool_from_long  sL    tzDI;77+<==|  dV,,,r   c                     t          j        | j        t          j                    t          j                    g          }|                     |d          }| j                            |||g          S )NPyComplex_FromDoublesr   )r   r   rk   r   r   r:   r   )r   realvalimagvalr   r   s        r   complex_from_doubleszPythonAPI.complex_from_doubles  s\    tzBMOOR]__+MNN+BCC|  gw%7888r   c                     t          j        t          j                    | j        g          }|                     |d          }| j                            ||g          S )NPyComplex_RealAsDoubler   r   r   r   rk   r   r:   r   r   cobjr   r   s       r   complex_real_as_doublez PythonAPI.complex_real_as_double  P    r}==+CDD|  dV,,,r   c                     t          j        t          j                    | j        g          }|                     |d          }| j                            ||g          S )NPyComplex_ImagAsDoubler   r  r  s       r   complex_imag_as_doublez PythonAPI.complex_imag_as_double  r  r   c                    t          j        | j        | j                  }t          j        | j        | j                  }t          j        | j        | j                  }t	          j        t	          j        d          | j        g| j                                        gdz  z             }| 	                    |d          }| j        
                    |||||f          }| j                            |          }| j                            |          }	| j                            |          }
t          j        | j        |          ||	|
fS )z
        Read the members of a slice of integers.

        Returns a (ok, start, stop, step) tuple where ok is a boolean and
        the following members are pointer-sized ints.
        r   r  numba_unpack_slicer   )r   rj   r:   r   r   r   r   rk   r   r   r   rp   r   )r   r?   pstartpstoppstepr   r   resstartstopsteps              r   slice_as_intszPythonAPI.slice_as_ints  s    $T\4?CC#DL$/BB#DL$/BBrz"~~ $
|t/I/I/K/K.Lq.PPR R+?@@lS&%$?@@!!&))|  ''|  ''t|S115$DDr   c                     t          j        | j        | j        | j        | j        g          }|                     |d          }| j                            ||||f          S )NPySequence_GetSlicer   r   r   rk   r   r   r:   r   )r   r?   r  r  r   r   s         r   sequence_getslicezPythonAPI.sequence_getslice  sa    tzDJ,0O,= > >+@AA|  c5$%7888r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )NPySequence_Tupler   r   r   s       r   sequence_tuplezPythonAPI.sequence_tuple  L    tzDJ<88+=>>|  cU+++r   c                     t          j        | j        | j        | j        g          }|                     |d          }| j                            |||g          S )NPySequence_Concatr   r   )r   obj1obj2r   r   s        r   sequence_concatzPythonAPI.sequence_concat  sS    tzDJ
+CDD+>??|  dD\222r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )N
PyList_Newr   r  )r   szvalr   r   s       r   list_newzPythonAPI.list_new  sL    tzDO+<==<88|  eW---r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )NPyList_Sizer   r   r   r   rk   r   r:   r   )r   lstr   r   s       r   	list_sizezPythonAPI.list_size  sK    t===99|  cU+++r   c                     t          j        t          j        d          | j        | j        g          }|                     |d          }| j                            |||g          S )Nr   PyList_Appendr   r:  )r   r  r4   r   r   s        r   list_appendzPythonAPI.list_append  sX    rz"~~
DJ/GHH?;;|  c3Z000r   c                     t          j        t          j        d          | j        | j        | j        g          }|                     |d          }| j                            ||||g          S )z6
        Warning: Steals reference to ``val``
        r   PyList_SetItemr   )r   r   r   rk   r   r   r:   r   )r   r  idxr4   r   r   s         r   list_setitemzPythonAPI.list_setitem  sh     rz"~~
DO04
0< = =+;<<|  c3_555r   c                 *   t          j        | j        | j        | j        g          }|                     |d          }t          |t                    r%| j                            t          j
        |          }| j                            |||g          S )z/
        Returns a borrowed reference.
        PyList_GetItemr   )r   r   rk   r   r   rV   r   r9   get_constantr   r   r:   r   )r   r  r	  r   r   s        r   rn   zPythonAPI.list_getitem  s     tzDJ+HII+;<<c3 	=,++EJ<<C|  c3Z000r   c                    ||                                  }t          j        t          j        d          | j        | j        | j        | j        g          }|                     |d          }| j                            |||||f          S )Nr   PyList_SetSlicer   )	r   r   r   r   rk   r   r   r:   r   )r   r  r  r  r?   r   r   s          r   list_setslicezPythonAPI.list_setslice  s    ;&&((Crz"~~
DO040M N N+<==|  c5$%<===r   c                     t          j        | j        | j        | j        g          }|                     |d          }| j                            t          j        |          }| j	        
                    |||g          S )z"
        Borrow reference
        PyTuple_GetItemr   )r   r   rk   r   r   r9   r  r   r   r:   r   )r   tupr	  r   r   s        r   tuple_getitemzPythonAPI.tuple_getitem  sn     tzDJ+HII+<==l''
C88|  c3Z000r   c                 >   t          j        | j        | j        gd          }|                     |d          }| j                            t          j        t          |                    }|g}|
                    |           | j                            ||          S )NTr   PyTuple_Packr   )r   r   rk   r   r   r9   r  r   r   ra   extendr:   r   )r   itemsr   r   nr   s         r   
tuple_packzPythonAPI.tuple_pack  s    tzDO+<dKKK>::L%%ej#e**==sE|  T***r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )NPyTuple_Sizer   r  )r   r  r   r   s       r   
tuple_sizezPythonAPI.tuple_size   sK    t==>::|  cU+++r   c                    t          j        | j        t          j        d          g          }|                     |d          }| j                            || j                            t          j
        |          g          S )Nr   PyTuple_Newr   )r   r   rk   r   r   r:   r   r9   r  r   int32)r   countr   r   s       r   	tuple_newzPythonAPI.tuple_new  sz    tzBJrNN+;<<=99|  dl&?&?@E'G 'G &H I I 	Ir   c                 F   t          j        t          j        d          | j        t          j        d          | j        g          }|                     |d          }| j                            t          j        |          }| j	        
                    ||||g           dS )z/
        Steals a reference to `item`.
        r   PyTuple_SetItemr   N)r   r   r   rk   r   r9   r  r   r   r:   r   )r   	tuple_valrd   itemr   
setitem_fns         r   tuple_setitemzPythonAPI.tuple_setitem  s     rz"~~
BJrNNDJ/WXX''3D'EE
))%+u==*y%&>?????r   c                     ||                                  }t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )N	PySet_Newr   r   r   r   rk   r   r:   r   )r   iterabler   r   s       r   set_newzPythonAPI.set_new  sb    ++--HtzDJ<88;77|  hZ000r   c                     t          j        t          j        d          | j        | j        g          }|                     |d          }| j                            |||g          S )Nr   	PySet_Addr   r:  )r   setrO   r   r   s        r   set_addzPythonAPI.set_add  sX    rz"~~
DJ/GHH;77|  c5\222r   c                     t          j        t          j        d          | j        g          }|                     |d          }| j                            ||g          S )Nr   PySet_Clearr   r:  r   r0  r   r   s       r   	set_clearzPythonAPI.set_clear$  sQ    rz"~~
|<<=99|  cU+++r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )N
PySet_Sizer   r  r4  s       r   set_sizezPythonAPI.set_size)  sK    t==<88|  cU+++r   c                     t          j        t          j        d          | j        | j        g          }|                     |d          }| j                            |||g          S )Nr   _PySet_Updater   r:  )r   r0  r,  r   r   s        r   
set_updatezPythonAPI.set_update.  sX    rz"~~
DJ/GHH?;;|  c8_555r   c                 X   t          j        t          j        d          | j        | j                                        | j                                        | j                                        g          }|                     |d          }| j        	                    |||||f          S )Nr   _PySet_NextEntryr   )
r   r   r   rk   r   r   r   r   r:   r   )r   r0  posptrkeyptrhashptrr   r   s          r   set_next_entryzPythonAPI.set_next_entry3  s    rz"~~ $
DO,F,F,H,H $
 5 5 7 79R9R9T9T VW W +=>>|  c667%CDDDr   c              #   D  	
K   | j         
t          j        
| j        d          }t          j        
| j        d          }t          j        
t          | j        d          d          }
                    d          }
                    d          	
	                    |           	
fd}

                    |          5  |                     ||||          }t          j        
|          }
                    |d	
          5  
	                    	           d d d            n# 1 swxY w Y   t          
                    |          |          V  
	                    |           d d d            n# 1 swxY w Y   
                    	           d S )Nr@  r   r?  r   r>  bb_bodybb_endc                  2                                     d S r   )branch)rD  r:   s   r   rw   z'PythonAPI.set_iterate.<locals>.do_breakH  s    NN6"""""r   Fr  )r:   r   rj   r   rk   alloca_once_valuer   r   append_basic_blockrF  
goto_blockrA  r   if_thenrv   rp   position_at_end)r   r0  r@  r?  r>  rC  rw   rfinishedrD  r:   s            @@r   set_iteratezPythonAPI.set_iterate:  s&     ,%gt~INNN$WdjxHHH*7+3DOQ+G+G08: : : ,,Y77++H55w	# 	# 	# 	# 	# 	# (( 	$ 	$##CAAAw22H%88 ' 'v&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' 'V 4 4h?????NN7###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	'''''s7   AF D/#F /D3	3F 6D3	7=F  FFc                 (   t          j        | j                  }t          j        t          j                    |g          }|                     |d          }t          j        | j        | j                  }| j        	                    ||g           |S )zk
        Ensure the GIL is acquired.
        The returned value must be consumed by gil_release().
        numba_gil_ensure)
r   r   r   r   r   r   r   rj   r:   r   )r   gilptrtyr   r   gilptrs        r   
gil_ensurezPythonAPI.gil_ensureY  sy    
 >$.11r{}}xj99&899$T\4>BB"vh'''r   c                     t          j        | j                  }t          j        t          j                    |g          }|                     |d          }| j                            ||g          S )zg
        Release the acquired GIL by gil_ensure().
        Must be paired with a gil_ensure().
        numba_gil_release)r   r   r   r   r   r   r:   r   )r   gilrQ  r   r   s        r   gil_releasezPythonAPI.gil_releasee  s^    
 >$.11r{}}xj99&9::|  cU+++r   c                     t          j        | j        g           }|                     |d          }| j                            |g           S )zj
        Release the GIL and return the former thread state
        (an opaque non-NULL pointer).
        PyEval_SaveThreadr   )r   r   r   r   r:   r   r   s      r   save_threadzPythonAPI.save_threado  sH    
 t|R00+>??|  R(((r   c                     t          j        t          j                    | j        g          }|                     |d          }| j                            ||g           dS )zH
        Restore the given thread state by reacquiring the GIL.
        PyEval_RestoreThreadr   N)r   r   r   r   r   r:   r   )r   thread_stater   r   s       r   restore_threadzPythonAPI.restore_threadx  sX     r{}}t|n==+ABB"|n-----r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||f          S )Nnumba_get_pyobject_private_datar   r_  r   s       r   object_get_private_dataz!PythonAPI.object_get_private_data  sL    t|dj\::+LMM|  cV,,,r   c                     t          j        t          j                    | j        | j        g          }|                     |d          }| j                            |||f          S )Nnumba_set_pyobject_private_datar   )r   r   r   rk   r   r   r:   r   )r   r?   ptrr   r   s        r   object_set_private_dataz!PythonAPI.object_set_private_data  sW    r{}}tz4<.HII+LMM|  c3Z000r   c                     t          j        t          j                    | j        g          }|                     |d          }| j                            ||f          S )N!numba_reset_pyobject_private_datar   r   r   s       r   object_reset_private_dataz#PythonAPI.object_reset_private_data  sP    r{}}tzl;;+NOO|  cV,,,r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )NPyImport_ImportModuleNoBlockr   r   r   rk   r   r   r:   r   )r   modnamer   r   s       r   import_module_noblockzPythonAPI.import_module_noblock  sL    tzDL>::+IJJ|  gY///r   c                 >   t          j        | j        | j        gd          }|                     |d          }|gt	          |          z   }|                    | j                            t          j	                             | j
                            ||          S )NTr   PyObject_CallFunctionObjArgsr   )r   r   rk   r   r   rb   r9   get_constant_nullr   r   r:   r   )r   calleeobjargsr   r   r   s         r   call_function_objargszPythonAPI.call_function_objargs  s    tzDJ<FFF+IJJx$w--'DL225>BBCCC|  T***r   r*   c                    | j                             | j        |          }t          j        | j        | j        | j        | j        gd          }|                     |d          }dt          |          z  }| j                             | j        |          }|||g}	|r|		                    |           |	
                    | j                             t          j                             | j                            ||	          S )NTr   PyObject_CallMethodr   O)r9   r   r~   r   r   rk   r   r   ra   r  rb   rp  r   r   r:   r   )
r   rq  methodrr  cnamer   r   r   cfmtr   s
             r   call_methodzPythonAPI.call_method  s    00fEEtzDJdl+S%)+ + ++@AACLL |//SAAt$ 	!KK   DL225>BBCCC|  T***r   c                 
   ||                                  }||                                  }t          j        | j        | j        gdz            }|                     |d          }| j                            ||||f          S )Nr  PyObject_Callr   r+  )r   rq  r   r   r   r   s         r   r   zPythonAPI.call  s    <''))D;&&((CtzDJ<!+;<<?;;|  fdC%8999r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||f          S )zJEmit a call to ``PyObject_Type(obj)`` to get the type of ``obj``.
        PyObject_Typer   r   r   s       r   object_typezPythonAPI.object_type  sM     tzDJ<88?;;|  cV,,,r   c                     t          j        t          j        d          | j        g          }|                     |d          }| j                            ||g          S )Nr   PyObject_IsTruer   r:  r   s       r   object_istruezPythonAPI.object_istrue  sR    rz"~~
|<<+<==|  cU+++r   c                     t          j        t          j        d          | j        g          }|                     |d          }| j                            ||g          S )Nr   PyObject_Notr   r:  r   s       r   
object_notzPythonAPI.object_not  sQ    rz"~~
|<<>::|  cU+++r   c                    g d}||v r|                     |          }t          j        | j        | j        | j        t          j        d          g          }|                     |d          }| j                            t          j	        |          }| j
                            ||||f          S |dk    r1| j
                            d||          }	|                     |	          S |dk    r1| j
                            d||          }	|                     |	          S |d	v rt          j        t          j        d          | j        | j        g          }|                     |d
          }| j
                            |||f          }
| j                            t          j	        d          }| j
                            d|
|          }t          j        | j
        t!          | j        d                    }t          j        | j
        |          5  |dk    r| j
                            |
          }
| j
                            |
t          j        d                    }| j
                            |                     |          |           ddd           n# 1 swxY w Y   | j
                            |          S t-          d                    |                    )zd
        Refer to Python source Include/object.h for macros definition
        of the opid.
        )<z<===!=>z>=r   PyObject_RichComparer   isr  zis notr  )innot inPySequence_ContainsNr     zUnknown operator {op!r})op)rd   r   r   rk   r   r   r9   r  r   r   r:   r   icmp_unsignedr  r   rG  r   	if_likelynot_truncrD   rp   NotImplementedErrorformat)r   r  r  opstropsopidr   r   lopidbitflagstatusnegoneis_goodoutptr	truncateds                  r   object_richcomparezPythonAPI.object_richcompare  s   
 100C<<99U##D?4:
DJ
SU/WXXD##D/E#FFBL--ek4@@E<$$R#sE):;;;d]]l00sC@@G&&w///hl00sC@@G&&w///&&&?2:b>>DJ
3KLLD##D/D#EEB\&&rC:66F\..u{B??Fl00vvFFG.t|/7
D/I/IK KF "4<99 + +H$$!\..v66F L..vrz!}}EE	""4#6#6y#A#A#)+ + ++ + + + + + + + + + + + + + + <$$V,,,%&?&F&F 'G ' '   s   A<JJ"Jc                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )NPyIter_Nextr   r   )r   iterobjr   r   s       r   	iter_nextzPythonAPI.iter_next  sK    tzDJ<88=99|  gY///r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )NPyObject_GetIterr   r   r   s       r   object_getiterzPythonAPI.object_getiter  r  r   c                     | j                             | j        |          }t          j        | j        | j        | j        g          }|                     |d          }| j        	                    |||g          S )NPyObject_GetAttrStringr   )
r9   r   r~   r   r   rk   r   r   r:   r   )r   r?   attrr!  r   r   s         r   object_getattr_stringzPythonAPI.object_getattr_string  sl    |//TBBtzDJ+EFF+CDD|  c4[111r   c                     t          j        | j        | j        | j        g          }|                     |d          }| j                            |||g          S )NPyObject_GetAttrr   r   )r   r?   r  r   r   s        r   object_getattrzPythonAPI.object_getattr  sS    tzDJ
+CDD+=>>|  c4[111r   c                    | j                             | j        |          }t          j        t          j        d          | j        | j        | j        g          }|                     |d          }| j	        
                    ||||g          S )Nr   PyObject_SetAttrStringr   )r9   r   r~   r   r   r   rk   r   r   r:   r   )r   r?   r  r4   r!  r   r   s          r   object_setattr_stringzPythonAPI.object_setattr_string
  sy    |//TBBrz"~~
DL$*/UVV+CDD|  c4%5666r   c                     t          j        t          j        d          | j        | j        | j        g          }|                     |d          }| j                            ||||g          S )Nr   PyObject_SetAttrr   r:  )r   r?   r  r4   r   r   s         r   object_setattrzPythonAPI.object_setattr  s`    rz"~~
DJ
/STT+=>>|  c4%5666r   c                 T    |                      |||                                           S r   )r  r   r   r?   r  s      r   object_delattr_stringzPythonAPI.object_delattr_string  s(     ))#tT5I5I5K5KLLLr   c                 T    |                      |||                                           S r   )r  r   r  s      r   object_delattrzPythonAPI.object_delattr  s(     ""3d.B.B.D.DEEEr   c                     t          j        | j        | j        | j        g          }|                     |d          }| j                            |||f          S )z!
        Return obj[key]
        PyObject_GetItemr   r   r   r?   keyr   r   s        r   object_getitemzPythonAPI.object_getitem  sU     tzDJ
+CDD+=>>|  c3Z000r   c                     t          j        t          j        d          | j        | j        | j        g          }|                     |d          }| j                            ||||f          S )z 
        obj[key] = val
        r   PyObject_SetItemr   r:  )r   r?   r  r4   r   r   s         r   object_setitemzPythonAPI.object_setitem'  sa     rz"~~
DJ
/STT+=>>|  c3_555r   c                     t          j        t          j        d          | j        | j        g          }|                     |d          }| j                            |||f          S )z
        del obj[key]
        r   PyObject_DelItemr   r:  r  s        r   object_delitemzPythonAPI.object_delitem/  s[     rz"~~
DJ/GHH+=>>|  c3Z000r   c                     t          j        | j        | j        g          }d}|                     ||          }| j                            ||g          S )NPyUnicode_AsUTF8r   )r   r   r   rk   r   r:   r   )r   strobjr   r  r   s        r   string_as_stringzPythonAPI.string_as_string7  sP    t|dj\::"511|  fX...r   c                    t          j        | j        | j                  }t	          j        | j        | j        | j                                        g          }d}| 	                    ||          }| j        
                    |||g          }| j                            dt          |j        d          |          }||| j                            |          fS )z
        Returns a tuple of ``(ok, buffer, length)``.
        The ``ok`` is i1 value that is set if ok.
        The ``buffer`` is a i8* of the output buffer.
        The ``length`` is a i32/i64 (py_ssize_t) of the length of the buffer.
        PyUnicode_AsUTF8AndSizer   r  N)r   rj   r:   r   r   r   r   rk   r   r   r   r  r   r   rp   )r   r  p_lengthr   r  r   bufferoks           r   string_as_string_and_sizez#PythonAPI.string_as_string_and_size=  s     &t|T_EEt|dj.2o.H.H.J.J.L M M)511""2'9::\''(0d(C(C(.0 0 FDL--h7788r   c           	         t          j        | j        | j                  }t          j        | j        t	          j        d                    }t          j        | j        t	          j        d                    }t          j        | j        | j                  }t	          j        | j        | j	        | j        
                                t	          j        d          
                                t	          j        d          
                                | j        
                                g          }d}|                     ||          }| j                            ||||||g          }	| j                            dt          |	j        d          |	          }
|
|	| j                            |          | j                            |          | j                            |          | j                            |          fS )a  
        Returns a tuple of ``(ok, buffer, length, kind)``.
        The ``ok`` is i1 value that is set if ok.
        The ``buffer`` is a i8* of the output buffer.
        The ``length`` is a i32/i64 (py_ssize_t) of the length of the buffer.
        The ``kind`` is a i32 (int32) of the Unicode kind constant
        The ``hash`` is a long/uint64_t (py_hash_t) of the Unicode constant hash
        r   numba_extract_unicoder   r  N)r   rj   r:   r   r   r   r   r   r   rk   r   r   r   r  r   r   rp   )r   r  r  p_kindp_asciip_hashr   r  r   r  r  s              r   string_as_string_size_and_kindz(PythonAPI.string_as_string_size_and_kindQ  s    &t|T_EE$T\2:b>>BB%dlBJrNNCC$T\4>BBt|dj.2o.H.H.J.J.0jnn.G.G.I.I.0jnn.G.G.I.I.2n.G.G.I.I	.K L L
 (511""67F;= =\''(0d(C(C(.0 0 FDL--h77!!&))4<+<+<W+E+E!!&))+ 	+r   c                     t          j        | j        | j        | j        g          }d}|                     ||          }| j                            |||g          S )NPyString_FromStringAndSizer   r   r   rk   r   r   r   r:   r   r   stringsizer   r  r   s         r   string_from_string_and_sizez%PythonAPI.string_from_string_and_sizeo  sW    tzDL$/+JKK,511|  fd^444r   c                     t          j        | j        | j        g          }d}|                     ||          }| j                            ||g          S )NPyUnicode_FromStringr   rk  )r   r  r   r  r   s        r   string_from_stringzPythonAPI.string_from_stringu  sP    tzDL>::&511|  fX...r   c                     t          j        | j        t          j        d          | j        | j        g          }d}|                     ||          }| j                            ||||g          S )Nr   PyUnicode_FromKindAndDatar   )	r   r   rk   r   r   r   r   r:   r   )r   kindr  r  r   r  r   s          r   string_from_kind_and_dataz#PythonAPI.string_from_kind_and_data{  sd    tzBJrNNDL$/+Z[[+511|  dFD%9:::r   c                     t          j        | j        | j        | j        g          }d}|                     ||          }| j                            |||g          S )NPyBytes_FromStringAndSizer   r  r  s         r   bytes_from_string_and_sizez$PythonAPI.bytes_from_string_and_size  sW    tzDL$/+JKK+511|  fd^444r   c                     t          j        | j        | j        g          }d}|                     ||          }| j                            ||g          S )NPyObject_Hashr   )r   r   r   rk   r   r:   r   )r   r?   r   r  r   s        r   object_hashzPythonAPI.object_hash  sP    t~
~>>511|  cV,,,r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )NPyObject_Strr   r   r   s       r   
object_strzPythonAPI.object_str  sK    tzDJ<88>::|  cU+++r   c                 X    |                                  }|                     |           |S r   )r  r   r   r?   s     r   r   zPythonAPI.make_none  s*      C
r   c                 ,    |                      d          S )N_Py_NoneStruct)r   r   s    r   r  zPythonAPI.borrow_none  s      !1222r   c                     t          j        t          j                    | j        gd          }|                     |d          }| j                            ||f|z             S )NTr   PySys_FormatStdoutr   )r   r   r   r   r   r:   r   )r   r   r   r   r   s        r   sys_write_stdoutzPythonAPI.sys_write_stdout  sY    r{}}t|ndKKK+?@@|  cVd]333r   c                     t          j        t          j                    | j        g          }|                     |d          }| j                            ||f          S )zL
        Dump a Python object on C stderr.  For debugging purposes.
        _PyObject_Dumpr   r   r   s       r   object_dumpzPythonAPI.object_dump  sR     r{}}tzl;;+;<<|  cV,,,r   c                    | j         j        s
J d            t          j        d          }|                     |                     |j                            }t          j        | j        | j	        | j        ||| j        g          }| 
                    |d          }|j        d                             d           | j                             t          j        |j                  }| j                             t          j        t#          |j                            }	t'          j        | j        |          }
| j                            || j                            |
| j	                  |||	|g          S )NzNRT requiredr   "NRT_adapt_ndarray_to_python_acqrefr   r   	nocapture)r9   
enable_nrtr   r   unserializeserialize_objectbox_typer   rk   r   r   r   add_attributer  r   r   ndimr   mutabler   rG  r:   r   bitcast)r   arytyarydtypeptrinttyserial_aryty_pytyper   r   r  writablearyptrs              r   nrt_adapt_ndarray_to_pythonz%PythonAPI.nrt_adapt_ndarray_to_python  sH   |&66666
2"..t/D/DU^/T/TUUtz $dj%
SU U+OPP

  ---|((ejAA<,,U[#em:L:LMM*4<==|  dl&:&:6;?<'I 'I&9&*Hh&@ A A 	Ar   c                    | j         j        }t          j        t          j        t          j        t          j        g          }t	          j        ||d          }|j        d                             d           |j        d                             d           |j	                            d           | j         
                    |||g          S )za
        Allocate a new MemInfo with data payload borrowed from a python
        object.
        NRT_meminfo_new_from_pyobjectr   r  r  noalias)r:   r~   r   r   r   	voidptr_tget_or_insert_functionr   r   return_valuer   )r   datark   modr   r   s         r   nrt_meminfo_new_from_pyobjectz'PythonAPI.nrt_meminfo_new_from_pyobject  s    
 l! 12  ++ 
 	
  ---

  ---
%%i000|  dE]333r   c                     | j         j        }t          j        | j        t
          j        g          }t          j        ||d          }|j        	                    d           | j         
                    ||g          S )NNRT_meminfo_as_pyobjectr  )r:   r~   r   r   rk   r   r  r  r  r   r   )r   miptrr  r   r   s        r   nrt_meminfo_as_pyobjectz!PythonAPI.nrt_meminfo_as_pyobject  sz    l!J
 
 +%
 

 	%%i000|  eW---r   c                     | j         j        }t          j        t          j        | j        g          }t	          j        ||d          }|j        	                    d           | j         
                    ||g          S )NNRT_meminfo_from_pyobjectr  )r:   r~   r   r   r   r  rk   r  r  r   r   )r   miobjr  r   r   s        r   nrt_meminfo_from_pyobjectz#PythonAPI.nrt_meminfo_from_pyobject  sy    l!ZL
 
 +'
 

 	%%i000|  eW---r   c                 l   | j         j        sJ t          j        t          j        d          | j        | j        g          }|                     |d          }|j        d         	                    d           |j        d         	                    d           | j
                            |||f          S )Nr   NRT_adapt_ndarray_from_pythonr   r   r  r  r9   r  r   r   r   rk   r   r   r   r   r:   r   r   r  rd  r   r   s        r   nrt_adapt_ndarray_from_pythonz'PythonAPI.nrt_adapt_ndarray_from_python  s    |&&&&rz"~~
DL/IJJ+JKK

  ---

  ---|  c3Z000r   c                    | j         j        sJ t          j        t          j                    t          j        | j                  | j        g          }|                     |d          }|j	        d         
                    d           |j	        d         
                    d           | j                            |||f          S )NNRT_adapt_buffer_from_pythonr   r   r  r  )r9   r  r   r   r   r   r   r   r   r   r   r:   r   r   bufrd  r   r   s        r   nrt_adapt_buffer_from_pythonz&PythonAPI.nrt_adapt_buffer_from_python  s    |&&&&r{}}r~d>N/O/O/3|/= > >+IJJ

  ---

  ---|  c3Z000r   c                 8    t          j        | j        ||          S r   )r   r  r~   )r   r   r   s      r   r   zPythonAPI._get_function  s    -dk4FFFr   c                 @    | j                             | j                  S r   )r:   allocark   r   s    r   
alloca_objzPythonAPI.alloca_obj  s    |""4:...r   c                 `    t          j        | j        t          | j        d                    }|S )zT
        Return a pointer to a stack-allocated, zero-initialized Py_buffer.
        N)r   rG  r:   r   r   )r   rd  s     r   alloca_bufferzPythonAPI.alloca_buffer	  s1    
 '(01A4(H(HJ J
r   c              #      K   t          j        | j        t          j        | j        |                    5  d V  d d d            d S # 1 swxY w Y   d S r   )r   r  r:   rm   r  s     r   rC  zPythonAPI.if_object_ok  s      t|&24<EEG G 	 	EEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                     |                      |          }|                     |          }| j                            | j        d          }|                     ||           |                     |           d S )Nz%s)r  r  r9   r   r~   r  r   )r   r?   r  r!  r   s        r   print_objectzPythonAPI.print_object  sm    %%$$V,,l..t{DAAc4(((Fr   c                 p    | j                             | j        |          }|                     |           d S r   )r9   r   r~   r  )r   textr   s      r   print_stringzPythonAPI.print_string  s5    l..t{DAAc"""""r   c                 ,    t          | j        d           S r   )r   rk   r   s    r   r   zPythonAPI.get_null_object#  s    
D)))r   c                 b    |                                  }| j                            |           d S r   )r   r:   rq   )r   nones     r   return_nonezPythonAPI.return_none&  s-    ~~r   c                    t          |          }|                     | j                            t          j        |                    }|                     |          5  t          |          D ]_}| j                            t          j        |          }|                     ||                    | 	                    ||||                    `	 d d d            n# 1 swxY w Y   |S r   )
ra   r  r9   r  r   r   rC  r  r   r
  )r   r  r  seqr  r	  s         r   	list_packzPythonAPI.list_pack*  s
   JJmmDL55ej!DDEEs## 	6 	61XX 6 6l//
A>>E!H%%%!!#sE!H55556	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6
 
s   A0CC!Cc                    t          j        | j        | j        t          j        d          | j        f          }|                     |d          }| j                            | j                            |          d          }| j                            | j                            |          d          }| j                            | j                            |          d          }| j        	                    ||||f          S )z
        Unserialize some data.  *structptr* should be a pointer to
        a {i8* data, i32 length, i8* hashbuf, i8* func_ptr, i32 alloc_flag}
        structure.
        r   numba_unpickler   r   r     )
r   r   rk   r   r   r   r:   extract_valuerp   r   )r   	structptrr   r   rd  r  hasheds          r   r  zPythonAPI.unserialize4  s     tz"lBJrNNDLIK K+;<<l(():):9)E)EqIIL&&t|'8'8'C'CQGG++DL,=,=i,H,H!LL|  c1f%5666r   c                     t          j        | j        | j        | j        f          }|                     |d          }| j                            |||f          S )z
        Serialize some data at runtime. Returns a pointer to a python tuple
        (bytes_data, hash) where the first element is the serialized data as
        bytes and the second its hash.
        "numba_runtime_build_excinfo_structr   r   )r   	struct_gvexc_argsr   r   s        r   build_dynamic_excinfo_structz&PythonAPI.build_dynamic_excinfo_structB  sV     tzDJ
+CDD+OPP|  i%:;;;r   c                     t          j        |          }t          |          dk     sJ dt          j        dk    rt          |          ndz  }t          j        |          }t          j        t          j	        |          
                                          }| j                            | j        ||          }| j                            | j        | d|          }t          j        |                    | j                  t          t%          j        d          |j        j        j                  |                    | j                  t          j        | j                  t          t%          j        d          d          g          }|S )z
        Same as serialize_object(), but don't create a global variable,
        simply return a literal for structure:
        {i8* data, i32 length, i8* hashbuf, i8* func_ptr, i32 alloc_flag}
        l        z.const.pickledata.%sr   DIFF_IRz.sha1r   )r   dumpsra   r	   rF  idr   make_bytearrayhashlibsha1digestr9   insert_unique_constr~   r   literal_structr  r   r   r   r   r   r!  get_null_value)	r   r?   r  r   bdatar?  arrhasharrstructs	            r   serialize_uncachedzPythonAPI.serialize_uncachedL  sG    s##4yy5    %FNa4G4GCYW&t,, 'T(:(:(A(A(C(CDDl..t{D%HH,22KD
 
 (KK%%RZ^^SX%5%;<<OODL))"4<00RZ^^Q''*   r   c                     	 | j         j        |         }ny# t          $ rl |                     |          }dt          j        dk    rt          |          ndz  }| j                            | j         ||          }|| j         j        |<   Y nw xY w|S )z
        Serialize the given object in the bitcode, and return it
        as a pointer to a
        {i8* data, i32 length, i8* hashbuf, i8* fn_ptr, i32 alloc_flag},
        structure constant (suitable for passing to unserialize()).
        z.const.picklebuf.%sr   rF  )	r~   r   r   rT  r	   rF  rH  r9   rM  )r   r?   gvrS  r   s        r   r  zPythonAPI.serialize_objecti  s    	/)#.BB 	/ 	/ 	/,,S11F(v~7J7JBsGGGPYZD11$+tVLLB,.DK$S)))	/ 	s    A3B
Bc                 Z    t          j        | j        |                                           S r   )r   rm   r:   r   r   s    r   c_api_errorzPythonAPI.c_api_errorz  s#    "4<1B1B1D1DEEEr   c                     ddl m} t                              |j        |          }t          | j        | j        |           } ||||          S )zn
        Unbox the Python object as the given Numba type.
        A NativeValue instance is returned.
        r   )unbox_unsupported)numba.core.boxingrZ  	_unboxersr&   	__class__r<   r9   r:   )r   r3   r?   rZ  implcs         r   r>   zPythonAPI.to_native_value}  sW    
 	877777/@AA$,d;;tCa   r   c                 |    t          |t          j                  r
J d            |                     |||          }|S )Nz;callconv should have prevented the return of optional value)rV   r   Optionalr0   )r   r3   r4   r1   outs        r   from_native_returnzPythonAPI.from_native_return  sS    c5>22 	E 	E 5E 	E 	E 	E $$S#{;;
r   c                     ddl m} t                              |j        |          }t          | j        | j        | |          } ||||          S )z
        Box the native value of the given Numba type.  A Python object
        pointer is returned (NULL if an error occurred).
        This method steals any native (NRT) reference embedded in *val*.
        r   )box_unsupported)r[  re  _boxersr&   r]  r,   r9   r:   )r   r3   r4   r1   re  r^  r_  s          r   r0   zPythonAPI.from_native_value  sV     	655555~~cm_==dlD+FFtCa   r   c                 6   t                               |j                  }|t          j        S t          j        | j        t          j                  }t          | j        | j        | ||          } ||||           | j        	                    |j
                  S )z
        Reflect the native value onto its Python original, if any.
        An error bit (as an LLVM value) is returned.
        )_reflectorsr&   r]  r   rP   rG  r:   rB   r9   rp   rE   )r   r3   r4   r1   r^  rE   r_  s          r   rJ   zPythonAPI.reflect_native_value  s    
 !!#-00<$$,T\7;LMMDL$,k$& &S#q|  ,,,r   c                     t          j        | j                            |                    }| j                            | j        ||          }t          |          S )zy
        Extract the generator structure pointer from a generator *obj*
        (a _dynfunc.Generator instance).
        )r   r   r9   get_data_typeget_generator_stater:   rM   )r   r?   r3   
gen_ptr_tyrO   s        r   to_native_generatorzPythonAPI.to_native_generator  sL    
 ^DL$>$>s$C$CDD
00sJOO5!!!r   c           	         | j                             |          }|j        rJ | j                             |          }| j                             |          }t          j        | j        | j        | j        | j        g          }|                     ||j	                  }t          j        t          j
                    | j        g          }	|j        r|                     |	|j                  }
n"t          t          j        |	          d          }
t          j        | j        | j        | j        t          j        |          t          j        |	          | j        g          }|                     |d          }t          | j        |          }| j                            || j                  }||                                 }| j                            || j                  }| j                            |||||
|f          S )z
        Make a Numba generator (a _dynfunc.Generator instance) from a
        generator structure pointer *val*.
        *env* is an optional _dynfunc.Environment instance to be wrapped
        in the generator.
        r   Nnumba_make_generator)r9   rj  
is_pointerget_abi_sizeofget_generator_descr   r   rk   r   llvm_cpython_wrapper_namer   r   has_finalizerllvm_finalizer_namer   r   r   r:   r  r   r   )r   r4   r3   rX   lltygen_struct_sizegendescgenfntygenfnfinalizerty	finalizerr   r   
state_sizeinitial_states                  r   from_native_generatorzPythonAPI.from_native_generator  s    |))#..?""",55d;;,11#66 /$*tz4:tz.RSS""71R"SS obkmmdl^DD 	D**;W=X*YYII !<!<dCCI tzDO,0L,.N7,C,C,.N;,G,G,0L	,: ; ;
 +ABBdo??
,,S$,??;&&((Cl""355|  ",mUIs!SU U 	Ur   c                 l   | j         j        rJ t          j        t          j        d          | j        | j        g          }|                     |d          }|j        d         	                    d           |j        d         	                    d           | j
                            |||f          S )Nr   numba_adapt_ndarrayr   r   r  r  r  r   s        r   numba_array_adaptorzPythonAPI.numba_array_adaptor  s    <****rz"~~
DL/IJJ+@AA

  ---

  ---|  c3Z000r   c                 r   t          j        t          j                    t          j        | j                  | j        g          }|                     |d          }|j        d                             d           |j        d                             d           | j	        
                    |||f          S )Nnumba_adapt_bufferr   r   r  r  )r   r   r   r   r   r   r   r   r   r:   r   r$  s        r   numba_buffer_adaptorzPythonAPI.numba_buffer_adaptor  s    r{}} nT-=>>MO O+?@@

  ---

  ---|  c3Z000r   c                     t          j        t          j        d          | j        |j        g          }|                     |d          }| j                            |||g          S )Nr   numba_complex_adaptorr   )r   r   r   rk   r   r   r:   r   )r   r  cmplxr   r   s        r   complex_adaptorzPythonAPI.complex_adaptor  sY    rz"~~
EJ/GHH+BCC|  dE]333r   c                     t          j        | j        | j        t          j        | j                  g          }|                     |d          }| j                            |||g          S )Nnumba_extract_record_datar   )	r   r   r   rk   r   r   r   r:   r   r   r?   pbufr   r   s        r   extract_record_datazPythonAPI.extract_record_data  se    t| $
BN4;K,L,LMO O+FGG|  c4[111r   c                     t          j        t          j        d          | j        t          j        | j                  g          }|                     |d          }| j                            |||g          S )Nr   numba_get_bufferr   )	r   r   r   rk   r   r   r   r:   r   r  s        r   
get_bufferzPythonAPI.get_buffer  sk    rz"~~ $
BN4;K,L,LMO O+=>>|  c4[111r   c                     t          j        t          j                    t          j        | j                  g          }|                     |d          }| j                            ||g          S )Nnumba_release_bufferr   )r   r   r   r   r   r   r:   r   )r   r  r   r   s       r   release_bufferzPythonAPI.release_buffer  s\    r{}}r~d>N/O/O.PQQ+ABB|  dV,,,r   c                     t          j        t          j        d          | j        g          }|                     |d          }| j                            ||g          S )N@   numba_extract_np_datetimer   r:  r   s       r   extract_np_datetimezPythonAPI.extract_np_datetime  sR    rz"~~
|<<+FGG|  cU+++r   c                     t          j        t          j        d          | j        g          }|                     |d          }| j                            ||g          S )Nr  numba_extract_np_timedeltar   r:  r   s       r   extract_np_timedeltazPythonAPI.extract_np_timedelta	  sR    rz"~~
|<<+GHH|  cU+++r   c                 H   t          t          j        d          t          |                    }t          j        | j        t          j        d          t          j        d          g          }|                     |d          }| j                            |||g          S )Nr   r  numba_create_np_datetimer   	r   r   r   r   r   rk   r   r:   r   r   r4   	unit_coder   r   s        r   create_np_datetimezPythonAPI.create_np_datetime  s}    RZ^^S^^<<	tzBJrNNBJrNN+KLL+EFF|  c9%5666r   c                 H   t          t          j        d          t          |                    }t          j        | j        t          j        d          t          j        d          g          }|                     |d          }| j                            |||g          S )Nr   r  numba_create_np_timedeltar   r  r  s        r   create_np_timedeltazPythonAPI.create_np_timedelta  s}    RZ^^S^^<<	tzBJrNNBJrNN+KLL+FGG|  c9%5666r   c                 l   t          j        | j        t          j        t          j        d                    t          j        d          | j        g          }|                     |d          }|                    |                    |                    }| j        	                    ||||g          S )Nr{   r   numba_recreate_recordr   )
r   r   rk   r   r   r   ru   re   r:   r   )r   pdatar  dtyper1   r   r   	dtypeaddrs           r   recreate_recordzPythonAPI.recreate_record  s    tzBN2:a==,I,I,.JrNNDJ,H I I+BCC**;+@+@+G+GHH	|  eT9%=>>>r   c                     | j                             | j        |          }| j                             t          j        t          |                    }|                     ||          S r   )r9   r   r~   r  r   r   ra   r  )r   r  r!  szs       r   string_from_constant_stringz%PythonAPI.string_from_constant_string!  sP    |//VDD\&&uz3v;;??//b999r   c           	         | j         }| j                            |||          }|j        j        }|j        }||k    r!t
                              d| d| d          | j                            ||j        ||          \  }}	t          j
        |t          j        d          }
| j                            |j                  }t          j
        ||d          }|                    |j                  5 \  }}|5  |                    |j        |
           | j        j                            || |           ddd           n# 1 swxY w Y   |5  t%          j        | j        ||||	          }	|                    |	|           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |                    |
          }|                    |          }	||	fS )aP  Calls into Numba jitted code and propagate error using the Python
        calling convention.

        Parameters
        ----------
        func : function
            The Python function to be compiled. This function is compiled
            in nopython-mode.
        sig : numba.typing.Signature
            The function signature for *func*.
        args : Sequence[llvmlite.binding.Value]
            LLVM values to use as arguments.

        Returns
        -------
        (is_error, res) :  2-tuple of llvmlite.binding.Value.
            is_error : true iff *func* raised an exception.
            res : Returned value from *func* iff *is_error* is false.

        If *is_error* is true, this method will adapt the nopython exception
        into a Python exception. Caller should return NULL to Python to
        indicate an error.
        zmismatching signature z != z.
Trg   N)r:   r9   compile_subroutine	signaturer   errorsLoweringErrorcall_internal_no_propagatefndescr   rj   bool_tr   rl   rE   rD   r   raise_errorr   fix_returning_optionalrp   )r   r   sigr   r:   cres	got_rettyrettyr  r  is_error_ptrres_typeres_ptrhas_errno_errrE   s                   r   call_jit_codezPythonAPI.call_jit_code&  s   2 ,|..wcBBN.	 &&BBBBBB   l==T[#t
 
 *7GN$OOO<..s??%gxtDDD __V_-- 
	,1B'6 J Jfo|<<<&227D&IIIJ J J J J J J J J J J J J J J  , ,5L'3  c7+++, , , , , , , , , , , , , , ,
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, 
	, <<--ll7##}sZ   4F':=E7F'E	F'
E	F'4FF'F	F'F	F''F+.F+)Fr   r   )F)r   )r*   rR   )r'   r(   r)   r7   r   r   r   r   r   r   r   r   r   r   r   ro   r   r   r   r   r   r  r  
contextlibcontextmanagerr  r   r"  r$  r*  r/  r2  r7  r>  rA  rG  rK  rQ  rU  rY  r\  r`  rg  rk  rp  rs  rv  ry  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  rn   r  r  r  r  r"  r(  r-  r1  r5  r8  r;  rA  rN  rS  rW  rZ  r^  ra  re  rh  rm  rs  rz  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r!  r&  r   r*  r,  rC  r/  r2  r   r6  r9  r  rD  rT  r  rX  r>   rc  r0   rJ   rm  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r*   r   r   ry   ry      s4        
F F FB@ @ @ ?D*,   2% % %
% % %
, , ,N N N? ? ?	N 	N 	N) ) )
) ) )
5 5 5J J J	- 	- 	- 	-8 8 81 1 1- - -
7 7 7
4 4 4
 * * * *8	8 	8 	85 5 5
5 5 5
' ' '2 2 22 2 2	P 	P 	P 	PA A A> > >
 
 
 - - -
: : :/ / /
/ / /
/ / /
/ / /) ) )- - -C C CH H HF F FH H H
F 
F 
F
F 
F 
F  
1 1 1 1L L L LQ Q Q QQ Q Q QS S S ST T T TR R R RW W W WO O O OO O O OL L L LK K K KL L L LE E E E- - -
- - -
, , ,
- - -
- - -
, , ,- - -
9 9 9
- - -
- - -E E E.9 9 9, , ,
3 3 3
. . .
, , ,
1 1 1
6 6 61 1 1> > >1 1 1+ + +, , ,
I I I@ @ @1 1 1 13 3 3
, , ,
, , ,
6 6 6
E E E ( ( (<
 
 
, , ,) ) ). . .- - -
1 1 1
- - -0 0 0
+ + ++ + + +: : : :- - -, , ,
, , ,
' ' 'R0 0 0
, , ,
2 2 22 2 2
7 7 77 7 7
M M M
F F F
1 1 16 6 61 1 1/ / /9 9 9(+ + +<5 5 5/ / /; ; ;5 5 5- - -, , ,
  
3 3 34 4 4
- - -A A A*4 4 4(. . .. . .1 1 11 1 1G G G/ / /     
  # # #* * *    7 7 7< < <  :  "F F F	! 	! 	!  ! ! ! !- - - - " " "'U 'U 'U 'UR1 1 11 1 14 4 4
2 2 22 2 2- - -
, , ,
, , ,
7 7 77 7 7? ? ?: : :
; ; ; ; ;r   ry   c                   4    e Zd ZdZd Zd Zed             ZdS )ObjModeUtilszHInternal utils for calling objmode dispatcher from within NPM code.
    c                     || _         d S r   )r/   )r   r/   s     r   r   zObjModeUtils.__init__g  s    


r   c                    | j         j        }| j         j        }|j        }t	          j        || j         j        |                    d                    }|j        	                    d           |_
        d|_        |                    d          }t          j        |j                  r| j                             |j        t#          |          f          }| j                             |          }	t'          j        ||	          }
|                    |
          5  |                    |           d d d            n# 1 swxY w Y   |                    |          }|                    t'          j        ||                    5  t          j        |j                  rt          |           }| j                             | j                             |j                            }| j                             ||	g          }| j                             |           | j                             |	           nL|j                            t#          |                    }|                    |t;          |          d          }| j                             |           |                    ||           d d d            n# 1 swxY w Y   |                    |           |                     |           |                    |          }|S )Ncached_objmode_dispatcherr   internalrD  with_objectmode)info)!r/   r:   r9   r~   r   GlobalVariablerk   get_unique_namer   r   initializerlinkagerH  r   is_serialiable
dispatcherr  r   r  r   r   rJ  rF  rp   _call_objmode_dispatcherrs  r   compileadd_dynamic_addrrH  r   rD   rK  )r   r   r   r:   tyctxmrV  rD  serialized_dispatchercompile_argsfailed_unsercachedr%   compilerrq  entry_pts                   r   load_dispatcherzObjModeUtils.load_dispatcherj  s5   *$
"N tz""#>??
 
 
 ..
 ++H55#DO44 		'$(J$?$?%//2% %!  :112GHHL"?7LAAL.. ' 'v&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' b!!__W_Wf==>> 	& 	&'88 4jj:11J//0LMM  99|n  
!!(+++
!!,////?225??CC//R\\0A 0   Jf%%%MM&"%%%'	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&* 	v'''b!!s%   D<<E E D-J==KKc                 :    | \  }}|                     |          }|S r   )r  )r  r  r   entrypts       r   r  z%ObjModeUtils._call_objmode_dispatcher  s$    +
H$$X..r   N)r'   r(   r)   r7   r   r  staticmethodr  r*   r   r   r  r  d  sX           5 5 5n   \  r   r  ).collectionsr   r  picklerJ  r]   llvmliter   llvmlite.irr   r   numbar   
numba.corer   r   r	   r
   r   r   r   r   PY_UNICODE_1BYTE_KINDr   PY_UNICODE_2BYTE_KINDr   PY_UNICODE_4BYTE_KINDr   PY_UNICODE_WCHAR_KINDobjectr   rf  r\  rh  r    r5   r@   rK   r,   r<   rB   rM   rT   rv   ry   r  r*   r   r   <module>r     s    " " " " " "       



                                           #8 "8 "8 "8        . )++IKK	ikk

H H H H H**]@B B H H H4 4 4 4 4JJ35 5 4 4 4K K K K Kjj!2#$ $ K K K&	 	 	 	 	& 	 	 	1! 1! 1! 1! 1! 1! 1! 1!h 
?,ABB@ @ @ @ @ @ @ @F.A A A A A A A A A Ar   