Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
July 22, 2005 segfault when printing 2 dimentional array | ||||
---|---|---|---|---|
| ||||
Hi all.
The following code makes the compiler segfault:
import std.stdio, std.string;
void main()
{
writefln(split("A b"));
}
--
---
Life is either tragedy or comedy.
Usually it's your choice. You can whine or you can laugh.
--Animorphs
|
July 23, 2005 Re: segfault when printing 2 dimentional array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ameer Armaly | On Fri, 22 Jul 2005 17:52:14 -0400, Ameer Armaly wrote: > Hi all. > The following code makes the compiler segfault: > import std.stdio, std.string; > void main() > { > writefln(split("A b")); > } The split() function returns a set of slices into its parameter. If you are running on Linux, the string literal is in protected RAM so writes to it will fail. When I run your test on Windows, I just get a bad format code message. Here is my version of your test to make it work ... import std.stdio, std.string; void main() { foreach(char[] s; split("A b".dup)) writefln(s); } -- Derek Parnell Melbourne, Australia 23/07/2005 8:59:00 PM |
July 23, 2005 Re: segfault when printing 2 dimentional array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ameer Armaly | "Ameer Armaly" <ameer_armaly@hotmail.com> wrote in message news:dbrprs$1pb6$1@digitaldaemon.com... > Hi all. > The following code makes the compiler segfault: > import std.stdio, std.string; > void main() > { > writefln(split("A b")); > } I think you wanted to post this to D.bugs and not D.announce. On Windows the compiler didn't seg-v (since you say seg-v I assume you're on Linux, though) but it does give a FormatError when you run the program. That's because general dynamic arrays are not handled by std.format.doFormat. I've fixed up doFormat to write the string [s_1,s_2,...,s_N] where s_k is the result of calling doFormat recursively on the kth element of the array. Right now I have it working for dynamic arrays. I'll try to get static and associative arrays going and send the result to Walter. |
July 23, 2005 Re: segfault when printing 2 dimentional array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | In article <dbteao$6oa$1@digitaldaemon.com>, Ben Hinkle says... > >"Ameer Armaly" <ameer_armaly@hotmail.com> wrote in message news:dbrprs$1pb6$1@digitaldaemon.com... >> Hi all. >> The following code makes the compiler segfault: >> import std.stdio, std.string; >> void main() >> { >> writefln(split("A b")); >> } > >I think you wanted to post this to D.bugs and not D.announce. >On Windows the compiler didn't seg-v (since you say seg-v I assume you're on >Linux, though) but it does give a FormatError when you run the program. >That's because general dynamic arrays are not handled by >std.format.doFormat. I've fixed up doFormat to write the string >[s_1,s_2,...,s_N] where s_k is the result of calling doFormat recursively on >the kth element of the array. Right now I have it working for dynamic >arrays. I'll try to get static and associative arrays going and send the >result to Walter. > With DMD v0.128, this code doesn't segfault on either Windows or Linux during compilation and 'Error: std.format formatArg' is the result when it is run on either. - Dave |
July 25, 2005 Re: segfault when printing 2 dimentional array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote: > On Fri, 22 Jul 2005 17:52:14 -0400, Ameer Armaly wrote: > >> Hi all. >> The following code makes the compiler segfault: >> import std.stdio, std.string; >> void main() >> { >> writefln(split("A b")); >> } > > The split() function returns a set of slices into its parameter. If you are > running on Linux, the string literal is in protected RAM so writes to it > will fail. <snip> Why would this code cause a write to the string literal? Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- a->--- UB@ P+ L E@ W++@ N+++ o K- w++@ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit. |
Copyright © 1999-2021 by the D Language Foundation