
\c        	   @   s  d  d l  Z  d  d l Z d  d l Z d d l m Z m Z d d l m Z d d l Td Z	 d Z
 d Z d	 f  d
     YZ d f  d     YZ d f  d     YZ d f  d     YZ d f  d     YZ d f  d     YZ e j d f k r e j Z n d e j f d     YZ d   Z e d  Z e d  Z d   Z d   Z d   Z d   Z d   Z d  e e  d! e  d e  e  d"  Z! d S(#   iNi   (   t   ffiplatformt   model(   t   VerificationError(   t   *i&  i'  i(  t
   GlobalExprc           B   s)   e  Z d  d  d  Z d   Z d   Z RS(   i    c         C   s1   | |  _  | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   namet   addresst   type_opt   sizet   check_value(   t   selfR   R   R   R   R	   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   __init__   s
    				c         C   s&   d |  j  |  j |  j j   |  j f S(   Ns'     { "%s", (void *)%s, %s, (void *)%s },(   R   R   R   t	   as_c_exprR   (   R
   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR      s    c         C   s    d |  j  j   |  j |  j f S(   Ns
   b'%s%s',%d(   R   t   as_python_bytesR   R	   (   R
   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   as_python_expr   s    (   t   __name__t
   __module__R   R   R   (    (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR      s   	t	   FieldExprc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s1   | |  _  | |  _ | |  _ | |  _ | |  _ d  S(   N(   R   t   field_offsett
   field_sizet   fbitsizet   field_type_op(   R
   R   R   R   R   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR      s
    				c         C   sO   d t  |  j  } d |  j |  j f d | |  j f d | |  j j   f S(   Nt    s     { "%s", %s,
s        %s   %s,
s        %s   %s },(   t   lenR   R   R   R   R   (   R
   t   spaces(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR   #   s    $c         C   s
   t   d  S(   N(   t   NotImplementedError(   R
   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR   )   s    c         C   sb   |  j  j t k r d } n* |  j  j t k r? t |  j  } n t  d |  j  j   | |  j f S(   Nt    s	   b'%s%s%s'(	   R   t   opt   OP_NOOPt   OP_BITFIELDt   format_four_bytesR   R   R   R   (   R
   t	   size_expr(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   as_field_python_expr,   s    	(   R   R   R   R   R   R    (    (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR      s   			t   StructUnionExprc           B   s#   e  Z d    Z d   Z d   Z RS(   c	   	      C   sL   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   R   t
   type_indext   flagsR   t	   alignmentt   commentt   first_field_indext   c_fields(	   R
   R   R"   R#   R   R$   R%   R&   R'   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR   8   s    							c         C   sf   d |  j  |  j |  j f d |  j |  j f d |  j t |  j  f |  j r] d |  j n d d S(   Ns     { "%s", %d, %s,s   
    %s, %s, s   %d, %d s	   /* %s */ R   s   },(	   R   R"   R#   R   R$   R&   R   R'   R%   (   R
   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR   C   s    c         C   sc   t  |  j t  } g  |  j D] } | j   ^ q } d t |  j  t |  |  j d j |  f S(   Ns   (b'%s%s%s',%s)t   ,(	   t   evalR#   t   G_FLAGSR'   R    R   R"   R   t   join(   R
   R#   t   c_fieldt   fields_expr(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR   J   s    	(   R   R   R   R   R   (    (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR!   7   s   		t   EnumExprc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s1   | |  _  | |  _ | |  _ | |  _ | |  _ d  S(   N(   R   R"   R   t   signedt   allenums(   R
   R   R"   R   R/   R0   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR   U   s
    				c         C   s&   d |  j  |  j |  j |  j |  j f S(   Ns1     { "%s", %d, _cffi_prim_int(%s, %s),
    "%s" },(   R   R"   R   R/   R0   (   R
   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR   \   s    c         C   sw   i t  d 6t d 6t d	 6t d
 6t d 6t d 6t d 6t d 6|  j |  j	 f } d t
 |  j  t
 |  |  j |  j f S(   Ni   i    i   i   i   s   b'%s%s%s\x00%s'(   i   i    (   i   i   (   i   i    (   i   i   (   i   i    (   i   i   (   i   i    (   i   i   (   t
   PRIM_UINT8t	   PRIM_INT8t   PRIM_UINT16t
   PRIM_INT16t   PRIM_UINT32t
   PRIM_INT32t   PRIM_UINT64t
   PRIM_INT64R   R/   R   R"   R   R0   (   R
   t
   prim_index(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR   a   s    	(   R   R   R   R   R   (    (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR.   T   s   		t   TypenameExprc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   | |  _  | |  _ d  S(   N(   R   R"   (   R
   R   R"   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR   m   s    	c         C   s   d |  j  |  j f S(   Ns     { "%s", %d },(   R   R"   (   R
   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR   q   s    c         C   s   d t  |  j  |  j f S(   Ns   b'%s%s'(   R   R"   R   (   R
   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR   t   s    (   R   R   R   R   R   (    (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR:   l   s   		t
   Recompilerc           B   s  e  Z d  Z e d  Z d   Z d   Z d   Z d   Z d d d d	 d
 g Z	 d   Z
 d d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d    Z d!   Z d"   Z  dN d#  Z" d$   Z# d%   Z$ d&   Z% e% Z& d'   Z' d(   Z( e( Z) d)   Z* e* Z+ d*   Z, d+   Z- d,   Z. dN d- dN d.  Z/ d/   Z0 d0   Z1 d1   Z2 d2   Z3 dN d3  Z4 d4   Z5 d5   Z6 d6   Z7 d7   Z8 d8   Z9 d9   Z: d:   Z; d;   Z< d<   Z= d=   Z> e> Z? Z@ d>   ZA d?   ZB d@   ZC dA   ZD dB   ZE eE ZF ZG dC   ZH dD   ZI dE   ZJ dF   ZK dG   ZL dH   ZM dI   ZN eN ZO eN ZP dJ   ZQ dK   ZR dL   ZS eS ZT dM   ZU RS(O   i    c         C   s(   | |  _  | |  _ | |  _ t |  _ d  S(   N(   t   ffit   module_namet   target_is_pythont   VERSION_BASEt   _version(   R
   R<   R=   R>   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR   ~   s    			c         C   s   t  |  j |  |  _ d  S(   N(   t   maxR@   (   R
   t   ver(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   needs_version   s    c      	   C   s  i  |  _  |  j d  t |  j  d t } g  |  _ x | D] } | j r; |  j  | d  k sc t  t |  j  |  j  | <|  j j	 |  x | j
 D]u } t | t j t j t j t j t j f  s t  |  j  | d  k r t |  j  |  j  | <n  |  j j	 |  q W|  j j	 d  q; q; Wx | D]w } | j r*|  j  | d  k r*t |  j  |  j  | <|  j j	 |  | j r| j d  k	 r|  j j	 d  qq*q*Wd  |  j  j   k st  i  |  _ i  |  _ xR | D]J } t | t j  rd  |  j | <qt | t j  rd  |  j | <qqWx9 t t |  j d d    D] \ } } | |  j | <qFWx9 t t |  j d d    D] \ } } | |  j | <qWx; | D]3 } t |  d | j j  } | | |  j  |  qWx& |  j D] } t | t  st  qWt |  j  |  _ d  S(   Nt   collecttypet   keyt   ENDt   LENc         S   s   |  j  S(   N(   R   (   t   tp(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   <lambda>   R   c         S   s   |  j  S(   N(   R   (   RH   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyRI      R   t   _emit_bytecode_(   t
   _typesdictt	   _generatet   sortedt   strt
   cffi_typest   is_raw_functiont   Nonet   AssertionErrorR   t   appendt   argst
   isinstanceR   t   VoidTypet   BasePrimitiveTypet   PointerTypet   StructOrUnionOrEnumt   FunctionPtrTypet   is_array_typet   lengtht   valuest   _struct_unionst   _enumst   StructOrUniont   EnumTypet	   enumeratet   getattrt	   __class__R   t   CffiOpt   tuple(   R
   t	   all_declsRH   t   tp1t   it   methodR   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   collect_type_table   sZ    					c         C   s6  t  | t j  sF t  | t  rB x | D] } |  j |  q( Wn  d  S| |  j k r2d  |  j | <t  | t j  r |  j | j    q2t  | t j	  r| j
 d  k	 r/| |  j j j k r/x? | j   D]. \ } } } } |  j |  j | | |   q Wq/q2x* | j   D] \ } } |  j |  qWn  d  S(   N(   RU   R   t   BaseTypeByIdentityRf   t   _do_collect_typeRK   RQ   RZ   t   as_raw_functionR`   t   fldtypesR<   t   _parsert   _included_declarationst
   enumfieldst   _field_typet
   _get_items(   R
   RH   t   xt   name1Rh   t   _(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyRm      s     &c   
      C   s   |  j  j j j   } x t |  D] \ } \ } } | j d d  \ } } y t |  d | | f  } Wn! t k
 r t d |   n Xy | |  _	 | | |  Wq" t
 k
 r }	 t j |	 |    q" Xq" Wd  S(   NR   i   s   _generate_cpy_%s_%ss"   not implemented in recompile(): %r(   R<   Rp   t   _declarationst   itemsRM   t   splitRc   t   AttributeErrorR   t   _current_qualst	   ExceptionR   t   attach_exception_info(
   R
   t	   step_namet   lstR   RH   t   qualst   kindt   realnameRj   t   e(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyRL      s    	t   globalt   fieldt   struct_uniont   enumt   typenamec         C   s  i  |  _  x |  j D] } g  |  j  | <q Wt   |  _ |  j d  |  j   xS |  j D]H } |  j  | } | d k r | j d d    n  t |  |  j  | <qW W|  j  d } xQ |  j j	   D]@ \ } } | t
 |  k  s t  | | j | j k s t  q Wt
 |  t
 |  j  k s%t  |  j  d } xQ |  j j	   D]@ \ } } | t
 |  k  sft  | | j | j k sBt  qBWt
 |  t
 |  j  k st  d  S(   Nt   ctxR   RE   c         S   s   |  j  S(   N(   R   (   t   entry(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyRI      R   R   R   (   t   _lstst	   ALL_STEPSt   sett   _seen_struct_unionsRL   t   _add_missing_struct_unionst   sortRf   R^   Ry   R   RR   R   R_   (   R
   R   R   RH   Ri   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   collect_step_tables   s*    	
 ! R   c         C   s   |  j  j | d  d  S(   Ns   
(   t   _ft   write(   R
   t   what(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _prnt  s    c         C   sQ   |  j  r+ | d  k s t  |  j |  n" | d  k	 s= t  |  j | |  d  S(   N(   R>   RQ   RR   t   write_py_source_to_ft   write_c_source_to_f(   R
   t   ft   preamble(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   write_source_to_f  s
    	c         C   sD   t  t j j t j j t  |  d  } | j   } | j   | S(   Nt   r(   t   opent   ost   pathR+   t   dirnamet   __file__t	   readlinest   close(   R
   t   filenamet   gt   lines(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _rel_readlines  s    *
c         C   s  | |  _  |  j } |  j j d  k	 r1 | d  n  |  j d  } | j d  } |  j d  | | | d +| d j |   |  j j	 d  d } |  j j d  k	 r| d	 |  j f  | d
  |  j
 |  j j  | d  | d  | d | f  | d  | d | f  | d  | d | f  | d  |  j d  } | j d  } |  j d  | | | d +| d j |   |  j t  n  | d  |   | |  |   | d  |   | d  t g  |  j j   D] \ } } | | f ^ q } xc t |  j  D]R \ } }	 d }
 | | k rKd | | j   }
 n  | d | |	 j   |
 f  qW|  j s| d  n  | d  |   t   |  _ |  j d  i  } x |  j D]| } |  j | } t |  | | <| | d k r| d | | f  x | D] } | | j    q
W| d  |   qqW|  j j r| d  x |  j j D]v } y | j d   \ } } Wn* t k
 rt d! |  j | f   n X| d  k rt d"   n  | d# | f  q_W| d$  | d  |   n  | d%  | d&  x@ |  j D]5 } | | d k r<| d' |  q| d( |  qWx8 |  j D]- } | d) k rX| d* | | | f  qXqXW|  j j r| d+  n
 | d,  | d- t |  j  f  d } |  j r| d O} n  | d. |  | d  |   | d/  | d0  | d  |   | d  | d1  | d2 | f  | d3  |  j r| d4  | d5  | d6  n  | d7 |  j  | d8  | d9  | d:  | d  | d;  | d<  | d=  | d>  | d? | f  | d@  | dA | f  | dB  | dB  | d  | d1  | dC | f  | d3  | dD |  j |  j f  | d;  | d  | d1  | dE | f  | d3  | dF |  j |  j f  | d;  | d  |   | d/  | dG  | d  d  |  _ d  S(H   Ns   #define _CFFI_USE_EMBEDDINGs   _cffi_include.hs   #include "parse_c_type.h"
s   parse_c_type.hi   R   t   .is   #define _CFFI_MODULE_NAME  "%s"s1   static const char _CFFI_PYTHON_STARTUP_CODE[] = {s   0 };s   #ifdef PYPY_VERSIONs5   # define _CFFI_PYTHON_STARTUP_FUNC  _cffi_pypyinit_%ss   #elif PY_MAJOR_VERSION >= 3s-   # define _CFFI_PYTHON_STARTUP_FUNC  PyInit_%ss   #elses*   # define _CFFI_PYTHON_STARTUP_FUNC  init%ss   #endifs   _embedding.hs   #include "_cffi_errors.h"
s   _cffi_errors.hs>   /************************************************************/s   static void *_cffi_types[] = {s    // s   /* %2d */ %s,%ss     0s   };t   decli    s.   static const struct _cffi_%s_s _cffi_%ss[] = {s.   static const char * const _cffi_includes[] = {i   sQ   ffi object %r includes %r, but the latter has not been prepared with set_source()sM   not implemented yet: ffi.include() of a Python-based ffi inside a C-based ffis     "%s",s     NULLs?   static const struct _cffi_type_context_s _cffi_type_context = {s     _cffi_types,s     _cffi_%ss,s     NULL,  /* no %ss */R   s     %d,  /* num_%ss */s     _cffi_includes,s     NULL,  /* no includes */s     %d,  /* num_types */s     %d,  /* flags */s   #ifdef __GNUC__s?   #  pragma GCC visibility push(default)  /* for -fvisibility= */t   PyMODINIT_FUNCs"   _cffi_pypyinit_%s(const void *p[])t   {s%       if (((intptr_t)p[0]) >= 0x0A03) {sQ           _cffi_call_python_org = (void(*)(struct _cffi_externpy_s *, char *))p[1];s       }s       p[0] = (const void *)0x%x;s       p[1] = &_cffi_type_context;s   #if PY_MAJOR_VERSION >= 3s       return NULL;t   }s   #  ifdef _MSC_VERs        PyMODINIT_FUNCs   #  if PY_MAJOR_VERSION >= 3s%        PyInit_%s(void) { return NULL; }s   #  elses        init%s(void) { }s   #  endifs   PyInit_%s(void)s5     return _cffi_init("%s", 0x%x, &_cffi_type_context);s   init%s(void)s.     _cffi_init("%s", 0x%x, &_cffi_type_context);s   #  pragma GCC visibility pop(    R   R   R<   t
   _embeddingRQ   R   t   indexR+   R=   Rz   t   _print_string_literal_in_arrayRC   t   VERSION_EMBEDDEDt   dictRK   Ry   Rb   RO   t   _get_c_nameR   R   t   _seen_constantsRL   R   R   R   t   _included_ffist   _assigned_sourceR{   R   t   _num_externpyR@   (   R
   R   R   t   prntR   Ri   t   base_module_nameRH   t   typeindex2typeR   R%   t   numsR   R   R   t   ffi_to_includet   included_module_namet   included_sourceR#   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR     s   		









4!	








	






	
























c         C   s   t  | t  r d | f St  | t t f  r g  | D] } |  j |  ^ q6 } t |  d k rs | j d  n  d d j |  f S| j   S(   Ns   b'%s'i   R   s   (%s)R(   (	   RU   RN   t   listRf   t   _to_pyR   RS   R+   R   (   R
   Ru   t   itemt   rep(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR     s    "c         C   sN  | |  _  |  j } | d  | d  t |  j j p8 d  } x t |  D] } |  j j | } y | j d  \ } } Wn* t k
 r t d |  j | f   n X| d  k	 r t d   n  | d | | f  qK W|   | d |  j
 f  | d |  j f  d  |  _ t |  j  |  _ g  |  j D] } | j   ^ q,}	 | d	 |  j d
 j |	   f  t g  |  j j   D] \ }
 } | |
 f ^ qz } x\ |  j D]Q } |  j | } t |  d k r| d k r| d | |  j |  f  qqW| d k r@| d d j g  t |  D] } d | ^ q f  n  | d  d  S(   Ns   # auto-generated files   import _cffi_backendi   sQ   ffi object %r includes %r, but the latter has not been prepared with set_source()sM   not implemented yet: ffi.include() of a C-based ffi inside a Python-based ffis   from %s import ffi as _ffi%ds   ffi = _cffi_backend.FFI('%s',s       _version = 0x%x,s       _types = %s,R   i    R   s       _%ss = %s,s       _includes = (%s,),s   , s   _ffi%dt   )(    (   R   R   R   R<   R   t   rangeR   R{   R   RQ   R=   R@   Rf   RO   R   R   R+   R   RK   Ry   R   R   (   R
   R   R   t   num_includesRi   R   R   R   R   t	   types_lstRH   R   R   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR     sB    		

	"#4$4c         C   s   |  j  | S(   N(   RK   (   R
   t   type(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _gettypenum  s    c   	      C   s  d } t  | t j  r | j   r | j   rV | j d k rV d } d | j } nu t  | t j  r d | j d  f } nJ | j d  } d | | j j d d  f } | d k r |  j	 t
  n  d } n t  | t j  r |  j | | | |  d  St  | t j  s$t  | t j  r\|  j d | |  j |  | f  |  j d |  d  St  | t j  rd | j d  } d |  j |  } d } n t |   |  j d | | | | f  |  j d | | j d  | f  |  j d |  d  S(   NR   t   _Boolt   _cffi_to_c_ints   , %ss   (%s)_cffi_to_c_doubles   (%s)_cffi_to_c_%sR   Rw   t   char16_tt   char32_ts   -1s6     if (_cffi_to_c((char *)&%s, _cffi_type(%d), %s) < 0)s       %s;s   (%s)_cffi_to_c_pointers   , _cffi_type(%d)t   NULLs     %s = %s(%s%s);s'     if (%s == (%s)%s && PyErr_Occurred())(   R   R   (   RU   R   RW   t   is_complex_typet   is_integer_typeR   t   UnknownFloatTypet
   get_c_namet   replaceRC   t   VERSION_CHAR16CHAR32RX   t"   _convert_funcarg_to_c_ptr_or_arrayRY   R   R   RZ   R   (	   R
   RH   t   fromvart   tovart   errcodet   extraargt	   convertert   cnamet   errvalue(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _convert_funcarg_to_c  s@    	
			c         C   s&   t  | t j  r" | j d  n  d  S(   Ns   Py_ssize_t datasize(   RU   R   RX   t   add(   R
   RH   t	   localvars(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _extra_local_variables3  s    c         C   s   |  j  d  |  j  d |  j |  | | f  |  j  d  |  j  d  |  j  d |  |  j  d | | j d  f  |  j  d | f  |  j  d	 | |  j |  | f  |  j  d |  |  j  d
  d  S(   Ns1     datasize = _cffi_prepare_pointer_call_argument(s(         _cffi_type(%d), %s, (char **)&%s);s     if (datasize != 0) {s       if (datasize < 0)s	         %s;s&       %s = (%s)alloca((size_t)datasize);R   s,       memset((void *)%s, 0, (size_t)datasize);sL       if (_cffi_convert_array_from_object((char *)%s, _cffi_type(%d), %s) < 0)s     }(   R   R   R   (   R
   RH   R   R   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR   7  s    			c         C   s  t  | t j  r | j   r> | j d k r> d | | j f St  | t j  r[ d | f S| j d k r | j   r | j j d d  } | d k r |  j t	  n  d	 | | f Sd
 | |  j
 |  f Sn t  | t j t j f  rd | |  j
 |  f St  | t j  r7d | |  j
 t j | j   f St  | t j  r| j d  k rwt d | j   | f   n  d | |  j
 |  f St  | t j  rd
 | |  j
 |  f St |   d  S(   NR   s   _cffi_from_c_int(%s, %s)s   _cffi_from_c_double(%s)s   long doubleR   Rw   R   R   s   _cffi_from_c_%s(%s)s/   _cffi_from_c_deref((char *)&%s, _cffi_type(%d))s0   _cffi_from_c_pointer((char *)%s, _cffi_type(%d))s!   '%s' is used as %s, but is opaques0   _cffi_from_c_struct((char *)&%s, _cffi_type(%d))(   R   R   (   RU   R   RW   R   R   R   R   R   RC   R   R   RX   RZ   t	   ArrayTypeR   R`   t   fldnamesRQ   t	   TypeErrorR   Ra   R   (   R
   RH   t   vart   contextR   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _convert_expr_from_cG  s8     c         C   s   |  j  | d | f  S(   Ns
   (*(%s *)0)(   t   _global_type(   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _typedef_typej  s    c         C   s   |  j  |  j | |   d  S(   N(   Rm   R   (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt!   _generate_cpy_typedef_collecttypem  s    c         C   s   d  S(   N(    (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _generate_cpy_typedef_declp  s    c         C   s.   |  j  | } |  j d j t | |   d  S(   NR   (   RK   R   RS   R:   (   R
   RH   R   R"   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _typedef_ctxs  s    c         C   s   |  j  | |  } |  j | |  t | d d   d k rV |  j | | j d d  n= t | t j  r |  j | j	 | j	 j d | j d | n  d  S(   Nt   origint   unknown_typet
   approxnamet	   named_ptr(
   R   R   Rc   RQ   t   _struct_ctxR   RU   R   t   NamedPointerTypet   totype(   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _generate_cpy_typedef_ctxw  s    !c         C   s:   |  j  | j    | j r6 |  j r6 |  j  |  n  d  S(   N(   Rm   Rn   t   ellipsisR>   (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt"   _generate_cpy_function_collecttype  s    c      
   C   s  |  j  s t  t | t j  s( t  | j rE |  j | |  d  S|  j } t | j	  } | d k rr d } n | d k r d } n d } g  } g  } d | } xK t
 | j	  D]: \ }	 }
 | j |
 j d |	 |   | j d |	  q Wd	 j |  } | p	d
 } | j r%| j d } n d } d | | | f } | d | j j |  f  | d  d	 j |  } d } t | j t j  rd } n  | d | | | f  | d  | d  | d  | d | | f  | d  d | } xA t
 | j	  D]0 \ }	 }
 |
 j d |	 |  } | d |  qWt   } x! | j	 D] }
 |  j |
 |  qLWx | D] } | d | f  qmWt | j t j  sd } d | } d | j j d |  } | |  n d  } d } t | j	  d k rt t | j	   } x | D] }	 | d |	  qW|   | d | t |  t |  d	 j g  | D] }	 d |	 ^ qW f  | d  n  |   xB t
 | j	  D]1 \ }	 }
 |  j |
 d |	 d |	 d  |   qW| d   | d!  g  t t | j	   D] }	 d |	 ^ q} d	 j |  } | d" | | | f  | d#  | d$  |   | d%  | d k rr| d&  n  | r| d' |  j | j d( d)   n | d*  | d+  | d  | d,  d-   } t } g  } g  } d | } x~ t
 | j	  D]m \ }	 }
 d } | |
  r%d. } t } n  |
 j d/ | |	 f |  } | j |  | j d0 | |	 f  qW| j } | |  rd | } | j d1 |  } | j d |  t j } d  } d2 } t } n  | ryd	 j |  } | pd
 } d3 | | | f } | d | j |  f  | d  | r3| |  n  d	 j |  } | d" | | | f  | rl| d4  n  | d  n | d5 | | f  | d6  |   d  S(7   Ni    t   noargi   t   arg0RT   s   argument of %ss    x%ds   x%ds   , t   voidR   R   s   %s_cffi_d_%s(%s)s	   static %sR   s   return s     %s%s(%s);R   s   #ifndef PYPY_VERSIONs   static PyObject *s(   _cffi_f_%s(PyObject *self, PyObject *%s)s     %s;s	   result = s   result of %ss    results     PyObject *arg%d;s1     if (!PyArg_UnpackTuple(args, "%s", %d, %d, %s))s   &arg%ds       return NULL;s   arg%ds   return NULLs     Py_BEGIN_ALLOW_THREADSs     _cffi_restore_errno();s     { %s%s(%s); }s     _cffi_save_errno();s     Py_END_ALLOW_THREADSs     (void)self; /* unused */s     (void)noarg; /* unused */s     return %s;t   results   result types     Py_INCREF(Py_None);s     return Py_None;s   #elsec         S   s.   t  |  t j  p- t  |  t j  o- |  j   S(   N(   RU   R   R`   t   PrimitiveTypeR   (   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   need_indirection  s    R   s    %sx%ds   %sx%ds    *results
   *result = s   %s_cffi_f_%s(%s)s     return result;s   #  define _cffi_f_%s _cffi_d_%ss   #endif(   R>   RR   RU   R   RZ   R   t   _generate_cpy_constant_declR   R   RT   Rb   RS   R   R+   t   abiR   RV   R   R   RQ   R   R   R   t   Falset   Truet   insertt	   void_type(   R
   RH   R   R   t   numargst   argnamet	   argumentst   call_argumentsR   Ri   R   t   repr_argumentsR   t   name_and_argumentst   result_codet   argR   R   t   result_declt   rngR   t
   differencet   indirectiont	   tp_result(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _generate_cpy_function_decl  s    				
	
	




	
+

,






	
		
			


c         C   s   | j  r' |  j r' |  j | |  d  S|  j | j   } t | j  } |  j r[ t } n0 | d k rp t } n | d k r t	 } n t
 } |  j d j t | d | t | |  d d |  d  S(   Ni    i   R   s
   _cffi_f_%sR   s
   _cffi_d_%s(   R   R>   t   _generate_cpy_constant_ctxRK   Rn   R   RT   t   OP_DLOPEN_FUNCt   OP_CPYTHON_BLTN_Nt   OP_CPYTHON_BLTN_Ot   OP_CPYTHON_BLTN_VR   RS   R   Re   (   R
   RH   R   R"   R   t	   meth_kind(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _generate_cpy_function_ctx#  s     				c         C   s~   t  | t j  rz | j } | d k rI | j d  } d | | f } n  |  j | d | | j  } t j | |  } n  | S(   Ns   ...R   s   _cffi_array_len(((%s)0)->%s)s   %s[0](   RU   R   R   R\   R   Rs   R   (   R
   t	   tp_structt
   field_namet   tp_fieldt   actual_lengtht   ptr_struct_namet   tp_item(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyRs   9  s    	c         C   sA   |  j  |  |  j r= x$ | j   D] } |  j |  q# Wn  d  S(   N(   Rm   R>   t   anonymous_struct_fieldst   _struct_collecttype(   R
   RH   t   fldtype(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR  E  s    	c         C   s  | j  d  k r d  S|  j } d | f } | d  | d | | f  | d  | d  | d  x | j   D] \ } } } }	 y | j   s | d k r | d | | | f  wr n  xG t | t j  r| j d  k s | j d	 k r| j	 } | d
 } q W| d | j
 d d | d |	 | f  Wqr t k
 rZ}
 | d t |
   qr Xqr W| d  | d | | f  |   d  S(   Ns   _cffi_checkfld_%st   _CFFI_UNUSED_FNs   static void %s(%s *p)R   s8     /* only to generate compile-time warnings or errors */s
     (void)p;i    s>     (void)((p->%s) | 0);  /* check that '%s.%s' is an integer */s   ...s   [0]s     { %s = &p->%s; (void)tmp; }s   *tmps   field %rR   s
     /* %s */R   s(   struct _cffi_align_%s { char x; %s y; };(   Ro   RQ   R   Rr   R   RU   R   R   R\   R   R   R   RN   (   R
   RH   R   R   R   t   checkfuncnamet   fnamet   ftypeR   t   fqualR   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _struct_declL  s6    	



	
c         C   s  |  j  | } d  } g  } t | t j  r; | j d  n  | j d  k r` | j d  d } n  | |  j j j	 k r| d  k s | |  j j j	 k r| j d  k r n+ | j
 s t | j    r n | j d  | j r-| j d k rt d | | j f   n  | j d  q-n | j d  d	 } d
 j |  p?d } g  } | d  k rf|  j }	 t | j |	   }
 x`|
 D]X\ } } } } |  j | | |  } |  j | d | j | f  t } | d k rt } d | } nd | d  k st | t j  r| j d  k rd } n. d | d  k r7| j d  n | j | f } | d  k s_| d k rhd } n; | d  k	 rd | j | f } n d | j d  | f } | j t | | | | t | |  j  |    qzWt |  j d  } |  j d j |  | d  k rd } d } d } q~| d  k	 rCd | j f } d } n d | f } d | f } d  } n d } d } d } | } |  j d j t  | j | | | | | | |   |  j! j" |  d  S(   Nt   _CFFI_F_UNIONt   _CFFI_F_OPAQUEt   opaquet   _CFFI_F_CHECK_FIELDSi   s   %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)t   _CFFI_F_PACKEDt   _CFFI_F_EXTERNALt   externalt   |t   0s   field '%s.%s'i    s   %d /* bits */s
   (size_t)-1s   sizeof(((%s)0)->%s)R   s"   ((char *)&((%s)0)->%s) - (char *)0s   offsetof(%s, %s)R   R   s
   (size_t)-2it   unnameds   sizeof(*(%s)0)s   -1 /* unknown alignment */s
   sizeof(%s)s"   offsetof(struct _cffi_align_%s, y)iR   (#   RK   RQ   RU   R   t	   UnionTypeRS   Ro   R<   Rp   Rq   t   partialt   anyR  t   packedR   R+   R>   R   Rr   Rs   t   _check_not_opaqueR   R   R   R   R\   R   R   Re   R   R   t   extendR!   R   R   (   R
   RH   R   R   R   R"   t   reason_for_not_expandingR#   R'   t   expand_anonymous_struct_unionRr   t   fldnameR  R   R"  R   R   t   offsetR&   t   alignR%   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR   m  s    		
		
				c         C   sZ   x t  | t j  r! | j } q Wt  | t j  rV | j d  k rV t d |   n  d  S(   Ns0   %s is of an opaque type (not declared in cdef())(   RU   R   R   R   R`   Ro   RQ   R   (   R
   RH   t   location(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR2    s
    !c         C   s  t  |  j j    } | j d d    x | D] \ } } | |  j k r/ | j ri t d | f   n  | j j d  r | j d j	   r | j d } nJ | j d k r | j
 d k r d } |  j | d  n t d | f   |  j | d  |  q/ q/ Wd  S(	   NRE   c         S   s   |  d S(   Ni   (    (   t   tp_order(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyRI     R   sD   internal inconsistency: %r is partial but was not seen at this pointt   $i   t   _IO_FILEt   FILEs   internal inconsistency: %r(   R   R^   Ry   R   R   R/  R   R   t
   startswitht   isdigitt	   forcenameR   R   RQ   (   R
   R   RH   t   orderR   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR     s    	%c         C   s   |  j  |  d  S(   N(   R  (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt    _generate_cpy_struct_collecttype  s    c         C   sC   | j  d  } d | k r1 | | j d d  f S| d | f Sd  S(   NR   R   Rw   (   R   R   (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _struct_names  s    c         C   s   |  j  | |  j |   d  S(   N(   R#  RC  (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _generate_cpy_struct_decl  s    c         C   s   |  j  | |  j |   d  S(   N(   R   RC  (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _generate_cpy_struct_ctx  s    c         C   s6   t  | t j  r% |  j | |  n |  j |  d  S(   N(   RU   R   Ra   t   _generate_cpy_enum_collecttypeR  (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt#   _generate_cpy_anonymous_collecttype  s    c         C   s=   t  | t j  r" |  j |  n |  j | | d |  d  S(   Nt   typedef_(   RU   R   Ra   t   _generate_cpy_enum_declR#  (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _generate_cpy_anonymous_decl  s    c         C   s@   t  | t j  r% |  j | |  n |  j | | d |  d  S(   NRH  (   RU   R   Ra   t	   _enum_ctxR   (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _generate_cpy_anonymous_ctx  s    t   constc         C   sY  | | f |  j  k r. t d | | f   n  |  j  j | | f  |  j } d | | f } | r | d |  | d  | d | f  | d | | f  | d  k	 r | d k r d | f } n  | d	 | f  | d
  n  | d  | d  nQ | d  k st  | d |  | d  | d | j d  | f  | d  |   d  S(   Ns    duplicate declaration of %s '%s's   _cffi_%s_%ss$   static int %s(unsigned long long *o)R   s     int n = (%s) <= 0;sI     *o = (unsigned long long)((%s) | 0);  /* check that %s is an integer */i    s   %dUs"     if (!_cffi_check_int(*o, n, %s))s       n |= 2;s     return n;R   s   static void %s(char *o)s     *(%s)o = %s;R   (   R   R   R   R   RQ   RR   R   (   R
   t   is_intR   RH   t   categoryR	   R   t   funcname(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _generate_cpy_const  s2    	



c         C   s0   | j    } | s |  j r, |  j |  n  d  S(   N(   R   R>   Rm   (   R
   RH   R   RN  (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt"   _generate_cpy_constant_collecttype,  s    c         C   s#   | j    } |  j | | |  d  S(   N(   R   RQ  (   R
   RH   R   RN  (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR   1  s    c         C   s   |  j  r( | j   r( t t d  } n4 |  j  r: t } n t } |  j | } t | |  } |  j d j t	 | d | |   d  S(   NiR   s   _cffi_const_%s(
   R>   R   Re   t   OP_CONSTANT_INTt   OP_DLOPEN_CONSTt   OP_CONSTANTRK   R   RS   R   (   R
   RH   R   R   t
   const_kindR"   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR  5  s    		c         C   s   |  j  |  d  S(   N(   Rm   (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyRF  E  s    c         C   s(   x! | j  D] } |  j t |  q
 Wd  S(   N(   t   enumeratorsRQ  R   (   R
   RH   R   t
   enumerator(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyRI  H  s    c         C   sH  |  j  | } t t d  } |  j r2 | j   n  xM t | j | j  D]6 \ } } |  j d j	 t
 | d | | d |  qH W| d  k	 r d | k r |  j r d | } d | } nN | j |  j g   }	 |  j j |	  } t t |  j j |	 d   d k   } d	 j | j  }
 |  j d
 j	 t | j | | | |
   d  S(   NiR   s   _cffi_const_%sR	   R;  s
   sizeof(%s)s   ((%s)-1) <= 0i    R(   R   (   RK   Re   t   OP_ENUMR>   t   check_not_partialt   zipRW  t
   enumvaluesR   RS   R   RQ   t   build_baseinttypeR<   t   sizeoft   intt   castR+   R.   R   (   R
   RH   R   R"   R   RX  t	   enumvalueR   R/   t   basetpR0   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyRK  L  s"    	""
'c         C   s   |  j  | | j    d  S(   N(   RK  R   (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _generate_cpy_enum_ctxa  s    c         C   s   d  S(   N(    (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _generate_cpy_macro_collecttypeg  s    c         C   s5   | d k r d  } n | } |  j t | d | d  S(   Ns   ...R	   (   RQ   RQ  R   (   R
   RH   R   R	   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _generate_cpy_macro_declj  s    	c         C   sw   | d k r4 |  j  r+ t d | f   n  d  } n | } t t d  } |  j d j t | d | | d |  d  S(   Ns   ...sG   cannot use the syntax '...' in '#define %s ...' when using the ABI modeiR   s   _cffi_const_%sR	   (   R>   R   RQ   Re   RS  R   RS   R   (   R
   RH   R   R	   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _generate_cpy_macro_ctxq  s    		c         C   si   t  | t j  re | j } | d k r7 d | f } n  |  j | j d |  } t j | |  } n  | S(   Ns   ...s   _cffi_array_len(%s)s   %s[0](   RU   R   R   R\   R   R   (   R
   RH   t   global_nameR  R  (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR     s    	c         C   s   |  j  |  j | |   d  S(   N(   Rm   R   (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt"   _generate_cpy_variable_collecttype  s    c         C   s   |  j  } |  j | |  } t | t j  rN | j d  k rN | j } d } n d } d | f } | d | j | d |  j	  | d  | d | | f  | d  |   d  S(	   NR   t   &s   *_cffi_var_%s(void)s   static R   R   s     return %s(%s);R   (
   R   R   RU   R   R   R\   RQ   R   R   R|   (   R
   RH   R   R   t	   ampersandR   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _generate_cpy_variable_decl  s    	!			 

c         C   sh   |  j  | |  } |  j | } |  j r1 t } n t } |  j d j t | d | t | |    d  S(   NR   s   _cffi_var_%s(	   R   RK   R>   t   OP_GLOBAL_VARt   OP_GLOBAL_VAR_FR   RS   R   Re   (   R
   RH   R   R"   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _generate_cpy_variable_ctx  s    		c         C   s)   t  | t j  s t  |  j |  d  S(   N(   RU   R   RZ   RR   Rm   (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt'   _generate_cpy_extern_python_collecttype  s    c         C   s  |  j  } t | j t j  r' d } n& d | } d | j j d |  f } | d |  | d |  j | | f  |   g  } d | } x@ t | j  D]/ \ } }	 |	 j d | |  }
 | j	 |
  q Wd	 j
 |  } | p d
 } d | | f } | j d k rd | } n  d   } t t | j  d d  } | | j  r\t | d  } n  t | j t j  rd | j j d  | | j j d  | f } n  | d | | j j |  f  | d  | d |  | d  x t | j  D]t \ } }	 d | }
 t |	 t j  s(| |	  rDd |
 }
 t j |	  }	 n  | d |	 j d  | d |
 f  qW| d |  t | j t j  s| d | j j d  f  n  | d  |   |  j d 7_ d  S(   NR,  s   result of %ss   (int)sizeof(%s)R   s3   static struct _cffi_externpy_s _cffi_externpy__%s =s     { "%s.%s", %s };s   argument of %ss    a%ds   , R   s   %s(%s)t	   __stdcalls   _cffi_stdcall c         S   s   t  |  t j  o |  j d k S(   Ns   long double(   RU   R   R   R   (   RH   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   may_need_128_bits  s    i   i   s!   sizeof(%s) > %d ? sizeof(%s) : %ds   %s%sR   s     char a[%s];s     char *p = a;s   a%dRi  s     *(%s)(p + %d) = %s;R   s,     _cffi_call_python(&_cffi_externpy__%s, p);s     return *(%s)p;R   i   (   R   RU   R   R   RV   R   R=   Rb   RT   RS   R+   R   RA   R   R`   RX   R   (   R
   RH   R   t   tag_and_spaceR   t   size_of_resultR   R  Ri   R   R  R  R  Rq  t	   size_of_a(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _extern_python_decl  sX    		

	 



( 
c         C   s   |  j  | | d  d  S(   Ns   static (   Ru  (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt    _generate_cpy_extern_python_decl  s    c         C   s   |  j  | | d  d  S(   Ns   CFFI_DLLEXPORT (   Ru  (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt#   _generate_cpy_dllexport_python_decl  s    c         C   s   |  j  | | d  d  S(   NR   (   Ru  (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt'   _generate_cpy_extern_python_plus_c_decl  s    c         C   sw   |  j  r t d   n  | j r0 t d   n  |  j | } t t |  } |  j d j t	 | d | | |   d  S(   Ns,   cannot use 'extern "Python"' in the ABI modes$   a vararg function is extern "Python"R   s   &_cffi_externpy__%s(
   R>   R   R   R   RK   Re   t   OP_EXTERN_PYTHONR   RS   R   (   R
   RH   R   R"   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _generate_cpy_extern_python_ctx  s    		c         C   s   |  j  } | d  x | j t  D]w } | d | j    d } xJ | D]B } t |  d k ru | |  d } n  | d t |  f 7} qJ W| |  q# Wd  S(   Ns=   // # NB. this is not a string because of a size limit in MSVCs   // R   iL   s   %d,(   R   t
   splitlinesR   t   rstripR   t   ord(   R
   t   sR   t   linet   printed_linet   c(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR     s    	

	c         C   s   t  t t  |  j | <d  S(   N(   Re   t   OP_PRIMITIVEt	   PRIM_VOIDRO   (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _emit_bytecode_VoidType  s    c         C   s'   t  | j } t t |  |  j | <d  S(   N(   t   PRIMITIVE_TO_INDEXR   Re   R  RO   (   R
   RH   R   R9   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _emit_bytecode_PrimitiveType  s    c         C   s6   d | j  | j  | j  f } t t |  |  j | <d  S(   Nsl   _cffi_prim_int(sizeof(%s), (
           ((%s)-1) | 0 /* check that %s is an integer type */
         ) <= 0)(   R   Re   R  RO   (   R
   RH   R   R~  (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt!   _emit_bytecode_UnknownIntegerType  s    c         C   s0   d | j  | j  f } t t |  |  j | <d  S(   Nsd   _cffi_prim_float(sizeof(%s) *
           (((%s)1) / 2) * 2 /* integer => 0, float => 1 */
         )(   R   Re   R  RO   (   R
   RH   R   R~  (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _emit_bytecode_UnknownFloatType#  s    c         C   s  t  t |  j | j  |  j | <| d 7} xr | j D]g } |  j | } | | k r t | t j  rx |  j	 | |  q t  t
 |  |  j | <n  | d 7} q4 Wt | j  } | j d  k	 r | j d k r | d O} q t d | j f   n  t  t |  |  j | <d  S(   Ni   Rp  i   s   abi=%r(   Re   t   OP_FUNCTIONRK   R   RO   RT   RU   R   R   R  R   R_  R   R   RQ   R   t   OP_FUNCTION_END(   R
   RH   R   Rh   t	   realindexR#   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _emit_bytecode_RawFunctionType)  s     
c         C   s$   t  t |  j | j  |  j | <d  S(   N(   Re   t
   OP_POINTERRK   R   RO   (   R
   RH   R   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _emit_bytecode_PointerType<  s    c         C   s-   | j    } t t |  j |  |  j | <d  S(   N(   Rn   Re   R  RK   RO   (   R
   RH   R   t   raw(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _emit_bytecode_FunctionPtrTypeB  s    c         C   s   |  j  | j } | j d  k r8 t t |  |  j | <n | j d k ro t d t |  j	 d d  f   nV |  j | d d k s t
  t t |  |  j | <t d  t | j   |  j | d <d  S(   Ns   ...si   type %s badly placed: the '...' array length can only be used on global arrays or on fields of structuress   /*...*/i   RG   (   RK   R   R\   RQ   Re   t   OP_OPEN_ARRAYRO   R   RN   R   RR   t   OP_ARRAY(   R
   RH   R   t
   item_index(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _emit_bytecode_ArrayTypeF  s    "c         C   s'   |  j  | } t t |  |  j | <d  S(   N(   R^   Re   t   OP_STRUCT_UNIONRO   (   R
   RH   R   t   struct_index(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _emit_bytecode_StructTypeT  s    c         C   s'   |  j  | } t t |  |  j | <d  S(   N(   R_   Re   RY  RO   (   R
   RH   R   t
   enum_index(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _emit_bytecode_EnumTypeY  s    N(V   R   R   R   R   R   RC   Rk   Rm   RL   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R  R  Rs   R  R#  RQ   R   R2  R   RB  t   _generate_cpy_union_collecttypeRC  RD  t   _generate_cpy_union_declRE  t   _generate_cpy_union_ctxRG  RJ  RL  RQ  RR  R   R  RF  RI  RK  Rc  Rd  Re  Rf  R   Rh  Rk  Rn  Ro  t*   _generate_cpy_dllexport_python_collecttypet.   _generate_cpy_extern_python_plus_c_collecttypeRu  Rv  Rw  Rx  Rz  t"   _generate_cpy_dllexport_python_ctxt&   _generate_cpy_extern_python_plus_c_ctxR   R  R  R  R  R  R  t   _emit_bytecode_ConstPointerTypet   _emit_bytecode_NamedPointerTypeR  R  R  t   _emit_bytecode_UnionTypeR  (    (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR;   {   s   		:							
	4		-			#											!W																									
	5				
										i   t   NativeIOc           B   s   e  Z d    Z RS(   c         C   s;   t  | t  r! | j d  } n  t t |   j |  d  S(   Nt   ascii(   RU   t   unicodet   encodet   superR  R   (   R
   R~  (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR   b  s    (   R   R   R   (    (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyR  a  s   c   
      C   sX  | r d | f GHn  t  |  | d | d  k } | j   | j   t   } | j | |  | j   } yV t | d  / } | j t	 |  d  | k r t
  n  Wd  QX| r d GHn  t SWn t
 k
 rSd | t j   f }	 t |	 d   } | j |  Wd  QXy t j |	 |  Wn. t k
 rNt j |  t j |	 |  n Xt SXd  S(   Ns   generating %sR>   R   i   s   (already up-to-date)s   %s.~%dt   w(   R;   RQ   Rk   R   R  R   t   getvalueR   t   readR   t   IOErrorR   R   t   getpidR   t   renamet   OSErrort   unlinkR   (
   R<   R=   R   t   target_filet   verboset
   recompilerR   t   outputt   f1t   tmp_file(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _make_c_or_py_sourceg  s4    

	c         C   s(   | d  k	 s t  t |  | | | |  S(   N(   RQ   RR   R  (   R<   R=   R   t   target_c_fileR  (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   make_c_source  s    c         C   s   t  |  | d  | |  S(   N(   R  RQ   (   R<   R=   t   target_py_fileR  (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   make_py_source  s    c         C   sp   | j  d  } y$ t j t j j |  | d    Wn t k
 rF n X| d c | 7<t j j |  |  | f S(   NR   i(   Rz   R   t   makedirsR   R+   R  (   t	   outputdirt   modnamet	   extensiont   parts(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _modname_to_file  s    $c         C   s9   t  | |  } |  j | | | f  t | | |  | S(   N(   Rc   RS   t   setattr(   t	   patchlistt   clsR   t   new_metht   old(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _patch_meth  s    c         C   s4   x- t  |   D] \ } } } t | | |  q Wd  S(   N(   t   reversedR  (   R  R  R   t   old_meth(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _unpatch_meths  s    c            s   t  j d k r8 d d l m } t |  | d d    n  t  j d k r~ d d l m }   f d   } t |  | d	 |    n  d  S(
   Nt   win32i(   t   MSVCCompilert   _remove_visual_c_refc         S   s   | S(   N(    (   R
   t   manifest_file(    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyRI     R   t   darwin(   t	   CCompilerc            sS   d |  j  k rC t |  j   |  _  |  j  j d  } d |  j  | <n    |  | |  S(   Ns   -bundles   -dynamiclib(   t	   linker_soR   R   (   R
   RT   t   kwdsRi   (   t   old_link_shared_object(    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   my_link_shared_object  s
    t   link_shared_object(   t   syst   platformt   distutils.msvc9compilerR  R  t   distutils.ccompilerR  (   R  R  R  R  (    (   R  s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _patch_for_embedding  s    	c            s   d d l  m }   j d  rn   d    t j d k rE   d 7  qn t j d k ra   d 7  qn   d	 7  n  t |  | d
   f d    d  S(   Ni(   t	   build_exts   .*iR  s   .dllR  s   .dylibs   .sot   get_ext_filenamec            s     S(   N(    (   R
   t   ext_name(   t   target(    s.   lib/python2.7/site-packages/cffi/recompiler.pyRI     R   (   t   distutils.command.build_extR  t   endswithR  R  R  (   R  R  R  (    (   R  s.   lib/python2.7/site-packages/cffi/recompiler.pyt   _patch_for_target  s    
R   s   .cc         K   sJ  t  | t  s! | j d  } n  |  j r: |  j |  n  | d  k	 r|  j d  k	 } | rk |  j |  n  | d  k r t | | |  \ } } | r | g | } n  t	 j
 j |   } n | } |	 d  k r | r d | }	 q d }	 n  t j | | |  } t |  | | | d | } | rg  } t	 j   } z | rFt |  n  |	 d k rbt | |	  n  | r| d k r}d } n d } d | t	 j
 j |  f GHn  t	 j |  t j d | | |
  } Wd  t	 j |  t |  X| S| | f SnS | d  k rt | | d	  \ } } n  t |  | | d | } | r<| Sd  | f Sd  S(
   NR  s   %s.*R   R  R   s   the current directory iss    setting the current directory tos   %s %rs   .py(   RU   RN   R  t   _windows_unicodet   _apply_windows_unicodeRQ   R   t   _apply_embedding_fixR  R   R   R+   R    t   get_extensionR  t   getcwdR  R  t   abspatht   chdirt   compileR  R  (   R<   R=   R   t   tmpdirt   call_c_compilert   c_filet   source_extensiont   extradirt   compiler_verboseR  t   debugR  t	   embeddingR  t
   ext_c_filet   extt   updatedR  t   cwdt   msgt   outputfilenameRw   (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt	   recompile  sb    						("   R   R  t   ioR   R    R   t   errorR   t   cffi_opcodeR?   R   R   R   R   R!   R.   R:   R;   t   version_infot   StringIOR  t   BytesIOR  R   R  R  R  R  R  R  R  R   RQ   R  (    (    (    s.   lib/python2.7/site-packages/cffi/recompiler.pyt   <module>   s<   $
    							