/*
 * Class:     jep_InvocationHandler
 * Method:    invoke
 * Signature: (Ljava/lang/String;JJ[Ljava/lang/Object;[Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object;
 */
JNIEXPORT jobject JNICALL Java_jep_InvocationHandler_invoke
(JNIEnv *env,
 jclass clazz,
 jstring jname,
 jlong _jepThread,
 jlong _target,
 jobjectArray args,
 jintArray types,
 jint returnType)
{

    JepThread     *jepThread;
    jobject        ret;
    const char    *cname;
    PyObject      *target;
    PyObject      *callable;

    target   = (PyObject *) (intptr_t) _target;
    ret      = NULL;
    callable = NULL;

    jepThread = (JepThread *) (intptr_t) _jepThread;
    if (!jepThread) {
        THROW_JEP(env, "Couldn't get thread objects.");
        return NULL;
    }

    PyEval_AcquireThread(jepThread->tstate);

    // now get the callable object
    cname = jstring2char(env, jname);
    // python docs say this returns a new ref. they lie like dogs.
    callable = PyObject_GetAttrString(target, (char *) cname);
    release_utf_char(env, jname, cname);

    if (process_py_exception(env, 0) || !callable) {
        goto EXIT;
    }

    ret = pyembed_invoke(env, callable, args, types);

EXIT:
    PyEval_ReleaseThread(jepThread->tstate);

    return ret;
}
Exemple #2
0
/*
 * Class:     jep_python_PyPointer
 * Method:    decref
 * Signature: (JJ)V
 */
JNIEXPORT void JNICALL Java_jep_python_PyPointer_decref
(JNIEnv *env, jobject obj, jlong tstate, jlong pyobj)
{
    JepThread  *jepThread;
    PyObject   *pyObject;

    jepThread = (JepThread *) tstate;
    if (!jepThread) {
        THROW_JEP(env, "Couldn't get thread objects.");
        return;
    }

    pyObject = (PyObject*) pyobj;

    PyEval_AcquireThread(jepThread->tstate);
    Py_DECREF(pyObject);
    PyEval_ReleaseThread(jepThread->tstate);
}