Program crash: GC destroys an object unexpectedly

jfondren julian.fondren at gmail.com
Tue Sep 14 16:43:50 UTC 2021


On Tuesday, 14 September 2021 at 16:15:20 UTC, eugene wrote:
> On Tuesday, 14 September 2021 at 16:07:00 UTC, jfondren wrote:
>> No. And when was the first one?
>
> here:
>
> On Monday, 13 September 2021 at 18:45:22 UTC, jfondren wrote:
>>  auto p = cast(EpollEvent*) pureMalloc(EpollEvent.sizeof);
>
> What? Allocate struct epoll_event on the heap?
> It is a feeble joke ;)

It is an example of deliberately static storage that does not fix 
your problem, thereby proving that the broken lifetimes of the 
struct are not your only problem.

I explained that one at the time, and I explained this one. If it 
comes with an explanation, it's probably not a joke.

>
> ```c
>     static int ecap__add(int fd, void *dptr)
>     {
>         struct epoll_event waitfor = {0};
>            int flags, r;
>
>         waitfor.data.ptr = dptr;
>
>         r = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &waitfor);
>         if (-1 == r) {
> ```
>
> All fd's (sockets, timers etc) are added the same way
> and corresponding EventSources are not destroyed by GC.

GC needs to be able to stop your program and find all of the live 
objects in it. The misaligned pointer and the 
reference-containing struct that vanishes on the return of your 
corresponding function are both problems for this.


More information about the Digitalmars-d-learn mailing list