Re: Issuing compile-time warnings with line numbers?

2011-09-20 Thread Jacob Carlborg
On 2011-09-21 02:18, Andrej Mitrovic wrote: Won't compile for obvious reasons: struct Bar { } struct Foo { this(Bar bar, int line = __LINE__) { pragma(msg, "Warning: Constructing Foo with Bar incurs precision loss. Line: " ~ line); } } void main() { auto foo = Foo(B

Re: How to read output of a script

2011-09-20 Thread Jonathan M Davis
On Wednesday, September 21, 2011 04:40:34 Cheng Wei wrote: > Thanks a lot. > Weird. It is not in the library reference in http://www.d-programming- > language.org/, but it is in the library reference in digitalmars.com. I > throught the previous one was the official web site now. It seems it > stil

Re: How to read output of a script

2011-09-20 Thread Cheng Wei
Thanks a lot. Weird. It is not in the library reference in http://www.d-programming- language.org/, but it is in the library reference in digitalmars.com. I throught the previous one was the official web site now. It seems it still is not synced well.

Is it a bug in execvb (std.process)?

2011-09-20 Thread Cheng Wei
import std.process; void main() { execvp("ip", ["route"]); } result: Object "ute" is unknown, try "ip help". So the first two bytes are lost. After adding two spaces in the first argument, it works. import std.process; void main() { execvp("ip", [" route"]); } dmd 2.055 linux 32bit. Is

Is this a bug in execvp of std.process

2011-09-20 Thread Cheng Wei
#import std.process void main() { execvp("ip", "route"); } result: Object "ute" is unknown, try "ip help". That is the first two bytes are lost Adding two spaces works: #import std.process void main() { execvp("ip", " route"); } Version 2.055, linux, 32bit Thanks.

Re: Dynamic Array Question

2011-09-20 Thread Jesse Phillips
On Tue, 20 Sep 2011 14:28:54 -0400, Steven Schveighoffer wrote: > You can deallocate the original array. The soon-to-be-deprecated method > (but easiest) is: > > delete t; > > To avoid having to change your other code, I'd do this: > > wchar[] t = ...; > scope(exit) delete t; // add this line

Re: How to read output of a script

2011-09-20 Thread Jonathan M Davis
On Wednesday, September 21, 2011 03:31:11 Cheng Wei wrote: > In D2, how can we get the output of running a script. > We can use 'system' to run the script, but how we cannot assign the > standard output of the running script. Is there any way to do it, or > whether it will be included into future v

How to read output of a script

2011-09-20 Thread Cheng Wei
In D2, how can we get the output of running a script. We can use 'system' to run the script, but how we cannot assign the standard output of the running script. Is there any way to do it, or whether it will be included into future version of std.process? Thanks a lot.

Re: Issuing compile-time warnings with line numbers?

2011-09-20 Thread Andrej Mitrovic
On 9/21/11, Adam D. Ruppe wrote: > I'd suggest having a version(warnings_suck) { static assert(0); } > so people who want more info can just stick a -version= on the build > and get the compiler's help. Yeah that was already planned, no worries. :)

Re: Issuing compile-time warnings with line numbers?

2011-09-20 Thread Adam D. Ruppe
I'd suggest having a version(warnings_suck) { static assert(0); } so people who want more info can just stick a -version= on the build and get the compiler's help. static assert(0) gives a kind of compile time stack trace.

Re: Dynamic Array Question

2011-09-20 Thread Jonathan M Davis
On Tuesday, September 20, 2011 21:48:10 Christophe wrote: > > To avoid having to change your other code, I'd do this: > > > > wchar[] t = ...; > > scope(exit) delete t; // add this line to the end of the function (after > > returning) > > > > There is another way, but it's not as easy: > > > > /

Re: Issuing compile-time warnings with line numbers?

2011-09-20 Thread Andrej Mitrovic
Ah, you're right. It should have been a compile-time argument, conv.to actually works in CTFE: import std.conv; struct Bar { } struct Foo { this(int line = __LINE__)(Bar bar) { pragma(msg, "Warning: Constructing Foo with Bar incurs precision loss. Line: " ~ to!string(line)); } }

Re: Issuing compile-time warnings with line numbers?

