From 140b7b5020f3b85e43fb0203ca041c176d9e730b Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Mon, 18 Jul 2011 19:06:59 +0200 Subject: custom impl for clGetExtensionFuncitonAddress binding to remove a few gluegen workarounds. should be also a bit more gc friendly. --- resources/cl-impl.cfg | 8 +++----- resources/clImplCustomCode.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) (limited to 'resources') diff --git a/resources/cl-impl.cfg b/resources/cl-impl.cfg index 1f9240a2..977f430e 100644 --- a/resources/cl-impl.cfg +++ b/resources/cl-impl.cfg @@ -45,11 +45,6 @@ ProcAddressNameExpr $UpperCase(arg) #...or force all ForceProcAddressGen __ALL__ -Unignore clGetExtensionFunctionAddress -RenameJavaMethod clGetExtensionFunctionAddress clGetExtensionFunctionAddressImpl -AccessControl clGetExtensionFunctionAddressImpl PROTECTED -ArgumentIsString clGetExtensionFunctionAddressImpl 0 - #append to generated c files CustomCCode #include CustomCCode #include @@ -79,6 +74,9 @@ ForceProcAddressGen clSetEventCallback Ignore clSetMemObjectDestructorCallback ForceProcAddressGen clSetMemObjectDestructorCallback +Ignore clGetExtensionFunctionAddress +ForceProcAddressGen clGetExtensionFunctionAddress + #take buffer capacity from input param 5 ReturnValueCapacity clEnqueueMapBuffer {5} diff --git a/resources/clImplCustomCode.c b/resources/clImplCustomCode.c index fba3cb3d..d1442f66 100644 --- a/resources/clImplCustomCode.c +++ b/resources/clImplCustomCode.c @@ -409,3 +409,36 @@ Java_com_jogamp_opencl_llb_impl_CLImpl_clSetMemObjectDestructorCallback0(JNIEnv return _res; } + +/* Java->C glue code: + * Java package: com.jogamp.opencl.llb.impl.CLImpl + * Java method: java.nio.ByteBuffer dispatch_clGetExtensionFunctionAddressImpl(java.lang.String func_name) + * C function: void * clGetExtensionFunctionAddress(const char * func_name); + */ +JNIEXPORT jlong JNICALL +Java_com_jogamp_opencl_llb_impl_CLImpl_dispatch_1clGetExtensionFunctionAddress1__Ljava_lang_String_2J(JNIEnv *env, jobject _unused, + jstring func_name, jlong procAddress) { + + typedef void * (*_local_ARG)(const char * func_name); + _local_ARG ptr_clGetExtensionFunctionAddress; + const char* _strchars_func_name = NULL; + void * _res; + + if (NULL != func_name) { + _strchars_func_name = (*env)->GetStringUTFChars(env, func_name, (jboolean*) NULL); + if (NULL == _strchars_func_name) { + (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/OutOfMemoryError"), "Failed to get UTF-8 chars for argument \"func_name\""); + return 0; + } + } + + ptr_clGetExtensionFunctionAddress = (_local_ARG) (intptr_t) procAddress; + _res = (* ptr_clGetExtensionFunctionAddress) ((char *) _strchars_func_name); + + if (NULL != func_name) { + (*env)->ReleaseStringUTFChars(env, func_name, _strchars_func_name); + } + if (NULL == _res) return 0; + + return (jlong)_res; +} -- cgit v1.2.3