Coverage Report

Created: 2025-06-24 07:01

/src/ghostpdl/psi/idisp.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2023 Artifex Software, Inc.
2
   All Rights Reserved.
3
4
   This software is provided AS-IS with no warranty, either express or
5
   implied.
6
7
   This software is distributed under license and may not be copied,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
13
   CA 94129, USA, for further information.
14
*/
15
16
17
/* idisp.c */
18
19
/*
20
 * This allows the interpreter to set the callback structure
21
 * of the "display" device.  This must set at the end of
22
 * initialization and before the device is used.
23
 * This is harmless if the 'display' device is not included.
24
 * If gsapi_set_display_callback() is not called, this code
25
 * won't even be used.
26
 */
27
28
#include "stdio_.h"
29
#include "stdpre.h"
30
#include "iapi.h"
31
#include "ghost.h"
32
#include "gp.h"
33
#include "gscdefs.h"
34
#include "gsmemory.h"
35
#include "gstypes.h"
36
#include "gsdevice.h"
37
#include "iref.h"
38
#include "imain.h"
39
#include "iminst.h"
40
#include "oper.h"
41
#include "ostack.h"
42
#include "gx.h"
43
#include "gxdevice.h"
44
#include "gxdevmem.h"
45
#include "idisp.h"
46
#include "gdevdevn.h"
47
#include "gsequivc.h"
48
#include "gdevdsp.h"
49
#include "gdevdsp2.h"
50
#include "gxgstate.h"
51
#include "gxdevsop.h"
52
53
int
54
reopen_device_if_required(gs_main_instance *minst)
55
162k
{
56
162k
    i_ctx_t *i_ctx_p;
57
162k
    int code;
58
162k
    gx_device *dev;
59
60
162k
    i_ctx_p = minst->i_ctx_p; /* run_string may change i_ctx_p if GC */
61
162k
    dev = gs_currentdevice_inline(i_ctx_p->pgs);
62
162k
    if (dev == NULL)
63
        /* This can happen if we invalidated devices on the stack by calling nulldevice after they were pushed */
64
0
        return_error(gs_error_undefined);
65
66
162k
    if (!dev->is_open)
67
0
        return 0;
68
69
162k
    if (dev_proc(dev, dev_spec_op)(dev, gxdso_reopen_after_init, NULL, 0) != 1)
70
162k
       return 0;
71
72
0
    code = gs_closedevice(dev);
73
0
    if (code < 0)
74
0
        return code;
75
76
0
    code = gs_opendevice(dev);
77
0
    if (code < 0) {
78
0
        dmprintf(dev->memory, "**** Unable to reopen the device, quitting.\n");
79
0
        return code;
80
0
    }
81
0
    return 0;
82
0
}