Skip to content

Commit

Permalink
remove g_param_spec_types link alltogether
Browse files Browse the repository at this point in the history
  • Loading branch information
eerii committed Sep 18, 2024
1 parent df58d90 commit cb02342
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 88 deletions.
2 changes: 1 addition & 1 deletion glib/gobject-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ v2_82 = ["v2_80"]
name = "gobject_sys"

[package]
build = "build_manual.rs"
build = "build.rs"
description = "FFI bindings to libgobject-2.0"
keywords = ["gobject", "ffi", "gtk-rs", "gnome"]
name = "gobject-sys"
Expand Down
23 changes: 0 additions & 23 deletions glib/gobject-sys/build_manual.rs

This file was deleted.

4 changes: 0 additions & 4 deletions glib/gobject-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@

use glib_sys as glib;

mod manual;

pub use manual::*;

#[allow(unused_imports)]
use libc::{
c_char, c_double, c_float, c_int, c_long, c_short, c_uchar, c_uint, c_ulong, c_ushort, c_void,
Expand Down
31 changes: 0 additions & 31 deletions glib/gobject-sys/src/manual.rs

This file was deleted.

56 changes: 27 additions & 29 deletions glib/src/param_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

use std::{
char::CharTryFromError,
collections::HashMap,
ffi::CStr,
num::{NonZeroI32, NonZeroI64, NonZeroI8, NonZeroU32, NonZeroU64, NonZeroU8},
path::{Path, PathBuf},
sync::{LazyLock, Mutex},
};

use crate::{
Expand Down Expand Up @@ -296,14 +298,20 @@ pub unsafe trait ParamSpecType:
{
}

static G_PARAM_SPEC_TYPES: LazyLock<Mutex<HashMap<&'static str, Type>>> =
LazyLock::new(|| Mutex::new(HashMap::new()));

macro_rules! define_param_spec {
($rust_type:ident, $ffi_type:path, $rust_type_offset:expr) => {
($rust_type:ident, $ffi_type:path) => {
impl StaticType for $rust_type {
#[inline]
fn static_type() -> Type {
unsafe {
from_glib(gobject_sys::g_param_spec_types_get_type($rust_type_offset))
}
let name = stringify!($rust_type);
*G_PARAM_SPEC_TYPES.lock().unwrap().entry(name).or_insert_with_key(|name| {
let name = format!("GParam{}", name.split("Spec").last().unwrap_or_default());
let name_c = std::ffi::CString::new(name).unwrap();
unsafe { from_glib(gobject_ffi::g_type_from_name(name_c.as_ptr())) }
})
}
}

Expand Down Expand Up @@ -551,8 +559,8 @@ macro_rules! define_param_spec_min_max {
}

macro_rules! define_param_spec_numeric {
($rust_type:ident, $ffi_type:path, $value_type:ty, $rust_type_offset:expr, $ffi_fun:ident) => {
define_param_spec!($rust_type, $ffi_type, $rust_type_offset);
($rust_type:ident, $ffi_type:path, $value_type:ty, $ffi_fun:ident) => {
define_param_spec!($rust_type, $ffi_type);
define_param_spec_default!($rust_type, $ffi_type, $value_type, |x| x);
define_param_spec_min_max!($rust_type, $ffi_type, $value_type);

Expand Down Expand Up @@ -782,7 +790,6 @@ define_param_spec_numeric!(
ParamSpecChar,
gobject_ffi::GParamSpecChar,
i8,
0,
g_param_spec_char
);

Expand All @@ -802,7 +809,6 @@ define_param_spec_numeric!(
ParamSpecUChar,
gobject_ffi::GParamSpecUChar,
u8,
1,
g_param_spec_uchar
);

Expand All @@ -823,7 +829,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecBoolean, gobject_ffi::GParamSpecBoolean, 2);
define_param_spec!(ParamSpecBoolean, gobject_ffi::GParamSpecBoolean);

define_param_spec_default!(
ParamSpecBoolean,
Expand Down Expand Up @@ -874,7 +880,6 @@ define_param_spec_numeric!(
ParamSpecInt,
gobject_ffi::GParamSpecInt,
i32,
3,
g_param_spec_int
);

Expand All @@ -894,7 +899,6 @@ define_param_spec_numeric!(
ParamSpecUInt,
gobject_ffi::GParamSpecUInt,
u32,
4,
g_param_spec_uint
);

Expand All @@ -919,7 +923,6 @@ define_param_spec_numeric!(
ParamSpecLong,
gobject_ffi::GParamSpecLong,
libc::c_long,
5,
g_param_spec_long
);

Expand All @@ -944,7 +947,6 @@ define_param_spec_numeric!(
ParamSpecULong,
gobject_ffi::GParamSpecULong,
libc::c_ulong,
6,
g_param_spec_ulong
);

Expand All @@ -969,7 +971,6 @@ define_param_spec_numeric!(
ParamSpecInt64,
gobject_ffi::GParamSpecInt64,
i64,
7,
g_param_spec_int64
);

Expand All @@ -994,7 +995,6 @@ define_param_spec_numeric!(
ParamSpecUInt64,
gobject_ffi::GParamSpecUInt64,
u64,
8,
g_param_spec_uint64
);

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

impl ParamSpecUnichar {
Expand Down Expand Up @@ -1057,7 +1057,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecEnum, gobject_ffi::GParamSpecEnum, 10);
define_param_spec!(ParamSpecEnum, gobject_ffi::GParamSpecEnum);

impl ParamSpecEnum {
unsafe fn new_unchecked<'a>(
Expand Down Expand Up @@ -1201,7 +1201,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecFlags, gobject_ffi::GParamSpecFlags, 11);
define_param_spec!(ParamSpecFlags, gobject_ffi::GParamSpecFlags);

impl ParamSpecFlags {
unsafe fn new_unchecked<'a>(
Expand Down Expand Up @@ -1344,7 +1344,6 @@ define_param_spec_numeric!(
ParamSpecFloat,
gobject_ffi::GParamSpecFloat,
f32,
12,
g_param_spec_float
);

Expand All @@ -1369,7 +1368,6 @@ define_param_spec_numeric!(
ParamSpecDouble,
gobject_ffi::GParamSpecDouble,
f64,
13,
g_param_spec_double
);

Expand All @@ -1390,7 +1388,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecString, gobject_ffi::GParamSpecString, 14);
define_param_spec!(ParamSpecString, gobject_ffi::GParamSpecString);

define_param_spec_default!(
ParamSpecString,
Expand Down Expand Up @@ -1499,7 +1497,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecParam, gobject_ffi::GParamSpecParam, 15);
define_param_spec!(ParamSpecParam, gobject_ffi::GParamSpecParam);

impl ParamSpecParam {
unsafe fn new_unchecked<'a>(
Expand Down Expand Up @@ -1541,7 +1539,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecBoxed, gobject_ffi::GParamSpecBoxed, 16);
define_param_spec!(ParamSpecBoxed, gobject_ffi::GParamSpecBoxed);

impl ParamSpecBoxed {
unsafe fn new_unchecked<'a>(
Expand Down Expand Up @@ -1629,7 +1627,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecPointer, gobject_ffi::GParamSpecPointer, 17);
define_param_spec!(ParamSpecPointer, gobject_ffi::GParamSpecPointer);

impl ParamSpecPointer {
unsafe fn new_unchecked<'a>(
Expand Down Expand Up @@ -1665,7 +1663,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecValueArray, gobject_ffi::GParamSpecValueArray, 18);
define_param_spec!(ParamSpecValueArray, gobject_ffi::GParamSpecValueArray);

impl ParamSpecValueArray {
unsafe fn new_unchecked<'a>(
Expand Down Expand Up @@ -1785,7 +1783,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecObject, gobject_ffi::GParamSpecObject, 19);
define_param_spec!(ParamSpecObject, gobject_ffi::GParamSpecObject);

impl ParamSpecObject {
unsafe fn new_unchecked<'a>(
Expand Down Expand Up @@ -1873,7 +1871,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecOverride, gobject_ffi::GParamSpecOverride, 20);
define_param_spec!(ParamSpecOverride, gobject_ffi::GParamSpecOverride);

impl ParamSpecOverride {
unsafe fn new_unchecked(name: &str, overridden: impl AsRef<ParamSpec>) -> ParamSpec {
Expand Down Expand Up @@ -1981,7 +1979,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecGType, gobject_ffi::GParamSpecGType, 21);
define_param_spec!(ParamSpecGType, gobject_ffi::GParamSpecGType);

impl ParamSpecGType {
unsafe fn new_unchecked<'a>(
Expand Down Expand Up @@ -2021,7 +2019,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecVariant, gobject_ffi::GParamSpecVariant, 22);
define_param_spec!(ParamSpecVariant, gobject_ffi::GParamSpecVariant);

define_param_spec_default!(
ParamSpecVariant,
Expand Down

0 comments on commit cb02342

Please sign in to comment.