bytedeco/javacpp-presets

DNG Adobe Presets

masterav10 opened this issue · 3 comments

Working on some presets for the Adobe DNG SDK, and I'm down to the final error.

I'm running into a compilation problem with setter func in the jni file from this definition (only showing relevant line):

// dng_idf.h
class dng_ifd
	{
	
	public:
	
		std::shared_ptr<const dng_memory_block> fSemanticXMP;

		...		
	};

Javacpp is generating the following output:

// dng_idf.java	
public native @Const @SharedPtr dng_memory_block fSemanticXMP(); 
public native dng_ifd fSemanticXMP(dng_memory_block setter);
// jnidng.cpp setter function definition
JNIEXPORT jobject JNICALL Java_org_bytedeco_dng_dng_1ifd_fSemanticXMP__(JNIEnv* env, jobject obj) {
dng_ifd* ptr = (dng_ifd*)jlong_to_ptr(env->GetLongField(obj, JavaCPP_addressFID));
if (ptr == NULL) {
	env->ThrowNew(JavaCPP_getClass(env, 7), "This pointer address is NULL.");
	return 0;
}
jlong position = env->GetLongField(obj, JavaCPP_positionFID);
ptr += position;
jobject rarg = NULL;
const dng_memory_block* rptr;
SharedPtrAdapter< const dng_memory_block > radapter(ptr->fSemanticXMP);
rptr = radapter;
jlong rcapacity = (jlong)radapter.size;
void* rowner = radapter.owner;
void (*deallocator)(void*) = rowner != NULL ? &SharedPtrAdapter< const dng_memory_block >::deallocate : 0;
if (rptr != NULL) {
	rarg = JavaCPP_createPointer(env, 30);
	if (rarg != NULL) {
		JavaCPP_initPointer(env, rarg, rptr, rcapacity, rowner, deallocator);
	}
}
return rarg;
}

Here is the error I receive:

jnidng.cpp(27414): error C2664: 'SharedPtrAdapter<dng_memory_block>::SharedPtrAdapter(const std::shared_ptr<dng_memory_block> &)': cannot convert argument 1 from 'std::shared_ptr<const dng_memory_block>' to 'const std::shared_ptr<dng_memory_block> &'
jnidng.cpp(27414): note: Reason: cannot convert from 'std::shared_ptr<const dng_memory_block>' to 'const std::shared_ptr<dng_memory_block>'
jnidng.cpp(27414): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

This line seems to be the problem child SharedPtrAdapter< const dng_memory_block > radapter(ptr->fSemanticXMP);

It makes sense, since the generic types don't match. Is there an easy way to overcome this using InfoMap (such as javaText(...) ) or is this just one of them issues where I gotta do something jank to overcome? I poked around in some of the other bindings but couldn't find an analogous case.

FYI I'm using 1.5.9 right now because I can't upgrade my CUDA yet. So if this is a bug that has already been fixed by the generator then I'll wait till we upgrade.

Sorry for the late reply! It's something we can work around with a cast like this:

.put(new Info("std::shared_ptr<const dng_memory_block>").annotations("@SharedPtr")
    .valueTypes("@Cast({\"const dng_memory_block*\", \"std::shared_ptr<const dng_memory_block>\"}) dng_memory_block")

Worked like a charm partner. Probably worth adding this behavior to https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes no?

Either way, this particular issue is fixed for me.