U
    ?h
  ã                   @   sT   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 edd„ ƒZ
edd	„ ƒZd
S )z6
Helpers to see the refcount information of an object
é    )Úir)ÚtypesÚcgutils)Ú	intrinsic)Ú_meminfo_struct_typec                 C   s   dd„ }t  |¡}||fS )zDump the refcount of an object to stdout.

    Returns True if and only if object is reference-counted and NRT is enabled.
    c                 S   sò   |\}|j \}g }| jr2| j |||¡}| |¡ |rè|  |¡}| ¡ }	| d |¡¡ |D ]p\}}
| 	|
t
 ¡ ¡}t ||dd¡}| |¡}| d |¡¡ | |t d¡¡}t |dd||¡}| |¡ q\| d¡ | |	¡ tjS tjS d S )Nzdump refct of {}r   z | {} refct=é    é   z%d [%p]z;
)ÚargsÚ
enable_nrtÚnrtÚget_meminfosÚextendZget_python_apiZ
gil_ensureZprint_stringÚformatÚbitcastr   Ú
as_pointerr   Úgep_inboundsÚloadÚtruncr   ÚIntTypeZsnprintf_stackbufferZsys_write_stdoutZgil_releaseZtrue_bitZ	false_bit)ÚcontextÚbuilderÚ	signaturer	   ÚobjÚtyÚmeminfosÚtmp_misZpyapiZ	gil_stateÚmiÚmiptrÚrefctptrÚrefctÚrefct_32bitZprinted© r!   úL/var/www/html/venv/lib/python3.8/site-packages/numba/core/unsafe/refcount.pyÚcodegen   s8    


    ÿ

zdump_refcount.<locals>.codegen)r   Zbool_©Z	typingctxr   r#   Úsigr!   r!   r"   Údump_refcount   s    !
r&   c                 C   s   dd„ }t  |¡}||fS )zUGet the current refcount of an object.

    FIXME: only handles the first object
    c                 S   s–   |\}|j \}g }| jr2| j |||¡}| |¡ g }|rŽ|D ]N\}}	| |	t ¡ ¡}
t 	||
dd¡}| 
|¡}| |t d¡¡}| |¡ q>|d S )Nr   r   )r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   Úappend)r   r   r   r	   r   r   r   r   Z	refcountsr   r   r   r   r    r!   r!   r"   r#   =   s    

zget_refcount.<locals>.codegen)r   Zint32r$   r!   r!   r"   Úget_refcount7   s    
r(   N)Ú__doc__Zllvmliter   Z
numba.corer   r   Znumba.core.extendingr   Znumba.core.runtime.nrtdynmodr   r&   r(   r!   r!   r!   r"   Ú<module>   s   
*