Skip to content

Commit f88b1a0

Browse files
authored
Merge pull request #267 from rtbo/reply_as_raw
add `Reply::as_raw`
2 parents 77a1972 + a1aad39 commit f88b1a0

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

build/cg/request.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ impl CodeGen {
354354
writeln!(out, " std::mem::forget(self);")?;
355355
writeln!(out, " raw")?;
356356
writeln!(out, " }}")?;
357+
writeln!(out)?;
358+
writeln!(out, " unsafe fn as_raw(&self) -> *const u8 {{")?;
359+
writeln!(out, " self.raw")?;
360+
writeln!(out, " }}")?;
357361
writeln!(out, "}}")?;
358362

359363
self.emit_debug_impl(out, reply_rs_typ, &reply.fields)?;

src/base.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ pub trait Reply {
301301
/// The returned pointer must be freed with [`libc::free`] to avoid any memory leak, or be used
302302
/// to build another reply.
303303
unsafe fn into_raw(self) -> *const u8;
304+
305+
/// Get the raw pointer of the XCB reply.
306+
///
307+
/// # Safety
308+
/// The returned pointer must NOT be freed. Passing this pointer to [`libc::free`] will result in a double free
309+
/// when the reply is dropped.
310+
unsafe fn as_raw(&self) -> *const u8;
304311
}
305312

306313
/// General trait for cookies returned by requests.

0 commit comments

Comments
 (0)