U
    ?h                     @   s   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	d
dddgZG dd deZejZeedd Ze  e Zeeej [dS )    )
namedtuple)finalize)	nrtdynmod)binding)global_compiler_lock)typeof_impl)typesconfig)_nrt_pythonZ
nrt_mstatsallocfreemi_allocmi_freec                   @   sZ   e Zd Zdd Zedd Zdd Zedd Ze	d	d
 Z
dd ZdddZdd ZdS )_Runtimec                 C   s
   d| _ d S )NF)_initself r   H/var/www/html/venv/lib/python3.8/site-packages/numba/core/runtime/nrt.py__init__   s    z_Runtime.__init__c                 C   sh   | j r
dS tjrt  tjD ]2}|dr2|}nd| }tj| }t|| qt	
|| _d| _ dS )zInitializes the NRT

        Must be called before any actual call to the NRT API.
        Safe to be called multiple times.
        N_ZNRT_T)r   r	   Z	NRT_STATS_nrtZmemsys_enable_statsZ	c_helpers
startswithllZ
add_symbolr   Zcompile_nrt_functions_library)r   ctxZpy_nameZc_nameZ	c_addressr   r   r   
initialize   s    


z_Runtime.initializec                 C   s   | j sd}t|d S )Nz'Runtime must be initialized before use.)r   RuntimeError)r   msgr   r   r   _init_guard0   s    z_Runtime._init_guardc                   C   s   t   dS )ze
        Shutdown the NRT
        Safe to be called without calling Runtime.initialize first
        N)r   Zmemsys_shutdownr   r   r   r   shutdown5   s    z_Runtime.shutdownc                 C   s   |    | jS )zQ
        Return the Library object containing the various NRT functions.
        )r   r   r   r   r   r   library=   s    z_Runtime.libraryc                 C   s   |    t||}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   dataZpyobjmir   r   r   r"   E   s    z_Runtime.meminfo_newFc                 C   sb   |    |dk r$d| d}t||r4t|}n
t|}|dkrZd| 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   Zmeminfo_alloc_safememinfo_allocMemoryErrorr#   )r   sizesafer   r%   r   r   r   r(   O   s    

z_Runtime.meminfo_allocc                 C   s    t t t t t dS )zw
        Returns a namedtuple of (alloc, free, mi_alloc, mi_free) for count of
        each memory operations.
        )r   r   r   r   )_nrt_mstatsr   Zmemsys_get_stats_allocZmemsys_get_stats_freeZmemsys_get_stats_mi_allocZmemsys_get_stats_mi_freer   r   r   r   get_allocation_statsf   s
    z_Runtime.get_allocation_statsN)F)__name__
__module____qualname__r   r   r   r   staticmethodr    propertyr!   r"   r(   r-   r   r   r   r   r      s   




r   c                 C   s   t t jS )N)r   ZMemInfoPointerZvoidptr)valcr   r   r   typeof_meminfov   s    r5   N)collectionsr   weakrefr   Z	_finalizeZnumba.core.runtimer   Zllvmliter   r   Znumba.core.compiler_lockr   Znumba.core.typing.typeofr   Z
numba.corer   r	   r
   r   r,   objectr   Z_MemInfor#   registerr5   Zmemsys_use_cpython_allocatorZrtsysr    r   r   r   r   <module>   s    d
