[rust] remove `NcSignalSet`

- hopefully solved the remaining bug of #1339
pull/1843/head
joseLuís 3 years ago
parent 4aeab4e987
commit 504dcaad59

@ -844,24 +844,6 @@ pub use ffi::{
NCPALETTESIZE,
};
// sig -------------------------------------------------------------------------
//
// already wrapped:
//
// // structs
// sigset_t,
// sigaction,
//
// // functions
// sigaddset,
// sigdelset,
// sigemptyset,
// sigfillset,
// sigismember,
// sigpending,
// sigprocmask,
// sigsuspend,
// fade callback ---------------------------------------------------------------
//
// already wrapped:

@ -2,7 +2,6 @@
use core::ptr::{null, null_mut};
use crate::ffi::sigset_t;
use crate::{
cstring, error, error_ref_mut, rstring, NcAlign, NcBlitter, NcCapabilities, NcChannels,
NcComponent, NcDim, NcDirect, NcDirectFlags, NcError, NcInput, NcOffset, NcPaletteIndex,
@ -556,33 +555,16 @@ impl NcDirect {
/// Provide a None `time` to block at length, a `time` of 0 for non-blocking
/// operation, and otherwise a timespec to bound blocking.
///
/// Signals in sigmask (less several we handle internally) will be atomically
/// masked and unmasked per [ppoll(2)](https://linux.die.net/man/2/ppoll).
///
/// `*sigmask` should generally contain all signals.
///
/// *C style function: [ncdirect_getc()][crate::ncdirect_getc].*
//
// CHECK returns 0 on a timeout.
pub fn getc(
&mut self,
time: Option<NcTime>,
sigmask: Option<&mut sigset_t>,
input: Option<&mut NcInput>,
) -> NcResult<char> {
pub fn getc(&mut self, time: Option<NcTime>, input: Option<&mut NcInput>) -> NcResult<char> {
let ntime;
if let Some(time) = time {
ntime = &time as *const _;
} else {
ntime = null();
}
let nsigmask;
if let Some(sigmask) = sigmask {
nsigmask = sigmask as *mut _;
} else {
nsigmask = null_mut() as *mut _;
}
let ninput;
if let Some(input) = input {
ninput = input as *mut _;
@ -590,7 +572,7 @@ impl NcDirect {
ninput = null_mut();
}
let c = unsafe {
core::char::from_u32_unchecked(crate::ncdirect_getc(self, ntime, nsigmask, ninput))
core::char::from_u32_unchecked(crate::ncdirect_getc(self, ntime, null_mut(), ninput))
};
if c as u32 as i32 == NCRESULT_ERR {
return Err(NcError::new());

@ -1,10 +1,10 @@
//! `ncdirect_*` reimplemented functions.
use core::ptr::null;
use core::ptr::{null, null_mut};
use crate::{
cstring, NcCapabilities, NcChannels, NcComponent, NcDim, NcDirect, NcInput, NcIntResult, NcRgb,
NcSignalSet, NcTime,
NcTime,
};
/// Can we directly specify RGB values per cell, or only use palettes?
@ -68,11 +68,7 @@ pub fn ncdirect_capabilities(ncd: &NcDirect) -> NcCapabilities {
// TODO: use from_u32 & return Option.
#[inline]
pub fn ncdirect_getc_blocking(ncd: &mut NcDirect, input: &mut NcInput) -> char {
unsafe {
let mut sigmask = NcSignalSet::new();
sigmask.emptyset();
core::char::from_u32_unchecked(crate::ncdirect_getc(ncd, null(), &mut sigmask, input))
}
unsafe { core::char::from_u32_unchecked(crate::ncdirect_getc(ncd, null(), null_mut(), input)) }
}
///
@ -84,10 +80,8 @@ pub fn ncdirect_getc_blocking(ncd: &mut NcDirect, input: &mut NcInput) -> char {
#[inline]
pub fn ncdirect_getc_nblock(ncd: &mut NcDirect, input: &mut NcInput) -> char {
unsafe {
let mut sigmask = NcSignalSet::new();
sigmask.fillset();
let ts = NcTime::new();
core::char::from_u32_unchecked(crate::ncdirect_getc(ncd, &ts, &mut sigmask, input))
core::char::from_u32_unchecked(crate::ncdirect_getc(ncd, &ts, null_mut(), input))
}
}

@ -130,7 +130,6 @@ mod palette;
mod pixel;
mod plane;
mod resizecb;
mod signal;
mod stats;
mod time;
mod visual;
@ -153,7 +152,6 @@ pub use pixel::*;
pub use plane::*;
pub use r#box::*;
pub use resizecb::*;
pub use signal::*;
pub use stats::*;
pub use time::*;
pub use visual::*;

@ -4,9 +4,8 @@ use core::ptr::{null, null_mut};
use crate::{
cstring, error, error_ref_mut, notcurses_init, rstring, Nc, NcAlign, NcBlitter, NcChannels,
NcDim, NcError, NcFile, NcInput, NcLogLevel, NcOptions, NcPlane, NcResult, NcScale,
NcSignalSet, NcStats, NcStyle, NcTime, NCOPTION_NO_ALTERNATE_SCREEN, NCOPTION_SUPPRESS_BANNERS,
NCRESULT_ERR,
NcDim, NcError, NcFile, NcInput, NcLogLevel, NcOptions, NcPlane, NcResult, NcScale, NcStats,
NcStyle, NcTime, NCOPTION_NO_ALTERNATE_SCREEN, NCOPTION_SUPPRESS_BANNERS, NCRESULT_ERR,
};
/// # `NcOptions` Constructors
@ -323,18 +322,8 @@ impl Nc {
/// Provide a None `time` to block at length, a `time` of 0 for non-blocking
/// operation, and otherwise a timespec to bound blocking.
///
/// Signals in sigmask (less several we handle internally) will be atomically
/// masked and unmasked per [ppoll(2)](https://linux.die.net/man/2/ppoll).
///
/// `*sigmask` should generally contain all signals.
///
/// *C style function: [notcurses_getc()][crate::notcurses_getc].*
pub fn getc(
&mut self,
time: Option<NcTime>,
sigmask: Option<&mut NcSignalSet>,
input: Option<&mut NcInput>,
) -> NcResult<char> {
pub fn getc(&mut self, time: Option<NcTime>, input: Option<&mut NcInput>) -> NcResult<char> {
let ntime;
if let Some(time) = time {
ntime = &time as *const _;
@ -342,12 +331,6 @@ impl Nc {
ntime = null();
}
let nsigmask;
if let Some(sigmask) = sigmask {
nsigmask = sigmask as *mut _;
} else {
nsigmask = null_mut() as *mut _;
}
let ninput;
if let Some(input) = input {
ninput = input as *mut _;
@ -355,7 +338,7 @@ impl Nc {
ninput = null_mut();
}
let c = unsafe {
core::char::from_u32_unchecked(crate::notcurses_getc(self, ntime, nsigmask, ninput))
core::char::from_u32_unchecked(crate::notcurses_getc(self, ntime, null_mut(), ninput))
};
if c as u32 as i32 == NCRESULT_ERR {
return Err(NcError::new());

@ -3,8 +3,8 @@
use core::ptr::{null, null_mut};
use crate::{
Nc, NcAlign, NcDim, NcError, NcInput, NcOffset, NcPlane, NcResult, NcSignalSet, NcTime,
NCALIGN_CENTER, NCALIGN_LEFT, NCALIGN_RIGHT, NCRESULT_MAX,
Nc, NcAlign, NcDim, NcError, NcInput, NcOffset, NcPlane, NcResult, NcTime, NCALIGN_CENTER,
NCALIGN_LEFT, NCALIGN_RIGHT, NCRESULT_MAX,
};
/// Returns the offset into `availcols` at which `cols` ought be output given
@ -40,13 +40,11 @@ pub fn notcurses_align(availcols: NcDim, align: NcAlign, cols: NcDim) -> NcOffse
#[inline]
pub fn notcurses_getc_nblock(nc: &mut Nc, input: &mut NcInput) -> char {
unsafe {
let mut sigmask = NcSignalSet::new();
sigmask.fillset();
let ts = NcTime {
tv_sec: 0,
tv_nsec: 0,
};
core::char::from_u32_unchecked(crate::notcurses_getc(nc, &ts, &sigmask, input))
core::char::from_u32_unchecked(crate::notcurses_getc(nc, &ts, null_mut(), input))
}
}
@ -66,9 +64,7 @@ pub fn notcurses_getc_blocking(nc: &mut Nc, input: Option<&mut NcInput>) -> char
input_ptr = null_mut();
}
unsafe {
let mut sigmask = NcSignalSet::new();
sigmask.emptyset();
core::char::from_u32_unchecked(crate::notcurses_getc(nc, null(), &sigmask, input_ptr))
core::char::from_u32_unchecked(crate::notcurses_getc(nc, null(), null_mut(), input_ptr))
}
}

@ -1,67 +0,0 @@
//! `NcSigSet`
use crate::NcIntResult;
/// A wrapper over
/// [sigset_t](https://www.gnu.org/software/libc/manual/html_node/Signal-Sets.html).
//
// Expected by [`notcurses_getc`], [`notcurses_getc_nblock`],
// [`ncdirect_getc`] & [`ncdirect_getc_nblock`], that can't use libc::sigset_t
pub type NcSignalSet = crate::bindings::ffi::sigset_t;
impl NcSignalSet {
/// New NcSignalSet.
pub fn new() -> Self {
// https://github.com/dankamongmen/notcurses/issues/1339
#[cfg(any(target_arch = "armv7l", target_arch = "i686"))]
return Self { __val: [0; 32] };
#[cfg(not(any(target_arch = "armv7l", target_arch = "i686")))]
return Self { __val: [0; 16] };
}
/// Adds `signum` to this set.
pub fn addset(&mut self, signum: i32) -> NcIntResult {
unsafe { crate::bindings::ffi::sigaddset(self, signum) }
}
/// Removes `signum` from this set.
pub fn delset(&mut self, signum: i32) -> NcIntResult {
unsafe { crate::bindings::ffi::sigdelset(self, signum) }
}
/// Clears all signals from this set.
pub fn emptyset(&mut self) -> NcIntResult {
unsafe { crate::bindings::ffi::sigemptyset(self) }
}
/// Sets all signals in this set.
pub fn fillset(&mut self) -> NcIntResult {
unsafe { crate::bindings::ffi::sigfillset(self) }
}
/// Is `signum` a member of this set?
pub fn ismember(&self, signum: i32) -> bool {
if unsafe { crate::bindings::ffi::sigismember(self, signum) } == 1 {
return true;
}
false
}
/// Puts in this set all signals that are blocked and waiting to be delivered.
pub fn pending(&mut self) -> NcIntResult {
unsafe { crate::bindings::ffi::sigpending(self) }
}
/// Gets and/or changes the set of blocked signals.
//
// https://linux.die.net/man/2/sigprocmask
pub fn procmask(how: i32, set: &NcSignalSet, old_set: &mut NcSignalSet) -> NcIntResult {
unsafe { crate::bindings::ffi::sigprocmask(how, set, old_set) }
}
/// Changes the set of blocked signals to the ones in this set,
/// waits until a signal arrives, and restores the set of blocked signals.
pub fn suspend(&self) -> NcIntResult {
unsafe { crate::bindings::ffi::sigsuspend(self) }
}
}
Loading…
Cancel
Save