<%!
from grust.mapping import Module
from grust.namematch import MatchList
# The GType symbols are in libgobject
ignore_gtype_functions = True
suppress_c_names = MatchList(
# Structures containing bit fields, custom-defined below
"GDate",
"GHookList",
"GIOChannel",
"GScannerConfig",
# Unions, custom-defined below
"GDoubleIEEE754",
"GFloatIEEE754",
"GMutex",
"GTokenValue",
# C compiler/ABI feature macros, varying with target
"G_HAVE_*",
"G_CAN_INLINE",
# System-specific definitions, custom-defined below
"GLIB_SYSDEF_*",
"G_GINT*_MODIFIER",
"G_GINT*_FORMAT",
"G_GUINT*_FORMAT",
"G_GSIZE_MODIFIER",
"G_GSSIZE_MODIFIER",
"G_GSIZE_FORMAT",
"G_GSSIZE_FORMAT",
"G_POLLFD_FORMAT",
"G_MODULE_SUFFIX",
"G_DIR_SEPARATOR*",
"G_SEARCHPATH_SEPARATOR*",
"GIOCondition",
"GPid",
# Macros expanding to size of types, not needed as constants in Rust
"GLIB_SIZEOF_*",
# Don't have va_list on the Rust side, no need for it either
"G_VA_COPY_AS_ARRAY",
# No use for it
"GLIB_STATIC_COMPILATION",
# Has a long double parameter
"g_assertion_message_cmpnum"
)
modules = [
Module(
cfg = 'unix',
name = 'unix',
symbols_match = MatchList(
"g_source_*_unix_fd",
"g_unix_*",
)
),
]
%>\
<%inherit file="/sys/crate.tmpl"/>
<%block name="custom_crate_attributes">\
#![allow(non_upper_case_globals)] // For G_CSET_a_2_z
</%block>
<%block name="custom_types">
#[repr(C)]
pub struct GDate([u32; 2]);
#[repr(C)]
pub struct GDoubleIEEE754(gdouble);
#[repr(C)]
pub struct GFloatIEEE754(gfloat);
#[repr(C)]
pub struct GHookList {
pub seq_id: gulong,
// Two bit fields in the C definition here
_hook_size_is_setup: u32,
pub hooks: *mut GHook,
dummy3: gpointer,
pub finalize_hook: Option<GHookFinalizeFunc>,
dummy: [gpointer; 2]
}
#[repr(C)]
pub struct GIOChannel {
ref_count :gint,
funcs: *mut GIOFuncs,
encoding: *mut gchar,
read_cd: GIConv,
write_cd: GIConv,
line_term: *mut gchar,
line_term_len: gint,
buf_size: gsize,
read_buf: *mut GString,
encoded_read_buf: *mut GString,
write_buf: *mut GString,
## 11 * size_of(usize) at this point
partial_write_buf: [gchar; 6],
// A group of bit fields in the C definition here
// to fit after partial_write_buf
flags: u16,
reserved1: gpointer,
reserved2: gpointer
}
// This happens to get the same determinants in all Unixes I have surveyed,
// and for non-Unix GLib provides the same values.
#[repr(C)]
pub enum GIOCondition {
In = 1,
Out = 4,
Pri = 2,
Err = 8,
Hup = 16,
Nval = 32
}
pub const G_IO_IN: guint = GIOCondition::In as guint;
pub const G_IO_OUT: guint = GIOCondition::Out as guint;
pub const G_IO_PRI: guint = GIOCondition::Pri as guint;
pub const G_IO_ERR: guint = GIOCondition::Err as guint;
pub const G_IO_HUP: guint = GIOCondition::Hup as guint;
pub const G_IO_NVAL: guint = GIOCondition::Nval as guint;
#[cfg(target_pointer_width = "32")]
#[repr(C)]
pub struct GMutex([guint; 2]);
// NOTE: An ILP64 target would need GMutex defined as above
#[cfg(target_pointer_width = "64")]
#[repr(C)]
pub struct GMutex(gpointer);
#[cfg(unix)]
pub type GPid = gint;
#[cfg(windows)]
pub type GPid = *mut libc::c_void;
#[repr(C)]
pub struct GScannerConfig {
pub cset_skip_characters: *mut gchar,
pub cset_identifier_first: *mut gchar,
pub cset_identifier_nth: *mut gchar,
pub cpair_comment_single: *mut gchar,
// a group of bit fields in the C definition here
flags: u32,
padding_dummy: guint
}
#[repr(C)]
pub struct GTokenValue {
v: u64
}
</%block>
<%block name="custom_constants">
pub const GLIB_SYSDEF_AF_INET: gint = libc::AF_INET;
pub const GLIB_SYSDEF_AF_INET6: gint = libc::AF_INET6;
pub const GLIB_SYSDEF_AF_UNIX: gint = libc::AF_UNIX;
mod consts {
// The BSD definitions are used everywhere,
// but we should keep an exhaustive list, just in case.
#[cfg(any(target_os = "linux",
target_os = "windows",
target_os = "macos",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "bitrig",
target_os = "netbsd",
target_os = "android",
target_os = "nacl"))]
pub mod os {
use gtypes::*;
pub const GLIB_SYSDEF_MSG_OOB: gint = 1;
pub const GLIB_SYSDEF_MSG_PEEK: gint = 2;
pub const GLIB_SYSDEF_MSG_DONTROUTE: gint = 4;
}
// ILP32, standard printf format modifiers
#[cfg(all(any(target_arch = "x86",
target_arch = "arm",
target_arch = "mips",
target_arch = "mipsel",
target_arch = "powerpc",
target_arch = "le32"),
not(windows)))]
pub mod datamodel {
pub const G_GINT16_MODIFIER: &'static [u8] = b"h\0";
pub const G_GINT16_FORMAT: &'static [u8] = b"hi\0";
pub const G_GUINT16_FORMAT: &'static [u8] = b"hu\0";
pub const G_GINT32_MODIFIER: &'static [u8] = b"\0";
pub const G_GINT32_FORMAT: &'static [u8] = b"i\0";
pub const G_GUINT32_FORMAT: &'static [u8] = b"u\0";
pub const G_GINT64_MODIFIER: &'static [u8] = b"ll\0";
pub const G_GINT64_FORMAT: &'static [u8] = b"lli\0";
pub const G_GUINT64_FORMAT: &'static [u8] = b"llu\0";
pub const G_GINTPTR_MODIFIER: &'static [u8] = b"\0";
pub const G_GINTPTR_FORMAT: &'static [u8] = b"i\0";
pub const G_GUINTPTR_FORMAT: &'static [u8] = b"u\0";
pub const G_GSIZE_MODIFIER: &'static [u8] = b"\0";
pub const G_GSSIZE_MODIFIER: &'static [u8] = b"\0";
pub const G_GSIZE_FORMAT: &'static [u8] = b"u\0";
pub const G_GSSIZE_FORMAT: &'static [u8] = b"i\0";
}
// On Win32, GLib uses MSVCRT-specific format modifiers for 64-bit types
#[cfg(all(windows, target_arch = "x86"))]
pub mod datamodel {
pub const G_GINT16_MODIFIER: &'static [u8] = b"h\0";
pub const G_GINT16_FORMAT: &'static [u8] = b"hi\0";
pub const G_GUINT16_FORMAT: &'static [u8] = b"hu\0";
pub const G_GINT32_MODIFIER: &'static [u8] = b"\0";
pub const G_GINT32_FORMAT: &'static [u8] = b"i\0";
pub const G_GUINT32_FORMAT: &'static [u8] = b"u\0";
pub const G_GINT64_MODIFIER: &'static [u8] = b"I64\0";
pub const G_GINT64_FORMAT: &'static [u8] = b"I64i\0";
pub const G_GUINT64_FORMAT: &'static [u8] = b"I64u\0";
pub const G_GINTPTR_MODIFIER: &'static [u8] = b"\0";
pub const G_GINTPTR_FORMAT: &'static [u8] = b"i\0";
pub const G_GUINTPTR_FORMAT: &'static [u8] = b"u\0";
pub const G_GSIZE_MODIFIER: &'static [u8] = b"\0";
pub const G_GSSIZE_MODIFIER: &'static [u8] = b"\0";
pub const G_GSIZE_FORMAT: &'static [u8] = b"u\0";
pub const G_GSSIZE_FORMAT: &'static [u8] = b"i\0";
}
// LP64
#[cfg(all(unix,
any(target_arch = "x86_64",
target_arch = "aarch64")))]
pub mod datamodel {
pub const G_GINT16_MODIFIER: &'static [u8] = b"h\0";
pub const G_GINT16_FORMAT: &'static [u8] = b"hi\0";
pub const G_GUINT16_FORMAT: &'static [u8] = b"hu\0";
pub const G_GINT32_MODIFIER: &'static [u8] = b"\0";
pub const G_GINT32_FORMAT: &'static [u8] = b"i\0";
pub const G_GUINT32_FORMAT: &'static [u8] = b"u\0";
pub const G_GINT64_MODIFIER: &'static [u8] = b"l\0";
pub const G_GINT64_FORMAT: &'static [u8] = b"li\0";
pub const G_GUINT64_FORMAT: &'static [u8] = b"lu\0";
pub const G_GINTPTR_MODIFIER: &'static [u8] = b"l\0";
pub const G_GINTPTR_FORMAT: &'static [u8] = b"li\0";
pub const G_GUINTPTR_FORMAT: &'static [u8] = b"lu\0";
pub const G_GSIZE_MODIFIER: &'static [u8] = b"l\0";
pub const G_GSSIZE_MODIFIER: &'static [u8] = b"l\0";
pub const G_GSIZE_FORMAT: &'static [u8] = b"lu\0";
pub const G_GSSIZE_FORMAT: &'static [u8] = b"li\0";
}
// 64-bit Windows
#[cfg(all(windows, target_arch = "x86_64"))]
pub mod datamodel {
pub const G_GINT16_MODIFIER: &'static [u8] = b"h\0";
pub const G_GINT16_FORMAT: &'static [u8] = b"hi\0";
pub const G_GUINT16_FORMAT: &'static [u8] = b"hu\0";
pub const G_GINT32_MODIFIER: &'static [u8] = b"\0";
pub const G_GINT32_FORMAT: &'static [u8] = b"i\0";
pub const G_GUINT32_FORMAT: &'static [u8] = b"u\0";
pub const G_GINT64_MODIFIER: &'static [u8] = b"I64\0";
pub const G_GINT64_FORMAT: &'static [u8] = b"I64i\0";
pub const G_GUINT64_FORMAT: &'static [u8] = b"I64u\0";
pub const G_GINTPTR_MODIFIER: &'static [u8] = b"I64\0";
pub const G_GINTPTR_FORMAT: &'static [u8] = b"I64i\0";
pub const G_GUINTPTR_FORMAT: &'static [u8] = b"I64u\0";
pub const G_GSIZE_MODIFIER: &'static [u8] = b"I64\0";
pub const G_GSSIZE_MODIFIER: &'static [u8] = b"I64\0";
pub const G_GSIZE_FORMAT: &'static [u8] = b"I64u\0";
pub const G_GSSIZE_FORMAT: &'static [u8] = b"I64i\0";
}
#[cfg(unix)]
pub mod filename {
pub const G_DIR_SEPARATOR: u8 = b'/';
pub const G_DIR_SEPARATOR_S: &'static [u8] = b"/\0";
pub const G_SEARCHPATH_SEPARATOR: u8 = b':';
pub const G_SEARCHPATH_SEPARATOR_S: &'static [u8] = b":\0";
pub const G_MODULE_SUFFIX: &'static [u8] = b"so\0";
}
#[cfg(windows)]
pub mod filename {
pub const G_DIR_SEPARATOR: u8 = b'\\';
pub const G_DIR_SEPARATOR_S: &'static [u8] = b"\\\0";
pub const G_SEARCHPATH_SEPARATOR: u8 = b';';
pub const G_SEARCHPATH_SEPARATOR_S: &'static [u8] = b";\0";
pub const G_MODULE_SUFFIX: &'static [u8] = b"dll\0";
}
#[cfg(unix)]
pub mod pollfd {
pub const G_POLLFD_FORMAT: &'static [u8] = b"%d\0";
}
#[cfg(windows)]
pub mod pollfd {
#[cfg(target_arch = "x86")]
pub const G_POLLFD_FORMAT: &'static [u8] = b"%#x\0";
#[cfg(target_arch = "x86_64")]
pub const G_POLLFD_FORMAT: &'static [u8] = b"%#I64x\0";
}
}
pub use consts::os::*;
pub use consts::datamodel::*;
pub use consts::filename::*;
pub use consts::pollfd::*;
</%block>