diff options
author | Robin Watts <Robin.Watts@artifex.com> | 2021-10-27 15:18:58 +0100 |
---|---|---|
committer | Robin Watts <Robin.Watts@artifex.com> | 2021-10-27 15:49:27 +0100 |
commit | fb05cea482a6e0f2c346812811d0e62404e2d566 (patch) | |
tree | 01f4d72e586e45c6589421aa902adb48e0dfcab1 /contrib/pcl3/eprn | |
parent | 81a053f31f4e25ae205c614d6cc5c5bdd7c2bdeb (diff) | |
download | ghostpdl-fb05cea482a6e0f2c346812811d0e62404e2d566.tar.gz |
Tweak eprn and pcl3 devices to remove non const statics.
This should make the devices threadsafe.
Diffstat (limited to 'contrib/pcl3/eprn')
-rw-r--r-- | contrib/pcl3/eprn/eprnparm.c | 6 | ||||
-rw-r--r-- | contrib/pcl3/eprn/gdeveprn.h | 4 | ||||
-rw-r--r-- | contrib/pcl3/eprn/mediasize.c | 27 | ||||
-rw-r--r-- | contrib/pcl3/eprn/mediasize.h | 12 |
4 files changed, 33 insertions, 16 deletions
diff --git a/contrib/pcl3/eprn/eprnparm.c b/contrib/pcl3/eprn/eprnparm.c index 1d989c402..34e47d674 100644 --- a/contrib/pcl3/eprn/eprnparm.c +++ b/contrib/pcl3/eprn/eprnparm.c @@ -390,7 +390,7 @@ static char *next_word(char *s) #define cleanup() (free(list), gp_fclose(f)) -static int eprn_read_media_data(eprn_Eprn *eprn, gs_memory_t *memory) +static int eprn_read_media_data(mediasize_table *tables, eprn_Eprn *eprn, gs_memory_t *memory) { char buffer[BUFFER_SIZE]; const char @@ -502,7 +502,7 @@ static int eprn_read_media_data(eprn_Eprn *eprn, gs_memory_t *memory) t++; } { - ms_MediaCode code = ms_find_code_from_name(s, eprn->flag_desc); + ms_MediaCode code = ms_find_code_from_name(tables, s, eprn->flag_desc); if (code == ms_none) { eprintf5("%s" ERRPREF "Unknown media name (%s) in " "media configuration file\n%s %s, line %d.\n", @@ -664,7 +664,7 @@ int eprn_set_media_data(eprn_Device *dev, const char *media_file, size_t length) else { strncpy(eprn->media_file, media_file, length); eprn->media_file[length] = '\0'; - if ((rc = eprn_read_media_data(eprn, dev->memory->non_gc_memory)) != 0) { + if ((rc = eprn_read_media_data(&dev->eprn.table, eprn, dev->memory->non_gc_memory)) != 0) { gs_free(dev->memory->non_gc_memory, eprn->media_file, length + 1, sizeof(char), "eprn_set_media_data"); eprn->media_file = NULL; diff --git a/contrib/pcl3/eprn/gdeveprn.h b/contrib/pcl3/eprn/gdeveprn.h index b079d002d..bc221db5a 100644 --- a/contrib/pcl3/eprn/gdeveprn.h +++ b/contrib/pcl3/eprn/gdeveprn.h @@ -528,6 +528,7 @@ typedef struct s_eprn_Device { present in 'next_scan_line' with its device coordinate being "next_y - 1", unless 'next_y' is zero in which case we have finished. */ gs_gstate * pgs; + mediasize_table table; } eprn_Eprn; /* Macro for device structure type definitions. Note that in contrast to @@ -625,7 +626,8 @@ typedef struct { 0, /* octets_per_line */ \ 0, /* output_planes */ \ 0, /* next_y */ \ - NULL /* pgs */ \ + NULL, /* pgs */ \ + { 0 } /* table */ \ } /* For the calling conventions of the following functions consult the comments diff --git a/contrib/pcl3/eprn/mediasize.c b/contrib/pcl3/eprn/mediasize.c index 21c6a26fc..c9e3d41f7 100644 --- a/contrib/pcl3/eprn/mediasize.c +++ b/contrib/pcl3/eprn/mediasize.c @@ -243,15 +243,21 @@ static const ms_Flag substrings[] = { {0, NULL} }; +/* If you get an error when compiling the following, then MAX_MEDIASIZES + * (defined in pcltables.h) must be increased. */ +typedef struct +{ + char compile_time_assert[array_size(list) <= MAX_MEDIASIZES ? 1 : -1]; +} compile_time_assert_for_list_length; + /*****************************************************************************/ -ms_MediaCode ms_find_code_from_name(const char *name, - const ms_Flag *user_flag_list) +ms_MediaCode ms_find_code_from_name(mediasize_table *tables, + const char *name, + const ms_Flag *user_flag_list) { const char *end; char stripped_name[LONGER_THAN_NAMES]; - static const ms_SizeDescription *sorted_list[array_size(list) - 1]; - static unsigned int entries = 0; ms_SizeDescription keydata, *key = &keydata; @@ -261,13 +267,14 @@ ms_MediaCode ms_find_code_from_name(const char *name, /* On the first use of this function, compile a table of pointers into the list which is sorted by the names of the sizes. */ - if (entries == 0) { - while (entries < array_size(sorted_list)) { - sorted_list[entries] = list + entries + 1; /* ignore 'ms_none' */ + if (tables->mediasize_list_inited == 0) { + int entries = 1; /* ignore 'ms_none' */ + while (entries < array_size(list)) { + tables->mediasize_list[entries] = list + entries; entries++; } - qsort(sorted_list, array_size(sorted_list), sizeof(ms_SizeDescription *), - &cmp_by_name); + qsort(tables->mediasize_list, array_size(list) - 1, sizeof(ms_SizeDescription *), &cmp_by_name); + tables->mediasize_list_inited = 1; } /* Prevent idiots (like myself) from crashing the routine */ @@ -325,7 +332,7 @@ ms_MediaCode ms_find_code_from_name(const char *name, keydata.name = stripped_name; /* Search */ - found = (const ms_SizeDescription **)bsearch(&key, sorted_list, entries, + found = (const ms_SizeDescription **)bsearch(&key, tables->mediasize_list, array_size(list) - 1, sizeof(ms_SizeDescription *), &cmp_by_name); return found == NULL? ms_none: ((*found)->size | flags); diff --git a/contrib/pcl3/eprn/mediasize.h b/contrib/pcl3/eprn/mediasize.h index 4033ad218..0599f9277 100644 --- a/contrib/pcl3/eprn/mediasize.h +++ b/contrib/pcl3/eprn/mediasize.h @@ -150,6 +150,13 @@ typedef struct { */ } ms_SizeDescription; +#define MAX_MEDIASIZES 128 + +typedef struct { + int mediasize_list_inited; + const ms_SizeDescription *mediasize_list[MAX_MEDIASIZES]; +} mediasize_table; + /****************************************************************************** Media codes @@ -254,8 +261,9 @@ extern const ms_SizeDescription *ms_find_size_from_code(ms_MediaCode code); and appearance as a qualifier or consider the order of appearance. - There is no support for serialization qualifiers. */ -extern ms_MediaCode ms_find_code_from_name(const char *name, - const ms_Flag *user_flag_list); +extern ms_MediaCode ms_find_code_from_name(mediasize_table *tables, + const char *name, + const ms_Flag *user_flag_list); /*===========================================================================*/ |