
    xKg                    P   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j2                  Zej6                  Zedv rej:                  Z G d	 d
e      Z  e        Z! e        Z" e        Z#e!jH                  Z%e"jH                  Z&e#jH                  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/y)    )
namedtupleN)ir)Constant)
_helperlib)typesutilsconfigloweringcgutilsimputils	serialize)	PYVERSION))   	   )r   
   )r      c                        e Zd Zd Zd ZddZy)	_Registryc                     i | _         y N)	functionsselfs    X/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/core/pythonapi.py__init__z_Registry.__init__   s	        c                 N     t        t        j                        sJ  fd}|S )Nc                 ^    j                   v rt        d      | j                   <   | S )Nzduplicate registration for )r   KeyError)funcr   	typeclasss    r   	decoratorz%_Registry.register.<locals>.decorator   s0    DNN*)MNN(,DNN9%Kr   )
issubclassr   Type)r   r!   r"   s   `` r   registerz_Registry.register   s$    )UZZ000	
 r   Nc                     t        |t        j                        sJ |j                  D ]#  }| j                  j                  |      }|!|c S  |S r   )r#   r   r$   __mro__r   get)r   r!   defaultclsr    s        r   lookupz_Registry.lookup&   sL    )UZZ000$$C>>%%c*D % r   r   )__name__
__module____qualname__r   r%   r+    r   r   r   r      s    r   r   c                       e Zd ZdZdZd Zy)_BoxContextz<
    The facilities required by boxing implementations.
    r/   c                 P    | j                   j                  ||| j                        S r   pyapifrom_native_valueenv_managerr   typvals      r   boxz_BoxContext.box>   !    zz++Cd6F6FGGr   N)r,   r-   r.   __doc__	__slots__r:   r/   r   r   r1   r1   7   s     IHr   r1   )contextbuilderr4   r6   c                       e Zd ZdZdZd Zy)_UnboxContextz>
    The facilities required by unboxing implementations.
    r/   c                 :    | j                   j                  ||      S r   )r4   to_native_value)r   r8   objs      r   unboxz_UnboxContext.unboxI   s    zz))#s33r   N)r,   r-   r.   r<   r=   rE   r/   r   r   rA   rA   B   s     I4r   rA   )r>   r?   r4   c                   &    e Zd ZdZdZd Zd Zd Zy)_ReflectContextz@
    The facilities required by reflection implementations.
    r/   c                 l    | j                   j                  | j                  t        j                         y r   )r?   storeis_errorr   true_bitr   s    r   	set_errorz_ReflectContext.set_errorV   s     4=='*:*:;r   c                 P    | j                   j                  ||| j                        S r   r3   r7   s      r   r:   z_ReflectContext.boxY   r;   r   c                 P    | j                   j                  ||| j                        S r   )r4   reflect_native_valuer6   r7   s      r   reflectz_ReflectContext.reflect\   s!    zz..sC9I9IJJr   N)r,   r-   r.   r<   r=   rL   r:   rP   r/   r   r   rG   rG   M   s     I<HKr   rG   )r>   r?   r4   r6   rJ   c                       e Zd ZdZddZy)NativeValuez
    Encapsulate the result of converting a Python object to a native value,
    recording whether the conversion was successful and how to cleanup.
    Nc                 R    || _         ||nt        j                  | _        || _        y r   )valuer   	false_bitrJ   cleanup)r   rT   rJ   rV   s       r   r   zNativeValue.__init__f   s$    
$,$8g>O>Or   NN)r,   r-   r.   r<   r   r/   r   r   rR   rR   `   s    
r   rR   c                       e Zd Zd Zd Zd Zy)EnvironmentManagerc                 t    t        |t        j                        sJ || _        || _        || _        || _        y r   )
isinstancer
   Environmentr4   envenv_bodyenv_ptr)r   r4   r]   r^   r_   s        r   r   zEnvironmentManager.__init__n   s4    #x33444
 r   c                 4   t        |t              rt        j                  |      }t	        | j
                  j                        D ]  \  }}||u s |S  t        | j
                  j                        }| j
                  j                  j                  |       |S )zF
        Add a constant to the environment, return its index.
        )	r[   strsysintern	enumerater]   constslenappend)r   constindexr9   s       r   	add_constzEnvironmentManager.add_constu   sw    
 eS!JJu%E#DHHOO4JE3e|  5 (EHHOO""5)r   c                    |t        | j                  j                        k  sJ | j                  j                  }| j
                  j                  }t        j                  || j                  j                  d      }|j                  t        j                  ||            5 \  }}|5  | j                  j                  ||      }|j                  ||       ddd       |5  | j                  j                  dd       ddd       ddd       |j                  |      S # 1 sw Y   IxY w# 1 sw Y   .xY w# 1 sw Y   2xY w)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`)rf   r]   re   r4   r?   r^   r   alloca_oncepyobjif_elseis_not_nulllist_getitemrI   err_set_stringload)r   ri   r?   re   retbr_not_nullbr_nullgetitems           r   
read_constzEnvironmentManager.read_const   s     s488??++++**$$%%!!'4::+;+;4H__W00&AB&g**11&%@gs+   

))(:  C ||C     CBs<   "D7(/D
D7!D+>D7D(	$D7+D4	0D77E N)r,   r-   r.   r   rj   rz   r/   r   r   rY   rY   l   s    !r   rY   _IteratorLoop)rT   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j0                  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/d- Z0d. Z1d/ Z2dd0Z3dd1Z4dd2Z5dd3Z6dd4Z7dd5Z8dd6Z9dd7Z:dd8Z;dd9Z<dd:Z=dd;Z>dd<Z?dd=Z@d> ZAd? ZBd@ ZCdA ZDdB ZEdC ZFdD ZGdE ZHdF ZIdG ZJdH ZKdI ZLdJ ZMdK ZNdL ZOdM ZPdN ZQdO ZRdP ZSdQ ZTdR ZUdS ZVdT ZWdU ZXdV ZYddWZZdX Z[dY Z\dZ Z]d[ Z^d\ Z_ej0                  d]        Z`d^ Zad_ Zbd` Zcda Zddb Zedc Zfdd Zgde Zhdf ZiddgZjddhZkdi Zldj Zmdk Zndl Zodm Zpdn Zqdo Zrdp Zsdq Ztdr Zuds Zvdt Zwdu Zxdv Zydw Zzdx Z{dy Z|dz 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j0                  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 Zy)	PythonAPIz^
    Code generation facilities to call into the CPython C API (and related
    helpers).
    c                 `   || _         || _        |j                  j                  j                  | _        	 | j                  j
                   | j                   j                  t        j                        | _
        | 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        j2                         | _        | j                   j7                  t        j8                        | _        t        j                  t        j                  d            | _        t        j                  t>        j@                  dz        | _!        t        jD                  t        j                  d      t>        jF                        | _$        | j:                  | _%        t>        jL                  | _&        t>        jN                  | _'        t>        jP                  | _(        y# t        $ r i | j                  _        Y aw xY w)zL
        Note: Maybe called multiple times when lowering a function
           N))r>   r?   basic_blockfunctionmodule_PythonAPI__serializedAttributeErrorget_argument_typer   pyobjectrp   
as_pointerpyobjptrr   PointerTypeIntTypevoidptrctypessizeofc_longlongulongc_ulonglonglonglong	ulonglong
DoubleTypedoubleget_value_typeintp
py_ssize_tcstringr   py_gil_state_size	gil_state	ArrayTypepy_buffer_sizepy_buffer_t	py_hash_tpy_unicode_1byte_kindpy_unicode_2byte_kindpy_unicode_4byte_kind)r   r>   r?   s      r   r   zPythonAPI.__init__   s    ))2299	*KK$$
 \\33ENNC


--/~~bjjm4JJv}}V]];a?@	YY


6==1C1C#Dq#HImmo,,55ejjA~~bjjm4J$@$@1$DE<<

1z7P7PQ%/%E%E"%/%E%E"%/%E%E"'  	*')DKK$	*s   J J-,J-c                     t        | |||      S r   )rY   )r   r]   r^   r_   s       r   get_env_managerzPythonAPI.get_env_manager   s    !$Xw??r   c                 ,   t        j                  | j                  |      }t        j                  | j                  |      5  |r| j                  j                  j
                  j                  }|j                  | j                  k(  sJ | j                  dd|        | j                  j                  | j                                n9| j                  j                  j                  | j                  t        d| f       ddd       y# 1 sw Y   yxY w)z;Emits LLVM code to ensure the `envptr` is not NULL
        rn   zmissing Environment: N)r   is_nullr?   if_unlikelyr   typepointeereturn_typerp   rt   rv   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  w7||,,1199''4::555##(,A)*M   !5!5!78&&66LL,,YK8: 877s   C D

Dc                     t        j                  t        j                         | j                  g      }| j	                  |d      }| j
                  j                  ||g       y )N	Py_IncRefnamer   FunctionTypeVoidTyperp   _get_functionr?   callr   rD   r   fns       r   increfzPythonAPI.incref   I    r{{}tzzl;;7"se$r   c                     t        j                  t        j                         | j                  g      }| j	                  |d      }| j
                  j                  ||g       y )N	Py_DecRefr   r   r   s       r   decrefzPythonAPI.decref   r   r   c                     t        j                  | j                  | j                  g      }| j                  |d      }| j                  j                  ||g      S )Nnumba_py_typer   r   r   rp   r   r?   r   r   s       r   get_typezPythonAPI.get_type   sJ    tzzDJJ<8?;||  cU++r   c                    t        j                  t        j                  d            }t        j                  |      }| j                  | j                  ||g}t        j                  t        j                  d      |d      }	| j                  |	d      }
| j                  j                  |
||||gt        |      z         S )Nr       Tvar_argPyArg_ParseTupleAndKeywordsr   	r   r   r   rp   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,
JJ

GZ@rzz"~xF+HI||  dCh%?$t*%LMMr   c                 >   t        j                  t        j                  d            }| j                  |g}t        j                  t        j                  d      |d      }| j                  |d      }| j                  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   sz    ..A/JJ(rzz"~xF+=>||  dC[4:%=>>r   c                 j   t        j                  t        j                  d            }| j                  || j                  | j                  g}t        j
                  t        j                  d      |d      }| j                  |d      }	t        | j                  t        |            }t        | j                  t        |            }t        |t              r0| j                  j                  | j                  j                  |      }| j                  j                  |	||||gt!        |      z         S )Nr   r   Tr   PyArg_UnpackTupler   )r   r   r   rp   r   r   r   r   intr[   ra   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/JJ$//Jrzz"~xF+>?#e*5#e*5dC <<33DLL4G4GND||  dD%%?$t*%LMMr   c                     t        j                  | j                  d      }| j                  |d      }| j                  j                  |d      S )Nr/   PyErr_Occurredr   r   r   r   r   s      r   err_occurredzPythonAPI.err_occurred  sC    tzz2.+;<||  R((r   c                     t        j                  t        j                         d      }| j                  |d      }| j                  j                  |d      S )Nr/   PyErr_Clearr   )r   r   r   r   r?   r   r   s      r   	err_clearzPythonAPI.err_clear  sD    r{{}b1=9||  R((r   c                    t        j                  t        j                         | j                  | j                  g      }| j                  |d      }t        |t              r| j                  |      }t        |t              r&| j                  j                  | j                  |      }| j                  j                  |||f      S )NPyErr_SetStringr   )r   r   r   rp   r   r   r[   ra   get_c_objectr>   r   r   r?   r   )r   exctypemsgr   r   s        r   rt   zPythonAPI.err_set_string   s    r{{}tzz4<<.HI+<=gs#''0Gc3,,224;;DC||  gs^44r   c                    t        j                  t        j                         | j                  | j                  gd      }| j                  |d      }t        |t              r| j                  |      }t        |t              r&| j                  j                  | j                  |      }| j                  j                  |||ft        |      z         S )NTr   PyErr_Formatr   )r   r   r   rp   r   r   r[   ra   r   r>   r   r   r?   r   tuple)r   r   r   format_argsr   r   s         r   
err_formatzPythonAPI.err_format)  s    r{{}tzz4<<.HRVW>:gs#''0Gc3,,224;;DC||  gs^eK6H%HIIr   Nc                     t        j                  t        j                         | j                  g      }| j	                  |d      }|| j                         }| j                  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   rp   r   	make_noner?   r   )r   excr   r   s       r   raise_objectzPythonAPI.raise_object2  s`    
 r{{}tzzl;+;<;.."C||  cV,,r   c                 "   t        j                  t        j                         | j                  | j                  g      }| j	                  |d      }t        |t              r| j                  |      }| j                  j                  |||f      S )NPyErr_SetObjectr   
r   r   r   rp   r   r[   ra   r   r?   r   )r   r   excvalr   r   s        r   err_set_objectzPythonAPI.err_set_object=  sq    r{{}tzz4::.FG+<=gs#''0G||  gv%677r   c                 
   t        j                  t        j                         | j                  g      }| j	                  |d      }t        |t              r| j                  |      }| j                  j                  ||f      S )NPyErr_SetNoner   r   )r   r   r   r   s       r   err_set_nonezPythonAPI.err_set_noneD  sf    r{{}tzzl;?;gs#''0G||  gZ00r   c                     t        j                  t        j                         | j                  g      }| j	                  |d      }| j
                  j                  ||f      S )NPyErr_WriteUnraisabler   r   r   s       r   err_write_unraisablezPythonAPI.err_write_unraisableK  sM    r{{}tzzl;+BC||  cV,,r   c                     t        j                  t        j                         | j                  gdz        }| j	                  |d      }| j
                  j                  ||||f      S )Nr   PyErr_Fetchr   )r   r   r   r   r   r?   r   )r   ptypvalptbr   r   s         r   	err_fetchzPythonAPI.err_fetchP  sV    r{{}t}}o.AB=9||  c4%566r   c                     t        j                  t        j                         | j                  gdz        }| j	                  |d      }| j
                  j                  ||||f      S )Nr   PyErr_Restorer   r   )r   tyr9   tbr   r   s         r   err_restorezPythonAPI.err_restoreU  sU    r{{}tzzlQ.>??;||  b#r]33r   c              #   J  K   t        d      D cg c],  }t        j                  | j                  | j                        . c}\  }}}| j                  |||       d | j                  j                  |      }| j                  j                  |      }| j                  j                  |      }|rt        j                  | j                  | j                               }	| j                  j                  |	d      5 \  }
}|
5  | j                  |       | j                  |       | j                  |       ddd       |5  | j                  |||       ddd       ddd       y| j                  |||       yc c}w # 1 sw Y   IxY w# 1 sw Y   7xY w# 1 sw Y   yxY ww)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.
        r   NFlikely)ranger   ro   r?   rp   r	  ru   rr   r   rq   r   r  )r   keep_newir  r  r  r  r9   r  	new_errorif_errorif_oks               r   err_pushzPythonAPI.err_pushZ  sR     $)8-#+a "--dllDJJG#+-T3sD#&\\s#ll%\\s#++DLL$:K:K:MNI%%i%>BS8UKKOKK$KKO	 
 $$Rb1  ?> Rb)'- X
 U ?>sY   F#1E:B<F#=F4E?7
FFF"F#?F	FF	FF F#c                 |    | j                   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?   rp   r   )r   r   s     r   r   zPythonAPI.get_c_objectw  s7     ||''djj6H6H$26 ( 8 	8r   c                 ~    d|z  }| j                   j                  | j                  |      }| j                  d|       y )Nzglobal name '%s' is not definedPyExc_NameErrorr>   r   r   rt   r   r   r   cstrs       r   raise_missing_global_errorz$PythonAPI.raise_missing_global_error  s7    /$6||//SA-t4r   c                 ~    d|z  }| j                   j                  | j                  |      }| j                  d|       y )Nzname '%s' is not definedr  r  r  s       r   raise_missing_name_errorz"PythonAPI.raise_missing_name_error  s7    (4/||//SA-t4r   c                 L   t        j                  t        j                         | j                  g      }| j	                  |d      }|j
                  j                  d       | j                  j                  | j                  |      }| j                  j                  ||f       y )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  su    r{{}t||n=?;
*%||//SA"tg&r   c                    t        j                  | j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  | j                  |      }| j                  j                  |||g      S )FLookup name inside dict

        Returns a borrowed reference
        PyDict_GetItemStringr   )
r   r   rp   r   r   r>   r   r   r?   r   )r   dicr   r   r   r   s         r   dict_getitem_stringzPythonAPI.dict_getitem_string  sp    
 tzzDJJ+EF+AB||//TB||  c4[11r   c                     t        j                  | j                  | j                  | j                  g      }| j                  |d      }| j                  j                  |||g      S )r+  PyDict_GetItemr   r   )r   r-  r   r   r   s        r   dict_getitemzPythonAPI.dict_getitem  sV    
 tzzDJJ

+CD+;<||  c4[11r   c           	         |dk(  rOt        j                  | j                  d      }| j                  |d      }| j                  j                  |d      S t        j                  | j                  | j                  g      }| j                  |d      }| j                  j                  |t        | j                  t        |            g      S )Nr   r/   
PyDict_Newr   _PyDict_NewPresized)	r   r   rp   r   r?   r   r   r   r   )r   presizer   r   s       r   dict_newzPythonAPI.dict_new  s    a<??4::r2D##D|#<B<<$$R,,??4::/@AD##D/D#EB<<$$R&.tG&M%NP Pr   c                     t        j                  t        j                  d      | j                  | j                  | j                  f      }| j	                  |d      }| j
                  j                  ||||f      S )Nr   PyDict_SetItemr   r   r   r   rp   r   r?   r   )r   dictobjnameobjvalobjr   r   s         r   dict_setitemzPythonAPI.dict_setitem  sf    rzz"~

