Created
September 21, 2015 21:22
-
-
Save anonymous/e4ed8c4bce312aea1e2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct { | |
uint8_t* ptr; | |
uintptr_t len; | |
} BytesSlice; | |
typedef BytesSlice Utf8Slice; | |
Callbacks* declare_callbacks( | |
// ... | |
int (*append_doctype_to_document)(ParserUserData*, Utf8Slice, Utf8Slice, Utf8Slice); | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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> { /* ... */ } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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