It all smells a bit messy After all, we are not talking about a lot of functions if we consider the groups with consistent naming ādoneā, no? WUNUSED also gives a clue, though I see quite a few more functions should have it. That could be fixed.
Iām not against, but I start getting the impression this is getting ugly and of limited value
Not sure. Janus is surely a lot more powerful and also faster, but pyswip can be used withour compiling anything, so it can be easier to install for Python users (depending on platform, etc.)
The PL_is_*() functions are consistent (and obvious); but the rest arenāt (e.g., some PL_put_*() canāt return an error and some can).
Hereās the breakdown (according to the mark-up I did in SWI-cpp2-plx.h, which could be slightly wrong):
142 āas-isā (of which 52 are for bool)
62 - false is an error
62 - false is failure or an error
29 - no return code
(I havenāt updated SWI-cpp2-plx.h with the latest changes from int to bool, so I canāt give a breakdown of error for bool and not-bool)
In addition, there some difficult to describe situation, such as that PL_new_term_ref() and PL_new_term_refs() can be called up to 10 times without checking the return code.If PL_new_term_ref() is marked WUNUSED, then the compiler can be quietened by (void)PL_new_term_ref(...)
Any PL_put_*() that can return an error is annotated with WUNUSED. At least, that is the theory.
Only in particular scenarios. For C++ Iād just check. That is mainly there for simplifying hand written code.
As PL_new_term_ref() returns a value you need, leaving it unused is rather unlikely. I guess we can safely mark it using WUNUSED, but I see little added value. What us critical is that it has a special return value (0) to indicate the error value. That is the case with many other functions, typically returning NULL for pointers in case of error and some negative value for functions returning int. Would adding something as ONERROR(Value) help?
I wasnāt thinking straight when I wrote that. (But ā as a general rule ā (void) cast can be used to turn off a WUNUSED warning)
I remember seeing some code that called PL_new_term_ref() and didnāt check that the result was non-zero ā this was because it was guaranteed that at least 10 new terms could be allocated. And it allows more compact code (and eliminates a test), although it could be written
term_t t1, t2;
if ((t1=PL_new_term_ref()) && (t2=PL_new_term_ref()))
For C++, it can be written
PlTerm_var t1, t2;
and thereās always a check, which can throw a C++ exception if it fails.