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

updated int -> bool #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions swipl/src/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ unifiable! {
(self:Atom, term) => {
let result = unsafe { PL_unify_atom(term.term_ptr(), self.atom) };

result != 0
result
}
}

Expand All @@ -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) };
Expand Down Expand Up @@ -352,7 +352,7 @@ unifiable! {
)
};

result != 0
result
}
}

Expand Down Expand Up @@ -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) };
Expand Down
12 changes: 6 additions & 6 deletions swipl/src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ pub unsafe fn unify_with_arc<T>(
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
Expand All @@ -372,7 +372,7 @@ pub unsafe fn unify_with_cloneable<T: Clone + Sized + Unpin>(
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 {
Expand All @@ -395,7 +395,7 @@ pub unsafe fn get_arc_from_term<T>(
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;
Expand All @@ -409,7 +409,7 @@ pub unsafe fn get_arc_from_term<T>(
std::ptr::null_mut(),
);

if result == 0 {
if !result {
None
} else {
Arc::increment_strong_count(data);
Expand All @@ -433,7 +433,7 @@ pub unsafe fn get_cloned_from_term<T: Clone + Sized + Unpin>(
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;
Expand All @@ -447,7 +447,7 @@ pub unsafe fn get_cloned_from_term<T: Clone + Sized + Unpin>(
std::ptr::null_mut(),
);

if result == 0 {
if !result {
None
} else {
let cloned = (*data).clone();
Expand Down
20 changes: 10 additions & 10 deletions swipl/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub(crate) unsafe fn with_cleared_exception<R>(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);
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}
Expand All @@ -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()));
}
}

Expand All @@ -987,15 +987,15 @@ 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);
}

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()));
}
}

Expand All @@ -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);
}
Expand All @@ -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()));
}
}

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions swipl/src/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand All @@ -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 } {
Expand Down Expand Up @@ -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 } {
Expand All @@ -329,7 +329,7 @@ impl<'a> Term<'a> {
pub fn get_dict_tag(&self) -> PrologResult<Option<Atom>> {
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))
Expand All @@ -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)
Expand All @@ -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()) }
}
}

Expand Down
4 changes: 2 additions & 2 deletions swipl/src/functor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ unifiable! {
(self: Functor, term) => {
let result = unsafe {PL_unify_compound(term.term_ptr(), self.functor)};

result != 0
result
}
}

Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions swipl/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -96,7 +96,7 @@ pub fn initialize_swipl_with_state(state: &'static [u8]) -> Option<EngineActivat
// https://www.swi-prolog.org/pldoc/doc_for?object=c(%27PL_set_resource_db_mem%27)
let result = unsafe { PL_set_resource_db_mem(state.as_ptr(), state.len()) };

if result != TRUE as i32 {
if !result {
return None;
}

Expand Down Expand Up @@ -207,5 +207,5 @@ pub unsafe fn register_foreign_in_module(
Some(converted_function_ptr),
flags.try_into().unwrap(),
c_meta.map(|m| m.as_ptr()).unwrap_or_else(std::ptr::null),
) == 1
)
}
4 changes: 2 additions & 2 deletions swipl/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Record {
/// Copy the recorded term into the given term reference.
pub fn recorded(&self, term: &Term) -> 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())) }
}
}

Expand Down Expand Up @@ -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
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions swipl/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Loading