PMunch / futhark

Automatic wrapping of C headers in Nim
MIT License
355 stars 19 forks source link

Fix incomplete structs #92

Closed daniel-j closed 3 months ago

daniel-j commented 4 months ago

ptr distinct object for example is invalid and can crash Nim compiler. It should be invalid codegen. Using incompleteStruct because empty structs have zero size in C. The actual struct implementation is usually in the .c file (private members in a way).

PMunch commented 4 months ago

Is this a new change? The existing system has worked great before. Although I agree that this incompleteStruct is probably cleaner anyways

daniel-j commented 4 months ago

This isn't a new change. This has caused me some headache trying to find out what is crashing the Nim compiler, turns out it was generic object types (distinct object shouldn't be used as concrete type). I don't have reproducible example, my code is multiple files and 500 lines long when the bug appeared. After compiling Nim compiler in debug mode I could get a stack trace which pointed me to the distinct object ending up unexpectedly.

PMunch commented 3 months ago

Not quite sure why GitHub didn't detect it, but I merged this manually after testing locally that it worked.

Ref.: https://github.com/PMunch/futhark/commit/6a89adf444acf6847dc487f44d9e98c4983aa926

daniel-j commented 3 months ago

Hmm, after further testing this seems like the wrong fix. What works is a plain object without incompleteStruct pragma.