Your IP : 13.58.61.176


Current Path : /usr/lib64/python3.6/site-packages/cffi/__pycache__/
Upload File :
Current File : //usr/lib64/python3.6/site-packages/cffi/__pycache__/vengine_gen.cpython-36.pyc

3

M��Z4h�@sHddlZddlZddlZddlmZddlmZGdd�de�ZdZ	dS)�N�)�model)�VerificationErrorc@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
�ZdZdd
�Z	dd�Z
d[dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZeZeZeZdd�ZeZdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Z d5d6�Z!d7d8�Z"d9d:�Z#d\d=d>�Z$d?d@�Z%eZ&d]dAdB�Z'dCdD�Z(dEdF�Z)dGdH�Z*dIdJ�Z+d^dLdM�Z,d_dNdO�Z-dPdQ�Z.dRdS�Z/eZ0dTdU�Z1dVdW�Z2eZ3dXdY�Z4d;S)`�VGenericEngine�gFcCs||_|j|_g|_i|_dS)N)�verifier�ffi�export_symbols�_struct_pending_verification)�selfr�r�#/usr/lib64/python3.6/vengine_gen.py�__init__szVGenericEngine.__init__cCs|jd|j�dS)Nr	)�
setdefaultr	)r�kwdsrrr
�patch_extension_kwdssz#VGenericEngine.patch_extension_kwdscCsTxN|D]F}||}|dkr tj}x*|D]"}tjj||�}tjj|�r&|Sq&WqWdS)N)�sys�path�os�join�isfile)rZmodule_namerZso_suffixesZ	so_suffix�basename�dirname�filenamerrr
�find_modules

