Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

record: Differentiate disguised vs pointer types #1530

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/analysis/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl IsIncomplete for Class {

impl IsIncomplete for Record {
fn is_incomplete(&self, lib: &Library) -> bool {
if self.c_type == "GHookList" || self.disguised {
if self.c_type == "GHookList" || self.disguised || self.pointer {
// Search for GHookList in sys codegen for rationale.
false
} else {
Expand Down
8 changes: 6 additions & 2 deletions src/codegen/sys/lib_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ fn generate_records(w: &mut dyn Write, env: &Env, records: &[&Record]) -> Result
// 5. Thus, we use custom generated GHookList.
// Hopefully someone will profit from all this.
generate_ghooklist(w)?;
} else if record.disguised {
} else if record.disguised || record.pointer {
generate_disguised(w, env, record)?;
} else {
let align = config.and_then(|c| c.align);
Expand Down Expand Up @@ -499,7 +499,11 @@ fn generate_disguised(w: &mut dyn Write, env: &Env, record: &Record) -> Result<(
cfg_condition(w, cfg_condition_, false, 0)?;
generate_opaque_type(w, &format!("_{}", record.c_type))?;
cfg_condition(w, cfg_condition_, false, 0)?;
writeln!(w, "pub type {name} = *mut _{name};", name = record.c_type)?;
if record.pointer {
writeln!(w, "pub type {name} = *mut _{name};", name = record.c_type)?;
} else {
writeln!(w, "pub type {name} = _{name};", name = record.c_type)?;
}
writeln!(w)
}

Expand Down
5 changes: 4 additions & 1 deletion src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,11 @@ pub struct Record {
pub deprecated_version: Option<Version>,
pub doc: Option<String>,
pub doc_deprecated: Option<String>,
/// A 'disguised' record is one where the c:type is a typedef that
/// A 'pointer' record is one where the c:type is a typedef that
/// doesn't look like a pointer, but is internally: typedef struct _X *X;
pub pointer: bool,
/// A 'disguised' record is one where the c:type is a typedef to
/// a struct whose content and size are unknown, it is :typedef struct _X X;
pub disguised: bool,
}

Expand Down
2 changes: 1 addition & 1 deletion src/library_postprocessing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ impl Library {
self.find_type(ns_id as u16, klass.type_struct.as_ref().unwrap())
{
if let Type::Record(record) = self.type_(class_record_tid) {
!record.disguised
!record.disguised && !record.pointer
} else {
unreachable!("Type {} with non-record class", full_name);
}
Expand Down
2 changes: 2 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ impl Library {
let gtype_struct_for = elem.attr("is-gtype-struct-for");
let version = self.read_version(parser, ns_id, elem)?;
let deprecated_version = self.read_deprecated_version(parser, ns_id, elem)?;
let pointer = elem.attr_bool("pointer", false);
let disguised = elem.attr_bool("disguised", false);

let mut fields = Vec::new();
Expand Down Expand Up @@ -406,6 +407,7 @@ impl Library {
doc,
doc_deprecated,
disguised,
pointer,
symbol_prefix,
});

Expand Down
Loading