Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/analysis/namespaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct Namespace {
pub struct Info {
namespaces: Vec<Namespace>,
pub is_glib_crate: bool,
pub glib_ns_id: NsId,
pub glib_ns_id: Option<NsId>,
}

impl Info {
Expand Down Expand Up @@ -74,6 +74,6 @@ pub fn run(gir: &library::Library) -> Info {
Info {
namespaces,
is_glib_crate,
glib_ns_id: glib_ns_id.expect("Missing `GLib` namespace!"),
glib_ns_id,
}
}
6 changes: 4 additions & 2 deletions src/analysis/return_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ pub fn analyze(
);
None
} else {
let ns = if env.namespaces.glib_ns_id == namespaces::MAIN {
let ns = if env.namespaces.glib_ns_id.is_none()
Copy link
Member

Choose a reason for hiding this comment

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

This and other code should panic if the GLib namespace is not found. It's using API from it so the namespace must exist in these situations

|| env.namespaces.glib_ns_id == Some(namespaces::MAIN)
{
"error"
} else {
"glib"
Expand All @@ -91,7 +93,7 @@ pub fn analyze(
);
None
} else {
let ns = if env.namespaces.glib_ns_id == namespaces::MAIN {
let ns = if env.namespaces.glib_ns_id.is_none() || env.namespaces.glib_ns_id == Some(namespaces::MAIN) {
"crate::BoolError"
} else {
"glib"
Expand Down
4 changes: 3 additions & 1 deletion src/codegen/return_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ impl ToReturnValue for analysis::return_value::Info {
format!(
"Result<{}, {}BoolError>",
&type_name[7..(type_name.len() - 1)],
if env.namespaces.glib_ns_id == namespaces::MAIN {
if env.namespaces.glib_ns_id.is_none()
|| env.namespaces.glib_ns_id == Some(namespaces::MAIN)
{
""
} else {
"glib::"
Expand Down
10 changes: 4 additions & 6 deletions src/codegen/sys/ffi_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,12 @@ fn fix_name(env: &Env, type_id: library::TypeId, name: &str) -> Result {
| Type::List(..)
| Type::SList(..)
| Type::HashTable(..) => {
if env.namespaces.glib_ns_id == namespaces::MAIN {
if env.namespaces.glib_ns_id == Some(namespaces::MAIN) {
Ok(name.into())
} else if let Some(glib_ns_id) = env.namespaces.glib_ns_id {
Ok(format!("{}::{}", &env.namespaces[glib_ns_id].crate_name, name).into())
} else {
Ok(format!(
"{}::{}",
&env.namespaces[env.namespaces.glib_ns_id].crate_name, name
)
.into())
Ok(name.into())
}
}
_ => Ok(name.into()),
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/sys/lib_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn generate_lib(w: &mut dyn Write, env: &Env) -> Result<()> {
include_custom_modules(w, env)?;
statics::after_extern_crates(w)?;

if env.config.library_name != "GLib" {
if env.config.library_name != "GLib" && env.namespaces.glib_ns_id.is_some() {
statics::use_glib(w)?;
}
match &*env.config.library_name {
Expand Down
8 changes: 5 additions & 3 deletions src/custom_type_glib_priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ impl Library {
return;
}

let Some(glib_ns_id) = self.find_namespace("GLib") else {
return;
};

let tid_int = self.find_type(0, "*.gint").expect("No basic type *.gint");
let glib_ns_id = self
.find_namespace("GLib")
.expect("Missing `GLib` namespace in add_glib_priority!");

let tid_priority = self.add_type(
glib_ns_id,
"Priority",
Expand Down
Loading