bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 13 forks source link

Compilation of BCC with legacy - math.c issues #658

Open GWRon opened 2 months ago

GWRon commented 2 months ago

When compiling BCC with legacy BlitzMax then "math.c" contains some helpers for ctranslation.

blitz_string.c and .h (in blitz.mod) of "NG" and "vanilla" (or vanilla + "maxmods") contain different definitions for "bbStringToLong": image

One fix (without tampering brl.mod of the legacy installation) would be to adjust math.c (but this then again makes it incompatible to ones with a newer blitz_string - like NG):

math.c

BBString * bmx_bitwise_not_longint(BBString * value, int size) {
    if (size == 4) {
        int v = bbStringToInt(value);
        return bbStringFromInt(~v);
    } else { // 8
        //BBInt64 v = bbStringToLong(value);                    //NGs version
        BBInt64 v;
        bbStringToLong(value, &v);
        return bbStringFromLong(~v);
    }
}

BBString * bmx_binarymathexpr_longint(enum binaryOps op, BBString * slhs, BBString * srhs, int size) {
    if (size == 4) {
...
            case OP_OR:
                res = lhs | rhs;
                break;
        }
        return bbStringFromInt(res);
    } else { // 8
        //BBInt64 lhs = bbStringToLong(slhs);                 //NGs version
        //BBInt64 rhs = bbStringToLong(srhs);                 //NGs version
        BBInt64 lhs;
        BBInt64 rhs;

Initially (when this feature was introduced - I think at least) https://github.com/bmx-ng/bcc/commit/98a510da16cc00d295003fc971daa932201915e8 there was a conditional to include math.c only for Non-NG

but then, with some other primitives added, this was changed to get included always: https://github.com/bmx-ng/bcc/commit/b1013fda29bcc9c6b42b94645ff765eecc9e3d5c

a simple fix is to have two math.c (math_ng.c and math_legacy.c) and use them accordingly but this is surely still kinda error prone. the alternative is to update "maxmods" for the new bbstringtolong definition but this makes it a requirement for bcc-compilation-with-legacy-blitzmax then.