ok

Mini Shell

Direktori : /opt/alt/python38/lib64/python3.8/site-packages/cffi/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/site-packages/cffi/__pycache__/recompiler.cpython-38.pyc

U

ل=^��@sddlZddlZddlZddlmZmZddlmZddlTdZ	dZ
dZGd	d
�d
�ZGdd�d�Z
Gd
d�d�ZGdd�d�ZGdd�d�ZGdd�d�Zejdkr�ejZnGdd�dej�Zdd�Zd.dd�Zd/dd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd0d,d-�ZdS)1�N�)�ffiplatform�model)�VerificationError)�*i&i'i(c@s&eZdZd	dd�Zdd�Zdd�ZdS)
�
GlobalExprrcCs"||_||_||_||_||_dS�N)�name�address�type_op�size�check_value)�selfr	r
rrr
�r�/recompiler.py�__init__s
zGlobalExpr.__init__cCsd|j|j|j��|jfS)Nz'  { "%s", (void *)%s, %s, (void *)%s },)r	r
r�	as_c_exprr�rrrrrs�zGlobalExpr.as_c_exprcCsd|j��|j|jfS)Nz
b'%s%s',%d)r�as_python_bytesr	r
rrrr�as_python_exprs�zGlobalExpr.as_python_exprN)rr��__name__�
__module__�__qualname__rrrrrrrrs
rc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�	FieldExprcCs"||_||_||_||_||_dSr)r	�field_offset�
field_size�fbitsize�
field_type_op)rr	rrrrrrrrs
zFieldExpr.__init__cCs>dt|j�}d|j|jfd||jfd||j��fS)N� z  { "%s", %s,
z     %s   %s,
z     %s   %s },)�lenr	rrrr)rZspacesrrrr#s��zFieldExpr.as_c_exprcCst�dSr)�NotImplementedErrorrrrrr)szFieldExpr.as_python_exprcCsD|jjtkrd}n|jjtkr*t|j�}nt�d|j��||jfS)N�z	b'%s%s%s')	r�op�OP_NOOP�OP_BITFIELD�format_four_bytesrr!rr	)rZ	size_exprrrr�as_field_python_expr,s
�zFieldExpr.as_field_python_exprN)rrrrrrr'rrrrrsrc@s$eZdZdd�Zdd�Zdd�ZdS)�StructUnionExprc		Cs4||_||_||_||_||_||_||_||_dSr)r	�
type_index�flagsr�	alignment�comment�first_field_index�c_fields)	rr	r)r*rr+r,r-r.rrrr8szStructUnionExpr.__init__cCsPd|j|j|jfd|j|jfd|jt|j�f|jrFd|jnddS)Nz  { "%s", %d, %s,z
    %s, %s, z%d, %d z	/* %s */ r"z},)	r	r)r*rr+r-r r.r,rrrrrCs����zStructUnionExpr.as_c_exprcCs>t|jt�}dd�|jD�}dt|j�t|�|jd�|�fS)NcSsg|]}|���qSr)r')�.0Zc_fieldrrr�
<listcomp>Ls�z2StructUnionExpr.as_python_expr.<locals>.<listcomp>z(b'%s%s%s',%s)�,)�evalr*ZG_FLAGSr.r&r)r	�join)rr*Zfields_exprrrrrJs��zStructUnionExpr.as_python_exprNrrrrrr(7sr(c@s$eZdZdd�Zdd�Zdd�ZdS)�EnumExprcCs"||_||_||_||_||_dSr�r	r)r�signed�allenums)rr	r)rr6r7rrrrUs
zEnumExpr.__init__cCsd|j|j|j|j|jfS)Nz1  { "%s", %d, _cffi_prim_int(%s, %s),
    "%s" },r5rrrrr\s��zEnumExpr.as_c_exprc	Cs@ttttttttd�|j|j	f}dt
|j�t
|�|j|j
fS)N))rr)rr)�r)r8r)�r)r9r)�r)r:rzb'%s%s%s\x00%s')Z
PRIM_UINT8Z	PRIM_INT8ZPRIM_UINT16Z
PRIM_INT16ZPRIM_UINT32Z
PRIM_INT32ZPRIM_UINT64Z
PRIM_INT64rr6r&r)r	r7)r�
prim_indexrrrras �
�
�zEnumExpr.as_python_exprNrrrrrr4Tsr4c@s$eZdZdd�Zdd�Zdd�ZdS)�TypenameExprcCs||_||_dSr�r	r))rr	r)rrrrmszTypenameExpr.__init__cCsd|j|jfS)Nz  { "%s", %d },r=rrrrrqszTypenameExpr.as_c_exprcCsdt|j�|jfS)Nzb'%s%s')r&r)r	rrrrrtszTypenameExpr.as_python_exprNrrrrrr<lsr<c@s�eZdZdZd�dd�Zdd�Zdd�Zd	d
�Zdd�Zd
ddddgZ	dd�Z
d�dd�Zdd�Zdd�Z
dd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Zd=d>�Zd?d@�Z d�dBdC�Z!dDdE�Z"dFdG�Z#dHdI�Z$e$Z%dJdK�Z&dLdM�Z'e'Z(dNdO�Z)e)Z*dPdQ�Z+dRdS�Z,dTdU�Z-d�dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2d�dadb�Z3dcdd�Z4dedf�Z5dgdh�Z6didj�Z7dkdl�Z8dmdn�Z9dodp�Z:dqdr�Z;dsdt�Z<dudv�Z=e=Z>Z?dwdx�Z@dydz�ZAd{d|�ZBd}d~�ZCdd��ZDeDZEZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMeMZNeMZOd�d��ZPd�d��ZQd�d��ZReRZSd�d��ZTdAS)��
RecompilerrFcCs||_||_||_t|_dSr)�ffi�module_name�target_is_python�VERSION_BASE�_version)rr?r@rArrrr~szRecompiler.__init__cCst|j|�|_dSr)�maxrC)rZverrrr�
needs_version�szRecompiler.needs_versionc	Cs.i|_|�d�t|jtd�}g|_|D]�}|jr(|j|dksDt�t|j�|j|<|j�|�|j	D]P}t
|tjtj
tjtjtjf�s�t�|j|dkr�t|j�|j|<|j�|�qf|j�d�q(|D]P}|js�|j|dkr�t|j�|j|<|j�|�|jr�|jdk	r�|j�d�q�d|j��k�s0t�i|_i|_|D]8}t
|tj��r^d|j|<nt
|tj��r@d|j|<�q@tt|jdd�d��D]\}}||j|<�q�tt|jdd�d��D]\}}||j|<�q�|D](}t|d|jj�}|||j|��q�|jD]}t
|t��st��qt|j�|_dS)	NZcollecttype��keyZEND�LENcSs|jSr�r	��tprrr�<lambda>��z/Recompiler.collect_type_table.<locals>.<lambda>cSs|jSrrIrJrrrrL�rMZ_emit_bytecode_)�
_typesdict�	_generate�sorted�str�
cffi_typesZis_raw_function�AssertionErrorr �append�args�
isinstancer�VoidType�BasePrimitiveType�PointerType�StructOrUnionOrEnum�FunctionPtrTypeZ
is_array_type�length�values�_struct_unions�_enums�
StructOrUnion�EnumType�	enumerate�getattr�	__class__r�CffiOp�tuple)rZ	all_declsrK�tp1�i�methodr#rrr�collect_type_table�s`

