Jump to page: 1 2 3
Thread overview
[Issue 11149] New: Runtime.args no longer available in static constructors.
Sep 30, 2013
Mike Wey
Oct 01, 2013
Andrej Mitrovic
Oct 01, 2013
Mike Wey
Oct 08, 2013
Walter Bright
Oct 08, 2013
Andrej Mitrovic
Oct 08, 2013
Martin Nowak
Oct 08, 2013
Martin Nowak
Oct 08, 2013
Andrej Mitrovic
Oct 14, 2013
Martin Nowak
Oct 14, 2013
Andrej Mitrovic
Oct 18, 2013
Martin Nowak
Oct 18, 2013
Andrej Mitrovic
Oct 22, 2013
Walter Bright
Oct 23, 2013
Martin Nowak
Oct 23, 2013
Jacob Carlborg
Oct 23, 2013
Martin Nowak
Oct 23, 2013
Jacob Carlborg
Oct 23, 2013
9999
Oct 25, 2013
Martin Nowak
Oct 25, 2013
Jacob Carlborg
Oct 25, 2013
Martin Nowak
Oct 25, 2013
Jacob Carlborg
Oct 26, 2013
Walter Bright
Oct 26, 2013
Jacob Carlborg
Oct 29, 2013
Martin Nowak
Oct 29, 2013
Walter Bright
Oct 30, 2013
Walter Bright
September 30, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11149

           Summary: Runtime.args no longer available in static
                    constructors.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: druntime
        AssignedTo: nobody@puremagic.com
        ReportedBy: mike-wey@planet.nl


--- Comment #0 from Mike Wey <mike-wey@planet.nl> 2013-09-30 11:30:58 PDT ---
With git head/2.064 core.runtime.Runtime.args always returns null when called from a static constructor, with 2.063 it used to return the commandline args.

Calling it from main works in both versions.

----
import core.runtime;

string[] test;

shared static this()
{
    test = Runtime.args;
}

void main()
{
    assert(test !is null);
}
----
The assert fails with git head/2.064.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11149


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-10-01 04:36:46 PDT ---
Any platform details?

I can't reproduce this on Win7 (using -m32) with these recent commits:

dmd: e0a201bbf80fb7bfbc7e5caf2c29921c3bddf5e3
druntime: 12d535030de97835b4c2fb96d079942d93ea708e
phobos: d744bec6d4500d6cb6f43011beefc7765dd0e5ce

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11149


Mike Wey <mike-wey@planet.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         OS/Version|All                         |Linux


--- Comment #2 from Mike Wey <mike-wey@planet.nl> 2013-10-01 10:31:00 PDT ---
Linux, both 64 and 32 bits.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 08, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11149


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |WORKSFORME


--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2013-10-08 02:17:05 PDT ---
This is working for me with dmd 2.064 head.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 08, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11149



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-10-08 05:36:04 PDT ---
(In reply to comment #3)
> This is working for me with dmd 2.064 head.

On Linux?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 08, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11149


Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@dawg.eu


--- Comment #5 from Martin Nowak <code@dawg.eu> 2013-10-08 09:48:20 PDT ---
*** Issue 11191 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 08, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11149


Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|WORKSFORME                  |


--- Comment #6 from Martin Nowak <code@dawg.eu> 2013-10-08 10:03:19 PDT ---
This is a regression caused by moving the module initialization into C's
.ctor/.dtor sections.
Not sure how to resolve this right now.

BTW, I don't that adding args/cArgs was a good idea in the first place. They provide global access to mutable data but the exact semantics remain unclear, e.g. how is mutating args reflected in main's args and vice versa.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 08, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11149



--- Comment #7 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-10-08 10:20:03 PDT ---
(In reply to comment #6)
> BTW, I don't that adding args/cArgs was a good idea in the first place.

Some libraries require the C arguments during initialization routines. If you try to initialize such a library in a module constructor then core.runtime is the only way of getting to the main() arguments.

(In reply to comment #6)
> how is mutating args reflected in main's args and vice versa.

It's not reflected since a copy is made in _d_run_main. But I guess this should be documented.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 14, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11149


Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|nobody@puremagic.com        |code@dawg.eu


--- Comment #8 from Martin Nowak <code@dawg.eu> 2013-10-14 03:50:27 PDT ---
(In reply to comment #7)
> It's not reflected since a copy is made in _d_run_main. But I guess this should be documented.

The arguments are not copied.

> This is a regression caused by moving the module initialization into C's
.ctor/.dtor sections.

Other than poking around in glibc's internals we can only resolve this issue
by delaying D's initialization until C's main again.
I'll look into this.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 14, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11149



--- Comment #9 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-10-14 07:26:55 PDT ---
(In reply to comment #8)
> (In reply to comment #7)
> > It's not reflected since a copy is made in _d_run_main. But I guess this should be documented.
> 
> The arguments are not copied.

I'm not seeing that:

-----
import core.runtime;
import std.stdio;
import std.string;

void main(char[][] args)
{
    auto c_args = Runtime.cArgs;
    printf("%s\n", c_args.argv[0]);

    c_args.argv[0] = cast(char*)("foobar\0".dup.ptr);
    printf("%s\n", c_args.argv[0]);

    writeln(args[0]);
}
-----

$ rdmd test.d
> C:\Users\ADMINI~1\AppData\Local\Temp\.rdmd\rdmd-test.d-E4AFE2A9EC3418A8D53133284F27D58A\test.exe foobar C:\Users\ADMINI~1\AppData\Local\Temp\.rdmd\rdmd-test.d-E4AFE2A9EC3418A8D53133284F27D58A\test.exe

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2 3