[Issue 4906] Dereferencing null error in a single expression

2022-12-17 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=4906 Iain Buclaw changed: What|Removed |Added Priority|P2 |P4 --

[Issue 4906] Dereferencing null error in a single expression

2012-12-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=4906 Andrej Mitrovic andrej.mitrov...@gmail.com changed: What|Removed |Added CC|

Re: dereferencing null

2012-03-09 Thread Timon Gehr
On 03/09/2012 01:43 AM, bearophile wrote: Adam D. Ruppe: D rox the web (and has for a while). (Oh, you are starting to copy Andrei talk style now :-) The birth of community words, idioms and sub-languages is a very common thing, sociology studies such things a lot). But there's always

Re: dereferencing null

2012-03-09 Thread bearophile
Timon Gehr: Comparing signed/unsigned is perfectly reasonable. Right, but only if the numbers don't get implicit reinterpretations to other intervals, as C/C++/D do. Bye, bearophile

Re: dereferencing null

2012-03-08 Thread Don Clugston
On 06/03/12 17:05, Sean Kelly wrote: On Mar 6, 2012, at 3:14 AM, Don Clugstond...@nospam.com wrote: Responding to traps is one of the very few examples I know of, where Windows got it completely right, and *nix got it absolutely completely wrong. Most notably, the hardware is *designed* for

Re: dereferencing null

2012-03-08 Thread Steven Schveighoffer
On Thu, 08 Mar 2012 03:58:22 -0500, Don Clugston d...@nospam.com wrote: On 06/03/12 17:05, Sean Kelly wrote: On Mar 6, 2012, at 3:14 AM, Don Clugstond...@nospam.com wrote: Responding to traps is one of the very few examples I know of, where Windows got it completely right, and *nix got it

Re: dereferencing null

2012-03-08 Thread Andrej Mitrovic
I think what Chad is looking for is a BlackHole/WhiteHole equivalent which doesn't need abstract functions but which figures out all the methods of a class at compile time and creates a subclass that throws/does nothing on method invocation. An 'alias this' field would be used that is

Re: dereferencing null