DJJ04

0< =+;<||  gw%?@@r   c                 F   t        j                  t        j                  d      | j                  | j                  | j                  f      }| j                  |d      }| j                  j                  | j                  |      }| j                  j                  ||||f      S )Nr   PyDict_SetItemStringr   )r   r   r   rp   r   r   r>   r   r   r?   r   )r   r:  r   r<  r   r   r   s          r   dict_setitem_stringzPythonAPI.dict_setitem_string  s    rzz"~

DLL04

0< =+AB||//TB||  gtV%<==r   c                     | j                         }| j                  |      5  |D ]  \  }}| j                  |||        	 ddd       |S # 1 sw Y   |S xY w)zb
        Args
        -----
        keyvalues: iterable of (str, llvm.Value of PyObject*)
        N)r6  if_object_okr@  )r   	keyvaluesr:  kvs        r   	dict_packzPythonAPI.dict_pack  sV     --/w'!1((!Q7 " (  ( s   AAc                     t        j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )NPyFloat_FromDoubler   )r   r   rp   r   r   r?   r   )r   fvalr   r   s       r   float_from_doublezPythonAPI.float_from_double  sK    tzzDKK=9+?@||  dV,,r   c                     t        j                  | j                  | j                  | j                  g      }| j	                  |d      }| j                  d      }| j                  j                  |||g      S )NPyNumber_AsSsize_tr   PyExc_OverflowError)r   r   r   rp   r   r   r?   r   )r   numobjr   r   	exc_classs        r   number_as_ssize_tzPythonAPI.number_as_ssize_t  sf    tTZZ0HI+?@%%&;<	||  fi%899r   c                     t        j                  | j                  | j                  g      }| j                  |d      }| j                  j                  ||g      S )NPyNumber_Longr   r   r   rN  r   r   s       r   number_longzPythonAPI.number_long  sJ    tzzDJJ<8?;||  fX..r   c                     t        j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )NPyLong_AsUnsignedLongLongr   r   r   r   rp   r   r?   r   rS  s       r   long_as_ulonglongzPythonAPI.long_as_ulonglong  sK    t~~

|<+FG||  fX..r   c                     t        j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )NPyLong_AsLongLongr   rW  rS  s       r   long_as_longlongzPythonAPI.long_as_longlong  sK    t~~

|<+>?||  fX..r   c                     t        j                  | j                  | j                  g      }| j	                  |d      }| j
                  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   rp   r   r?   r   rS  s       r   long_as_voidptrzPythonAPI.long_as_voidptr  sM    
 t||djj\:+=>||  fX..r   c                    t        j                  | j                  |g      }| j                  ||      }t	        j
                  | j                  | j                        }| j                  ||      }| j                  j                  | j                  j                  ||g      |       | j                  j                  |      S )Nr   )
r   r   rp   r   r   ro   r?   rI   r   ru   )r   ival	func_namenative_int_typesignedr   r   resptrs           r   _long_from_native_intzPythonAPI._long_from_native_int  s    tzzO+<=95$$T\\4::>954<<,,R$8&A||  ((r   c                     d}t        j                  | j                  | j                  g      }| j	                  ||      }| j
                  j                  ||g      S )NPyLong_FromLongr   r   r   rp   r   r   r?   r   )r   ra  rb  r   r   s        r   long_from_longzPythonAPI.long_from_long   sO    %	tzzDII;795||  dV,,r   c                 @    | j                  |d| j                  d      S )NPyLong_FromUnsignedLongFrd  )rf  r   r   ra  s     r   long_from_ulongzPythonAPI.long_from_ulong  s*    ))$0I*.))E * C 	Cr   c                 @    | j                  |d| j                  d      S )NPyLong_FromSsize_tTrm  )rf  r   rn  s     r   long_from_ssize_tzPythonAPI.long_from_ssize_t
  s*    ))$0D*.//$ * H 	Hr   c                 @    | j                  |d| j                  d      S )NPyLong_FromLongLongTrm  )rf  r   rn  s     r   long_from_longlongzPythonAPI.long_from_longlong  s*    ))$0E*.-- * F 	Fr   c                 @    | j                  |d| j                  d      S )NPyLong_FromUnsignedLongLongFrm  )rf  r   rn  s     r   long_from_ulonglongzPythonAPI.long_from_ulonglong  s*    ))$0M*... * H 	Hr   c                    |j                   j                  }|| j                  j                  k  r5| j                  | j                  j                  || j                              S || j                  j                  k  r5| j                  | j                  j                  || j                              S t        d|z        )zH
        Return a Python integer from any native integer value.
        integer too big (%d bits))	r   widthr   rj  r?   sextr   ru  OverflowErrorr   ra  bitss      r   long_from_signed_intzPythonAPI.long_from_signed_int  s     yy499??"&&t||'8'8tyy'IJJT]](((**4<<+<+<T4==+QRR ;t DEEr   c                    |j                   j                  }|| j                  j                  k  r5| j                  | j                  j                  || j                              S || j                  j                  k  r5| j                  | j                  j                  || j                              S t        d|z        )zH
        Same as long_from_signed_int, but for unsigned values.
        rz  )	r   r{  r   ro  r?   zextr   rx  r}  r~  s      r   long_from_unsigned_intz PythonAPI.long_from_unsigned_int"  s     yy4::###''(9(9$

(KLLT^^)))++DLL,=,=dDNN,STT ;t DEEr   c                     t        j                  | j                  | j                  | j                  g      }| j                  |d|z        }|S )NzPyNumber_%sr   )r   r   rp   r   )r   r   r   r   s       r   _get_number_operatorzPythonAPI._get_number_operator.  sB    tzzDJJ

+CD=4+?@	r   c                 n    |rd|z   }| j                  |      }| j                  j                  |||g      S )NInPlace)r  r?   r   )r   r   lhsrhsinplacer   s         r   _call_number_operatorzPythonAPI._call_number_operator3  s:    t#D&&t,||  c3Z00r   c                 ,    | j                  d|||      S )NAddr  r  r   r  r  r  s       r   
number_addzPythonAPI.number_add9      ))%c7)KKr   c                 ,    | j                  d|||      S )NSubtractr  r  r  s       r   number_subtractzPythonAPI.number_subtract<      ))*c3)PPr   c                 ,    | j                  d|||      S )NMultiplyr  r  r  s       r   number_multiplyzPythonAPI.number_multiply?  r  r   c                 ,    | j                  d|||      S )N
TrueDivider  r  r  s       r   number_truedividezPythonAPI.number_truedivideB  s    )),S')RRr   c                 ,    | j                  d|||      S )NFloorDivider  r  r  s       r   number_floordividezPythonAPI.number_floordivideE  s    ))-c7)SSr   c                 ,    | j                  d|||      S )N	Remainderr  r  r  s       r   number_remainderzPythonAPI.number_remainderH  s    ))+sC)QQr   c                 ,    | j                  d|||      S )NMatrixMultiplyr  r  r  s       r   number_matrix_multiplyz PythonAPI.number_matrix_multiplyK  s    ))*:Cg)VVr   c                 ,    | j                  d|||      S )NLshiftr  r  r  s       r   number_lshiftzPythonAPI.number_lshiftN      ))(Cg)NNr   c                 ,    | j                  d|||      S )NRshiftr  r  r  s       r   number_rshiftzPythonAPI.number_rshiftQ  r  r   c                 ,    | j                  d|||      S )NAndr  r  r  s       r   
number_andzPythonAPI.number_andT  r  r   c                 ,    | j                  d|||      S )NOrr  r  r  s       r   	number_orzPythonAPI.number_orW  s    ))$S')JJr   c                 ,    | j                  d|||      S )NXorr  r  r  s       r   
number_xorzPythonAPI.number_xorZ  r  r   c                     t        j                  | j                  | j                  gdz        }|rdnd}| j                  ||      }| j                  j                  |||| j                         g      S )Nr   PyNumber_InPlacePowerPyNumber_Power)r   r   rp   r   r?   r   borrow_none)r   r  r  r  r   fnamer   s          r   number_powerzPythonAPI.number_power]  se    tzzDJJ<!+;<+2'8He,||  c30@0@0B%CDDr   c                     t        j                  | j                  | j                  g      }| j                  |d      }| j                  j                  ||f      S )NPyNumber_Negativer   r   r   s       r   number_negativezPythonAPI.number_negativec  K    tzzDJJ<8+>?||  cV,,r   c                     t        j                  | j                  | j                  g      }| j                  |d      }| j                  j                  ||f      S )NPyNumber_Positiver   r   r   s       r   number_positivezPythonAPI.number_positiveh  r  r   c                     t        j                  | j                  | j                  g      }| j                  |d      }| j                  j                  ||g      S )NPyNumber_Floatr   r   )r   r9   r   r   s       r   number_floatzPythonAPI.number_floatm  sK    tzzDJJ<8+;<||  cU++r   c                     t        j                  | j                  | j                  g      }| j                  |d      }| j                  j                  ||f      S )NPyNumber_Invertr   r   r   s       r   number_invertzPythonAPI.number_invertr  sK    tzzDJJ<8+<=||  cV,,r   c                     t        j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )NPyFloat_AsDoubler   )r   r   r   rp   r   r?   r   )r   fobjr   r   s       r   float_as_doublezPythonAPI.float_as_doublew  sK    t{{TZZL9+=>||  dV,,r   c                 p    | j                   j                  || 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|  s/     ,,##D$))4""7++r   c                     t        j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )NPyBool_FromLongr   ri  )r   ra  r   r   s       r   r  zPythonAPI.bool_from_long  sK    tzzDII;7+<=||  dV,,r   c                     t        j                  | j                  t        j                         t        j                         g      }| j	                  |d      }| j
                  j                  |||g      S )NPyComplex_FromDoublesr   )r   r   rp   r   r   r?   r   )r   realvalimagvalr   r   s        r   complex_from_doubleszPythonAPI.complex_from_doubles  sY    tzzBMMOR]]_+MN+BC||  gw%788r   c                     t        j                  t        j                         | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )NPyComplex_RealAsDoubler   r   r   r   rp   r   r?   r   r   cobjr   r   s       r   complex_real_as_doublez PythonAPI.complex_real_as_double  M    r}}=+CD||  dV,,r   c                     t        j                  t        j                         | j                  g      }| j	                  |d      }| j
                  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                  j                         gdz  z         }| j                  |d      }| j                  j                  |||||f      }| j                  j                  |      }| j                  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   ro   r?   r   r   r   r   rp   r   r   r   ru   r   )r   rD   pstartpstoppstepr   r   resstartstopsteps              r   slice_as_intszPythonAPI.slice_as_ints  s    $$T\\4??C##DLL$//B##DLL$//Brzz"~ $

