Commit de8821f9 authored by Lisandro Dalcin's avatar Lisandro Dalcin

Merge pull request #303 from markpeek/markpeek-includes

Add more libc and posix includes
parents 959def97 bf7169de
# http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/resource.h.html
from posix.time cimport timeval
from posix.types cimport id_t
cdef extern from "sys/resource.h" nogil:
enum: PRIO_PROCESS
enum: PRIO_PGRP
enum: PRIO_USER
enum: RLIM_INFINITY
enum: RLIM_SAVED_MAX
enum: RLIM_SAVED_CUR
enum: RUSAGE_SELF
enum: RUSAGE_CHILDREN
enum: RLIMIT_CORE
enum: RLIMIT_CPU
enum: RLIMIT_DATA
enum: RLIMIT_FSIZE
enum: RLIMIT_NOFILE
enum: RLIMIT_STACK
enum: RLIMIT_AS
ctypedef unsigned long rlim_t
cdef struct rlimit:
rlim_t rlim_cur
rlim_t rlim_max
cdef struct rusage:
timeval ru_utime
timeval ru_stime
long ru_maxrss
long ru_ixrss
long ru_idrss
long ru_isrss
long ru_minflt
long ru_majflt
long ru_nswap
long ru_inblock
long ru_oublock
long ru_msgsnd
long ru_msgrcv
long ru_nsignals
long ru_nvcsw
long ru_nivcsw
int getpriority(int, id_t)
int getrlimit(int, rlimit *)
int getrusage(int, rusage *)
int setpriority(int, id_t, int)
int setrlimit(int, const rlimit *)
# 7.14 Signal handling <signal.h>
from posix.types cimport pid_t, sigset_t, uid_t
cdef extern from "signal.h" nogil:
cdef union sigval:
int sival_int
void *sival_ptr
cdef struct sigevent:
int sigev_notify
int sigev_signo
sigval sigev_value
void *sigev_notify_function(sigval)
ctypedef struct siginfo_t:
int si_signo
int si_code
int si_errno
pid_t si_pid
uid_t si_uid
void *si_addr
int si_status
long si_band
sigval si_value
cdef struct sigaction_t "sigaction":
void *sa_handler(int)
sigset_t sa_mask
int sa_flags
void sa_sigaction(int, siginfo_t *, void *)
enum: SA_NOCLDSTOP
enum: SIG_BLOCK
enum: SIG_UNBLOCK
enum: SIG_SETMASK
enum: SA_ONSTACK
enum: SA_RESETHAND
enum: SA_RESTART
enum: SA_SIGINFO
enum: SA_NOCLDWAIT
enum: SA_NODEFER
enum: SS_ONSTACK
enum: SS_DISABLE
enum: MINSIGSTKSZ
enum: SIGSTKSZ
enum: SIGEV_NONE
enum: SIGEV_SIGNAL
enum: SIGEV_THREAD
enum: SIGEV_THREAD_ID
int kill (pid_t, int)
int killpg (pid_t, int)
int sigaction (int, const sigaction_t *, sigaction_t *)
int sigpending (sigset_t *)
int sigprocmask (int, const sigset_t *, sigset_t *)
int sigsuspend (const sigset_t *)
int sigaddset (sigset_t *, int)
int sigdelset (sigset_t *, int)
int sigemptyset (sigset_t *)
int sigfillset (sigset_t *)
int sigismember (const sigset_t *)
# http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/time.h.html
from posix.signal cimport sigevent
from posix.types cimport clock_t, clockid_t, suseconds_t, time_t, timer_t
cdef extern from "sys/time.h" nogil:
enum: CLOCKS_PER_SEC
enum: CLOCK_PROCESS_CPUTIME_ID
enum: CLOCK_THREAD_CPUTIME_ID
enum: CLOCK_REALTIME
enum: TIMER_ABSTIME
enum: CLOCK_MONOTONIC
# FreeBSD-specific clocks
enum: CLOCK_UPTIME
enum: CLOCK_UPTIME_PRECISE
enum: CLOCK_UPTIME_FAST
enum: CLOCK_REALTIME_PRECISE
enum: CLOCK_REALTIME_FAST
enum: CLOCK_MONOTONIC_PRECISE
enum: CLOCK_MONOTONIC_FAST
enum: CLOCK_SECOND
# Linux-specific clocks
enum: CLOCK_PROCESS_CPUTIME_ID
enum: CLOCK_THREAD_CPUTIME_ID
enum: CLOCK_MONOTONIC_RAW
enum: CLOCK_REALTIME_COARSE
enum: CLOCK_MONOTONIC_COARSE
enum: CLOCK_BOOTTIME
enum: CLOCK_REALTIME_ALARM
enum: CLOCK_BOOTTIME_ALARM
enum: ITIMER_REAL
enum: ITIMER_VIRTUAL
enum: ITIMER_PROF
cdef struct timeval:
time_t tv_sec
suseconds_t tv_usec
cdef struct itimerval:
timeval it_interval
timeval it_value
cdef struct timezone:
int tz_minuteswest
int dsttime
cdef struct timespec:
time_t tv_sec
long tv_nsec
cdef struct itimerspec:
timespec it_interval
timespec it_value
cdef struct tm:
int tm_sec
int tm_min
int tm_hour
int tm_mday
int tm_mon
int tm_year
int tm_wday
int tm_yday
int tm_isdst
char *tm_zone
long tm_gmtoff
char *asctime(const tm *)
char *asctime_r(const tm *, char *)
clock_t clock()
int clock_getcpuclockid(pid_t, clockid_t *)
int clock_getres(clockid_t, timespec *)
int clock_gettime(clockid_t, timespec *)
int clock_nanosleep(clockid_t, int, const timespec *, timespec *)
int clock_settime(clockid_t, const timespec *)
char *ctime(const time_t *)
char *ctime_r(const time_t *, char *)
double difftime(time_t, time_t)
tm *getdate(const char *)
int getitimer(int, itimerval *)
int gettimeofday(timeval *tp, timezone *tzp)
tm *gmtime(const time_t *)
tm *gmtime_r(const time_t *, tm *)
tm *localtime(const time_t *)
tm *localtime_r(const time_t *, tm *)
time_t mktime(tm *)
int nanosleep(const timespec *, timespec *)
int setitimer(int, const itimerval *, itimerval *)
size_t strftime(char *, size_t, const char *, const tm *)
char *strptime(const char *, const char *, tm *)
time_t time(time_t *)
int timer_create(clockid_t, sigevent *, timer_t *)
int timer_delete(timer_t)
int timer_gettime(timer_t, itimerspec *)
int timer_getoverrun(timer_t)
int timer_settime(timer_t, int, const itimerspec *, itimerspec *)
void tzset()
int daylight
long timezone
char *tzname[2]
cdef extern from "sys/types.h":
ctypedef long blkcnt_t
ctypedef long blksize_t
ctypedef long clock_t
ctypedef long clockid_t
ctypedef long dev_t
ctypedef long gid_t
ctypedef long id_t
ctypedef long ino_t
ctypedef long mode_t
ctypedef long nlink_t
ctypedef long off_t
ctypedef long pid_t
ctypedef long sigset_t
ctypedef long suseconds_t
ctypedef long time_t
ctypedef long timer_t
ctypedef long uid_t
......@@ -15,6 +15,10 @@ cimport posix.types
from posix cimport types
from posix.types cimport *
cimport posix.signal
from posix cimport signal
from posix.signal cimport *
cimport posix.stat
from posix cimport stat
from posix.stat cimport *
......@@ -22,3 +26,11 @@ from posix.stat cimport *
cimport posix.stdlib
from posix cimport stdlib
from posix.stdlib cimport *
cimport posix.time
from posix cimport time
from posix.time cimport *
cimport posix.resource
from posix cimport resource
from posix.resource cimport *
# tag: posix
from posix.unistd cimport *
from posix.resource cimport *
def test_getpriority():
"""
>>> test_getpriority()
"""
ret = getpriority(PRIO_PROCESS, getpid())
assert ret == 0
def test_getrlimit():
"""
>>> test_getrlimit()
"""
cdef rlimit rlim
ret = getrlimit(RLIMIT_CPU, &rlim)
assert ret == 0
assert rlim.rlim_cur != 0
def test_getrusage():
"""
>>> test_getrusage()
"""
cdef rusage r
ret = getrusage(RUSAGE_SELF, &r)
assert ret == 0
# tag: posix
from libc.stdlib cimport getenv
from posix.stdlib cimport setenv, unsetenv
from posix.time cimport *
def test_itimer(sec, usec):
"""
>>> test_itimer(10, 2)
(10, 2)
"""
cdef itimerval t, gtime
t.it_interval.tv_sec = sec
t.it_interval.tv_usec = usec
t.it_value.tv_sec = sec
t.it_value.tv_usec = usec
ret = setitimer(ITIMER_REAL, &t, NULL)
assert ret == 0
ret = getitimer(ITIMER_REAL, &gtime)
assert ret == 0
t.it_interval.tv_sec = 0
t.it_interval.tv_usec = 0
t.it_value.tv_sec = 0
t.it_value.tv_usec = 0
ret = setitimer(ITIMER_REAL, &t, NULL)
return gtime.it_interval.tv_sec, gtime.it_interval.tv_usec
def test_gettimeofday():
"""
>>> test_gettimeofday()
"""
cdef timeval t
ret = gettimeofday(&t, NULL)
assert ret == 0
def test_time():
"""
>>> test_time()
"""
cdef time_t t1, t2
t1 = time(NULL)
assert t1 != 0
t1 = time(&t2)
assert t1 == t2
def test_mktime():
"""
tests/run/posix_time.pyx
>>> test_mktime() # doctest:+ELLIPSIS
(986138177, ...'Sun Apr 1 15:16:17 2001\\n')
"""
cdef tm t, gmt
cdef time_t tt
cdef char *ct
cdef char *tz
tz = getenv("TZ")
setenv("TZ", "UTC", 1)
tzset()
t.tm_sec = 17
t.tm_min = 16
t.tm_hour = 15
t.tm_year = 101
t.tm_mon = 3
t.tm_mday = 1
t.tm_isdst = 0
tt = mktime(&t)
assert tt != -1
ct = ctime(&tt)
assert ct != NULL
if tz:
setenv("TZ", tz, 1)
else:
unsetenv("TZ")
tzset()
return tt, ct
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