Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
9cb90055
Commit
9cb90055
authored
May 05, 2010
by
Lisandro Dalcin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add some POSIX pxd's and a few tests
parent
68b24fae
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
298 additions
and
1 deletion
+298
-1
Cython/Includes/posix/__init__.pxd
Cython/Includes/posix/__init__.pxd
+1
-0
Cython/Includes/posix/fcntl.pxd
Cython/Includes/posix/fcntl.pxd
+67
-0
Cython/Includes/posix/unistd.pxd
Cython/Includes/posix/unistd.pxd
+127
-0
runtests.py
runtests.py
+2
-1
tests/compile/posix_pxds.pyx
tests/compile/posix_pxds.pyx
+9
-0
tests/run/posix_test.pyx
tests/run/posix_test.pyx
+92
-0
No files found.
Cython/Includes/posix/__init__.pxd
0 → 100644
View file @
9cb90055
# empty file
Cython/Includes/posix/fcntl.pxd
0 → 100644
View file @
9cb90055
# http://www.opengroup.org/onlinepubs/009695399/basedefs/fcntl.h.html
cdef
extern
from
"fcntl.h"
nogil
:
enum
:
F_DUPFD
enum
:
F_GETFD
enum
:
F_SETFD
enum
:
F_GETFL
enum
:
F_SETFL
enum
:
F_GETLK
enum
:
F_SETLK
enum
:
F_SETLKW
enum
:
F_GETOWN
enum
:
F_SETOWN
enum
:
FD_CLOEXEC
enum
:
F_RDLCK
enum
:
F_UNLCK
enum
:
F_WRLCK
enum
:
SEEK_SET
enum
:
SEEK_CUR
enum
:
SEEK_END
enum
:
O_CREAT
enum
:
O_EXCL
enum
:
O_NOCTTY
enum
:
O_TRUNC
enum
:
O_APPEND
enum
:
O_DSYNC
enum
:
O_NONBLOCK
enum
:
O_RSYNC
enum
:
O_SYNC
enum
:
O_ACCMODE
# O_RDONLY|O_WRONLY|O_RDWR
enum
:
O_RDONLY
enum
:
O_WRONLY
enum
:
O_RDWR
enum
:
S_IFMT
enum
:
S_IFBLK
enum
:
S_IFCHR
enum
:
S_IFIFO
enum
:
S_IFREG
enum
:
S_IFDIR
enum
:
S_IFLNK
enum
:
S_IFSOCK
ctypedef
int
mode_t
ctypedef
signed
pid_t
ctypedef
signed
off_t
struct
flock
:
short
l_type
short
l_whence
off_t
l_start
off_t
l_len
pid_t
l_pid
int
creat
(
char
*
,
mode_t
)
int
fcntl
(
int
,
int
,
...)
int
open
(
char
*
,
int
,
...)
#int open (char *, int, mode_t)
Cython/Includes/posix/unistd.pxd
0 → 100644
View file @
9cb90055
# http://www.opengroup.org/onlinepubs/009695399/basedefs/unistd.h.html
cdef
extern
from
"unistd.h"
nogil
:
#:NULL
enum
:
R_OK
enum
:
W_OK
enum
:
X_OK
enum
:
F_OK
# confstr()
#_CS_PATH
#_CS_POSIX_*
enum
:
SEEK_SET
enum
:
SEEK_CUR
enum
:
SEEK_END
enum
:
F_LOCK
enum
:
F_TEST
enum
:
F_TLOCK
enum
:
F_ULOCK
# pathconf()
# _PC_*
# sysconf()
# _SC_*
enum
:
STDIN_FILENO
#0
enum
:
STDOUT_FILENO
#1
enum
:
STDERR_FILENO
#2
#:ctypedef unsigned size_t
#:ctypedef signed ssize_t
ctypedef
int
uid_t
ctypedef
int
gid_t
ctypedef
signed
off_t
ctypedef
signed
pid_t
ctypedef
unsigned
useconds_t
ctypedef
signed
intptr_t
int
access
(
char
*
,
int
)
unsigned
alarm
(
unsigned
)
int
chdir
(
char
*
)
int
chown
(
char
*
,
uid_t
,
gid_t
)
int
close
(
int
)
size_t
confstr
(
int
,
char
*
,
size_t
)
char
*
crypt
(
char
*
,
char
*
)
char
*
ctermid
(
char
*
)
int
dup
(
int
)
int
dup2
(
int
,
int
)
void
encrypt
(
char
[
64
],
int
)
int
execl
(
char
*
,
char
*
,
...)
int
execle
(
char
*
,
char
*
,
...)
int
execlp
(
char
*
,
char
*
,
...)
int
execv
(
char
*
,
char
*
[])
int
execve
(
char
*
,
char
*
[],
char
*
[])
int
execvp
(
char
*
,
char
*
[])
void
_exit
(
int
)
int
fchown
(
int
,
uid_t
,
gid_t
)
int
fchdir
(
int
)
int
fdatasync
(
int
)
pid_t
fork
()
long
fpathconf
(
int
,
int
)
int
fsync
(
int
)
int
ftruncate
(
int
,
off_t
)
char
*
getcwd
(
char
*
,
size_t
)
gid_t
getegid
()
uid_t
geteuid
()
gid_t
getgid
()
int
getgroups
(
int
,
gid_t
[])
long
gethostid
()
int
gethostname
(
char
*
,
size_t
)
char
*
getlogin
()
int
getlogin_r
(
char
*
,
size_t
)
int
getopt
(
int
,
char
*
[],
char
*
)
pid_t
getpgid
(
pid_t
)
pid_t
getpgrp
()
pid_t
getpid
()
pid_t
getppid
()
pid_t
getsid
(
pid_t
)
uid_t
getuid
()
char
*
getwd
(
char
*
)
int
isatty
(
int
)
int
lchown
(
char
*
,
uid_t
,
gid_t
)
int
link
(
char
*
,
char
*
)
int
lockf
(
int
,
int
,
off_t
)
off_t
lseek
(
int
,
off_t
,
int
)
int
nice
(
int
)
long
pathconf
(
char
*
,
int
)
int
pause
()
int
pipe
(
int
[
2
])
ssize_t
pread
(
int
,
void
*
,
size_t
,
off_t
)
ssize_t
pwrite
(
int
,
void
*
,
size_t
,
off_t
)
ssize_t
read
(
int
,
void
*
,
size_t
)
ssize_t
readlink
(
char
*
,
char
*
,
size_t
)
int
rmdir
(
char
*
)
int
setegid
(
gid_t
)
int
seteuid
(
uid_t
)
int
setgid
(
gid_t
)
int
setpgid
(
pid_t
,
pid_t
)
pid_t
setpgrp
()
int
setregid
(
gid_t
,
gid_t
)
int
setreuid
(
uid_t
,
uid_t
)
pid_t
setsid
()
int
setuid
(
uid_t
)
unsigned
sleep
(
unsigned
)
void
swab
(
void
*
,
void
*
,
ssize_t
)
int
symlink
(
char
*
,
char
*
)
void
sync
()
long
sysconf
(
int
)
pid_t
tcgetpgrp
(
int
)
int
tcsetpgrp
(
int
,
pid_t
)
int
truncate
(
char
*
,
off_t
)
char
*
ttyname
(
int
)
int
ttyname_r
(
int
,
char
*
,
size_t
)
useconds_t
ualarm
(
useconds_t
,
useconds_t
)
int
unlink
(
char
*
)
int
usleep
(
useconds_t
)
pid_t
vfork
()
ssize_t
write
(
int
,
void
*
,
size_t
)
char
*
optarg
int
optind
int
opterr
int
optopt
runtests.py
View file @
9cb90055
...
...
@@ -35,7 +35,8 @@ TEST_RUN_DIRS = ['run', 'wrappers', 'pyregr']
# which should be excluded if the module is not present.
EXT_DEP_MODULES
=
{
'numpy'
:
re
.
compile
(
'.*
\
.
n
umpy_.*'
).
match
,
'pstats'
:
re
.
compile
(
'.*
\
.ps
t
ats_.*'
).
match
'pstats'
:
re
.
compile
(
'.*
\
.ps
t
ats_.*'
).
match
,
'posix'
:
re
.
compile
(
'.*
\
.posix_.*
'
).match,
}
def get_numpy_include_dirs():
...
...
tests/compile/posix_pxds.pyx
0 → 100644
View file @
9cb90055
cimport
posix
cimport
posix.unistd
from
posix
cimport
unistd
from
posix.unistd
cimport
*
cimport
posix.fcntl
from
posix
cimport
fcntl
from
posix.fcntl
cimport
*
tests/run/posix_test.pyx
0 → 100644
View file @
9cb90055
from
libc.stdio
cimport
*
from
posix.unistd
cimport
*
from
posix.fcntl
cimport
*
cdef
int
noisy_function
()
except
-
1
:
cdef
int
ret
=
0
ret
=
printf
(
b"0123456789
\
n
"
,
0
)
assert
ret
==
11
ret
=
fflush
(
stdout
)
assert
ret
==
0
ret
=
fprintf
(
stdout
,
b"0123456789
\
n
"
,
0
)
assert
ret
==
11
ret
=
fflush
(
stdout
)
assert
ret
==
0
ret
=
write
(
STDOUT_FILENO
,
b"0123456789
\
n
"
,
11
)
assert
ret
==
11
return
0
def
test_silent_stdout
():
"""
>>> test_silent_stdout()
"""
cdef
int
ret
cdef
int
stdout_save
,
dev_null
stdout_save
=
dup
(
STDOUT_FILENO
)
assert
stdout_save
!=
-
1
dev_null
=
open
(
b"/dev/null"
,
O_WRONLY
,
0
)
assert
dev_null
!=
-
1
ret
=
dup2
(
dev_null
,
STDOUT_FILENO
)
assert
ret
==
STDOUT_FILENO
ret
=
close
(
dev_null
)
assert
ret
==
0
try
:
noisy_function
()
finally
:
ret
=
dup2
(
stdout_save
,
STDOUT_FILENO
)
assert
ret
==
STDOUT_FILENO
ret
=
close
(
stdout_save
)
assert
ret
==
0
cdef
class
silent_fd
:
cdef
int
fd_save
,
fd
def
__cinit__
(
self
,
int
fd
=-
1
):
self
.
fd_save
=
-
1
self
.
fd
=
STDOUT_FILENO
if
fd
!=
-
1
:
self
.
fd
=
fd
def
__enter__
(
self
):
cdef
int
ret
=
0
,
dev_null
=
-
1
assert
self
.
fd_save
==
-
1
dev_null
=
open
(
b"/dev/null"
,
O_WRONLY
,
0
)
assert
dev_null
!=
-
1
try
:
self
.
fd_save
=
dup
(
self
.
fd
)
assert
self
.
fd_save
!=
-
1
try
:
ret
=
dup2
(
dev_null
,
self
.
fd
)
assert
ret
!=
-
1
except
:
ret
=
close
(
self
.
fd_save
)
self
.
fd_save
=
-
1
finally
:
ret
=
close
(
dev_null
)
def
__exit__
(
self
,
t
,
v
,
tb
):
cdef
int
ret
=
0
if
self
.
fd_save
!=
-
1
:
ret
=
dup2
(
self
.
fd_save
,
self
.
fd
)
assert
ret
==
self
.
fd
ret
=
close
(
self
.
fd_save
)
assert
ret
==
0
self
.
fd_save
=
-
1
return
None
def
test_silent_stdout_ctxmanager
():
"""
>> test_silent_stdout_ctxmanager()
"""
with
silent_fd
():
noisy_function
()
try
:
with
silent_fd
():
noisy_function
()
raise
RuntimeError
except
RuntimeError
:
pass
with
silent_fd
(
STDOUT_FILENO
):
noisy_function
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment