www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - char ***argc problems.

reply "Andrew" <andrew.spott gmail.com> writes:
I'm attempting to create a wrapper for MPI, however, MPI_Init
wants to read the arguments for main():

MPI_Init(int *argv, char ***argc);

How do I get this last level of pointer reference?

So far, I have:

void main (string[] args)
{
      auto argarr = new char*[args.length];
      foreach(i, a; args)
          argarr[i] = (a.dup ~ '\0').ptr;

      int argc = to!(int)(argarr.length);
      MPI_Init(&argc, argarr.ptr);
}

Any ideas?

-Andrew
Aug 12 2012
next sibling parent reply "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
On Sun, 12 Aug 2012 22:30:57 +0200, Andrew <andrew.spott gmail.com> wrote:

 I'm attempting to create a wrapper for MPI, however, MPI_Init
 wants to read the arguments for main():

 MPI_Init(int *argv, char ***argc);

 How do I get this last level of pointer reference?

 So far, I have:

 void main (string[] args)
 {
       auto argarr = new char*[args.length];
       foreach(i, a; args)
           argarr[i] = (a.dup ~ '\0').ptr;

       int argc = to!(int)(argarr.length);
       MPI_Init(&argc, argarr.ptr);
 }

 Any ideas?
// Array of pointers to command line parameters. char*[] argv = args.map!((a)=>(a.dup~'\0').ptr).array; // Address of first element of that array. char** argvp = &argv[0]; // And finally, address of the pointer to that first element. char*** argvpp = &argvp; Now, the interesting part is reconstructing the string[] from the potentially modified argvpp... -- Simen
Aug 12 2012
parent reply "1100110" <10equals2 gmail.com> writes:
Would this be useful?
https://github.com/1100110/OpenMPI

On Sunday, 12 August 2012 at 20:52:03 UTC, Simen Kjaeraas wrote:
 On Sun, 12 Aug 2012 22:30:57 +0200, Andrew 
 <andrew.spott gmail.com> wrote:

 I'm attempting to create a wrapper for MPI, however, MPI_Init
 wants to read the arguments for main():

 MPI_Init(int *argv, char ***argc);

 How do I get this last level of pointer reference?

 So far, I have:

 void main (string[] args)
 {
      auto argarr = new char*[args.length];
      foreach(i, a; args)
          argarr[i] = (a.dup ~ '\0').ptr;

      int argc = to!(int)(argarr.length);
      MPI_Init(&argc, argarr.ptr);
 }

 Any ideas?
// Array of pointers to command line parameters. char*[] argv = args.map!((a)=>(a.dup~'\0').ptr).array; // Address of first element of that array. char** argvp = &argv[0]; // And finally, address of the pointer to that first element. char*** argvpp = &argvp; Now, the interesting part is reconstructing the string[] from the potentially modified argvpp...
Aug 12 2012
parent "1100110" <10equals2 gmail.com> writes:
(sorry for spam...)

On Sunday, 12 August 2012 at 21:04:55 UTC, 1100110 wrote:
 Would this be useful?
 https://github.com/1100110/OpenMPI

 On Sunday, 12 August 2012 at 20:52:03 UTC, Simen Kjaeraas wrote:
 On Sun, 12 Aug 2012 22:30:57 +0200, Andrew 
 <andrew.spott gmail.com> wrote:

 I'm attempting to create a wrapper for MPI, however, MPI_Init
 wants to read the arguments for main():

 MPI_Init(int *argv, char ***argc);

 How do I get this last level of pointer reference?

 So far, I have:

 void main (string[] args)
 {
     auto argarr = new char*[args.length];
     foreach(i, a; args)
         argarr[i] = (a.dup ~ '\0').ptr;

     int argc = to!(int)(argarr.length);
     MPI_Init(&argc, argarr.ptr);
 }

 Any ideas?
// Array of pointers to command line parameters. char*[] argv = args.map!((a)=>(a.dup~'\0').ptr).array; // Address of first element of that array. char** argvp = &argv[0]; // And finally, address of the pointer to that first element. char*** argvpp = &argvp; Now, the interesting part is reconstructing the string[] from the potentially modified argvpp...
Aug 12 2012
prev sibling next sibling parent reply 1100110 <10equals2 gmail.com> writes:
Would this help?
https://github.com/1100110/OpenMPI

On Sun, 12 Aug 2012 15:30:57 -0500, Andrew <andrew.spott gmail.com> wrote:

 I'm attempting to create a wrapper for MPI, however, MPI_Init
 wants to read the arguments for main():

 MPI_Init(int *argv, char ***argc);

 How do I get this last level of pointer reference?

 So far, I have:

 void main (string[] args)
 {
       auto argarr = new char*[args.length];
       foreach(i, a; args)
           argarr[i] = (a.dup ~ '\0').ptr;

       int argc = to!(int)(argarr.length);
       MPI_Init(&argc, argarr.ptr);
 }

 Any ideas?

 -Andrew
-- Using Opera's revolutionary email client: http://www.opera.com/mail/
Aug 12 2012
parent reply "Andrew" <andrew.spott gmail.com> writes:
Yes, incredibly.

Thanks!

On Sunday, 12 August 2012 at 20:57:47 UTC, 1100110 wrote:
 Would this help?
 https://github.com/1100110/OpenMPI

 On Sun, 12 Aug 2012 15:30:57 -0500, Andrew 
 <andrew.spott gmail.com> wrote:

 I'm attempting to create a wrapper for MPI, however, MPI_Init
 wants to read the arguments for main():

 MPI_Init(int *argv, char ***argc);

 How do I get this last level of pointer reference?

 So far, I have:

 void main (string[] args)
 {
      auto argarr = new char*[args.length];
      foreach(i, a; args)
          argarr[i] = (a.dup ~ '\0').ptr;

      int argc = to!(int)(argarr.length);
      MPI_Init(&argc, argarr.ptr);
 }

 Any ideas?

 -Andrew
Aug 12 2012
parent 1100110 <10equals2 gmail.com> writes:
Let me know if you see something weird, I haven't tried building that in a  
long time.
Aug 12 2012
prev sibling next sibling parent 1100110 <10equals2 gmail.com> writes:
Also the Elementary repo has a wrapper for main() from E17, might be  
useful.

On Sun, 12 Aug 2012 15:54:45 -0500, 1100110 <10equals2 gmail.com> wrote:

 Would this help?
 https://github.com/1100110/OpenMPI

 On Sun, 12 Aug 2012 15:30:57 -0500, Andrew <andrew.spott gmail.com>  
 wrote:

 I'm attempting to create a wrapper for MPI, however, MPI_Init
 wants to read the arguments for main():

 MPI_Init(int *argv, char ***argc);

 How do I get this last level of pointer reference?

 So far, I have:

 void main (string[] args)
 {
       auto argarr = new char*[args.length];
       foreach(i, a; args)
           argarr[i] = (a.dup ~ '\0').ptr;

       int argc = to!(int)(argarr.length);
       MPI_Init(&argc, argarr.ptr);
 }

 Any ideas?

 -Andrew
-- Using Opera's revolutionary email client: http://www.opera.com/mail/
Aug 12 2012
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 8/12/12, Simen Kjaeraas <simen.kjaras gmail.com> wrote:
      // Array of pointers to command line parameters.
      char*[] argv = args.map!((a)=>(a.dup~'\0').ptr).array;
You know.. it'd be much simpler if argc & argv were stored somewhere. druntime/src/rt/dmain2.d is where the action begins: extern (C) int main(int argc, char** argv) { ... } And then this is stored as a string[] to _d_args which can be picked up via Runtime.args() in core.runtime. I'm thinking that having to retrieve the original argc/argv is common when interfacing with C/C++, so maybe we should have a druntime function which can return the original unprocessed args?
Aug 12 2012
prev sibling next sibling parent "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
On Sun, 12 Aug 2012 23:02:43 +0200, Andrej Mitrovic  
<andrej.mitrovich gmail.com> wrote:

 On 8/12/12, Simen Kjaeraas <simen.kjaras gmail.com> wrote:
      // Array of pointers to command line parameters.
      char*[] argv = args.map!((a)=>(a.dup~'\0').ptr).array;
You know.. it'd be much simpler if argc & argv were stored somewhere. druntime/src/rt/dmain2.d is where the action begins: extern (C) int main(int argc, char** argv) { ... } And then this is stored as a string[] to _d_args which can be picked up via Runtime.args() in core.runtime. I'm thinking that having to retrieve the original argc/argv is common when interfacing with C/C++, so maybe we should have a druntime function which can return the original unprocessed args?
That don't sound too stupid. File an enhancement request, wouldya? -- Simen
Aug 12 2012
prev sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 8/12/12, Simen Kjaeraas <simen.kjaras gmail.com> wrote:
 That don't sound too stupid. File an enhancement request, wouldya?
http://d.puremagic.com/issues/show_bug.cgi?id=8544
Aug 12 2012