@@ -332,7 +332,7 @@ function jnew(T::Symbol, argtypes::Tuple = () , args...)
332
332
if jmethodId == C_NULL
333
333
throw (JavaCallError (" No constructor for $T with signature $sig " ))
334
334
end
335
- return _jnicall (metaclass (T), jmethodId, JNI . NewObjectA, JavaObject{T}, argtypes, args... )
335
+ return _jcall (metaclass (T), jmethodId, JavaObject{T}, argtypes, args... ; callmethod = JNI . NewObjectA )
336
336
end
337
337
338
338
_jcallable (typ:: Type{JavaObject{T}} ) where T = metaclass (T)
411
411
# JField invoke
412
412
(f:: JField )(obj) = jfield (obj, f)
413
413
414
- function _jfield (obj, jfieldID:: Ptr{Nothing} , fieldType:: Type )
415
- result = _jnifield (obj, jfieldID, fieldType)
416
- result== C_NULL && geterror ()
417
- return convert_result (fieldType, result)
418
- end
419
-
420
- function _jcall (obj, jmethodId, callmethod, rettype, argtypes, args... )
421
- savedArgs, convertedArgs = convert_args (argtypes, args... )
422
- GC. @preserve savedArgs begin
423
- result = _jnicall (obj, jmethodId, rettype, argtypes, jvalue .(convertedArgs))
424
- end
425
- deleteref .(filter (x-> isa (x,JavaObject),convertedArgs))
426
- result== C_NULL && geterror ()
427
- return convert_result (rettype, result)
428
- end
429
-
430
- # Generate these methods to satisfy ccall's compile time constant requirement
431
414
for (x, name) in [(:Type , " Object" ),
432
415
(:(Type{jboolean}), " Boolean" ),
433
416
(:(Type{jchar}), " Char" ),
@@ -443,18 +426,29 @@ for (x, name) in [(:Type, "Object"),
443
426
callmethod = :(JNI.$ (Symbol (cstr)))
444
427
fieldmethod = :(JNI.$ (Symbol (fstr)))
445
428
m = quote
446
- function _jnicall (obj:: T , jmethodId:: Ptr{Nothing} , rettype:: $x ,
447
- argtypes:: Tuple , args) where T <: $t
448
- $ callmethod (Ptr (obj), jmethodId, Array {JNI.jvalue} (args))
429
+ function _jfield (obj:: T , jfieldID:: Ptr{Nothing} , fieldType:: $x ) where T <: $t
430
+ result = $ fieldmethod (Ptr (obj), jfieldID)
431
+ result== C_NULL && geterror ()
432
+ return convert_result (fieldType, result)
449
433
end
450
- function _jnifield (obj:: T , jfieldID:: Ptr{Nothing} , fieldType:: $x ) where T <: $t
451
- $ fieldmethod (Ptr (obj), jfieldID)
434
+ function _jcall (obj:: T , jmethodId:: Ptr{Nothing} , rettype:: $x ,
435
+ argtypes:: Tuple , args... ; callmethod= $ callmethod) where T <: $t
436
+ savedArgs, convertedArgs = convert_args (argtypes, args... )
437
+ GC. @preserve savedArgs begin
438
+ result = callmethod (Ptr (obj), jmethodId, Array {JNI.jvalue} (jvalue .(convertedArgs)))
439
+ end
440
+ cleanup_arg .(convertedArgs)
441
+ result== C_NULL && geterror ()
442
+ return convert_result (rettype, result)
452
443
end
453
444
end
454
445
eval (m)
455
446
end
456
447
end
457
448
449
+ cleanup_arg (arg) = nothing
450
+ cleanup_arg (arg:: JavaObject ) = deleteref (arg)
451
+
458
452
global const _jmc_cache = [ Dict {Symbol, JavaMetaClass} () ]
459
453
460
454
function _metaclass (class:: Symbol )
0 commit comments