Re: how to debug memory errors

2016-11-07 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 8 November 2016 at 06:04:59 UTC, thedeemon wrote: On Tuesday, 8 November 2016 at 05:36:22 UTC, Era Scarecrow wrote: Hmmm.. I had the impression that if something was referenced by another object, then it couldn't be collected, Another *live* object, I.e. reachable from globals a

Re: Thread (spawn) for object's method

2016-11-07 Thread Basile B. via Digitalmars-d-learn
On Monday, 7 November 2016 at 16:15:44 UTC, Konstantin Kutsevalov wrote: Is there a way to make new thread for class method? E.g. I have some class and I need to run one of them method in new thread. I found wxamples only with function... import core.thread; class Foo { void method(){

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Basile B. via Digitalmars-d-learn
On Monday, 7 November 2016 at 23:03:32 UTC, Picaud Vincent wrote: I need: 1/ a way to detect compile-time constant vs "dynamic" values /** * Indicates if something is a value known at compile time. * * Params: * V = The value to test. * T = Optional, the expected value type. *

Re: how to debug memory errors

2016-11-07 Thread thedeemon via Digitalmars-d-learn
On Tuesday, 8 November 2016 at 05:36:22 UTC, Era Scarecrow wrote: Hmmm.. I had the impression that if something was referenced by another object, then it couldn't be collected, Another *live* object, i.e. reachable from globals and stack. If you have a big tree and it becomes unreachable (you

Re: how to debug memory errors

2016-11-07 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 8 November 2016 at 03:27:32 UTC, Steven Schveighoffer wrote: Err that makes no sense... If that's the case why have a destructor at all? To free non-GC resources. http://dlang.org/spec/class.html#destructors "Furthermore, the order in which the garbage collector calls destru

Re: how to debug memory errors

2016-11-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/6/16 11:01 PM, thedeemon wrote: On Monday, 7 November 2016 at 02:22:35 UTC, Steven Schveighoffer wrote: OP: it's not legal to destroy or even access GC allocated members in a destructor. The GC may have already destroyed that data. Isn't destroy() fine there? It doesn't call destructors

Re: how to debug memory errors

2016-11-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/6/16 10:57 PM, Era Scarecrow wrote: On Monday, 7 November 2016 at 02:22:35 UTC, Steven Schveighoffer wrote: OP: it's not legal to destroy or even access GC allocated members in a destructor. The GC may have already destroyed that data. I would recommend printing the stack trace when you ge

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Picaud Vincent via Digitalmars-d-learn
On Monday, 7 November 2016 at 23:07:27 UTC, Picaud Vincent wrote: typo... auto capacity = max(0,(size_-1)*stride_+1); To be more correct I have something like: alias IntergralConstant!(int,0) Zero_c; alias IntergralConstant!(int,1) One_c; auto capacity = max(Zero_c,(size_-One_c)*stride_+One_c

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Picaud Vincent via Digitalmars-d-learn
typo... auto capacity = max(0,(size_-1)*stride_+1);

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Picaud Vincent via Digitalmars-d-learn
On Monday, 7 November 2016 at 22:18:56 UTC, Jerry wrote: On Monday, 7 November 2016 at 21:37:50 UTC, Picaud Vincent wrote: static if ( isIntegralConstant!(typeof(required_capacity()) ) { } else { } } Premature post send by error sorry Well something like: static if ( isIntegralCons

Re: Bug after update to 2.072?

2016-11-07 Thread Alex via Digitalmars-d-learn
On Monday, 7 November 2016 at 18:38:14 UTC, ag0aep6g wrote: I've reduced it to this: void main() {} void f() { import core.atomic: atomicOp; shared size_t workUnitIndex; atomicOp!"+="(workUnitIndex, 1); } Which crashes when compiled with -profile. Looks like issue 14511 c

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Jerry via Digitalmars-d-learn
On Monday, 7 November 2016 at 21:37:50 UTC, Picaud Vincent wrote: static if ( isIntegralConstant!(typeof(required_capacity()) ) { } else { } } Premature post send by error sorry Well something like: static if ( isIntegralConstant!(typeof(required_capacity()) ) ElementType[requir

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Picaud Vincent via Digitalmars-d-learn
On Monday, 7 November 2016 at 21:23:37 UTC, Picaud Vincent wrote: On Monday, 7 November 2016 at 18:59:24 UTC, Jerry wrote: On Monday, 7 November 2016 at 18:42:37 UTC, Picaud Vincent wrote: template isIntegralConstant(ANY) { enum bool isIntegralConstant=__traits(identifier,ANY)=="IntegralCo

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Picaud Vincent via Digitalmars-d-learn
On Monday, 7 November 2016 at 18:59:24 UTC, Jerry wrote: On Monday, 7 November 2016 at 18:42:37 UTC, Picaud Vincent wrote: template isIntegralConstant(ANY) { enum bool isIntegralConstant=__traits(identifier,ANY)=="IntegralConstant"; } A bit more elegant way of doing that would be: enum

Re: Are contracts intended for verifying @safety;

2016-11-07 Thread Somebody via Digitalmars-d-learn
On Monday, 7 November 2016 at 21:05:32 UTC, Jonathan M Davis wrote: No. @trusted. The calling function could only be marked @safe if the callee were @trusted, and I was suggesting that it be marked @system so that it's then clear to the caller that they need to pass the correct arguments for

Re: Are contracts intended for verifying @safety;

2016-11-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, November 07, 2016 20:38:00 Somebody via Digitalmars-d-learn wrote: > > So, while I don't know what the official stance is, I'd suggest > > having the function be @trusted and having the documentation > > make it clear what the preconditions are so that the calling > > function can be ma

Re: Are contracts intended for verifying @safety;

2016-11-07 Thread Somebody via Digitalmars-d-learn
On Monday, 7 November 2016 at 20:42:26 UTC, ag0aep6g wrote: Apparently, yes: `version (D_NoBoundsChecks)`. http://dlang.org/spec/version.html#predefined-versions You're probably aware of it, but just to be sure: Note that -noboundscheck (or -boundscheck=off) absolutely breaks safety. Yes I

Re: Are contracts intended for verifying @safety;

2016-11-07 Thread ag0aep6g via Digitalmars-d-learn
On 11/07/2016 09:16 PM, Somebody wrote: Can the version switch be used to detect noboundscheck? Apparently, yes: `version (D_NoBoundsChecks)`. http://dlang.org/spec/version.html#predefined-versions I was thinking that if, it could be used to make an overload of enforce that acts just like in

Re: Are contracts intended for verifying @safety;

2016-11-07 Thread Somebody via Digitalmars-d-learn
On Monday, 7 November 2016 at 20:24:25 UTC, Jonathan M Davis wrote: That's a matter of debate. What you're saying is that the contract for the function requires certain conditions be true for the function arguments, and if they are true, then the function is @safe. And that's legitimate. But

Re: Are contracts intended for verifying @safety;

2016-11-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, November 07, 2016 17:30:09 Somebody via Digitalmars-d-learn wrote: > void moveFrom(int[] a, in int[] b) @trusted in{ > assert(a.length >= b.length); > } body { > memmove(cast(void*)a.ptr, cast(void*)b.ptr, b.length * > int.sizeof); > } > > Is this ok? And if not, how should it

Re: Are contracts intended for verifying @safety;

2016-11-07 Thread Somebody via Digitalmars-d-learn
...and it would, unlike enforce(), of course throw an Error instead of an Exception.

Re: Are contracts intended for verifying @safety;

2016-11-07 Thread Somebody via Digitalmars-d-learn
On Monday, 7 November 2016 at 19:30:01 UTC, ag0aep6g wrote: No, it's not ok. Contracts and (most) asserts are not included in release builds, but the rules for @safe/@trusted don't change. So you'd be breaking @safe in release builds. You can use std.exception.enforce instead, in the body inst

Re: Are contracts intended for verifying @safety;

2016-11-07 Thread ag0aep6g via Digitalmars-d-learn
On 11/07/2016 06:30 PM, Somebody wrote: void moveFrom(int[] a, in int[] b) @trusted in{ assert(a.length >= b.length); } body { memmove(cast(void*)a.ptr, cast(void*)b.ptr, b.length * int.sizeof); } Is this ok? And if not, how should it be done, preferably without changing the condition or

Re: New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Jerry via Digitalmars-d-learn
On Monday, 7 November 2016 at 18:42:37 UTC, Picaud Vincent wrote: template isIntegralConstant(ANY) { enum bool isIntegralConstant=__traits(identifier,ANY)=="IntegralConstant"; } A bit more elegant way of doing that would be: enum isIntegralConstant(T) = is(T : IntegralConstant!U, U...);

New to D and mimicking C++ : how to implement std::integral_constant<>?

2016-11-07 Thread Picaud Vincent via Digitalmars-d-learn
Hi all, I have ~15y of C++ and now I want to test D, because it seems really intersting and "cleaner" than C++. As an exercice I m trying to implement something equivalent to the C++ std::integral_constant in D. In D: struct IntegralConstant(T, T VALUE) { ... } But I do not know how to w

Re: Bug after update to 2.072?

2016-11-07 Thread ag0aep6g via Digitalmars-d-learn
On 11/07/2016 06:18 PM, Alex wrote: On Monday, 7 November 2016 at 17:12:32 UTC, Alex wrote: dmd -c -of./app.o -debug -g -gc -O -profile -w ./app.d -vcolumns dmd -of./app ./app.o -g -gc Knowing this, I tried to find the option which does the difference. This was the profile option. So, if I om

Are contracts intended for verifying @safety;

2016-11-07 Thread Somebody via Digitalmars-d-learn
void moveFrom(int[] a, in int[] b) @trusted in{ assert(a.length >= b.length); } body { memmove(cast(void*)a.ptr, cast(void*)b.ptr, b.length * int.sizeof); } Is this ok? And if not, how should it be done, preferably without changing the condition or memmove call?

Re: Bug after update to 2.072?

2016-11-07 Thread Alex via Digitalmars-d-learn
On Monday, 7 November 2016 at 16:55:29 UTC, Alex wrote: Ok... Another point is, that I'm using dub and trying compiling my app directly by dmd does not yield the error. So, I have to attach the compiling commands, which I see, when tried dub build --force -v dmd -c -of./app.o -debug -g -gc -O

Re: Bug after update to 2.072?

2016-11-07 Thread Alex via Digitalmars-d-learn
On Monday, 7 November 2016 at 17:12:32 UTC, Alex wrote: dmd -c -of./app.o -debug -g -gc -O -profile -w ./app.d -vcolumns dmd -of./app ./app.o -g -gc Knowing this, I tried to find the option which does the difference. This was the profile option. So, if I omit it, the segmentation fault is go

Re: Can't understand the application of delegates in toString() functions

2016-11-07 Thread Heisenberg via Digitalmars-d-learn
On Monday, 7 November 2016 at 16:54:06 UTC, Ali Çehreli wrote: On 11/07/2016 08:40 AM, Heisenberg wrote: [...] Exactly how it happens requires explaining a long chain of function calls. Probably that's why the author did not elaborate further. ;) I've probably omitted some steps here but I

Re: Bug after update to 2.072?

2016-11-07 Thread Alex via Digitalmars-d-learn
Ok, ok. Here, I pasted the code, minimized as far as I could. There are 434 lines of code, sorry. http://pastebin.com/UcZUc79g The main is empty. This is intended. I still have the segmentation fault. Maybe, I have another hint: If I comment all the attributes in the private HeadUnshared!(T)

Re: Can't understand the application of delegates in toString() functions

2016-11-07 Thread Ali Çehreli via Digitalmars-d-learn
On 11/07/2016 08:40 AM, Heisenberg wrote: On Monday, 7 November 2016 at 16:33:30 UTC, Adam D. Ruppe wrote: On Monday, 7 November 2016 at 16:22:17 UTC, Heisenberg wrote: Why? How can a delegate which returns nothing be used as an array which is going to be printed on the screen? You pass the s

Re: Can't understand the application of delegates in toString() functions

2016-11-07 Thread Heisenberg via Digitalmars-d-learn
On Monday, 7 November 2016 at 16:37:50 UTC, Mathias Lang wrote: On Monday, 7 November 2016 at 16:22:17 UTC, Heisenberg wrote: [...] When you ask for a string (or more generally, an array), you put a specific construct on the way the data should be. For starters, the items have to be contiguo

Re: Can't understand the application of delegates in toString() functions

2016-11-07 Thread Heisenberg via Digitalmars-d-learn
On Monday, 7 November 2016 at 16:33:30 UTC, Adam D. Ruppe wrote: On Monday, 7 November 2016 at 16:22:17 UTC, Heisenberg wrote: Why? How can a delegate which returns nothing be used as an array which is going to be printed on the screen? You pass the string to the delegate, which does whatever

Re: Can't understand the application of delegates in toString() functions

2016-11-07 Thread Mathias Lang via Digitalmars-d-learn
On Monday, 7 November 2016 at 16:22:17 UTC, Heisenberg wrote: Hi there. I'm currently following Ali Çehreli's "Programming in D" book and I can't seem to be able to wrap my head around the of delegates in the toString() functions.. http://ddili.org/ders/d.en/lambda.html (Bottom of the page)

Re: Can't understand the application of delegates in toString() functions

2016-11-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 7 November 2016 at 16:22:17 UTC, Heisenberg wrote: Why? How can a delegate which returns nothing be used as an array which is going to be printed on the screen? You pass the string to the delegate, which does whatever with it somewhere else. So you call: `passed_delegate("your str

Can't understand the application of delegates in toString() functions

2016-11-07 Thread Heisenberg via Digitalmars-d-learn
Hi there. I'm currently following Ali Çehreli's "Programming in D" book and I can't seem to be able to wrap my head around the of delegates in the toString() functions.. http://ddili.org/ders/d.en/lambda.html (Bottom of the page) We have defined many toString() functions up to this point in t

Thread (spawn) for object's method

2016-11-07 Thread Konstantin Kutsevalov via Digitalmars-d-learn
Is there a way to make new thread for class method? E.g. I have some class and I need to run one of them method in new thread. I found wxamples only with function...

Re: Floating-point Modulus math.fmod

2016-11-07 Thread Fendercaster via Digitalmars-d-learn
On Monday, 7 November 2016 at 09:21:11 UTC, Ilya Yaroshenko wrote: On Sunday, 6 November 2016 at 21:45:28 UTC, Fendercaster wrote: I'm not quite sure if this is the right forum to ask this question: I've been trying to implement the "floating-point modulus" function from the math library. Equiv

Re: Bug after update to 2.072?

2016-11-07 Thread ag0aep6g via Digitalmars-d-learn
On 11/07/2016 12:21 PM, Alex wrote: On Sunday, 6 November 2016 at 16:07:54 UTC, ag0aep6g wrote: [...] Very weird. Would be great if you could provide a test case. Doesn't need to be minimal. I would if I would know how... :) the problem is, setting up the debugger itself was not a simple task

Re: Bug after update to 2.072?

2016-11-07 Thread Alex via Digitalmars-d-learn
On Sunday, 6 November 2016 at 16:07:54 UTC, ag0aep6g wrote: On 11/06/2016 05:00 PM, Alex wrote: On Sunday, 6 November 2016 at 15:13:56 UTC, Alex wrote: ok... played with the code a little bit. If I remove the @trusted attribute in line 657 inside atomic.d everything works as expected... Any id

Re: Floating-point Modulus math.fmod

2016-11-07 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Sunday, 6 November 2016 at 21:45:28 UTC, Fendercaster wrote: I'm not quite sure if this is the right forum to ask this question: I've been trying to implement the "floating-point modulus" function from the math library. Equivalently that's what I've tried in Python too. Problem is - the resu

Re: Error 42 When Trying to Interop with a C# Libary

2016-11-07 Thread Mike Parker via Digitalmars-d-learn
On Monday, 7 November 2016 at 06:22:16 UTC, Mike Parker wrote: What I would do rather than adding -m32mscoff in additional options Oh, and I forgot. Don't set the lib path in additional options either. In 'Configuration Properties -> Linker', enter the path in the 'Library Search Path' fie

Re: Error 42 When Trying to Interop with a C# Libary

2016-11-07 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 6 November 2016 at 17:57:23 UTC, Sarcross wrote: Building Debug\Resume_Parser.exe... OPTLINK (R) for Win32 Release 8.00.17 "$(VisualDInstallDir)pipedmd.exe" dmd -g -debug -X -Xf"$(IntDir)\$(TargetName).json" -deps="$(OutDir)\$(ProjectName).dep" -of"$(OutDir)\$(ProjectName).exe

Re: how to debug memory errors

2016-11-07 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 7 November 2016 at 02:22:35 UTC, Steven Schveighoffer wrote: OP: it's not legal to destroy or even access GC allocated members in a destructor. The GC may have already destroyed that data. I would recommend printing the stack trace when you get the exception, and figure out where the

Re: how to debug memory errors

2016-11-07 Thread thedeemon via Digitalmars-d-learn
On Monday, 7 November 2016 at 02:22:35 UTC, Steven Schveighoffer wrote: OP: it's not legal to destroy or even access GC allocated members in a destructor. The GC may have already destroyed that data. Isn't destroy() fine there? It doesn't call destructors for already destroyed objects, so I g

how to debug memory errors

2016-11-07 Thread Øivind via Digitalmars-d-learn
Hi, My app occasionally gives me a *** Error in `./hauto-test': double free or corruption (fasttop): 0x7f504c002a60 *** but gives me the following on every termination core.exception.InvalidMemoryOperationError@src/core/exception.d(693): Invalid memory operation How do I go about debug

Re: how to debug memory errors

2016-11-07 Thread Lodovico Giaretta via Digitalmars-d-learn
On Sunday, 6 November 2016 at 21:46:52 UTC, Øivind wrote: Hi, My app occasionally gives me a *** Error in `./hauto-test': double free or corruption (fasttop): 0x7f504c002a60 *** but gives me the following on every termination core.exception.InvalidMemoryOperationError@src/core/exception

Re: how to debug memory errors

2016-11-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/6/16 5:15 PM, Lodovico Giaretta wrote: On Sunday, 6 November 2016 at 21:46:52 UTC, Øivind wrote: Hi, My app occasionally gives me a *** Error in `./hauto-test': double free or corruption (fasttop): 0x7f504c002a60 *** but gives me the following on every termination core.exception.In

Re: system's "kill " signal

2016-11-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/6/16 11:05 AM, Konstantin Kutsevalov wrote: On Saturday, 5 November 2016 at 07:52:53 UTC, Basile B. wrote: On Saturday, 5 November 2016 at 06:17:51 UTC, Basile B. wrote: 3rd option, from my Windows times I remember that people tend to use launchers to handle the real application, i.e a pro

Re: Sockets and using them...

2016-11-07 Thread Charles Hixson via Digitalmars-d-learn
On 11/05/2016 11:02 PM, Era Scarecrow via Digitalmars-d-learn wrote: So I've got a project where I want to create basically a decentralized chat program where every program is a host and a client. When you connect all connections can go through to route the chat to everyone else. So to make

Floating-point Modulus math.fmod

2016-11-07 Thread Fendercaster via Digitalmars-d-learn
I'm not quite sure if this is the right forum to ask this question: I've been trying to implement the "floating-point modulus" function from the math library. Equivalently that's what I've tried in Python too. Problem is - the results are different and not even close. Please have a look at both

Re: Bug after update to 2.072?

2016-11-07 Thread ag0aep6g via Digitalmars-d-learn
On 11/06/2016 05:00 PM, Alex wrote: On Sunday, 6 November 2016 at 15:13:56 UTC, Alex wrote: ok... played with the code a little bit. If I remove the @trusted attribute in line 657 inside atomic.d everything works as expected... Any ideas, why it is so? By the way, replacement with @safe works

Re: system's "kill " signal

2016-11-07 Thread Konstantin Kutsevalov via Digitalmars-d-learn
On Saturday, 5 November 2016 at 06:17:51 UTC, Basile B. wrote: On Saturday, 5 November 2016 at 02:24:00 UTC, Konstantin Kutsevalov wrote: Hi, is there a way to catch system signal of "kill" command or "shutdown"? During the Run-time: You can register a signal callback,

Re: Error 42 When Trying to Interop with a C# Libary

2016-11-07 Thread Sarcross via Digitalmars-d-learn
On Sunday, 6 November 2016 at 02:37:23 UTC, Mike Parker wrote: On Saturday, 5 November 2016 at 22:06:21 UTC, Sarcross wrote: LINK : fatal error LNK1104: cannot open file '+C:\Users\antzy_000\Documents\Programming\D\Resume-Parser\src\Parser2.lib' --- errorlevel 1104 dmd failed with exit code 11

Re: system's "kill " signal

2016-11-07 Thread Konstantin Kutsevalov via Digitalmars-d-learn
On Sunday, 6 November 2016 at 16:05:44 UTC, Konstantin Kutsevalov wrote: On Saturday, 5 November 2016 at 07:52:53 UTC, Basile B. wrote: On Saturday, 5 November 2016 at 06:17:51 UTC, Basile B. wrote: 3rd option, from my Windows times I remember that people tend to use launchers to handle the rea

Re: system's "kill " signal

2016-11-07 Thread Konstantin Kutsevalov via Digitalmars-d-learn
On Saturday, 5 November 2016 at 07:52:53 UTC, Basile B. wrote: On Saturday, 5 November 2016 at 06:17:51 UTC, Basile B. wrote: 3rd option, from my Windows times I remember that people tend to use launchers to handle the real application, i.e a process that launches the main process. Then the lau

Re: Bug after update to 2.072?

2016-11-07 Thread Alex via Digitalmars-d-learn
On Sunday, 6 November 2016 at 15:13:56 UTC, Alex wrote: ok... played with the code a little bit. If I remove the @trusted attribute in line 657 inside atomic.d everything works as expected... Any ideas, why it is so? By the way, replacement with @safe works too...

Re: Bug after update to 2.072?

2016-11-07 Thread Alex via Digitalmars-d-learn
ok... played with the code a little bit. If I remove the @trusted attribute in line 657 inside atomic.d everything works as expected... Any ideas, why it is so?