Skip to content

Instantly share code, notes, and snippets.

Created September 21, 2015 21:22
Show Gist options
  • Save anonymous/e4ed8c4bce312aea1e2b to your computer and use it in GitHub Desktop.
Save anonymous/e4ed8c4bce312aea1e2b to your computer and use it in GitHub Desktop.
typedef struct {
uint8_t* ptr;
uintptr_t len;
} BytesSlice;
typedef BytesSlice Utf8Slice;
Callbacks* declare_callbacks(
// ...
int (*append_doctype_to_document)(ParserUserData*, Utf8Slice, Utf8Slice, Utf8Slice);
);
#[repr(C)]
#[derive(Copy, Clone, Debug)]
#[allow(raw_pointer_derive)]
pub struct BytesSlice {
ptr: *const u8,
len: usize,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct Utf8Slice(BytesSlice);
#[no_mangle]
pub unsafe extern "C" fn declare_callbacks(
// ...
append_doctype_to_document: extern "C" fn(*const OpaqueParserUserData, Utf8Slice, Utf8Slice, Utf8Slice) -> c_int
) -> Option<&'static Callbacks> { /* ... */ }
print('ptr: %s, len: 0x%x' % (slice_.ptr, slice_.len))
ptr: <cdata 'uint8_t *' 0x7fffe5ff06b8>, len: 0x4
ptr: <cdata 'uint8_t *' 0x7f4aac6c2cd7>, len: 0x0
ptr: <cdata 'uint8_t *' NULL>, len: 0x7f4aaca66610
println!("{:?}", slice)
Utf8Slice(BytesSlice { ptr: 0x7fffe5ff06b8, len: 4 })
Utf8Slice(BytesSlice { ptr: 0x7f4aac6c2cd7, len: 0 })
Utf8Slice(BytesSlice { ptr: 0x7f4aac6c2cd7, len: 0 })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment