本文整理汇总了Python中pypy.rpython.extfunc.extdef函数的典型用法代码示例。如果您正苦于以下问题:Python extdef函数的具体用法?Python extdef怎么用?Python extdef使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了extdef函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register_os_uname
def register_os_uname(self):
CHARARRAY = lltype.FixedSizeArray(lltype.Char, 1)
class CConfig:
_compilation_info_ = ExternalCompilationInfo(
includes = ['sys/utsname.h']
)
UTSNAME = platform.Struct('struct utsname', [
('sysname', CHARARRAY),
('nodename', CHARARRAY),
('release', CHARARRAY),
('version', CHARARRAY),
('machine', CHARARRAY)])
config = platform.configure(CConfig)
UTSNAMEP = lltype.Ptr(config['UTSNAME'])
os_uname = self.llexternal('uname', [UTSNAMEP], rffi.INT,
compilation_info=CConfig._compilation_info_)
def uname_llimpl():
l_utsbuf = lltype.malloc(UTSNAMEP.TO, flavor='raw')
result = os_uname(l_utsbuf)
if result == -1:
raise OSError(rposix.get_errno(), "os_uname failed")
retval = (
rffi.charp2str(rffi.cast(rffi.CCHARP, l_utsbuf.c_sysname)),
rffi.charp2str(rffi.cast(rffi.CCHARP, l_utsbuf.c_nodename)),
rffi.charp2str(rffi.cast(rffi.CCHARP, l_utsbuf.c_release)),
rffi.charp2str(rffi.cast(rffi.CCHARP, l_utsbuf.c_version)),
rffi.charp2str(rffi.cast(rffi.CCHARP, l_utsbuf.c_machine)),
)
lltype.free(l_utsbuf, flavor='raw')
return retval
return extdef([], (str, str, str, str, str),
"ll_os.ll_uname", llimpl=uname_llimpl)
示例2: register_time_sleep
def register_time_sleep(self):
if sys.platform == 'win32':
MAX = maxint32
Sleep = self.llexternal('Sleep', [rffi.ULONG], lltype.Void)
def time_sleep_llimpl(secs):
millisecs = secs * 1000.0
while millisecs > MAX:
Sleep(MAX)
millisecs -= MAX
Sleep(rffi.cast(rffi.ULONG, int(millisecs)))
else:
c_select = self.llexternal('select', [rffi.INT, rffi.VOIDP,
rffi.VOIDP, rffi.VOIDP,
self.TIMEVALP], rffi.INT)
def time_sleep_llimpl(secs):
void = lltype.nullptr(rffi.VOIDP.TO)
t = lltype.malloc(self.TIMEVAL, flavor='raw')
try:
frac = math.fmod(secs, 1.0)
rffi.setintfield(t, 'c_tv_sec', int(secs))
rffi.setintfield(t, 'c_tv_usec', int(frac*1000000.0))
if rffi.cast(rffi.LONG, c_select(0, void, void, void, t)) != 0:
errno = rposix.get_errno()
if errno != EINTR:
raise OSError(rposix.get_errno(), "Select failed")
finally:
lltype.free(t, flavor='raw')
return extdef([float], None, llimpl=time_sleep_llimpl,
export_name='ll_time.ll_time_sleep')
示例3: register_os_getcwd
def register_os_getcwd(self):
os_getcwd = self.llexternal(underscore_on_windows + 'getcwd',
[rffi.CCHARP, rffi.SIZE_T],
rffi.CCHARP)
def os_getcwd_llimpl():
bufsize = 256
while True:
buf = lltype.malloc(rffi.CCHARP.TO, bufsize, flavor='raw')
res = os_getcwd(buf, rffi.cast(rffi.SIZE_T, bufsize))
if res:
break # ok
error = rposix.get_errno()
lltype.free(buf, flavor='raw')
if error != errno.ERANGE:
raise OSError(error, "getcwd failed")
# else try again with a larger buffer, up to some sane limit
bufsize *= 4
if bufsize > 1024*1024: # xxx hard-coded upper limit
raise OSError(error, "getcwd result too large")
result = rffi.charp2str(res)
lltype.free(buf, flavor='raw')
return result
def os_getcwd_oofakeimpl():
return OOSupport.to_rstr(os.getcwd())
return extdef([], str,
"ll_os.ll_os_getcwd", llimpl=os_getcwd_llimpl,
oofakeimpl=os_getcwd_oofakeimpl)
示例4: register_os_write
def register_os_write(self):
os_write = self.llexternal(underscore_on_windows+'write',
[rffi.INT, rffi.VOIDP, rffi.SIZE_T],
rffi.SIZE_T)
def os_write_llimpl(fd, data):
count = len(data)
outbuf = lltype.malloc(rffi.CCHARP.TO, count, flavor='raw')
try:
for i in range(count):
outbuf[i] = data[i]
written = rffi.cast(lltype.Signed, os_write(
rffi.cast(rffi.INT, fd),
outbuf, rffi.cast(rffi.SIZE_T, count)))
if written < 0:
raise OSError(rposix.get_errno(), "os_write failed")
finally:
lltype.free(outbuf, flavor='raw')
return written
def os_write_oofakeimpl(fd, data):
return os.write(fd, OOSupport.from_rstr(data))
return extdef([int, str], SomeInteger(nonneg=True),
"ll_os.ll_os_write", llimpl=os_write_llimpl,
oofakeimpl=os_write_oofakeimpl)
示例5: register_os_readlink
def register_os_readlink(self):
os_readlink = self.llexternal('readlink',
[rffi.CCHARP, rffi.CCHARP, rffi.SIZE_T],
rffi.INT)
# XXX SSIZE_T in POSIX.1-2001
def os_readlink_llimpl(path):
bufsize = 1023
while True:
l_path = rffi.str2charp(path)
buf = lltype.malloc(rffi.CCHARP.TO, bufsize,
flavor='raw')
res = rffi.cast(lltype.Signed, os_readlink(l_path, buf, bufsize))
lltype.free(l_path, flavor='raw')
if res < 0:
error = rposix.get_errno() # failed
lltype.free(buf, flavor='raw')
raise OSError(error, "readlink failed")
elif res < bufsize:
break # ok
else:
# buf too small, try again with a larger buffer
lltype.free(buf, flavor='raw')
bufsize *= 4
# convert the result to a string
l = [buf[i] for i in range(res)]
result = ''.join(l)
lltype.free(buf, flavor='raw')
return result
return extdef([str], str,
"ll_os.ll_os_readlink",
llimpl=os_readlink_llimpl)
示例6: register_os_waitpid
def register_os_waitpid(self):
if sys.platform.startswith('win'):
# emulate waitpid() with the _cwait() of Microsoft's compiler
os__cwait = self.llexternal('_cwait',
[rffi.INTP, rffi.PID_T, rffi.INT],
rffi.PID_T)
def os_waitpid(pid, status_p, options):
result = os__cwait(status_p, pid, options)
# shift the status left a byte so this is more
# like the POSIX waitpid
status_p[0] <<= 8
return result
else:
# Posix
os_waitpid = self.llexternal('waitpid',
[rffi.PID_T, rffi.INTP, rffi.INT],
rffi.PID_T)
def os_waitpid_llimpl(pid, options):
status_p = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
status_p[0] = rffi.cast(rffi.INT, 0)
result = os_waitpid(rffi.cast(rffi.PID_T, pid),
status_p,
rffi.cast(rffi.INT, options))
result = rffi.cast(lltype.Signed, result)
status = status_p[0]
lltype.free(status_p, flavor='raw')
if result == -1:
raise OSError(rposix.get_errno(), "os_waitpid failed")
return (rffi.cast(lltype.Signed, result),
rffi.cast(lltype.Signed, status))
return extdef([int, int], (int, int),
"ll_os.ll_os_waitpid",
llimpl=os_waitpid_llimpl)
示例7: register_time_clock
def register_time_clock(self):
c_clock = self.llexternal('clock', [], self.CLOCK_T,
threadsafe=False)
if sys.platform == 'win32':
# hacking to avoid LARGE_INTEGER which is a union...
A = lltype.FixedSizeArray(lltype.SignedLongLong, 1)
QueryPerformanceCounter = self.llexternal(
'QueryPerformanceCounter', [lltype.Ptr(A)], lltype.Void,
threadsafe=False)
QueryPerformanceFrequency = self.llexternal(
'QueryPerformanceFrequency', [lltype.Ptr(A)], rffi.INT,
threadsafe=False)
class State(object):
pass
state = State()
state.divisor = 0.0
state.counter_start = 0
def time_clock_llimpl():
a = lltype.malloc(A, flavor='raw')
if state.divisor == 0.0:
QueryPerformanceCounter(a)
state.counter_start = a[0]
QueryPerformanceFrequency(a)
state.divisor = float(a[0])
QueryPerformanceCounter(a)
diff = a[0] - state.counter_start
lltype.free(a, flavor='raw')
return float(diff) / state.divisor
else:
def time_clock_llimpl():
result = c_clock()
return float(result) / self.CLOCKS_PER_SEC
return extdef([], float, llimpl=time_clock_llimpl,
export_name='ll_time.ll_time_clock')
示例8: register_os_execve
def register_os_execve(self):
os_execve = self.llexternal(
'execve', [rffi.CCHARP, rffi.CCHARPP, rffi.CCHARPP], rffi.INT)
def execve_llimpl(path, args, env):
# XXX Check path, args, env for \0 and raise TypeErrors as
# appropriate
envstrs = []
for item in env.iteritems():
envstrs.append("%s=%s" % item)
l_args = rffi.liststr2charpp(args)
l_env = rffi.liststr2charpp(envstrs)
os_execve(path, l_args, l_env)
# XXX untested
rffi.free_charpp(l_env)
rffi.free_charpp(l_args)
raise OSError(rposix.get_errno(), "execve failed")
return extdef(
[str, [str], {str: str}],
s_ImpossibleValue,
llimpl=execve_llimpl,
export_name="ll_os.ll_os_execve")
示例9: register_os_read
def register_os_read(self):
os_read = self.llexternal(underscore_on_windows+'read',
[rffi.INT, rffi.VOIDP, rffi.SIZE_T],
rffi.SIZE_T)
def os_read_llimpl(fd, count):
if count < 0:
raise OSError(errno.EINVAL, None)
inbuf = lltype.malloc(rffi.CCHARP.TO, count, flavor='raw')
try:
got = rffi.cast(lltype.Signed, os_read(rffi.cast(rffi.INT, fd),
inbuf, rffi.cast(rffi.SIZE_T, count)))
if got < 0:
raise OSError(rposix.get_errno(), "os_read failed")
# XXX too many copies of the data!
l = [inbuf[i] for i in range(got)]
finally:
lltype.free(inbuf, flavor='raw')
return ''.join(l)
def os_read_oofakeimpl(fd, count):
return OOSupport.to_rstr(os.read(fd, count))
return extdef([int, int], str, "ll_os.ll_os_read",
llimpl=os_read_llimpl, oofakeimpl=os_read_oofakeimpl)
示例10: register_time_time
def register_time_time(self):
# Note: time.time() is used by the framework GC during collect(),
# which means that we have to be very careful about not allocating
# GC memory here. This is the reason for the _nowrapper=True.
# AWFUL
if self.HAVE_GETTIMEOFDAY:
if self.GETTIMEOFDAY_NO_TZ:
c_gettimeofday = self.llexternal('gettimeofday',
[self.TIMEVALP], rffi.INT,
_nowrapper=True, threadsafe=False)
else:
c_gettimeofday = self.llexternal('gettimeofday',
[self.TIMEVALP, rffi.VOIDP], rffi.INT,
_nowrapper=True, threadsafe=False)
else:
c_gettimeofday = None
if self.HAVE_FTIME:
self.configure(CConfigForFTime)
c_ftime = self.llexternal(FTIME, [lltype.Ptr(self.TIMEB)],
lltype.Void,
_nowrapper=True, threadsafe=False)
else:
c_ftime = None # to not confuse the flow space
c_time = self.llexternal('time', [rffi.VOIDP], rffi.TIME_T,
_nowrapper=True, threadsafe=False)
def time_time_llimpl():
void = lltype.nullptr(rffi.VOIDP.TO)
result = -1.0
if self.HAVE_GETTIMEOFDAY:
t = lltype.malloc(self.TIMEVAL, flavor='raw')
errcode = -1
if self.GETTIMEOFDAY_NO_TZ:
errcode = g_gettimeofday(t)
else:
errcode = c_gettimeofday(t, void)
if rffi.cast(rffi.LONG, errcode) == 0:
result = float(rffi.cast(lltype.Signed, t.c_tv_sec)) \
+ float(rffi.cast(lltype.Signed, t.c_tv_usec)) \
* 0.000001
lltype.free(t, flavor='raw')
if result != -1:
return result
if self.HAVE_FTIME:
t = lltype.malloc(self.TIMEB, flavor='raw')
c_ftime(t)
result = float(int(t.c_time)) + float(int(t.c_millitm)) * 0.001
lltype.free(t, flavor='raw')
return result
return float(c_time(void))
return extdef([], float, llimpl=time_time_llimpl,
export_name='ll_time.ll_time_time')
示例11: register_os__exit
def register_os__exit(self):
os__exit = self.llexternal('_exit', [rffi.INT], lltype.Void)
def _exit_llimpl(status):
os__exit(rffi.cast(rffi.INT, status))
return extdef([int], s_None, llimpl=_exit_llimpl,
export_name="ll_os.ll_os__exit")
示例12: register_os_isatty
def register_os_isatty(self):
os_isatty = self.llexternal(underscore_on_windows+'isatty', [rffi.INT], rffi.INT)
def isatty_llimpl(fd):
res = rffi.cast(rffi.LONG, os_isatty(rffi.cast(rffi.INT, fd)))
return res != 0
return extdef([int], bool, llimpl=isatty_llimpl,
export_name="ll_os.ll_os_isatty")
示例13: register_os_umask
def register_os_umask(self):
os_umask = self.llexternal(underscore_on_windows+'umask', [rffi.MODE_T], rffi.MODE_T)
def umask_llimpl(fd):
res = os_umask(rffi.cast(rffi.MODE_T, fd))
return rffi.cast(lltype.Signed, res)
return extdef([int], int, llimpl=umask_llimpl,
export_name="ll_os.ll_os_umask")
示例14: register_os_system
def register_os_system(self):
os_system = self.llexternal('system', [rffi.CCHARP], rffi.INT)
def system_llimpl(command):
res = os_system(command)
return rffi.cast(lltype.Signed, res)
return extdef([str], int, llimpl=system_llimpl,
export_name="ll_os.ll_os_system")
示例15: register_os_unlink
def register_os_unlink(self):
os_unlink = self.llexternal(underscore_on_windows+'unlink', [rffi.CCHARP], rffi.INT)
def unlink_llimpl(pathname):
res = rffi.cast(lltype.Signed, os_unlink(pathname))
if res < 0:
raise OSError(rposix.get_errno(), "os_unlink failed")
return extdef([str], s_None, llimpl=unlink_llimpl,
export_name="ll_os.ll_os_unlink")