<s> import py <EOL> from pypy . rpython . extfunc import BaseLazyRegistering , extdef , registering <EOL> from pypy . rlib import rarithmetic <EOL> from pypy . rpython . lltypesystem import lltype , rffi <EOL> from pypy . tool . autopath import pypydir <EOL> from pypy . rpython . ootypesystem import ootype <EOL> from pypy . rlib import rposix <EOL> from pypy . translator . tool . cbuild import ExternalCompilationInfo <EOL> from pypy . tool . autopath import pypydir <EOL> class CConfig : <EOL> _compilation_info_ = ExternalCompilationInfo ( <EOL> includes = [ '<STR_LIT>' ] , <EOL> include_dirs = [ str ( py . path . local ( pypydir ) . join ( '<STR_LIT>' , '<STR_LIT:c>' ) ) ] , <EOL> separate_module_sources = [ '<STR_LIT>' ] , <EOL> export_symbols = [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ) <EOL> class RegisterStrtod ( BaseLazyRegistering ) : <EOL> def __init__ ( self ) : <EOL> self . configure ( CConfig ) <EOL> @ registering ( rarithmetic . formatd ) <EOL> def register_formatd ( self ) : <EOL> ll_strtod = self . llexternal ( '<STR_LIT>' , <EOL> [ rffi . CCHARP , rffi . DOUBLE ] , rffi . CCHARP , <EOL> sandboxsafe = True , threadsafe = False ) <EOL> def llimpl ( fmt , x ) : <EOL> res = ll_strtod ( fmt , x ) <EOL> return rffi . charp2str ( res ) <EOL> def oofakeimpl ( fmt , x ) : <EOL> return ootype . oostring ( rarithmetic . formatd ( fmt . _str , x ) , - <NUM_LIT:1> ) <EOL> return extdef ( [ str , float ] , str , '<STR_LIT>' , <EOL> llimpl = llimpl , oofakeimpl = oofakeimpl , <EOL> sandboxsafe = True ) <EOL> @ registering ( rarithmetic . parts_to_float ) <EOL> def register_parts_to_float ( self ) : <EOL> ll_parts_to_float = self . llexternal ( '<STR_LIT>' , <EOL> [ rffi . CCHARP ] * <NUM_LIT:4> , rffi . DOUBLE , <EOL> sandboxsafe = True , <EOL> threadsafe = False ) <EOL> def llimpl ( sign , beforept , afterpt , exponent ) : <EOL> res = ll_parts_to_float ( sign , beforept , afterpt , exponent ) <EOL> if res == - <NUM_LIT:1> and rposix . get_errno ( ) == <NUM_LIT> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return res <EOL> def oofakeimpl ( sign , beforept , afterpt , exponent ) : <EOL> return rarithmetic . parts_to_float ( sign . _str , beforept . _str , <EOL> afterpt . _str , exponent . _str ) <EOL> return extdef ( [ str , str , str , str ] , float , <EOL> '<STR_LIT>' , llimpl = llimpl , <EOL> oofakeimpl = oofakeimpl , sandboxsafe = True ) </s>
