[foreign-jextract] Wrong MemoryLayout and VarHandle carrier for integer field

Filip Krakowski krakowski at hhu.de
Thu Aug 27 10:44:12 UTC 2020


Hi,

I would like to report a bug regarding jextract. The header file 
(https://github.com/linux-rdma/rdma-core/blob/master/libibverbs/verbs.h) 
I give to jextract contains the following struct.

    struct ibv_qp_init_attr {
             void                   *qp_context;
             struct ibv_cq          *send_cq;
             struct ibv_cq          *recv_cq;
             struct ibv_srq         *srq;
             struct ibv_qp_cap       cap;
             enum ibv_qp_type        qp_type;
             int                     sq_sig_all;
    };


The Code generated for the "sq_sig_all" field looks like this.

    private static final MemoryLayout sq_sig_all$LAYOUT_ =C_BOOL;
    private static final VarHandle sq_sig_all$VH_ =sq_sig_all$LAYOUT_.varHandle(byte.class);

    public static int sq_sig_all$get(MemorySegment seg) {
         return (int)verbs_h$constants$3.sq_sig_all$VH().get(seg);
    }

    public static void sq_sig_all$set(jdk.incubator.foreign.MemorySegment seg,int x) {
         verbs_h$constants$3.sq_sig_all$VH().set(seg, x);
    }

As you can see jextract chooses "C_BOOL" as the MemoryLayout for the 
"sq_sig_all" field and uses "byte" for the VarHandle's carrier. In 
contrast to this, getters and setters work with "int" which leads to an 
Exception during runtime.

    java.lang.invoke.WrongMethodTypeException: cannot convert
    MethodHandle(VarHandle,MemorySegment,byte)void to
    (VarHandle,MemorySegment,int)void




More information about the panama-dev mailing list