
    J/Ph                    f   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 d dlmZ ej        Zej        Zej        Zedv r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	serialize)	PYVERSION))   
   )r      c                   "    e Zd Zd Zd ZddZdS )	_Registryc                     i | _         d S N)	functionsselfs    T/var/www/html/test/jupyter/venv/lib/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__r9   r.   r   r   r0   r0   7   s9          IH H H H Hr   r0   )contextbuilderr3   r5   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   )r3   to_native_value)r   r7   objs      r   unboxz_UnboxContext.unboxI   s    z))#s333r   N)r+   r,   r-   r;   r<   rD   r.   r   r   r@   r@   B   s4          I4 4 4 4 4r   r@   )r=   r>   r3   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_errorV   s%    4='*:;;;;;r   c                 D    | j                             ||| j                  S r   r2   r6   s      r   r9   z_ReflectContext.boxY   r:   r   c                 D    | j                             ||| j                  S r   )r3   reflect_native_valuer5   r6   s      r   reflectz_ReflectContext.reflect\   s    z..sC9IJJJr   N)r+   r,   r-   r;   r<   rK   r9   rO   r.   r   r   rF   rF   M   sZ          I< < <H H HK K K K Kr   rF   )r=   r>   r3   r5   rI   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_bitrI   cleanup)r   rS   rI   rU   s       r   r   zNativeValue.__init__f   s'    
$,$8g>Or   NN)r+   r,   r-   r;   r   r.   r   r   rQ   rQ   `   s2         
     r   rQ   c                        e Zd Zd Zd Zd ZdS )EnvironmentManagerc                 v    t          |t          j                  sJ || _        || _        || _        || _        d S r   )
isinstancer
   Environmentr3   envenv_bodyenv_ptr)r   r3   r\   r]   r^   s        r   r   zEnvironmentManager.__init__n   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.
        )	rZ   strsysintern	enumerater\   constslenappend)r   constindexr8   s       r   	add_constzEnvironmentManager.add_constu   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`)re   r\   rd   r3   r>   r]   r   alloca_oncepyobjif_elseis_not_nulllist_getitemrH   err_set_stringload)r   rh   r>   rd   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   ri   ry   r.   r   r   rX   rX   l   sA            ! ! ! ! !r   rX   _IteratorLoop)rS   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 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                    | _        t6          j        r*| j                             t          j                  | _        n)| j                             t          j                   | _        t          j        t          j        d                    | _!        t          j        tD          j#        dz            | _$        t          j%        t          j        d          tD          j&                  | _'        | j        | _(        tD          j)        | _)        tD          j*        | _*        tD          j+        | _+        dS )zL
        Note: Maybe called multiple times when lowering a function
           N),r=   r>   basic_blockfunctionmodule_PythonAPI__serializedAttributeErrorget_argument_typer   pyobjectro   
