
    pi                     4   d dl mZ d dlmZ d dlmZ d dlmZ	 d dl
mZ d dlmZ d dlmZmZ d dlmZ  ed	g d
      Z G d de      Zej,                  Z ej0                  e      d        Z ej4                           e       Z eeej8                         [y)    )
namedtuple)finalize)	nrtdynmod)binding)global_compiler_lock)typeof_impl)typesconfig)_nrt_python
nrt_mstatsallocfreemi_allocmi_freec                   \    e Zd Zd Zed        Zd Zed        Ze	d        Z
d Zd
dZd Zy	)_Runtimec                     d| _         y )NF)_initselfs    X/opt/services/ai/voice_agent/venv/lib/python3.12/site-packages/numba/core/runtime/nrt.py__init__z_Runtime.__init__   s	    
    c                 V   | j                   ryt        j                  rt        j                          t        j
                  D ]D  }|j                  d      r|}nd|z   }t        j
                  |   }t        j                  ||       F t        j                  |      | _        d| _         y)zInitializes the NRT

        Must be called before any actual call to the NRT API.
        Safe to be called multiple times.
        N_NRT_T)r   r
   	NRT_STATS_nrtmemsys_enable_stats	c_helpers
startswithll
add_symbolr   compile_nrt_functions_library)r   ctxpy_namec_name	c_addresss        r   
initializez_Runtime.initialize   s     :: $$& ~~ 	-G!!#& ')w/IMM&),	- "77<
r   c                 6    | j                   sd}t        |      y )Nz'Runtime must be initialized before use.)r   RuntimeError)r   msgs     r   _init_guardz_Runtime._init_guard0   s    zz;Cs## r   c                  ,    t        j                          y)ze
        Shutdown the NRT
        Safe to be called without calling Runtime.initialize first
        N)r   memsys_shutdown r   r   shutdownz_Runtime.shutdown5   s     	r   c                 :    | j                          | j                  S )zQ
        Return the Library object containing the various NRT functions.
        )r/   r&   r   s    r   libraryz_Runtime.library=   s    
 	}}r   c                 d    | j                          t        j                  ||      }t        |      S )z
        Returns a MemInfo object that tracks memory at `data` owned by `pyobj`.
        MemInfo will acquire a reference on `pyobj`.
        The release of MemInfo will release a reference on `pyobj`.
        )r/   r   meminfo_newMemInfo)r   datapyobjmis       r   r7   z_Runtime.meminfo_newE   s,     	dE*r{r   c                     | j                          |dk  rd| d}t        |      |rt        j                  |      }nt        j                  |      }|dk(  rd| d}t        |      t        |      S )a  
        Allocate a new memory of `size` bytes and returns a MemInfo object
        that tracks the allocation.  When there is no more reference to the
        MemInfo object, the underlying memory will be deallocated.

        If `safe` flag is True, the memory is allocated using the `safe` scheme.
        This is used for debugging and testing purposes.
        See `NRT_MemInfo_alloc_safe()` in "nrt.h" for details.
        r   z,Cannot allocate a negative number of bytes: .zRequested allocation of z bytes failed.)r/   
ValueErrorr   meminfo_alloc_safememinfo_allocMemoryErrorr8   )r   sizesafer.   r;   s        r   r@   z_Runtime.meminfo_allocO   s|     	!8@aHCS/!((.B##D)B7,TF.ACc""r{r   c                     t        t        j                         t        j                         t        j                         t        j
                               S )zw
        Returns a namedtuple of (alloc, free, mi_alloc, mi_free) for count of
        each memory operations.
        r   )_nrt_mstatsr   memsys_get_stats_allocmemsys_get_stats_freememsys_get_stats_mi_allocmemsys_get_stats_mi_freer   s    r   get_allocation_statsz_Runtime.get_allocation_statsf   sB     !<!<!> $ : : <$($B$B$D#'#@#@#BD 	Dr   N)F)__name__
__module____qualname__r   r   r+   r/   staticmethodr3   propertyr5   r7   r@   rJ   r2   r   r   r   r      sX      8$
    .	Dr   r   c                 H    t        j                  t         j                        S )N)r	   MemInfoPointervoidptr)valcs     r   typeof_meminforU   v   s    ..r   N)collectionsr   weakrefr   	_finalizenumba.core.runtimer   llvmliter   r#   numba.core.compiler_lockr   numba.core.typing.typeofr   
numba.corer	   r
   r   r   rE   objectr   _MemInfor8   registerrU   memsys_use_cpython_allocatorrtsysr3   r2   r   r   <module>rc      s    " ) ( " 9 0 $ 2'OP`Dv `DH -- g/ /
 " ! ! #
 
%"" # r   