Re: may gc free malloced memory?

2013-09-12 Thread monarch_dodra
On Thursday, 12 September 2013 at 05:36:31 UTC, Alexandr Druzhinin wrote: Some C function malloc-ed memory. This memory should be freeed much later. I don't want to manually call C function to free this memory in some point later, so may I in some way ask gc to free this memory using something

Re: Greedy memory handling

2013-09-12 Thread Jacob Carlborg
On 2013-09-11 10:06, monarch_dodra wrote: I have a function that will *massively* benefit from having a persistent internal buffer it can re-use (and grow) from call to call, instead of re-allocating on every call. What I don't want is either of: 1. To set a fixed limitation of size, if the

Re: may gc free malloced memory?

2013-09-12 Thread Rene Zwanenburg
On Thursday, 12 September 2013 at 05:59:33 UTC, monarch_dodra wrote: On Thursday, 12 September 2013 at 05:36:31 UTC, Alexandr Druzhinin wrote: Some C function malloc-ed memory. This memory should be freeed much later. I don't want to manually call C function to free this memory in some point

Re: may gc free malloced memory?

2013-09-12 Thread Alexandr Druzhinin
12.09.2013 14:45, Rene Zwanenburg пишет: On Thursday, 12 September 2013 at 05:59:33 UTC, monarch_dodra wrote: On Thursday, 12 September 2013 at 05:36:31 UTC, Alexandr Druzhinin wrote: Some C function malloc-ed memory. This memory should be freeed much later. I don't want to manually call C

Re: VisualD import

2013-09-12 Thread QAston
On Wednesday, 11 September 2013 at 22:15:07 UTC, Rainer Schuetze wrote: On 11.09.2013 23:42, Lemonfiend wrote: On Wednesday, 11 September 2013 at 20:36:39 UTC, Rainer Schuetze wrote: On 11.09.2013 18:13, Lemonfiend wrote: Oops, I forgot to say what I actually did. I added derelict to

override and package

