musikr: pass iostream ptr to cpp

This commit is contained in:
Alexander Capehart 2025-02-19 16:38:32 -07:00
parent 47604724a4
commit e22f811c81
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
4 changed files with 17 additions and 11 deletions

View file

@ -11,7 +11,7 @@ namespace taglib_shim
class WrappedRsIOStream : public TagLib::IOStream class WrappedRsIOStream : public TagLib::IOStream
{ {
public: public:
explicit WrappedRsIOStream(rust::Box<RsIOStream> stream); explicit WrappedRsIOStream(RsIOStream *stream);
~WrappedRsIOStream() override; ~WrappedRsIOStream() override;
// TagLib::IOStream interface implementation // TagLib::IOStream interface implementation
@ -29,10 +29,10 @@ namespace taglib_shim
bool isOpen() const override; bool isOpen() const override;
private: private:
rust::Box<RsIOStream> rust_stream; RsIOStream *rust_stream;
}; };
WrappedRsIOStream::WrappedRsIOStream(rust::Box<RsIOStream> stream) : rust_stream(std::move(stream)) {} WrappedRsIOStream::WrappedRsIOStream(RsIOStream *stream) : rust_stream(stream) {}
WrappedRsIOStream::~WrappedRsIOStream() = default; WrappedRsIOStream::~WrappedRsIOStream() = default;
@ -154,9 +154,9 @@ namespace taglib_shim
} }
// Factory function to create a new RustIOStream // Factory function to create a new RustIOStream
std::unique_ptr<TagLib::IOStream> wrap_RsIOStream(rust::Box<RsIOStream> stream) std::unique_ptr<TagLib::IOStream> wrap_RsIOStream(RsIOStream *stream)
{ {
return std::unique_ptr<TagLib::IOStream>(new WrappedRsIOStream(std::move(stream))); return std::unique_ptr<TagLib::IOStream>(new WrappedRsIOStream(stream));
} }
} // namespace taglib_shim } // namespace taglib_shim

View file

@ -12,5 +12,5 @@ struct RsIOStream;
namespace taglib_shim namespace taglib_shim
{ {
// Factory functions with external linkage // Factory functions with external linkage
std::unique_ptr<TagLib::IOStream> wrap_RsIOStream(rust::Box<RsIOStream> stream); std::unique_ptr<TagLib::IOStream> wrap_RsIOStream(RsIOStream *stream);
} // namespace taglib_shim } // namespace taglib_shim

View file

@ -51,8 +51,8 @@ mod bridge_impl {
#[namespace = "TagLib"] #[namespace = "TagLib"]
#[cxx_name = "IOStream"] #[cxx_name = "IOStream"]
type CPPIOStream<'io_stream>; type CPPIOStream<'io_stream>;
fn wrap_RsIOStream<'io_stream>( unsafe fn wrap_RsIOStream<'io_stream>(
stream: Box<DynIOStream<'io_stream>>, stream: *mut DynIOStream<'io_stream>,
) -> UniquePtr<CPPIOStream<'io_stream>>; ) -> UniquePtr<CPPIOStream<'io_stream>>;
#[namespace = "TagLib"] #[namespace = "TagLib"]

View file

@ -14,14 +14,20 @@ pub trait IOStream {
} }
pub(super) struct BridgedIOStream<'io_stream> { pub(super) struct BridgedIOStream<'io_stream> {
stream: Box<DynIOStream<'io_stream>>,
cpp_stream: UniquePtr<CPPIOStream<'io_stream>>, cpp_stream: UniquePtr<CPPIOStream<'io_stream>>,
} }
impl<'io_stream> BridgedIOStream<'io_stream> { impl<'io_stream> BridgedIOStream<'io_stream> {
pub fn new<T: IOStream + 'io_stream>(stream: T) -> Self { pub fn new<T: IOStream + 'io_stream>(stream: T) -> Self {
let rs_stream: Box<DynIOStream<'io_stream>> = Box::new(DynIOStream(Box::new(stream))); let mut rs_stream: Box<DynIOStream<'io_stream>> = Box::new(DynIOStream(Box::new(stream)));
let cpp_stream: UniquePtr<CPPIOStream<'io_stream>> = bridge::wrap_RsIOStream(rs_stream); let cpp_stream: UniquePtr<CPPIOStream<'io_stream>> = unsafe {
BridgedIOStream { cpp_stream } bridge::wrap_RsIOStream(rs_stream.as_mut() as *mut _)
};
BridgedIOStream {
stream: rs_stream,
cpp_stream,
}
} }
pub fn cpp_stream(&self) -> &UniquePtr<CPPIOStream> { pub fn cpp_stream(&self) -> &UniquePtr<CPPIOStream> {