cjdrake / pyeda

Python EDA
BSD 2-Clause "Simplified" License
301 stars 55 forks source link

Building on Windows #152

Closed alexwebr closed 2 years ago

alexwebr commented 5 years ago

Hello, It seems that PyEDA doesn't easily build on Windows with MSVC, because it uses a C99 feature not available in MSVC. The error is the following:

extension\boolexpr\boolexpr.c(440): error C2057: expected constant expression
extension\boolexpr\boolexpr.c(440): error C2466: cannot allocate an array of constant size 0
extension\boolexpr\boolexpr.c(440): error C2133: 'xs': unknown size
extension\boolexpr\boolexpr.c(449): error C2057: expected constant expression
extension\boolexpr\boolexpr.c(449): error C2466: cannot allocate an array of constant size 0
extension\boolexpr\boolexpr.c(449): error C2133: 'xs': unknown size
[... continues ...]

It appears the problem is with the use of variable-length arrays in the BN_OrN, BN_AndN, and related functions:

BX_OrN(size_t n, ...)
{
    struct BoolExpr *xs[n];
    READ_ARGS(n, xs);
    return BX_Or(n, xs);
}

This StackOverflow questions seems to indicate this feature will never come to MSVC: https://stackoverflow.com/q/5246900

If I replace the 8ish uses of VLAs in boolexpr.c with calls to alloca(), it appears to allow PyEDA to build easily on Windows. I have the changes in a branch and can open a pull request if you like? What do you think about this change?

Here's the diff: https://github.com/alexwebr/pyeda/commit/a07acb0f09ac020b906976df61179ea049a6331a

Happy to discuss, and thanks for the great software!

alexwebr commented 5 years ago

I opened the PR here: https://github.com/cjdrake/pyeda/pull/153

earphonebreaker commented 2 years ago

On our server, the gcc doesn't recognize alloca(), so I tried to use malloc instead:

struct BoolExpr *
BX_OrN(size_t n, ...)
{
    struct BoolExpr **xs = malloc(sizeof(struct BoolExpr) * n);
    READ_ARGS(n, xs);
    struct BoolExpr* y;
    y = BX_Or(n, xs);
    free(*xs);
    return y;
}

It works anyway. Maybe helpful to someone who has the same problem.

alexwebr commented 2 years ago

@earphonebreaker Hi, do you happen to know what version of Linux and GCC this is? If it's something I can get my hands on, I might do a followup to PR #153 to handle this. Thanks!