Thank you! (foreign non-deterministic predicates)

#1

Jan,

Thank you so much for providing swipl -d chk_secure, without it, it would have been almost impossible to debug an error in my foreign code!

Two warnings for all those who are doing non deterministic foreign predicates:

  1. don’t write code that references the term_t arguments outside of the switch statement which checks if the call is PL_FIRST_CALL, PL_REDO or PL_PRUNED.
  2. don’t use the term_t references inside the PL_PRUNED case.

Longer explanation:

If an exception is thrown (after the foreign predicate returned with one of PL_retrys), the term_t arguments are not valid anymore, and the the function is called again with control_t call type set to PL_PRUNED (this is needed to cleanup memory).
If you have code that uses the term_ts it will crash the system, eventually causing the garbage collector will bail out with a segfault.