def _sem_timedwait_save(sem, deadline): delay = 0 void = lltype.nullptr(rffi.VOIDP.TO) with lltype.scoped_alloc(TIMEVALP.TO, 1) as tvdeadline: while True: # poll if _sem_trywait(sem) == 0: return 0 elif rposix.get_saved_errno() != errno.EAGAIN: return -1 now = gettimeofday() c_tv_sec = rffi.getintfield(deadline[0], 'c_tv_sec') c_tv_nsec = rffi.getintfield(deadline[0], 'c_tv_nsec') if (c_tv_sec < now[0] or (c_tv_sec == now[0] and c_tv_nsec <= now[1])): rposix.set_saved_errno(errno.ETIMEDOUT) return -1 # calculate how much time is left difference = ((c_tv_sec - now[0]) * 1000000 + (c_tv_nsec - now[1])) # check delay not too long -- maximum is 20 msecs if delay > 20000: delay = 20000 if delay > difference: delay = difference delay += 1000 # sleep rffi.setintfield(tvdeadline[0], 'c_tv_sec', delay / 1000000) rffi.setintfield(tvdeadline[0], 'c_tv_usec', delay % 1000000) if _select(0, void, void, void, tvdeadline) < 0: return -1
def f(n, x, *args): rposix.set_saved_errno(24) result1 = c_test() result2 = rposix.get_saved_errno() assert result1 == 24 assert result2 == 42 n -= 1 return (n, x) + args
def readdir(dirp): rposix.set_saved_errno(0) direntp = os_readdir(dirp) if not direntp: if rposix.get_saved_errno() == 0: return None else: raise OSError(rposix.get_saved_errno(), "error in readdir") namep = rffi.cast(rffi.CCHARP, direntp.c_d_name) return rffi.charp2str(namep)
def f(): set_saved_errno(12) return get_saved_errno()
def check_errno(value): rposix.set_saved_errno(value) for i in range(10000000): pass assert rposix.get_saved_errno() == value
def set_errno(space, w_errno): rposix.set_saved_errno(space.int_w(w_errno))
def set_errno(space, errno): rposix.set_saved_errno(errno)