<div dir="ltr"><div dir="ltr">On Thu, Sep 10, 2020 at 11:14 PM Romain Vimont <<a href="mailto:rom1v@videolabs.io">rom1v@videolabs.io</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Kartik,<br>
<br>
Thank you for your work.<br>
<br>
(comment below)<br>
<br>
On Thu, Sep 10, 2020 at 10:17:29PM +0530, Kartik Ohri wrote:<br>
> diff --git a/src/vlccore-rs/src/<a href="http://stream.rs" rel="noreferrer" target="_blank">stream.rs</a> b/src/vlccore-rs/src/<a href="http://stream.rs" rel="noreferrer" target="_blank">stream.rs</a><br>
> new file mode 100644<br>
> index 0000000000..ea2ab4fc52<br>
> --- /dev/null<br>
> +++ b/src/vlccore-rs/src/<a href="http://stream.rs" rel="noreferrer" target="_blank">stream.rs</a><br>
> @@ -0,0 +1,119 @@<br>
> +use vlccore_sys::stream as ffi;<br>
> +use libc::{c_char, c_void};<br>
> +use std::ffi::{CStr, CString};<br>
> +use std::io::{Error, ErrorKind, Read, Result, Seek, SeekFrom};<br>
> +use std::ptr::null_mut;<br>
> +<br>
> +pub struct Stream {<br>
> +    stream: *mut ffi::stream_t,<br>
> +    is_owned: bool<br>
<br>
The ownership should be tracked by the Rust syntax.<br>
<br>
To avoid the need for a flag here, I suggest the following changes to<br>
your patch 2. The idea is to pass the "&mut Stream" to the real Rust<br>
implementation, and mem::forget() the stream in the wrapper function.<br>
<br></blockquote><div>Finally, I understood what you meant the first time :D. I have applied the changes and used ManuallyDrop.  I am inclined towards doing this on the API level because this should be the right behaviour when we receive a stream pointer from C. I am unsure how to do so as using the From trait we cannot return ManuallyDrop.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
--------8<-------------------------------------------------------------<br>
diff --git a/modules/demux/playlist/cuesheet/src/<a href="http://capi.rs" rel="noreferrer" target="_blank">capi.rs</a> b/modules/demux/playlist/cuesheet/src/<a href="http://capi.rs" rel="noreferrer" target="_blank">capi.rs</a><br>
index b2e3e9e683..11eb92562c 100644<br>
--- a/modules/demux/playlist/cuesheet/src/<a href="http://capi.rs" rel="noreferrer" target="_blank">capi.rs</a><br>
+++ b/modules/demux/playlist/cuesheet/src/<a href="http://capi.rs" rel="noreferrer" target="_blank">capi.rs</a><br>
@@ -14,14 +14,21 @@ pub struct CCuesheet {<br>
<br>
 #[no_mangle]<br>
 pub extern fn cuesheet_from_demux(s: *mut stream_t) -> *mut CCuesheet {<br>
-    let stream = stream::Stream::from(s);<br>
+    let mut stream = stream::Stream::from(s);<br>
+    let cuesheet = rust_cuesheet_from_demux(&mut stream);<br>
+    std::mem::forget(stream);<br>
+<br>
+    let c_cuesheet = Box::new(CCuesheet {cuesheet});<br>
+    Box::into_raw(c_cuesheet)<br>
+}<br>
+<br>
+fn rust_cuesheet_from_demux(stream: &mut stream::Stream) -> Cuesheet {<br>
     let mut cuesheet = Cuesheet::default();<br>
     let reader = BufReader::new(stream);<br>
     reader.lines().for_each(|line| {<br>
         line.map(|l| cuesheet.process_line(l.as_str()));<br>
     });<br>
-    let c_cuesheet = Box::new(CCuesheet {cuesheet});<br>
-    Box::into_raw(c_cuesheet)<br>
+    cuesheet<br>
 }<br>
<br>
 #[no_mangle]<br>
--------8<-------------------------------------------------------------<br>
<br>
Regards<br>
_______________________________________________<br>
vlc-devel mailing list<br>
To unsubscribe or modify your subscription options:<br>
<a href="https://mailman.videolan.org/listinfo/vlc-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/vlc-devel</a></blockquote></div></div>