[vlc-devel] [PATCH 1/2] libvlc: Add Rust API for writing modules in rust
Romain Vimont
rom1v at videolabs.io
Sun Sep 20 11:38:08 CEST 2020
On Sun, Sep 20, 2020 at 09:29:44AM +0300, Rémi Denis-Courmont wrote:
> Le sunnuntaina 20. syyskuuta 2020, 2.00.20 EEST Romain Vimont a écrit :
> > To solve the problem, you propose to call libc::malloc() from Rust and
> > free() from C (or malloc() from C and libc::free() from Rust). I like
> > this solution, but IIUC, it is not guaranteed to be correct, because the
> > allocators used by Rust and C may be different:
> > > To free the data behind the C pointer you should call a C function
> > > that does it, so that definitely the same C’s allocator is used. If
> > > the pointer comes from C’s malloc, then Rust’s libc::free may work,
> > > except it’s dangerous to do so if Windows DLLs are involved, since
> > > each DLL may have separate runtime.
>
> The VLC code base has been exchanging heap allocations and file descriptors
> between DLLs all the time. It's been working fine, and at this point, it is
> very deeply ingrained into the code base, so it has to work fine.
>
> This problem only exists if you set up the build system in a stupid manner
> like LAVfilters does.
>
> It might be a problem if you want to use LibVLC from a Rust application. But I
> believe that that's out of scope of this patchset.
Yes, that makes sense.
So in that situation, I think the best solution is to call
libc::malloc() from Rust and free() from C (like you did, Kartik).
Thank you all for your insights.
Regards
More information about the vlc-devel
mailing list