python-autopxd2 icon indicating copy to clipboard operation
python-autopxd2 copied to clipboard

autopxd2 generates invalid code when array subscript is a calculated define

Open markmelvin opened this issue 5 years ago • 2 comments

I have the following C code:

#define NUMBER_A 64
#define NUMBER_B 4
#define SUMMATION (NUMBER_A + NUMBER_B)

int some_function(uint8_t valuesOut[2][SUMMATION], uint8_t valuesIn[NUMBER_B]);

This code compiles fine, but autopxd2 generated invalid Cython. What gets generated in my .pxd file is:

int some_function(uint8_t valuesOut[2][], uint8_t valuesIn[4]);

...which fails to compile with the following error:

Array element type 'uint8_t []' is incomplete

I turned on preproccessor debugging and it generates an appropriate signature of the following:

int some_function(uint8_t valuesOut[2][(64 + 4)], uint8_t valuesIn[4]);

But somewhere along the way - the generated Cython is incorrect.

Any ideas?

markmelvin avatar Oct 15 '20 02:10 markmelvin

I wonder if you used the preprocessing built into pycparser (as per this example), if things would fare better?

markmelvin avatar Oct 15 '20 03:10 markmelvin

@markmelvin sorry, just seeing this now. This project isn't under active development but I'd be happy to review and release any pull requests submitted.

elijahr avatar Nov 26 '20 22:11 elijahr