zVGenericEngine.find_modulecCsdS)Nr)rrrr
�
collect_types%szVGenericEngine.collect_types�cCs|jj|d�dS)N�
)Z_f�write)rZwhatrrr
�_prnt(szVGenericEngine._prntcCs`|j}|t�||jj�|jd�tjdkr\tjdkr>d}nd}|jj�}|d||f�dS)NZdeclZwin32�ZPyInit_Zinitzvoid %s%s(void) { }
)r )	r�cffimod_headerrZpreamble�	_generater�platform�version_infoZget_module_name)r�prnt�prefix�modnamerrr
�write_source_to_f+s



z VGenericEngine.write_source_to_frcsj�jj}tjjtj�jj�}|j||���j	�d�G���fdd�dt
j���d�}�j	�d|d�|S)NZloadingcs&eZdZ�Z�jZgZ�fdd�ZdS)z/VGenericEngine.load_library.<locals>.FFILibrarycs�jS)N)�	_cffi_dir)r)�
FFILibraryrr
�__dir__Tsz7VGenericEngine.load_library.<locals>.FFILibrary.__dir__N)�__name__�
__module__�__qualname__Z_cffi_generic_modulerZ	_cffi_ffir)r+r)r*�modulerrr
r*Psr*rZloaded)�library)r�_backendrrr�curdirrZmodulefilename�load_library�_load�types�
ModuleType)r�flags�backendrr0r)r*r/rr
r3AszVGenericEngine.load_librarycCs$dd�|jjjj�D�}|j�|S)NcSsg|]\}\}}||f�qSrr)�.0�key�tpZqualrrr
�
<listcomp>^sz4VGenericEngine._get_declarations.<locals>.<listcomp>)rZ_parserZ
_declarations�items�sort)rZlstrrr
�_get_declarations]sz VGenericEngine._get_declarationscCs�x�|j�D]�\}}|jdd�\}}yt|d||f�}Wn tk
rXtd|��YnXy|||�Wq
tk
r�}ztj||��WYdd}~Xq
Xq
WdS)N� rz_generate_gen_%s_%sznot implemented in verify(): %r)r?�split�getattr�AttributeErrorr�	Exceptionr�attach_exception_info)r�	step_name�namer;�kind�realname�method�errr
r"cszVGenericEngine._generatec
Ks�x||j�D]p\}}|jdd�\}}t|d||f�}y||||f|�Wq
tk
rx}	ztj|	|��WYdd}	~	Xq
Xq
WdS)Nr@rz
_%s_gen_%s)r?rArBrDrrE)
rr/rFrrGr;rHrIrJrKrrr
r4rszVGenericEngine._loadcCsdS)Nr)rr;rGrrr
�_generate_nothing|sz VGenericEngine._generate_nothingcKsdS)Nr)rr;rGr/rrrr
�_loaded_noopszVGenericEngine._loaded_noopcs�t|tj�st�|jr(|jd||�dS|j}t|j�}g}x<t	|j�D].\}}d}t|tj
�rdd}|jd||f�qHWd|��fdd�t|j|�D�}	|j
}
t|
tj
�r�|	jd|
jd	���tj}
d
j|	�p�d}	d|}|jj|�|jr�|jd
}nd}d|||	f}
d|�||
j|
���|d�t|j
tj
��rDd}nt|j
tj��sZd}nd}|d||d
j|�f�|d�|�dS)NFr�*z%sx%dzargument of %scs g|]\}}|jd|���qS)z %s)�
get_c_name)r9�type�arg)�contextrr
r<�sz>VGenericEngine._generate_gen_function_decl.<locals>.<listcomp>rz *rz, �voidz
_cffi_f_%sr@z	 %s%s(%s)zresult of %s�{z*r = zreturn z  %s%s(%s);�})�
isinstancer�FunctionPtrType�AssertionError�ellipsis�_generate_gen_constr�len�args�	enumerate�
StructOrUnion�append�zip�result�insertrO�	void_typerr	�abiZVoidType)rr;rGr%ZnumargsZargnames�irPZindirectionZarglistZtpresult�wrappernamerdZfuncdeclZresult_coder)rRr
�_generate_gen_function_decl�sJ

z*VGenericEngine._generate_gen_function_declcCsrt|tj�st�|jr*|jd|||�}�n(g}|}tdd�|jD��sVt|jtj	��rg}xDt
|j�D]6\}	}
t|
tj	�r�tj|
�}
|j|	|
f�|j|
�qfW|j}t|tj	�r�|j
dkr�td|j�f��tj|�}|jd|�|jdd|f�tj}tjt|�||j�}|jj|�}d|}
|j||
�}x"|D]\}	}
|j||	|
|�}�q4Wt|||�t|�jj|�dS)NFcss|]}t|tj�VqdS)N)rVrr^)r9�typrrr
�	<genexpr>�sz6VGenericEngine._loaded_gen_function.<locals>.<genexpr>z*'%s' is used as result type, but is opaquerraz
_cffi_f_%s)rVrrWrXrY�_load_constant�anyr\rar^r]�PointerTyper_Zfldtypes�	TypeError�_get_c_namerbrc�tupler�_get_cached_btype�
load_function�_make_struct_wrapper�setattrrPr))rr;rGr/r0ZnewfunctionZindirections�base_tpZ
indirect_argsrerhZindirect_result�BFuncrfrrr
�_loaded_gen_function�s@





z#VGenericEngine._loaded_gen_functioncsP|jj�|jj|���dkr4|j����fdd�}n����fdd�}||_|S)Nracs �j��}�|f|��|dS)Nr)�new)r\�res)�BTyper�oldfuncrr
�newfunc�s
z4VGenericEngine._make_struct_wrapper.<locals>.newfunccs6|d���j�|��f|�dd�}�|�S)Nr)Znewp)r\)ryr8rerzrr
r{�s.)rr1rpZ_cffi_base_type)rrzrer;rtr{r)ryr8rrerzr
rr�sz#VGenericEngine._make_struct_wrappercCs ||jkst�|j|d|�dS)N�struct)rGrX�_generate_struct_or_union_decl)rr;rGrrr
�_generate_gen_struct_decl�sz(VGenericEngine._generate_gen_struct_declcCs|j|d||�dS)Nr|)�_loading_struct_or_union)rr;rGr/rrr
�_loading_gen_struct�sz"VGenericEngine._loading_gen_structcKs|j|�dS)N)�_loaded_struct_or_union)rr;rGr/rrrr
�_loaded_gen_struct�sz!VGenericEngine._loaded_gen_structcCs ||jkst�|j|d|�dS)N�union)rGrXr})rr;rGrrr
�_generate_gen_union_decl�sz'VGenericEngine._generate_gen_union_declcCs|j|d||�dS)Nr�)r)rr;rGr/rrr
�_loading_gen_unionsz!VGenericEngine._loading_gen_unioncKs|j|�dS)N)r�)rr;rGr/rrrr
�_loaded_gen_unionsz VGenericEngine._loaded_gen_unionc
Cs|jdkrdSd||f}d||f}d||fj�}|j}|d||f�|d�|d�|d�x�|j�D]�\}}	}
}t|	tj�r�|	j�s�|
dkr�|d	|�qny$|d
|	jdd||d
�|f�Wqnt	k
r�}z|dt
|��WYdd}~XqnXqnW|d�|jj|�|d|f�|d�|d|�|d�|d|�|d�xt|j�D]h\}}	}
}|
dk�rv�q\|d||f�t|	tj
��r�|	jdk�r�|d|	j��n|d||f��q\W|d�|d�|d�|d�|d|f�|d�|�dS)Nz_cffi_check_%s_%sz_cffi_layout_%s_%sz%s %szstatic void %s(%s *p)rTz8  /* only to generate compile-time warnings or errors */z
  (void)p;rz  (void)((p->%s) << 1);z  { %s = &p->%s; (void)tmp; }z*tmpzfield %r)Zqualsz
  /* %s */rUzintptr_t %s(intptr_t i)z,  struct _cffi_aligncheck { char x; %s y; };z  static intptr_t nums[] = {z    sizeof(%s),z)    offsetof(struct _cffi_aligncheck, y),z    offsetof(%s, %s),z    0,  /* %s */z    sizeof(((%s *)0)->%s),z    -1z  };z  return nums[i];z3  /* the next line is not executed, but compiled */z  %s(0);)�fldnames�stripr�
enumfieldsrVr�
PrimitiveType�is_integer_typerOr�strr	r_�	ArrayType�lengthrn)
rr;r&rGZ
checkfuncname�layoutfuncname�cnamer%�fname�ftype�fbitsize�fqualrKrrr
r}sT
&
z-VGenericEngine._generate_struct_or_union_declcCs
|jdkrdSd||f}|jjd�d}|j||�}g}d}	x(||	�}
|
dkrRP|j|
�|	d7}	q@Wt|tj�r�|jr�|d}|d}|ddd�}
|ddd�}|j	�t
|
�t
|�ko�t
|j�kns�t�|
|||f|_nd||fj
�}||f|j|<dS)Nz_cffi_layout_%s_%szintptr_t(*)(intptr_t)rr�r z%s %s)r�r�_typeof_lockedrqr_rVrr^�partialZ
force_flattenr[rXZfixedlayoutr�r
)rr;r&rGr/r�ru�function�layoutZnum�xZ	totalsizeZtotalalignmentZfieldofsZ	fieldsizer�rrr
r7s.

*z'VGenericEngine._loading_struct_or_unionc
Cs|jdkrdS|jj|�||jk�rdd�}|j}|j|�}|jj|�\}}||d|j|�d�||d|j|�d�d}x�|j�D]v\}}	}
}|
dkr�q�||||j||�d|f�||ddkr�|j|	�}|||d|j|�d	|f�|d7}q�W|t	|�k�st
�dS)
NcSs||krtd|||f��dS)Nz'%s (we have %d, but C compiler says %d))r)Z	realvalueZ
expectedvalue�msgrrr
�checkZsz5VGenericEngine._loaded_struct_or_union.<locals>.checkrzwrong total sizerzwrong total alignmentr�zwrong offset for field %rzwrong size for field %r)r�rrpr
�pop�sizeofZalignofr�Zoffsetofr[rX)
rr;r�rZBStructr�r�rer�r�r�r�ZBFieldrrr
r�Ss,


z&VGenericEngine._loaded_struct_or_unioncCs.t|tj�r|j||d�n|j|d|�dS)Nr)rVr�EnumType�_generate_gen_enum_declr})rr;rGrrr
�_generate_gen_anonymous_declusz+VGenericEngine._generate_gen_anonymous_declcCs2t|tj�r|j|||d�n|j|d||�dS)Nr)rVrr��_loading_gen_enumr)rr;rGr/rrr
�_loading_gen_anonymous{sz%VGenericEngine._loading_gen_anonymouscKs.t|tj�r |j|||f|�n
|j|�dS)N)rVrr��_loaded_gen_enumr�)rr;rGr/rrrr
�_loaded_gen_anonymous�sz$VGenericEngine._loaded_gen_anonymousN�constc
CsD|j}d||f}|jj|�|dk	rl|s.t�|dks:t�|d|�|d�|j||�|d�|d�n�|r�|dks|t�|d|�|d�|d|f�|d	|f�|d�n�|dk	s�t�|dks�t�|d
kr�d}nd}d}	|dko�t|tj��rd
}	d}||jd|	|f|��|d�|d||f�|d�|�dS)Nz_cffi_%s_%sr�zint %s(char *out_error)rTz  return 0;rUzint %s(long long *out_value)z  *out_value = (long long)(%s);z  return (%s) <= 0;�var�&rzconst *z %s%s(void)z  return (%s%s);)	rr	r_rX�_check_int_constant_valuerVrr^rO)
r�is_intrGr;�category�check_valuer%�funcnameZ	ampersandZextrarrr
rZ�s@

z"VGenericEngine._generate_gen_constcCs&t|tj�o|j�}|j|||�dS)N)rVrr�r�rZ)rr;rGr�rrr
�_generate_gen_constant_decl�sz*VGenericEngine._generate_gen_constant_declcCsd|}|dk	r*|st�|j||�|}n�|r�|jjd�d}|jjd�d}	|j|	|�}
|jj|�}|
|�}t|d�}|dkr�|r�|jjd�d}
|dd|jj|
�>7}nd|dks�t�d}t|t	j
�r�d	|}|jj|j||��d}	|j|	|�}
|
�}t|t	j
��r|d}|S)
Nz_cffi_const_%sz
long long*rzint(*)(long long*)z	long longr�z	(*)(void)rN)rX�_load_known_int_constantrr�rqrw�intr�rVrr^rO)rr�r;rGr/r�r��valueryrur��p�negativeZ	BLongLongZfntypeextrarrr
rj�s2zVGenericEngine._load_constantcCsDt|tj�o|j�}|j||||�}t|||�t|�jj|�dS)N)	rVrr�r�rjrsrPr)r_)rr;rGr/r0r�r�rrr
�_loaded_gen_constant�sz#VGenericEngine._loaded_gen_constantcCs�|j}|dkr"|d|||f�n|d|||f�|d�|d|�|d|�|d�|d|�|d	�|d
|dd�|f�|d�|d
�dS)Nrz&  if ((%s) > 0 || (long)(%s) != %dL) {z1  if ((%s) <= 0 || (unsigned long)(%s) != %dUL) {z    char buf[64];z    if ((%s) <= 0)z)        sprintf(buf, "%%ld", (long)(%s));z    elsez2        sprintf(buf, "%%lu", (unsigned long)(%s));z:    sprintf(out_error, "%s has the real value %s, not %s",z            "%s", buf, "%d");�dz    return -1;z  })r)rrGr�r%rrr
r��s z(VGenericEngine._check_int_constant_valuecCsr|jjd�d}|jjd�d}|j||�}|jj|d�}||�dkrn|jj|�}tjdkrft|d�}t|��dS)Nzchar[]rz
int(*)(char*)�r zutf-8)r )	rr�rqrw�stringrr$r�r)rr/r�ryrur�r��errorrrr
r��s

z'VGenericEngine._load_known_int_constantcCs|jdd�}d||fS)N�$Z___D_z
_cffi_e_%s_%s)�replace)rr&rGrrr
�_enum_funcname�szVGenericEngine._enum_funcname�enumcCs�|jr&x|jD]}|jd|�qWdS|j||�}|jj|�|j}|d|�|d�x&t|j|j�D]\}}|j	||�qhW|d�|d�|�dS)NTzint %s(char *out_error)rTz  return 0;rU)
r��enumeratorsrZr�r	r_rr`�
enumvaluesr�)rr;rGr&�
enumeratorr�r%�	enumvaluerrr
r��sz&VGenericEngine._generate_gen_enum_declcsL�jr0���fdd��jD�}t|��_d�_n�j||�}�j�|�dS)Ncsg|]}�jd�|���qS)T)rj)r9r�)r/rr;rr
r<sz4VGenericEngine._loading_gen_enum.<locals>.<listcomp>T)r�r�ror�Zpartial_resolvedr�r�)rr;rGr/r&r�r�r)r/rr;r
r�s