2011-09-20 Thread Jonathan M Davis
On Tuesday, September 20, 2011 17:18 Andrej Mitrovic wrote: > Won't compile for obvious reasons: > > struct Bar { } > struct Foo > { > this(Bar bar, int line = __LINE__) > { > pragma(msg, "Warning: Constructing Foo with Bar incurs > precision loss. Line: " ~ line); > } > } > > void main() > { > a

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Christophe
Timon Gehr , dans le message (digitalmars.D.learn:29641), a écrit : >> Last point: WalkLength is not optimized for strings. >> std.utf.count should be. >> >> This short implementation of count was 3 to 8 times faster than >> walkLength is a simple benchmark: >> >> size_t myCount(string text) >> { >

Issuing compile-time warnings with line numbers?

2011-09-20 Thread Andrej Mitrovic
Won't compile for obvious reasons: struct Bar { } struct Foo { this(Bar bar, int line = __LINE__) { pragma(msg, "Warning: Constructing Foo with Bar incurs precision loss. Line: " ~ line); } } void main() { auto foo = Foo(Bar()); } That's just an example, but I want to iss

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Timon Gehr
On 09/21/2011 01:57 AM, Christophe wrote: "Jonathan M Davis" , dans le message (digitalmars.D.learn:29637), a écrit : On Tuesday, September 20, 2011 14:43 Andrej Mitrovic wrote: On 9/20/11, Jonathan M Davis wrote: Or std.range.walkLength. I don't know why we really have std.utf.count. I jus

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Christophe
"Jonathan M Davis" , dans le message (digitalmars.D.learn:29637), a écrit : > On Tuesday, September 20, 2011 14:43 Andrej Mitrovic wrote: >> On 9/20/11, Jonathan M Davis wrote: >> > Or std.range.walkLength. I don't know why we really have std.utf.count. I >> > just >> > calls walkLength anyway. I

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Jonathan M Davis
On Tuesday, September 20, 2011 15:10 Andrej Mitrovic wrote: > On 9/20/11, Jonathan M Davis wrote: > > We specifically avoid having aliases in Phobos simply for having > > alternate function names. Aliases need to actually be useful, or they > > shouldn't be there. > > And function names have to b

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Andrej Mitrovic
On 9/20/11, Jonathan M Davis wrote: > We specifically avoid having aliases in Phobos simply for having alternate > function names. Aliases need to actually be useful, or they shouldn't be > there. And function names have to be useful to library users. walkLength is an awful name for something tha

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Jonathan M Davis
On Tuesday, September 20, 2011 14:43 Andrej Mitrovic wrote: > On 9/20/11, Jonathan M Davis wrote: > > Or std.range.walkLength. I don't know why we really have std.utf.count. I > > just > > calls walkLength anyway. I suspect that it's a function that predates > > walkLength and was made to use walk

Re: Dynamic Array Question

2011-09-20 Thread Christophe
> To avoid having to change your other code, I'd do this: > > wchar[] t = ...; > scope(exit) delete t; // add this line to the end of the function (after > returning) > > There is another way, but it's not as easy: > > // put this at the top of file > import core.memory; > > ... > > scope(ex

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Andrej Mitrovic
One other thing, count can only take an array which seems too restrictive since walkLength can take any range at all. So maybe count should be just an alias to walkLength or it should possibly be removed (I'm against fully removing it because I already use it in code and I think the name does make

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Andrej Mitrovic
On 9/20/11, Jonathan M Davis wrote: > Or std.range.walkLength. I don't know why we really have std.utf.count. I > just > calls walkLength anyway. I suspect that it's a function that predates > walkLength and was made to use walkLength after walkLength was introduced. > But > it's kind of pointless

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Jonathan M Davis
On Tuesday, September 20, 2011 14:27 Andrej Mitrovic wrote: > Don't use length, use std.utf.count, ala: > > import std.utf; > alias toUTFz!(const(wchar)*, string) toUTF16z; > GetTextExtentPoint32W(str.toUTF16z, std.utf.count(str), s); Or std.range.walkLength. I don't know why we really have std.u

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Andrej Mitrovic
Don't use length, use std.utf.count, ala: import std.utf; alias toUTFz!(const(wchar)*, string) toUTF16z; GetTextExtentPoint32W(str.toUTF16z, std.utf.count(str), s); I like to keep that alias for my code since I was already using it beforehand. I'm pretty sure (ok maybe 80% sure) that GetTextExt

Re: const->immutable array argument?

2011-09-20 Thread bearophile
Steven Schveighoffer: > BTW, when posting questions like this, it is *immensely* helpful to give > exact error messages, I have forgotten to do that by mistake. I am sorry. Bye, bearophile

Re: Dynamic Array Question

2011-09-20 Thread Dax
Does it 'leak'? What is your exact setup, why isn't the GC collecting that memory? I have a Label class with a text() property that calls the procedure that I have written in my first post and returns the result. I have posted here because I was looking the memory usage (more precisely th

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Andre
Am Tue, 20 Sep 2011 20:44:40 +0200 schrieb Timon Gehr: > On 09/20/2011 08:24 PM, Timon Gehr wrote: >> On 09/20/2011 08:07 PM, Andre wrote: >>> Am Tue, 20 Sep 2011 19:27:03 +0200 schrieb Trass3r: >>> > bool test(HDC dc, string str, int len, SIZE* s) > { > wchar[] wstr = toUTFz!(wchar*)s

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Timon Gehr
On 09/20/2011 08:24 PM, Timon Gehr wrote: On 09/20/2011 08:07 PM, Andre wrote: Am Tue, 20 Sep 2011 19:27:03 +0200 schrieb Trass3r: bool test(HDC dc, string str, int len, SIZE* s) { wchar[] wstr = toUTFz!(wchar*)str; GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s); toUTFz returns a wchar*,

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Timon Gehr
On 09/20/2011 08:34 PM, Trass3r wrote: Are you sure that the call requires the string to be null terminated? I do not know that winapi function, but this might work: bool test(HDC dc, string str, SIZE* s) { auto wstr = to!(wchar[])str; GetTextExtentPoint32W(dc, wstr.ptr, wstr.length, s); ... I

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Trass3r
Are you sure that the call requires the string to be null terminated? I do not know that winapi function, but this might work: bool test(HDC dc, string str, SIZE* s) { auto wstr = to!(wchar[])str; GetTextExtentPoint32W(dc, wstr.ptr, wstr.length, s); ... It doesn't need to be null-terminated f

Re: Dynamic Array Question

2011-09-20 Thread Timon Gehr
On 09/20/2011 08:06 PM, Dax wrote: Hi! I'm working on a library written in D. After some tests I have discovered that my library leaks memory, those leaks are caused by dynamics array that I use in my library. Does it 'leak'? What is your exact setup, why isn't the GC collecting that memory?

Re: Dynamic Array Question

2011-09-20 Thread Jonathan M Davis
On Tuesday, September 20, 2011 11:06 Dax wrote: > Hi! > I'm working on a library written in D. > After some tests I have discovered that my library leaks memory, those > leaks are caused by dynamics array that I use in my library. > > My question is: > Should dynamics array be deallocated automati

Re: Dynamic Array Question

2011-09-20 Thread Steven Schveighoffer
On Tue, 20 Sep 2011 14:06:34 -0400, Dax wrote: Hi! I'm working on a library written in D. After some tests I have discovered that my library leaks memory, those leaks are caused by dynamics array that I use in my library. My question is: Should dynamics array be deallocated automatically wh

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Timon Gehr
On 09/20/2011 08:07 PM, Andre wrote: Am Tue, 20 Sep 2011 19:27:03 +0200 schrieb Trass3r: bool test(HDC dc, string str, int len, SIZE* s) { wchar[] wstr = toUTFz!(wchar*)str; GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s); toUTFz returns a wchar*, not a wchar[]. I am not familiar with po

Dynamic Array Question

2011-09-20 Thread Dax
Hi! I'm working on a library written in D. After some tests I have discovered that my library leaks memory, those leaks are caused by dynamics array that I use in my library. My question is: Should dynamics array be deallocated automatically when a procedure returns? There is another way to acom

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Andre
Am Tue, 20 Sep 2011 19:27:03 +0200 schrieb Trass3r: >> bool test(HDC dc, string str, int len, SIZE* s) >> { >> wchar[] wstr = toUTFz!(wchar*)str; >> GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s); > > toUTFz returns a wchar*, not a wchar[]. I am not familiar with pointers. I know I have to c

Re: Is there a profiler for D2?

2011-09-20 Thread Mike Wey
On 09/20/2011 08:46 AM, Jonathan M Davis wrote: I don't believe that it doesn't currently work with 64-bit binaries though, You could use oprofile in that case. http://oprofile.sourceforge.net/ -- Mike Wey

Re: toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Trass3r
bool test(HDC dc, string str, int len, SIZE* s) { wchar[] wstr = toUTFz!(wchar*)str; GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s); toUTFz returns a wchar*, not a wchar[].

toUTFz and WinAPI GetTextExtentPoint32W

2011-09-20 Thread Andre
Hi, I want something like: bool test(HDC dc, string str, int len, SIZE* s) { wchar[] wstr = toUTFz!(wchar*)str; GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s); ... I get the wchar[] stuff not working. I am struggling with pointer to array. Could you give some advice? Kind regards Andre

Re: const->immutable array argument?

2011-09-20 Thread Daniel Murphy
"Steven Schveighoffer" wrote in message news:op.v13w8td2eav7ka@localhost.localdomain... > On Tue, 20 Sep 2011 07:33:20 -0400, bearophile > wrote: > >> void foo(const ref int[5] a) {} >> void main() { >> immutable int[5] arr; >> foo(arr); // Error? >> } > > The complaint from the compile

Re: Calling D code from C

2011-09-20 Thread Denis Shelomovskij
20.09.2011 9:55, Jonathan M Davis пишет: Someone who has actually done a C or C++ application or two which used D code should answer this question. I know that there are at least a few folks around here who have done that, but I've never done it myself. http://stackoverflow.com/questions/7480046

Re: const->immutable array argument?

2011-09-20 Thread Steven Schveighoffer
On Tue, 20 Sep 2011 07:33:20 -0400, bearophile wrote: In this bug report I have asked for better error messages: http://d.puremagic.com/issues/show_bug.cgi?id=6696 But beside the error message, do you know why an immutable ref can't be given to a function with a const ref argument? foo() c

Re: const->immutable array argument?

2011-09-20 Thread Steven Schveighoffer
On Tue, 20 Sep 2011 07:33:20 -0400, bearophile wrote: In this bug report I have asked for better error messages: http://d.puremagic.com/issues/show_bug.cgi?id=6696 But beside the error message, do you know why an immutable ref can't be given to a function with a const ref argument? foo() c

Re: const->immutable array argument?

2011-09-20 Thread Kagamin
bearophile Wrote: > In this bug report I have asked for better error messages: > http://d.puremagic.com/issues/show_bug.cgi?id=6696 > > But beside the error message, do you know why an immutable ref can't be given > to a function with a const ref argument? foo() can't change the contents of > t

Re: const->immutable array argument?

2011-09-20 Thread bearophile
Christophe: > I don't think it is wrong. Did you try changind the order of const and > ref, or adding parenthesis ? I am trying now, and it seems the situation doesn't change. Bye, bearophile

Re: const->immutable array argument?

2011-09-20 Thread Christophe
bearophile , dans le message (digitalmars.D.learn:29609), a écrit : > what's wrong in this code? > > > void foo(const ref int[5] a) {} > void main() { > immutable int[5] arr; > foo(arr); // Error? > } I don't think it is wrong. Did you try changind the order of const and ref, or adding

const->immutable array argument?

2011-09-20 Thread bearophile
In this bug report I have asked for better error messages: http://d.puremagic.com/issues/show_bug.cgi?id=6696 But beside the error message, do you know why an immutable ref can't be given to a function with a const ref argument? foo() can't change the contents of the array a any way, so what's w

Re: A little puzzle

2011-09-20 Thread Regan Heath
On Mon, 19 Sep 2011 23:09:45 +0100, Simen Kjaeraas wrote: On Mon, 19 Sep 2011 23:20:47 +0200, bearophile wrote: A tiny puzzle I've shown on IRC. This is supposed to create an inverted array of cards, but what does it print instead? import std.stdio, std.algorithm, std.range; void main

Re: Calling D code from C

2011-09-20 Thread Kagamin
Jonathan M Davis Wrote: > Someone who has actually done a C or C++ application or two which used D code > should answer this question. I know that there are at least a few folks > around > here who have done that, but I've never done it myself. > > http://stackoverflow.com/questions/7480046/im