2013-09-12 Thread Namespace
Code: import std.stdio; class T1 { protected: void _apply() { writeln(Call T1); } } class T2 : T1 { public: override void _apply() { writeln(Call T2); } } class T3 : T1 { protected: override void _apply() {

Re: override and package

2013-09-12 Thread Namespace
Same with private, of course.

Re: Adding libraries to an executable

2013-09-12 Thread Anton Alexeev
On Thursday, 12 September 2013 at 01:16:28 UTC, Mike Parker wrote: On 9/12/2013 6:20 AM, Anton Alexeev wrote: On Tuesday, 10 September 2013 at 11:06:04 UTC, Jacob Carlborg wrote: On 2013-09-10 11:04, Anton Alexeev wrote: Can be but not libphobos2 Link statically with it, which is does by

Re: override and package

2013-09-12 Thread Jacob Carlborg
On 2013-09-12 11:28, Namespace wrote: But if I try to write 'override' before [1], I get this error message: Error: function T4._apply cannot override a non-virtual function This seems inconsistent. I really overwrite the method, and then I put it in a package label. I think the error

Re: Adding libraries to an executable

2013-09-12 Thread Jacob Carlborg
On 2013-09-12 12:14, Anton Alexeev wrote: I've installed libcurl4-openssl-dev 7.29.0-1ubuntu3.1 before I asked for help here. Else I can't even compile with that command: dmd -L-lphobos2 -L-lcurl test.d How does your dmd.conf file look like? -- /Jacob Carlborg

Re: override and package

2013-09-12 Thread Namespace
On Thursday, 12 September 2013 at 11:29:22 UTC, Jacob Carlborg wrote: On 2013-09-12 11:28, Namespace wrote: But if I try to write 'override' before [1], I get this error message: Error: function T4._apply cannot override a non-virtual function This seems inconsistent. I really overwrite the

Re: override and package

2013-09-12 Thread Jacob Carlborg
On 2013-09-12 13:34, Namespace wrote: Obvious. But what happend? Is the original _apply hidden? If you call through an object of the same type, T4 in this case, the method in the base class is hidden. If you call through a base class reference, T1 in this case, the _apply method in the

Re: override and package

2013-09-12 Thread Jacob Carlborg
On 2013-09-12 13:39, Jacob Carlborg wrote: If you call through an object of the same type, T4 in this case, the method in the base class is hidden. If you call through a base class reference, T1 in this case, the _apply method in the subclass is hidden. I'm guessing it's the same as

Re: __FILE__ and __LINE__ again...

2013-09-12 Thread Dicebot
On Tuesday, 10 September 2013 at 16:58:54 UTC, H. S. Teoh wrote: On Tue, Sep 10, 2013 at 06:50:03PM +0200, Dicebot wrote: On Tuesday, 10 September 2013 at 16:45:33 UTC, H. S. Teoh wrote: but you can get rid of this with link-time optimization (on Posix, you'd add -L-gc-sections to your dmd

Re: Greedy memory handling

2013-09-12 Thread H. S. Teoh
On Thu, Sep 12, 2013 at 08:27:59AM +0200, Jacob Carlborg wrote: On 2013-09-11 10:06, monarch_dodra wrote: I have a function that will *massively* benefit from having a persistent internal buffer it can re-use (and grow) from call to call, instead of re-allocating on every call. What I don't

Re: __FILE__ and __LINE__ again...

2013-09-12 Thread H. S. Teoh
On Thu, Sep 12, 2013 at 03:37:58PM +0200, Dicebot wrote: On Tuesday, 10 September 2013 at 16:58:54 UTC, H. S. Teoh wrote: On Tue, Sep 10, 2013 at 06:50:03PM +0200, Dicebot wrote: On Tuesday, 10 September 2013 at 16:45:33 UTC, H. S. Teoh wrote: but you can get rid of this with link-time

Re: __FILE__ and __LINE__ again...

2013-09-12 Thread Dicebot
On Thursday, 12 September 2013 at 13:58:03 UTC, H. S. Teoh wrote: Interesting. However, I ran into some runtime segfaults caused by --gc-sections yesterday. I didn't investigate further, but that makes me hesitant to make --gc-sections the default. Something, somewhere, is being broken by

Re: Adding libraries to an executable

2013-09-12 Thread Anton Alexeev
On Thursday, 12 September 2013 at 11:30:05 UTC, Jacob Carlborg wrote: On 2013-09-12 12:14, Anton Alexeev wrote: I've installed libcurl4-openssl-dev 7.29.0-1ubuntu3.1 before I asked for help here. Else I can't even compile with that command: dmd -L-lphobos2 -L-lcurl test.d How does your

Handling exceptions from Windows DLL

2013-09-12 Thread FreeSlave
Hello. There was an issue 2 years ago: https://github.com/D-Programming-Language/druntime/pull/92 It seems that this bug is still here (I can't handle D Exception from dll builded with dmd and dmc link). Will this bug get fixed? Do other D compilers have the same issue?

Re: override and package

2013-09-12 Thread Maxim Fomin
On Thursday, 12 September 2013 at 11:29:22 UTC, Jacob Carlborg wrote: On 2013-09-12 11:28, Namespace wrote: But if I try to write 'override' before [1], I get this error message: Error: function T4._apply cannot override a non-virtual function This seems inconsistent. I really overwrite the

Re: Greedy memory handling

2013-09-12 Thread Dmitry Olshansky
12-Sep-2013 17:51, H. S. Teoh пишет: On Thu, Sep 12, 2013 at 08:27:59AM +0200, Jacob Carlborg wrote: On 2013-09-11 10:06, monarch_dodra wrote: I have a function that will *massively* benefit from having a persistent internal buffer it can re-use (and grow) from call to call, instead of

Re: Any idea for a solution to handle overloads when dynamically implementing methods?

2013-09-12 Thread Gary Willoughby
On Wednesday, 11 September 2013 at 18:24:31 UTC, H. S. Teoh wrote: On Mon, Sep 09, 2013 at 10:16:42PM +0200, Gary Willoughby wrote: Just wondered if i could pick you brains for a nice solution to dynamically add methods to a class, paying particular attention to overloads. I'm currently

What does __parameters return?

2013-09-12 Thread simendsjo
The documentation says the parameter tuple of a function, delegate, or function pointer. This includes the parameter types, names, and default values. .. but what type is it? Error: argument (int i, char c, string s, bool b = false) to typeof is not an expression How am I supposed to get

Re: Safety/purity and assert/enforce error messages

2013-09-12 Thread H. S. Teoh
On Thu, Sep 12, 2013 at 09:12:18PM +0200, bearophile wrote: H. S. Teoh: In phobos git HEAD, std.format has been made pure @safe nothrow (and CTFE-able), so you should be able to write your assert as: assert(condition, format(x = %s, blahblah, x)); With the latest DMD from updated

Re: cascade operator or nearest equivalent

2013-09-12 Thread bearophile
Daniel Davidson: I am using Dart for code generation but would like to consider D if I can find a convenient replacement for the following declarative style: Replacing Dart with D seems quite strange, such two languages have so much different usage niches. var dateRange =

Re: Linking Trouble (Linux)

2013-09-12 Thread Craig Dillabaugh
On Thursday, 12 September 2013 at 19:46:21 UTC, Craig Dillabaugh wrote: I just upgraded my Linux distro (openSuse) and now when trying to compile a project with dub I am getting linking errors. Compilation goes OK until the linking stage, when I get the following: Linking... dmd

Re: Safety/purity and assert/enforce error messages

2013-09-12 Thread Jonathan M Davis
On Thursday, September 12, 2013 13:21:26 H. S. Teoh wrote: On Thu, Sep 12, 2013 at 04:07:24PM -0400, Jonathan M Davis wrote: On Thursday, September 12, 2013 12:42:34 H. S. Teoh wrote: On Thu, Sep 12, 2013 at 09:12:18PM +0200, bearophile wrote: H. S. Teoh: In phobos git HEAD,

Re: Safety/purity and assert/enforce error messages

2013-09-12 Thread H. S. Teoh
On Thu, Sep 12, 2013 at 10:17:30PM +0200, Joseph Rushton Wakeling wrote: On 12/09/13 22:07, Jonathan M Davis wrote: format can't be nothrow, because it throws when you screw up the format specifiers. You have to wrap it in a try-catch block and assert(0) in the catch block if you want to put

Cannot access frame of insert whatever here

2013-09-12 Thread simendsjo
I haven't done any D coding since May, but picked up my little toy code again now. Last time I had a lot of hassle with not being able to store/access symbols through templates, and I got the same thing now. Am I the only one hitting these all the time? I'm basically playing around with

Re: Greedy memory handling

2013-09-12 Thread Dmitry Olshansky
12-Sep-2013 20:51, H. S. Teoh пишет: On Thu, Sep 12, 2013 at 07:50:25PM +0400, Dmitry Olshansky wrote: 12-Sep-2013 17:51, H. S. Teoh пишет: [...] struct WeakPointer(T) { enum size_t mask = 0xdeadbeef; union Impl { T* ptr;

Re: Safety/purity and assert/enforce error messages

2013-09-12 Thread bearophile
H. S. Teoh: In phobos git HEAD, std.format has been made pure @safe nothrow (and CTFE-able), so you should be able to write your assert as: assert(condition, format(x = %s, blahblah, x)); With the latest DMD from updated GIT head: import std.string: format; void main() pure

Re: Safety/purity and assert/enforce error messages

2013-09-12 Thread Jonathan M Davis
On Thursday, September 12, 2013 12:42:34 H. S. Teoh wrote: On Thu, Sep 12, 2013 at 09:12:18PM +0200, bearophile wrote: H. S. Teoh: In phobos git HEAD, std.format has been made pure @safe nothrow (and CTFE-able), so you should be able to write your assert as: assert(condition, format(x

Re: Safety/purity and assert/enforce error messages

2013-09-12 Thread H. S. Teoh
On Thu, Sep 12, 2013 at 04:07:24PM -0400, Jonathan M Davis wrote: On Thursday, September 12, 2013 12:42:34 H. S. Teoh wrote: On Thu, Sep 12, 2013 at 09:12:18PM +0200, bearophile wrote: H. S. Teoh: In phobos git HEAD, std.format has been made pure @safe nothrow (and CTFE-able), so you

Re: Greedy memory handling

2013-09-12 Thread monarch_dodra
On Thursday, 12 September 2013 at 19:13:40 UTC, Dmitry Olshansky wrote: Double indirection? Allocate a class that has finalizer, hold that via weak-ref. The wrapper in turn contains a pointer to the buffer. The interesting point then is that one may allocate said buffer via C's realloc. Then

Re: What does __parameters return?

2013-09-12 Thread H. S. Teoh
On Thu, Sep 12, 2013 at 08:44:29PM +0200, simendsjo wrote: The documentation says the parameter tuple of a function, delegate, or function pointer. This includes the parameter types, names, and default values. .. but what type is it? Error: argument (int i, char c, string s, bool b =

Re: Safety/purity and assert/enforce error messages

2013-09-12 Thread Jonathan M Davis
On Thursday, September 12, 2013 22:17:30 Joseph Rushton Wakeling wrote: On 12/09/13 22:07, Jonathan M Davis wrote: format can't be nothrow, because it throws when you screw up the format specifiers. You have to wrap it in a try-catch block and assert(0) in the catch block if you want to put

Re: Adding libraries to an executable

2013-09-12 Thread Jacob Carlborg
On 2013-09-12 18:25, Anton Alexeev wrote: [Environment] DFLAGS=-I/usr/include/dmd/phobos -I/usr/include/dmd/druntime/import -L-L/usr/lib/i386-linux-gnu -L-L/usr/lib/x86_64-linux-gnu -L--no-warn-search-mismatch -L--export-dynamic I don't see way explicitly linking with Phobos would make a

Re: Greedy memory handling

2013-09-12 Thread H. S. Teoh
On Thu, Sep 12, 2013 at 07:50:25PM +0400, Dmitry Olshansky wrote: 12-Sep-2013 17:51, H. S. Teoh пишет: [...] struct WeakPointer(T) { enum size_t mask = 0xdeadbeef; union Impl { T* ptr; size_t uintVal; }

Re: Greedy memory handling

2013-09-12 Thread Jacob Carlborg
On 2013-09-12 15:51, H. S. Teoh wrote: The problem is, he wants to reuse the buffer next time if the GC hasn't collected it yet. I was thinking he could reuse the stack/static buffer. Basically using two buffers, one static and one dynamic. -- /Jacob Carlborg

Re: Safety/purity and assert/enforce error messages

2013-09-12 Thread Joseph Rushton Wakeling
On 12/09/13 22:07, Jonathan M Davis wrote: format can't be nothrow, because it throws when you screw up the format specifiers. You have to wrap it in a try-catch block and assert(0) in the catch block if you want to put it in a nothrow function. std.datetime does this in at least a few places.

Re: Greedy memory handling

2013-09-12 Thread H. S. Teoh
On Thu, Sep 12, 2013 at 11:13:30PM +0400, Dmitry Olshansky wrote: 12-Sep-2013 20:51, H. S. Teoh пишет: On Thu, Sep 12, 2013 at 07:50:25PM +0400, Dmitry Olshansky wrote: [...] Better option is to have finalizer hooked up to set some flag. Then _after_ restoring the pointer we consult that flag

Linking Trouble (Linux)

2013-09-12 Thread Craig Dillabaugh
I just upgraded my Linux distro (openSuse) and now when trying to compile a project with dub I am getting linking errors. Compilation goes OK until the linking stage, when I get the following: Linking... dmd -of/home/craig/cloud/vibe-tiles/vibe /home/craig/cloud/vibe-tiles/temp.o

Re: Safety/purity and assert/enforce error messages

2013-09-12 Thread Joseph Rushton Wakeling
On 12/09/13 20:49, H. S. Teoh wrote: In phobos git HEAD, std.format has been made pure @safe nothrow (and CTFE-able), so you should be able to write your assert as: assert(condition, format(x = %s, blahblah, x)); Don't think it will work on 2.063.2, though, since it was a relatively

Re: Greedy memory handling

2013-09-12 Thread Dmitry Olshansky
13-Sep-2013 00:11, H. S. Teoh пишет: On Thu, Sep 12, 2013 at 11:13:30PM +0400, Dmitry Olshansky wrote: 12-Sep-2013 20:51, H. S. Teoh пишет: On Thu, Sep 12, 2013 at 07:50:25PM +0400, Dmitry Olshansky wrote: [...] Better option is to have finalizer hooked up to set some flag. Then _after_

Re: What does __parameters return?

2013-09-12 Thread simendsjo
On Thursday, 12 September 2013 at 19:41:26 UTC, H. S. Teoh wrote: On Thu, Sep 12, 2013 at 08:44:29PM +0200, simendsjo wrote: (...) .. but what type is it? Error: argument (int i, char c, string s, bool b = false) to typeof is not an expression How am I supposed to get the parameter names

Re: override and package

2013-09-12 Thread Namespace
On Thursday, 12 September 2013 at 16:16:14 UTC, Maxim Fomin wrote: On Thursday, 12 September 2013 at 11:29:22 UTC, Jacob Carlborg wrote: On 2013-09-12 11:28, Namespace wrote: But if I try to write 'override' before [1], I get this error message: Error: function T4._apply cannot override a

Re: Safety/purity and assert/enforce error messages

2013-09-12 Thread H. S. Teoh
On Thu, Sep 12, 2013 at 08:13:37PM +0200, Joseph Rushton Wakeling wrote: Hi all, Suppose that I want to insert some variable values into an assert error message. The easy way to do this is something like: assert(someCondition, text(x = , x, , cannot blah blah blah)); However, the

Re: What does __parameters return?

2013-09-12 Thread Andrej Mitrovic
On 9/12/13, simendsjo simend...@gmail.com wrote: Thanks. I just ended up using both is(__parameters and is(function to fetch the parameter names. Sometimes it seems things are added to D without a very thorough design phase, but then again, it starts with __, so I guess I'm on my own :) Have

Re: Linking Trouble (Linux)

2013-09-12 Thread Craig Dillabaugh
On Thursday, 12 September 2013 at 20:26:29 UTC, Craig Dillabaugh wrote: On Thursday, 12 September 2013 at 19:46:21 UTC, Craig Dillabaugh wrote: I just upgraded my Linux distro (openSuse) and now when trying to compile a project with dub I am getting linking errors. Compilation goes OK until

Re: What does __parameters return?

2013-09-12 Thread H. S. Teoh
On Thu, Sep 12, 2013 at 10:40:06PM +0200, simendsjo wrote: On Thursday, 12 September 2013 at 19:41:26 UTC, H. S. Teoh wrote: On Thu, Sep 12, 2013 at 08:44:29PM +0200, simendsjo wrote: (...) .. but what type is it? Error: argument (int i, char c, string s, bool b = false) to typeof is not

Re: Safety/purity and assert/enforce error messages

2013-09-12 Thread Joseph Rushton Wakeling
On 12/09/13 22:23, Jonathan M Davis wrote: You can put the try-catch in a version(assert) block to get around that problem, but it is true that it's not exactly ideal. However, there really isn't any way around that with a function that takes a format string unless you want it to ignore bad

Re: Safety/purity and assert/enforce error messages

2013-09-12 Thread H. S. Teoh
On Thu, Sep 12, 2013 at 11:37:10PM +0200, Joseph Rushton Wakeling wrote: On 12/09/13 22:23, Jonathan M Davis wrote: You can put the try-catch in a version(assert) block to get around that problem, but it is true that it's not exactly ideal. However, there really isn't any way around that with

Re: isRandomAccessRange!(const(size_t[])) is false ... ?

2013-09-12 Thread Ali Çehreli
On 09/12/2013 02:53 PM, Joseph Rushton Wakeling wrote: import std.range; void main() { assert(isRandomAccessRange!(const(size_t[]))); } results in an assertion error. This is a bug, no ... ? That one is fine. You probably want a slice of const(size_t): import std.range; void

isRandomAccessRange!(const(size_t[])) is false ... ?

2013-09-12 Thread Joseph Rushton Wakeling
import std.range; void main() { assert(isRandomAccessRange!(const(size_t[]))); } results in an assertion error. This is a bug, no ... ?

Re: Safety/purity and assert/enforce error messages

2013-09-12 Thread Meta
On Thursday, 12 September 2013 at 20:07:40 UTC, Jonathan M Davis wrote: On Thursday, September 12, 2013 12:42:34 H. S. Teoh wrote: On Thu, Sep 12, 2013 at 09:12:18PM +0200, bearophile wrote: H. S. Teoh: In phobos git HEAD, std.format has been made pure @safe nothrow (and CTFE-able), so

Re: isRandomAccessRange!(const(size_t[])) is false ... ?

2013-09-12 Thread Jonathan M Davis
On Thursday, September 12, 2013 23:53:15 Joseph Rushton Wakeling wrote: import std.range; void main() { assert(isRandomAccessRange!(const(size_t[]))); } results in an assertion error. This is a bug, no ... ? Nope. It's correct. Because it's const, you can't call popFront on it or

Re: isRandomAccessRange!(const(size_t[])) is false ... ?

2013-09-12 Thread H. S. Teoh
On Thu, Sep 12, 2013 at 03:12:48PM -0700, Ali Çehreli wrote: On 09/12/2013 02:53 PM, Joseph Rushton Wakeling wrote: import std.range; void main() { assert(isRandomAccessRange!(const(size_t[]))); } results in an assertion error. This is a bug, no ... ? That one is fine. You

Re: Safety/purity and assert/enforce error messages

2013-09-12 Thread H. S. Teoh
On Thu, Sep 12, 2013 at 11:45:07PM +0200, Meta wrote: On Thursday, 12 September 2013 at 20:07:40 UTC, Jonathan M Davis wrote: [...] format can't be nothrow, because it throws when you screw up the format specifiers. You have to wrap it in a try-catch block and assert(0) in the catch block if

Re: isRandomAccessRange!(const(size_t[])) is false ... ?

2013-09-12 Thread Andrej Mitrovic
On 9/12/13, Joseph Rushton Wakeling joseph.wakel...@webdrake.net wrote: import std.range; void main() { assert(isRandomAccessRange!(const(size_t[]))); } results in an assertion error. This is a bug, no ... ? I think ranges have to be non-const. I mean how can you iterate over

Re: isRandomAccessRange!(const(size_t[])) is false ... ?

2013-09-12 Thread Joseph Rushton Wakeling
On 13/09/13 00:15, Jonathan M Davis wrote: Nope. It's correct. Because it's const, you can't call popFront on it or any of the other mutating range operations. So, it's not a valid range. D'oh! :-P I gave the assert as an example, but this one snuck up on me rather unexpectedly -- I'd got a

Re: isRandomAccessRange!(const(size_t[])) is false ... ?

2013-09-12 Thread Jonathan M Davis
On Friday, September 13, 2013 00:46:20 Joseph Rushton Wakeling wrote: On 13/09/13 00:15, Jonathan M Davis wrote: Nope. It's correct. Because it's const, you can't call popFront on it or any of the other mutating range operations. So, it's not a valid range. D'oh! :-P I gave the assert as

Re: Safety/purity and assert/enforce error messages

2013-09-12 Thread Meta
On Thursday, 12 September 2013 at 22:04:20 UTC, H. S. Teoh wrote: Currently, this is not possible, because the format string may be a runtime-computed value. For example: ... When you don't have a runtime computed format string, though (which is generally the case for my code, at least),