Skip to content

Commit cb02342

Browse files
committed
remove g_param_spec_types link alltogether
1 parent df58d90 commit cb02342

File tree

5 files changed

+28
-88
lines changed

5 files changed

+28
-88
lines changed

glib/gobject-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ v2_82 = ["v2_80"]
2828
name = "gobject_sys"
2929

3030
[package]
31-
build = "build_manual.rs"
31+
build = "build.rs"
3232
description = "FFI bindings to libgobject-2.0"
3333
keywords = ["gobject", "ffi", "gtk-rs", "gnome"]
3434
name = "gobject-sys"

glib/gobject-sys/build_manual.rs

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

glib/gobject-sys/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313

1414
use glib_sys as glib;
1515

16-
mod manual;
17-
18-
pub use manual::*;
19-
2016
#[allow(unused_imports)]
2117
use libc::{
2218
c_char, c_double, c_float, c_int, c_long, c_short, c_uchar, c_uint, c_ulong, c_ushort, c_void,

glib/gobject-sys/src/manual.rs

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

glib/src/param_spec.rs

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
use std::{
44
char::CharTryFromError,
5+
collections::HashMap,
56
ffi::CStr,
67
num::{NonZeroI32, NonZeroI64, NonZeroI8, NonZeroU32, NonZeroU64, NonZeroU8},
78
path::{Path, PathBuf},
9+
sync::{LazyLock, Mutex},
810
};
911

1012
use crate::{
@@ -296,14 +298,20 @@ pub unsafe trait ParamSpecType:
296298
{
297299
}
298300

301+
static G_PARAM_SPEC_TYPES: LazyLock<Mutex<HashMap<&'static str, Type>>> =
302+
LazyLock::new(|| Mutex::new(HashMap::new()));
303+
299304
macro_rules! define_param_spec {
300-
($rust_type:ident, $ffi_type:path, $rust_type_offset:expr) => {
305+
($rust_type:ident, $ffi_type:path) => {
301306
impl StaticType for $rust_type {
302307
#[inline]
303308
fn static_type() -> Type {
304-
unsafe {
305-
from_glib(gobject_sys::g_param_spec_types_get_type($rust_type_offset))
306-
}
309+
let name = stringify!($rust_type);
310+
*G_PARAM_SPEC_TYPES.lock().unwrap().entry(name).or_insert_with_key(|name| {
311+
let name = format!("GParam{}", name.split("Spec").last().unwrap_or_default());
312+
let name_c = std::ffi::CString::new(name).unwrap();
313+
unsafe { from_glib(gobject_ffi::g_type_from_name(name_c.as_ptr())) }
314+
})
307315
}
308316
}
309317

@@ -551,8 +559,8 @@ macro_rules! define_param_spec_min_max {
551559
}
552560

553561
macro_rules! define_param_spec_numeric {
554-
($rust_type:ident, $ffi_type:path, $value_type:ty, $rust_type_offset:expr, $ffi_fun:ident) => {
555-
define_param_spec!($rust_type, $ffi_type, $rust_type_offset);
562+
($rust_type:ident, $ffi_type:path, $value_type:ty, $ffi_fun:ident) => {
563+
define_param_spec!($rust_type, $ffi_type);
556564
define_param_spec_default!($rust_type, $ffi_type, $value_type, |x| x);
557565
define_param_spec_min_max!($rust_type, $ffi_type, $value_type);
558566

@@ -782,7 +790,6 @@ define_param_spec_numeric!(
782790
ParamSpecChar,
783791
gobject_ffi::GParamSpecChar,
784792
i8,
785-
0,
786793
g_param_spec_char
787794
);
788795

@@ -802,7 +809,6 @@ define_param_spec_numeric!(
802809
ParamSpecUChar,
803810
gobject_ffi::GParamSpecUChar,
804811
u8,
805-
1,
806812
g_param_spec_uchar
807813
);
808814

@@ -823,7 +829,7 @@ wrapper! {
823829
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
824830
}
825831
}
826-
define_param_spec!(ParamSpecBoolean, gobject_ffi::GParamSpecBoolean, 2);
832+
define_param_spec!(ParamSpecBoolean, gobject_ffi::GParamSpecBoolean);
827833

828834
define_param_spec_default!(
829835
ParamSpecBoolean,
@@ -874,7 +880,6 @@ define_param_spec_numeric!(
874880
ParamSpecInt,
875881
gobject_ffi::GParamSpecInt,
876882
i32,
877-
3,
878883
g_param_spec_int
879884
);
880885

@@ -894,7 +899,6 @@ define_param_spec_numeric!(
894899
ParamSpecUInt,
895900
gobject_ffi::GParamSpecUInt,
896901
u32,
897-
4,
898902
g_param_spec_uint
899903
);
900904

@@ -919,7 +923,6 @@ define_param_spec_numeric!(
919923
ParamSpecLong,
920924
gobject_ffi::GParamSpecLong,
921925
libc::c_long,
922-
5,
923926
g_param_spec_long
924927
);
925928

@@ -944,7 +947,6 @@ define_param_spec_numeric!(
944947
ParamSpecULong,
945948
gobject_ffi::GParamSpecULong,
946949
libc::c_ulong,
947-
6,
948950
g_param_spec_ulong
949951
);
950952

@@ -969,7 +971,6 @@ define_param_spec_numeric!(
969971
ParamSpecInt64,
970972
gobject_ffi::GParamSpecInt64,
971973
i64,
972-
7,
973974
g_param_spec_int64
974975
);
975976

@@ -994,7 +995,6 @@ define_param_spec_numeric!(
994995
ParamSpecUInt64,
995996
gobject_ffi::GParamSpecUInt64,
996997
u64,
997-
8,
998998
g_param_spec_uint64
999999
);
10001000

@@ -1015,7 +1015,7 @@ wrapper! {
10151015
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
10161016
}
10171017
}
1018-
define_param_spec!(ParamSpecUnichar, gobject_ffi::GParamSpecUnichar, 9);
1018+
define_param_spec!(ParamSpecUnichar, gobject_ffi::GParamSpecUnichar);
10191019
define_param_spec_default!(ParamSpecUnichar, gobject_ffi::GParamSpecUnichar, Result<char, CharTryFromError>, TryFrom::try_from);
10201020

10211021
impl ParamSpecUnichar {
@@ -1057,7 +1057,7 @@ wrapper! {
10571057
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
10581058
}
10591059
}
1060-
define_param_spec!(ParamSpecEnum, gobject_ffi::GParamSpecEnum, 10);
1060+
define_param_spec!(ParamSpecEnum, gobject_ffi::GParamSpecEnum);
10611061

10621062
impl ParamSpecEnum {
10631063
unsafe fn new_unchecked<'a>(
@@ -1201,7 +1201,7 @@ wrapper! {
12011201
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
12021202
}
12031203
}
1204-
define_param_spec!(ParamSpecFlags, gobject_ffi::GParamSpecFlags, 11);
1204+
define_param_spec!(ParamSpecFlags, gobject_ffi::GParamSpecFlags);
12051205

12061206
impl ParamSpecFlags {
12071207
unsafe fn new_unchecked<'a>(
@@ -1344,7 +1344,6 @@ define_param_spec_numeric!(
13441344
ParamSpecFloat,
13451345
gobject_ffi::GParamSpecFloat,
13461346
f32,
1347-
12,
13481347
g_param_spec_float
13491348
);
13501349

@@ -1369,7 +1368,6 @@ define_param_spec_numeric!(
13691368
ParamSpecDouble,
13701369
gobject_ffi::GParamSpecDouble,
13711370
f64,
1372-
13,
13731371
g_param_spec_double
13741372
);
13751373

@@ -1390,7 +1388,7 @@ wrapper! {
13901388
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
13911389
}
13921390
}
1393-
define_param_spec!(ParamSpecString, gobject_ffi::GParamSpecString, 14);
1391+
define_param_spec!(ParamSpecString, gobject_ffi::GParamSpecString);
13941392

13951393
define_param_spec_default!(
13961394
ParamSpecString,
@@ -1499,7 +1497,7 @@ wrapper! {
14991497
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
15001498
}
15011499
}
1502-
define_param_spec!(ParamSpecParam, gobject_ffi::GParamSpecParam, 15);
1500+
define_param_spec!(ParamSpecParam, gobject_ffi::GParamSpecParam);
15031501

15041502
impl ParamSpecParam {
15051503
unsafe fn new_unchecked<'a>(
@@ -1541,7 +1539,7 @@ wrapper! {
15411539
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
15421540
}
15431541
}
1544-
define_param_spec!(ParamSpecBoxed, gobject_ffi::GParamSpecBoxed, 16);
1542+
define_param_spec!(ParamSpecBoxed, gobject_ffi::GParamSpecBoxed);
15451543

15461544
impl ParamSpecBoxed {
15471545
unsafe fn new_unchecked<'a>(
@@ -1629,7 +1627,7 @@ wrapper! {
16291627
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
16301628
}
16311629
}
1632-
define_param_spec!(ParamSpecPointer, gobject_ffi::GParamSpecPointer, 17);
1630+
define_param_spec!(ParamSpecPointer, gobject_ffi::GParamSpecPointer);
16331631

16341632
impl ParamSpecPointer {
16351633
unsafe fn new_unchecked<'a>(
@@ -1665,7 +1663,7 @@ wrapper! {
16651663
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
16661664
}
16671665
}
1668-
define_param_spec!(ParamSpecValueArray, gobject_ffi::GParamSpecValueArray, 18);
1666+
define_param_spec!(ParamSpecValueArray, gobject_ffi::GParamSpecValueArray);
16691667

16701668
impl ParamSpecValueArray {
16711669
unsafe fn new_unchecked<'a>(
@@ -1785,7 +1783,7 @@ wrapper! {
17851783
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
17861784
}
17871785
}
1788-
define_param_spec!(ParamSpecObject, gobject_ffi::GParamSpecObject, 19);
1786+
define_param_spec!(ParamSpecObject, gobject_ffi::GParamSpecObject);
17891787

17901788
impl ParamSpecObject {
17911789
unsafe fn new_unchecked<'a>(
@@ -1873,7 +1871,7 @@ wrapper! {
18731871
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
18741872
}
18751873
}
1876-
define_param_spec!(ParamSpecOverride, gobject_ffi::GParamSpecOverride, 20);
1874+
define_param_spec!(ParamSpecOverride, gobject_ffi::GParamSpecOverride);
18771875

18781876
impl ParamSpecOverride {
18791877
unsafe fn new_unchecked(name: &str, overridden: impl AsRef<ParamSpec>) -> ParamSpec {
@@ -1981,7 +1979,7 @@ wrapper! {
19811979
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
19821980
}
19831981
}
1984-
define_param_spec!(ParamSpecGType, gobject_ffi::GParamSpecGType, 21);
1982+
define_param_spec!(ParamSpecGType, gobject_ffi::GParamSpecGType);
19851983

19861984
impl ParamSpecGType {
19871985
unsafe fn new_unchecked<'a>(
@@ -2021,7 +2019,7 @@ wrapper! {
20212019
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
20222020
}
20232021
}
2024-
define_param_spec!(ParamSpecVariant, gobject_ffi::GParamSpecVariant, 22);
2022+
define_param_spec!(ParamSpecVariant, gobject_ffi::GParamSpecVariant);
20252023

20262024
define_param_spec_default!(
20272025
ParamSpecVariant,

0 commit comments

Comments
 (0)