from cffi import FFI
ffi = FFI()
ffi.set_source("_sigwaitinfo","""
#include <signal.h>
""")
print("new")
ffi.cdef("""
// the typedef are not guess by in struct by cffi
typedef int pid_t;
typedef unsigned int uid_t;
typedef struct {
int si_signo; /* Signal number */
pid_t si_pid; /* Sending process ID */
uid_t si_uid; /* Real user ID of sending process */
...;
} siginfo_t ;
typedef struct {
...; } sigset_t;
#define SIGUSR1 ...
#define SIG_BLOCK ...
int sigaddset(sigset_t *set, int signum);
int sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
int sigwaitinfo(const sigset_t *set, siginfo_t *info);
""")
ffi.compile()
我知道的唯一方法是从python调用c标准库。在
python stdlib中使用ctypes的一种方法,但它相当复杂。在
所以我给出了cffi解
这是一个两步走的过程
首先通过运行这个脚本编译一个模块。我把这个模块命名为
然后通过一个与原始c代码一样简单的脚本来使用它(与python代码相比,测试返回代码是一个额外的负担)。这是让读者练习一下)
^{pr2}$相关问题 更多 >
编程相关推荐