Search code examples
cswig

Swig using non constant declarations for size of typedeffed array


I'm trying to wrap a C project with swig for Python. I have a .h file I'm including in swig with %include. I'd like everything in the header file to be wrapped.

Is there anything I can do to handle the below error, without having to edit the source header file.

test.h

#define SEPARATOR "-"
#define SEPARATOR_SIZE ((int)sizeof(SEPARATOR))
typedef char SEPARATOR_ARRAY [SEPARATOR_SIZE];

test.i

%module test
%{
  #include "test.h"
%}
%include test.h

After running swig -python test.i I get test.h:3: Error: Syntax error in input(1).

Using swig version 4.0.2.


Solution

  • Found the answer:

    Swig only supported sizeof(<type>). Since this question there has been a commit to swig's github which handles the parsing of some further values in sizeof, such as "foo" 'f' and 300, but this still seems to cause compilation issues later on.

    https://github.com/swig/swig/commit/7ab24e7e865e0f1281f002fefdaba11b80416ea2