digitalmars.D.learn - this is null
- ANtlord (11/11) Mar 09 2019 Hello everyone! I've encountered the problem which I already
- Paul Backus (15/27) Mar 09 2019 You can end up with a null `this` reference if you dereference a
- ANtlord (4/7) Mar 09 2019 I can but my reference is not null before calling. Take a look at
- =?UTF-8?Q?Ali_=c3=87ehreli?= (6/17) Mar 09 2019 I haven't run the code but which pointer is null? Try adding this check
- ANtlord (11/15) Mar 09 2019 I mean `this` by "this" word. You can see that `this` is null if
- spir (7/17) Mar 10 2019 There is a typo in this instruction:
- ANtlord (4/10) Mar 10 2019 Good catch! But I have the same typo within the definition of the
- ANtlord (2/13) Mar 09 2019 Anyway, thank you! I didn't know about the feature.
Hello everyone! I've encountered the problem which I already encountered before. Unfortunately, I had no time in the previous time to report and to talk about it. So I decided to play making my own "malloc" function in pure D (betterC) at this time. And I encountered the issue one more time. `this` can be null. How? Please take a look at my project [0]. It gets the current heap break and tries to increase via a free list. So the segfault I meet happens there [1]. Tell me, please. What do I wrong? [0] https://github.com/ANtlord/deadmemory [1] https://github.com/ANtlord/deadmemory/blob/master/src/deadmemory/freelist.d#L56
Mar 09 2019
On Saturday, 9 March 2019 at 19:18:38 UTC, ANtlord wrote:Hello everyone! I've encountered the problem which I already encountered before. Unfortunately, I had no time in the previous time to report and to talk about it. So I decided to play making my own "malloc" function in pure D (betterC) at this time. And I encountered the issue one more time. `this` can be null. How? Please take a look at my project [0]. It gets the current heap break and tries to increase via a free list. So the segfault I meet happens there [1]. Tell me, please. What do I wrong? [0] https://github.com/ANtlord/deadmemory [1] https://github.com/ANtlord/deadmemory/blob/master/src/deadmemory/freelist.d#L56You can end up with a null `this` reference if you dereference a null pointer to a struct and then call a method on the result. For example: struct S { bool isThisNull() { return &this is null; } } void main() { import.std.stdio; S* p = null; writeln((*p).isThisNull); // true } Interactive version: https://run.dlang.io/is/fgT2rS
Mar 09 2019
On Saturday, 9 March 2019 at 20:04:53 UTC, Paul Backus wrote:You can end up with a null `this` reference if you dereference a null pointer to a struct and then call a method on the result. For example:I can but my reference is not null before calling. Take a look at the line of code [0]. There is a check before the line. https://github.com/ANtlord/deadmemory/blob/master/src/deadmemory/mem.d#L20 [0]
Mar 09 2019
On 03/09/2019 12:10 PM, ANtlord wrote:On Saturday, 9 March 2019 at 20:04:53 UTC, Paul Backus wrote:I haven't run the code but which pointer is null? Try adding this check as well: auto node = this.list.getFisrtFreeOrAdd(memViewLen); assert(node !is null); AliYou can end up with a null `this` reference if you dereference a null pointer to a struct and then call a method on the result. For example:I can but my reference is not null before calling. Take a look at the line of code [0]. There is a check before the line. https://github.com/ANtlord/deadmemory/blob/master/src/deadmemory/mem.d#L20 [0]
Mar 09 2019
On Saturday, 9 March 2019 at 21:00:51 UTC, Ali Çehreli wrote:I haven't run the code but which pointer is null? Try addingI mean `this` by "this" word. You can see that `this` is null if you run gdb and before that line make `p/x this` [0]this check as well: auto node = this.list.getFisrtFreeOrAdd(memViewLen); assert(node !is null);I get segfault in `getFisrtFreeOrAdd` method. Before the line I have an assertion [1]. It looks like the program misses (I have no idea how) `list` object while calling its method `getFisrtFreeOrAdd`. [0] https://github.com/ANtlord/deadmemory/blob/master/src/deadmemory/freelist.d#L56 [1] https://github.com/ANtlord/deadmemory/blob/master/src/deadmemory/mem.d#L19
Mar 09 2019
On 09/03/2019 21:10, ANtlord via Digitalmars-d-learn wrote:On Saturday, 9 March 2019 at 20:04:53 UTC, Paul Backus wrote:There is a typo in this instruction: T* ptr = this.list.getFisrtFreeOrAdd(memViewLen).getPtr!T(); ^^ rs (may this explain your null? the compiler should complain) dinizYou can end up with a null `this` reference if you dereference a null pointer to a struct and then call a method on the result. For example:I can but my reference is not null before calling. Take a look at the line of code [0]. There is a check before the line. https://github.com/ANtlord/deadmemory/blob/master/src/deadmemory/mem.d#L20 [0]
Mar 10 2019
On Sunday, 10 March 2019 at 14:25:56 UTC, spir wrote:There is a typo in this instruction: T* ptr = this.list.getFisrtFreeOrAdd(memViewLen).getPtr!T(); ^^ rs (may this explain your null? the compiler should complain) dinizGood catch! But I have the same typo within the definition of the method. I believe DMD screams about undefined method if it happens.
Mar 10 2019
On Saturday, 9 March 2019 at 20:04:53 UTC, Paul Backus wrote:struct S { bool isThisNull() { return &this is null; } } void main() { import.std.stdio; S* p = null; writeln((*p).isThisNull); // true } Interactive version: https://run.dlang.io/is/fgT2rSAnyway, thank you! I didn't know about the feature.
Mar 09 2019