I'm trying to add PS/PDF/SVG stream support to pycairo and want to make sure that exceptions are raised when a stream write error occurs. The stream write function returns CAIRO_STATUS_WRITE_ERROR on a write error but the surface and cairo context ignore this and are not given an error status. So what is the purpose of returning CAIRO_STATUS_WRITE_ERROR? The attached program demonstrates stream errors, for me it outputs: status (CAIRO_STATUS_SUCCESS is 0) libpng error: Write Error PNG 1 PS 0, 0 PS 0, 0 PS 0, 0 I/O error : flush error I would expect all the status numbers to be non-zero (like PNG).
Created attachment 5747 [details] demonstrate that error status is not reported
The problem with the test case is that the surfaces do not attempt to write to the stream until cairo_surface_finish() (in this case called implicitly from cairo_surface_destroy) at which point the error status has been silently lost. After adding cairo_surface_finish() before the cairo_surface_status(), the test output becomes: status (CAIRO_STATUS_SUCCESS is 0) PNG 11 (error while writing to output stream) PS 0 (success), 11 (error while writing to output stream) PDF 0 (success), 11 (error while writing to output stream) SVG 0 (success), 11 (error while writing to output stream)
Created attachment 11755 [details] Updated test case with explicit cairo_surface_finish()
Stephen, I've added test cases to ensure that a write error is propagated back to the application - but given the API constraints the application must call cairo_surface_finish() explicitly to ensure that the surface is written out (which requires fiddling with cairo_surface_get_refererence_count() in its surface_destroy function for PyCairo to support throwing exceptions from write-out). Retitling to reflect issue with current cairo_*_destroy() API.
We've discussed changing _destroy() functions to return cairo_status before. Not sure how nicely that maps to language bindings though.
-- GitLab Migration Automatic Message -- This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/cairo/cairo/issues/285.
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.