Skip to content

Commit

Permalink
Merge pull request #267 from rtbo/reply_as_raw
Browse files Browse the repository at this point in the history
add `Reply::as_raw`
  • Loading branch information
rtbo committed May 10, 2024
2 parents 77a1972 + a1aad39 commit f88b1a0
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 @@ -301,6 +301,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 f88b1a0

Please sign in to comment.