On 28-09-22, 14:20, Bartosz Golaszewski wrote: > Ok, so this is not correct. The doc for > gpiod_edge_event_buffer_get_event() says: > > * @return Pointer to an event stored in the buffer. The lifetime of the > * event is tied to the buffer object. Users must not free the event > * returned by this function. > > We make no guarantees that the address returned by > gpiod_edge_event_buffer_get_event() will still be valid after a call > to gpiod_line_request_read_edge_event(). In fact the doc for the > latter says: > > * @note Any exising events in the buffer are overwritten. This is not an > * append operation. > > So we're being clear that after a call to > gpiod_line_request_read_edge_event(), all previously returned edge > event pointers are invalid unless the objects to which they point were > explicitly copied. > > Current implementation does indeed work like what you describe but > that behavior is not "contractually" guaranteed and can change even > between minor releases. > > In C++ if you do: > > const edge_event& ev = buffer.get_event(0); > request.read_edge_event(buffer); > std::cout << ev << std::endl; > > You risk a segfault. > > My understanding is that Rust should not allow a crash in this > situation by design. Hmm, so what exactly do we want to do here then ? - Don't allow events to be referenced ? i.e. make event_clone() the default behavior ? - Don't allow read_edge_event() to be called twice for a buffer ? that will be inefficient though. - Somehow guarantee that reference to all the events are dropped before issuing read_edge_event() again, else make it fail ? I am not sure how straight forward that can be though. -- viresh