�
��
zRecompiler.collect_type_tablecCs�t|tj�s.t|t�r*|D]}|�|�qdS||jkr�d|j|<t|tj�r^|�|���nlt|tj�r�|j	dk	r�||j
jjkr�|�
�D] \}}}}|�|�|||��q�n|��D]\}}|�|�q�dSr)rVrZBaseTypeByIdentityrf�_do_collect_typerNr[�as_raw_functionr`�fldtypesr?�_parser�_included_declarations�
enumfields�_field_typeZ
_get_items)rrK�xZname1rg�_rrrrk�s"



�zRecompiler._do_collect_typec
Cs�|jjj��}t|�D]�\}\}}|�dd�\}}zt|d||f�}Wn tk
rhtd|��YnXz||_	|||�Wqt
k
r�}	zt�|	|��W5d}	~	XYqXqdS)Nrrz_generate_cpy_%s_%sz"not implemented in recompile(): %r)
r?rnZ
_declarations�itemsrP�splitrc�AttributeErrorr�_current_quals�	ExceptionrZattach_exception_info)
r�	step_name�lstr	rK�qualsZkindZrealnameri�errrrO�s"��
zRecompiler._generate�global�field�struct_union�enum�typenamecCs(i|_|jD]}g|j|<qt�|_|�d�|��|jD]4}|j|}|dkrb|jdd�d�t|�|j|<q<|jd}|j�	�D],\}}|t
|�ks�t�||j|jks�t�q�t
|�t
|j�ks�t�|jd}|j
�	�D],\}}|t
|�ks�t�||j|jks�t�q�t
|�t
|j
�k�s$t�dS)NZctxr~cSs|jSrrI)�entryrrrrL�rMz0Recompiler.collect_step_tables.<locals>.<lambda>rFrr�)�_lsts�	ALL_STEPS�set�_seen_struct_unionsrO�_add_missing_struct_unions�sortrfr^rtr rSr	r_)rryrzrKrhrrr�collect_step_tables�s*





zRecompiler.collect_step_tablesr"cCs|j�|d�dS)N�
)�_f�write)rZwhatrrr�_prntszRecompiler._prntcCs:|jr|dkst�|�|�n|dk	s*t�|�||�dSr)rArS�write_py_source_to_f�write_c_source_to_f)r�f�preamblerrr�write_source_to_fs
zRecompiler.write_source_to_fcCs0ttj�tj�t�|�d�}|��}|��|S)N�r)�open�os�pathr3�dirname�__file__�	readlines�close)r�filename�g�linesrrr�_rel_readlinesszRecompiler._rel_readlinesc	Csb||_|j}|jjdk	r |d�|�d�}|�d�}|�d�|||d�<|d�|��|j�d�d}|jjdk	�r0|d	|jf�|d
�|�	|jj�|d�|d�|d
|f�|d�|d|f�|d�|d|f�|d�|�d�}|�d�}|�d�|||d�<|d�|��|�
t�|d�|�||�|�|d�|�|d�tdd�|j
��D��}t|j�D]>\}}d}	||k�r�d||��}	|d||��|	f��q�|j�s�|d�|d�|�t�|_|�d�i}
|jD]`}|j|}t|�|
|<|
|dk�r�|d ||f�|D]}
||
����q:|d�|��q�|jj�r�|d!�|jjD]f}z|jdd"�\}}Wn(tk
�r�td#|j|f��YnX|dk�r�td$��|d%|f��qz|d&�|d�|�|d'�|d(�|jD].}|
|dk�r.|d)|�n|d*|��q|jD]$}|d+k�rD|d,|
||f��qD|jj�r~|d-�n|d.�|d/t|j�f�d}|j�r�|dO}|d0|�|d�|�|d1�|d2�|d�|�|d�|d3�|d4|f�|d5�|j�r,|d6�|d7�|d8�|d9|j�|d:�|d;�|d<�|d�|d=�|d>�|d?�|d@�|dA|f�|dB�|dC|f�|dD�|dD�|d�|d3�|dE|f�|d5�|dF|j|jf�|d=�|d�|d3�|dG|f�|d5�|dH|j|jf�|d=�|d�|�|d1�|dI�|d�d|_dS)JNz#define _CFFI_USE_EMBEDDINGz_cffi_include.hz#include "parse_c_type.h"
zparse_c_type.hrr"�.���z#define _CFFI_MODULE_NAME  "%s"z1static const char _CFFI_PYTHON_STARTUP_CODE[] = {z0 };z#ifdef PYPY_VERSIONz5# define _CFFI_PYTHON_STARTUP_FUNC  _cffi_pypyinit_%sz#elif PY_MAJOR_VERSION >= 3z-# define _CFFI_PYTHON_STARTUP_FUNC  PyInit_%s�#elsez*# define _CFFI_PYTHON_STARTUP_FUNC  init%s�#endifz_embedding.hz#include "_cffi_errors.h"
z_cffi_errors.hz>/************************************************************/zstatic void *_cffi_types[] = {cSsg|]\}}||f�qSrr�r/rKrhrrrr0Gsz2Recompiler.write_c_source_to_f.<locals>.<listcomp>z // z/* %2d */ %s,%sz  0z};�declrz.static const struct _cffi_%s_s _cffi_%ss[] = {z.static const char * const _cffi_includes[] = {r8�Qffi object %r includes %r, but the latter has not been prepared with set_source()zMnot implemented yet: ffi.include() of a Python-based ffi inside a C-based ffiz  "%s",z  NULLz?static const struct _cffi_type_context_s _cffi_type_context = {z  _cffi_types,z  _cffi_%ss,z  NULL,  /* no %ss */r~z  %d,  /* num_%ss */z  _cffi_includes,z  NULL,  /* no includes */z  %d,  /* num_types */z  %d,  /* flags */z#ifdef __GNUC__z?#  pragma GCC visibility push(default)  /* for -fvisibility= */ZPyMODINIT_FUNCz"_cffi_pypyinit_%s(const void *p[])�{z%    if (((intptr_t)p[0]) >= 0x0A03) {zQ        _cffi_call_python_org = (void(*)(struct _cffi_externpy_s *, char *))p[1];z    }z    p[0] = (const void *)0x%x;z    p[1] = &_cffi_type_context;z#if PY_MAJOR_VERSION >= 3�    return NULL;�}z#  ifdef _MSC_VERz     PyMODINIT_FUNCz#  if PY_MAJOR_VERSION >= 3z%     PyInit_%s(void) { return NULL; }z#  elsez     init%s(void) { }z#  endifzPyInit_%s(void)z5  return _cffi_init("%s", 0x%x, &_cffi_type_context);zinit%s(void)z.  _cffi_init("%s", 0x%x, &_cffi_type_context);z#  pragma GCC visibility pop)r�r�r?�
_embeddingr��indexr3r@ru�_print_string_literal_in_arrayrE�VERSION_EMBEDDED�dictrNrtrbrR�_get_c_namerr��_seen_constantsrOr�r�r �_included_ffis�_assigned_sourcervr�
_num_externpyrC)rr�r��prntr�rhZbase_module_name�typeindex2typer#r,Znumsryrzr��ffi_to_include�included_module_name�included_sourcer*rrrr�s6

���






�

�
���

�




��zRecompiler.write_c_source_to_fcsbt|t�rd|fSt|ttf�rZ�fdd�|D�}t|�dkrJ|�d�dd�|�fS|��S)Nzb'%s'csg|]}��|��qSr)�_to_py)r/�itemrrrr0�sz%Recompiler._to_py.<locals>.<listcomp>rr"z(%s)r1)rVrQ�listrfr rTr3r)rrrZreprrrr��s


zRecompiler._to_pyc	Cs�||_|j}|d�|d�t|jjp(d�}t|�D]n}|jj|}z|jdd�\}}Wn&tk
r�td|j|f��YnX|dk	r�td��|d||f�q4|�|d|j	f�|d	|j
f�d|_
t|j�|_d
d�|jD�}|d|�
d
�|��f�tdd�|j��D��}	|jD]>}
|j|
}t|�dk�r$|
dk�r$|d|
|�
|�f��q$|dk�r�|dd�dd�t|�D��f�|d�dS)Nz# auto-generated filezimport _cffi_backendrr8r�zMnot implemented yet: ffi.include() of a C-based ffi inside a Python-based ffizfrom %s import ffi as _ffi%dzffi = _cffi_backend.FFI('%s',z    _version = 0x%x,cSsg|]}|���qSr)r)r/r#rrrr0�sz3Recompiler.write_py_source_to_f.<locals>.<listcomp>z    _types = %s,r"cSsg|]\}}||f�qSrrr�rrrr0�srr~z    _%ss = %s,z    _includes = (%s,),�, cSsg|]}d|�qS)z_ffi%dr�r/rhrrrr0�s�))r�r�r r?r��ranger�rvrr@rCrfrRr�r3r�rNrtr�r�)rr�r�Znum_includesrhr�r�r�Z	types_lstr�ryrzrrrr��sP�
���
�


�zRecompiler.write_py_source_to_fcCs
|j|Sr)rN)r�typerrr�_gettypenumszRecompiler._gettypenumc	Csnd}t|tj�r�|��s�|��r:|jdkr:d}d|j}nPt|tj�rXd|�d�f}n2|�d�}d||j�dd�f}|d	kr�|�	t
�d
}n�t|tj�r�|�||||�dSt|tj
�s�t|tj�r�|�d||�|�|f�|�d|�dSt|tj��r$d
|�d�}d|�|�}d}nt|��|�d||||f�|�d||�d�|f�|�d|�dS)Nr"�_BoolZ_cffi_to_c_intz, %sz(%s)_cffi_to_c_doublez(%s)_cffi_to_c_%srrs�Zchar16_tZchar32_tz-1z6  if (_cffi_to_c((char *)&%s, _cffi_type(%d), %s) < 0)z    %s;z(%s)_cffi_to_c_pointerz, _cffi_type(%d)ZNULLz  %s = %s(%s%s);z'  if (%s == (%s)%s && PyErr_Occurred()))rVrrX�is_complex_type�is_integer_typer	�UnknownFloatType�
get_c_name�replacerE�VERSION_CHAR16CHAR32rY�"_convert_funcarg_to_c_ptr_or_arrayrZr�r�r[r!)	rrK�fromvar�tovar�errcodeZextraargZ	converter�cnameZerrvaluerrr�_convert_funcarg_to_csP
�
�
���z Recompiler._convert_funcarg_to_ccCs.t|tj�r*|�d�|�d�|�d�dS)NzPy_ssize_t datasizez-struct _cffi_freeme_s *large_args_free = NULLzIif (large_args_free != NULL) _cffi_free_array_arguments(large_args_free);)rVrrY�add)rrK�	localvars�	freelinesrrr�_extra_local_variables3s

