Jump to page: 1 2
Thread overview
char ***argc problems.
Aug 12, 2012
Andrew
Aug 12, 2012
Simen Kjaeraas
Aug 12, 2012
1100110
Aug 12, 2012
1100110
Aug 12, 2012
1100110
Aug 12, 2012
Andrew
Aug 12, 2012
1100110
Aug 12, 2012
1100110
Aug 12, 2012
Andrej Mitrovic
Aug 12, 2012
Simen Kjaeraas
Aug 12, 2012
Andrej Mitrovic
August 12, 2012
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
August 12, 2012
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
August 12, 2012
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/
August 12, 2012
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/
August 12, 2012
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?
August 12, 2012
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
August 12, 2012
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...


August 12, 2012
(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...


August 12, 2012
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
August 12, 2012
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


« First   ‹ Prev
1 2