From: Choonghwan L. <ch...@hd...> - 2008-08-11 17:45:15
|
With SWIG, I'm generating Python wrapper for a C library containing complicated preprocessor macros. For example, #define MACRO1 (funccall1(), globalvar) #define MACRO2 (funccall2(), 2 /* literal */) I could see SWIG ignored those macros although globalvar was put inside cvar property. My goal is to access those macros in Python like the following: modulename.MACRO1 modulename.MACRO2 Assuming that globalvar is not modified after the initialization, I think one possible solution is to write some SWIG commands in the interface file. For example, %module modulename %{ %} %init %{ funccall1(); funccall2(); %} #undef MACRO1 %constant int MACRO1 = globalvar; #undef MACRO2 #define MACRO2 2 It worked (at least) for me, but I was wondering if there is any better solution. I don't think is a good solution in that I hardcoded a variable and a literal. Since calling funccall1() and funccall2() several times does not make any problem, I don't think any complicated logic is needed here; the generated Python wrapper can just call funccall1() or funccall2() and then retrieve the variable or the number whenever MACRO1 or MACRO2 is accessed. If this is not supported, I'm wondering if others think this is important or useful feature, and it is worth requesting this feature. Thanks! |