as_pointerpyobjptrr   PointerTypeIntTypevoidptrctypessizeofc_longlongulongc_ulonglonglonglong	ulonglong
DoubleTypedoubler	   USE_LEGACY_TYPE_SYSTEMget_value_typeintp
py_ssize_tc_intp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)r   r=   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( 	H"l99%*EEDOO"l99%,GGDO~bjmm44J$@1$DEE<
1z7PQQ%/%E"%/%E"%/%E"""s   3 AAc                 &    t          | |||          S r   )rX   )r   r\   r]   r^   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
        rm   zmissing Environment: N)r   is_nullr>   if_unlikelyr   typepointeereturn_typero   rs   ru   get_null_objectr=   	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VoidTypero   _get_functionr>   callr   rC   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   ro   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   ro   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   ro   r   r   r   r   intrZ   r`   r=   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   ro   r   r   rZ   r`   get_c_objectr=   r   r   r>   r   )r   exctypemsgr   r   s        r   rs   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   ro   r   r   rZ   r`   r   r=   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   ro   r   	make_noner>   r   )r   excr   r   s       r   raise_objectzPythonAPI.raise_object5  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   ro   r   rZ   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_noneG  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_unraisableN  sP    r{}}tzl;;+BCC|  cV,,,r   c                     t          j        t          j                    | j        gdz            }|                     |d          }| j                            ||||f          S )Nr   PyErr_Fetchr   )r   r   r   r   r   r>   r   )r   ptypvalptbr   r   s         r   	err_fetchzPythonAPI.err_fetchS  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   tyr8   tbr   r   s         r   err_restorezPythonAPI.err_restoreX  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   rn   r>   ro   ).0ir   s     r   
<listcomp>z&PythonAPI.err_push.<locals>.<listcomp>e  s:     - - - "-dlDJGG - - -r   r   NFlikely)
ranger  r>   rt   r   rq   r   rp   r   r  )r   keep_newr  r	  r
  r  r8   r  	new_errorif_errorif_oks   `          r   err_pushzPythonAPI.err_push]  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)r=   get_c_valuer>   ro   r   )r   r   s     r   r   zPythonAPI.get_c_objectz  s3     |''dj6H$26 ( 8 8 	8r   c                 |    d|z  }| j                             | j        |          }|                     d|           d S )Nzglobal name '%s' is not definedPyExc_NameErrorr=   r   r   rs   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addr=   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   ro   r   r   r=   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 )r0  PyDict_GetItemr   r   )r   r2  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   ro   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   ro   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   ro   r   r   r=   r   r   r>   r   )r   r?  r   rA  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)r;  if_object_okrE  )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   ro   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   ro   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   rS  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   ro   r   r>   r   rX  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   r\  rX  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   ro   r   r>   r   rX  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   ro   r   r   rn   r>   rH   r   rt   )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   ro   r   r   r>   r   )r   rf  rg  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ri  )rk  r   r   rf  s     r   long_from_ulongzPythonAPI.long_from_ulong	  s.    ))$0I*.)E * C C 	Cr   c                 >    |                      |d| j        d          S )NPyLong_FromSsize_tTrr  )rk  r   rs  s     r   long_from_ssize_tzPythonAPI.long_from_ssize_t  s.    ))$0D*./$ * H H 	Hr   c                 >    |                      |d| j        d          S )NPyLong_FromLongLongTrr  )rk  r   rs  s     r   long_from_longlongzPythonAPI.long_from_longlong  s.    ))$0E*.- * F F 	Fr   c                 >    |                      |d| j        d          S )NPyLong_FromUnsignedLongLongFrr  )rk  r   rs  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   ro  r>   sextr   rz  OverflowErrorr   rf  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   rt  r>   zextr   r}  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   ro   r   )r   r   r   r   s       r   _get_number_operatorzPythonAPI._get_number_operator1  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_operator6  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_add<      ))%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_multiplyB  r  r   c                 4    |                      d|||          S )N
TrueDivider  r  r  s       r   number_truedividezPythonAPI.number_truedivideE  s    )),S')RRRr   c                 4    |                      d|||          S )NFloorDivider  r  r  s       r   number_floordividezPythonAPI.number_floordivideH  s    ))-c7)SSSr   c                 4    |                      d|||          S )N	Remainderr  r  r  s       r   number_remainderzPythonAPI.number_remainderK  s    ))+sC)QQQr   c                 4    |                      d|||          S )NMatrixMultiplyr  r  r  s       r   number_matrix_multiplyz PythonAPI.number_matrix_multiplyN  s     ))*:Cg)VVVr   c                 4    |                      d|||          S )NLshiftr  r  r  s       r   number_lshiftzPythonAPI.number_lshiftQ      ))(Cg)NNNr   c                 4    |                      d|||          S )NRshiftr  r  r  s       r   number_rshiftzPythonAPI.number_rshiftT  r  r   c                 4    |                      d|||          S )NAndr  r  r  s       r   
number_andzPythonAPI.number_andW  r  r   c                 4    |                      d|||          S )NOrr  r  r  s       r   	number_orzPythonAPI.number_orZ  s    ))$S')JJJr   c                 4    |                      d|||          S )NXorr  r  r  s       r   
number_xorzPythonAPI.number_xor]  r  r   c                     t          j        | j        | j        gdz            }|rdnd}|                     ||          }| j                            ||||                                 g          S )Nr   PyNumber_InPlacePowerPyNumber_Power)r   r   ro   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_negativef  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_positivek  r  r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )NPyNumber_Floatr   r   )r   r8   r   r   s       r   number_floatzPythonAPI.number_floatp  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_invertu  sL    tzDJ<88+<==|  cV,,,r   c                     t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )NPyFloat_AsDoubler   )r   r   r   ro   r   r>   r   )r   fobjr   r   s       r   float_as_doublezPythonAPI.float_as_doublez  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   rn  )r   rf  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   ro   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   ro   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   rn   r>   r   r   r   r   ro   r   r   r   rt   r   )r   rC   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   ro   r   r   r>   r   )r   rC   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   ro   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  r8   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   ro   r   r   r>   r   )r   r  idxr8   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   ro   r   r   rZ   r   r=   get_constantr   r   r>   r   )r   r  r  r   r   s        r   rr   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   ro   r   r   r>   r   )r   r  r  r  rC   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   ro   r   r   r=   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   ro   r   r   r=   r  r   r   re   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        | j        g          }|                     |d          }| j                            ||                     |          g          S )NPyTuple_Newr   r  )r   countr   r   s       r   	tuple_newzPythonAPI.tuple_new	  sY    tzDO+<===99|  dooe&<&<%=>>>r   c                    t          j        t          j        d          | j        | j        | j        g          }|                     |d          }|                     |          }| j                            ||||g           dS )z/
        Steals a reference to `item`.
        r   PyTuple_SetItemr   Nr  )r   	tuple_valrh   itemr   
setitem_fns         r   tuple_setitemzPythonAPI.tuple_setitem  s     rz"~~ $
DOTZHJ J''3D'EE
&&*y%&>?????r   c                     ||                                  }t          j        | j        | j        g          }|                     |d          }| j                            ||g          S )N	PySet_Newr   )r   r   r   ro   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   setrS   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   r3  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  r7  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   r3  r/  r   r   s        r   
set_updatezPythonAPI.set_update2  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   ro   r   r   r   r   r>   r   )r   r3  posptrkeyptrhashptrr   r   s          r   set_next_entryzPythonAPI.set_next_entry7  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 )NrC  r   rB  r   rA  bb_bodybb_endc                  2                                     d S r   )branch)rG  r>   s   r   r{   z'PythonAPI.set_iterate.<locals>.do_breakL  s    NN6"""""r   Fr  )r>   r   rn   r   ro   alloca_once_valuer   r   append_basic_blockrI  
goto_blockrD  r   if_thenrz   rt   position_at_end)r   r3  rC  rB  rA  rF  r{   rfinishedrG  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   rn   r>   r   )r   gilptrtyr   r   gilptrs        r   
gil_ensurezPythonAPI.gil_ensure]  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   gilrT  r   r   s        r   gil_releasezPythonAPI.gil_releasei  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_threads  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_thread|  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   rc  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   ro   r   r   r>   r   )r   rC   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_ImportModuler   r   r   ro   r   r   r>   r   )r   modnamer   r   s       r   import_modulezPythonAPI.import_module  sL    tzDL>::+BCC|  gY///r   c                 >   t          j        | j        | j        gd          }|                     |d          }|gt	          |          z   }|                    | j                            t          j	                             | j
                            ||          S )NTr   PyObject_CallFunctionObjArgsr   )r   r   ro   r   r   rf   r=   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)r=   r   r   r   r   ro   r   r   re   r  rf   rs  r   r   r>   r   )
