Re: [PATCH V6 3/8] libgpiod: Add rust wrapper crate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11-10-22, 10:07, Viresh Kumar wrote:
> And I am not sure why, as the reference isn't used anymore in this
> case to the event0.

This works though:

diff --git a/bindings/rust/libgpiod/examples/gpiobufferevent.rs b/bindings/rust/libgpiod/examples/gpiobufferevent.rs
index 613a800584e3..e16a1a39b22c 100644
--- a/bindings/rust/libgpiod/examples/gpiobufferevent.rs
+++ b/bindings/rust/libgpiod/examples/gpiobufferevent.rs
@@ -40,10 +40,12 @@ fn main() -> Result<()> {
         let event1 = buffer.event(1)?;

         println!("{:?}", (event0.line_offset(), event1.line_offset()));
+        let event0_copy = edge::Event::event_clone(&event0)?;
         drop(event0);
         // This fails to compile
         // request.read_edge_events(&mut buffer)?;
         drop(event1);
         request.read_edge_events(&mut buffer)?;
+        drop(event0_copy);
     }
 }
diff --git a/bindings/rust/libgpiod/src/edge_event.rs b/bindings/rust/libgpiod/src/edge_event.rs
index f5426459d779..12c0fd73f778 100644
--- a/bindings/rust/libgpiod/src/edge_event.rs
+++ b/bindings/rust/libgpiod/src/edge_event.rs
@@ -43,8 +43,8 @@ impl<'b> Event<'b> {
         })
     }

-    pub fn event_clone(&self) -> Result<Self> {
-        let event = unsafe { gpiod::gpiod_edge_event_copy(self.event) };
+    pub fn event_clone(event: &Event) -> Result<Self> {
+        let event = unsafe { gpiod::gpiod_edge_event_copy(event.event) };
         if event.is_null() {
             return Err(Error::OperationFailed(
                 OperationType::EdgeEventCopy,


-- 
viresh



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux