Skip to content

Commit

Permalink
add Reply::as_raw
Browse files Browse the repository at this point in the history
  • Loading branch information
rtbo committed May 10, 2024
1 parent 5f23596 commit a1aad39
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build/cg/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ impl CodeGen {
writeln!(out, " std::mem::forget(self);")?;
writeln!(out, " raw")?;
writeln!(out, " }}")?;
writeln!(out)?;
writeln!(out, " unsafe fn as_raw(&self) -> *const u8 {{")?;
writeln!(out, " self.raw")?;
writeln!(out, " }}")?;
writeln!(out, "}}")?;

self.emit_debug_impl(out, reply_rs_typ, &reply.fields)?;
Expand Down
7 changes: 7 additions & 0 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ pub trait Reply {
/// The returned pointer must be freed with [`libc::free`] to avoid any memory leak, or be used
/// to build another reply.
unsafe fn into_raw(self) -> *const u8;

/// Get the raw pointer of the XCB reply.
///
/// # Safety
/// The returned pointer must NOT be freed. Passing this pointer to [`libc::free`] will result in a double free
/// when the reply is dropped.
unsafe fn as_raw(&self) -> *const u8;
}

/// General trait for cookies returned by requests.
Expand Down

0 comments on commit a1aad39

Please sign in to comment.