bytedeco/javacpp

PointerPointer's ambiguous constructor

Open

#410 opened on Jun 28, 2020

View on GitHub
 (5 comments) (0 reactions) (0 assignees)Java (620 forks)batch import
enhancementhelp wanted

Repository metrics

Stars
 (4,279 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Here is the code There are these two constructors in class PointerPointer:

    public PointerPointer(P ... array) { this(array.length); put(array); }

    public PointerPointer(Pointer p) { super(p); }

When you pass one pointer object to it, it will call the second constructor. If user didn't know the detail of constructor, it could bring difficult bugs to the program.

Here is the program I wrote, the second params is wrong because I want a pointer points to an array.

        LLVMValueRef c_neg1 = LLVMConstInt(LLVMInt32Type(), -1,1);
        PointerPointer<LLVMValueRef> params = new PointerPointer( new LLVMValueRef[] {c_neg1} );
        LLVMBuildCall(builder, fun_exit, params, 1, "");

        PointerPointer<LLVMValueRef> params = new PointerPointer<LLVMValueRef>( c_neg1 );   //wrong

I feel converting a pointer to a pointer pointer is somehow a re-interpret ? Maybe using a static function in PointerPointer and a pointer as parameter, instead of using constructor is a good choice?

Contributor guide