Bug 702965 - Handle /dev/null output device with multi-page eps2write driver
Summary: Handle /dev/null output device with multi-page eps2write driver
Status: RESOLVED WONTFIX
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: PDF Writer (show other bugs)
Version: 9.53.0
Hardware: PC Linux
: P4 normal
Assignee: Default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-05 17:48 UTC by Tom Callaway
Modified: 2021-08-24 17:27 UTC (History)
4 users (show)

See Also:
Customer:
Word Size: ---


Attachments
detect special null output file and do not use multipage logic (2.21 KB, patch)
2020-10-05 17:48 UTC, Tom Callaway
Details | Diff
Make generic function to check for null device and use it (7.39 KB, patch)
2021-01-04 16:46 UTC, Tom Callaway
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Callaway 2020-10-05 17:48:08 UTC
Created attachment 19921 [details]
detect special null output file and do not use multipage logic

Asymptote (https://github.com/vectorgraphics/asymptote) uses ghostscript (specifically, the eps2write driver) to generate graphical output. In one part of asymptote, it calls gs with -sOutputFile=/dev/null (or -sOutputFile=NUL on Windows). As of 9.53.0, this no longer works when parsing multi-page output, since /dev/null fails the "single file" test.

After discussing workarounds with the asymptote upstream, they suggested that the most correct fix would be for ghostscript to handle the condition where /dev/null is the output device. Looking at the ghostscript code, there is precedent for this, specifically in the bit* driver.

When the OutputFile is /dev/null, there is no need to be worried about multi-page output, since it is all going into a black hole. We also do not need to close and reopen /dev/null (it won't actually work).

I have attached a proposed fix to the pdf_output_page function in devices/vector/gdevpdf.c to detect special null devices (using the same logic in the bit* driver) and to conditionalize out the multi-page handling. I have tested this fix and it resolves the failure case in asymptote.

As this is my first commit to ghostscript, I also need to submit the Artifex Contributor License Agreement. I have a digitally "signed" and completed PDF form, but the form says "Insert Email" as to where I should send it (and I do not want to attach it to this bug for the obvious PII concerns). Please let me know where to send that.
Comment 1 Peter Cherepanov 2021-01-02 21:24:57 UTC
This roposal is reasonable, but the submitted patch is not general enough. A better patch should add a new function to the portability layer, gp_*.c  to identify a null device, and use it when needed. All devices that generate multiple output files need special handling of the null device.
Comment 2 Tom Callaway 2021-01-04 16:46:47 UTC
Created attachment 20417 [details]
Make generic function to check for null device and use it

Okay. I think this patch accomplishes that. I went through and replaced any manual checks for the null device in the code with this function. Wasn't sure if gpmisc.* was the right place for it, so if not, I can adjust. This change has the added feature of making these null device checks more correct across all platforms (not just UNIX/DOS/WIN).
Comment 3 Ray Johnston 2021-08-24 17:27:21 UTC
We have discussed this and will not make this change. The only reason there
are a few devices that use a "quick and dirty" method to detect the NUL:
device (or /dev/null) is for performance testing where we want to measure
the processing time of Ghostscript including rendering the page, but do not
want to include the time of system calls to write the data.

It is not clear what use Asymptote would make of running Ghostscript to only
throw away the output -- all it would do is slow things down.

Better for all to just skip that step and save the processing power for useful
work.