z!Recompiler._extra_local_variablescCs�|�d�|�d|�|�||f�|�d�|�d||�d�f�|�d|�|�||f�|�d�|�d|�|�d	�dS)
Nz1  datasize = _cffi_prepare_pointer_call_argument(z(      _cffi_type(%d), %s, (char **)&%s);z  if (datasize != 0) {zI    %s = ((size_t)datasize) <= 640 ? (%s)alloca((size_t)datasize) : NULL;r"zF    if (_cffi_convert_array_argument(_cffi_type(%d), %s, (char **)&%s,z,            datasize, &large_args_free) < 0)z	      %s;z  })r�r�r�)rrKr�r�r�rrrr�:s$
�
���
z-Recompiler._convert_funcarg_to_c_ptr_or_arraycCsJt|tj�r�|��r,|jdkr,d||jfSt|tj�rBd|fS|jdkr�|��s�|j�dd�}|dkrt|�t	�d||fSd	||�
|�fSn�t|tjtjf�r�d
||�
|�fSt|tj
�r�d
||�
t�|j��fSt|tj��r|jdk�rtd|��|f��d||�
|�fSt|tj��r>d	||�
|�fSt|��dS)
Nr�z_cffi_from_c_int(%s, %s)z_cffi_from_c_double(%s)�long doublerrsr�z_cffi_from_c_%s(%s)z/_cffi_from_c_deref((char *)&%s, _cffi_type(%d))z0_cffi_from_c_pointer((char *)%s, _cffi_type(%d))z!'%s' is used as %s, but is opaquez0_cffi_from_c_struct((char *)&%s, _cffi_type(%d)))rVrrXr�r	r�r�r�rEr�r�rYr[�	ArrayTyper�r`Zfldnames�	TypeErrorr�rar!)rrK�var�contextr�rrr�_convert_expr_from_cHsP

������zRecompiler._convert_expr_from_ccCs|�|d|f�S)Nz
(*(%s *)0))�_global_type�rrKr	rrr�
_typedef_typekszRecompiler._typedef_typecCs|�|�||��dSr)rkr�r�rrr�!_generate_cpy_typedef_collecttypensz,Recompiler._generate_cpy_typedef_collecttypecCsdSrrr�rrr�_generate_cpy_typedef_declqsz%Recompiler._generate_cpy_typedef_declcCs$|j|}|jd�t||��dS)Nr�)rNr�rTr<)rrKr	r)rrr�_typedef_ctxts
zRecompiler._typedef_ctxcCsf|�||�}|�||�t|dd�dkr<|j||jdd�n&t|tj�rb|j|j|jj|j|d�dS)N�originZunknown_type)�
approxname)r��	named_ptr)	r�r�rc�_struct_ctxr	rVrZNamedPointerType�totyper�rrr�_generate_cpy_typedef_ctxxs�z$Recompiler._generate_cpy_typedef_ctxcCs(|�|���|jr$|js$|�|�dSr)rkrl�ellipsisrAr�rrr�"_generate_cpy_function_collecttype�sz-Recompiler._generate_cpy_function_collecttypec	Cs |jr
t�t|tj�st�|jr0|�||�dS|j}t|j	�}|dkrNd}n|dkr\d}nd}g}g}d|}t
|j	�D],\}	}
|�|
�d|	|��|�d|	�qzd	�
|�}|p�d
}|jr�|jd}nd}d
|||f}
|d|j�|
�f�|d�d	�
|�}d}t|jtj��rd}|d|||f�|d�|d�|d�|d||f�|d�d|}t
|j	�D]&\}	}
|
�d|	|�}|d|��qrt�}t�}|j	D]}
|�|
||��q�t|�D]}|d|f��q�t|jtj��s d}d|}d|j�d|�}||�|d�nd}d}t|j	�dk�r�tt|j	��}|D]}	|d|	��qJ|�|d|t|�t|�d	�
dd�|D��f�|d�|�t
|j	�D](\}	}
|�|
d |	d|	d!�|��q�|d"�|d#�d$d�tt|j	��D�}d	�
|�}|d%|||f�|d&�|d'�|�|d(�|dk�rF|d)�|�r�|d*|�|jd+d,��|D]}|d-|��qh|d.�n(|D]}|d-|��q�|d/�|d0�|d�|d1�d2d3�}d4}g}g}d|}t
|j	�D]P\}	}
d}||
��rd5}d6}|
�d7||	f|�}|�|�|�d8||	f��q�|j}||��rxd|}|�d9|�}|�d|�tj}d}d:}d6}|�r�d	�
|�}|�p�d
}d;|||f}
|d|�|
�f�|d�|�r�||�d	�
|�}|d%|||f�|�r�|d<�|d�n|d=||f�|d>�|�dS)?NrZnoargrZarg0rU�argument of %sz x%d�x%dr��voidrr"z%s_cffi_d_%s(%s)z	static %sr�zreturn z  %s%s(%s);r�z#ifndef PYPY_VERSIONzstatic PyObject *z(_cffi_f_%s(PyObject *self, PyObject *%s)z  %s;z	result = �result of %sz resultz  PyObject *pyresult;z  PyObject *arg%d;z1  if (!PyArg_UnpackTuple(args, "%s", %d, %d, %s))cSsg|]}d|�qS)z&arg%drr�rrrr0�sz:Recompiler._generate_cpy_function_decl.<locals>.<listcomp>r�zarg%dzreturn NULLz  Py_BEGIN_ALLOW_THREADSz  _cffi_restore_errno();cSsg|]}d|�qS)r�rr�rrrr0�sz  { %s%s(%s); }z  _cffi_save_errno();z  Py_END_ALLOW_THREADSz  (void)self; /* unused */z  (void)noarg; /* unused */z  pyresult = %s;�resultzresult typez  z  return pyresult;z  Py_INCREF(Py_None);z  return Py_None;r�cSs t|tj�pt|tj�o|��Sr)rVrr`�
PrimitiveTyper�)r�rrr�need_indirection�s�z@Recompiler._generate_cpy_function_decl.<locals>.need_indirectionFrTz %sx%dz%sx%dz *resultz
*result = z%s_cffi_f_%s(%s)z  return result;z#  define _cffi_f_%s _cffi_d_%sr�)rArSrVrr[r��_generate_cpy_constant_declr�r rUrbrTr�r3�abir�rWr�r�rPr�r�r��insertZ	void_type)rrKr	r��numargs�argname�	argumentsZcall_argumentsr�rhr��repr_argumentsr��name_and_argumentsZresult_code�argr�r�r�Zresult_decl�rngZfreeliner��
differenceZindirectionZ	tp_resultrrr�_generate_cpy_function_decl�s





