On 9/14/21 9:56 AM, eugene wrote:

> On Tuesday, 14 September 2021 at 16:43:50 UTC, jfondren wrote:

>> The misaligned pointer and the
>> reference-containing struct that vanishes on the return of your
>> corresponding function are both problems for this.
>
> where did you find 'misaligned pointer'?...

I think it's the align(1) for EpollEvent.

I was able to reproduce the segmentation fault and was seemingly able to fix it by making the EventSource class references alive by adding a constructor:

align (1) struct EpollEvent {
    align(1):
    uint event_mask;
    EventSource es;

  this(uint event_mask, EventSource es) {
    this.event_mask = event_mask;
    this.es = es;
    living ~= es;  // <-- Introduced this constructor for this line
  }
    /* just do not want to use that union, epoll_data_t */
}

// Here is the array that keeps EventSource alive:
EventSource[] living;

If that really is the fix, of course the references must be taken out of that container when possible.

Ali

Reply via email to