comparison setup_osutil_cffi.py @ 29600:7a157639b8f2

osutil: add darwin-only version of os.listdir using cffi
author Maciej Fijalkowski <fijall@gmail.com>
date Mon, 11 Jul 2016 11:05:08 +0200
parents
children a043c6d372db
comparison
equal deleted inserted replaced
29599:e3dc96834126 29600:7a157639b8f2
1 from __future__ import absolute_import
2
3 import cffi
4
5 ffi = cffi.FFI()
6 ffi.set_source("_osutil_cffi", """
7 #include <sys/attr.h>
8 #include <sys/vnode.h>
9 #include <unistd.h>
10 #include <fcntl.h>
11 #include <time.h>
12
13 typedef struct val_attrs {
14 uint32_t length;
15 attribute_set_t returned;
16 attrreference_t name_info;
17 fsobj_type_t obj_type;
18 struct timespec mtime;
19 uint32_t accessmask;
20 off_t datalength;
21 } __attribute__((aligned(4), packed)) val_attrs_t;
22 """, include_dirs=['mercurial'])
23 ffi.cdef('''
24
25 typedef uint32_t attrgroup_t;
26
27 typedef struct attrlist {
28 uint16_t bitmapcount; /* number of attr. bit sets in list */
29 uint16_t reserved; /* (to maintain 4-byte alignment) */
30 attrgroup_t commonattr; /* common attribute group */
31 attrgroup_t volattr; /* volume attribute group */
32 attrgroup_t dirattr; /* directory attribute group */
33 attrgroup_t fileattr; /* file attribute group */
34 attrgroup_t forkattr; /* fork attribute group */
35 ...;
36 };
37
38 typedef struct attribute_set {
39 ...;
40 } attribute_set_t;
41
42 typedef struct attrreference {
43 int attr_dataoffset;
44 int attr_length;
45 ...;
46 } attrreference_t;
47
48 typedef struct val_attrs {
49 uint32_t length;
50 attribute_set_t returned;
51 attrreference_t name_info;
52 uint32_t obj_type;
53 struct timespec mtime;
54 uint32_t accessmask;
55 int datalength;
56 ...;
57 } val_attrs_t;
58
59 /* the exact layout of the above struct will be figured out during build time */
60
61 typedef int ... time_t;
62 typedef int ... off_t;
63
64 typedef struct timespec {
65 time_t tv_sec;
66 ...;
67 };
68
69 int getattrlist(const char* path, struct attrlist * attrList, void * attrBuf,
70 size_t attrBufSize, unsigned int options);
71
72 int getattrlistbulk(int dirfd, struct attrlist * attrList, void * attrBuf,
73 size_t attrBufSize, uint64_t options);
74
75 #define ATTR_BIT_MAP_COUNT ...
76 #define ATTR_CMN_NAME ...
77 #define ATTR_CMN_OBJTYPE ...
78 #define ATTR_CMN_MODTIME ...
79 #define ATTR_CMN_ACCESSMASK ...
80 #define ATTR_CMN_ERROR ...
81 #define ATTR_CMN_RETURNED_ATTRS ...
82 #define ATTR_FILE_DATALENGTH ...
83
84 #define VREG ...
85 #define VDIR ...
86 #define VLNK ...
87 #define VBLK ...
88 #define VCHR ...
89 #define VFIFO ...
90 #define VSOCK ...
91
92 #define S_IFMT ...
93
94 int open(const char *path, int oflag, int perm);
95 int close(int);
96
97 #define O_RDONLY ...
98 ''')
99
100 if __name__ == '__main__':
101 ffi.compile()