Repository navigation
Stop on broken preconditions; return run-time failures in status_t - #87
Merged
Merged
Conversation
This was referenced Nov 22, 2026
fplotlib now tells two kinds of failure apart. A call that breaks a documented precondition is a bug in the calling code: drawing before open_canvas, a nonfinite coordinate reaching a renderer, an alpha outside [0, 1], an unknown fill rule, bytes before close_canvas, savefig of an unknown format, xlim with an infinite limit. contract_error in the new fplotlib_status writes "fplotlib: <rule>" to standard error and stops with exit code 1; every stop in the library goes through it, in place of the error stops and prints there were. A failure a correct program can still meet at run time is returned instead, in a status_t: an output file that cannot be opened, written or closed (ERROR_IO), or a PNG cropped with bbox_inches="tight" to more than MAX_PNG_PIXELS pixels (ERROR_SIZE). savefig, save_animation, show and the render_* functions take an optional status; without one they stop with the message and exit code 2, except show, which only reports. renderer_t checks its contract once, for every backend: its public methods are non_overridable wrappers that check their arguments and the call order, and the backends implement deferred *_impl methods. encoded_renderer_t adds bytes for the backends that encode a file. Coordinates and sizes are bounded by MAX_COORD (1e15 points), a round- or square-ended dashed pen by MAX_PEN_PER_DASH (100) times its pattern, a PNG canvas by MAX_PNG_PIXELS (1e8), and an animation's frames by MAX_REEL_BYTES, counted as they encode at worst. docs/api/fplotlib_status.md lists the limits. tests/test_contract.f90 runs the test binary once per broken call and checks the exit code and the message.
certik
force-pushed
the
split-3-status
branch
from
November 22, 2026 20:42
d3b12d3 to
73e3f1d
Compare
This was referenced Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contract stops and
status_tfplotlib now tells two kinds of failure apart.
A call that breaks a documented precondition stops. Examples:
open_canvas;bytesbeforeclose_canvas;savefigof an unknown format, orxlimwith an infinite limit.contract_errorin the newfplotlib_statuswritesfplotlib: <rule>to stderr and stops with exit code 1. Every stop in the library goes through it, in place of theerror stops andprints there were.A failure that a correct program can still meet at run time is returned in a
status_t. There are two:ERROR_IO: an output file can't be opened, written or closed;ERROR_SIZE: a PNG cropped withbbox_inches="tight"comes out with more thanMAX_PNG_PIXELSpixels.savefig,save_animation,showand therender_*functions take an optionalstatus. Without one they stop with the message and exit code 2, exceptshow, which only reports.The renderer contract is checked once, for every backend.
renderer_t's public methods arenon_overridablewrappers that check their arguments and the call order. The backends implement deferred*_implmethods, andencoded_renderer_taddsbytesfor the backends that encode a file.Limits. These are listed in
docs/api/fplotlib_status.md:MAX_COORD(1e15 points);MAX_PEN_PER_DASH(100) times its pattern;MAX_PNG_PIXELS(1e8);MAX_REEL_BYTES, counted as they encode at worst.tests/test_contract.f90runs the test binary once per broken call (22 here) and checks the exit code and the message.This is part of a stack of five PRs that together are exactly #83 (the final tree of the last one is byte for byte #83's), split so that each can be reviewed and merged on its own. Each one builds and passes the whole test suite with gfortran, gfortran
-O3 -march=native, flang, flang-O3 -march=nativeand LFortran, and the docs build.status_t(the error API)Merge them in order; each PR's base is the one before it. #83 went through 30 rounds of independent review, the last with no blockers.