[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Metalscan <contact@m...> |
| Subject: | Re: [Caml-list] java: short [] [] -> JNI -> int array array |
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