Skip to content

Commit

Permalink
try manual __imp_ dereference
Browse files Browse the repository at this point in the history
  • Loading branch information
eerii committed Sep 17, 2024
1 parent 06abb15 commit 330ec5b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 44 deletions.
4 changes: 0 additions & 4 deletions glib/gobject-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

mod build_manual;

#[cfg(not(docsrs))]
use std::process;

Expand All @@ -16,6 +14,4 @@ fn main() {
println!("cargo:warning={s}");
process::exit(1);
}

build_manual::main();
}
33 changes: 0 additions & 33 deletions glib/gobject-sys/build_manual.rs

This file was deleted.

26 changes: 20 additions & 6 deletions glib/gobject-sys/src/manual.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
use glib_sys::GType;

// `g_param_spec_types` extern binding generated by build.rs
include!(concat!(env!("OUT_DIR"), "/param_spec.rs"));
#[repr(C)]
pub struct GParamSpecTypes(*const GType);

/// # Safety
/// This should be safe as long as the offset added to g_param_spec_types is in bounds.
pub unsafe fn g_param_spec_types_get_type(offset: usize) -> GType {
*g_param_spec_types.add(offset)
unsafe impl Sync for GParamSpecTypes {}

impl GParamSpecTypes {
/// # Safety
/// This should be safe as long as the offset added to g_param_spec_types is in bounds.
pub unsafe fn get_type(&self, offset: usize) -> GType {
*self.0.add(offset)
}
}

extern "C" {
static g_param_spec_types: GParamSpecTypes;
}

//#[cfg(not(target_os = "windows"))]
pub static __imp_g_param_spec_types: &'static GParamSpecTypes = unsafe { &g_param_spec_types };

//#[cfg(all(target_env = "msvc", not(feature = "static")))]
//pub static __imp_g_param_spec_types: &'static GParamSpecTypes = unsafe { &g_param_spec_types };
2 changes: 1 addition & 1 deletion glib/src/param_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ macro_rules! define_param_spec {
#[inline]
fn static_type() -> Type {
unsafe {
from_glib(gobject_ffi::g_param_spec_types_get_type($rust_type_offset))
from_glib(gobject_sys::__imp_g_param_spec_types.get_type($rust_type_offset))
}
}
}
Expand Down

0 comments on commit 330ec5b

Please sign in to comment.