本文整理汇总了Python中pypy.rlib.rposix.get_errno函数的典型用法代码示例。如果您正苦于以下问题:Python get_errno函数的具体用法?Python get_errno怎么用?Python get_errno使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_errno函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: time_sleep_llimpl
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)
t.c_tv_sec = int(secs)
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')
示例2: tcsetattr_llimpl
def tcsetattr_llimpl(fd, when, attributes):
c_struct = lltype.malloc(TERMIOSP.TO, flavor='raw')
c_struct.c_c_iflag, c_struct.c_c_oflag, c_struct.c_c_cflag, \
c_struct.c_c_lflag, ispeed, ospeed, cc = attributes
try:
for i in range(NCCS):
c_struct.c_c_cc[i] = rffi.r_uchar(ord(cc[i][0]))
if c_cfsetispeed(c_struct, ispeed) < 0:
raise OSError(rposix.get_errno(), 'tcsetattr failed')
if c_cfsetospeed(c_struct, ospeed) < 0:
raise OSError(rposix.get_errno(), 'tcsetattr failed')
if c_tcsetattr(fd, when, c_struct) < 0:
raise OSError(rposix.get_errno(), 'tcsetattr failed')
finally:
lltype.free(c_struct, flavor='raw')
示例3: flush
def flush(self, offset=0, size=0):
self.check_valid()
if size == 0:
size = self.size
if offset < 0 or size < 0 or offset + size > self.size:
raise RValueError("flush values out of range")
else:
start = self.getptr(offset)
if _MS_WINDOWS:
res = FlushViewOfFile(start, size)
# XXX res == 0 means that an error occurred, but in CPython
# this is not checked
return res
elif _POSIX:
## XXX why is this code here? There is no equivalent in CPython
## if _LINUX:
## # alignment of the address
## value = cast(self.data, c_void_p).value
## aligned_value = value & ~(PAGESIZE - 1)
## # the size should be increased too. otherwise the final
## # part is not "msynced"
## new_size = size + value & (PAGESIZE - 1)
res = c_msync(start, size, MS_SYNC)
if res == -1:
errno = rposix.get_errno()
raise OSError(errno, os.strerror(errno))
return 0
示例4: startup
def startup(self):
if not OPROFILE_AVAILABLE:
return
agent = op_open_agent()
if not agent:
raise OProfileError(get_errno(), "startup")
self.agent = agent
示例5: bindtextdomain
def bindtextdomain(space, domain, w_dir):
"""bindtextdomain(domain, dir) -> string
Bind the C library's domain to dir."""
if space.is_w(w_dir, space.w_None):
dir = None
domain_c = rffi.str2charp(domain)
try:
dirname = _bindtextdomain(domain_c, dir)
finally:
rffi.free_charp(domain_c)
else:
dir = space.str_w(w_dir)
domain_c = rffi.str2charp(domain)
dir_c = rffi.str2charp(dir)
try:
dirname = _bindtextdomain(domain_c, dir_c)
finally:
rffi.free_charp(domain_c)
rffi.free_charp(dir_c)
if not dirname:
errno = rposix.get_errno()
raise OperationError(space.w_OSError, space.wrap(errno))
return space.wrap(rffi.charp2str(dirname))
示例6: spawnv_llimpl
def spawnv_llimpl(mode, path, args):
mode = rffi.cast(rffi.INT, mode)
l_args = rffi.liststr2charpp(args)
childpid = os_spawnv(mode, path, l_args)
rffi.free_charpp(l_args)
if childpid == -1:
raise OSError(rposix.get_errno(), "os_spawnv failed")
return rffi.cast(lltype.Signed, childpid)
示例7: mkdir_llimpl
def mkdir_llimpl(pathname, mode):
if IGNORE_MODE:
res = os_mkdir(pathname)
else:
res = os_mkdir(pathname, mode)
res = rffi.cast(lltype.Signed, res)
if res < 0:
raise OSError(rposix.get_errno(), "os_mkdir failed")
示例8: native_code_written
def native_code_written(self, name, address, size):
assert size > 0
if not OPROFILE_AVAILABLE:
return
uaddress = rffi.cast(rffi.ULONG, address)
success = op_write_native_code(self.agent, name, uaddress, rffi.cast(rffi.VOIDP, 0), size)
if success != 0:
raise OProfileError(get_errno(), "write")
示例9: _check_error
def _check_error(x):
errno = rposix.get_errno()
if errno:
if errno == ERANGE:
if not x:
return # we consider underflow to not be an error, like CPython
raise OverflowError("math range error")
else:
raise ValueError("math domain error")
示例10: sh_cmd
def sh_cmd(vm):
(cmd_o,),_ = vm.decode_args("S")
assert isinstance(cmd_o, Con_String)
r = system(cmd_o.v)
if r == -1:
vm.raise_helper("Exception", [Con_String(vm, os.strerror(rposix.get_errno()))])
return Con_Int(vm, os.WEXITSTATUS(r))
示例11: flush
def flush(self):
if self.buf_count > 0:
bytes = self.buf_count * rffi.sizeof(rffi.LONG)
count = raw_os_write(self.fd,
rffi.cast(llmemory.Address, self.writebuffer),
rffi.cast(rffi.SIZE_T, bytes))
if rffi.cast(lltype.Signed, count) != bytes:
raise OSError(rposix.get_errno(), "raw_os_write failed")
self.buf_count = 0
示例12: lseek_llimpl
def lseek_llimpl(fd, pos, how):
how = fix_seek_arg(how)
res = os_lseek(rffi.cast(rffi.INT, fd),
rffi.cast(rffi.LONGLONG, pos),
rffi.cast(rffi.INT, how))
res = rffi.cast(lltype.SignedLongLong, res)
if res < 0:
raise OSError(rposix.get_errno(), "os_lseek failed")
return res
示例13: PyOS_string_to_double
def PyOS_string_to_double(space, s, endptr, w_overflow_exception):
"""Convert a string s to a double, raising a Python
exception on failure. The set of accepted strings corresponds to
the set of strings accepted by Python's float() constructor,
except that s must not have leading or trailing whitespace.
The conversion is independent of the current locale.
If endptr is NULL, convert the whole string. Raise
ValueError and return -1.0 if the string is not a valid
representation of a floating-point number.
If endptr is not NULL, convert as much of the string as
possible and set *endptr to point to the first unconverted
character. If no initial segment of the string is the valid
representation of a floating-point number, set *endptr to point
to the beginning of the string, raise ValueError, and return
-1.0.
If s represents a value that is too large to store in a float
(for example, "1e500" is such a string on many platforms) then
if overflow_exception is NULL return Py_HUGE_VAL (with
an appropriate sign) and don't set any exception. Otherwise,
overflow_exception must point to a Python exception object;
raise that exception and return -1.0. In both cases, set
*endptr to point to the first character after the converted value.
If any other error occurs during the conversion (for example an
out-of-memory error), set the appropriate Python exception and
return -1.0.
"""
user_endptr = True
try:
if not endptr:
endptr = lltype.malloc(rffi.CCHARPP.TO, 1, flavor='raw')
user_endptr = False
result = rdtoa.dg_strtod(s, endptr)
endpos = (rffi.cast(rffi.LONG, endptr[0]) -
rffi.cast(rffi.LONG, s))
if endpos == 0 or (not user_endptr and not endptr[0][0] == '\0'):
raise OperationError(
space.w_ValueError,
space.wrap('invalid input at position %s' % endpos))
if rposix.get_errno() == errno.ERANGE:
rposix.set_errno(0)
if w_overflow_exception is None:
if result > 0:
return rfloat.INFINITY
else:
return -rfloat.INFINITY
else:
raise OperationError(w_overflow_exception,
space.wrap('value too large'))
return result
finally:
if not user_endptr:
lltype.free(endptr, flavor='raw')
示例14: os_pipe_llimpl
def os_pipe_llimpl():
filedes = lltype.malloc(INT_ARRAY_P.TO, 2, flavor='raw')
error = rffi.cast(lltype.Signed, os_pipe(filedes))
read_fd = filedes[0]
write_fd = filedes[1]
lltype.free(filedes, flavor='raw')
if error != 0:
raise OSError(rposix.get_errno(), "os_pipe failed")
return (rffi.cast(lltype.Signed, read_fd),
rffi.cast(lltype.Signed, write_fd))
示例15: os_listdir_llimpl
def os_listdir_llimpl(path):
dirp = os_opendir(path)
if not dirp:
raise OSError(rposix.get_errno(), "os_opendir failed")
rposix.set_errno(0)
result = []
while True:
direntp = os_readdir(dirp)
if not direntp:
error = rposix.get_errno()
break
namep = rffi.cast(rffi.CCHARP, direntp.c_d_name)
name = rffi.charp2str(namep)
if name != '.' and name != '..':
result.append(name)
os_closedir(dirp)
if error:
raise OSError(error, "os_readdir failed")
return result