Skip to content

Commit 15aeddd

Browse files
committed
try manual __imp_ dereference
1 parent 06abb15 commit 15aeddd

File tree

4 files changed

+28
-44
lines changed

4 files changed

+28
-44
lines changed

glib/gobject-sys/build.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// from gir-files (https://github.com/gtk-rs/gir-files)
33
// DO NOT EDIT
44

5-
mod build_manual;
6-
75
#[cfg(not(docsrs))]
86
use std::process;
97

@@ -16,6 +14,4 @@ fn main() {
1614
println!("cargo:warning={s}");
1715
process::exit(1);
1816
}
19-
20-
build_manual::main();
2117
}

glib/gobject-sys/build_manual.rs

Lines changed: 0 additions & 33 deletions
This file was deleted.

glib/gobject-sys/src/manual.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
use glib_sys::GType;
22

3-
// `g_param_spec_types` extern binding generated by build.rs
4-
include!(concat!(env!("OUT_DIR"), "/param_spec.rs"));
3+
#[cfg(not(target_os = "windows"))]
4+
pub type GParamSpecType = *const GType;
55

6-
/// # Safety
7-
/// This should be safe as long as the offset added to g_param_spec_types is in bounds.
8-
pub unsafe fn g_param_spec_types_get_type(offset: usize) -> GType {
9-
*g_param_spec_types.add(offset)
6+
#[cfg(target_os = "windows")]
7+
pub type GParamSpecType = usize;
8+
9+
#[repr(C)]
10+
pub struct GParamSpecTypesWrapper(&'static GParamSpecType);
11+
12+
unsafe impl Sync for GParamSpecTypesWrapper {}
13+
14+
impl GParamSpecTypesWrapper {
15+
/// # Safety
16+
/// This should be safe as long as the offset added to g_param_spec_types is in bounds.
17+
pub unsafe fn get_type(&self, offset: usize) -> GType {
18+
*(*self.0 as *const GType).add(offset)
19+
}
1020
}
21+
22+
extern "C" {
23+
#[cfg_attr(target_os = "windows", link_name = "__imp_g_param_spec_types")]
24+
static g_param_spec_types: GParamSpecType;
25+
}
26+
27+
pub static g_param_spec_types_ref: GParamSpecTypesWrapper =
28+
unsafe { GParamSpecTypesWrapper(&g_param_spec_types) };
29+
30+
//#[cfg(all(target_env = "msvc", not(feature = "static")))]
31+
//pub static __imp_g_param_spec_types: &'static GParamSpecTypes = unsafe { &g_param_spec_types };

glib/src/param_spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ macro_rules! define_param_spec {
302302
#[inline]
303303
fn static_type() -> Type {
304304
unsafe {
305-
from_glib(gobject_ffi::g_param_spec_types_get_type($rust_type_offset))
305+
from_glib(gobject_sys::g_param_spec_types_ref.get_type($rust_type_offset))
306306
}
307307
}
308308
}

0 commit comments

Comments
 (0)