Skip to content

Commit

Permalink
Merge pull request #1530 from ocrete/record-disguised-vs-pointer
Browse files Browse the repository at this point in the history
record: Differentiate disguised vs pointer types
  • Loading branch information
sdroege authored Dec 14, 2023
2 parents 71ca4ed + 1147792 commit 20a5b17
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
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

0 comments on commit 20a5b17

Please sign in to comment.