|t/I/I/K.Lq.PPR+?@llS&%$?@!!&)||  '||  't||S15$DDr   c                     t        j                  | j                  | j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  ||||f      S )NPySequence_GetSlicer   r   r   rp   r   r   r?   r   )r   rD   r  r  r   r   s         r   sequence_getslicezPythonAPI.sequence_getslice  sb    tzzDJJ,0OO,= >+@A||  c5$%788r   c                     t        j                  | j                  | j                  g      }| j                  |d      }| j                  j                  ||g      S )NPySequence_Tupler   r   r   s       r   sequence_tuplezPythonAPI.sequence_tuple  K    tzzDJJ<8+=>||  cU++r   c                     t        j                  | j                  | j                  | j                  g      }| j                  |d      }| j                  j                  |||g      S )NPySequence_Concatr   r   )r   obj1obj2r   r   s        r   sequence_concatzPythonAPI.sequence_concat  sT    tzzDJJ

+CD+>?||  dD\22r   c                     t        j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )N
PyList_Newr   r  )r   szvalr   r   s       r   list_newzPythonAPI.list_new  sK    tzzDOO+<=<8||  eW--r   c                     t        j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )NPyList_Sizer   r   r   r   rp   r   r?   r   )r   lstr   r   s       r   	list_sizezPythonAPI.list_size  sJ    t==9||  cU++r   c                     t        j                  t        j                  d      | j                  | j                  g      }| j	                  |d      }| j
                  j                  |||g      S )Nr   PyList_Appendr   r9  )r   r  r9   r   r   s        r   list_appendzPythonAPI.list_append  sW    rzz"~

DJJ/GH?;||  c3Z00r   c                     t        j                  t        j                  d      | j                  | j                  | j                  g      }| j                  |d      }| j                  j                  ||||g      S )z6
        Warning: Steals reference to ``val``
        r   PyList_SetItemr   )r   r   r   rp   r   r   r?   r   )r   r  idxr9   r   r   s         r   list_setitemzPythonAPI.list_setitem  sg     rzz"~

DOO04

0< =+;<||  c3_55r   c                 D   t        j                  | j                  | j                  | j                  g      }| j	                  |d      }t        |t              r*| j                  j                  t        j                  |      }| j                  j                  |||g      S )z/
        Returns a borrowed reference.
        PyList_GetItemr   )r   r   rp   r   r   r[   r   r>   get_constantr   r   r?   r   )r   r  r  r   r   s        r   rs   zPythonAPI.list_getitem  sz     tzzDJJ+HI+;<c3,,++EJJ<C||  c3Z00r   c                 6   || j                         }t        j                  t        j                  d      | j                  | j
                  | j
                  | j                  g      }| j                  |d      }| j                  j                  |||||f      S )Nr   PyList_SetSlicer   )	r   r   r   r   rp   r   r   r?   r   )r   r  r  r  rD   r   r   s          r   list_setslicezPythonAPI.list_setslice  s    ;&&(Crzz"~

DOO040M N+<=||  c5$%<==r   c                 $   t        j                  | j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  t        j                  |      }| j                  j                  |||g      S )z"
        Borrow reference
        PyTuple_GetItemr   )r   r   rp   r   r   r>   r  r   r   r?   r   )r   tupr  r   r   s        r   tuple_getitemzPythonAPI.tuple_getitem  sp     tzzDJJ+HI+<=ll''

C8||  c3Z00r   c                 H   t        j                  | j                  | j                  gd      }| j	                  |d      }| j
                  j                  t        j                  t        |            }|g}|j                  |       | j                  j                  ||      S )NTr   PyTuple_Packr   )r   r   rp   r   r   r>   r  r   r   rf   extendr?   r   )r   itemsr   r   nr   s         r   
tuple_packzPythonAPI.tuple_pack  s|    tzzDOO+<dK>:LL%%ejj#e*=sE||  T**r   c                     t        j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )NPyTuple_Sizer   r   )r   r  r   r   s       r   
tuple_sizezPythonAPI.tuple_size  sJ    t=>:||  cU++r   c                    t        j                  | j                  t        j                  d      g      }| j	                  |d      }| j
                  j                  || j                  j                  t        j                  |      g      S )Nr   PyTuple_Newr   )r   r   rp   r   r   r?   r   r>   r  r   int32)r   countr   r   s       r   	tuple_newzPythonAPI.tuple_new  sr    tzzBJJrN+;<=9||  dll&?&?@E'G &H I 	Ir   c                 b   t        j                  t        j                  d      | j                  t        j                  d      | j                  g      }| j	                  |d      }| j
                  j                  t        j                  |      }| j                  j                  ||||g       y)z/
        Steals a reference to `item`.
        r   PyTuple_SetItemr   N)r   r   r   rp   r   r>   r  r   r  r?   r   )r   	tuple_valri   itemr   
setitem_fns         r   tuple_setitemzPythonAPI.tuple_setitem  s~     rzz"~

BJJrNDJJ/WX''3D'E
))%++u=*y%&>?r   c                     || j                         }t        j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )N	PySet_Newr   )r   r   r   rp   r   r?   r   )r   iterabler   r   s       r   set_newzPythonAPI.set_new  s^    ++-HtzzDJJ<8;7||  hZ00r   c                     t        j                  t        j                  d      | j                  | j                  g      }| j	                  |d      }| j
                  j                  |||g      S )Nr   	PySet_Addr   r9  )r   setrT   r   r   s        r   set_addzPythonAPI.set_add   sW    rzz"~

DJJ/GH;7||  c5\22r   c                     t        j                  t        j                  d      | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )Nr   PySet_Clearr   r9  r   r.  r   r   s       r   	set_clearzPythonAPI.set_clear%  sN    rzz"~

|<=9||  cU++r   c                     t        j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )N
PySet_Sizer   r   r2  s       r   set_sizezPythonAPI.set_size*  sJ    t=<8||  cU++r   c                     t        j                  t        j                  d      | j                  | j                  g      }| j	                  |d      }| j
                  j                  |||g      S )Nr   _PySet_Updater   r9  )r   r.  r*  r   r   s        r   
set_updatezPythonAPI.set_update/  sW    rzz"~

DJJ/GH?;||  c8_55r   c                 f   t        j                  t        j                  d      | j                  | j                  j                         | j                  j                         | j                  j                         g      }| j                  |d      }| j                  j                  |||||f      S )Nr   _PySet_NextEntryr   )
r   r   r   rp   r   r   r   r   r?   r   )r   r.  posptrkeyptrhashptrr   r   s          r   set_next_entryzPythonAPI.set_next_entry4  s    rzz"~ $