r   rt  methodru  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                 F   |d u x}r|                      d          }||                                 }t          j        | j        | j        gdz            }|                     |d          }| j                            ||||f          }|r|                     |           |S )Nr   r   PyObject_Callr   )	r&  r   r   r   ro   r   r>   r   r   )r   rt  r   r   args_was_noner   r   results           r   r   zPythonAPI.call  s     DL(= 	%>>!$$D;&&((CtzDJ<!+;<<?;;""2c':;; 	KKr   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)rh   r   r   ro   r   r   r=   r  r   int32r>   r   icmp_unsignedr  r   rJ  r   	if_likelynot_truncrH   rt   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   )
r=   r   r   r   r   ro   r   r   r>   r   )r   rC   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   rC   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   )r=   r   r   r   r   r   ro   r   r   r>   r   )r   rC   r  r8   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   rC   r  r8   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   rC   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   rC   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   rC   r  r8   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_delitem6  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   ro   r   r>   r   )r   strobjr   r  r   s        r   string_as_stringzPythonAPI.string_as_string>  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   rn   r>   r   r   r   r   ro   r   r   r   r  r   r   rt   )r   r  p_lengthr   r  r   bufferoks           r   string_as_string_and_sizez#PythonAPI.string_as_string_and_sizeD  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   rn   r>   r   r   r   r   r   r   ro   r   r   r   r  r   r   rt   )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_kindX  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   ro   r   r   r   r>   r   r   stringsizer   r  r   s         r   string_from_string_and_sizez%PythonAPI.string_from_string_and_sizev  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   rn  )r   r  r   r  r   s        r   string_from_stringzPythonAPI.string_from_string|  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   ro   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        g          }d}|                     ||          }| j                            ||g          S )NPyBytes_AsStringr   r  r   rC   r   r  r   s        r   bytes_as_stringzPythonAPI.bytes_as_string  sP    t|dj\::"511|  cU+++r   c                    t          j        t          j        d          | j        | j                                        | j                                        g          }d}|                     ||          }| j        	                    ||||g          }| j        
                    dt          |j        d          |          }|S )Nr   PyBytes_AsStringAndSizer   r  r  )r   r   r   ro   r   r   r   r   r>   r   icmp_signedr   r   )	r   rC   p_bufferr  r   r  r   r  r  s	            r   bytes_as_string_and_sizez"PythonAPI.bytes_as_string_and_size  s    JrNNZ0022DO4N4N4P4PQ
 
 *511""2Xx'@AA\%%dHV[",E,EvNN	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   ro   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   rC   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)r=   