��


�





�

z&Recompiler._generate_cpy_function_declcCs�|jr|js|�||�dS|j|��}t|j�}|jr@t}n |dkrNt}n|dkr\t	}nt
}|jd�t
|d|t||�d|d��dS)Nrrr}z
_cffi_f_%sz
_cffi_d_%s)r)r�rA�_generate_cpy_constant_ctxrNrlr rUZOP_DLOPEN_FUNCZOP_CPYTHON_BLTN_NZOP_CPYTHON_BLTN_OZOP_CPYTHON_BLTN_Vr�rTrre)rrKr	r)r�Z	meth_kindrrr�_generate_cpy_function_ctx+s$


��z%Recompiler._generate_cpy_function_ctxcCsTt|tj�rP|j}|dkr0|�d�}d||f}|�|d||j�}t�||�}|S)N�...rz_cffi_array_len(((%s)0)->%s)�%s[0])rVrr�r\r�rqr�)rZ	tp_structZ
field_nameZtp_field�
actual_lengthZptr_struct_name�tp_itemrrrrqAs
��zRecompiler._field_typecCs,|�|�|jr(|��D]}|�|�qdSr)rkrA�anonymous_struct_fields�_struct_collecttype)rrK�fldtyperrrrMs
zRecompiler._struct_collecttypecCs>|jdkrdS|j}d|f}|d�|d||f�|d�|d�|d�|��D]�\}}}}	z�|��st|dkr�|dkr�|d	|||f�WqVt|tj�r�|jdks�|jd
kr�|j}|d}q�|d|j	d
d||	d�|f�WqVt
k
�r}
z|dt|
��W5d}
~
XYqVXqV|d�|d||f�|�dS)Nz_cffi_checkfld_%sZ_CFFI_UNUSED_FNzstatic void %s(%s *p)r�z8  /* only to generate compile-time warnings or errors */z
  (void)p;rr"z>  (void)((p->%s) | 0);  /* check that '%s.%s' is an integer */r�z[0]z  { %s = &p->%s; (void)tmp; }z*tmpzfield %r�r{z
  /* %s */r�z(struct _cffi_align_%s { char x; %s y; };)rmr�rpr�rVrr�r\r�r�rrQ)rrKr�r�r�Z
checkfuncnameZfnameZftyper�fqualr|rrr�_struct_declTsB

���
�$zRecompiler._struct_declNcCs�|j|}d}g}t|tj�r(|�d�|jdkr@|�d�d}||jjjkr�|dksd||jjjkr�|jdkrpn|j	s�t
|���r�n
|�d�|jr�|jdkr�t
d||jf��|�d�n|�d�d	}d
�|�p�d}g}|dk�rr|j}	t|�|	��}
|
D�]\}}}
}|�|||�}|�|d|j|f�t}|
d
k�rNt}d|
}nL|dk�srt|tj��rx|jdk�rxd}n"d|dk�r�|�d�n|j|f}|dk�s�|
d
k�r�d}n,|dk	�r�d|j|f}nd|�d�|f}|�t||||
t||j|����qt|jd�}|jd�|�|dk�r<d}d}d}n4|dk	�rXd|jf}d}nd|f}d|f}d}nd}d}d}|}|jd�t|j|||||||��|j �!|�dS)NZ
_CFFI_F_UNIONZ_CFFI_F_OPAQUEZopaqueZ_CFFI_F_CHECK_FIELDSrz�%r is declared with 'pack=%r'; only 0 or 1 are supported in API mode (try to use "...;", which does not require a 'pack' declaration)Z_CFFI_F_PACKEDZ_CFFI_F_EXTERNALZexternal�|�0z
field '%s.%s'rz
%d /* bits */z
(size_t)-1zsizeof(((%s)0)->%s)rz"((char *)&((%s)0)->%s) - (char *)0zoffsetof(%s, %s)r"r~z
(size_t)-2���Zunnamedzsizeof(*(%s)0)z-1 /* unknown alignment */�
sizeof(%s)z"offsetof(struct _cffi_align_%s, y)r�r)"rNrVrZ	UnionTyperTrmr?rnro�partial�anyrZpackedr!r3rAr�rprq�_check_not_opaquer	r$r%r�r\r�rrer r��extendr(r�r�)rrKr�r�r�r)Zreason_for_not_expandingr*r.Zexpand_anonymous_struct_unionrpZfldnamerrrr#r�offsetr-Zalignr,rrrr�vs�



��


��

�



���
�
��




