-
Notifications
You must be signed in to change notification settings - Fork 18
Add Pltermv(0) + clean up initialization checks #31
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,6 +189,13 @@ PREDICATE(hello_query, 2) | |
| return true; | ||
| } | ||
|
|
||
| PREDICATE(call_cut, 1) | ||
| { PlQuery q(A1.as_string(), PlTermv()); | ||
| PlCheck(q.next_solution()); | ||
| q.cut(); | ||
| return true; | ||
| } | ||
|
|
||
| PREDICATE(hello_call, 1) | ||
| { PlCheck(PlCall(A1)); | ||
| return true; | ||
|
|
@@ -500,7 +507,7 @@ PREDICATE(ensure_PlTerm_forward_declarations_are_implemented, 0) | |
| PlTerm_atom p_atom4(std::string("abc")); | ||
| PlTerm_atom p_atom5(std::wstring(L"世界")); | ||
| PlTerm_term_t t_t(PL_new_term_ref()); | ||
| PlTerm_term_t t_null; // null | ||
| PlTerm_term_t t_null(PlTerm::null); | ||
| PlTerm_integer t_int1(std::numeric_limits<int>::max()); | ||
| PlTerm_integer t_int1b(std::numeric_limits<int>::min()); | ||
| PlTerm_integer t_int2(std::numeric_limits<long>::max()); | ||
|
|
@@ -524,7 +531,7 @@ PREDICATE(ensure_PlTerm_forward_declarations_are_implemented, 0) | |
| PlAtom atom3(std::string("atom3")); | ||
| PlAtom atom4(std::wstring(L"原子4")); | ||
| PlAtom a5a(t_atom1.as_atom()); | ||
| PlAtom atom_null; | ||
| PlAtom atom_null(PlAtom::null); | ||
| // The following are unsafe (the as_string() is deleted in the statement): | ||
| // const char * x01 = t_var.as_string().c_str(); | ||
| // const wchar_t *x01a = t_var.as_wstring().c_str(); | ||
|
|
@@ -990,7 +997,7 @@ PREDICATE(cpp_options, 3) | |
| int quoted = false; | ||
| size_t length = 10; | ||
| PlTerm_var callback; | ||
| PlAtom token; | ||
| PlAtom token(PlAtom::null); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only place where we want
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Answering your general comment with a long-winded answer (which I wrote to myself), which perhaps should go into the documentation. As a software philosophy, it's important that there should be no such thing as a "half-constructed" object - the constructor should ensure that the object is "complete" or else throw an exception. That is the purpose of
However, all the other objects allow the notion of a "null" object. This is used in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. I see. I guess ideally we should change APIs such that there is no need for "half baked" objects? Not sure how feasible this is. And yes, I'll wait for you to complete this sequence of fast commits and will merge then. By now it seems you understand all the dirty corners of SWI-Prolog's C interface and you definitely understand more of C++ 😄 |
||
| const char *descr = ""; | ||
| bool opt_all_v = opt_all.as_bool(); | ||
| int flags = opt_all_v ? OPT_ALL : 0; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to call Pl_new_term_ref(). Do I understand correctly that the old implementation called it twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No - the old code was explicitly "calling" the parent constructor (
PlTerm()), which in turn "called" theWrappedC<term_t>constructor. It is now implicit.