digitalmars.D.bugs - [Issue 814] New: lazy argument + variadic arguments
- d-bugmail puremagic.com (51/51) Jan 07 2007 http://d.puremagic.com/issues/show_bug.cgi?id=814
- d-bugmail puremagic.com (7/7) Apr 05 2007 http://d.puremagic.com/issues/show_bug.cgi?id=814
- d-bugmail puremagic.com (25/25) Jul 02 2009 http://d.puremagic.com/issues/show_bug.cgi?id=814
- d-bugmail puremagic.com (30/30) Jul 02 2009 http://d.puremagic.com/issues/show_bug.cgi?id=814
- d-bugmail puremagic.com (17/17) Jul 20 2009 http://d.puremagic.com/issues/show_bug.cgi?id=814
- d-bugmail puremagic.com (12/12) Oct 06 2009 http://d.puremagic.com/issues/show_bug.cgi?id=814
http://d.puremagic.com/issues/show_bug.cgi?id=814 Summary: lazy argument + variadic arguments Product: D Version: 1.00 Platform: PC OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: ville.mattila iki.fi Hello, I'm very new to d. I'm testing lazy evaluation and it seems like I've found bug w/ dmd compiler on linux. Here are the details. -- foo.d --- import std.stdio; import std.stdarg; import std.string, std.conv, std.stream; void foo(lazy void expression, ...) { //expression(); if (_arguments.length > 0) { _arguments[0].print(); //writefln("got vararg:" ~ _arguments[0].name); if ((_arguments[0]) == typeid(char[])) { writefln("got vararg:" ~ std.conv.toString(_arguments.length)); char[] tmp_msg = va_arg!(char[])(_argptr); writefln("GOOTT vararg: " ~ tmp_msg); } } } int main(char[][] args) { foo(writefln("barz"),"foo"); return(0); } --- foo.d ---- ./foo char[] got vararg:1 Segmentation fault (core dumped) mulperi mulperi-desktop:/usr/local/src/apps/d/dmd/samples/d$ dmd --help Digital Mars D Compiler v1.0 Copyright (c) 1999-2007 by Digital Mars written by Walter Bright Documentation: www.digitalmars.com/d/index.html Usage: dmd files.d ... { -switch } I'm usring xubuntu 6.10 w/ latest patches. - Ville --
Jan 07 2007
http://d.puremagic.com/issues/show_bug.cgi?id=814 Added to DStress as http://dstress.kuehne.cn/run/l/lazy_04_A.d http://dstress.kuehne.cn/run/l/lazy_04_B.d http://dstress.kuehne.cn/run/l/lazy_04_C.d --
Apr 05 2007
http://d.puremagic.com/issues/show_bug.cgi?id=814 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |clugdbug yahoo.com.au Summary|lazy argument + variadic |lazy argument + variadic |arguments |arguments = segfault Reduced test case shows it's an out-by-1 error in grabbing the arguments. The length ends up in the ptr field. Probably, it's neglecting the fact that lazy arguments have a pointer as well as the value, or something similar. import std.stdarg; void foo(lazy int expr, ...){ char[] tmp_msg = va_arg!(char[])(_argptr); if (cast(int)(tmp_msg.ptr)=="food_for_thought".length) assert(0, "length is in the pointer!"); } void main(){ foo(515,"food_for_thought"); } Applies to D2 as well as D1. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 02 2009
http://d.puremagic.com/issues/show_bug.cgi?id=814 In fact, by replacing the T arg line below with the commented out-line, it gets the correct arguments. So in fact, it's just getting the size of the lazy parameter wrong when it's calculating _argptr. ------------- alias void* va_list; template va_arg(T) { T va_arg(inout va_list _argptr) { T arg = *cast(T*)_argptr; // original from Phobos // T arg = *(cast(T*)(cast(int *)_argptr+1)); _argptr = _argptr + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1)); return arg; } } void foo(lazy int expr, ...){ char[] tmp_msg = va_arg!(char[])(_argptr); if (cast(int)(tmp_msg.ptr)=="food_for_thought".length) assert(0, "length is in the pointer!"); assert(tmp_msg=="food_for_thought"); } int bar() { return 3; } void main(){ foo(bar(),"food_for_thought"); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 02 2009
http://d.puremagic.com/issues/show_bug.cgi?id=814 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch PATCH: func.c, line 1211. Need to account for a lazy last parameter. - offset = p->type->size(); + if (p->storage_class & STClazy) { + // If the last parameter is lazy, it's the size of a delegate + offset = sizeof(int(*)(int)) + sizeof(void *); + } else { + offset = p->type->size(); + } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 20 2009
http://d.puremagic.com/issues/show_bug.cgi?id=814 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla digitalmars.com Resolution| |FIXED 02:12:02 PDT --- Fixed dmd 1.048 and 2.033 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 06 2009