rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

macros defining integer constants using expressions containing enum values don't work

Open heycam opened this issue 9 years ago • 6 comments

In Gecko (in gfxFontConstants.h) we have:

enum {
    eFeatureAlternates_historical,
    eFeatureAlternates_stylistic,
    eFeatureAlternates_styleset,
    eFeatureAlternates_character_variant,
    eFeatureAlternates_swash,
    eFeatureAlternates_ornaments,
    eFeatureAlternates_annotation,

    eFeatureAlternates_numFeatures
};

#define NS_FONT_VARIANT_ALTERNATES_HISTORICAL        (1 << eFeatureAlternates_historical)

rust-bindgen doesn't generate anything for NS_FONT_VARIANT_ALTERNATES_HISTORICAL.

heycam avatar Nov 15 '16 09:11 heycam

cc @emilio

heycam avatar Nov 15 '16 09:11 heycam

Ugh, this never worked though... I know how to fix it for this case, but it's not pretty, and it's definitely hard to make it work for the general case.

emilio avatar Nov 15 '16 11:11 emilio

If only clang gave us a way of evaluating an expression in a given context...

emilio avatar Nov 15 '16 11:11 emilio

Yeah, so I looked into patching libclang so it works, but I can't see a clear way to do this. Basically, clang needs to expand the macro so it knows in what context to evaluate it. You can convert that into a constant, and then I think I can do stuff with it.

emilio avatar Nov 15 '16 12:11 emilio

FWIW, if those are switched to constants, they'll work properly with #260, even though it's a complex expression.

emilio avatar Nov 16 '16 16:11 emilio

Just to point out other uses / problems, the same underlying problem happen for "function aliases" defines, such as some functions in monocypher.

I didn't open a new issue since you've already merged #1546, which is the same but with structs, into this one.

pheki avatar Oct 21 '21 19:10 pheki