2012-03-08 Thread H. S. Teoh
On Thu, Mar 08, 2012 at 02:57:00PM +0100, Andrej Mitrovic wrote: [...] I don't know why we don't have __traits(allFunction). We have 'getVirtualFunctions' but it requires a function name, but using allMembers to filter out function names is damn difficult if you ask me. foreach (name;

Re: dereferencing null

2012-03-08 Thread Sean Kelly
On Mar 8, 2012, at 12:58 AM, Don Clugston d...@nospam.com wrote: On 06/03/12 17:05, Sean Kelly wrote: On Mar 6, 2012, at 3:14 AM, Don Clugstond...@nospam.com wrote: Responding to traps is one of the very few examples I know of, where Windows got it completely right, and *nix got it

Re: dereferencing null - what about something like an check-scope?

2012-03-08 Thread dennis luehring
could it be a good idea to add something like an check-scope for modules,functions,etc. for typical fails to easy the detection? wild-idea-and-syntax-list: @CheckForNull @CheckForNaN @CheckForUnnormalFloat ... x.d modul x @CheckForNull // will introduce NullChecks for the complete

Re: dereferencing null

2012-03-08 Thread Andrej Mitrovic
On 3/8/12, H. S. Teoh hst...@quickfur.ath.cx wrote: foreach (name; __traits(allMembers, typeof(obj))) { static if (__traits(compiles, __traits(getMember, obj, name))) { alias typeof(__traits(getMember, obj,

Re: dereferencing null

2012-03-08 Thread Andrej Mitrovic
Sorry, mixin(getOverloads!(UnreliableResource)()); should be: mixin(getOverloads!(Base)());

Re: dereferencing null

2012-03-08 Thread Andrej Mitrovic
Plus I left over some code. Anyway the point is that was just a hardcoded example of something that's doable, you'd probably want it to be much more sophisticated before it goes into a library.

Re: dereferencing null - what about something like an check-scope?

2012-03-08 Thread David Eagen
I like the way Scala handles this with the Option class. None indicates no value which is equivalent to your null sentinal value but it is a value itself so it is always safe to use. Combined with pattern matching and the orElse methods makes it very easy to use one variable that both stores

Re: dereferencing null

2012-03-08 Thread H. S. Teoh
On Thu, Mar 08, 2012 at 05:49:20PM +0100, Andrej Mitrovic wrote: On 3/8/12, H. S. Teoh hst...@quickfur.ath.cx wrote: foreach (name; __traits(allMembers, typeof(obj))) { static if (__traits(compiles, __traits(getMember, obj, name))) {

Re: dereferencing null

2012-03-08 Thread Walter Bright
On 3/8/2012 12:58 AM, Don Clugston wrote: The documentation is terrible, but it's really a beautiful design. I agree, it really is very flexible and useful. The downside is that it leaves significant overhead in functions that are exception-aware, even if they never throw or unwind. And

Re: dereferencing null

2012-03-08 Thread David Nadlinger
On Thursday, 8 March 2012 at 22:20:10 UTC, Walter Bright wrote: I agree, it really is very flexible and useful. The downside is that it leaves significant overhead in functions that are exception-aware, even if they never throw or unwind. This problem is avoided by the switch to the

Re: dereferencing null

2012-03-08 Thread bearophile
Regarding people that desire a compiler switch to add run-time tests inside the binary that guard against null seg-faults to turn turn them into errors with a stack trace: I have recently shown the D language to a friend. She answered me that most code she writes is for the Web and it's not

Re: dereferencing null

2012-03-08 Thread Adam D. Ruppe
On Friday, 9 March 2012 at 00:19:38 UTC, bearophile wrote: So maybe for her D language is not needed, other more flexible languages are better for her. D rox the web (and has for a while).

Re: dereferencing null

2012-03-08 Thread bearophile
Adam D. Ruppe: D rox the web (and has for a while). (Oh, you are starting to copy Andrei talk style now :-) The birth of community words, idioms and sub-languages is a very common thing, sociology studies such things a lot). But there's always some space for improvements :-) In D.learn

Re: dereferencing null

2012-03-08 Thread Chad J
On 03/08/2012 10:40 AM, H. S. Teoh wrote: On Thu, Mar 08, 2012 at 02:57:00PM +0100, Andrej Mitrovic wrote: I think what Chad is looking for is a BlackHole/WhiteHole equivalent which doesn't need abstract functions but which figures out all the methods of a class at compile time and creates a

Re: dereferencing null

2012-03-07 Thread Timon Gehr
On 03/07/2012 02:40 AM, Chad J wrote: On 03/06/2012 12:19 PM, Timon Gehr wrote: ... For example: http://pm.inf.ethz.ch/publications/getpdf.php/bibname/Own/id/SummersMuellerTR11.pdf CTFE and static constructors solve that issue for static data. I can't seem to download the PDF... it always

Re: dereferencing null

2012-03-07 Thread Timon Gehr
On 03/07/2012 02:40 AM, Chad J wrote: But to initialize non-null fields, I suspect we would need to be able to do stuff like this: class Foo { int dummy; } class Bar { Foo foo = new Foo(); this() { foo.dummy = 5; } } Which would be lowered by the compiler into this: class Bar { // Assume

Re: dereferencing null

2012-03-07 Thread Steven Schveighoffer
On Mon, 05 Mar 2012 22:51:28 -0500, Jonathan M Davis jmdavisp...@gmx.com wrote: On Monday, March 05, 2012 21:04:20 Steven Schveighoffer wrote: On Mon, 05 Mar 2012 20:17:32 -0500, Michel Fortin michel.for...@michelf.com wrote: That said, throwing an exception might not be a better response

Re: dereferencing null

2012-03-07 Thread Steven Schveighoffer
On Tue, 06 Mar 2012 23:07:24 -0500, Walter Bright newshou...@digitalmars.com wrote: On 3/6/2012 8:05 PM, Walter Bright wrote: What I'm talking about is the idea that one can recover from seg faults resulting from program bugs. I've written about this before, but I want to emphasize that

Re: dereferencing null

2012-03-07 Thread Steven Schveighoffer
On Mon, 05 Mar 2012 23:58:48 -0500, Chad J chadjoan@__spam.is.bad__gmail.com wrote: On 03/05/2012 11:27 PM, Jonathan M Davis wrote: On Tuesday, March 06, 2012 05:11:30 Martin Nowak wrote: There are two independent discussions being conflated here. One about getting more information out of

Re: dereferencing null

2012-03-07 Thread Steven Schveighoffer
On Wed, 07 Mar 2012 09:22:27 -0500, Chad J chadjoan@__spam.is.bad__gmail.com wrote: On 03/07/2012 07:57 AM, Steven Schveighoffer wrote: On Mon, 05 Mar 2012 23:58:48 -0500, Chad J chadjoan@__spam.is.bad__gmail.com wrote: Why is it fatal? A segmentation fault indicates that a program

Re: dereferencing null

2012-03-07 Thread Chad J
On Wednesday, 7 March 2012 at 14:23:18 UTC, Chad J wrote: On 03/07/2012 07:57 AM, Steven Schveighoffer wrote: On Mon, 05 Mar 2012 23:58:48 -0500, Chad J chadjoan@__spam.is.bad__gmail.com wrote: Why is it fatal? A segmentation fault indicates that a program tried to access memory that is

Re: dereferencing null

2012-03-07 Thread Chad J
On Wednesday, 7 March 2012 at 14:23:18 UTC, Chad J wrote: On 03/07/2012 07:57 AM, Steven Schveighoffer wrote: On Mon, 05 Mar 2012 23:58:48 -0500, Chad J chadjoan@__spam.is.bad__gmail.com wrote: Why is it fatal? A segmentation fault indicates that a program tried to access memory that is

Re: dereferencing null

2012-03-07 Thread Steven Schveighoffer
On Wed, 07 Mar 2012 10:10:32 -0500, Chad J chadjoan@__spam.is.bad__gmail.com wrote: On Wednesday, 7 March 2012 at 14:23:18 UTC, Chad J wrote: On 03/07/2012 07:57 AM, Steven Schveighoffer wrote: On Mon, 05 Mar 2012 23:58:48 -0500, Chad J chadjoan@__spam.is.bad__gmail.com wrote: Why is it

Re: dereferencing null

2012-03-07 Thread H. S. Teoh
On Wed, Mar 07, 2012 at 09:22:27AM -0500, Chad J wrote: On 03/07/2012 07:57 AM, Steven Schveighoffer wrote: [...] However, there are several causes of seg faults: 1. You forgot to initialize a variable. 2. Your memory has been corrupted, and some corrupted pointer now points into no-mem

Re: dereferencing null

2012-03-07 Thread Jonathan M Davis
On Wednesday, March 07, 2012 07:55:35 H. S. Teoh wrote: It's not that the null pointer itself corrupts memory. It's that the null pointer is a sign that something may have corrupted memory *before* you got to that point. The point is, it's impossible to tell whether the null pointer was

Re: dereferencing null

2012-03-07 Thread Chad J
On 03/07/2012 04:41 AM, Timon Gehr wrote: On 03/07/2012 02:40 AM, Chad J wrote: But to initialize non-null fields, I suspect we would need to be able to do stuff like this: class Foo { int dummy; } class Bar { Foo foo = new Foo(); this() { foo.dummy = 5; } } Which would be lowered by the

Re: dereferencing null

2012-03-07 Thread Timon Gehr
On 03/08/2012 01:24 AM, Chad J wrote: On 03/07/2012 04:41 AM, Timon Gehr wrote: On 03/07/2012 02:40 AM, Chad J wrote: But to initialize non-null fields, I suspect we would need to be able to do stuff like this: class Foo { int dummy; } class Bar { Foo foo = new Foo(); this() { foo.dummy =

Re: dereferencing null

2012-03-07 Thread Chad J
On 03/07/2012 10:21 AM, Steven Schveighoffer wrote: On Wed, 07 Mar 2012 10:10:32 -0500, Chad J chadjoan@__spam.is.bad__gmail.com wrote: On Wednesday, 7 March 2012 at 14:23:18 UTC, Chad J wrote: I spoke too soon! We missed one: 1. You forgot to initialize a variable. 2. Your memory has been

Re: dereferencing null

2012-03-07 Thread Chad J
On 03/07/2012 02:09 PM, Jonathan M Davis wrote: On Wednesday, March 07, 2012 07:55:35 H. S. Teoh wrote: It's not that the null pointer itself corrupts memory. It's that the null pointer is a sign that something may have corrupted memory *before* you got to that point. The point is, it's

Re: dereferencing null

2012-03-07 Thread Chad J
On 03/07/2012 07:39 PM, Timon Gehr wrote: On 03/08/2012 01:24 AM, Chad J wrote: Though, more to the point: I would probably forbid Foo foo = new Foo(this);. The design that leads to this is creating circular dependencies, which is usually bad to begin with. Circular object references are

Re: dereferencing null

2012-03-07 Thread Jonathan M Davis
On Wednesday, March 07, 2012 20:44:59 Chad J wrote: On 03/07/2012 10:21 AM, Steven Schveighoffer wrote: You can use sentinels other than null. -Steve Example? Create an instance of the class which is immutable and represents an invalid value. You could check whether something is that

Re: dereferencing null

2012-03-07 Thread Chad J
On 03/07/2012 10:08 PM, Jonathan M Davis wrote: On Wednesday, March 07, 2012 20:44:59 Chad J wrote: On 03/07/2012 10:21 AM, Steven Schveighoffer wrote: You can use sentinels other than null. -Steve Example? Create an instance of the class which is immutable and represents an invalid

Re: dereferencing null

2012-03-07 Thread Jonathan M Davis
On Wednesday, March 07, 2012 22:36:50 Chad J wrote: On 03/07/2012 10:08 PM, Jonathan M Davis wrote: On Wednesday, March 07, 2012 20:44:59 Chad J wrote: On 03/07/2012 10:21 AM, Steven Schveighoffer wrote: You can use sentinels other than null. -Steve Example? Create an

Re: dereferencing null

2012-03-07 Thread Chad J
On 03/07/2012 10:40 PM, Jonathan M Davis wrote: On Wednesday, March 07, 2012 22:36:50 Chad J wrote: On 03/07/2012 10:08 PM, Jonathan M Davis wrote: On Wednesday, March 07, 2012 20:44:59 Chad J wrote: On 03/07/2012 10:21 AM, Steven Schveighoffer wrote: You can use sentinels other than null.

Re: dereferencing null

2012-03-07 Thread Jonathan M Davis
On Wednesday, March 07, 2012 22:58:44 Chad J wrote: On 03/07/2012 10:40 PM, Jonathan M Davis wrote: On Wednesday, March 07, 2012 22:36:50 Chad J wrote: On 03/07/2012 10:08 PM, Jonathan M Davis wrote: On Wednesday, March 07, 2012 20:44:59 Chad J wrote: On 03/07/2012 10:21 AM, Steven

Re: dereferencing null

2012-03-07 Thread Chad J
On 03/07/2012 11:17 PM, Jonathan M Davis wrote: On Wednesday, March 07, 2012 22:58:44 Chad J wrote: On 03/07/2012 10:40 PM, Jonathan M Davis wrote: On Wednesday, March 07, 2012 22:36:50 Chad J wrote: On 03/07/2012 10:08 PM, Jonathan M Davis wrote: On Wednesday, March 07, 2012 20:44:59 Chad J

Re: dereferencing null

2012-03-06 Thread Walter Bright
On 3/5/2012 11:51 AM, Jacob Carlborg wrote: Yeah, C and C++ might not do what's suggested but basically all other languages do it. People turn to C and C++ for systems work and high performance.

Re: dereferencing null

2012-03-06 Thread James Miller
If you have a possible null, then check for it *yourself* sometimes you know its null, sometimes you don't have any control. However, the compiler has no way of knowing that. Its basically an all-or-nothing thing with the compiler. However, the compiler can (and I think does) warn of possible

Re: dereferencing null

2012-03-06 Thread Walter Bright
On 3/5/2012 12:05 PM, Nick Sabalausky wrote: Walter Brightnewshou...@digitalmars.com wrote in message news:jiunst$qrm$1...@digitalmars.com... 3. Intercepting and recovering from seg faults, div by 0, etc., all sounds great on paper. In practice, it is almost always wrong. The only exception

Re: dereferencing null

2012-03-06 Thread Timon Gehr
On 03/05/2012 05:39 AM, Adam D. Ruppe wrote: On Monday, 5 March 2012 at 03:24:32 UTC, Chad J wrote: News to me. I've had bad runs with that back in the day, but maybe things have improved a bit. Strangely, I've never had a problem with gdb and D, as far back as 2007. (at least for the basic

Re: dereferencing null

2012-03-06 Thread Jacob Carlborg
On 2012-03-06 10:11, James Miller wrote: If you have a possible null, then check for it *yourself* sometimes you know its null, sometimes you don't have any control. However, the compiler has no way of knowing that. Its basically an all-or-nothing thing with the compiler. If I know there is a

Re: dereferencing null

2012-03-06 Thread Don Clugston
On 04/03/12 04:34, Walter Bright wrote: On 3/3/2012 6:53 PM, Sandeep Datta wrote: It's been there for 10 years, and turns out to be a solution looking for a problem. I beg to differ, the ability to catch and respond to such asynchronous exceptions is vital to the stable operation of long

Re: dereferencing null

2012-03-06 Thread bearophile
James Miller: If you have a possible null, then check for it *yourself* sometimes you know its null, sometimes you don't have any control. However, the compiler has no way of knowing that. Its basically an all-or-nothing thing with the compiler. In a normal program there are many situations

Re: dereferencing null

2012-03-06 Thread Chad J
On 03/06/2012 02:54 AM, Jacob Carlborg wrote: On 2012-03-06 08:53, Jacob Carlborg wrote: On 2012-03-06 03:04, Steven Schveighoffer wrote: Certainly for Mac OS X, it should do the most informative appropriate thing for the OS it's running on. Does the above happen for D programs currently on

Re: dereferencing null

2012-03-06 Thread Chad J
On 03/06/2012 03:27 AM, Walter Bright wrote: On 3/5/2012 11:51 AM, Jacob Carlborg wrote: Yeah, C and C++ might not do what's suggested but basically all other languages do it. People turn to C and C++ for systems work and high performance. Optional. Flags. If there is a truly unavoidable

Re: dereferencing null

2012-03-06 Thread bearophile
Sandeep Datta: I am just going to leave this here... *Fast Bounds Checking Using Debug Register* http://www.ecsl.cs.sunysb.edu/tr/TR225.pdf Is this idea usable in DMD to speed up D code compiled in non-release mode? Bye, bearophile

Re: dereferencing null

2012-03-06 Thread Michel Fortin
On 2012-03-06 10:53:19 +, Jacob Carlborg d...@me.com said: On Mac OS X the runtime would only need to catch any exception (as it already does) and print the stack trace. But also re-throw the exception to let the OS handle the logging of the exception (at least I hope that will work).

Re: dereferencing null

2012-03-06 Thread Jacob Carlborg
On 2012-03-06 13:48, Chad J wrote: On 03/06/2012 02:54 AM, Jacob Carlborg wrote: On 2012-03-06 08:53, Jacob Carlborg wrote: On 2012-03-06 03:04, Steven Schveighoffer wrote: Certainly for Mac OS X, it should do the most informative appropriate thing for the OS it's running on. Does the above

Re: dereferencing null

2012-03-06 Thread foobar
On Tuesday, 6 March 2012 at 09:11:07 UTC, James Miller wrote: If you have a possible null, then check for it *yourself* sometimes you know its null, sometimes you don't have any control. However, the compiler has no way of knowing that. Its basically an all-or-nothing thing with the compiler.

Re: dereferencing null

2012-03-06 Thread foobar
On Tuesday, 6 March 2012 at 10:19:19 UTC, Timon Gehr wrote: This is quite close, but real support for non-nullable types means that they are the default and checked statically, ideally using data flow analysis. I agree that non-nullable types should be made the default and statically

Re: dereferencing null

2012-03-06 Thread Sean Kelly
On Mar 6, 2012, at 3:14 AM, Don Clugston d...@nospam.com wrote: Responding to traps is one of the very few examples I know of, where Windows got it completely right, and *nix got it absolutely completely wrong. Most notably, the hardware is *designed* for floating point traps to be fully

Re: dereferencing null

2012-03-06 Thread Martin Nowak
On Tue, 06 Mar 2012 14:22:09 +0100, bearophile bearophileh...@lycos.com wrote: Sandeep Datta: I am just going to leave this here... *Fast Bounds Checking Using Debug Register* http://www.ecsl.cs.sunysb.edu/tr/TR225.pdf Is this idea usable in DMD to speed up D code compiled in

Re: dereferencing null

2012-03-06 Thread Martin Nowak
On Tue, 06 Mar 2012 12:14:56 +0100, Don Clugston d...@nospam.com wrote: On 04/03/12 04:34, Walter Bright wrote: On 3/3/2012 6:53 PM, Sandeep Datta wrote: It's been there for 10 years, and turns out to be a solution looking for a problem. I beg to differ, the ability to catch and respond to

Re: dereferencing null

2012-03-06 Thread Christopher Bergqvist
On Tuesday, 6 March 2012 at 15:46:54 UTC, foobar wrote: On Tuesday, 6 March 2012 at 10:19:19 UTC, Timon Gehr wrote: This is quite close, but real support for non-nullable types means that they are the default and checked statically, ideally using data flow analysis. I agree that

Re: dereferencing null

2012-03-06 Thread Mantis
06.03.2012 8:04, Chad J пишет: On 03/06/2012 12:07 AM, Jonathan M Davis wrote: If you dereference a null pointer, there is a serious bug in your program. Continuing is unwise. And if it actually goes so far as to be a segfault (since the hardware caught it rather than the program), it is

Re: dereferencing null

2012-03-06 Thread Chad J
On 03/06/2012 03:39 PM, Mantis wrote: 06.03.2012 8:04, Chad J пишет: On 03/06/2012 12:07 AM, Jonathan M Davis wrote: If you dereference a null pointer, there is a serious bug in your program. Continuing is unwise. And if it actually goes so far as to be a segfault (since the hardware caught

Re: dereferencing null

2012-03-06 Thread Chad J
On 03/06/2012 12:19 PM, Timon Gehr wrote: On 03/06/2012 04:46 PM, foobar wrote: On Tuesday, 6 March 2012 at 10:19:19 UTC, Timon Gehr wrote: This is quite close, but real support for non-nullable types means that they are the default and checked statically, ideally using data flow analysis.

Re: dereferencing null

2012-03-06 Thread Walter Bright
On 3/6/2012 5:29 PM, Chad J wrote: But what do you say to the notion of isolation? someFunc is isolated from riskyShenanigans becuase it /knows/ what state is touched by riskyShenanigans. If riskyShenanigans does something strange and unexpected, and yes, it does have a bug in it, then I feel

Re: dereferencing null

2012-03-06 Thread H. S. Teoh
On Tue, Mar 06, 2012 at 08:29:35PM -0500, Chad J wrote: [...] But what do you say to the notion of isolation? someFunc is isolated from riskyShenanigans becuase it /knows/ what state is touched by riskyShenanigans. If riskyShenanigans does something strange and unexpected, and yes, it does

Re: dereferencing null

2012-03-06 Thread bearophile
Chad J: I can't seem to download the PDF... it always gives me just two bytes. But to initialize non-null fields, I suspect we would need to be able to do stuff like this: There are some links here: http://d.puremagic.com/issues/show_bug.cgi?id=4571 Bye, bearophile

Re: dereferencing null

2012-03-06 Thread Sean Kelly
On Mar 6, 2012, at 6:29 PM, Walter Bright newshou...@digitalmars.com wrote: On 3/6/2012 5:29 PM, Chad J wrote: But what do you say to the notion of isolation? someFunc is isolated from riskyShenanigans becuase it /knows/ what state is touched by riskyShenanigans. If riskyShenanigans does

Re: dereferencing null

2012-03-06 Thread Walter Bright
On 3/6/2012 8:05 PM, Walter Bright wrote: What I'm talking about is the idea that one can recover from seg faults resulting from program bugs. I've written about this before, but I want to emphasize that attempting to recover from program BUGS is the absolutely WRONG way to go about writing

Re: dereferencing null

2012-03-06 Thread Walter Bright
On 3/6/2012 7:08 PM, Sean Kelly wrote: Minor point, but some apps are designed such that segfaults are intended. I worked on a DB that dynamically mapped memory in the segfault handler and then resumed execution. Since D is a systems languages, very few assumptions can be made about error

Re: dereferencing null

2012-03-06 Thread Sean Kelly
Oh alright. Then we're in complete agreement. On Mar 6, 2012, at 8:05 PM, Walter Bright newshou...@digitalmars.com wrote: On 3/6/2012 7:08 PM, Sean Kelly wrote: Minor point, but some apps are designed such that segfaults are intended. I worked on a DB that dynamically mapped memory in the

Re: dereferencing null

2012-03-05 Thread Jacob Carlborg
On 2012-03-05 07:25, Walter Bright wrote: On 3/4/2012 6:31 PM, Chad J wrote: class Bar { int foo; } void main() { Bar bar; try { bar.foo = 5; } catch ( Exception e ) { writefln(%s,e); } } DMD 2.057 on Gentoo Linux, compiled with -g -debug. It prints this: Segmentation fault Very frustrating!

Re: dereferencing null

2012-03-05 Thread David Nadlinger
On Monday, 5 March 2012 at 09:09:30 UTC, Jacob Carlborg wrote: On 2012-03-05 07:25, Walter Bright wrote: […] run (run your program) bt (print a backtrace) quit (exit gdb) […] Is demangling supposed to work on Mac OS X? As the D demangling support was added in GDB 7.something, unfortunately

Re: dereferencing null

2012-03-05 Thread Jesse Phillips
On Monday, 5 March 2012 at 00:33:18 UTC, Nathan M. Swan wrote: On Saturday, 3 March 2012 at 02:51:41 UTC, Walter Bright wrote: Adding in software checks for null pointers will dramatically slow things down. What about the debug/release difference? Isn't the point of debug mode to allow

Re: dereferencing null

2012-03-05 Thread Walter Bright
On 3/4/2012 11:50 PM, Chad J wrote: Problems: - I have to rerun the program in a debugger to see the stack trace. This is a slow workflow. It's a big improvement if the segfault is hard to find, but only a small improvement if the segfault is easy to find. Very bad if I'm prototyping

Re: dereferencing null

2012-03-05 Thread Sandeep Datta
No hardware support for them, so no choice. I am just going to leave this here... *Fast Bounds Checking Using Debug Register* http://www.ecsl.cs.sunysb.edu/tr/TR225.pdf

Re: dereferencing null

2012-03-05 Thread deadalnix
Le 03/03/2012 21:10, Timon Gehr a écrit : On 03/03/2012 09:00 PM, deadalnix wrote: Le 03/03/2012 20:06, Walter Bright a écrit : On 3/3/2012 2:13 AM, bearophile wrote: Walter: Adding in software checks for null pointers will dramatically slow things down. Define this use of dramatically in

Re: dereferencing null

2012-03-05 Thread Jacob Carlborg
On 2012-03-05 11:38, Walter Bright wrote: On 3/4/2012 11:50 PM, Chad J wrote: I'm pretty sure other languages like C# and Java get this right. Haven't used those two in a while though. Haxe... totally got this right. Also Actionscript 3 by proxy. Hell, even Synergy/DE, the DIBOL (!!) derivative

Re: dereferencing null

2012-03-05 Thread Martin Nowak
On Mon, 05 Mar 2012 10:43:22 +0100, David Nadlinger s...@klickverbot.at wrote: On Monday, 5 March 2012 at 09:09:30 UTC, Jacob Carlborg wrote: On 2012-03-05 07:25, Walter Bright wrote: […] run (run your program) bt (print a backtrace) quit (exit gdb) […] Is demangling supposed to work on

Re: dereferencing null

2012-03-05 Thread Andrej Mitrovic
Personally I'd love to get more info about out-of-bounds errors. E.g. for arrays, which index the code attempted to access, and for hashes which key. Sure it's easy to use an enforce, but I'd rather have that inserted in debug builds with bounds checking anyway. For example: void main() {

Re: dereferencing null

2012-03-05 Thread Steven Schveighoffer
On Fri, 02 Mar 2012 10:19:13 -0500, deadalnix deadal...@gmail.com wrote: Le 02/03/2012 15:37, Jacob Carlborg a écrit : Isn't it quite unsafe to throw an exception in a signal ? One does not need to throw an exception. Just print a stack trace. I've advocated for this multiple times. I

Re: dereferencing null

2012-03-05 Thread H. S. Teoh
On Mon, Mar 05, 2012 at 02:50:25AM -0500, Chad J wrote: [...] Problems: - I have to rerun the program in a debugger to see the stack trace. Nope. You can run it on a dumped core. [...] - It only gives one line number. I imagine there's a way to get it to spill the rest? At least it's the

Re: dereferencing null

2012-03-05 Thread H. S. Teoh
On Mon, Mar 05, 2012 at 02:30:14PM +0100, Andrej Mitrovic wrote: Personally I'd love to get more info about out-of-bounds errors. E.g. for arrays, which index the code attempted to access, and for hashes which key. Personally, I'd love to see D's added string capabilities put to good use in

Re: dereferencing null

2012-03-05 Thread Adam D. Ruppe
On Monday, 5 March 2012 at 06:19:53 UTC, Chad J wrote: That's cool. Maybe someone should stick it in Phobos? I just made a patch and sent it up. It'll have to be reviewed by the others, but I expect we'll have something in std.typecons for the next release. I also didn't know about

Re: dereferencing null

2012-03-05 Thread Andrej Mitrovic
On 3/5/12, H. S. Teoh hst...@quickfur.ath.cx wrote: snip Yep, agreed with everything you've said. Also, I find your message signatures amusing. :P

Re: dereferencing null

2012-03-05 Thread deadalnix
Le 05/03/2012 15:26, Steven Schveighoffer a écrit : On Fri, 02 Mar 2012 10:19:13 -0500, deadalnix deadal...@gmail.com wrote: Le 02/03/2012 15:37, Jacob Carlborg a écrit : Isn't it quite unsafe to throw an exception in a signal ? One does not need to throw an exception. Just print a stack

Re: dereferencing null

2012-03-05 Thread Walter Bright
On 3/5/2012 4:27 AM, Jacob Carlborg wrote: On 2012-03-05 11:38, Walter Bright wrote: Notably, C and C++ do not do what you suggest. Just because C and C++ do something in a certain way doesn't make it a valid reason to do the same thing in D. I think this is an argument we need to stop using

Re: dereferencing null

2012-03-05 Thread Walter Bright
On 3/5/2012 8:07 AM, H. S. Teoh wrote: A file not found exception should tell you what the offending filename is. std.file.read(adsfasdf) gives: std.file.FileException@std\file.d(305): adsfasdf: The system cannot find the file specified.

Re: dereferencing null

2012-03-05 Thread H. S. Teoh
On Mon, Mar 05, 2012 at 11:06:40AM -0800, Walter Bright wrote: On 3/5/2012 8:07 AM, H. S. Teoh wrote: A file not found exception should tell you what the offending filename is. std.file.read(adsfasdf) gives: std.file.FileException@std\file.d(305): adsfasdf: The system cannot find the file

Re: dereferencing null

2012-03-05 Thread H. S. Teoh
On Mon, Mar 05, 2012 at 06:12:43PM +0100, Andrej Mitrovic wrote: [...] Also, I find your message signatures amusing. :P I have a file of amusing quotes that I collected over the years from various sources (including some not-so-funny ones I made up myself), and a 1-line perl script hooked to my

Re: dereferencing null

2012-03-05 Thread Nick Sabalausky
Walter Bright newshou...@digitalmars.com wrote in message news:jj32l2$1dk$1...@digitalmars.com... On 3/5/2012 4:27 AM, Jacob Carlborg wrote: On 2012-03-05 11:38, Walter Bright wrote: Notably, C and C++ do not do what you suggest. Just because C and C++ do something in a certain way doesn't

Re: dereferencing null

2012-03-05 Thread Nick Sabalausky
Walter Bright newshou...@digitalmars.com wrote in message news:jj252v$15vf$1...@digitalmars.com... On 3/4/2012 11:50 PM, Chad J wrote: Problems: - I have to rerun the program in a debugger to see the stack trace. This is a slow workflow. It's a big improvement if the segfault is hard to

Re: dereferencing null

2012-03-05 Thread Jacob Carlborg
On 2012-03-05 20:02, Walter Bright wrote: On 3/5/2012 4:27 AM, Jacob Carlborg wrote: On 2012-03-05 11:38, Walter Bright wrote: Notably, C and C++ do not do what you suggest. Just because C and C++ do something in a certain way doesn't make it a valid reason to do the same thing in D. I

Re: dereferencing null

2012-03-05 Thread Nick Sabalausky
Adam D. Ruppe destructiona...@gmail.com wrote in message news:ewuffoakafwmuybbz...@forum.dlang.org... On Monday, 5 March 2012 at 03:24:32 UTC, Chad J wrote: It's that I simply cannot expect users to run my code in a debugger. :) I'm lucky if I can get more from my users than the site doesn't

Re: dereferencing null

2012-03-05 Thread Nick Sabalausky
Walter Bright newshou...@digitalmars.com wrote in message news:jiunst$qrm$1...@digitalmars.com... 3. Intercepting and recovering from seg faults, div by 0, etc., all sounds great on paper. In practice, it is almost always wrong. The only exception (!) to the rule is when sandboxing a plugin

Re: dereferencing null

2012-03-05 Thread Steven Schveighoffer
On Mon, 05 Mar 2012 13:29:09 -0500, deadalnix deadal...@gmail.com wrote: Le 05/03/2012 15:26, Steven Schveighoffer a écrit : On Fri, 02 Mar 2012 10:19:13 -0500, deadalnix deadal...@gmail.com wrote: Le 02/03/2012 15:37, Jacob Carlborg a écrit : Isn't it quite unsafe to throw an exception

Re: dereferencing null

2012-03-05 Thread Jérôme M. Berger
Steven Schveighoffer wrote: On Mon, 05 Mar 2012 13:29:09 -0500, deadalnix deadal...@gmail.com wrote: Le 05/03/2012 15:26, Steven Schveighoffer a écrit : On Fri, 02 Mar 2012 10:19:13 -0500, deadalnix deadal...@gmail.com wrote: Le 02/03/2012 15:37, Jacob Carlborg a écrit : Isn't it quite

Re: dereferencing null

2012-03-05 Thread Steven Schveighoffer
On Mon, 05 Mar 2012 05:38:20 -0500, Walter Bright newshou...@digitalmars.com wrote: On 3/4/2012 11:50 PM, Chad J wrote: Problems: - I have to rerun the program in a debugger to see the stack trace. This is a slow workflow. It's a big improvement if the segfault is hard to find, but only

Re: dereferencing null

2012-03-05 Thread H. S. Teoh
On Mon, Mar 05, 2012 at 05:31:34PM -0500, Steven Schveighoffer wrote: [...] I wholeheartedly agree that we should use the hardware features that we are given, and that NullPointerException is not worth the bloat. But we should be doing *something* better than just printing Segmentation Fault.

Re: dereferencing null

2012-03-05 Thread Jonathan M Davis
On Monday, March 05, 2012 15:05:57 Nick Sabalausky wrote: Walter Bright newshou...@digitalmars.com wrote in message news:jiunst$qrm$1...@digitalmars.com... 3. Intercepting and recovering from seg faults, div by 0, etc., all sounds great on paper. In practice, it is almost always wrong. The

  1   2   >