gir icon indicating copy to clipboard operation
gir copied to clipboard

#define big constants overflow i32

Open Ekleog opened this issue 4 years ago • 7 comments

When generating bindings for Aravis, there are things like:

#define ARV_PIXEL_FORMAT_CUSTOM_BAYER_BG_12_PACKED  	0x810c0004

This codegens into GIR:

<constant name="PIXEL_FORMAT_CUSTOM_BAYER_BG_12_PACKED"
          value="2165047300"
          c:type="ARV_PIXEL_FORMAT_CUSTOM_BAYER_BG_12_PACKED">
  <type name="gint" c:type="gint"/>
</constant>

And then into Rust:

pub const ARV_PIXEL_FORMAT_CUSTOM_BAYER_BG_12_PACKED: c_int = 2165047300;

However this value is too big, and overflows i32. Either #[allow(overflowing_literals)] or upping the type would be fixes IMO

Ekleog avatar Oct 16 '19 23:10 Ekleog

Seems you need do this manually:

  1. add it to manual array in gir.toml
  2. add manual.rs with right definition near lib.rs, then on next regen it will be included See https://github.com/gtk-rs/sys/blob/master/gtk-sys/src/manual.rs as example

Alternative is changing constant in .gir file

EPashkin avatar Oct 17 '19 04:10 EPashkin

This is a bug in the C library. It should make sure that a correct type is used for the integer literal, not just a gint (see XML). Something like the following should do the job:

#define ARV_PIXEL_FORMAT_CUSTOM_BAYER_BG_12_PACKED  	0x810c0004U

sdroege avatar Oct 17 '19 07:10 sdroege

Thank you for your answers! Just opened https://github.com/AravisProject/aravis/pull/304, let's see how that moves :)

Ekleog avatar Oct 20 '19 17:10 Ekleog

@sdroege Looks like it didn't change anything https://github.com/AravisProject/aravis/pull/304 ; is that normal? (I have no idea how gobject-introspection works :/)

Ekleog avatar Oct 22 '19 22:10 Ekleog

I don't know, it works in GStreamer with the big constants

sdroege avatar Oct 23 '19 06:10 sdroege

See https://github.com/AravisProject/aravis/pull/304#issuecomment-545303648

sdroege avatar Oct 23 '19 07:10 sdroege

I don't think this is a gir issue, gir does the right thing if the introspection data is correct.

bilelmoussaoui avatar May 22 '22 10:05 bilelmoussaoui