Author: mturk Date: Fri Apr 17 08:01:37 2009 New Revision: 765892 URL: http://svn.apache.org/viewvc?rev=765892&view=rev Log: Code update
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h?rev=765892&r1=765891&r2=765892&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_pointer.h Fri Apr 17 08:01:37 2009 @@ -40,13 +40,29 @@ /** * Create new Pointer class instance - * param env Current JNI environment - * param p Native pointer to wrap into Pointer class - * param cb callback function to use on Pointer.finalize() + * @param env Current JNI environment + * @param p Native pointer to wrap into Pointer class + * @param cb callback function to use on Pointer.finalize() */ -ACR_DECLARE(jobject) ACR_CreatePointer(JNIEnv *env, void *p, +ACR_DECLARE(jobject) ACR_PointerCreate(JNIEnv *env, void *p, acr_pointer_callback_fn_t *cb); +/** + * Call pointer cleanup. + * @param env Current JNI environment + * @param ptr Java Pointer object to clean. The function will + * clear the callback and pointer inside Java object. + * @return ACR_INCOMPLETE if already cleared. + */ +ACR_DECLARE(int) ACR_PointerCleanup(JNIEnv *env, jobject ptr); + +/** + * Get the native pointer from the Pointer object. + * @param env Current JNI environment + * @param ptr Java Pointer object use. + * @return Underlying wrapped pointer. + */ +ACR_DECLARE(void *) ACR_PointerGet(JNIEnv *env, jobject ptr); #ifdef __cplusplus } Modified: commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c?rev=765892&r1=765891&r2=765892&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Fri Apr 17 08:01:37 2009 @@ -118,7 +118,6 @@ if (h) { SET_IFIELD_I(0000, _O, 0); } - #endif cleanup = (acr_pointer_callback_fn_t *)((acr_ptr_t)c); if (cleanup) { @@ -130,7 +129,7 @@ } } -ACR_DECLARE(jobject) ACR_CreatePointer(JNIEnv *_E, void *p, +ACR_DECLARE(jobject) ACR_PointerCreate(JNIEnv *_E, void *p, acr_pointer_callback_fn_t *cb) { if (_clazzn.i && _m0000n.i) @@ -139,3 +138,60 @@ else return NULL; } + +ACR_DECLARE(int) ACR_PointerCleanup(ACR_JNISTDARGS) +{ + if (_clazzn.i && _m0000n.i) { + acr_pointer_callback_fn_t *cleanup; +#if CC_SIZEOF_VOIDP == 8 + jlong h = GET_IFIELD_J(0000, _O); + jlong c = GET_IFIELD_J(0001, _O); + + if (h) { + SET_IFIELD_J(0000, _O, 0); + } + if (c) { + SET_IFIELD_J(0001, _O, 0); + } +#else + jint h = GET_IFIELD_I(0000, _O); + jint c = GET_IFIELD_I(0001, _O); + + if (h) { + SET_IFIELD_I(0000, _O, 0); + } + if (c) { + SET_IFIELD_I(0001, _O, 0); + } +#endif + cleanup = (acr_pointer_callback_fn_t *)((acr_ptr_t)c); + if (cleanup) { + int rc = (*cleanup)((void *)((acr_ptr_t)h)); + if (rc) { + /* Throw RuntimeException with errno message */ + ACR_ThrowException(_E, THROW_FMARK, ACR_EX_ERUNTIME, rc); + } + return rc; + } + else { + /* Already cleared */ + return ACR_INCOMPLETE; + } + } + else + return ACR_ESYMNOTFOUND; +} + +ACR_DECLARE(void *) ACR_PointerGet(ACR_JNISTDARGS) +{ + if (_clazzn.i && _m0000n.i) { +#if CC_SIZEOF_VOIDP == 8 + jlong h = GET_IFIELD_J(0000, _O); +#else + jint h = GET_IFIELD_I(0000, _O); +#endif + return (void *)((acr_ptr_t)h); + } + else + return NULL; +} Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=765892&r1=765891&r2=765892&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Fri Apr 17 08:01:37 2009 @@ -220,5 +220,5 @@ ACR_JNI_EXPORT_DECLARE(jobject, TestPrivate, test017)(ACR_JNISTDARGS, jint d) { - return ACR_CreatePointer(_E, (void *)d, callback); + return ACR_PointerCreate(_E, (void *)d, callback); }