我有一堆 C 宏,我需要在 python 中模拟它们的操作。我看到了一些指向 pygccxml 或 ctypeslib 等的指针。这些是要走的路吗?或者有更好的东西吗?
如果 C 宏发生变化,我希望自动生成 python 实现,而不必进行手动修改。因此问题。
my_c_header.h:
#ifdef OS
#define NUM_FLAGS (uint16_t)(3)
#define NUM_BITS (uint16_t)(8)
#else
#define NUM_FLAGS (uint16_t)(6)
#define NUM_BITS (uint16_t)(16)
#endif
#define MAKE_SUB_FLAGS (uint16_t)((1<<NUMFLAGS) -1)
#define MAKE_TOTAL_FLAGS(x) (uint16_t)((x & MAKE_SUB_FLAGS) >> NUM_BITS)
/* #defines type 2 */
#ifdef OS
#DO_SOMETHING(X) os_specifc_process(x)
#else
#DO_SOMETHING(x)
#endif
/* #defines type 3 */
enum
{
CASE0,
CASE1,
CASE2
}
#define MY_CASE_0 ((uint16_t)CASE0)
#define MY_CASE_1 ((uint16_t)CASE1)
#define MY_CASE_2 ((uint16_t)CASE2)
/*End of file <my_c_header.h> */
请您参考如下方法:
