Commit b6a42152 authored by GalaxySnail's avatar GalaxySnail Committed by GitHub

Add `uio.pxd` and update some posix pxds (GH-4526)

* Add a wrapper for posix <sys/uio.h>
* Add a script to generate tests for posix pxds
* Generate `tests/compile/posix_pxds.pyx`
* Update fcntl.pxd to POSIX.1-2017
* Update urls for posix/mman.pxd
* Update urls for posix/resource.pxd
* Add url for posix/select.pxd, and remove a `const`
* Update stat.pxd to POSIX.1-2017
* Update url for posix/wait.pxd

Closes https://github.com/cython/cython/issues/4522
parent 13046485
# http://www.opengroup.org/onlinepubs/009695399/basedefs/fcntl.h.html
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/fcntl.h.html
from posix.types cimport mode_t, off_t, pid_t
cdef extern from "<fcntl.h>" nogil:
enum: F_DUPFD
enum: F_DUPFD_CLOEXEC
enum: F_GETFD
enum: F_SETFD
enum: F_GETFL
......@@ -23,11 +26,14 @@ cdef extern from "<fcntl.h>" nogil:
enum: SEEK_CUR
enum: SEEK_END
enum: O_CLOEXEC
enum: O_CREAT
enum: O_DIRECT
enum: O_DIRECTORY
enum: O_EXCL
enum: O_NOCTTY
enum: O_TRUNC
enum: O_TTY_INIT
enum: O_APPEND
enum: O_DSYNC
......@@ -37,9 +43,17 @@ cdef extern from "<fcntl.h>" nogil:
enum: O_ACCMODE # O_RDONLY|O_WRONLY|O_RDWR
enum: O_EXEC
enum: O_RDONLY
enum: O_WRONLY
enum: O_RDWR
enum: O_SEARCH
enum: AT_FDCWD
enum: AT_EACCESS
enum: AT_SYMLINK_NOFOLLOW
enum: AT_SYMLINK_FOLLOW
enum: AT_REMOVEDIR
enum: S_IFMT
enum: S_IFBLK
......@@ -50,9 +64,12 @@ cdef extern from "<fcntl.h>" nogil:
enum: S_IFLNK
enum: S_IFSOCK
ctypedef int mode_t
ctypedef signed pid_t
ctypedef signed off_t
enum: POSIX_FADV_DONTNEED
enum: POSIX_FADV_NOREUSE
enum: POSIX_FADV_NORMAL
enum: POSIX_FADV_RANDOM
enum: POSIX_FADV_SEQUENTIAL
enum: POSIX_FADV_WILLNEED
struct flock:
short l_type
......@@ -61,8 +78,10 @@ cdef extern from "<fcntl.h>" nogil:
off_t l_len
pid_t l_pid
int creat(char *, mode_t)
int creat(const char *, mode_t)
int fcntl(int, int, ...)
int open(char *, int, ...)
#int open (char *, int, mode_t)
int open(const char *, int, ...)
int openat(int, const char *, int, ...)
int posix_fadvise(int, off_t, off_t, int)
int posix_fallocate(int, off_t, off_t)
# https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/mman.h.html
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_mman.h.html
# https://man7.org/linux/man-pages/man2/mmap.2.html
# https://www.freebsd.org/cgi/man.cgi?query=mmap&sektion=2
from posix.types cimport off_t, mode_t
......
# https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/resource.h.html
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_resource.h.html
# https://man7.org/linux/man-pages/man2/getrusage.2.html
from posix.time cimport timeval
from posix.types cimport id_t
......@@ -33,6 +34,7 @@ cdef extern from "<sys/resource.h>" nogil:
cdef struct rusage:
timeval ru_utime
timeval ru_stime
# Linux-specific
long ru_maxrss
long ru_ixrss
long ru_idrss
......
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_select.h.html
from .types cimport sigset_t
from .time cimport timeval, timespec
......@@ -12,7 +14,7 @@ cdef extern from "<sys/select.h>" nogil:
void FD_ZERO(fd_set*)
int select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, const timeval *timeout)
fd_set *exceptfds, timeval *timeout)
int pselect(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, const timespec *timeout,
......
# https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/stat.h.html
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html
from posix.types cimport (blkcnt_t, blksize_t, dev_t, gid_t, ino_t, mode_t,
nlink_t, off_t, time_t, uid_t)
from posix.time cimport timespec
cdef extern from "<sys/stat.h>" nogil:
......@@ -14,9 +18,14 @@ cdef extern from "<sys/stat.h>" nogil:
off_t st_size
blksize_t st_blksize
blkcnt_t st_blocks
# POSIX.1-2001
time_t st_atime
time_t st_mtime
time_t st_ctime
# POSIX.1-2008
timespec st_atim
timespec st_mtim
timespec st_ctim
# st_birthtime exists on *BSD and OS X.
# Under Linux, defining it here does not hurt. Compilation under Linux
......@@ -25,12 +34,24 @@ cdef extern from "<sys/stat.h>" nogil:
# POSIX prescribes including both <sys/stat.h> and <unistd.h> for these
cdef extern from "<unistd.h>" nogil:
int fchmod(int, mode_t)
int chmod(const char *, mode_t)
int fchmod(int, mode_t)
int fchmodat(int, const char *, mode_t, int flags)
int fstat(int, struct_stat *)
int lstat(const char *, struct_stat *)
int stat(const char *, struct_stat *)
int lstat(const char *, struct_stat *)
int fstat(int, struct_stat *)
int fstatat(int, const char *, struct_stat *, int flags)
int mkdir(const char *, mode_t)
int mkdirat(int, const char *, mode_t)
int mkfifo(const char *, mode_t)
int mkfifoat(int, const char *, mode_t)
int mknod(const char *, mode_t, dev_t)
int mknodat(int, const char *, mode_t, dev_t)
int futimens(int, const timespec *)
int utimensat(int, const char *, const timespec *, int flags)
# Macros for st_mode
mode_t S_ISREG(mode_t)
......@@ -69,3 +90,10 @@ cdef extern from "<unistd.h>" nogil:
mode_t S_IROTH
mode_t S_IWOTH
mode_t S_IXOTH
# test file types
bint S_TYPEISMQ(struct_stat *buf)
bint S_TYPEISSEM(struct_stat *buf)
bint S_TYPEISSHM(struct_stat *buf)
bint S_TYPEISTMO(struct_stat *buf)
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_uio.h.html
from posix.types cimport off_t
cdef extern from "<sys/uio.h>" nogil:
cdef struct iovec:
void *iov_base
size_t iov_len
ssize_t readv (int fd, const iovec *iov, int iovcnt)
ssize_t writev(int fd, const iovec *iov, int iovcnt)
# Linux-specific, https://man7.org/linux/man-pages/man2/readv.2.html
ssize_t preadv (int fd, const iovec *iov, int iovcnt, off_t offset)
ssize_t pwritev(int fd, const iovec *iov, int iovcnt, off_t offset)
enum: RWF_DSYNC
enum: RWF_HIPRI
enum: RWF_SYNC
enum: RWF_NOWAIT
enum: RWF_APPEND
ssize_t preadv2 (int fd, const iovec *iov, int iovcnt, off_t offset, int flags)
ssize_t pwritev2(int fd, const iovec *iov, int iovcnt, off_t offset, int flags)
# https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/wait.h.html
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html
from posix.types cimport pid_t, id_t
from posix.signal cimport siginfo_t
......
#!/usr/bin/python3
from pathlib import Path
PROJECT_ROOT = Path(__file__) / "../.."
POSIX_PXDS_DIR = PROJECT_ROOT / "Cython/Includes/posix"
TEST_PATH = PROJECT_ROOT / "tests/compile/posix_pxds.pyx"
def main():
datas = [
"# tag: posix\n"
"# mode: compile\n"
"\n"
"# This file is generated by `Tools/gen_tests_for_posix_pxds.py`.\n"
"\n"
"cimport posix\n"
]
filenames = sorted(map(lambda path: path.name, POSIX_PXDS_DIR.iterdir()))
for name in filenames:
if name == "__init__.pxd":
continue
if name.endswith(".pxd"):
name = name[:-4]
else:
continue
s = (
"cimport posix.{name}\n"
"from posix cimport {name}\n"
"from posix.{name} cimport *\n"
).format(name=name)
datas.append(s)
with open(TEST_PATH, "w", encoding="utf-8", newline="\n") as f:
f.write("\n".join(datas))
if __name__ == "__main__":
main()
# tag: posix
# mode: compile
# This file is generated by `Tools/gen_tests_for_posix_pxds.py`.
cimport posix
cimport posix.unistd
from posix cimport unistd
from posix.unistd cimport *
cimport posix.dlfcn
from posix cimport dlfcn
from posix.dlfcn cimport *
cimport posix.fcntl
from posix cimport fcntl
from posix.fcntl cimport *
from posix.fcntl cimport *
cimport posix.types
from posix cimport types
from posix.types cimport *
cimport posix.ioctl
from posix cimport ioctl
from posix.ioctl cimport *
cimport posix.mman
from posix cimport mman
from posix.mman cimport *
cimport posix.resource
from posix cimport resource
from posix.resource cimport *
cimport posix.select
from posix cimport select
from posix.select cimport *
cimport posix.signal
from posix cimport signal
......@@ -31,22 +45,26 @@ cimport posix.stdlib
from posix cimport stdlib
from posix.stdlib cimport *
cimport posix.strings
from posix cimport strings
from posix.strings cimport *
cimport posix.time
from posix cimport time
from posix.time cimport *
cimport posix.resource
from posix cimport resource
from posix.resource cimport *
cimport posix.types
from posix cimport types
from posix.types cimport *
cimport posix.uio
from posix cimport uio
from posix.uio cimport *
cimport posix.unistd
from posix cimport unistd
from posix.unistd cimport *
cimport posix.wait
from posix cimport wait
from posix.wait cimport *
cimport posix.mman
from posix cimport mman
from posix.mman cimport *
cimport posix.dlfcn
from posix cimport dlfcn
from posix.dlfcn cimport *
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment