|
PPL C Language Interface 2.0
|
A handle returned by a ppl_new_* function denotes a new object owned by the caller. The caller must eventually release it exactly once using the matching ppl_delete_* function. Copying a handle value does not copy its object or create another ownership obligation. Deleting an object invalidates all handles, iterators and references to that object and its parts. Only caller-owned objects may be deleted; this restriction also applies to deletion functions accepting const handles.
A borrowed handle denotes part of another object, its owner. The caller must not delete or modify the borrowed object, including by casting away constness or passing it to an assignment, recycling or ASCII-load function. The owner, and every owner above it, must remain alive and valid throughout use of the handle. The individual accessor specifies which operations invalidate the borrow. No reference counting or lifetime tracking is performed. A const handle can also refer to an independently owned object: constness describes permitted access, not ownership.
Output addresses must be non-null and writable. Unless explicitly stated otherwise, a handle output parameter receives a handle value; it does not receive an assignment to, or delete, any object previously referenced by that value. Keep another handle to any previously owned object or delete it first. Check the return status before using an output. An accessor returning a null handle documents when this occurs; a null handle must never be passed as an object to another PPL function.
When a function promises to leave an output unchanged on failure, that promise concerns the output handle value. It does not extend the lifetime of an earlier borrowed result across an operation that may invalidate it.
Polyhedron constraint and generator getters, and Grid congruence and grid generator getters, return borrowed systems without copying them. This applies to both ordinary and minimized getters. The domain object owns the system and must remain alive. Treat any subsequent operation taking the domain object as an argument as invalidating the system handle and its iterators and elements, even when the argument is const: lazy computation can reorganize the representation. An enclosing owner, such as a powerset containing the domain object, must also remain valid.
This rule does not prohibit reading the borrowed system or its elements. System inspection, creating begin/end iterators, comparing and advancing those iterators, and reading the elements do not invalidate the borrow. Complete those operations before calling another operation on the domain or its enclosing owner. For example, this fragment requires no system copy. It requires the Polyhedron instantiation in a configured C interface, assumes a valid polyhedron handle ph, and aborts on error; abort is declared in <stdlib.h>.
With the Grid instantiation, the corresponding example reads the borrowed congruence system of a valid grid handle gr. It does not require the Polyhedron instantiation.
If the system must survive another operation on its owner, make an independent copy while the borrow is still valid, for example with ppl_new_Constraint_System_from_Constraint_System. The caller then owns that copy. A copy is optional when the borrowed lifetime is sufficient.
Domains that compute a system by value instead provide constructors such as ppl_new_Constraint_System_from_Rational_Box (which requires the Rational_Box instantiation in a configured C interface). Their output is caller-owned and independent of the source, including after source modification or deletion. These constructors leave the output handle unchanged on failure. They do not return borrowed handles.
The constructor name specifies the resulting system and the source domain; the suffix _minimized requests its minimized representation. The mathematical meaning is the same as that of the corresponding C++ accessor:
The change in ownership does not change these mathematical operations. An independently owned result is not necessarily an exact representation of its source in a different abstract domain.
System iterator objects are owned by the caller, but their positions and the elements obtained by dereferencing them borrow from the system. Creating or copying an iterator does not copy or extend the lifetime of the system. A newly constructed default iterator must be assigned a valid position, for example by a system's begin/end functions, before comparison, increment or dereference. Compare only iterators into the same system; never increment or dereference the past-the-end iterator.
Destroying, assigning to or modifying a system invalidates its iterators and borrowed element handles. If the system itself is borrowed, its owner's invalidation rules also apply. Read-only system and element inspection and ordinary iterator traversal do not invalidate them. Incrementing, assigning to or deleting an iterator does not destroy the element to which it previously referred. An iterator whose position is invalid may still be deleted or assigned a new valid position; it must not be compared, advanced or dereferenced while invalid.
Powerset iterators are caller-owned objects whose positions borrow from the powerset. Initialize them with begin/end or by copying a valid iterator. Compare only positions in the same powerset. Never dereference or increment end, or decrement begin; decrementing end requires a nonempty powerset. Iterators do not extend the powerset's lifetime.
Dereferencing either kind of iterator returns a read-only disjunct owned by the powerset. Do not modify or delete that disjunct. Keep the powerset and its enclosing owners alive and valid. Apart from obtaining begin/end positions and ordinary iterator traversal, any operation on the powerset or an enclosing owner may invalidate its iterator positions and borrowed disjuncts, including const operations. A modifier that returns an iterator specifies its new valid position. Invalid iterator objects may still be deleted or assigned a new valid position.
Inspecting a disjunct is permitted. Its own borrowed systems obey Borrowed Domain Systems, so finish inspecting such a system before another operation on the disjunct. For an independent domain object, use the corresponding domain copy constructor while the disjunct is valid. Copying, advancing or deleting an iterator does not delete its disjunct.
The constraint and objective-function accessors borrow from the MIP problem. Their results are non-null on success, must not be modified or deleted, and remain valid while the problem is alive and unmodified. Read-only inspection of the problem, and solving it, do not invalidate these input-data views. Assignment, clearing, ASCII loading and other modifications to the problem may invalidate them.
Feasible-point and optimizing-point accessors borrow the problem's cached point. Besides problem modification or deletion, operations that compute a solution may invalidate that view: is_satisfiable, solve, feasible_point, optimizing_point and optimal_value. Read the point, or copy it with ppl_new_Generator_from_Generator, before the next such call. Ordinary point inspection and objective-function evaluation on the point are permitted. A successful point accessor produces a non-null handle; an unavailable point is reported as an error, leaving the output unchanged.
A constraint obtained from a PIP problem is borrowed from that problem. It is non-null on success and remains valid while the problem is alive and unmodified. Read-only inspection and solving do not invalidate these input constraints; modifications such as adding constraints, assignment, clearing and ASCII loading may invalidate them.
Solution roots, child nodes, node constraints, parametric expressions and artificial parameters are borrowed parts of the originating PIP problem's solution tree. None may be modified or deleted by the caller. All depend on the continued validity of the problem and its solution tree. Treat problem modification or deletion, and subsequent solution-computing calls (is_satisfiable, solve, solution or optimizing_solution), as invalidating the tree and all handles and iterator positions derived from it.
Read-only tree traversal does not invalidate these handles: node type queries and conversions, child access, constraint inspection, artificial parameter iteration and parametric-value access may be freely combined. In particular, querying another variable's parametric value does not invalidate previously returned expressions. Read-only problem metadata queries such as space_dimension and number_of_constraints are also safe. Independent copies of constraint systems and linear expressions may be made using their existing copy constructors while the borrow is valid. Artificial-parameter iterators follow the same position and lifetime rules as System Iterators and Elements, with the node's sequence as their container.
The solution accessors return a null root when no solution exists. A node type conversion returns null when the node is not of the requested type; child access returns null for an absent branch. These are successful results, not error return codes. Test the returned handle before using it.