admin管理员组文章数量:1400294
I am creating a JNA (5.16) interface to V4L2 running on a Raspberry Pi 5 (Debian aarch64). Most of the structs map well, but v4l2_format
is undersized at 204 compared to C sizeof 208. The offset of the union fmt
is 4 in Java, 8 in C. The alignment is default. Using OpenJDK 64-bit 23.0.1.
Any ideas to fix the packing?
struct v4l2_format {
__u32 type;
union {
struct v4l2_pix_format pix;
struct v4l2_pix_format_mplane pix_mp;
struct v4l2_window win;
struct v4l2_vbi_format vbi;
struct v4l2_sliced_vbi_format sliced;
struct v4l2_sdr_format sdr;
struct v4l2_meta_format meta;
__u8 raw_data[200];
} fmt;
};
sizeof(struct v4l2_format) = 208 // 204 in Java
sizeof(struct v4l2_format.fmt) = 200 // 200 in Java
offsetof(struct v4l2_format,fmt) = 8 // 4 in Java
import com.sun.jna.Structure;
import com.sun.jna.Structure.FieldOrder;
import com.sun.jna.Union;
public class V4l2 {
@FieldOrder({ "raw_data" })
public static class v4l2_format_fmt extends Union {
// simplified
public byte[] raw_data = new byte[200];
}
@FieldOrder({ "type", "fmt" })
public static class v4l2_format extends Structure {
public int type;
public v4l2_format_fmt fmt;
}
public static void main(String[] args) {
System.out.println("sizeof(v4l2_format) = " + new v4l2_format().size()); // 204
System.out.println("sizeof(v4l2_format_fmt) = " + new v4l2_format_fmt().size()); // 200
}
}
本文标签: Java JNA Unexpected struct packing size with nested unionStack Overflow
版权声明:本文标题:Java JNA: Unexpected struct packing size with nested union - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744257433a2597549.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论