Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for libc::time_t and related types #1562

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/analysis/conversion_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Scalar,
/// Type implementing TryFromGlib<Error=GlibNoneError>.
Option,
/// Type implementing TryFromGlib<Err> where Err is neither GlibNoneError

Check warning on line 13 in src/analysis/conversion_type.rs

View workflow job for this annotation

GitHub Actions / build-deploy

unclosed HTML tag `Err`
/// nor GlibNoneOrInvalidError. Embeds the Error type name.
/// Defaults to the object's type for the `Ok` variant if `ok_type` is
/// `None`.
Expand Down Expand Up @@ -71,6 +71,13 @@
Filename => Self::Pointer,
OsString => Self::Pointer,
Type => Self::Scalar,
TimeT => Self::Direct,
OffT => Self::Direct,
DevT => Self::Direct,
GidT => Self::Direct,
PidT => Self::Direct,
SockLenT => Self::Direct,
UidT => Self::Direct,
None => Self::Unknown,
IntPtr => Self::Direct,
UIntPtr => Self::Direct,
Expand Down
7 changes: 7 additions & 0 deletions src/analysis/ffi_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ fn ffi_inner(env: &Env, tid: TypeId, inner: &str) -> Result {
SSize => "libc::ssize_t",
Float => "libc::c_float",
Double => "libc::c_double",
TimeT => "libc::time_t",
OffT => "libc::off_t",
DevT => "libc::dev_t",
GidT => "libc::gid_t",
PidT => "libc::pid_t",
SockLenT => "libc::socklen_t",
UidT => "libc::uid_t",
UniChar => "u32",
Utf8 => "libc::c_char",
Filename => "libc::c_char",
Expand Down
7 changes: 7 additions & 0 deletions src/codegen/sys/ffi_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ fn ffi_inner(env: &Env, tid: library::TypeId, mut inner: String) -> Result {
ULong => "c_ulong",
Size => "size_t",
SSize => "ssize_t",
TimeT => "time_t",
OffT => "off_t",
DevT => "dev_t",
GidT => "gid_t",
PidT => "pid_t",
SockLenT => "socklen_t",
UidT => "uid_t",
Float => "c_float",
Double => "c_double",
UniChar => "u32",
Expand Down
5 changes: 4 additions & 1 deletion src/codegen/sys/statics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ pub fn after_extern_crates(w: &mut dyn Write) -> Result<()> {
"#[allow(unused_imports)]",
"use libc::{c_int, c_char, c_uchar, c_float, c_uint, c_double,",
" c_short, c_ushort, c_long, c_ulong,",
" c_void, size_t, ssize_t, intptr_t, uintptr_t, FILE};",
" c_void, size_t, ssize_t, time_t, off_t, intptr_t, uintptr_t, FILE};",
"#[cfg(unix)]",
"#[allow(unused_imports)]",
"use libc::{dev_t, gid_t, pid_t, socklen_t, uid_t};",
];

write_vec(w, &v)
Expand Down
14 changes: 14 additions & 0 deletions src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ pub enum Basic {
Type,
IntPtr,
UIntPtr,
TimeT,
OffT,
DevT,
GidT,
PidT,
SockLenT,
UidT,
// Same encoding as Filename but can contains any string
// Not defined in GLib directly
OsString,
Expand Down Expand Up @@ -303,6 +310,13 @@ const BASIC: &[(&str, Basic)] = &[
// TODO: this is temporary name, change it when type added to GLib
("os_string", Basic::OsString),
("bool", Basic::Bool),
("time_t", Basic::TimeT),
("off_t", Basic::OffT),
("dev_t", Basic::DevT),
("gid_t", Basic::GidT),
("pid_t", Basic::PidT),
("socklen_t", Basic::SockLenT),
("uid_t", Basic::UidT),
];

#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
Expand Down
Loading