author | Tero Marttila <terom@fixme.fi> |
Sun, 16 Aug 2009 23:32:00 +0300 | |
changeset 14 | c44754cc1ffe |
parent 13 | a1091632a8a7 |
child 19 | e6b670dbfe3b |
permissions | -rw-r--r-- |
7
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
""" |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
Libc stuff |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
""" |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
5 |
cdef extern from "stdint.h" : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
6 |
# yes, these are "wrong" |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
ctypedef unsigned char uint8_t |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
ctypedef unsigned short uint16_t |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
9 |
ctypedef unsigned int uint32_t |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
10 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
11 |
ctypedef signed char int8_t |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
12 |
ctypedef signed short int16_t |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
13 |
ctypedef signed int int32_t |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
15 |
cdef extern from "sys/types.h" : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
16 |
# potentially wrong... |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
17 |
ctypedef signed long ssize_t |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
18 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
19 |
# <linux/types.h> |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
20 |
cdef extern from "linux/types.h" : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
21 |
ctypedef uint8_t __u8 |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
22 |
ctypedef uint16_t __u16 |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
23 |
ctypedef uint32_t __u32 |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
24 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
25 |
ctypedef int8_t __s8 |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
26 |
ctypedef int16_t __s16 |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
27 |
ctypedef int32_t __s32 |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
28 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
29 |
cdef extern from "errno.h" : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
30 |
int errno |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
31 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
32 |
cdef extern from "string.h" : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
33 |
void* memcpy (void *dest, void *src, size_t n) |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
34 |
void* memset (void *s, int c, size_t n) |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
35 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
36 |
char* strerror (int errno) |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
37 |
|
12
314d47bdd4d9
full range of send/write operations
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
38 |
cdef extern from "unistd.h" : |
314d47bdd4d9
full range of send/write operations
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
39 |
ssize_t read (int fd, void *buf, size_t count) |
314d47bdd4d9
full range of send/write operations
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
40 |
ssize_t write (int fd, void *buf, size_t count) |
314d47bdd4d9
full range of send/write operations
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
41 |
|
13
a1091632a8a7
implement __cinit__, shutdown, close, __dealloc__ for socket, and also add a try-except to not leak client sock from accept()
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
42 |
int close (int fd) |
a1091632a8a7
implement __cinit__, shutdown, close, __dealloc__ for socket, and also add a try-except to not leak client sock from accept()
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
43 |
|
7
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
44 |
cdef extern from "alloca.h" : |
14
c44754cc1ffe
some recv magic, still no PyString_Resize, though
Tero Marttila <terom@fixme.fi>
parents:
13
diff
changeset
|
45 |
# XXX: this is unsafe because there is it may fail nastily for allocations that won't fit on the stack - SIGSEGV |
7
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
46 |
void* alloca (size_t size) |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
47 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
48 |
cdef extern from "sys/uio.h" : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
49 |
struct iovec : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
50 |
void *iov_base |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
51 |
size_t iov_len |
12
314d47bdd4d9
full range of send/write operations
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
52 |
|
314d47bdd4d9
full range of send/write operations
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
53 |
ssize_t readv (int fd, iovec *iov, int iovcnt) |
314d47bdd4d9
full range of send/write operations
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
54 |
ssize_t writev (int fd, iovec *iov, int iovcnt) |
7
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
55 |
|
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
56 |
## general errno-based errors |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
57 |
#cdef class Errno (py.OSError) : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
58 |
# """ |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
59 |
# Some libc function returned an error code: |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
60 |
# |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
61 |
# func - the name of the function called |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
62 |
# err - the system error code |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
63 |
# strerror - human-readable error code -> message |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
64 |
# """ |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
65 |
# |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
66 |
# cdef readonly char *func |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
67 |
# cdef readonly int err |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
68 |
# cdef readonly object strerror |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
69 |
# |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
70 |
#cdef class GAIError (py.OSError) : |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
71 |
# """ |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
72 |
# Some libc GAI function returnd an error code: |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
73 |
# |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
74 |
# func - the name of the function called |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
75 |
# err - the GAI_* error code |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
76 |
# strerror - human-readable error code -> message |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
77 |
# """ |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
78 |
# |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
79 |
# cdef readonly char *func |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
80 |
# cdef readonly int err |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
81 |
# cdef readonly object strerror |
74fde84264b1
broke Cython with this package magic
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
82 |
# |