DOO,F,F,H $

 5 5 79R9R9T VW +=>||  c667%CDDr   c              #   
  	
K   | j                   
t        j                  
| j                  d      }t        j                  
| j                  d      }t        j
                  
t        | j                  d      d      }
j                  d      }
j                  d      	
j                  |       	
fd}
j                  |      5  | j                  ||||      }t        j                  
|      }
j                  |d	
      5  
j                  	       d d d        t        
j                  |      |       
j                  |       d d d        
j!                  	       y # 1 sw Y   QxY w# 1 sw Y   'xY ww)Nr>  r   r=  r   r<  bb_bodybb_endc                  (    j                          y r   )branch)rB  r?   s   r   r|   z'PythonAPI.set_iterate.<locals>.do_breakI  s    NN6"r   Fr  )r?   r   ro   r   rp   alloca_once_valuer   r   append_basic_blockrD  
goto_blockr?  r   if_thenr{   ru   position_at_end)r   r.  r>  r=  r<  rA  r|   rfinishedrB  r?   s            @@r   set_iteratezPythonAPI.set_iterate;  s5    ,,%%gt~~IN$$WdjjxH**7+3DOOQ+G08: ,,Y7++H5w	# (##CAAw2H%8v& 9V 4h??NN7# ) 	' 98 )(s6   CF>E7	E+6E7F+E4	0E77F <Fc                 H   t        j                  | j                        }t        j                  t        j                         |g      }| j                  |d      }t        j                  | 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   ro   r?   r   )r   gilptrtyr   r   gilptrs        r   
gil_ensurezPythonAPI.gil_ensureZ  sv    
 >>$..1r{{}xj9&89$$T\\4>>B"vh'r   c                     t        j                  | j                        }t        j                  t        j                         |g      }| j                  |d      }| j                  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   gilrO  r   r   s        r   gil_releasezPythonAPI.gil_releasef  sZ    
 >>$..1r{{}xj9&9:||  cU++r   c                     t        j                  | j                  g       }| j                  |d      }| j                  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_threadp  sE    
 t||R0+>?||  R((r   c                     t        j                  t        j                         | j                  g      }| j	                  |d      }| j
                  j                  ||g       y)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_thready  sL     r{{}t||n=+AB"|n-r   c                     t        j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  ||f      S )Nnumba_get_pyobject_private_datar   r^  r   s       r   object_get_private_dataz!PythonAPI.object_get_private_data  sK    t||djj\:+LM||  cV,,r   c                     t        j                  t        j                         | j                  | j                  g      }| j                  |d      }| j                  j                  |||f      S )Nnumba_set_pyobject_private_datar   )r   r   r   rp   r   r   r?   r   )r   rD   ptrr   r   s        r   object_set_private_dataz!PythonAPI.object_set_private_data  sV    r{{}tzz4<<.HI+LM||  c3Z00r   c                     t        j                  t        j                         | j                  g      }| j	                  |d      }| j
                  j                  ||f      S )N!numba_reset_pyobject_private_datar   r   r   s       r   object_reset_private_dataz#PythonAPI.object_reset_private_data  sM    r{{}tzzl;+NO||  cV,,r   c                     t        j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )NPyImport_ImportModuleNoBlockr   r   r   rp   r   r   r?   r   )r   modnamer   r   s       r   import_module_noblockzPythonAPI.import_module_noblock  sK    tzzDLL>:+IJ||  gY//r   c                 H   t        j                  | j                  | j                  gd      }| j                  |d      }|gt	        |      z   }|j                  | j                  j                  t        j                               | j                  j                  ||      S )NTr   PyObject_CallFunctionObjArgsr   )r   r   rp   r   r   rg   r>   get_constant_nullr   r   r?   r   )r   calleeobjargsr   r   r   s         r   call_function_objargszPythonAPI.call_function_objargs  sz    tzzDJJ<F+IJx$w-'DLL225>>BC||  T**r   c                 :   | j                   j                  | j                  |      }t        j                  | j
                  | j
                  | j                  | j                  gd      }| j                  |d      }dt        |      z  }| j                   j                  | j                  |      }|||g}	|r|	j                  |       |	j                  | j                   j                  t        j                               | j                  j                  ||	      S )NTr   PyObject_CallMethodr   O)r>   r   r   r   r   rp   r   r   rf   r  rg   rn  r   r   r?   r   )
r   ro  methodrp  cnamer   r   r   cfmtr   s
             r   call_methodzPythonAPI.call_method  s    00fEtzzDJJdll+S%)++@ACL ||//SAt$KK DLL225>>BC||  T**r   c                 >   |d u x}r| j                  d      }|| j                         }t        j                  | j                  | j                  gdz        }| j                  |d      }| j                  j                  ||||f      }|r| j                  |       |S )Nr   r   PyObject_Callr   )	r!  r   r   r   rp   r   r?   r   r   )r   ro  r   r   args_was_noner   r   results           r   r   zPythonAPI.call  s     DL(=(>>!$D;&&(CtzzDJJ<!+;<?;""2c':;KKr   c                     t        j                  | j                  | j                  g      }| j                  |d      }| j                  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  sL     tzzDJJ<8?;||  cV,,r   c                     t        j                  t        j                  d      | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )Nr   PyObject_IsTruer   r9  r   s       r   object_istruezPythonAPI.object_istrue  sO    rzz"~

|<+<=||  cU++r   c                     t        j                  t        j                  d      | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )Nr   PyObject_Notr   r9  r   s       r   
object_notzPythonAPI.object_not  sN    rzz"~

|<>:||  cU++r   c                    g d}||v r|j                  |      }t        j                  | j                  | j                  | j                  t        j                  d      g      }| j                  |d      }| j                  j                  t        j                  |      }| j                  j                  ||||f      S |dk(  r.| j                  j                  d||      }	| j                  |	      S |dk(  r.| j                  j                  d||      }	| j                  |	      S |d	v rt        j                  t        j                  d      | j                  | j                  g      }| j                  |d
      }| j                  j                  |||f      }
| j                  j                  t        j                  d      }| j                  j                  d|
|      }t        j                  | j                  t!        | j                  d            }t        j"                  | j                  |      5  |dk(  r| j                  j%                  |
      }
| j                  j'                  |
t        j                  d            }| j                  j)                  | j                  |      |       ddd       | j                  j+                  |      S t-        dj/                  |            # 1 sw Y   ?xY w)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)ri   r   r   rp   r   r   r>   r  r   r  r?   r   icmp_unsignedr  r   rE  r   	if_likelynot_truncrI   ru   NotImplementedErrorformat)r   r  r  opstropsopidr   r   lopidbitflagstatusnegoneis_goodoutptr	truncateds                  r   object_richcomparezPythonAPI.object_richcompare  si   
 1C<99U#D??4::

DJJ

SU/WXD##D/E#FBLL--ekk4@E<<$$R#sE):;;d]ll00sC@G&&w//hll00sC@G&&w//&&??2::b>DJJ

3KLD##D/D#EB\\&&rC:6F\\..u{{B?Fll00vvFG..t||/7

D/IKF ""4<<9H$!\\..v6F LL..vrzz!}E	""4#6#6y#A#)+ : <<$$V,,%&?&F&F 'G '   :9s   6A;K//K8c                     t        j                  | j                  | j                  g      }| j                  |d      }| j                  j                  ||g      S )NPyIter_Nextr   r   )r   iterobjr   r   s       r   	iter_nextzPythonAPI.iter_next  sJ    tzzDJJ<8=9||  gY//r   c                     t        j                  | j                  | j                  g      }| j                  |d      }| j                  j                  ||g      S )NPyObject_GetIterr   r   r   s       r   object_getiterzPythonAPI.object_getiter  r  r   c                    | j                   j                  | j                  |      }t        j                  | j
                  | j
                  | j                  g      }| j                  |d      }| j                  j                  |||g      S )NPyObject_GetAttrStringr   )
r>   r   r   r   r   rp   r   r   r?   r   )r   rD   attrr   r   r   s         r   object_getattr_stringzPythonAPI.object_getattr_string  sn    ||//TBtzzDJJ+EF+CD||  c4[11r   c                     t        j                  | j                  | j                  | j                  g      }| j                  |d      }| j                  j                  |||g      S )NPyObject_GetAttrr   r   )r   rD   r  r   r   s        r   object_getattrzPythonAPI.object_getattr	  sT    tzzDJJ

+CD+=>||  c4[11r   c                 F   | j                   j                  | j                  |      }t        j                  t        j
                  d      | j                  | j                  | j                  g      }| j                  |d      }| j                  j                  ||||g      S )Nr   PyObject_SetAttrStringr   )r>   r   r   r   r   r   rp   r   r   r?   r   )r   rD   r  r9   r   r   r   s          r   object_setattr_stringzPythonAPI.object_setattr_string  s{    ||//TBrzz"~

DLL$**/UV+CD||  c4%566r   c                     t        j                  t        j                  d      | j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  ||||g      S )Nr   PyObject_SetAttrr   r9  )r   rD   r  r9   r   r   s         r   object_setattrzPythonAPI.object_setattr  sa    rzz"~

DJJ

/ST+=>||  c4%566r   c                 D    | j                  ||| j                               S r   )r  r   r   rD   r  s      r   object_delattr_stringzPythonAPI.object_delattr_string  s"     ))#tT5I5I5KLLr   c                 D    | j                  ||| j                               S r   )r  r   r  s      r   object_delattrzPythonAPI.object_delattr  s"     ""3d.B.B.DEEr   c                     t        j                  | j                  | j                  | j                  g      }| j                  |d      }| j                  j                  |||f      S )z!
        Return obj[key]
        PyObject_GetItemr   r   r   rD   keyr   r   s        r   object_getitemzPythonAPI.object_getitem#  sV     tzzDJJ

+CD+=>||  c3Z00r   c                     t        j                  t        j                  d      | j                  | j                  | j                  g      }| j	                  |d      }| j
                  j                  ||||f      S )z 
        obj[key] = val
        r   PyObject_SetItemr   r9  )r   rD   r  r9   r   r   s         r   object_setitemzPythonAPI.object_setitem+  sb     rzz"~

DJJ

/ST+=>||  c3_55r   c                     t        j                  t        j                  d      | j                  | j                  g      }| j	                  |d      }| j
                  j                  |||f      S )z
        del obj[key]
        r   PyObject_DelItemr   r9  r  s        r   object_delitemzPythonAPI.object_delitem3  sZ     rzz"~

DJJ/GH+=>||  c3Z00r   c                     t        j                  | j                  | j                  g      }d}| j	                  ||      }| j
                  j                  ||g      S )NPyUnicode_AsUTF8r   r   r   r   rp   r   r?   r   )r   strobjr   r  r   s        r   string_as_stringzPythonAPI.string_as_string;  sO    t||djj\:"51||  fX..r   c                    t        j                  | j                  | j                        }t	        j
                  | j                  | j                  | j                  j                         g      }d}| j                  ||      }| j                  j                  |||g      }| j                  j                  dt        |j                  d      |      }||| j                  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   ro   r?   r   r   r   r   rp   r   r   r   r  r   r   ru   )r   r  p_lengthr   r  r   bufferoks           r   string_as_string_and_sizez#PythonAPI.string_as_string_and_sizeA  s     &&t||T__Et||djj.2oo.H.H.J.L M)51""2'9:\\''(0d(C(.0 FDLL--h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                  j                         t	        j
                  d      j                         t	        j
                  d      j                         | j                  j                         g      }d}| j                  ||      }| j                  j                  ||||||g      }	| j                  j                  dt        |	j                  d      |	      }
|
|	| j                  j!                  |      | j                  j!                  |      | 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   ro   r?   r   r   r   r   r   r   rp   r   r   r   r  r   r   ru   )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_kindU  s    &&t||T__E$$T\\2::b>B%%dllBJJrNC$$T\\4>>Bt||djj.2oo.H.H.J.0jjn.G.G.I.0jjn.G.G.I.2nn.G.G.I	.K L
 (51""67F;=\\''(0d(C(.0 FDLL--h7!!&)4<<+<+<W+E!!&)+ 	+r   c                     t        j                  | j                  | j                  | j                  g      }d}| j                  ||      }| j                  j                  |||g      S )NPyString_FromStringAndSizer   r   r   rp   r   r   r   r?   r   r   stringsizer   r  r   s         r   string_from_string_and_sizez%PythonAPI.string_from_string_and_sizes  sX    tzzDLL$//+JK,51||  fd^44r   c                     t        j                  | j                  | j                  g      }d}| j	                  ||      }| j
                  j                  ||g      S )NPyUnicode_FromStringr   ri  )r   r  r   r  r   s        r   string_from_stringzPythonAPI.string_from_stringy  sO    tzzDLL>:&51||  fX..r   c                     t        j                  | j                  t        j                  d      | j                  | j
                  g      }d}| j                  ||      }| j                  j                  ||||g      S )Nr   PyUnicode_FromKindAndDatar   )	r   r   rp   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  se    tzzBJJrNDLL$//+Z[+51||  dFD%9::r   c                     t        j                  | j                  | j                  g      }d}| j	                  ||      }| j
                  j                  ||g      S )NPyBytes_AsStringr   r  r   rD   r   r  r   s        r   bytes_as_stringzPythonAPI.bytes_as_string  sO    t||djj\:"51||  cU++r   c                    t        j                  t        j                  d      | j                  | j                  j                         | j                  j                         g      }d}| j                  ||      }| j                  j                  ||||g      }| j                  j                  dt        |j                  d      |      }|S )Nr   PyBytes_AsStringAndSizer   r  r  )r   r   r   rp   r   r   r   r   r?   r   icmp_signedr   r   )	r   rD   p_bufferr  r   r  r   r|  r  s	            r   bytes_as_string_and_sizez"PythonAPI.bytes_as_string_and_size  s    JJrNZZ002DOO4N4N4PQ
 *51""2Xx'@A\\%%dHV[[",EvN	r   c                     t        j                  | j                  | j                  | j                  g      }d}| j                  ||      }| j                  j                  |||g      S )NPyBytes_FromStringAndSizer   r  r  s         r   bytes_from_string_and_sizez$PythonAPI.bytes_from_string_and_size  sX    tzzDLL$//+JK+51||  fd^44r   c                     t        j                  | j                  | j                  g      }d}| j	                  ||      }| j
                  j                  ||g      S )NPyObject_Hashr   )r   r   r   rp   r   r?   r   r  s        r   object_hashzPythonAPI.object_hash  sO    t~~

~>51||  cV,,r   c                     t        j                  | j                  | j                  g      }| j                  |d      }| j                  j                  ||g      S )NPyObject_Strr   r   r   s       r   
object_strzPythonAPI.object_str  sJ    tzzDJJ<8>:||  cU++r   c                 H    | j                         }| j                  |       |S r   )r  r   r   rD   s     r   r   zPythonAPI.make_none  s!     C
r   c                 $    | j                  d      S )N_Py_NoneStruct)r   r   s    r   r  zPythonAPI.borrow_none  s      !122r   c                     t        j                  t        j                         | j                  gd      }| j	                  |d      }| j
                  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  sS    r{{}t||ndK+?@||  cVd]33r   c                     t        j                  t        j                         | j                  g      }| j	                  |d      }| j
                  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  sO     r{{}tzzl;+;<||  cV,,r   c                 N   | j                   j                  sJ d       t        j                  d      }| j	                  | j                  |j                              }t        j                  | j                  | j                  | j                  ||| j                  g      }| j                  |d      }|j                  d   j                  d       | j                   j                  t        j                  |j                         }| j                   j                  t        j                  t#        |j$                              }	t'        j(                  | j*                  |      }
| 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   rp   r   r   r   add_attributer  r   r  ndimr   mutabler   rE  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  s?   ||&&66&

2"..t/D/DU^^/TUtzz $djj%

SU+OP

  -||((ejjA<<,,U[[#emm:LM**4<<=||  dll&:&:6;?<<'I&9&*Hh&@ A 	Ar   c                    | j                   j                  }t        j                  t        j
                  t        j
                  t        j
                  g      }t	        j                  ||d      }|j                  d   j                  d       |j                  d   j                  d       |j                  j                  d       | j                   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   datarp   modr   r   s         r   nrt_meminfo_new_from_pyobjectz'PythonAPI.nrt_meminfo_new_from_pyobject  s    
 ll!! 1 12 +++
 	
  -

  -
%%i0||  dE]33r   c                 *   | j                   j                  }t        j                  | j                  t
        j                  g      }t        j                  ||d      }|j                  j                  d       | j                   j                  ||g      S )NNRT_meminfo_as_pyobjectr  )r?   r   r   r   rp   r   r  r  r  r
  r   )r   miptrr  r   r   s        r   nrt_meminfo_as_pyobjectz!PythonAPI.nrt_meminfo_as_pyobject  sz    ll!!JJ
 ++%

 	%%i0||  eW--r   c                 *   | j                   j                  }t        j                  t        j
                  | j                  g      }t	        j                  ||d      }|j                  j                  d       | j                   j                  ||g      S )NNRT_meminfo_from_pyobjectr  )r?   r   r   r   r   r  rp   r  r  r
  r   )r   miobjr  r   r   s        r   nrt_meminfo_from_pyobjectz#PythonAPI.nrt_meminfo_from_pyobject  sy    ll!!ZZL
 ++'

 	%%i0||  eW--r   c                    | j                   j                  sJ t        j                  t        j                  d      | j
                  | j                  g      }| j                  |d      }|j                  d   j                  d       |j                  d   j                  d       | j                  j                  |||f      S )Nr   NRT_adapt_ndarray_from_pythonr   r   r  r  r>   r  r   r   r   rp   r   r   r   r
  r?   r   r   r  rb  r   r   s        r   nrt_adapt_ndarray_from_pythonz'PythonAPI.nrt_adapt_ndarray_from_python  s    ||&&&&rzz"~

DLL/IJ+JK

  -

  -||  c3Z00r   c                    | j                   j                  sJ t        j                  t        j                         t        j
                  | j                        | j                  g      }| j                  |d      }|j                  d   j                  d       |j                  d   j                  d       | j                  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   bufrb  r   r   s        r   nrt_adapt_buffer_from_pythonz&PythonAPI.nrt_adapt_buffer_from_python  s    ||&&&&r{{}r~~d>N>N/O/3||/= >+IJ

  -

  -||  c3Z00r   c                 D    t        j                  | j                  ||      S r   )r   r  r   )r   r   r   s      r   r   zPythonAPI._get_function  s    --dkk4FFr   c                 L    | j                   j                  | j                        S r   )r?   allocarp   r   s    r   
alloca_objzPythonAPI.alloca_obj  s    ||""4::..r   c                 n    t        j                  | j                  t        | j                  d            }|S )zT
        Return a pointer to a stack-allocated, zero-initialized Py_buffer.
        N)r   rE  r?   r   r   )r   rb  s     r   alloca_bufferzPythonAPI.alloca_buffer  s0    
 ''(01A1A4(HJ
r   c              #      K   t        j                  | j                  t        j                  | j                  |            5  d  d d d        y # 1 sw Y   y xY wwr   )r   r  r?   rr   r  s     r   rB  zPythonAPI.if_object_ok'  sD     t||&224<<EGG G Gs   ?AA	AAAc                     | j                  |      }| j                  |      }| j                  j                  | j                  d      }| j                  ||       | j                  |       y )Nz%s)r  r  r>   r   r   r  r   )r   rD   r  r   r   s        r   print_objectzPythonAPI.print_object-  sV    %$$V,ll..t{{DAc4(Fr   c                 r    | j                   j                  | j                  |      }| j                  |       y r   )r>   r   r   r  )r   textr   s      r   print_stringzPythonAPI.print_string4  s*    ll..t{{DAc"r   c                 .    t        | j                  d       S r   )r   rp   r   s    r   r   zPythonAPI.get_null_object8  s    

D))r   c                 Z    | j                         }| j                  j                  |       y r   )r   r?   rv   )r   nones     r   return_nonezPythonAPI.return_none;  s     ~~r   c                    t        |      }| j                  | j                  j                  t        j
                  |            }| j                  |      5  t        |      D ]V  }| j                  j                  t        j
                  |      }| j                  ||          | j                  ||||          X 	 d d d        |S # 1 sw Y   |S xY wr   )
rf   r  r>   r  r   r   rB  r  r   r	  )r   r  r  seqr  r  s         r   	list_packzPythonAPI.list_pack?  s    JmmDLL55ejj!DEs#1Xll//

A>E!H%!!#sE!H5  $
 
 $
 
s   A%CCc                 8   t        j                  | j                  | j                  t        j                  d      | j                  f      }| j                  |d      }| j                  j                  | j                  j                  |      d      }| j                  j                  | j                  j                  |      d      }| j                  j                  | j                  j                  |      d      }| j                  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   rp   r   r   r   r?   extract_valueru   r   )r   	structptrr   r   rb  r  hasheds          r   r  zPythonAPI.unserializeI  s     tzz"llBJJrNDLLIK+;<ll(():):9)EqILL&&t||'8'8'CQG++DLL,=,=i,H!L||  c1f%566r   c                     t        j                  | j                  | j                  | j                  f      }| j                  |d      }| j                  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_structW  sW     tzzDJJ

+CD+OP||  i%:;;r   c                 P   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                  ||      }| j                  j                  | j                  | d|      }t        j                  |j!                  | j"                        t        t%        j&                  d      |j(                  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   dumpsrf   r	   rP  idr   make_bytearrayhashlibsha1digestr>   insert_unique_constr   r   literal_structr  r   r   r   r   r   r   get_null_value)	r   rD   r  r   bdatarI  arrhasharrstructs	            r   serialize_uncachedzPythonAPI.serialize_uncacheda  s8    s#4y5   %FNNa4GCYW&&t, ''T(:(A(A(CDll..t{{D%H,,22KKD6
 ((KK%RZZ^SXX%5%5%;%;<OODLL)""4<<0RZZ^Q'*  r   c                 B   	 | j                   j                  |   }|S # t        $ rx | j                  |      }dt        j
                  dk(  rt        |      ndz  }| j                  j                  | j                   ||      }|| j                   j                  |<   Y |S w xY w)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   rP  )	r   r   r   r^  r	   rP  rR  r>   rW  )r   rD   gvr]  r   s        r   r  zPythonAPI.serialize_object~  s    	/))#.B 	  	/,,S1F(v~~7JBsGPYZD11$++tVLB,.DKK$$S)		/s    A=BBc                 ^    t        j                  | j                  | j                               S r   )r   rr   r?   r   r   s    r   c_api_errorzPythonAPI.c_api_error  s"    ""4<<1B1B1DEEr   c                     ddl m} t        j                  |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.boxingrd  	_unboxersr+   	__class__rA   r>   r?   )r   r8   rD   rd  implcs         r   rC   zPythonAPI.to_native_value  sC    
 	8/@A$,,d;Ca  r   c                 n    t        |t        j                        rJ d       | j                  |||      }|S )Nz;callconv should have prevented the return of optional value)r[   r   Optionalr5   )r   r8   r9   r6   outs        r   from_native_returnzPythonAPI.from_native_return  s@    c5>>2 	E 5E 	E2 $$S#{;
r   c                     ddl m} t        j                  |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)re  ro  _boxersr+   rg  r1   r>   r?   )r   r8   r9   r6   ro  rh  ri  s          r   r5   zPythonAPI.from_native_value  sB     	6~~cmm_=dllD+FCa  r   c                 d   t         j                  |j                        }|t        j                  S t        j
                  | j                  t        j                        }t        | j                  | 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+   rg  r   rU   rE  r?   rG   r>   ru   rJ   )r   r8   r9   r6   rh  rJ   ri  s          r   rO   zPythonAPI.reflect_native_value  s    
 !!#--0<$$$,,T\\7;L;LMDLL$,,k$&S#q||  ,,r   c                     t        j                  | j                  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?   rR   )r   rD   r8   
gen_ptr_tyrT   s        r   to_native_generatorzPythonAPI.to_native_generator  sH    
 ^^DLL$>$>s$CD
00sJO5!!r   c           	         | j                   j                  |      }|j                  rJ | j                   j                  |      }| j                   j	                  |      }t        j                  | j                  | j                  | j                  | j                  g      }| j                  ||j                        }t        j                  t        j                         | j                  g      }	|j                  r| j                  |	|j                        }
nt        t        j                  |	      d      }
t        j                  | j                  | j                   | j                  t        j                  |      t        j                  |	      | j                  g      }| j                  |d      }t        | j                   |      }| j"                  j%                  || j                        }|| 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>   rt  
is_pointerget_abi_sizeofget_generator_descr   r   rp   r   llvm_cpython_wrapper_namer   r   has_finalizerllvm_finalizer_namer   r   r   r?   r  r   r   )r   r9   r8   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 //$**tzz4::tzz.RS""71R1R"S oobkkmdll^D**;W=X=X*YI !<dCI tzzDOO,0LL,.NN7,C,.NN;,G,0LL	,: ;
 +ABdoo?
,,S$,,?;&&(Cll""35||  ",mUIs!SU 	Ur   c                    | j                   j                  rJ t        j                  t        j                  d      | j
                  | j                  g      }| j                  |d      }|j                  d   j                  d       |j                  d   j                  d       | j                  j                  |||f      S )Nr   numba_adapt_ndarrayr   r   r  r  r)  r*  s        r   numba_array_adaptorzPythonAPI.numba_array_adaptor  s    <<****rzz"~

DLL/IJ+@A

  -

  -||  c3Z00r   c                 ~   t        j                  t        j                         t        j                  | j                        | j
                  g      }| j                  |d      }|j                  d   j                  d       |j                  d   j                  d       | j                  j                  |||f      S )Nnumba_adapt_bufferr   r   r  r  )r   r   r   r   r   r   r   r   r
  r?   r   r.  s        r   numba_buffer_adaptorzPythonAPI.numba_buffer_adaptor  s    r{{} nnT-=-=>MO+?@

  -

  -||  c3Z00r   c                     t        j                  t        j                  d      | j                  |j                  g      }| j                  |d      }| j                  j                  |||g      S )Nr   numba_complex_adaptorr   )r   r   r   rp   r   r   r?   r   )r   r  cmplxr   r   s        r   complex_adaptorzPythonAPI.complex_adaptor  sX    rzz"~