��zRecompiler._struct_ctxcCs:t|tj�r|j}qt|tj�r6|jdkr6td|��dS)Nz0%s is of an opaque type (not declared in cdef()))rVrr�r�r`rmr�)rrK�locationrrrr�s�zRecompiler._check_not_opaquecCs�t|j���}|jdd�d�|D]�\}}||jkr"|jrHtd|f��|j�d�rv|jdd��	�rv|jdd�}n4|jdkr�|j
dkr�d}|�|d�ntd	|f��|�|d|�q"dS)
NcSs|dS)Nrr)Ztp_orderrrrrL�rMz7Recompiler._add_missing_struct_unions.<locals>.<lambda>rFzDinternal inconsistency: %r is partial but was not seen at this point�$rZ_IO_FILE�FILEzinternal inconsistency: %r)
r�r^rtr�r�r
r!r	�
startswith�isdigitZ	forcenamer�r�)rrzrK�orderr�rrrr��s"
��z%Recompiler._add_missing_struct_unionscCs|�|�dSr)rr�rrr� _generate_cpy_struct_collecttype�sz+Recompiler._generate_cpy_struct_collecttypecCs2|�d�}d|kr"||�dd�fS|d|fSdS)Nr"rrs)r�r�)rrKr�rrr�
_struct_names�s
zRecompiler._struct_namescCs|j|f|�|���dSr)rrr�rrr�_generate_cpy_struct_decl�sz$Recompiler._generate_cpy_struct_declcCs|j|f|�|���dSr)r�rr�rrr�_generate_cpy_struct_ctx�sz#Recompiler._generate_cpy_struct_ctxcCs(t|tj�r|�||�n
|�|�dSr)rVrra�_generate_cpy_enum_collecttyperr�rrr�#_generate_cpy_anonymous_collecttypesz.Recompiler._generate_cpy_anonymous_collecttypecCs.t|tj�r|�|�n|�||d|�dS�NZtypedef_)rVrra�_generate_cpy_enum_declrr�rrr�_generate_cpy_anonymous_declsz'Recompiler._generate_cpy_anonymous_declcCs0t|tj�r|�||�n|�||d|�dSr)rVrra�	_enum_ctxr�r�rrr�_generate_cpy_anonymous_ctxsz&Recompiler._generate_cpy_anonymous_ctx�constcCs||f|jkrtd||f��|j�||f�|j}d||f}|r�|d|�|d�|d|f�|d||f�|dk	r�|dkr�d|f}|d	|f�|d
�|d�|d�n>|dks�t�|d
|�|d�|d|�d�|f�|d�|�dS)Nz duplicate declaration of %s '%s'z_cffi_%s_%sz$static int %s(unsigned long long *o)r�z  int n = (%s) <= 0;zI  *o = (unsigned long long)((%s) | 0);  /* check that %s is an integer */rz%dUz"  if (!_cffi_check_int(*o, n, %s))z    n |= 2;z  return n;r�zstatic void %s(char *o)z  *(%s)o = %s;r)r�rr�r�rSr�)r�is_intr	rK�categoryr
r��funcnamerrr�_generate_cpy_consts6
��

zRecompiler._generate_cpy_constcCs |��}|r|jr|�|�dSr)r�rArk�rrKr	r!rrr�"_generate_cpy_constant_collecttype5s
z-Recompiler._generate_cpy_constant_collecttypecCs|��}|�|||�dSr)r�r$r%rrrr�:sz&Recompiler._generate_cpy_constant_declcCs^|js|��rttd�}n$|jr&t}nt}|j|}t||�}|jd�t	|d||��dS)Nr�r}�_cffi_const_%s)
rAr�re�OP_CONSTANT_INTZOP_DLOPEN_CONSTZOP_CONSTANTrNr�rTr)rrKr	rZ
const_kindr)rrrr�>s


�z%Recompiler._generate_cpy_constant_ctxcCs|�|�dSr)rkr�rrrrNsz)Recompiler._generate_cpy_enum_collecttypecCs|jD]}|�d|�qdS)NT)�enumeratorsr$)rrKr	�
enumeratorrrrrQs
z"Recompiler._generate_cpy_enum_declc	Cs�|j|}ttd�}|jr"|��t|j|j�D](\}}|jd�	t
|d|||d��q0|dk	r�d|kr�|js�d|}d|}n4|�|jg�}	|j�
|	�}tt|j�|	d��dk�}d	�|j�}
|jd
�	t|j||||
��dS)Nr�r}r'�r
rr	z
((%s)-1) <= 0rr1r�)rNre�OP_ENUMrAZcheck_not_partial�zipr)Z
enumvaluesr�rTrZbuild_baseinttyper?Zsizeof�int�castr3r4r	)rrKr�r)rr*Z	enumvaluerr6Zbasetpr7rrrrUs(


��

�zRecompiler._enum_ctxcCs|�||���dSr)rr�r�rrr�_generate_cpy_enum_ctxjsz!Recompiler._generate_cpy_enum_ctxcCsdSrrr�rrr�_generate_cpy_macro_collecttypepsz*Recompiler._generate_cpy_macro_collecttypecCs&|dkrd}n|}|jd||d�dS)Nr�Tr+)r$)rrKr	r
rrr�_generate_cpy_macro_declssz#Recompiler._generate_cpy_macro_declcCsT|dkr"|jrtd|f��d}n|}ttd�}|jd�t|d|||d��dS)Nr�zGcannot use the syntax '...' in '#define %s ...' when using the ABI moder�r}r'r+)rArrer(r�rTr)rrKr	r
rrrr�_generate_cpy_macro_ctxzs��

��z"Recompiler._generate_cpy_macro_ctxcCsFt|tj�rB|j}|dkr$d|f}|�|jd|�}t�||�}|S)Nr�z_cffi_array_len(%s)r�)rVrr�r\r�r�)rrKZglobal_namer�r�rrrr��s
zRecompiler._global_typecCs|�|�||��dSr)rkr�r�rrr�"_generate_cpy_variable_collecttype�sz-Recompiler._generate_cpy_variable_collecttypecCs�|j}|�||�}t|tj�r4|jdkr4|j}d}nd}d|f}|d|j||jd��|d�|d||f�|d�|�dS)	Nr"�&z*_cffi_var_%s(void)�static rr�z  return %s(%s);r�)	r�r�rVrr�r\r�r�rw)rrKr	r�Z	ampersandr�rrr�_generate_cpy_variable_decl�s	
z&Recompiler._generate_cpy_variable_declcCsL|�||�}|j|}|jr"t}nt}|jd�t|d|t||���dS)Nr}z_cffi_var_%s)	r�rNrAZ
OP_GLOBAL_VARZOP_GLOBAL_VAR_Fr�rTrre)rrKr	r)r#rrr�_generate_cpy_variable_ctx�s

�z%Recompiler._generate_cpy_variable_ctxcCst|tj�st�|�|�dSr)rVrr[rSrkr�rrr�'_generate_cpy_extern_python_collecttype�sz2Recompiler._generate_cpy_extern_python_collecttypecCs|j}t|jtj�rd}nd|}d|j�d|�f}|d|�|d|j||f�|�g}d|}t|j�D]"\}}	|	�d||�}
|�	|
�qrd	�
|�}|p�d
}d||f}|jdkr�d
|}dd�}
tt
|j�dd�}|
|j�r�t|d�}t|jtj��r&d|j�d�||j�d�|f}|d||j�|�f�|d�|d|�|d�t|j�D]X\}}	d|}
t|	tj��s�|
|	��r�d|
}
t�|	�}	|d|	�d�|d|
f��qd|d|�t|jtj��s�|d|j�d�f�|d�|�|jd7_dS)Nrr�z(int)sizeof(%s)r"z3static struct _cffi_externpy_s _cffi_externpy__%s =z  { "%s.%s", %s, 0, 0 };r�z a%dr�r�z%s(%s)�	__stdcallz_cffi_stdcall cSst|tj�o|jdkS)Nr�)rVrr�r	rJrrr�may_need_128_bits�s�z9Recompiler._extern_python_decl.<locals>.may_need_128_bitsr:�z!sizeof(%s) > %d ? sizeof(%s) : %dz%s%sr�z
  char a[%s];z  char *p = a;za%dr5z  *(%s)(p + %d) = %s;rz,  _cffi_call_python(&_cffi_externpy__%s, p);z  return *(%s)p;r�r)r�rVr�rrWr�r@rbrUrTr3r�rDr r`rYr�)rrKr	Z
