rpms/cups/FC-5 cups-gnome.patch,NONE,1.1 cups.spec,1.137,1.138
fedora-cvs-commits at redhat.com
fedora-cvs-commits at redhat.com
Sun Apr 2 19:22:21 UTC 2006
Author: twaugh
Update of /cvs/dist/rpms/cups/FC-5
In directory cvs.devel.redhat.com:/tmp/cvs-serv9702
Modified Files:
cups.spec
Added Files:
cups-gnome.patch
Log Message:
* Sun Apr 2 2006 Tim Waugh <twaugh at redhat.com> 1:1.2-0.2.rc1.2.5
- Backported svn 5365:5366 change for mutex-protected stringpool.
cups-gnome.patch:
globals.c | 4 -
globals.h | 11 ---
i18n.h | 2
language.c | 83 ++++++++++++++++++++-----
string.c | 107 ++++++++++++++++++++++++++-------
string.h | 1
transcode.c | 193 ++++++++++++++++++++++++++++++++++++++++++++----------------
7 files changed, 297 insertions(+), 104 deletions(-)
--- NEW FILE cups-gnome.patch ---
--- cups-1.2rc1/cups/string.h.gnome 2006-03-07 04:41:42.000000000 +0000
+++ cups-1.2rc1/cups/string.h 2006-04-02 20:04:23.000000000 +0100
@@ -131,6 +131,7 @@
*/
extern char *_cupsStrAlloc(const char *s);
+extern void _cupsStrFlush(void);
extern void _cupsStrFree(const char *s);
extern size_t _cupsStrStatistics(size_t *alloc_bytes, size_t *total_bytes);
--- cups-1.2rc1/cups/language.c.gnome 2006-03-31 18:31:36.000000000 +0100
+++ cups-1.2rc1/cups/language.c 2006-04-02 20:08:27.000000000 +0100
@@ -66,6 +66,18 @@
/*
+ * Local globals...
+ */
+
+#ifdef HAVE_PTHREAD_H
+static pthread_mutex_t lang_mutex = PTHREAD_MUTEX_INITIALIZER;
+ /* Mutex to control access to cache */
+#endif /* HAVE_PTHREAD_H */
+static cups_lang_t *lang_cache = NULL;
+ /* Language string cache */
+
+
+/*
* Local functions...
*/
@@ -204,17 +216,6 @@
void
cupsLangFlush(void)
{
- _cupsLangFlush(_cupsGlobals());
-}
-
-
-/*
- * '_cupsLangFlush()' - Flush all language data out of the cache.
- */
-
-void
-_cupsLangFlush(_cups_globals_t *cg) /* I - Global data */
-{
cups_lang_t *lang, /* Current language */
*next; /* Next language */
@@ -223,7 +224,11 @@
* Free all languages in the cache...
*/
- for (lang = cg->lang_cache; lang != NULL; lang = next)
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_lock(&lang_mutex);
+#endif /* HAVE_PTHREAD_H */
+
+ for (lang = lang_cache; lang != NULL; lang = next)
{
/*
* Free all messages...
@@ -239,7 +244,11 @@
free(lang);
}
- cg->lang_cache = NULL;
+ lang_cache = NULL;
+
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&lang_mutex);
+#endif /* HAVE_PTHREAD_H */
}
@@ -252,8 +261,16 @@
void
cupsLangFree(cups_lang_t *lang) /* I - Language to free */
{
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_lock(&lang_mutex);
+#endif /* HAVE_PTHREAD_H */
+
if (lang != NULL && lang->used > 0)
lang->used --;
+
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&lang_mutex);
+#endif /* HAVE_PTHREAD_H */
}
@@ -577,9 +594,17 @@
* Country localization not available, look for generic localization...
*/
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_lock(&lang_mutex);
+#endif /* HAVE_PTHREAD_H */
+
if ((lang = cups_cache_lookup(langname, encoding)) != NULL)
return (lang);
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&lang_mutex);
+#endif /* HAVE_PTHREAD_H */
+
snprintf(filename, sizeof(filename), "%s/%s/cups_%s.po", cg->localedir,
langname, langname);
@@ -603,7 +628,7 @@
* record...
*/
- for (lang = cg->lang_cache; lang != NULL; lang = lang->next)
+ for (lang = lang_cache; lang != NULL; lang = lang->next)
if (lang->used == 0)
break;
@@ -614,10 +639,16 @@
*/
if ((lang = calloc(sizeof(cups_lang_t), 1)) == NULL)
+ {
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&lang_mutex);
+#endif /* HAVE_PTHREAD_H */
+
return (NULL);
+ }
- lang->next = cg->lang_cache;
- cg->lang_cache = lang;
+ lang->next = lang_cache;
+ lang_cache = lang;
}
else
{
@@ -650,6 +681,10 @@
* Return...
*/
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&lang_mutex);
+#endif /* HAVE_PTHREAD_H */
+
return (lang);
}
@@ -672,7 +707,21 @@
if (!lang || !message)
return (message);
+#ifdef HAVE_PTHREAD_H
+ {
+ const char *s; /* Localized message */
+
+ pthread_mutex_lock(&lang_mutex);
+
+ s = _cupsMessageLookup(lang->strings, message);
+
+ pthread_mutex_unlock(&lang_mutex);
+
+ return (s);
+ }
+#else
return (_cupsMessageLookup(lang->strings, message));
+#endif /* HAVE_PTHREAD_H */
}
@@ -1170,7 +1219,7 @@
* Loop through the cache and return a match if found...
*/
- for (lang = _cupsGlobals()->lang_cache; lang != NULL; lang = lang->next)
+ for (lang = lang_cache; lang != NULL; lang = lang->next)
{
DEBUG_printf(("cups_cache_lookup: lang=%p, language=\"%s\", encoding=%d(%s)\n",
lang, lang->language, lang->encoding,
--- cups-1.2rc1/cups/i18n.h.gnome 2006-03-15 21:09:32.000000000 +0000
+++ cups-1.2rc1/cups/i18n.h 2006-04-02 20:04:23.000000000 +0100
@@ -31,6 +31,7 @@
* Include necessary headers...
*/
+# include <stdio.h>
# include "transcode.h"
# ifdef __cplusplus
@@ -90,6 +91,7 @@
* Prototypes...
*/
+extern void _cupsCharmapFlush(void);
extern void _cupsCharmapFree(const cups_encoding_t encoding);
extern void *_cupsCharmapGet(const cups_encoding_t encoding);
extern const char *_cupsEncodingName(cups_encoding_t encoding);
--- cups-1.2rc1/cups/globals.c.gnome 2006-03-21 15:28:29.000000000 +0000
+++ cups-1.2rc1/cups/globals.c 2006-04-02 20:04:23.000000000 +0100
@@ -163,10 +163,6 @@
for (i = 0; i < 3; i ++)
cupsFileClose(cg->stdio_files[i]);
- _cupsStrFlush(cg);
- _cupsLangFlush(cg);
- _cupsCharmapFlush(cg);
-
cupsFreeOptions(cg->cupsd_num_settings, cg->cupsd_settings);
free(value);
--- cups-1.2rc1/cups/transcode.c.gnome 2006-03-17 19:50:14.000000000 +0000
+++ cups-1.2rc1/cups/transcode.c 2006-04-02 20:04:23.000000000 +0100
@@ -37,6 +37,7 @@
* conv_vbcs_to_utf8() - Convert legacy DBCS/VBCS to UTF-8.
* free_sbcs_charmap() - Free memory used by a single byte character set.
* free_vbcs_charmap() - Free memory used by a variable byte character set.
+ * get_charmap() - Lookup or get a character set map (private).
* get_charmap_count() - Count lines in a charmap file.
* get_sbcs_charmap() - Get SBCS Charmap.
* get_vbcs_charmap() - Get DBCS/VBCS Charmap.
@@ -54,6 +55,20 @@
/*
+ * Local globals...
+ */
+
+#ifdef HAVE_PTHREAD_H
+static pthread_mutex_t map_mutex = PTHREAD_MUTEX_INITIALIZER;
+ /* Mutex to control access to maps */
+#endif /* HAVE_PTHREAD_H */
+static _cups_cmap_t *cmap_cache = NULL;
+ /* SBCS Charmap Cache */
+static _cups_vmap_t *vmap_cache = NULL;
+ /* VBCS Charmap Cache */
+
+
+/*
* Local functions...
*/
@@ -76,6 +91,7 @@
const cups_encoding_t encoding);
static void free_sbcs_charmap(_cups_cmap_t *sbcs);
static void free_vbcs_charmap(_cups_vmap_t *vbcs);
+static void *get_charmap(const cups_encoding_t encoding);
static int get_charmap_count(cups_file_t *fp);
static _cups_cmap_t *get_sbcs_charmap(const cups_encoding_t encoding,
const char *filename);
@@ -88,7 +104,7 @@
*/
void
-_cupsCharmapFlush(_cups_globals_t *cg) /* I - Global data */
+_cupsCharmapFlush(void)
{
_cups_cmap_t *cmap, /* Legacy SBCS / Unicode Charset Map */
*cnext; /* Next Legacy SBCS Charset Map */
@@ -96,24 +112,28 @@
*vnext; /* Next Legacy VBCS Charset Map */
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_lock(&map_mutex);
+#endif /* HAVE_PTHREAD_H */
+
/*
* Loop through SBCS charset map cache, free all memory...
*/
- for (cmap = cg->cmap_cache; cmap; cmap = cnext)
+ for (cmap = cmap_cache; cmap; cmap = cnext)
{
cnext = cmap->next;
free_sbcs_charmap(cmap);
}
- cg->cmap_cache = NULL;
+ cmap_cache = NULL;
/*
* Loop through DBCS/VBCS charset map cache, free all memory...
*/
- for (vmap = cg->vmap_cache; vmap; vmap = vnext)
+ for (vmap = vmap_cache; vmap; vmap = vnext)
{
vnext = vmap->next;
@@ -122,7 +142,11 @@
free(vmap);
}
- cg->vmap_cache = NULL;
+ vmap_cache = NULL;
+
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&map_mutex);
+#endif /* HAVE_PTHREAD_H */
}
@@ -138,21 +162,23 @@
{
_cups_cmap_t *cmap; /* Legacy SBCS / Unicode Charset Map */
_cups_vmap_t *vmap; /* Legacy VBCS / Unicode Charset Map */
- _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
/*
* See if we already have this SBCS charset map loaded...
*/
- for (cmap = cg->cmap_cache; cmap; cmap = cmap->next)
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_lock(&map_mutex);
+#endif /* HAVE_PTHREAD_H */
+
+ for (cmap = cmap_cache; cmap; cmap = cmap->next)
{
if (cmap->encoding == encoding)
{
if (cmap->used > 0)
cmap->used --;
-
- return;
+ break;
}
}
@@ -160,15 +186,19 @@
* See if we already have this DBCS/VBCS charset map loaded...
*/
- for (vmap = cg->vmap_cache; vmap; vmap = vmap->next)
+ for (vmap = vmap_cache; vmap; vmap = vmap->next)
{
if (vmap->encoding == encoding)
{
if (vmap->used > 0)
vmap->used --;
- return;
+ break;
}
}
+
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&map_mutex);
+#endif /* HAVE_PTHREAD_H */
}
@@ -185,8 +215,7 @@
_cupsCharmapGet(
const cups_encoding_t encoding) /* I - Encoding */
{
- char filename[1024]; /* Filename for charset map file */
- _cups_globals_t *cg = _cupsGlobals(); /* Global data */
+ void *charmap; /* Charset map pointer */
DEBUG_printf(("_cupsCharmapGet(encoding=%d)\n", encoding));
@@ -202,24 +231,20 @@
}
/*
- * Get the data directory and charset map name...
+ * Lookup or get the charset map pointer and return...
*/
- snprintf(filename, sizeof(filename), "%s/charmaps/%s.txt",
- cg->cups_datadir, _cupsEncodingName(encoding));
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_lock(&map_mutex);
+#endif /* HAVE_PTHREAD_H */
- DEBUG_printf((" filename=\"%s\"\n", filename));
+ charmap = get_charmap(encoding);
- /*
- * Read charset map input file into cache...
- */
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&map_mutex);
+#endif /* HAVE_PTHREAD_H */
- if (encoding < CUPS_ENCODING_SBCS_END)
- return (get_sbcs_charmap(encoding, filename));
- else if (encoding < CUPS_ENCODING_VBCS_END)
- return (get_vbcs_charmap(encoding, filename));
- else
- return (NULL);
+ return (charmap);
}
@@ -239,6 +264,9 @@
const int maxout, /* I - Max output */
const cups_encoding_t encoding) /* I - Encoding */
{
+ int bytes; /* Number of bytes converted */
+
+
/*
* Check for valid arguments...
*/
@@ -270,15 +298,25 @@
* Convert input legacy charset to UTF-8...
*/
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_lock(&map_mutex);
+#endif /* HAVE_PTHREAD_H */
+
if (encoding < CUPS_ENCODING_SBCS_END)
- return (conv_sbcs_to_utf8(dest, (cups_sbcs_t *)src, maxout, encoding));
+ bytes = conv_sbcs_to_utf8(dest, (cups_sbcs_t *)src, maxout, encoding);
else if (encoding < CUPS_ENCODING_VBCS_END)
- return (conv_vbcs_to_utf8(dest, (cups_sbcs_t *)src, maxout, encoding));
+ bytes = conv_vbcs_to_utf8(dest, (cups_sbcs_t *)src, maxout, encoding);
else
{
- puts(" Bad encoding, returning -1");
- return (-1);
+ DEBUG_puts(" Bad encoding, returning -1");
+ bytes = -1;
}
+
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&map_mutex);
+#endif /* HAVE_PTHREAD_H */
+
+ return (bytes);
}
@@ -298,6 +336,9 @@
const int maxout, /* I - Max output */
const cups_encoding_t encoding) /* I - Encoding */
{
+ int bytes; /* Number of bytes converted */
+
+
/*
* Check for valid arguments...
*/
@@ -325,12 +366,22 @@
* Convert input UTF-8 to legacy charset...
*/
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_lock(&map_mutex);
+#endif /* HAVE_PTHREAD_H */
+
if (encoding < CUPS_ENCODING_SBCS_END)
- return (conv_utf8_to_sbcs((cups_sbcs_t *)dest, src, maxout, encoding));
+ bytes = conv_utf8_to_sbcs((cups_sbcs_t *)dest, src, maxout, encoding);
else if (encoding < CUPS_ENCODING_VBCS_END)
- return (conv_utf8_to_vbcs((cups_sbcs_t *)dest, src, maxout, encoding));
+ bytes = conv_utf8_to_vbcs((cups_sbcs_t *)dest, src, maxout, encoding);
else
- return (-1);
+ bytes = -1;
+
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&map_mutex);
+#endif /* HAVE_PTHREAD_H */
+
+ return (bytes);
}
@@ -675,7 +726,7 @@
* Find legacy charset map in cache...
*/
- if ((cmap = (_cups_cmap_t *)_cupsCharmapGet(encoding)) == NULL)
+ if ((cmap = (_cups_cmap_t *)get_charmap(encoding)) == NULL)
return (-1);
/*
@@ -714,7 +765,7 @@
* Convert internal UCS-4 to output UTF-8 (and delete BOM)...
*/
- _cupsCharmapFree(encoding);
+ cmap->used --;
return (cupsUTF32ToUTF8(dest, work, maxout));
}
@@ -743,7 +794,7 @@
* Find legacy charset map in cache...
*/
- if ((cmap = (_cups_cmap_t *) _cupsCharmapGet(encoding)) == NULL)
+ if ((cmap = (_cups_cmap_t *)get_charmap(encoding)) == NULL)
return (-1);
/*
@@ -790,7 +841,7 @@
*dest = '\0';
- _cupsCharmapFree(encoding);
+ cmap->used --;
return ((int)(dest - start));
}
@@ -820,7 +871,7 @@
* Find legacy charset map in cache...
*/
- if ((vmap = (_cups_vmap_t *)_cupsCharmapGet(encoding)) == NULL)
+ if ((vmap = (_cups_vmap_t *)get_charmap(encoding)) == NULL)
return (-1);
/*
@@ -902,7 +953,7 @@
*dest = '\0';
- _cupsCharmapFree(encoding);
+ vmap->used --;
return ((int)(dest - start));
}
@@ -932,7 +983,7 @@
* Find legacy charset map in cache...
*/
- if ((vmap = (_cups_vmap_t *)_cupsCharmapGet(encoding)) == NULL)
+ if ((vmap = (_cups_vmap_t *)get_charmap(encoding)) == NULL)
return (-1);
/*
@@ -1027,7 +1078,7 @@
*workptr = 0;
- _cupsCharmapFree(encoding);
+ vmap->used --;
/*
* Convert internal UCS-4 to output UTF-8 (and delete BOM)...
@@ -1081,6 +1132,46 @@
/*
+ * 'get_charmap()' - Lookup or get a character set map (private).
+ *
+ * This code handles single-byte (SBCS), double-byte (DBCS), and
+ * variable-byte (VBCS) character sets _without_ charset escapes...
+ * This code does not handle multiple-byte character sets (MBCS)
+ * (such as ISO-2022-JP) with charset switching via escapes...
+ */
+
+
+void * /* O - Charset map pointer */
+get_charmap(
+ const cups_encoding_t encoding) /* I - Encoding */
+{
+ char filename[1024]; /* Filename for charset map file */
+ _cups_globals_t *cg = _cupsGlobals(); /* Global data */
+
+
+ /*
+ * Get the data directory and charset map name...
+ */
+
+ snprintf(filename, sizeof(filename), "%s/charmaps/%s.txt",
+ cg->cups_datadir, _cupsEncodingName(encoding));
+
+ DEBUG_printf((" filename=\"%s\"\n", filename));
+
+ /*
+ * Read charset map input file into cache...
+ */
+
+ if (encoding < CUPS_ENCODING_SBCS_END)
+ return (get_sbcs_charmap(encoding, filename));
+ else if (encoding < CUPS_ENCODING_VBCS_END)
+ return (get_vbcs_charmap(encoding, filename));
+ else
+ return (NULL);
+}
+
+
+/*
* 'get_charmap_count()' - Count lines in a charmap file.
*/
@@ -1129,19 +1220,19 @@
cups_ucs2_t *crow; /* Pointer to UCS-2 row in 'char2uni' */
cups_sbcs_t *srow; /* Pointer to SBCS row in 'uni2char' */
char line[256]; /* Line from charset map file */
- _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
/*
* See if we already have this SBCS charset map loaded...
*/
- for (cmap = cg->cmap_cache; cmap; cmap = cmap->next)
+ for (cmap = cmap_cache; cmap; cmap = cmap->next)
{
if (cmap->encoding == encoding)
{
cmap->used ++;
DEBUG_printf((" returning existing cmap=%p\n", cmap));
+
return ((void *)cmap);
}
}
@@ -1161,6 +1252,7 @@
{
cupsFileClose(fp);
DEBUG_puts(" Unable to allocate memory!");
+
return (NULL);
}
@@ -1228,8 +1320,8 @@
* Add it to the cache and return...
*/
- cmap->next = cg->cmap_cache;
- cg->cmap_cache = cmap;
+ cmap->next = cmap_cache;
+ cmap_cache = cmap;
DEBUG_printf((" returning new cmap=%p\n", cmap));
@@ -1273,7 +1365,6 @@
char line[256]; /* Line from charset map file */
int i; /* Loop variable */
int wide; /* 32-bit legacy char */
- _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
DEBUG_printf(("get_vbcs_charmap(encoding=%d, filename=\"%s\")\n",
@@ -1283,12 +1374,13 @@
* See if we already have this DBCS/VBCS charset map loaded...
*/
- for (vmap = cg->vmap_cache; vmap; vmap = vmap->next)
+ for (vmap = vmap_cache; vmap; vmap = vmap->next)
{
if (vmap->encoding == encoding)
{
vmap->used ++;
DEBUG_printf((" returning existing vmap=%p\n", vmap));
+
return ((void *)vmap);
}
}
@@ -1300,6 +1392,7 @@
if ((fp = cupsFileOpen(filename, "r")) == NULL)
{
DEBUG_printf((" Unable to open file: %s\n", strerror(errno)));
+
return (NULL);
}
@@ -1310,6 +1403,7 @@
if ((mapcount = get_charmap_count(fp)) <= 0)
{
DEBUG_puts(" Unable to get charmap count!");
+
return (NULL);
}
@@ -1323,6 +1417,7 @@
{
cupsFileClose(fp);
DEBUG_puts(" Unable to allocate memory!");
+
return (NULL);
}
@@ -1465,8 +1560,8 @@
* Add it to the cache and return...
*/
- vmap->next = cg->vmap_cache;
- cg->vmap_cache = vmap;
+ vmap->next = vmap_cache;
+ vmap_cache = vmap;
DEBUG_printf((" returning new vmap=%p\n", vmap));
--- cups-1.2rc1/cups/string.c.gnome 2006-03-31 18:45:13.000000000 +0100
+++ cups-1.2rc1/cups/string.c 2006-04-02 20:06:54.000000000 +0100
@@ -46,9 +46,24 @@
#include <stdlib.h>
#include <limits.h>
+#include "array.h"
#include "debug.h"
#include "string.h"
-#include "globals.h"
+#ifdef HAVE_PTHREAD_H
+# include <pthread.h>
+#endif /* HAVE_PTHREAD_H */
+
+
+/*
+ * Local globals...
+ */
+
+#ifdef HAVE_PTHREAD_H
+static pthread_mutex_t sp_mutex = PTHREAD_MUTEX_INITIALIZER;
+ /* Mutex to control access to pool */
+#endif /* HAVE_PTHREAD_H */
+static cups_array_t *stringpool = NULL;
+ /* Global string pool */
/*
@@ -65,7 +80,6 @@
char * /* O - String pointer */
_cupsStrAlloc(const char *s) /* I - String */
{
- _cups_globals_t *cg; /* Global data */
_cups_sp_item_t *item, /* String pool item */
key; /* Search key */
@@ -81,13 +95,21 @@
* Get the string pool...
*/
- cg = _cupsGlobals();
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_lock(&sp_mutex);
+#endif /* HAVE_PTHREAD_H */
+
+ if (!stringpool)
+ stringpool = cupsArrayNew((cups_array_func_t)compare_sp_items, NULL);
+
+ if (!stringpool)
+ {
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&sp_mutex);
+#endif /* HAVE_PTHREAD_H */
- if (!cg->stringpool)
- cg->stringpool = cupsArrayNew((cups_array_func_t)compare_sp_items, NULL);
-
- if (!cg->stringpool)
return (NULL);
+ }
/*
* See if the string is already in the pool...
@@ -95,7 +117,7 @@
key.str = (char *)s;
- if ((item = (_cups_sp_item_t *)cupsArrayFind(cg->stringpool, &key)) != NULL)
+ if ((item = (_cups_sp_item_t *)cupsArrayFind(stringpool, &key)) != NULL)
{
/*
* Found it, return the cached string...
@@ -103,6 +125,10 @@
item->ref_count ++;
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&sp_mutex);
+#endif /* HAVE_PTHREAD_H */
+
return (item->str);
}
@@ -112,7 +138,13 @@
item = (_cups_sp_item_t *)calloc(1, sizeof(_cups_sp_item_t));
if (!item)
+ {
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&sp_mutex);
+#endif /* HAVE_PTHREAD_H */
+
return (NULL);
+ }
item->ref_count = 1;
item->str = strdup(s);
@@ -120,6 +152,11 @@
if (!item->str)
{
free(item);
+
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&sp_mutex);
+#endif /* HAVE_PTHREAD_H */
+
return (NULL);
}
@@ -127,7 +164,11 @@
* Add the string to the pool and return it...
*/
- cupsArrayAdd(cg->stringpool, item);
+ cupsArrayAdd(stringpool, item);
+
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&sp_mutex);
+#endif /* HAVE_PTHREAD_H */
return (item->str);
}
@@ -138,20 +179,30 @@
*/
void
-_cupsStrFlush(_cups_globals_t *cg) /* I - Global data */
+_cupsStrFlush(void)
{
_cups_sp_item_t *item; /* Current item */
+ DEBUG_printf((" %d strings in array\n", cupsArrayCount(stringpool)));
+
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_lock(&sp_mutex);
+#endif /* HAVE_PTHREAD_H */
- for (item = (_cups_sp_item_t *)cupsArrayFirst(cg->stringpool);
+ for (item = (_cups_sp_item_t *)cupsArrayFirst(stringpool);
item;
- item = (_cups_sp_item_t *)cupsArrayNext(cg->stringpool))
+ item = (_cups_sp_item_t *)cupsArrayNext(stringpool))
{
free(item->str);
free(item);
}
- cupsArrayDelete(cg->stringpool);
+ cupsArrayDelete(stringpool);
+ stringpool = NULL;
+
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&sp_mutex);
+#endif /* HAVE_PTHREAD_H */
}
@@ -242,7 +293,6 @@
void
_cupsStrFree(const char *s) /* I - String to free */
{
- _cups_globals_t *cg; /* Global data */
_cups_sp_item_t *item, /* String pool item */
key; /* Search key */
@@ -258,18 +308,20 @@
* Get the string pool...
*/
- cg = _cupsGlobals();
-
- if (!cg->stringpool)
+ if (!stringpool)
return;
/*
* See if the string is already in the pool...
*/
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_lock(&sp_mutex);
+#endif /* HAVE_PTHREAD_H */
+
key.str = (char *)s;
- if ((item = (_cups_sp_item_t *)cupsArrayFind(cg->stringpool, &key)) != NULL
+ if ((item = (_cups_sp_item_t *)cupsArrayFind(stringpool, &key)) != NULL
&& item->str == s)
{
/*
@@ -284,12 +336,16 @@
* Remove and free...
*/
- cupsArrayRemove(cg->stringpool, item);
+ cupsArrayRemove(stringpool, item);
free(item->str);
free(item);
}
}
+
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&sp_mutex);
+#endif /* HAVE_PTHREAD_H */
}
@@ -403,19 +459,20 @@
tbytes, /* Total string bytes */
len; /* Length of string */
_cups_sp_item_t *item; /* Current item */
- _cups_globals_t *cg; /* Global data */
/*
* Loop through strings in pool, counting everything up...
*/
- cg = _cupsGlobals();
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_lock(&sp_mutex);
+#endif /* HAVE_PTHREAD_H */
for (count = 0, abytes = 0, tbytes = 0,
- item = (_cups_sp_item_t *)cupsArrayFirst(cg->stringpool);
+ item = (_cups_sp_item_t *)cupsArrayFirst(stringpool);
item;
- item = (_cups_sp_item_t *)cupsArrayNext(cg->stringpool))
+ item = (_cups_sp_item_t *)cupsArrayNext(stringpool))
{
/*
* Count allocated memory, using a 64-bit aligned buffer as a basis.
@@ -427,6 +484,10 @@
tbytes += item->ref_count * len;
}
+#ifdef HAVE_PTHREAD_H
+ pthread_mutex_unlock(&sp_mutex);
+#endif /* HAVE_PTHREAD_H */
+
/*
* Return values...
*/
--- cups-1.2rc1/cups/globals.h.gnome 2006-03-21 15:28:29.000000000 +0000
+++ cups-1.2rc1/cups/globals.h 2006-04-02 20:04:23.000000000 +0100
@@ -95,7 +95,6 @@
/* Unknown error statuses */
/* language.c */
- cups_lang_t *lang_cache; /* Language string cache */
cups_lang_t *lang_default; /* Default language */
# ifdef __APPLE__
# ifdef HAVE_CF_LOCALE_ID
@@ -113,10 +112,6 @@
/* tempfile.c */
char tempfile[1024]; /* cupsTempFd/File buffer */
- /* transcode.c */
- _cups_cmap_t *cmap_cache; /* SBCS Charmap Cache */
- _cups_vmap_t *vmap_cache; /* VBCS Charmap Cache */
-
/* usersys.c */
http_encryption_t encryption; /* Encryption setting */
char user[65], /* User name */
@@ -134,9 +129,6 @@
/* Default printer */
char ppd_filename[HTTP_MAX_URI];
/* PPD filename */
-
- /* string.c */
- cups_array_t *stringpool; /* String pool */
} _cups_globals_t;
@@ -144,12 +136,9 @@
* Prototypes...
*/
-extern void _cupsCharmapFlush(_cups_globals_t *cg);
extern const char *_cupsGetPassword(const char *prompt);
extern _cups_globals_t *_cupsGlobals(void);
-extern void _cupsLangFlush(_cups_globals_t *cg);
extern void _cupsSetError(ipp_status_t status, const char *message);
-extern void _cupsStrFlush(_cups_globals_t *cg);
/*
Index: cups.spec
===================================================================
RCS file: /cvs/dist/rpms/cups/FC-5/cups.spec,v
retrieving revision 1.137
retrieving revision 1.138
diff -u -r1.137 -r1.138
--- cups.spec 1 Apr 2006 08:25:58 -0000 1.137
+++ cups.spec 2 Apr 2006 19:22:19 -0000 1.138
@@ -7,7 +7,7 @@
Summary: Common Unix Printing System
Name: cups
Version: 1.2
-Release: 0.2.%{beta}.2.4
+Release: 0.2.%{beta}.2.5
License: GPL
Group: System Environment/Daemons
Source: ftp://ftp.easysw.com/pub/cups/test/cups-1.2%{beta}-source.tar.bz2
@@ -39,6 +39,7 @@
Patch16: cups-pie.patch
Patch17: cups-1.1.19-no_rpath.patch
Patch18: cups-language.patch
+Patch19: cups-gnome.patch
Patch22: cups-dest-cache-v2.patch
Patch24: cups-maxlogsize.patch
Patch28: cups-no-propagate-ipp-port.patch
@@ -135,6 +136,7 @@
%endif
%patch17 -p1 -b .no_rpath
%patch18 -p1 -b .language
+%patch19 -p1 -b .gnome
%patch22 -p1 -b .dest-cache-v2
%patch24 -p1 -b .maxlogsize
%patch28 -p1 -b .no-propagate-ipp-port
@@ -385,6 +387,9 @@
%{cups_serverbin}/daemon/cups-lpd
%changelog
+* Sun Apr 2 2006 Tim Waugh <twaugh at redhat.com> 1:1.2-0.2.rc1.2.5
+- Backported svn 5365:5366 change for mutex-protected stringpool.
+
* Sat Apr 1 2006 Tim Waugh <twaugh at redhat.com>
- Fixed _cupsStrFree() (STR #1529).
More information about the fedora-cvs-commits
mailing list