-
Notifications
You must be signed in to change notification settings - Fork 200
Open
Description
As per #1294 I was able to create a lower level interface to access the JVM. But significant improvements would be required.
- We would need to provide a frame object which holds references for a limited scope.
import jpype.jni at jni
from jpype.jni import * # gives jint, jlong, jchar, jobject, jarray etc.
# We can use JPype for most high level operations
JString =jpype.JClass("java.lang.string")
# If someone wants to perform a low level operation they must create a frame to hold Java references
env = jni.GetEnv()
with jni.Frame(16) as fx:
fx.GetVersion()
ja = fx.NewObjectArray(10, fx.ref(JString), fx.null) // light wrapper to ctypes interface dealing with the env.contents.functions.contents non-sense
... do something with it.
// ja is set to null when frame leave scope
- We would need to have an accessor which can take our JPype resources and convert them into local references that one can pass to Java.
with env.Frame() as fx:
jpype_array = JInt[100]
jni_array = fx.ref(jpype_array) // Convert a JPype resource into a low level resource
...
jpype_array2 = fx.wrap(jni_array) // Convert a low level resource back into a global JPype reference.
- We would need resource locks for holding the lock/unlock string and array access. Again would need to be using the with operator.
Is this worth putting the effort into? It may make it possible to communicate with JEP or some other wrapper, but only if those other wrappers had simpler ability to make a local reference and wrap an existing reference.
As for a name jtypes, jni, or jffi make sense. We need a reference and wrap method. Those could be operators like [] or maybe ~ though I could see conflicts with the number types. We could just use the existing cast operations.
Example as functions
ja = fx.ref(JInt[10]) # Convert to local reference
array = fx.wrap(ja) # Convert local reference back to JPype (holds global)
Example as casting
ja = fx@JInt[10] # Convert to local reference
array = JObject@ja # Convert local reference back to JPype (holds global)
@marscher as you are the primary maintainer, I think the ultimate decision will go to you.
Metadata
Metadata
Assignees
Labels
No labels