How to wrap a C structure which is defined with __attribute__((packed,aligned(1)))?

断了今生、忘了曾经 提交于 2019-12-12 03:45:56

问题


How do I wrap a C structure which is defined with __attribute__((packed,aligned(1))) in SWIG?


回答1:


You need to do almost nothing to make this work, simply #define the attribute away:

%module test

#define __attribute__(x) 
struct foo {} __attribute__((packed,aligned(1)));

Will parse and work as intended.

The reason this works is that SWIG doesn't generate any code that cares about the layout or size of an object. Nor does it generate code that makes any assumptions about it either. Instead all accesses/malloc/new are handled via the compiler which compiles the generated code exactly as normal.

So as long as you make sure that the definition of your struct, as seen by the compiler that compiles the module is correct you won't have any problems.



来源:https://stackoverflow.com/questions/41994788/how-to-wrap-a-c-structure-which-is-defined-with-attribute-packed-aligned1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!