tag_and_spacer�Zsize_of_resultr�r�rhr�r�r�r�r;Z	size_of_arrr�_extern_python_decl�sj��





��
 zRecompiler._extern_python_declcCs|�||d�dS)Nr6�r=r�rrr� _generate_cpy_extern_python_decl�sz+Recompiler._generate_cpy_extern_python_declcCs|�||d�dS)NzCFFI_DLLEXPORT r>r�rrr�#_generate_cpy_dllexport_python_decl�sz.Recompiler._generate_cpy_dllexport_python_declcCs|�||d�dS)Nr"r>r�rrr�'_generate_cpy_extern_python_plus_c_decl�sz2Recompiler._generate_cpy_extern_python_plus_c_declcCsR|jrtd��|jrtd��|j|}tt|�}|jd�t	|d|||��dS)Nz,cannot use 'extern "Python"' in the ABI modez$a vararg function is extern "Python"r}z&_cffi_externpy__%s)
rArr�r!rNreZOP_EXTERN_PYTHONr�rTr)rrKr	r)rrrr�_generate_cpy_extern_python_ctxs�


�z*Recompiler._generate_cpy_extern_python_ctxcCsr|j}|d�|�d�D]T}|d|���d}|D].}t|�dkrP||�d}|dt|�f7}q4||�qdS)Nz=// # NB. this is not a string because of a size limit in MSVCTz// r"�Lz%d,)r��
splitlines�rstripr �ord)r�sr��lineZprinted_line�crrrr�sz)Recompiler._print_string_literal_in_arraycCsttt�|j|<dSr)re�OP_PRIMITIVEZ	PRIM_VOIDrR�rrKr�rrr�_emit_bytecode_VoidType sz"Recompiler._emit_bytecode_VoidTypecCst|j}tt|�|j|<dSr)ZPRIMITIVE_TO_INDEXr	rerJrR)rrKr�r;rrr�_emit_bytecode_PrimitiveType#s
z'Recompiler._emit_bytecode_PrimitiveTypecCs(d|j|j|jf}tt|�|j|<dS)Nzl_cffi_prim_int(sizeof(%s), (
           ((%s)-1) | 0 /* check that %s is an integer type */
         ) <= 0)�r	rerJrR�rrKr�rGrrr�!_emit_bytecode_UnknownIntegerType's�z,Recompiler._emit_bytecode_UnknownIntegerTypecCs$d|j|jf}tt|�|j|<dS)Nzd_cffi_prim_float(sizeof(%s) *
           (((%s)1) / 2) * 2 /* integer => 0, float => 1 */
         )rNrOrrr�_emit_bytecode_UnknownFloatType-s
�z*Recompiler._emit_bytecode_UnknownFloatTypecCs�tt|j|j�|j|<|d7}|jD]H}|j|}||krft|tj�rV|�	||�ntt
|�|j|<|d7}q&t|j�}|j
dk	r�|j
dkr�|dO}ntd|j
f��tt|�|j|<dS)Nrr:r8zabi=%r)reZOP_FUNCTIONrNr�rRrUrVrr�rMr$r.r�r�r!ZOP_FUNCTION_END)rrKr�rgZ	realindexr*rrr�_emit_bytecode_RawFunctionType3s






z)Recompiler._emit_bytecode_RawFunctionTypecCstt|j|j�|j|<dSr)re�
OP_POINTERrNr�rRrKrrr�_emit_bytecode_PointerTypeFsz%Recompiler._emit_bytecode_PointerTypecCs"|��}tt|j|�|j|<dSr)rlrerSrNrR)rrKr��rawrrr�_emit_bytecode_FunctionPtrTypeLsz)Recompiler._emit_bytecode_FunctionPtrTypecCs�|j|j}|jdkr(tt|�|j|<nf|jdkrNtdt|��dd�f��n@|j|ddksdt	�tt
|�|j|<tdt|j��|j|d<dS)Nr�zitype %s badly placed: the '...' array length can only be used on global arrays or on fields of structuresz/*...*/rrH)rNr�r\reZ
OP_OPEN_ARRAYrRrrQr�rSZOP_ARRAY)rrKr�Z
item_indexrrr�_emit_bytecode_ArrayTypePs

