Skip to content

Return a status from the postsolve functions - #140

Merged
dance858 merged 1 commit into
mainfrom
postsolve-status
Nov 16, 2026
Merged

dance858 merged 1 commit into
mainfrom
postsolve-status

Conversation

@dance858

Copy link
Copy Markdown
Owner

Closes #133 (its second part; the first part was #137).

postsolve, map_original_sol_to_reduced, postsolve_primal_infeas_ray and postsolve_dual_infeas_ray were void and reported a failure only by printing to stderr. A program that embeds PSLP could neither route that text nor detect that the outputs were left untouched.

What changes

  • The four functions return bool, true on success. Existing callers that ignore the result compile and behave as before. The failure conditions are listed in the comments of PSLP_API.h.
  • No writes to stderr from these functions. The reason for a failure is printed to stdout, and only when verbose is set, like the rest of PSLP's output.
  • map_original_sol_to_reduced: requesting an output without its input (x_red without x, y_red without y, z_red without y_red) is now a documented precondition checked with assert, where it used to print a warning and skip that output. Skipping a part by passing NULL outputs still works.
  • postsolve_primal_infeas_ray: a failed scratch allocation returns false. Before, a release build dereferenced NULL.
  • Time limit: the line "Maximum time limit of X seconds reached." is printed only when verbose is set. It used to be printed always.

With verbose off, the only remaining output of a release build is the exit(1) path of #139.

Not in this PR

Testing

On macOS: Debug and Release, shared and static, with PSLP_BUILD_TESTING=ON: all tests pass and the exported-symbol check passes. The tests of the failure paths (ray postsolve with a fold, with cone blocks and after free_presolver_reduced_problem; the map for a QP and for z_red after the reduced problem was freed) now assert the false return, and representative success paths assert true. The test binary writes nothing to stderr.

🤖 Generated with Claude Code

postsolve, map_original_sol_to_reduced, postsolve_primal_infeas_ray and
postsolve_dual_infeas_ray were void and reported a failure (out of memory,
unsupported problem, call after free_presolver_reduced_problem) only by
printing to stderr. A program that embeds PSLP could neither route that
text nor detect the failure (#133).

They now return bool, true on success. The reason for a failure is printed
to stdout and only when 'verbose' is set, so a release build no longer writes
to stderr from these functions.

Also:
- map_original_sol_to_reduced: an output requested without its input is a
  precondition (assert) and no longer a runtime warning.
- postsolve_primal_infeas_ray: a failed scratch allocation returns false
  instead of dereferencing NULL in a release build.
- The "Maximum time limit reached" line is printed only when 'verbose' is set.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@dance858
dance858 merged commit ac61a4a into main Nov 16, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generic exported symbol names can clash when PSLP is embedded in another library

1 participant