Coverage Report

Created: 2025-06-10 07:27

/src/ghostpdl/psi/iplugin.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
/* Plugin manager */
18
19
#include "malloc_.h"
20
#include "string_.h"
21
#include "ghost.h"
22
#include "gxalloc.h"
23
#include "ierrors.h"
24
#include "ialloc.h"
25
#include "iplugin.h"
26
#include "icstate.h"
27
28
/*  Plugin list is being build in raw memory pool,
29
    because it is irrelevant to PS virtual memory.
30
    At least it must live during alloc_restore_all, allowing
31
    plugins to handle the finalization of objects they manage.
32
*/
33
34
extern_i_plugin_table();
35
36
static void *i_plugin_mem_alloc(i_plugin_client_memory *mem, unsigned int nbytes, const char *cname)
37
0
{   gs_memory_t *mem_raw = mem->client_data;
38
0
    return mem_raw->procs.alloc_bytes_immovable(mem_raw, nbytes, cname);
39
0
}
40
41
static void i_plugin_mem_free(i_plugin_client_memory *mem, void *data, const char *cname)
42
0
{   gs_memory_t *mem_raw = mem->client_data;
43
0
    mem_raw->procs.free_object(mem_raw, data, cname);
44
0
}
45
46
void i_plugin_make_memory(i_plugin_client_memory *mem, gs_memory_t *mem_raw)
47
319k
{   mem->client_data = mem_raw;
48
319k
    mem->alloc = i_plugin_mem_alloc;
49
319k
    mem->free  = i_plugin_mem_free;
50
319k
}
51
52
int i_plugin_init(i_ctx_t *i_ctx_p)
53
159k
{   gs_memory_t *mem_raw = i_ctx_p->memory.current->non_gc_memory;
54
159k
    const i_plugin_instantiation_proc *p = i_plugin_table;
55
159k
    i_plugin_holder *h;
56
159k
    int code;
57
159k
    i_plugin_client_memory client_mem;
58
159k
    i_plugin_make_memory(&client_mem, mem_raw);
59
159k
    for (; *p != 0; p++) {
60
0
        i_plugin_instance *instance = 0;
61
0
        code = (*p)(&client_mem, &instance);
62
0
        if (code != 0)
63
0
            return code;
64
0
        h = (i_plugin_holder *)gs_alloc_bytes_immovable(mem_raw, sizeof(i_plugin_holder), "plugin_holder");
65
0
        if (h == 0)
66
0
            return_error(gs_error_Fatal);
67
0
        h->I = instance;
68
0
        h->next = i_ctx_p->plugin_list;
69
0
        i_ctx_p->plugin_list = h;
70
0
    }
71
159k
    return 0;
72
159k
}
73
74
void i_plugin_finit(gs_memory_t *mem_raw, i_plugin_holder *list)
75
159k
{   i_plugin_client_memory client_mem;
76
159k
    i_plugin_make_memory(&client_mem, mem_raw);
77
159k
    while (list != 0) {
78
0
        i_plugin_holder *h = list;
79
0
        list = h->next;
80
0
        h->I->d->finit(h->I, &client_mem);
81
0
        gs_free_object(mem_raw, h, "plugin_holder");
82
0
    }
83
159k
}
84
85
i_plugin_holder * i_plugin_get_list(i_ctx_t *i_ctx_p)
86
0
{   return i_ctx_p->plugin_list;
87
0
}
88
89
i_plugin_instance *i_plugin_find(i_ctx_t *i_ctx_p, const char *type, const char *subtype)
90
0
{   i_plugin_holder *h = i_ctx_p->plugin_list;
91
0
    for (; h != 0; h = h->next) {
92
0
        i_plugin_instance *I = h->I;
93
0
        if (!strcmp(I->d->type, type) && !strcmp(I->d->subtype, subtype))
94
0
            return I;
95
0
    }
96
0
    return NULL;
97
0
}
98
99
/* todo: define plugin enumerator by 'type' */