Browse Source

JNI-142: "Mem-mgmt: Defined behaviour of Message.close()"

* close() method is now idempotent
* Access to Message obj after close() results in IllegalStateException (Not SEGV anymore)
JNI-149 Release_2.1.12
heck 1 year ago
parent
commit
d9e782faff
2 changed files with 45 additions and 12 deletions
  1. +44
    -12
      src/codegen/gen_cpp_Message.ysl2
  2. +1
    -0
      src/codegen/gen_java_Message.ysl2

+ 44
- 12
src/codegen/gen_cpp_Message.ysl2 View File

@ -28,14 +28,17 @@ tstylesheet {
namespace JNIAdapter {
static ::«@name» *«@name»_ptr(JNIEnv *env, jobject me) {
jfieldID handle;
handle = getFieldID(env, "foundation/pEp/jniadapter/«$jname»", "handle", "J");
if(!handle) {
throw runtime_error("field not found: handle");
}
try {
handle = getFieldID(env, "foundation/pEp/jniadapter/«$jname»", "handle", "J");
} catch (std::exception& ex) {
assert(0);
return NULL;
long handle_val = static_cast<long>(env->GetLongField(me, handle));
if(!handle_val) {
throw runtime_error("invalid handle (0)");
}
return reinterpret_cast<::«@name» *>(env->GetLongField(me, handle));
return reinterpret_cast<::«@name» *>(handle_val);
}
};
@ -86,10 +89,19 @@ tstylesheet {
}
JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_«$jname»__1encodeMIME(JNIEnv *env,
jobject msg)
jobject obj)
{
pEpLog("called");
«@name» *_obj = «@name»_ptr(env, msg);
«@name»* _obj = nullptr;
try {
_obj = «@name»_ptr(env, obj);
} catch(...) {
jclass ex = env->FindClass("java/lang/IllegalStateException");
assert(ex);
env->ThrowNew(ex, nullptr);
return static_cast<jbyteArray>(NULL);
}
char *mime_text = nullptr;
PEP_STATUS status = ::mime_encode_«@name»(_obj, false, &mime_text, false);
if (status) {
@ -136,12 +148,24 @@ tstylesheet {
with "type", "$type";
with "name", "concat('set', $jname)";
}
const "type_ret" call "jni_type" with "type", "name(.)";
||
JNIEXPORT `call "jni_type" with "type", "name(.)"` JNICALL «$getname»(JNIEnv *env,
// CodeGen: Getter
JNIEXPORT «$type_ret» JNICALL «$getname»(JNIEnv *env,
jobject obj)
{
pEpLog("called");
«$name» *_obj = «$name»_ptr(env, obj);
«$name»* _obj = nullptr;
try {
_obj = «$name»_ptr(env, obj);
} catch(...) {
jclass ex = env->FindClass("java/lang/IllegalStateException");
assert(ex);
env->ThrowNew(ex, nullptr);
return static_cast<«$type_ret»>(NULL);
}
||
choose {
when "../enum[@name=$type]"
@ -151,14 +175,22 @@ tstylesheet {
}
||
}
// CodeGen: Setter
JNIEXPORT void JNICALL «$setname»(JNIEnv *env,
jobject obj,
`call "jni_type" with "type", "name(.)"`
value)
{
pEpLog("called");
«$name» *_obj = «$name»_ptr(env, obj);
«$name»* _obj = nullptr;
try {
_obj = «$name»_ptr(env, obj);
} catch(...) {
jclass ex = env->FindClass("java/lang/IllegalStateException");
assert(ex);
env->ThrowNew(ex, nullptr);
return;
}
||
choose {
when "../enum[@name=$type]"


+ 1
- 0
src/codegen/gen_java_Message.ysl2 View File

@ -66,6 +66,7 @@ tstylesheet {
public final void close() {
release(handle);
handle = 0;
}
final protected long getHandle() {


Loading…
Cancel
Save