2
2
3
3
use std:: {
4
4
char:: CharTryFromError ,
5
+ collections:: HashMap ,
5
6
ffi:: CStr ,
6
7
num:: { NonZeroI32 , NonZeroI64 , NonZeroI8 , NonZeroU32 , NonZeroU64 , NonZeroU8 } ,
7
8
path:: { Path , PathBuf } ,
9
+ sync:: { LazyLock , Mutex } ,
8
10
} ;
9
11
10
12
use crate :: {
@@ -296,14 +298,20 @@ pub unsafe trait ParamSpecType:
296
298
{
297
299
}
298
300
301
+ static G_PARAM_SPEC_TYPES : LazyLock < Mutex < HashMap < & ' static str , Type > > > =
302
+ LazyLock :: new ( || Mutex :: new ( HashMap :: new ( ) ) ) ;
303
+
299
304
macro_rules! define_param_spec {
300
- ( $rust_type: ident, $ffi_type: path, $rust_type_offset : expr ) => {
305
+ ( $rust_type: ident, $ffi_type: path) => {
301
306
impl StaticType for $rust_type {
302
307
#[ inline]
303
308
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
+ } )
307
315
}
308
316
}
309
317
@@ -551,8 +559,8 @@ macro_rules! define_param_spec_min_max {
551
559
}
552
560
553
561
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) ;
556
564
define_param_spec_default!( $rust_type, $ffi_type, $value_type, |x| x) ;
557
565
define_param_spec_min_max!( $rust_type, $ffi_type, $value_type) ;
558
566
@@ -782,7 +790,6 @@ define_param_spec_numeric!(
782
790
ParamSpecChar ,
783
791
gobject_ffi:: GParamSpecChar ,
784
792
i8 ,
785
- 0 ,
786
793
g_param_spec_char
787
794
) ;
788
795
@@ -802,7 +809,6 @@ define_param_spec_numeric!(
802
809
ParamSpecUChar ,
803
810
gobject_ffi:: GParamSpecUChar ,
804
811
u8 ,
805
- 1 ,
806
812
g_param_spec_uchar
807
813
) ;
808
814
@@ -823,7 +829,7 @@ wrapper! {
823
829
unref => |ptr| gobject_ffi:: g_param_spec_unref( ptr as * mut gobject_ffi:: GParamSpec ) ,
824
830
}
825
831
}
826
- define_param_spec ! ( ParamSpecBoolean , gobject_ffi:: GParamSpecBoolean , 2 ) ;
832
+ define_param_spec ! ( ParamSpecBoolean , gobject_ffi:: GParamSpecBoolean ) ;
827
833
828
834
define_param_spec_default ! (
829
835
ParamSpecBoolean ,
@@ -874,7 +880,6 @@ define_param_spec_numeric!(
874
880
ParamSpecInt ,
875
881
gobject_ffi:: GParamSpecInt ,
876
882
i32 ,
877
- 3 ,
878
883
g_param_spec_int
879
884
) ;
880
885
@@ -894,7 +899,6 @@ define_param_spec_numeric!(
894
899
ParamSpecUInt ,
895
900
gobject_ffi:: GParamSpecUInt ,
896
901
u32 ,
897
- 4 ,
898
902
g_param_spec_uint
899
903
) ;
900
904
@@ -919,7 +923,6 @@ define_param_spec_numeric!(
919
923
ParamSpecLong ,
920
924
gobject_ffi:: GParamSpecLong ,
921
925
libc:: c_long,
922
- 5 ,
923
926
g_param_spec_long
924
927
) ;
925
928
@@ -944,7 +947,6 @@ define_param_spec_numeric!(
944
947
ParamSpecULong ,
945
948
gobject_ffi:: GParamSpecULong ,
946
949
libc:: c_ulong,
947
- 6 ,
948
950
g_param_spec_ulong
949
951
) ;
950
952
@@ -969,7 +971,6 @@ define_param_spec_numeric!(
969
971
ParamSpecInt64 ,
970
972
gobject_ffi:: GParamSpecInt64 ,
971
973
i64 ,
972
- 7 ,
973
974
g_param_spec_int64
974
975
) ;
975
976
@@ -994,7 +995,6 @@ define_param_spec_numeric!(
994
995
ParamSpecUInt64 ,
995
996
gobject_ffi:: GParamSpecUInt64 ,
996
997
u64 ,
997
- 8 ,
998
998
g_param_spec_uint64
999
999
) ;
1000
1000
@@ -1015,7 +1015,7 @@ wrapper! {
1015
1015
unref => |ptr| gobject_ffi:: g_param_spec_unref( ptr as * mut gobject_ffi:: GParamSpec ) ,
1016
1016
}
1017
1017
}
1018
- define_param_spec ! ( ParamSpecUnichar , gobject_ffi:: GParamSpecUnichar , 9 ) ;
1018
+ define_param_spec ! ( ParamSpecUnichar , gobject_ffi:: GParamSpecUnichar ) ;
1019
1019
define_param_spec_default ! ( ParamSpecUnichar , gobject_ffi:: GParamSpecUnichar , Result <char , CharTryFromError >, TryFrom :: try_from) ;
1020
1020
1021
1021
impl ParamSpecUnichar {
@@ -1057,7 +1057,7 @@ wrapper! {
1057
1057
unref => |ptr| gobject_ffi:: g_param_spec_unref( ptr as * mut gobject_ffi:: GParamSpec ) ,
1058
1058
}
1059
1059
}
1060
- define_param_spec ! ( ParamSpecEnum , gobject_ffi:: GParamSpecEnum , 10 ) ;
1060
+ define_param_spec ! ( ParamSpecEnum , gobject_ffi:: GParamSpecEnum ) ;
1061
1061
1062
1062
impl ParamSpecEnum {
1063
1063
unsafe fn new_unchecked < ' a > (
@@ -1201,7 +1201,7 @@ wrapper! {
1201
1201
unref => |ptr| gobject_ffi:: g_param_spec_unref( ptr as * mut gobject_ffi:: GParamSpec ) ,
1202
1202
}
1203
1203
}
1204
- define_param_spec ! ( ParamSpecFlags , gobject_ffi:: GParamSpecFlags , 11 ) ;
1204
+ define_param_spec ! ( ParamSpecFlags , gobject_ffi:: GParamSpecFlags ) ;
1205
1205
1206
1206
impl ParamSpecFlags {
1207
1207
unsafe fn new_unchecked < ' a > (
@@ -1344,7 +1344,6 @@ define_param_spec_numeric!(
1344
1344
ParamSpecFloat ,
1345
1345
gobject_ffi:: GParamSpecFloat ,
1346
1346
f32 ,
1347
- 12 ,
1348
1347
g_param_spec_float
1349
1348
) ;
1350
1349
@@ -1369,7 +1368,6 @@ define_param_spec_numeric!(
1369
1368
ParamSpecDouble ,
1370
1369
gobject_ffi:: GParamSpecDouble ,
1371
1370
f64 ,
1372
- 13 ,
1373
1371
g_param_spec_double
1374
1372
) ;
1375
1373
@@ -1390,7 +1388,7 @@ wrapper! {
1390
1388
unref => |ptr| gobject_ffi:: g_param_spec_unref( ptr as * mut gobject_ffi:: GParamSpec ) ,
1391
1389
}
1392
1390
}
1393
- define_param_spec ! ( ParamSpecString , gobject_ffi:: GParamSpecString , 14 ) ;
1391
+ define_param_spec ! ( ParamSpecString , gobject_ffi:: GParamSpecString ) ;
1394
1392
1395
1393
define_param_spec_default ! (
1396
1394
ParamSpecString ,
@@ -1499,7 +1497,7 @@ wrapper! {
1499
1497
unref => |ptr| gobject_ffi:: g_param_spec_unref( ptr as * mut gobject_ffi:: GParamSpec ) ,
1500
1498
}
1501
1499
}
1502
- define_param_spec ! ( ParamSpecParam , gobject_ffi:: GParamSpecParam , 15 ) ;
1500
+ define_param_spec ! ( ParamSpecParam , gobject_ffi:: GParamSpecParam ) ;
1503
1501
1504
1502
impl ParamSpecParam {
1505
1503
unsafe fn new_unchecked < ' a > (
@@ -1541,7 +1539,7 @@ wrapper! {
1541
1539
unref => |ptr| gobject_ffi:: g_param_spec_unref( ptr as * mut gobject_ffi:: GParamSpec ) ,
1542
1540
}
1543
1541
}
1544
- define_param_spec ! ( ParamSpecBoxed , gobject_ffi:: GParamSpecBoxed , 16 ) ;
1542
+ define_param_spec ! ( ParamSpecBoxed , gobject_ffi:: GParamSpecBoxed ) ;
1545
1543
1546
1544
impl ParamSpecBoxed {
1547
1545
unsafe fn new_unchecked < ' a > (
@@ -1629,7 +1627,7 @@ wrapper! {
1629
1627
unref => |ptr| gobject_ffi:: g_param_spec_unref( ptr as * mut gobject_ffi:: GParamSpec ) ,
1630
1628
}
1631
1629
}
1632
- define_param_spec ! ( ParamSpecPointer , gobject_ffi:: GParamSpecPointer , 17 ) ;
1630
+ define_param_spec ! ( ParamSpecPointer , gobject_ffi:: GParamSpecPointer ) ;
1633
1631
1634
1632
impl ParamSpecPointer {
1635
1633
unsafe fn new_unchecked < ' a > (
@@ -1665,7 +1663,7 @@ wrapper! {
1665
1663
unref => |ptr| gobject_ffi:: g_param_spec_unref( ptr as * mut gobject_ffi:: GParamSpec ) ,
1666
1664
}
1667
1665
}
1668
- define_param_spec ! ( ParamSpecValueArray , gobject_ffi:: GParamSpecValueArray , 18 ) ;
1666
+ define_param_spec ! ( ParamSpecValueArray , gobject_ffi:: GParamSpecValueArray ) ;
1669
1667
1670
1668
impl ParamSpecValueArray {
1671
1669
unsafe fn new_unchecked < ' a > (
@@ -1785,7 +1783,7 @@ wrapper! {
1785
1783
unref => |ptr| gobject_ffi:: g_param_spec_unref( ptr as * mut gobject_ffi:: GParamSpec ) ,
1786
1784
}
1787
1785
}
1788
- define_param_spec ! ( ParamSpecObject , gobject_ffi:: GParamSpecObject , 19 ) ;
1786
+ define_param_spec ! ( ParamSpecObject , gobject_ffi:: GParamSpecObject ) ;
1789
1787
1790
1788
impl ParamSpecObject {
1791
1789
unsafe fn new_unchecked < ' a > (
@@ -1873,7 +1871,7 @@ wrapper! {
1873
1871
unref => |ptr| gobject_ffi:: g_param_spec_unref( ptr as * mut gobject_ffi:: GParamSpec ) ,
1874
1872
}
1875
1873
}
1876
- define_param_spec ! ( ParamSpecOverride , gobject_ffi:: GParamSpecOverride , 20 ) ;
1874
+ define_param_spec ! ( ParamSpecOverride , gobject_ffi:: GParamSpecOverride ) ;
1877
1875
1878
1876
impl ParamSpecOverride {
1879
1877
unsafe fn new_unchecked ( name : & str , overridden : impl AsRef < ParamSpec > ) -> ParamSpec {
@@ -1981,7 +1979,7 @@ wrapper! {
1981
1979
unref => |ptr| gobject_ffi:: g_param_spec_unref( ptr as * mut gobject_ffi:: GParamSpec ) ,
1982
1980
}
1983
1981
}
1984
- define_param_spec ! ( ParamSpecGType , gobject_ffi:: GParamSpecGType , 21 ) ;
1982
+ define_param_spec ! ( ParamSpecGType , gobject_ffi:: GParamSpecGType ) ;
1985
1983
1986
1984
impl ParamSpecGType {
1987
1985
unsafe fn new_unchecked < ' a > (
@@ -2021,7 +2019,7 @@ wrapper! {
2021
2019
unref => |ptr| gobject_ffi:: g_param_spec_unref( ptr as * mut gobject_ffi:: GParamSpec ) ,
2022
2020
}
2023
2021
}
2024
- define_param_spec ! ( ParamSpecVariant , gobject_ffi:: GParamSpecVariant , 22 ) ;
2022
+ define_param_spec ! ( ParamSpecVariant , gobject_ffi:: GParamSpecVariant ) ;
2025
2023
2026
2024
define_param_spec_default ! (
2027
2025
ParamSpecVariant ,
0 commit comments