aboutsummaryrefslogtreecommitdiff
path: root/fontconfig/src/fcstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'fontconfig/src/fcstr.c')
-rw-r--r--fontconfig/src/fcstr.c65
1 files changed, 18 insertions, 47 deletions
diff --git a/fontconfig/src/fcstr.c b/fontconfig/src/fcstr.c
index cc1465cc9..cdab38397 100644
--- a/fontconfig/src/fcstr.c
+++ b/fontconfig/src/fcstr.c
@@ -29,24 +29,13 @@
#ifdef HAVE_REGEX_H
#include <regex.h>
#endif
-#ifdef _WIN32
-#include <windows.h>
-#endif
+
+/* Objects MT-safe for readonly access. */
FcChar8 *
FcStrCopy (const FcChar8 *s)
{
- int len;
- FcChar8 *r;
- if (!s)
- return 0;
- len = strlen ((char *) s) + 1;
- r = (FcChar8 *) malloc (len);
- if (!r)
- return 0;
- FcMemAlloc (FC_MEM_STRING, len);
- memcpy (r, s, len);
- return r;
+ return FcStrdup (s);
}
FcChar8 *
@@ -59,7 +48,6 @@ FcStrPlus (const FcChar8 *s1, const FcChar8 *s2)
if (!s)
return 0;
- FcMemAlloc (FC_MEM_STRING, l);
memcpy (s, s1, s1l);
memcpy (s + s1l, s2, s2l + 1);
return s;
@@ -68,7 +56,6 @@ FcStrPlus (const FcChar8 *s1, const FcChar8 *s2)
void
FcStrFree (FcChar8 *s)
{
- FcMemFree (FC_MEM_STRING, strlen ((char *) s) + 1);
free (s);
}
@@ -78,8 +65,6 @@ FcStrFree (FcChar8 *s)
#define FcCaseFoldUpperCount(cf) \
((cf)->method == FC_CASE_FOLD_FULL ? 1 : (cf)->count)
-#define FC_STR_CANON_BUF_LEN 1024
-
typedef struct _FcCaseWalker {
const FcChar8 *read;
const FcChar8 *src;
@@ -206,7 +191,6 @@ FcStrDowncase (const FcChar8 *s)
d = dst = malloc (len + 1);
if (!d)
return 0;
- FcMemAlloc (FC_MEM_STRING, len + 1);
FcStrCaseWalkerInit (s, &w);
while ((*d++ = FcStrCaseWalkerNext (&w)));
return dst;
@@ -782,7 +766,6 @@ FcStrBufDestroy (FcStrBuf *buf)
{
if (buf->allocated)
{
- FcMemFree (FC_MEM_STRBUF, buf->size);
free (buf->buf);
FcStrBufInit (buf, 0, 0);
}
@@ -799,7 +782,6 @@ FcStrBufDone (FcStrBuf *buf)
ret = malloc (buf->len + 1);
if (ret)
{
- FcMemAlloc (FC_MEM_STRING, buf->len + 1);
memcpy (ret, buf->buf, buf->len);
ret[buf->len] = '\0';
}
@@ -832,7 +814,6 @@ FcStrBufChar (FcStrBuf *buf, FcChar8 c)
if (buf->allocated)
{
size = buf->size * 2;
- FcMemFree (FC_MEM_STRBUF, buf->size);
new = realloc (buf->buf, size);
}
else
@@ -850,7 +831,6 @@ FcStrBufChar (FcStrBuf *buf, FcChar8 c)
buf->failed = FcTrue;
return FcFalse;
}
- FcMemAlloc (FC_MEM_STRBUF, size);
buf->size = size;
buf->buf = new;
}
@@ -941,7 +921,6 @@ FcStrDirname (const FcChar8 *file)
dir = malloc ((slash - file) + 1);
if (!dir)
return 0;
- FcMemAlloc (FC_MEM_STRING, (slash - file) + 1);
strncpy ((char *) dir, (const char *) file, slash - file);
dir[slash - file] = '\0';
return dir;
@@ -970,7 +949,6 @@ FcStrCanonAbsoluteFilename (const FcChar8 *s)
file = malloc (size);
if (!file)
return NULL;
- FcMemAlloc (FC_MEM_STRING, size);
slash = NULL;
f = file;
#ifdef _WIN32
@@ -1090,8 +1068,7 @@ FcStrSetCreate (void)
FcStrSet *set = malloc (sizeof (FcStrSet));
if (!set)
return 0;
- FcMemAlloc (FC_MEM_STRSET, sizeof (FcStrSet));
- set->ref = 1;
+ FcRefInit (&set->ref, 1);
set->num = 0;
set->size = 0;
set->strs = 0;
@@ -1112,14 +1089,10 @@ _FcStrSetAppend (FcStrSet *set, FcChar8 *s)
if (!strs)
return FcFalse;
- FcMemAlloc (FC_MEM_STRSET, (set->size + 2) * sizeof (FcChar8 *));
if (set->num)
memcpy (strs, set->strs, set->num * sizeof (FcChar8 *));
if (set->strs)
- {
- FcMemFree (FC_MEM_STRSET, (set->size + 1) * sizeof (FcChar8 *));
free (set->strs);
- }
set->size = set->size + 1;
set->strs = strs;
}
@@ -1247,20 +1220,20 @@ FcStrSetDel (FcStrSet *set, const FcChar8 *s)
void
FcStrSetDestroy (FcStrSet *set)
{
- if (--set->ref == 0)
- {
- int i;
+ int i;
- for (i = 0; i < set->num; i++)
- FcStrFree (set->strs[i]);
- if (set->strs)
- {
- FcMemFree (FC_MEM_STRSET, (set->size + 1) * sizeof (FcChar8 *));
- free (set->strs);
- }
- FcMemFree (FC_MEM_STRSET, sizeof (FcStrSet));
- free (set);
- }
+ /* We rely on this in FcGetDefaultLangs for caching. */
+ if (FcRefIsConst (&set->ref))
+ return;
+
+ if (FcRefDec (&set->ref) != 1)
+ return;
+
+ for (i = 0; i < set->num; i++)
+ FcStrFree (set->strs[i]);
+ if (set->strs)
+ free (set->strs);
+ free (set);
}
FcStrList *
@@ -1271,9 +1244,8 @@ FcStrListCreate (FcStrSet *set)
list = malloc (sizeof (FcStrList));
if (!list)
return 0;
- FcMemAlloc (FC_MEM_STRLIST, sizeof (FcStrList));
list->set = set;
- set->ref++;
+ FcRefInc (&set->ref);
list->n = 0;
return list;
}
@@ -1290,7 +1262,6 @@ void
FcStrListDone (FcStrList *list)
{
FcStrSetDestroy (list->set);
- FcMemFree (FC_MEM_STRLIST, sizeof (FcStrList));
free (list);
}