is there a cleaner way to new a static sized array?

2010-02-23 Thread BCS
I need a function that works like the following: T* New(T)() { return new T; } But that also works with static arrays: auto i = New!(int)(); auto a = New!(int[27])(); The cleanest solution I can think of is: T* New(T)() { return (new T[1]).ptr; } but that seems ugly. Any ideas? -- ..

Re: Bizarre find() error [D2]

2010-02-23 Thread Jonathan M Davis
It looks to me like it might be the same issue as bug# 3682: http://d.puremagic.com/issues/show_bug.cgi?id=3682 - although I ran into it in a different way. - Jonathan M Davis

Re: segfaults

2010-02-23 Thread Bernard Helyer
On 24/02/10 12:53, Ellery Newcomer wrote: Hey! You're right! import tango.io.Stdout; void main(){ Object obj = null; int[] a; a ~= 1; Stdout(obj.toString()).newline; } gives me Die: DW_TAG_type_unit (abbrev 7, offset 0x6f) parent at offset: 0xb has children: FALSE attributes: DW_AT_byte_size (

Re: Bizarre find() error [D2]

2010-02-23 Thread Jonathan M Davis
bearophile wrote: > Jonathan M Davis: >> This is starting to look like a bug in DMD rather than my code. That is, >> unless I'm just totally misunderstanding something about how imports >> work. As it is, it just seems downright weird. > > D2 module system has several bugs, but I can't know if th

exceptions

2010-02-23 Thread Ellery Newcomer
Okay, does anyone know a good way to figure out where something like this is coming from: object.Exception: lengths don't match for array copy

Simple Socket Server Code

2010-02-23 Thread sybrandy
All, Does anyone know where I can get a simple example of writing a server in D? Just a stupid little echo server would be fine. I'm trying to write one myself, but for some reason it doesn't seem to be accepting any connections. I figure it's something stupidly simple, but I'm just not se

Re: When is array-to-array cast legal, and what does actually happen?

2010-02-23 Thread div0
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Ali Çehreli wrote: > Daniel Keep wrote: >>> ... > Well I forget the details, but it's been pointed out before that D's cast is fundamentally broken. You get one cast operator that hides the full set of c++ static, dynamic, const & reinterpret casts.

Re: segfaults

2010-02-23 Thread Ellery Newcomer
On 02/23/2010 03:22 PM, Bernard Helyer wrote: On 24/02/10 03:45, Ellery Newcomer wrote: I'm thinking it's an issue with DMD. I can get backtraces with simple programs. If you use a dynamic array in there somewhere, the chances of it not working go up, I'm afraid. This doesn't leave many progr

Re: Bizarre find() error [D2]

2010-02-23 Thread bearophile
Jonathan M Davis: > This is starting to look like a bug in DMD rather than my code. That is, > unless I'm just totally misunderstanding something about how imports work. > As it is, it just seems downright weird. D2 module system has several bugs, but I can't know if the bug is in your code, in

Re: segfaults

2010-02-23 Thread Bernard Helyer
On 24/02/10 03:45, Ellery Newcomer wrote: I'm thinking it's an issue with DMD. I can get backtraces with simple programs. If you use a dynamic array in there somewhere, the chances of it not working go up, I'm afraid. This doesn't leave many programs that *work*.

Re: Bizarre find() error [D2]

2010-02-23 Thread Jonathan M Davis
Steven Schveighoffer wrote: > This works for me (dmd 2.040): > > import std.algorithm; > import std.array; > > void main() > { > string[] list; > string str; > auto f = find(list, str); > bool strInList = !f.empty(); > } > > -Steve Hmmm. It seems to have to do with calling t

Re: segfaults

2010-02-23 Thread Robert Clipsham
On 23/02/10 17:33, Ellery Newcomer wrote: Oh. good idea. mua ha ha. ldc dies on compile: ldc: /home/kamm/eigenes/projekte/ldc/llvm-26/lib/VMCore/Instructions.cpp:921: void llvm::StoreInst::AssertOK(): Assertion `getOperand(0)->getType() == cast(getOperand(1)->getType())->getElementType() && "Pt

Re: segfaults

2010-02-23 Thread Ellery Newcomer
On 02/23/2010 10:34 AM, Robert Clipsham wrote: I'm no expert, but that looks like a dmd bug, can you reproduce with ldc? The actual segfault is probably to do with your code, but if gdb gives that then there's a problem with the debug info that dmd is writing. The only easy way to debug this if

Re: segfaults

2010-02-23 Thread Robert Clipsham
On 23/02/10 02:14, Ellery Newcomer wrote: Is there any decent way to figure out where segfaults are coming from? e.g. 200k lines of bad code converted from java I tried gdb, and it didn't seem to work too well. Die: DW_TAG_type_unit (abbrev 3, offset 0x6d) parent at offset: 0xb has children: F

Re: segfaults

2010-02-23 Thread Ellery Newcomer
On 02/23/2010 06:28 AM, Steven Schveighoffer wrote: On Mon, 22 Feb 2010 21:14:08 -0500, Ellery Newcomer wrote: Is there any decent way to figure out where segfaults are coming from? e.g. 200k lines of bad code converted from java I tried gdb, and it didn't seem to work too well. Die: DW_TAG

Re: Bizarre find() error [D2]

2010-02-23 Thread Steven Schveighoffer
On Tue, 23 Feb 2010 00:07:45 -0500, Jonathan M Davis wrote: Okay, I'm trying to find out if a particular string is in an array of strings. The best function that I can find for that appears to be find(), since there's no contains() or anything like that and in only works for associative ar

Re: segfaults

2010-02-23 Thread Steven Schveighoffer
On Mon, 22 Feb 2010 21:14:08 -0500, Ellery Newcomer wrote: Is there any decent way to figure out where segfaults are coming from? e.g. 200k lines of bad code converted from java I tried gdb, and it didn't seem to work too well. Die: DW_TAG_type_unit (abbrev 3, offset 0x6d) parent at off

Re: Commmandline arguments and UTF8 error

2010-02-23 Thread Jacob Carlborg
On 2/23/10 01:35, Daniel Keep wrote: Jacob Carlborg wrote: On 2010-02-22 15.39, Nils Hensel wrote: Daniel Keep schrieb: If you look at the real main function in src\phobos\internal\dmain2.d, you'll see this somewhere around line 109 (I'm using 1.051, but it's unlikely to be much different in

Re: segfaults

2010-02-23 Thread bearophile
Ellery Newcomer: > Is there any decent way to figure out where segfaults are coming from? > e.g. 200k lines of bad code converted from java To perform that translation you have to do first adapt the original Java code to D as much as possible keeping it woeking, then add unit tests to each method

Re: Running external program from a D program [D2]

2010-02-23 Thread Lutger
"Jérôme M. Berger" wrote: > Jonathan M Davis wrote: >> Jesse Phillips wrote: >>> As you may have noticed by the comments to on bug 3158. exec()[1] calls >>> replace your process, this means it will not continue your program. To >>> get arround this you find that people will first fork()[2] and exe

Re: When is array-to-array cast legal, and what does actually happen?

2010-02-23 Thread Lars T. Kyllingstad
Daniel Keep wrote: ... I see that neither the constructor nor the postblit is called. Apparently the bit representation is used. This has the risk of violating struct invariants. Is it legal? Thank you, Ali cast is to value conversions what a tactical nuclear strike is to peaceful negotiatio