caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Metalscan <contact@metalscan.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] java: short [] [] -> JNI -> int array array
Date: Fri, 29 Nov 2002 13:19:31 +0100	[thread overview]
Message-ID: <20021129121931.GA27490@rhinoceros.mts> (raw)
In-Reply-To: <20021128190209.GA19294@rhinoceros.mts>

Lastly I have a working solution.

I'm still not sure of it's correctness...

If some guru have the time to points me any amelioration, I would
appreciate (both for pure C part, and manipulation of values).

I apologize if this is of topic.

Thanks in advance,
Matthieu Dubuget

value short_p_to_val(char const  * i)
{
    value v;  
    short k = * i ;

    v= Val_int((short) *((short *) i) );
    return v ;
}

value f(char const * l)
{
  CAMLparam0() ;
  CAMLlocal1(v);

  v=alloc_array(&short_p_to_val,(char const * * ) l) ;

  CAMLreturn(v);
}

value java_short_array_array_to_ocaml_int_array_array
    (JNIEnv * env, jobject obj , jobjectArray jcscanA) {
 
    CAMLparam0 ();
    CAMLlocal1(v);

    //One element (line) of the jcscanA array
    jobjectArray ligne ;

    //bodies for each lines of the jcscanA pointer
    jshort * * ligne_body = NULL ;
    
    int i, j;  

    // The C array in wich I'll put the values of jcscanA
    // Must do that because we need a null ended array for alloc_array
    short * * * cscan ;

    jsize lignes,colonnes;

    // Allocation de cscan et ligne_body
    lignes = (*env) -> GetArrayLength(env,jcscanA) ;
    cscan = malloc((lignes+1) * sizeof(short * *));
    ligne_body = malloc (lignes * sizeof(jshort *));

    // Again : cscan is NULL ended
    cscan[lignes]=NULL;

    // Remplissage avec les valeurs de jcscanA
    for (i=0;i<lignes;i++){
	
	ligne = (*env)->GetObjectArrayElement(env,jcscanA,i);
	colonnes = (*env) -> GetArrayLength(env,ligne);
	ligne_body[i] = (*env)->GetShortArrayElements(env,ligne,0);
	cscan[i] = malloc( (colonnes+1) * sizeof(short *) );
	cscan[i][colonnes] = NULL ;
	for(j=0;j<colonnes;j++)
	    cscan[i][j] =  &(ligne_body[i][j]) ;
    }
    
    v = alloc_array(&f, (char const * *) cscan) ;

    for(i=0;i<lignes;i++){
	(*env)->ReleaseShortArrayElements(env,ligne,ligne_body[i],0);
	free(cscan[i]);    
    }
    free(ligne_body);
    free(cscan);

    CAMLreturn (v) ;
};
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


      reply	other threads:[~2002-11-29 17:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-28 19:02 Metalscan
2002-11-29 12:19 ` Metalscan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20021129121931.GA27490@rhinoceros.mts \
    --to=contact@metalscan.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).