Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions crates/generate-raw/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,27 @@ fn render_const(src: &mut String, name: &str, c: &IntDatatype) {
fn render_union(src: &mut String, name: &str, u: &UnionDatatype) {
src.push_str("#[repr(C)]\n");
src.push_str("#[derive(Copy, Clone)]\n");
src.push_str(&format!("pub union {} {{\n", name.to_camel_case()));
src.push_str(&format!("pub union {}U {{\n", name.to_camel_case()));
for variant in u.variants.iter() {
rustdoc(&variant.docs, src);
src.push_str("pub ");
variant.name.render(src);
src.push_str(": ");
variant.tref.render(src);
src.push_str(",\n");
if let Some(ref tref) = variant.tref {
rustdoc(&variant.docs, src);
src.push_str("pub ");
variant.name.render(src);
src.push_str(": ");
tref.render(src);
src.push_str(",\n");
}
}
src.push_str("}");
src.push_str("}\n");
src.push_str("#[repr(C)]\n");
src.push_str("#[derive(Copy, Clone)]\n");
src.push_str(&format!("pub struct {} {{\n", name.to_camel_case()));
src.push_str(&format!(
"pub tag: {},\n",
u.tag.name.as_str().to_camel_case()
));
src.push_str(&format!("pub u: {}U,\n", name.to_camel_case()));
src.push_str("}\n");
}

fn render_struct(src: &mut String, name: &str, s: &StructDatatype) {
Expand Down Expand Up @@ -189,14 +200,7 @@ fn render_alias(src: &mut String, name: &str, dest: &TypeRef) {
src.push_str("<'a>");
}
src.push_str(" = ");

// Give `size_t` special treatment to translate it to `usize` in Rust
// instead of `u32`, makes things a bit nicer in Rust.
if name == "size" {
src.push_str("usize");
} else {
dest.render(src);
}
dest.render(src);
src.push(';');
}

Expand Down
39 changes: 18 additions & 21 deletions src/lib_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::mem::MaybeUninit;

pub use crate::error::Error;
pub type Result<T, E = Error> = core::result::Result<T, E>;
pub type Size = usize;
pub type Size = u32;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this intentional? IIRC this was a convenience from before because usize is used so ubiquitously in Rust right nwo

pub type Filesize = u64;
pub type Timestamp = u64;
pub type Clockid = u32;
Expand Down Expand Up @@ -495,21 +495,16 @@ pub struct EventFdReadwrite {
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union EventU {
/// When type is `eventtype::fd_read` or `eventtype::fd_write`:
pub fd_readwrite: EventFdReadwrite,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct Event {
/// User-provided value that got attached to `subscription::userdata`.
pub userdata: Userdata,
/// If non-zero, an error that occurred while processing the subscription request.
pub error: Errno,
/// The type of the event that occurred.
/// The type of event that occured
pub r#type: Eventtype,
/// The contents of the event.
pub u: EventU,
/// The contents of the event, if it is an `eventtype::fd_read` or
/// `eventtype::fd_write`. `eventtype::clock` events ignore this field.
pub fd_readwrite: EventFdReadwrite,
}
pub type Subclockflags = u16;
/// If set, treat the timestamp provided in
Expand Down Expand Up @@ -539,21 +534,25 @@ pub struct SubscriptionFdReadwrite {
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union SubscriptionU {
/// When type is `eventtype::clock`:
pub union SubscriptionUU {
pub clock: SubscriptionClock,
/// When type is `eventtype::fd_read` or `eventtype::fd_write`:
pub fd_readwrite: SubscriptionFdReadwrite,
pub fd_read: SubscriptionFdReadwrite,
pub fd_write: SubscriptionFdReadwrite,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct SubscriptionU {
pub tag: Eventtype,
pub u: SubscriptionUU,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct Subscription {
/// User-provided value that is attached to the subscription in the
/// implementation and returned through `event::userdata`.
pub userdata: Userdata,
/// The type of the event to which to subscribe.
pub r#type: Eventtype,
/// The contents of the subscription.
/// The type of the event to which to subscribe, and its contents
pub u: SubscriptionU,
}
pub type Exitcode = u32;
Expand Down Expand Up @@ -677,17 +676,15 @@ pub struct PrestatDir {
#[repr(C)]
#[derive(Copy, Clone)]
pub union PrestatU {
/// When type is `preopentype::dir`:
pub dir: PrestatDir,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct Prestat {
/// The type of the pre-opened capability.
pub pr_type: Preopentype,
/// The contents of the information.
pub tag: Preopentype,
pub u: PrestatU,
}

/// Read command-line argument data.
/// The size of the array should match that returned by `args_sizes_get`
pub unsafe fn args_get(argv: *mut *mut u8, argv_buf: *mut u8) -> Result<()> {
Expand Down