www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8544] New: Expose "cArgs" in druntime

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8544

           Summary: Expose "cArgs" in druntime
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



14:22:34 PDT ---
When interfacing with C/C++ libraries one common problem is having to extract
argc/argv arguments from D main() and passing them back to library functions. A
common solution is:

// Array of pointers to command line parameters.
char*[] argv = args.map!((a)=>(a.dup~'\0').ptr).array;

But it would be much simpler (and more efficient) if argc & argv were stored
somewhere in druntime. There's a Runtime.args() function in core.runtime which
exports the runtime args as a D-friendly array, so we could provide a cArgs
equivalent which returns a struct with argc/argv.

druntime/src/rt/dmain2.d is where main is called from:
extern (C) int main(int argc, char** argv) { ... }

From there we could easily store argc+argv into a global struct variable,
similar to how _d_args is exposed as a __gshared string[].

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 12 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8544


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 12 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8544




16:53:34 PDT ---
I'd like to fix this myself. But I'm not sure how this should be exposed in the
Runtime struct. Should it be two properties, 'argc' and 'argv', or a single
property such as the following, in core.runtime:

extern (C) CArgs rt_cArgs();

static  property string[] cArgs()
{
    return rt_cArgs();
}

and in src\rt\dmain2.d:
struct CArgs
{
    int argc
    char** argv;
}

__gshared CArgs _cArgs = null;

extern (C) string[] rt_cArgs()
{
    return _cArgs;
}

extern (C) int main(int argc, char** argv)
{
    _cArgs.argc = argc;
    _cArgs.argv = argv;
    ...
}

Thoughts?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 02 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8544




16:54:34 PDT ---

 I'd like to fix this myself. But I'm not sure how this should be exposed in the
 Runtime struct. Should it be two properties, 'argc' and 'argv', or a single
 property such as the following, in core.runtime:
 
 extern (C) CArgs rt_cArgs();
 
 static  property string[] cArgs()
 {
     return rt_cArgs();
 }
That should be:
 static  property CArgs cArgs()
and
 extern (C) CArgs rt_cArgs()
Obviously I'm just pseudocoding. :) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 02 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8544


Alex Rønne Petersen <alex lycus.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alex lycus.org



CEST ---
I suppose it wouldn't be a problem to have a cArgs property on the Runtime
struct. I'd prefer returning a struct over two separate properties.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 02 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8544




Commits pushed to master at https://github.com/D-Programming-Language/druntime

https://github.com/D-Programming-Language/druntime/commit/2e73c0fd3139af781f3afe926c4485b20f88a16d
Fixes Issue 8544 - Expose cArgs in Druntime struct for easier interfacing with
C libraries.

https://github.com/D-Programming-Language/druntime/commit/84beb97864444e11b419cfa5eb4792d7fbdc8e1a


Fix Issue 8544 - Expose cArgs in Druntime struct for C interfacing

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 23 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8544


Alex Rønne Petersen <alex lycus.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 23 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8544




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/14cdab6fc079b2d99e159e7a7e85e80f87251bf8
Add test for druntime Issue 8544

https://github.com/D-Programming-Language/dmd/commit/e19b894ca972b559137708258744ea781935c1cb


Add test for druntime Issue 8544

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 27 2012