

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
3 messages in net.java.dev.jna.users[jna-users] question about Strings an...| From | Sent On | Attachments |
|---|---|---|
| Simon BASLE | Jun 18, 2007 10:47 am | |
| Timothy Wall | Jun 18, 2007 11:23 am | |
| Simon BASLE | Jun 20, 2007 4:23 pm |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | [jna-users] question about Strings and array pointers | Actions... |
|---|---|---|
| From: | Simon BASLE (sba...@free.fr) | |
| Date: | Jun 18, 2007 10:47:07 am | |
| List: | net.java.dev.jna.users | |
Ok I've just read your reply to my previous message and I've been struggling
with it all the afternoon,
Without success, so I'd like more details on it :)
But first I guess that I should myself give more details so here it goes :
I am currently trying to use a C library called PVM, which allows me to make a
virtual supercomputer using several computers accross a network.
It's a distributed systems thing ;) The function that cause trouble is called
spawn.
It allows to spawn a process on a distant machine and link to the spawning one
via PVM.
Here is the signature :
int pvm_spawn(char *task, char **args, int spawnType, char *where, int nbTasks,
int *tids);
task is the string name of the executable file to spawn
args is an array of strings which are the arguments passed to the spawned
process. Last element must be NULL.
where contains the hostname of the machine where to spawn if required by
spawnType, NULL otherwise
nbTasks is the number of tasks to spawn, tids is an array of size >= nbTasks
which will receive the corresponding PVM ids
when I try to map to String[] or byte[][] I receive an "unsupported array class"
error
so here is how I tried to map it :
int pvm_spawn(String task, Memory spargs, int flag, String where, int ntask,
int[] tids);
and here is what I do to call the pvm_spawn method :
============================
int[] tids = null;
String arg1 = "/home/balai/workspace/JnaTest/SecondApp.jar";
byte arg2 = '\0';
Memory ptr1 = new Memory(arg1.length()+1); ptr1.setString(0, arg1, false);
Memory ptr2 = new Memory(Byte.SIZE); ptr2.setByte(0, arg2);
Memory spargs = new Memory(ptr1.getSize()+ptr2.getSize()); spargs.setPointer(0, ptr1); spargs.setPointer(ptr1.getSize(), null);
test.pvm_spawn("/home/balai/jnaJarLaunch", spargs, PvmCst.PvmTaskDefault,
"noule", 1, tids);
============================
I've made an executable jar called SecondApp.jar that is pvm enabled and will
receive the message from the "spawner"
I've also made a bash script that launch java with the proper parameters
(jna.library.path) and execute the passed jar file
This is jnaJarLaunch.
So basically what happens is that the "spawner" spawns jnaJarLaunch and pass the
name of the jar to be spawned to it.
PVM is made in a way that if you spawn a script which in turn execute a pvm
enabled program, this program will be the one linked to pvm...
I've tested it with a C pvm program which seamlessly spawns my jar.
Also when I try to directly spawn a task (without parameters, so it must be a C
task) it works !
But when I try to spawn a java task (with parameters) it tells me :
# An unexpected error has been detected by Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0xb7e6bbfb, pid=13219, tid=3084737424
#
# Java VM: Java HotSpot(TM) Client VM (1.6.0-b105 mixed mode, sharing)
# Problematic frame:
# C [libc.so.6+0x6dbfb] strlen+0xb
In the log the problem seems to be from Proxy$pvm_spawn or something like
that...
And the most strange of all : it runs correctly every now and then (but it's
very rare, I'd say 3 times in 25 attemps maybe :[ )
So I guess I've done something wrong... Hope you will be able to help me! Sorry for the long message. Simon
Hi again! I now encounter a char** function (expecting an array of Strings). I tried to use String[ ] but it doesn't let me... Not even when using byte[ ][ ] instead. How can I do that?
File an RFE to automatically convert String[] arguments. You can do it by allocating a Memory object of the appropriate size and calling setPointer at each char* offset; you'd need to construct each element yourself. Not pretty, but one of the goals of JNA's design is to allow you to do just about anything you could do in C.
char** is common enough that it should be supported automatically, though.







