Jump to page: 1 2
Thread overview
[Issue 2479] New: sformat is broken
Nov 29, 2008
d-bugmail
May 20, 2009
Gide Nwawudu
Aug 29, 2009
Brad Roberts
Aug 29, 2009
Brad Roberts
Aug 31, 2009
Don
[Issue 2479] Badcode regression: closure corrupts _argptr value
Oct 15, 2009
Don
Oct 15, 2009
Don
Nov 02, 2009
Don
Nov 02, 2009
Leandro Lucarella
Nov 05, 2009
Walter Bright
Nov 05, 2009
Leandro Lucarella
[Issue 2479] Regression: cannot use variadic arguments inside a closure
Nov 10, 2009
Don
[Issue 2479] Cannot use variadic arguments inside a closure
Feb 13, 2011
Don
November 29, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2479

           Summary: sformat is broken
           Product: D
           Version: 2.022
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: dick221z@yahoo.com


char [32] tmp;
sformat(tmp,"hi");
writefln(tmp);

tmp is null after calling sformat. In some other cases an EXCEPTION_ACCESS_VIOLATION is thrown.

Oddly enough format works fine

The problem seems to be in passing the variable argument list to sformat, the argptr passed to sformat is null.

Workaround is to go back to 2.021


-- 

May 20, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2479


Gide Nwawudu <gide@nwawudu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |gide@nwawudu.com
           Severity|major                       |regression




--- Comment #1 from Gide Nwawudu <gide@nwawudu.com>  2009-05-20 07:37:33 PDT ---
Set importance to regression.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 29, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2479


Brad Roberts <braddr@puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |braddr@puremagic.com




--- Comment #2 from Brad Roberts <braddr@puremagic.com>  2009-08-29 14:45:40 PDT ---
A reduced test case (larger, but complete and doesn't import large swaths of code).  This is a massive reduction of all the irrelevant parts of doFormat torn away, and sformat reduced a good bit as well.

module bug2479;

import std.stdarg;

void doFormat(void delegate(dchar) myputc, TypeInfo[] arguments, va_list
argptr)
{
    string fmt = va_arg!(string)(argptr);
    assert(!(fmt is null)); // fires when it shouldn't.
}

char[] sformat(char[] s, ...)
{
    void putc(dchar c) { s[0] = cast(char)c; }

    doFormat(&putc, _arguments, _argptr);
    return s[0 .. 1];
}

void main()
{
    char[32] tmp;
    sformat(tmp, "%s", "hi");
}

Changing putc to not touch 's' causes the va_arg call to succeed an fmt is no longer null.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 29, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2479





--- Comment #3 from Brad Roberts <braddr@puremagic.com>  2009-08-29 14:55:44 PDT ---
Adding a printf at the top of doFormat...

The broken case:
  argptr = 0xf7ceeffc
  core.exception.AssertError@bug2479.d(11): Assertion failure

With putc emptied out:
  argptr = 0xffb004d4
  (no assert)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 31, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2479


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au




--- Comment #4 from Don <clugdbug@yahoo.com.au>  2009-08-31 01:59:58 PDT ---
Even further reduced, removing all imports. My patch to bug 814 does not fix this.
------
alias void* va_list;

T va_arg(T)(inout va_list _argptr) {
    T arg = *cast(T*)_argptr;
    _argptr = _argptr + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1));
    return arg;
}

void doFormat(void delegate(dchar) myputc, TypeInfo[] args, va_list
argptr){
    string fmt = va_arg!(string)(argptr);
    assert(!(fmt is null)); // fires when it shouldn't.
}

char[] sformat(char[] s, ...){
    void putc(dchar c) { s[0] = cast(char)c; }

    doFormat(&putc, _arguments, _argptr);
    return s[0 .. 1];
}

void main(){
    char[32] tmp;
    sformat(tmp, "%s", "hi");
}

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


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei@metalanguage.com
         AssignedTo|nobody@puremagic.com        |andrei@metalanguage.com


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


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|Phobos                      |DMD
            Summary|sformat is broken           |Badcode regression: closure
                   |                            |corrupts _argptr value


--- Comment #5 from Don <clugdbug@yahoo.com.au> 2009-10-15 05:21:36 PDT ---
Reduced test case. This does not seem to be a Phobos bug.
If you remove any reference to s from the delegate (so that it stops being a
closure), the code works correctly.
----
void doFormat(void delegate() myputc, void * argptr){
    assert(!(*cast(string*)argptr is null));
}

void sformat(string s, ...){
    void putc() { assert(s[0]==s[0]); }
    doFormat(&putc, _argptr);
}

void main(){
    sformat("xxx", "hi");
}

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


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 02, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2479



--- Comment #6 from Don <clugdbug@yahoo.com.au> 2009-11-02 00:20:19 PST ---
I have patched Phobos so that original symptom is fixed.
The compiler bug is that in FuncDeclaration::buildClosure() in toir.c, variadic
arguments aren't supported, but _argptr is set in FuncDeclaration::semantic3()
as if they were.

Partial patch, to turn this from a wrong-code into a rejects-valid bug, until
the bug is actually fixed:
func.c, line 1282.
---
        if (argptr)
        {    // Initialize _argptr to point past non-variadic arg
#if IN_GCC
        // Handled in FuncDeclaration::toObjFile
        v_argptr = argptr;
        v_argptr->init = new VoidInitializer(loc);
#else
+        // BUG: Fix this in FuncDeclaration::buildClosure() in toir.c.
+        if (needsClosure())
+            error("Closures are not yet supported with variadic arguments
(Bugzilla 2479)");
        Type *t = argptr->type;
        VarDeclaration *p;
        unsigned offset;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 02, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2479


Leandro Lucarella <llucax@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |llucax@gmail.com


--- Comment #7 from Leandro Lucarella <llucax@gmail.com> 2009-11-02 05:40:56 PST ---
SVN commit (workarround in Phobos, not a real fix): http://www.dsource.org/projects/phobos/changeset/1318

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