ó
\K]c           @` s  d  d l  m Z m Z 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 d  d	 l m Z d d
 l m Z e d d d d d g  Z d e f d     YZ e j Z e j e  d    Z e j   e   Z e e e j  [ d S(   i    (   t   print_functiont   absolute_importt   division(   t
   namedtuplei   (   t	   nrtdynmod(   t   binding(   t   finalize(   t   global_compiler_lock(   t   typeof_impl(   t   types(   t   _nrt_pythont
   nrt_mstatst   alloct   freet   mi_alloct   mi_freet   _Runtimec           B` se   e  Z d    Z e d    Z d   Z e d    Z e d    Z	 d   Z
 e d  Z d   Z RS(   c         C` s   t  |  _ d  S(   N(   t   Falset   _init(   t   self(    (    s0   lib/python2.7/site-packages/numba/runtime/nrt.pyt   __init__   s    c         C` sĖ   |  j  r d Sx8 t j D]- } d | } t j | } t j | |  q Wt j |  |  _ |  j j d  |  _	 |  j j d  |  _
 |  j j d  |  _ t j |  j	 |  j
  t j |  j  t |  _  d S(   s   Initializes the NRT

        Must be called before any actual call to the NRT API.
        Safe to be called multiple times.
        Nt   NRT_t   nrt_atomic_addt   nrt_atomic_subt   nrt_atomic_cas(   R   t   _nrtt	   c_helperst   llt
   add_symbolR   t   compile_nrt_functionst   _libraryt   get_pointer_to_functiont   _ptr_inct   _ptr_dect   _ptr_cast   memsys_set_atomic_inc_dect   memsys_set_atomic_cast   True(   R   t   ctxt   py_namet   c_namet	   c_address(    (    s0   lib/python2.7/site-packages/numba/runtime/nrt.pyt
   initialize   s    	
c         C` s"   |  j  s d } t |   n  d  S(   Ns'   Runtime must be initialized before use.(   R   t   RuntimeError(   R   t   msg(    (    s0   lib/python2.7/site-packages/numba/runtime/nrt.pyt   _init_guard3   s    	c           C` s   t  j   d S(   se   
        Shutdown the NRT
        Safe to be called without calling Runtime.initialize first
        N(   R   t   memsys_shutdown(    (    (    s0   lib/python2.7/site-packages/numba/runtime/nrt.pyt   shutdown8   s    c         C` s   |  j    |  j S(   sQ   
        Return the Library object containing the various NRT functions.
        (   R-   R   (   R   (    (    s0   lib/python2.7/site-packages/numba/runtime/nrt.pyt   library@   s    
c         C` s&   |  j    t j | |  } t |  S(   sŌ   
        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   t   meminfo_newt   MemInfo(   R   t   datat   pyobjt   mi(    (    s0   lib/python2.7/site-packages/numba/runtime/nrt.pyR1   H   s    
c         C` s;   |  j    | r" t j |  } n t j |  } t |  S(   s­  
        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-   R   t   meminfo_alloc_safet   meminfo_allocR2   (   R   t   sizet   safeR5   (    (    s0   lib/python2.7/site-packages/numba/runtime/nrt.pyR7   R   s
    

c      	   C` s7   t  d t j   d t j   d t j   d t j    S(   sw   
        Returns a namedtuple of (alloc, free, mi_alloc, mi_free) for count of
        each memory operations.
        R   R   R   R   (   t   _nrt_mstatsR   t   memsys_get_stats_alloct   memsys_get_stats_freet   memsys_get_stats_mi_alloct   memsys_get_stats_mi_free(   R   (    (    s0   lib/python2.7/site-packages/numba/runtime/nrt.pyt   get_allocation_statsc   s    (   t   __name__t
   __module__R   R   R*   R-   t   staticmethodR/   t   propertyR0   R1   R   R7   R?   (    (    (    s0   lib/python2.7/site-packages/numba/runtime/nrt.pyR      s   			
c         C` s   t  j t  j  S(   N(   R	   t   MemInfoPointert   voidptr(   t   valt   c(    (    s0   lib/python2.7/site-packages/numba/runtime/nrt.pyt   typeof_meminfos   s    N(    t
   __future__R    R   R   t   collectionsR   t    R   t   llvmliteR   R   t   numba.utilsR   t	   _finalizet   numba.compiler_lockR   t   numba.typing.typeofR   t   numbaR	   R
   R   R:   t   objectR   t   _MemInfoR2   t   registerRH   t   memsys_use_cpython_allocatort   rtsysR/   (    (    (    s0   lib/python2.7/site-packages/numba/runtime/nrt.pyt   <module>   s    _	
	