[2788] in java-interest

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

Re: Returning new instances of ArrayOf(s) from C

daemon@ATHENA.MIT.EDU (Thomas Ball)
Fri Oct 13 16:59:34 1995

Date: Fri, 13 Oct 1995 11:43:18 -0700
From: Thomas.Ball@Eng.Sun.COM (Thomas Ball)
To: root@cyberpunk.com
Cc: java-interest@java.Eng.Sun.COM

>  Hiya All,
>  
>  	After digging through the code for makeJavaString I decided to write
>  something called makeHArrayOfInt (basically return int[] to java from c). I believe I
>  am using the write Alloc however the int arrays body field is a long*...
>  whichseems to not like memsets memcpys etc... Exactly how does one return an array
>  of ints through c without having to be given one. Thanks in advance

This should do it:

#include <native.h>

HArrayOfInt *MyClass_makeHArrayOfInt(HMyClass * this, long num)
{
    HArrayOfInt		*ret;
    ArrayOfInt		*val;
    int			i;

    ret = (HArrayOfInt *) ArrayAlloc(T_INT, num);
    if (ret == 0) {
        SignalError(0, JAVAPKG "OutOfMemoryError", 0);
        return NULL;
    }
    val = (ArrayOfInt *)unhand(ret);
    for (i = 0; i < (int)num; i++) {
	val->body[i] = i;
    }
    return ret;
}

Tom Ball
Java Products Group
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

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