enable_nrtr   r   unserializeserialize_objectbox_typer   ro   r   r   r   add_attributer  r   r  ndimr   mutabler   rJ  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   dataro   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   ro   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  ro   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  r=   r  r   r   r   ro   r   r   r   r  r>   r   r   r  rg  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  )r=   r  r   r   r   r   r   r   r   r   r  r>   r   r   bufrg  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>   allocaro   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   rJ  r>   r   r   )r   rg  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>   rq   r   s     r   rG  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  r=   r   r   r  r   )r   rC   r  r%  r   s        r   print_objectzPythonAPI.print_object0  sm    %%$$V,,l..t{DAAc4(((Fr   c                 p    | j                             | j        |          }|                     |           d S r   )r=   r   r   r  )r   textr   s      r   print_stringzPythonAPI.print_string7  s5    l..t{DAAc"""""r   c                 ,    t          | j        d           S r   )r   ro   r   s    r   r   zPythonAPI.get_null_object;  s    
D)))r   c                 b    |                                  }| j                            |           d S r   )r   r>   ru   )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   )
re   r  r=   r  r   r   rG  r  r   r  )r   r  r  seqr  r  s         r   	list_packzPythonAPI.list_packB  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   ro   r   r   r   r>   extract_valuert   r   )r   	structptrr   r   rg  r  hasheds          r   r  zPythonAPI.unserializeL  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_structZ  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   dumpsre   r	   rV  idr   make_bytearrayhashlibsha1digestr=   insert_unique_constr   r   literal_structr  r   r   r   r   r   r%  get_null_value)	r   rC   r"  r   bdatarO  arrhasharrstructs	            r   serialize_uncachedzPythonAPI.serialize_uncachedd  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   rV  )	r   r   r   rd  r	   rV  rX  r=   r]  )r   rC   gvrc  r   s        r   r  zPythonAPI.serialize_object  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   rq   r>   r   r   s    r   c_api_errorzPythonAPI.c_api_error  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.boxingrj  	_unboxersr*   	__class__r@   r=   r>   )r   r7   rC   rj  implcs         r   rB   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)rZ   r   Optionalr4   )r   r7   r8   r5   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)rk  ru  _boxersr*   rm  r0   r=   r>   )r   r7   r8   r5   ru  rn  ro  s          r   r4   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*   rm  r   rT   rJ  r>   rF   r=   rt   rI   )r   r7   r8   r5   rn  rI   ro  s          r   rN   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   r=   get_data_typeget_generator_stater>   rQ   )r   rC   r7   
gen_ptr_tyrS   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)r=   rz  
is_pointerget_abi_sizeofget_generator_descr   r   ro   r   llvm_cpython_wrapper_namer   r   has_finalizerllvm_finalizer_namer   r   r   r>   r  r   r   )r   r8   r7   r\   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/  r0  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   r4  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   ro   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   ro   r   r   r   r>   r   r   rC   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   ro   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   ro   r   r>   r   r   r8   	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   ro   r   r   r   ry   ri   r>   r   )r   pdatar  dtyper5   r   r   	dtypeaddrs           r   recreate_recordzPythonAPI.recreate_record2  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   )r=   r   r   r  r   r   re   r  )r   r  r%  szs       r   string_from_constant_stringz%PythonAPI.string_from_constant_string9  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.
Trk   N)r>   r=   compile_subroutine	signaturer   errorsLoweringErrorcall_internal_no_propagatefndescr   rn   bool_tr   rp   rI   rH   r   raise_errorr   fix_returning_optionalrt   )r   r   sigr   r>   cres	got_rettyrettyr  r  is_error_ptrres_typeres_ptrhas_errno_errrI   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.   rV   )r+   r,   r-   r;   r   r   r   r   r   r   r   r   r   r   r   rs   r   r   r   r  r  r  r  
contextlibcontextmanagerr  r   r&  r(  r.  r3  r6  r;  rB  rE  rK  rO  rU  rY  r]  r`  rd  rk  ro  rt  rw  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  rr   r  r  r  r"  r&  r,  r0  r4  r8  r;  r>  rD  rQ  rV  rZ  r]  ra  rd  rh  rk  rp  rv  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,  r1  r6  r   r:  r<  rG  r?  rB  r   rF  rI  r  rT  rd  r  rh  rB   rs  r4   rN   r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r.   r   r   r}   r}      sO        
!F !F !FF@ @ @ ?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+ + +, , ,
? ? ?
@ @ @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   r}   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   )r3   )r   r3   s     r   r   zObjModeUtils.__init__  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   internalrG  with_objectmode)info)!r3   r>   r=   r   r   GlobalVariablero   get_unique_namer   r   initializerlinkagerK  r   is_serialiable
dispatcherr  r   r  r   r   rM  rI  rt   _call_objmode_dispatcherrv  r   compileadd_dynamic_addrrX  r   rH   rN  )r   r   r   r>   tyctxmrf  rG  serialized_dispatchercompile_argsfailed_unsercachedr)   compilerrt  entry_pts                   r   load_dispatcherzObjModeUtils.load_dispatcher  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-   r;   r   r  staticmethodr  r.   r   r   r  r  |  sX           5 5 5n   \  r   r  )0collectionsr   r  picklerZ  ra   llvmliter   llvmlite.irr   r   numbar   
numba.corer   r   r	   r
   r   r   r   numba.core.utilsr   r   PY_UNICODE_1BYTE_KINDr   PY_UNICODE_2BYTE_KINDr   PY_UNICODE_4BYTE_KINDpy_unicode_wchar_kindPY_UNICODE_WCHAR_KINDobjectr   rv  rl  rx  r$   r9   rD   rO   r0   r@   rF   rQ   rX   rz   r}   r  r.   r   r   <module>r     s   " " " " " "       



                                           ' & & & & &"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V V V V V V V Vr.A A A A A A A A A Ar   