���z#Recompiler._emit_bytecode_ArrayTypecCs|j|}tt|�|j|<dSr)r^reZOP_STRUCT_UNIONrR)rrKr�Zstruct_indexrrr�_emit_bytecode_StructType^s
z$Recompiler._emit_bytecode_StructTypecCs|j|}tt|�|j|<dSr)r_rer,rR)rrKr�Z
enum_indexrrr�_emit_bytecode_EnumTypecs
z"Recompiler._emit_bytecode_EnumType)F)r")N)Nr N)N)Urrrr�rrErjrkrOr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rqrrr�rr�rZ_generate_cpy_union_collecttyperrZ_generate_cpy_union_declrZ_generate_cpy_union_ctxrrrr$r&r�r�rrrr0r1r2r3r�r4r7r8r9Z*_generate_cpy_dllexport_python_collecttypeZ._generate_cpy_extern_python_plus_c_collecttyper=r?r@rArBZ"_generate_cpy_dllexport_python_ctxZ&_generate_cpy_extern_python_plus_c_ctxr�rLrMrPrQrRrTZ_emit_bytecode_ConstPointerTypeZ_emit_bytecode_NamedPointerTyperVrWrXZ_emit_bytecode_UnionTyperYrrrrr>{s�
:
,
4-##"
W	�

	
�6
�r>)�cseZdZ�fdd�Z�ZS)�NativeIOcs(t|t�r|�d�}tt|��|�dS)N�ascii)rVZunicode�encode�superr[r�)rrG�rdrrr�ls

zNativeIO.write)rrrr��
__classcell__rrr_rr[ksr[c
Cs|rtd|f�t|||dkd�}|��|��t�}|�||�|��}zBt|d�� }|�t	|�d�|krvt
�W5QRX|r�td�WdSt
k
�rd|t��f}	t|	d��}|�
|�W5QRXzt�|	|�Wn,tk
�rt�|�t�|	|�YnXYd	SXdS)
Nz
generating %s)rAr�rz(already up-to-date)Fz%s.~%d�wT)�printr>rjr�r[r��getvaluer��readr �IOErrorr��getpidr��rename�OSError�unlink)
r?r@r�Ztarget_file�verboseZ
recompilerr��output�f1Ztmp_filerrr�_make_c_or_py_sourceqs6�
rmFcCs|dk	st�t|||||�Sr)rSrm)r?r@r�Z
target_c_filerjrrr�
make_c_source�s
�rncCst||d||�Sr)rm)r?r@Ztarget_py_filerjrrr�make_py_source�s
�rocCsj|�d�}z$t�tjj|f|dd����Wntk
rBYnX|d|7<tjj|f|��|fS)Nr�r�)rur��makedirsr�r3rh)Z	outputdir�modname�	extension�partsrrr�_modname_to_file�s
$rtcCs*t||�}|�|||f�t|||�|Sr)rcrT�setattr)�	patchlist�clsr	Znew_meth�oldrrr�_patch_meth�s
rycCs$t|�D]\}}}t|||�qdSr)�reversedru)rvrwr	Zold_methrrr�_unpatch_meths�sr{cs\tjdkr(ddlm}t||ddd��tjdkrXddlm}�fd	d
�}t||d|��dS)N�win32r)�MSVCCompilerZ_remove_visual_c_refcSs|Srr)rZ
manifest_filerrrrL�rMz&_patch_for_embedding.<locals>.<lambda>�darwin)�	CCompilercs<d|jkr,t|j�|_|j�d�}d|j|<�|f|�|�S)Nz-bundlez-dynamiclib)Z	linker_sor�r�)rrU�kwdsrh�Zold_link_shared_objectrr�my_link_shared_object�s


z3_patch_for_embedding.<locals>.my_link_shared_objectZlink_shared_object)�sys�platformZdistutils.msvc9compilerr}ryZdistutils.ccompilerr)rvr}rr�rr�r�_patch_for_embedding�s
�
�r�cslddlm}��d�rR�dd��tjdkr6�d7�ntjdkrJ�d7�n�d	7�t||d
�fdd��dS)
Nr)�	build_extz.*rr|z.dllr~z.dylibz.soZget_ext_filenamecs�Srr)rZext_name��targetrrrL�rMz#_patch_for_target.<locals>.<lambda>)Zdistutils.command.build_extr��endswithr�r�ry)rvr�r�rr�r�_patch_for_target�s





�r�r�T�.cc	Ks�t|t�s|�d�}|jr$|�|�|dk	�r^|jdk	}|rF|�|�|dkrzt|||�\}}
|rl|g|
}
tj	j
|
�}n|}|	dkr�|r�d|}	nd}	tj||f|�}t
|||||d�}|�rTg}t��}zn|r�t|�|	dkr�t||	�|�r|dk�rd}nd}td|tj	�|�f�t�|�t�d|||
�}W5t�|�t|�X|S||fSn<|dk�rxt||d	�\}}t||||d�}|�r�|Sd|fSdS)
Nr\z%s.*r)rjr�zthe current directory isz setting the current directory toz%s %rz.py)rVrQr]Z_windows_unicodeZ_apply_windows_unicoder�Z_apply_embedding_fixrtr�r�r3rZ
get_extensionrn�getcwd�chdirr{r�r�rb�abspath�compilero)r?r@r�ZtmpdirZcall_c_compilerZc_fileZsource_extensionZextradirZcompiler_verboser��debugr�Z	embeddingrsZ
ext_c_fileZext�updatedrv�cwd�msgZoutputfilenamersrrr�	recompile�sl





�


�


�



�r�)F)F)r�TNr�NrNN)r�r��ior"rr�errorrZcffi_opcoderBr�r�rrr(r4r<r>�version_info�StringIOr[�BytesIOrmrnrortryr{r�r�r�rrrr�<module>sPv


�

Zerion Mini Shell 1.0