ó
\K]c           @   sx   d  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 „  ƒ Z
 e d „  ƒ Z d	 S(
   s6   
Helpers to see the refcount information of an object
iÿÿÿÿ(   t   ir(   t   types(   t   cgutils(   t	   intrinsic(   t   _meminfo_struct_typec         C   s"   d „  } t  j | ƒ } | | f S(   s   Dump the refcount of an object to stdout.

    Returns True if and only if object is reference-counted and NRT is enabled.
    c         S   sd  | \ } | j  \ } g  } |  j rL |  j j | | | ƒ } | j | ƒ n  | rY|  j | ƒ } | j ƒ  }	 | j d j | ƒ ƒ x² | D]ª \ } }
 | j	 |
 t
 j ƒ  ƒ } t j | | d d ƒ } | j | ƒ } | j d j | ƒ ƒ | j | t j d ƒ ƒ } t j | d d j | ƒ | ƒ } | j | ƒ qŠ W| j d ƒ | j |	 ƒ t j St j Sd  S(   Ns   dump refct of {}i    s    | {} refct=i    i   s   %ds   ;
(   t   argst
   enable_nrtt   nrtt   get_meminfost   extendt   get_python_apit
   gil_ensuret   print_stringt   formatt   bitcastR   t
   as_pointerR   t   gep_inboundst   loadt   truncR    t   IntTypet   snprintf_stackbuffert   sys_write_stdoutt   gil_releaset   true_bitt	   false_bit(   t   contextt   buildert	   signatureR   t   objt   tyt   meminfost   tmp_mist   pyapit	   gil_statet   mit   miptrt   refctptrt   refctt   refct_32bitt   printed(    (    s4   lib/python2.7/site-packages/numba/unsafe/refcount.pyt   codegen   s.    		(   R   t   bool_(   t	   typingctxR   R(   t   sig(    (    s4   lib/python2.7/site-packages/numba/unsafe/refcount.pyt   dump_refcount   s    	!c         C   s"   d „  } t  j | ƒ } | | f S(   sU   Get the current refcount of an object.

    FIXME: only handles the first object
    c         S   sá   | \ } | j  \ } g  } |  j rL |  j j | | | ƒ } | j | ƒ n  g  } | rÙ x~ | D]s \ } }	 | j |	 t j ƒ  ƒ }
 t j	 | |
 d d ƒ } | j
 | ƒ } | j | t j d ƒ ƒ } | j | ƒ q_ Wn  | d S(   Ni    i    (   R   R   R   R   R	   R   R   R   R   R   R   R   R    R   t   append(   R   R   R   R   R   R   R   R   t	   refcountsR"   R#   R$   R%   R&   (    (    s4   lib/python2.7/site-packages/numba/unsafe/refcount.pyR(   >   s    		(   R   t   int32(   R*   R   R(   R+   (    (    s4   lib/python2.7/site-packages/numba/unsafe/refcount.pyt   get_refcount8   s    	N(   t   __doc__t   llvmliteR    t   numbaR   R   t   numba.extendingR   t   numba.runtime.nrtdynmodR   R,   R0   (    (    (    s4   lib/python2.7/site-packages/numba/unsafe/refcount.pyt   <module>   s   +