<s> """<STR_LIT>""" <EOL> from pypy . rpython . tool import rffi_platform <EOL> from pypy . translator . tool . cbuild import ExternalCompilationInfo <EOL> from pypy . rpython . lltypesystem import lltype , rffi <EOL> from pypy . rlib . rarithmetic import intmask <EOL> import os , sys <EOL> WIN32 = os . name == "<STR_LIT>" <EOL> if WIN32 : <EOL> eci = ExternalCompilationInfo ( <EOL> includes = [ '<STR_LIT>' ] , <EOL> libraries = [ '<STR_LIT>' ] , <EOL> ) <EOL> else : <EOL> eci = ExternalCompilationInfo ( ) <EOL> class CConfig : <EOL> _compilation_info_ = eci <EOL> if WIN32 : <EOL> DWORD_PTR = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . LONG ) <EOL> WORD = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . UINT ) <EOL> DWORD = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . UINT ) <EOL> BOOL = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . LONG ) <EOL> BYTE = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . UCHAR ) <EOL> INT = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . INT ) <EOL> LONG = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . LONG ) <EOL> PLONG = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . LONGP ) <EOL> LPVOID = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . INTP ) <EOL> LPCVOID = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . VOIDP ) <EOL> LPSTR = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . CCHARP ) <EOL> LPCSTR = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . CCHARP ) <EOL> LPDWORD = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . INTP ) <EOL> SIZE_T = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . SIZE_T ) <EOL> ULONG_PTR = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . ULONG ) <EOL> HRESULT = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . LONG ) <EOL> HLOCAL = rffi_platform . SimpleType ( "<STR_LIT>" , rffi . VOIDP ) <EOL> FILETIME = rffi_platform . Struct ( '<STR_LIT>' , <EOL> [ ( '<STR_LIT>' , rffi . UINT ) , <EOL> ( '<STR_LIT>' , rffi . UINT ) ] ) <EOL> SYSTEMTIME = rffi_platform . Struct ( '<STR_LIT>' , <EOL> [ ] ) <EOL> LPSECURITY_ATTRIBUTES = rffi_platform . SimpleType ( <EOL> "<STR_LIT>" , rffi . CCHARP ) <EOL> DEFAULT_LANGUAGE = rffi_platform . ConstantInteger ( <EOL> "<STR_LIT>" ) <EOL> for name in """<STR_LIT>""" . split ( ) : <EOL> locals ( ) [ name ] = rffi_platform . ConstantInteger ( name ) <EOL> for k , v in rffi_platform . configure ( CConfig ) . items ( ) : <EOL> globals ( ) [ k ] = v <EOL> def winexternal ( name , args , result ) : <EOL> return rffi . llexternal ( name , args , result , compilation_info = eci , calling_conv = '<STR_LIT>' ) <EOL> if WIN32 : <EOL> HANDLE = rffi . ULONG <EOL> LPHANDLE = rffi . CArrayPtr ( HANDLE ) <EOL> HMODULE = HANDLE <EOL> INVALID_HANDLE_VALUE = rffi . cast ( HANDLE , - <NUM_LIT:1> ) <EOL> PFILETIME = rffi . CArrayPtr ( FILETIME ) <EOL> GetLastError = winexternal ( '<STR_LIT>' , [ ] , DWORD ) <EOL> SetLastError = winexternal ( '<STR_LIT>' , [ DWORD ] , lltype . Void ) <EOL> LoadLibrary = winexternal ( '<STR_LIT>' , [ rffi . CCHARP ] , rffi . VOIDP ) <EOL> GetProcAddress = winexternal ( '<STR_LIT>' , <EOL> [ rffi . VOIDP , rffi . CCHARP ] , <EOL> rffi . VOIDP ) <EOL> FreeLibrary = winexternal ( '<STR_LIT>' , [ rffi . VOIDP ] , BOOL ) <EOL> LocalFree = winexternal ( '<STR_LIT>' , [ HLOCAL ] , DWORD ) <EOL> CloseHandle = winexternal ( '<STR_LIT>' , [ HANDLE ] , lltype . Void ) <EOL> FormatMessage = winexternal ( <EOL> '<STR_LIT>' , <EOL> [ DWORD , rffi . VOIDP , DWORD , DWORD , rffi . CCHARP , DWORD , rffi . VOIDP ] , <EOL> DWORD ) <EOL> _get_osfhandle = rffi . llexternal ( '<STR_LIT>' , [ rffi . INT ] , HANDLE ) <EOL> def FormatError ( code ) : <EOL> return llimpl_FormatError ( code ) <EOL> def llimpl_FormatError ( code ) : <EOL> "<STR_LIT>" <EOL> buf = lltype . malloc ( rffi . VOIDPP . TO , <NUM_LIT:1> , flavor = '<STR_LIT>' ) <EOL> try : <EOL> msglen = FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER | <EOL> FORMAT_MESSAGE_FROM_SYSTEM , <EOL> None , <EOL> code , <EOL> DEFAULT_LANGUAGE , <EOL> rffi . cast ( rffi . VOIDP , buf ) , <EOL> <NUM_LIT:0> , None ) <EOL> if msglen <= <NUM_LIT:2> or msglen > sys . maxint : <EOL> return fake_FormatError ( code ) <EOL> buflen = intmask ( msglen - <NUM_LIT:2> ) <EOL> assert buflen > <NUM_LIT:0> <EOL> result = rffi . charpsize2str ( buf [ <NUM_LIT:0> ] , buflen ) <EOL> LocalFree ( buf [ <NUM_LIT:0> ] ) <EOL> finally : <EOL> lltype . free ( buf , flavor = '<STR_LIT>' ) <EOL> return result <EOL> def fake_FormatError ( code ) : <EOL> return '<STR_LIT>' % ( code , ) <EOL> def lastWindowsError ( context = "<STR_LIT>" ) : <EOL> code = GetLastError ( ) <EOL> return WindowsError ( code , context ) <EOL> def FAILED ( hr ) : <EOL> return rffi . cast ( HRESULT , hr ) < <NUM_LIT:0> <EOL> _GetModuleFileName = winexternal ( '<STR_LIT>' , <EOL> [ HMODULE , rffi . CCHARP , DWORD ] , <EOL> DWORD ) <EOL> def GetModuleFileName ( module ) : <EOL> size = MAX_PATH <EOL> buf = lltype . malloc ( rffi . CCHARP . TO , size , flavor = '<STR_LIT>' ) <EOL> try : <EOL> res = _GetModuleFileName ( module , buf , size ) <EOL> if not res : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT>' . join ( [ buf [ i ] for i in range ( res ) ] ) <EOL> finally : <EOL> lltype . free ( buf , flavor = '<STR_LIT>' ) </s>