z VGenericEngine._loading_gen_enumcCs<x6t|j|j�D]$\}}t|||�t|�jj|�qWdS)N)r`r�r�rsrPr)r_)rr;rGr/r0r�r�rrr
r�szVGenericEngine._loaded_gen_enumcCs&|dkrd}n|}|jd||d�dS)Nz...T)r�)rZ)rr;rGr�rrr
�_generate_gen_macro_decl sz'VGenericEngine._generate_gen_macro_declcCsF|dkrd}n|}|jd||||d�}t|||�t|�jj|�dS)Nz...T)r�)rjrsrPr)r_)rr;rGr/r0r�r�rrr
�_loaded_gen_macro)sz VGenericEngine._loaded_gen_macrocCs�t|tj�rx|jdkr\|j}d|f}|jj|�|d|�|d�|d|f�|d�tj|j�}|j	d||�ntj|�}|j	d||dd	�dS)
Nz...z_cffi_sizeof_%szsize_t %s(void)rTz  return sizeof(%s);rUFr�)r�)
rVrr�r�rr	r_rl�itemrZ)rr;rGr%r��tp_ptrrrr
�_generate_gen_variable_decl6s


z*VGenericEngine._generate_gen_variable_declcs^t|tj�r�|jdkr�d|f}|jjd�d}|j||�}|�}|jj|j�}	t	||jj
|	��\}
}|dkr�td||jf��|j|
�}tj
|j�}|jd|||�}
|jdk	r�|jj|�}|jj||
�}
t|||
�t|�jj|�dSd|}|jj|jd|��d}|j||�}|���fd	d
�}�fdd�}tt|�|t||��t|�jj|�dS)
Nz...z_cffi_sizeof_%szsize_t(*)(void)rz/bad size: %r does not seem to be an array of %sFz_cffi_var_%sz
*(*)(void)cs�dS)Nrr)r0)�ptrrr
�gettergsz3VGenericEngine._loaded_gen_variable.<locals>.gettercs|�d<dS)Nrr)r0r�)r�rr
�setterisz3VGenericEngine._loaded_gen_variable.<locals>.setter)rVrr�r�rr�rqrpr��divmodr�rZresolve_lengthrlrj�castrsrPr)r_rO�property)rr;rGr/r0r�rur��sizeZ	BItemTyper��restr�r�ZBArrayr�r�r)r�r
�_loaded_gen_variableHs:



z#VGenericEngine._loaded_gen_variable)r)r)Nr�N)N)r�)r�)5r,r-r.Z
_class_keyZ_gen_python_modulerrrrrr(r3r?r"r4rLrMZ_generate_gen_typedef_declZ_loading_gen_typedefZ_loaded_gen_typedefrgZ_loading_gen_functionrvrrr~r�r�r�r�r�r}rr�r�r�r�rZr�Z_loading_gen_constantrjr�r�r�r�r�r�r�r�Z_loading_gen_macror�r�Z_loading_gen_variabler�rrrr
rsf



-$1"	
$
	



rad
#include <stdio.h>
#include <stddef.h>
#include <stdarg.h>
#include <errno.h>
#include <sys/types.h>   /* XXX for ssize_t on some platforms */

/* this block of #ifs should be kept exactly identical between
   c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py
   and cffi/_cffi_include.h */
#if defined(_MSC_VER)
# include <malloc.h>   /* for alloca() */
# if _MSC_VER < 1600   /* MSVC < 2010 */
   typedef __int8 int8_t;
   typedef __int16 int16_t;
   typedef __int32 int32_t;
   typedef __int64 int64_t;
   typedef unsigned __int8 uint8_t;
   typedef unsigned __int16 uint16_t;
   typedef unsigned __int32 uint32_t;
   typedef unsigned __int64 uint64_t;
   typedef __int8 int_least8_t;
   typedef __int16 int_least16_t;
   typedef __int32 int_least32_t;
   typedef __int64 int_least64_t;
   typedef unsigned __int8 uint_least8_t;
   typedef unsigned __int16 uint_least16_t;
   typedef unsigned __int32 uint_least32_t;
   typedef unsigned __int64 uint_least64_t;
   typedef __int8 int_fast8_t;
   typedef __int16 int_fast16_t;
   typedef __int32 int_fast32_t;
   typedef __int64 int_fast64_t;
   typedef unsigned __int8 uint_fast8_t;
   typedef unsigned __int16 uint_fast16_t;
   typedef unsigned __int32 uint_fast32_t;
   typedef unsigned __int64 uint_fast64_t;
   typedef __int64 intmax_t;
   typedef unsigned __int64 uintmax_t;
# else
#  include <stdint.h>
# endif
# if _MSC_VER < 1800   /* MSVC < 2013 */
#  ifndef __cplusplus
    typedef unsigned char _Bool;
#  endif
# endif
#else
# include <stdint.h>
# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux)
#  include <alloca.h>
# endif
#endif
)
rrr5rrr�r�objectrr!rrrr
�<module>s

?>