diff --git a/swipl/src/atom.rs b/swipl/src/atom.rs index f96709a85..01c582ab1 100644 --- a/swipl/src/atom.rs +++ b/swipl/src/atom.rs @@ -148,7 +148,7 @@ unifiable! { (self:Atom, term) => { let result = unsafe { PL_unify_atom(term.term_ptr(), self.atom) }; - result != 0 + result } } @@ -169,7 +169,7 @@ where return Err(PrologError::Exception); } - let arg = if result == 0 { + let arg = if !result { None } else { let atom = unsafe { Atom::wrap(atom) }; @@ -352,7 +352,7 @@ unifiable! { ) }; - result != 0 + result } } @@ -383,7 +383,7 @@ where return Err(PrologError::Exception); } - let arg = if result == 0 { + let arg = if !result { None } else { let swipl_string_ref = unsafe { std::slice::from_raw_parts(ptr as *const u8, len) }; diff --git a/swipl/src/blob.rs b/swipl/src/blob.rs index 388f462f9..c75abafd0 100644 --- a/swipl/src/blob.rs +++ b/swipl/src/blob.rs @@ -346,7 +346,7 @@ pub unsafe fn unify_with_arc( blob_definition as *const fli::PL_blob_t as *mut fli::PL_blob_t, ); - result != 0 + result } /// Unify the term with the given Cloneable, using the given blob @@ -372,7 +372,7 @@ pub unsafe fn unify_with_cloneable( blob_definition as *const fli::PL_blob_t as *mut fli::PL_blob_t, ); - if result != 0 { + if result { std::mem::forget(cloned); true } else { @@ -395,7 +395,7 @@ pub unsafe fn get_arc_from_term( term.assert_term_handling_possible(); let mut blob_type = std::ptr::null_mut(); - if fli::PL_is_blob(term.term_ptr(), &mut blob_type) == 0 + if !fli::PL_is_blob(term.term_ptr(), &mut blob_type) || blob_definition as *const fli::PL_blob_t != blob_type { return None; @@ -409,7 +409,7 @@ pub unsafe fn get_arc_from_term( std::ptr::null_mut(), ); - if result == 0 { + if !result { None } else { Arc::increment_strong_count(data); @@ -433,7 +433,7 @@ pub unsafe fn get_cloned_from_term( term.assert_term_handling_possible(); let mut blob_type = std::ptr::null_mut(); - if fli::PL_is_blob(term.term_ptr(), &mut blob_type) == 0 + if !fli::PL_is_blob(term.term_ptr(), &mut blob_type) || blob_definition as *const fli::PL_blob_t != blob_type { return None; @@ -447,7 +447,7 @@ pub unsafe fn get_cloned_from_term( std::ptr::null_mut(), ); - if result == 0 { + if !result { None } else { let cloned = (*data).clone(); diff --git a/swipl/src/context.rs b/swipl/src/context.rs index 8d8e05fa4..932c26da0 100644 --- a/swipl/src/context.rs +++ b/swipl/src/context.rs @@ -76,7 +76,7 @@ pub(crate) unsafe fn with_cleared_exception(f: impl FnOnce() -> R) -> R { let error_term_ref = pl_default_exception(); if error_term_ref != 0 { let backup_term_ref = PL_new_term_ref(); - assert!(PL_unify(backup_term_ref, error_term_ref) != 0); + assert!(PL_unify(backup_term_ref, error_term_ref)); PL_clear_exception(); let result = f(); PL_raise_exception(backup_term_ref); @@ -117,7 +117,7 @@ impl<'a> ExceptionTerm<'a> { ) -> R { ctx.assert_activated(); let backup_term_ref = PL_new_term_ref(); - assert!(PL_unify(backup_term_ref, self.0.term_ptr()) != 0); + assert!(PL_unify(backup_term_ref, self.0.term_ptr())); let backup_term = Term::new(backup_term_ref, ctx.as_term_origin()); PL_clear_exception(); @@ -958,7 +958,7 @@ impl<'a, T: QueryableContextType> Context<'a, T> { let mut size = 0; if unsafe { - PL_get_compound_name_arity(compound.term_ptr(), std::ptr::null_mut(), &mut size) != 1 + !PL_get_compound_name_arity(compound.term_ptr(), std::ptr::null_mut(), &mut size) } { return Err(PrologError::Failure); } @@ -969,7 +969,7 @@ impl<'a, T: QueryableContextType> Context<'a, T> { let terms: [Term; N] = self.new_term_refs(); for (i, term) in terms.iter().enumerate() { unsafe { - assert!(PL_get_arg((i + 1) as i32, compound.term_ptr(), term.term_ptr()) == 1); + assert!(PL_get_arg((i + 1) as i32, compound.term_ptr(), term.term_ptr())); } } @@ -987,7 +987,7 @@ impl<'a, T: QueryableContextType> Context<'a, T> { let mut size = 0; if unsafe { - PL_get_compound_name_arity(compound.term_ptr(), std::ptr::null_mut(), &mut size) != 1 + !PL_get_compound_name_arity(compound.term_ptr(), std::ptr::null_mut(), &mut size) } { return Err(PrologError::Failure); } @@ -995,7 +995,7 @@ impl<'a, T: QueryableContextType> Context<'a, T> { let terms = self.new_term_refs_vec(size as usize); for (i, term) in terms.iter().enumerate() { unsafe { - assert!(PL_get_arg((i + 1) as i32, compound.term_ptr(), term.term_ptr()) == 1); + assert!(PL_get_arg((i + 1) as i32, compound.term_ptr(), term.term_ptr())); } } @@ -1018,7 +1018,7 @@ impl<'a, T: QueryableContextType> Context<'a, T> { let mut size = 0; if unsafe { - PL_get_compound_name_arity(compound.term_ptr(), std::ptr::null_mut(), &mut size) != 1 + !PL_get_compound_name_arity(compound.term_ptr(), std::ptr::null_mut(), &mut size) } { return Err(PrologError::Failure); } @@ -1029,7 +1029,7 @@ impl<'a, T: QueryableContextType> Context<'a, T> { let terms = self.new_term_refs_vec(count); for (i, term) in terms.iter().enumerate() { unsafe { - assert!(PL_get_arg((i + 1) as i32, compound.term_ptr(), term.term_ptr()) == 1); + assert!(PL_get_arg((i + 1) as i32, compound.term_ptr(), term.term_ptr())); } } @@ -1077,7 +1077,7 @@ impl<'a, T: QueryableContextType> Context<'a, T> { ) -> Result<(Term<'b>, Term<'b>), PrologError> { let [head, tail] = self.new_term_refs(); match unsafe { PL_unify_list(term.term_ptr(), head.term_ptr(), tail.term_ptr()) } { - 0 => { + false => { unsafe { head.reset(); } @@ -1113,7 +1113,7 @@ impl<'a, 'b, CT: QueryableContextType> Iterator for TermListIterator<'a, 'b, CT> let head = self.context.new_term_ref(); let tail = self.context.new_term_ref(); let success = - unsafe { PL_get_list(self.cur.term_ptr(), head.term_ptr(), tail.term_ptr()) != 0 }; + unsafe { PL_get_list(self.cur.term_ptr(), head.term_ptr(), tail.term_ptr()) }; if success { self.cur = tail; diff --git a/swipl/src/dict.rs b/swipl/src/dict.rs index a3384d593..576a4a319 100644 --- a/swipl/src/dict.rs +++ b/swipl/src/dict.rs @@ -247,7 +247,7 @@ unsafe impl<'a> Unifiable for DictBuilder<'a> { let dict_term = context.new_term_ref(); self.put(&dict_term); - let result = unsafe { fli::PL_unify(dict_term.term_ptr(), term.term_ptr()) != 0 }; + let result = unsafe { fli::PL_unify(dict_term.term_ptr(), term.term_ptr()) }; unsafe { dict_term.reset(); }; @@ -271,7 +271,7 @@ impl<'a> Term<'a> { let term = context.new_term_ref(); let get_result = - unsafe { fli::PL_get_dict_key(key_atom, self.term_ptr(), term.term_ptr()) != 0 }; + unsafe { fli::PL_get_dict_key(key_atom, self.term_ptr(), term.term_ptr()) }; std::mem::drop(alloc); // purely to get rid of the never-read warning let result = if unsafe { fli::pl_default_exception() != 0 } { @@ -304,7 +304,7 @@ impl<'a> Term<'a> { let (key_atom, alloc) = key.atom_ptr(); let result = - unsafe { fli::PL_get_dict_key(key_atom, self.term_ptr(), term.term_ptr()) != 0 }; + unsafe { fli::PL_get_dict_key(key_atom, self.term_ptr(), term.term_ptr()) }; std::mem::drop(alloc); // purely to get rid of the never-read warning if unsafe { fli::pl_default_exception() != 0 } { @@ -329,7 +329,7 @@ impl<'a> Term<'a> { pub fn get_dict_tag(&self) -> PrologResult> { self.assert_term_handling_possible(); - if unsafe { fli::PL_is_dict(self.term_ptr()) == 0 } { + if unsafe { !fli::PL_is_dict(self.term_ptr()) } { Err(PrologError::Failure) } else if let Some(atom) = attempt_opt(self.get_arg(1))? { Ok(Some(atom)) @@ -352,7 +352,7 @@ impl<'a> Term<'a> { panic!("terms being unified are not part of the same engine"); } - if unsafe { fli::PL_is_dict(self.term_ptr()) == 0 } { + if unsafe { !fli::PL_is_dict(self.term_ptr()) } { Err(PrologError::Failure) } else { self.unify_arg(1, term) @@ -362,7 +362,7 @@ impl<'a> Term<'a> { /// Returns true if this term reference holds a dictionary. pub fn is_dict(&self) -> bool { self.assert_term_handling_possible(); - unsafe { fli::PL_is_dict(self.term_ptr()) != 0 } + unsafe { fli::PL_is_dict(self.term_ptr()) } } } diff --git a/swipl/src/functor.rs b/swipl/src/functor.rs index c7f55d9bf..ac664cf01 100644 --- a/swipl/src/functor.rs +++ b/swipl/src/functor.rs @@ -105,7 +105,7 @@ unifiable! { (self: Functor, term) => { let result = unsafe {PL_unify_compound(term.term_ptr(), self.functor)}; - result != 0 + result } } @@ -114,7 +114,7 @@ term_getable! { let mut functor = 0; let result = unsafe { PL_get_functor(term.term_ptr(), &mut functor) }; - if result == 0 { + if !result { None } else { diff --git a/swipl/src/init.rs b/swipl/src/init.rs index 65777adc3..2402cb951 100644 --- a/swipl/src/init.rs +++ b/swipl/src/init.rs @@ -30,7 +30,7 @@ pub fn activate_main() -> EngineActivation<'static> { /// Check if SWI-Prolog has been initialized. pub fn is_swipl_initialized() -> bool { - unsafe { PL_is_initialised(std::ptr::null_mut(), std::ptr::null_mut()) != 0 } + unsafe { PL_is_initialised(std::ptr::null_mut(), std::ptr::null_mut()) } } /// Panic if SWI-Prolog has not been initialized. @@ -96,7 +96,7 @@ pub fn initialize_swipl_with_state(state: &'static [u8]) -> Option PrologResult<()> { term.assert_term_handling_possible(); - unsafe { into_prolog_result(fli::PL_recorded(self.record, term.term_ptr()) != 0) } + unsafe { into_prolog_result(fli::PL_recorded(self.record, term.term_ptr())) } } } @@ -77,7 +77,7 @@ unifiable! { let result = fli::PL_unify(term.term_ptr(), extra_term); fli::PL_reset_term_refs(extra_term); - result != 0 + result } } } diff --git a/swipl/src/stream.rs b/swipl/src/stream.rs index da2714090..55e20cf23 100644 --- a/swipl/src/stream.rs +++ b/swipl/src/stream.rs @@ -72,7 +72,7 @@ term_getable! { // origin. (WritablePrologStream<'a>, term) => { let mut stream: *mut fli::IOSTREAM = std::ptr::null_mut(); - if unsafe { fli::PL_get_stream(term.term_ptr(), &mut stream, fli::SH_OUTPUT|fli::SH_UNLOCKED|fli::SH_NOPAIR) } != 0 { + if unsafe { fli::PL_get_stream(term.term_ptr(), &mut stream, fli::SH_OUTPUT|fli::SH_UNLOCKED|fli::SH_NOPAIR) } { Some(unsafe {WritablePrologStream::new(stream) }) } else { @@ -273,7 +273,7 @@ term_getable! { // origin. (ReadablePrologStream<'a>, term) => { let mut stream: *mut fli::IOSTREAM = std::ptr::null_mut(); - if unsafe { fli::PL_get_stream(term.term_ptr(), &mut stream, fli::SH_INPUT|fli::SH_UNLOCKED|fli::SH_NOPAIR) } != 0 { + if unsafe { fli::PL_get_stream(term.term_ptr(), &mut stream, fli::SH_INPUT|fli::SH_UNLOCKED|fli::SH_NOPAIR) } { Some(unsafe {ReadablePrologStream::new(stream) }) } else { diff --git a/swipl/src/term/mod.rs b/swipl/src/term/mod.rs index a7ad98cc3..0f7cd7a02 100644 --- a/swipl/src/term/mod.rs +++ b/swipl/src/term/mod.rs @@ -120,25 +120,25 @@ impl<'a> Term<'a> { /// Returns true if this term reference holds a variable. pub fn is_var(&self) -> bool { self.assert_term_handling_possible(); - unsafe { PL_is_variable(self.term) != 0 } + unsafe { PL_is_variable(self.term) } } /// Returns true if this term reference holds an atom. pub fn is_atom(&self) -> bool { self.assert_term_handling_possible(); - unsafe { PL_is_atom(self.term) != 0 } + unsafe { PL_is_atom(self.term) } } /// Returns true if this term reference holds a string. pub fn is_string(&self) -> bool { self.assert_term_handling_possible(); - unsafe { PL_is_string(self.term) != 0 } + unsafe { PL_is_string(self.term) } } /// Returns true if this term reference holds an integer. pub fn is_integer(&self) -> bool { self.assert_term_handling_possible(); - unsafe { PL_is_integer(self.term) != 0 } + unsafe { PL_is_integer(self.term) } } /// Reset terms created after this term, including this term itself. @@ -210,7 +210,7 @@ impl<'a> Term<'a> { let arg = unsafe { Term::new(arg_ref, self.origin.clone()) }; let mut result2 = Err(PrologError::Failure); - if result != 0 { + if result { result2 = arg.unify(unifiable); } @@ -321,7 +321,7 @@ impl<'a> Term<'a> { let arg = unsafe { Term::new(arg_ref, self.origin.clone()) }; let mut result2 = Err(PrologError::Failure); - if result != 0 { + if result { result2 = arg.get(); } @@ -356,7 +356,7 @@ impl<'a> Term<'a> { } let arg = unsafe { Term::new(arg_ref, self.origin.clone()) }; - let result2 = if result != 0 { + let result2 = if result { arg.get_ex() } else { let context = unsafe { unmanaged_engine_context() }; @@ -393,7 +393,7 @@ impl<'a> Term<'a> { return Err(PrologError::Exception); } - let arg = if result == 0 { + let arg = if !result { None } else { let swipl_string_ref = unsafe { std::slice::from_raw_parts(ptr as *const u8, len) }; @@ -442,7 +442,7 @@ impl<'a> Term<'a> { return Err(PrologError::Exception); } - let arg = if result == 0 { + let arg = if !result { None } else { let swipl_string_ref = unsafe { std::slice::from_raw_parts(ptr as *const u8, len) }; @@ -779,7 +779,7 @@ unifiable! { let result = unsafe { PL_unify(self.term, term.term) }; // TODO we should actually properly test for an exception here. - result != 0 + result } } @@ -801,7 +801,7 @@ unifiable! { }; let result = unsafe { PL_unify_bool(term.term, num) }; - result != 0 + result } } @@ -809,7 +809,7 @@ term_getable! { (bool, term) => { let mut out = 0; let result = unsafe { PL_get_bool(term.term, &mut out) }; - if result == 0 { + if !result { None } else { @@ -857,7 +857,7 @@ unifiable! { false } else { - result != 0 + result } })} } @@ -865,7 +865,7 @@ unifiable! { term_getable! { (u64, "integer", term) => { - if unsafe { PL_is_integer(term.term) == 0 } { + if unsafe { !PL_is_integer(term.term) } { return None; } @@ -892,7 +892,7 @@ term_getable! { error_term.reset(); None } - else if result == 0 { + else if !result { None } else { @@ -912,7 +912,7 @@ unifiable! { (self:i64, term) => { let result = unsafe { PL_unify_int64(term.term, *self) }; - result != 0 + result } } @@ -920,7 +920,7 @@ term_getable! { (i64, "integer", term) => { let mut out = 0; let result = unsafe { PL_get_int64(term.term, &mut out) }; - if result == 0 { + if !result { None } else { @@ -939,7 +939,7 @@ unifiable! { (self:f64, term) => { let result = unsafe { PL_unify_float(term.term, *self) }; - result != 0 + result } } @@ -947,7 +947,7 @@ term_getable! { (f64, "float", term) => { let mut out = 0.0; let result = unsafe { PL_get_float(term.term, &mut out) }; - if result == 0 { + if !result { None } else { @@ -972,7 +972,7 @@ unifiable! { ) }; - result != 0 + result } } @@ -986,7 +986,7 @@ unifiable! { ) }; - result != 0 + result } } @@ -1028,7 +1028,7 @@ unifiable! { (self: &[u8], term) => { let result = unsafe { PL_unify_string_nchars(term.term_ptr(), self.len(), self.as_ptr() as *const std::os::raw::c_char) }; - result != 0 + result } } @@ -1037,7 +1037,7 @@ term_getable! { let mut string_ptr = std::ptr::null_mut(); let mut len = 0; let result = unsafe { PL_get_string(term.term_ptr(), &mut string_ptr, &mut len) }; - if result == 0 { + if !result { return None; } @@ -1062,7 +1062,7 @@ unifiable! { (self:Nil, term) => { let result = unsafe { PL_unify_nil(term.term_ptr()) }; - result != 0 + result } } @@ -1070,7 +1070,7 @@ term_getable! { (Nil, "list", term) => { let result = unsafe { PL_get_nil(term.term_ptr()) }; - match result != 0 { + match result { true => Some(Nil), false => None } @@ -1109,7 +1109,7 @@ where // if list unification fails, or head can not be unified with current term, // return false early. // note: || is short-circuiting OR - if unsafe { PL_unify_list(list.term_ptr(), head.term_ptr(), tail.term_ptr()) == 0 } + if unsafe { !PL_unify_list(list.term_ptr(), head.term_ptr(), tail.term_ptr()) } || head.unify(t).is_err() { return false; @@ -1125,7 +1125,7 @@ where frame2.close(); } - let success = unsafe { PL_unify_nil(list.term_ptr()) != 0 }; + let success = unsafe { PL_unify_nil(list.term_ptr()) }; frame.close(); success @@ -1147,7 +1147,7 @@ unsafe impl TermGetable for Vec { list.unify(term).unwrap(); let mut success = true; loop { - if unsafe { PL_get_nil(list.term_ptr()) != 0 } { + if unsafe { PL_get_nil(list.term_ptr()) } { break; } @@ -1155,7 +1155,7 @@ unsafe impl TermGetable for Vec { let head = frame2.new_term_ref(); let tail = frame2.new_term_ref(); success = - unsafe { PL_get_list(list.term_ptr(), head.term_ptr(), tail.term_ptr()) != 0 }; + unsafe { PL_get_list(list.term_ptr(), head.term_ptr(), tail.term_ptr()) }; if !success { break; diff --git a/swipl/src/text.rs b/swipl/src/text.rs index 4ecdb1d31..8a1ff8394 100644 --- a/swipl/src/text.rs +++ b/swipl/src/text.rs @@ -41,7 +41,7 @@ term_getable! { flags) }; - if result == 0 { + if !result { None } else {