EJJ/GH+BC||  dE]33r   c                     t        j                  | j                  | j                  t        j                  | j
                        g      }| j                  |d      }| j                  j                  |||g      S )Nnumba_extract_record_datar   )	r   r   r   rp   r   r   r   r?   r   r   rD   pbufr   r   s        r   extract_record_datazPythonAPI.extract_record_data  sc    t|| $

BNN4;K;K,LMO+FG||  c4[11r   c                    t        j                  t        j                  d      | j                  t        j                  | j
                        g      }| j                  |d      }| j                  j                  |||g      S )Nr   numba_get_bufferr   )	r   r   r   rp   r   r   r   r?   r   r  s        r   
get_bufferzPythonAPI.get_buffer  sg    rzz"~ $

BNN4;K;K,LMO+=>||  c4[11r   c                     t        j                  t        j                         t        j                  | j                        g      }| j                  |d      }| j                  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  sY    r{{}r~~d>N>N/O.PQ+AB||  dV,,r   c                     t        j                  t        j                  d      | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )N@   numba_extract_np_datetimer   r9  r   s       r   extract_np_datetimezPythonAPI.extract_np_datetime  sO    rzz"~

|<+FG||  cU++r   c                     t        j                  t        j                  d      | j                  g      }| j	                  |d      }| j
                  j                  ||g      S )Nr  numba_extract_np_timedeltar   r9  r   s       r   extract_np_timedeltazPythonAPI.extract_np_timedelta  sO    rzz"~

|<+GH||  cU++r   c                 D   t        t        j                  d      t        |            }t        j                  | j
                  t        j                  d      t        j                  d      g      }| j                  |d      }| j                  j                  |||g      S )Nr   r  numba_create_np_datetimer   	r   r   r   r   r   rp   r   r?   r   r   r9   	unit_coder   r   s        r   create_np_datetimezPythonAPI.create_np_datetime#  su    RZZ^S^<	tzzBJJrNBJJrN+KL+EF||  c9%566r   c                 D   t        t        j                  d      t        |            }t        j                  | j
                  t        j                  d      t        j                  d      g      }| j                  |d      }| j                  j                  |||g      S )Nr   r  numba_create_np_timedeltar   r  r  s        r   create_np_timedeltazPythonAPI.create_np_timedelta)  su    RZZ^S^<	tzzBJJrNBJJrN+KL+FG||  c9%566r   c                 r   t        j                  | j                  t        j                  t        j                  d            t        j                  d      | j                  g      }| j                  |d      }|j                  |j                  |            }| j                  j                  ||||g      S )Nr   r   numba_recreate_recordr   )
r   r   rp   r   r   r   rz   rj   r?   r   )r   pdatar  dtyper6   r   r   	dtypeaddrs           r   recreate_recordzPythonAPI.recreate_record/  s    tzzBNN2::a=,I,.JJrNDJJ,H I+BC**;+@+@+GH	||  eT9%=>>r   c                     | j                   j                  | j                  |      }| j                   j                  t        j
                  t        |            }| j                  ||      S r   )r>   r   r   r  r   r   rf   r  )r   r  r   szs       r   string_from_constant_stringz%PythonAPI.string_from_constant_string6  sM    ||//VD\\&&uzz3v;?//b99r   c           	         | j                   }| j                  j                  |||      }|j                  j                  }|j                  }||k7  rt
        j                  d| d| d      | j                  j                  ||j                  ||      \  }}	t        j                  |t        j                  d      }
| j                  j                  |j                        }t        j                  ||d      }|j                  |j                        5 \  }}|5  |j                  |j                  |
       | j                  j                   j#                  || |       ddd       |5  t%        j&                  | j                  ||||	      }	|j                  |	|       ddd       ddd       |j)                  |
      }|j)                  |      }	||	fS # 1 sw Y   wxY w# 1 sw Y   CxY w# 1 sw Y   GxY w)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.
Trl   N)r?   r>   compile_subroutine	signaturer   errorsLoweringErrorcall_internal_no_propagatefndescr   ro   bool_tr   rq   rJ   rI   r   raise_errorr   fix_returning_optionalru   )r   r    sigr   r?   cres	got_rettyrettyr  r  is_error_ptrres_typeres_ptrhas_errno_errrJ   s                   r   call_jit_codezPythonAPI.call_jit_code;  s   2 ,,||..wcBNN..	 &&(4wcB  ll==T[[#t
 **7GNN$O<<..s?%%gxtD __V__-1B'6foo|<&&227D&I  55LL'3 c7+  . <<-ll7#}   .-s=   G.AG 
G.*6G" G.G	G."G+	'G..G7)F r   )F)r   )r/   rW   )r,   r-   r.   r<   r   r   r   r   r   r   r   r   r   r   r   rt   r   r   r   r   r  r	  r  
contextlibcontextmanagerr  r   r!  r#  r)  r.  r1  r6  r=  r@  rF  rJ  rP  rT  rX  r[  r_  rf  rj  ro  rr  ru  rx  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	  rs   r  r  r  r  r!  r'  r+  r/  r3  r6  r9  r?  rL  rQ  rU  rX  r\  r_  rc  rf  rk  rq  rx  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+  r0  r   r4  r6  rB  r9  r<  r   r@  rC  r  rN  r^  r  rb  rC   rm  r5   rO   rw  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r/   r   r   r~   r~      s   
F@@ ?D*,2%
%
,N?	N)
)
5J	-81-
7
4
 * *8	85
5
'22	PA>
 -
:/
/
/
/)-CHFH
F
F
1LQQSTRWOOLKLE-
-
,
-
-
,-
9
-
-E.9,
3
.
,
1
61>1+,
I@13
,
,
6
E ( (<
,).-
1
-0
++
-,
,
'R0
,
22
77
M
F
161/9(+<5/;,	5-,

34
-A*4(..11G/  
#*7<:"F	!!- "'UR114
22-
,
,
77?:
;r   r~   c                   ,    e Zd ZdZd Zd Zed        Zy)ObjModeUtilszHInternal utils for calling objmode dispatcher from within NPM code.
    c                     || _         y r   )r4   )r   r4   s     r   r   zObjModeUtils.__init__|  s	    
r   c                    | j                   j                  }| j                   j                  }|j                  }t	        j
                  || j                   j                  |j                  d            }|j                  j                  d       |_
        d|_        |j                  d      }t        j                  |j                        r| j                   j!                  |j                  t#        |      f      }| j                   j%                  |      }	t'        j(                  ||	      }
|j+                  |
      5  |j-                  |       d d d        |j/                  |      }|j+                  t'        j(                  ||            5  t        j                  |j                        rt        |       }| j                   j%                  | j                   j!                  |j0                              }| j                   j3                  |	g      }| j                   j5                  |       | j                   j5                  |	       nA|j                  j7                  t#        |            }|j9                  |t;        |      d      }| j                   j=                  |       |j?                  ||       d d d        |j-                  |       |jA                  |       |j/                  |      }|S # 1 sw Y   xY w# 1 sw Y   KxY w)Ncached_objmode_dispatcherr   internalrB  with_objectmode)info)!r4   r?   r>   r   r   GlobalVariablerp   get_unique_namer   r   initializerlinkagerF  r   is_serialiable
dispatcherr  r   r  r   r   rH  rD  ru   _call_objmode_dispatcherrq  r   compileadd_dynamic_addrrR  r   rI   rI  )r   r   r   r?   tyctxmr`  rB  serialized_dispatchercompile_argsfailed_unsercachedr*   compilerro  entry_pts                   r   load_dispatcherzObjModeUtils.load_dispatcher  sU   **$$

""NN tzz""#>?
 .
 ++H5##DOO4$(JJ$?$?%/2%!  ::112GHL"??7LAL.v& / b!__W__Wf=>''84j::11JJ//0L0LM 99|n 

!!(+

!!,/??225?C//R\0A 0  JJf%MM&"%' ?* 	v'b!= /.
 ?>s   =K5D+L5K?Lc                 2    | \  }}|j                  |      }|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  y  s&    5n  r   r  )0collectionsr   r  picklerT  rb   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   rp  rf  rr  r%   r:   rE   rP   r1   rA   rG   rR   rY   r{   r~   r  r/   r   r   <module>r     s>   "    
        '"88 "88 "88 **&<< . +K	k


H*]@B H4J35 4Kj!2#$ K&	& 	1! 1!h ?,ABS Sl.A Ar   