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.
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.
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).
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.