[5964] in java-interest

home help back first fref pref prev next nref lref last post

Re: How to call java methods and constructors from native C methods ?

daemon@ATHENA.MIT.EDU (Fabrice PARDO)
Wed Mar 6 15:44:27 1996

Date: Wed, 6 Mar 1996 20:02:31 +0100
From: Fabrice PARDO <fabrice.pardo@bagneux.cnet.fr>
To: java-interest@java.sun.com
Cc: fabrice.pardo@bagneux.cnet.fr

I have just got JDK 1.0 source. Thanks Sun. I can respond now my questions
Q1 and Q2

> 
> Q1) How can I call methods involving double args
> Now I'm able to call with success execute_java_dynamic_method and
> execute_java_constructor fonctions declared in java1.0/include/interpreter.h
> if args are not double nor java long.
> 
> double Test_sqroot(struct HEssai *essai, double d) {
>     ClassClass *cc=FindClass(0, "java/lang/Math", 1);
>     long ret=execute_java_static_method(0,  cc, "sqrt", "(D)D", ?which args?);
>     return ?what to return?;
> }
> 
> 
> Q2) How to pass arguments from a list ? With "..." args in C, I can suppose
> that there is less than (for example) 10 args and pass always 10 args :
> v[0], v[1], v[2], etc. v[9])
> I think there is other functions, able to manipulate java stack.
> Any documentation ?

execute_java_static_method is here an inadequate wrapper to
do_execute_java_method_vararg. Calling do_execute_java_method_vararg
directly works with array datas and returns double half part of 64 bits data.
Other half part need to be referenced by highBits.
do_execute_java_method_vararg is declared in include/interpreter.h
of java-DTK-1.0

long do_execute_java_method_vararg(ExecEnv *ee, void *obj, 
				   char *method_name, char *signature, 
				   struct methodblock *mb,
				   bool_t isStaticCall, va_list args, 
				   long *highBits, bool_t shortFloats);


As an example, the implementation of a native static method
TryIt.atan2Test(double, double) that is in fact Math.atan2(double, double) :

file TryIt.java:
class TryIt {
    public static native double atan2Test(double a, double b);
}

file mathtest.c:
#include <StubPreamble.h>
#include <math.h>
#include "TryIt.h"
double TryIt_atan2Test(struct HTryIt *essai, double a, double b) {
    ClassClass *cc;
    double args[2];
    Java8 sixtyfour;
    args[0]=a;
    args[1]=b;
    cc=FindClass(0, "java/lang/Math", 1);
    sixtyfour.x[1]=do_execute_java_method_vararg(
        0, cc, "atan2", "(DD)D", 0, TRUE, args, &(sixtyfour.x[0]), FALSE);
    return sixtyfour.d;
}

*************************************************************
Fabrice Pardo
Laboratoire de Microstructures et de Micro-Electronique, CNRS
196 avenue Henri Ravera F-92225 Bagneux
(33-1)42.31.75.63
fabrice.pardo@bagneux.cnet.fr
*************************************************************
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post