View | Details | Raw Unified | Return to bug 253212 | Differences between
and this patch

Collapse All | Expand All

(-)b/x11-fonts/fontconfig/Makefile (-54 / +43 lines)
Lines 2-10 Link Here
2
# $FreeBSD$
2
# $FreeBSD$
3
3
4
PORTNAME=	fontconfig
4
PORTNAME=	fontconfig
5
PORTVERSION=	2.13.92
5
DISTVERSION=	2.13.93
6
PORTREVISION?=	2
6
PORTEPOCH=	1
7
PORTEPOCH?=	1
8
CATEGORIES=	x11-fonts
7
CATEGORIES=	x11-fonts
9
MASTER_SITES=	https://www.freedesktop.org/software/fontconfig/release/
8
MASTER_SITES=	https://www.freedesktop.org/software/fontconfig/release/
10
9
Lines 14-89 COMMENT= XML-based font configuration API for X Windows Link Here
14
LICENSE=	MIT
13
LICENSE=	MIT
15
LICENSE_FILE=	${WRKSRC}/COPYING
14
LICENSE_FILE=	${WRKSRC}/COPYING
16
15
17
USES=		gperf tar:xz
18
19
.if !defined(REFERENCE_PORT)
20
21
LIB_DEPENDS=	libfreetype.so:print/freetype2 \
16
LIB_DEPENDS=	libfreetype.so:print/freetype2 \
22
		libexpat.so:textproc/expat2
17
		libexpat.so:textproc/expat2
23
18
24
USES+=		cpe gmake libtool pathfix pkgconfig
19
USES=		cpe gperf meson pkgconfig python:3.5+,build shebangfix tar:xz
25
CPE_VENDOR=	fontconfig_project
20
CPE_VENDOR=	fontconfig_project
26
USE_LDCONFIG=	yes
21
USE_LDCONFIG=	yes
27
GNU_CONFIGURE=	yes
22
28
CONFIGURE_ARGS=	--with-configdir=${PREFIX}/etc/fonts/conf.d \
23
SHEBANG_FILES=	conf.d/link_confs.py \
29
		--with-templatedir=${PREFIX}/etc/fonts/conf.avail \
24
		conf.d/write-35-lang-normalize-conf.py \
30
		--with-xmldir=${PREFIX}/etc/fonts \
25
		fc-case/fc-case.py \
31
		--with-expat-includes=${LOCALBASE}/include \
26
		fc-lang/fc-lang.py
32
		--with-expat-lib=${LOCALBASE}/lib \
27
33
		--with-default-hinting=${PREFERRED_HINTING} \
28
TEST_TARGET=	test
34
		--with-default-fonts=${PREFIX}/share/fonts \
29
35
		--with-add-fonts=${LOCALBASE}/lib/X11/fonts \
30
# Custom configuration variables
36
		--with-cache-dir=/var/db/fontconfig \
31
FCDEFAULTFONTS=	${PREFIX}/share/fonts
37
		--with-pkgconfigdir=${PREFIX}/libdata/pkgconfig \
32
FCADDFONTS=	${LOCALBASE}/lib/X11/fonts
38
		--disable-docs
33
39
34
# To avoid circular depdency docs (including manpages) needs to be disabled as
40
# D6155: static linked library linking added to support statically linked
35
# they depend on textproc/docbook-utils which requires fontconfig
41
# 	 applications, e.g. x11/xforward static option
36
MESON_ARGS=	-Ddefault_library=both -Ddoc=disabled
42
CONFIGURE_ARGS+=	--enable-static
43
44
PKGINSTALL=	${WRKDIR}/pkg-install
45
INSTALL_TARGET=install-strip
46
37
47
PLIST_SUB=	PREFERRED_HINTING=${PREFERRED_HINTING}
38
PLIST_SUB=	PREFERRED_HINTING=${PREFERRED_HINTING}
48
PORTDOCS=	fontconfig-user.html fontconfig-user.pdf fontconfig-user.txt
49
39
50
OPTIONS_DEFINE=	DOCS NLS NO_BITMAPS
40
OPTIONS_DEFINE=	NLS BITMAPS TEST
51
OPTIONS_DEFAULT=HINTING_SLIGHT
41
OPTIONS_DEFAULT=BITMAPS HINTING_SLIGHT
52
OPTIONS_SUB=	yes
42
OPTIONS_SUB=	yes
53
43
54
NO_BITMAPS_DESC=	Reject bitmap fonts by default
55
56
OPTIONS_SINGLE=	HINTING
44
OPTIONS_SINGLE=	HINTING
57
HINTING_DESC=	Preferred pixel hinting configuration
58
.for opt in NONE SLIGHT MEDIUM FULL
45
.for opt in NONE SLIGHT MEDIUM FULL
59
OPTIONS_SINGLE_HINTING+=	HINTING_${opt}
46
OPTIONS_SINGLE_HINTING+=	HINTING_${opt}
60
HINTING_${opt}_DESC=	${opt:tl}
47
HINTING_${opt}_DESC=	${opt:tl}
61
HINTING_${opt}_VARS=	PREFERRED_HINTING=${opt:tl}
48
HINTING_${opt}_VARS=	PREFERRED_HINTING=${opt:tl}
62
.endfor
49
.endfor
63
50
64
NLS_USES=		gettext
51
BITMAPS_DESC=	Enable bitmap fonts by default
65
NLS_CONFIGURE_ENABLE=	nls
52
HINTING_DESC=	Preferred pixel hinting configuration
53
54
NLS_USES=		gettext-tools
55
NLS_MESON_ENABLED=	nls
56
57
TEST_MESON_ENABLED=	tests
66
58
67
post-patch-NO_BITMAPS-on:
59
post-patch:
68
	@${REINPLACE_CMD} -i '.bitmaps.bak' -e \
60
	@${REINPLACE_CMD} -e 's|%%FCDEFAULTFONTS%%|${FCDEFAULTFONTS}|g' \
69
		'/^CONF_LINKS =/s|$$|\${.newline}	70-no-bitmaps.conf \\|' \
61
	    ${PATCH_WRKSRC}/meson.build
70
		${WRKSRC}/conf.d/Makefile.in
62
	@${REINPLACE_CMD} -e 's|%%FCADDFONTS%%|${FCADDFONTS}|g' \
63
	    ${PATCH_WRKSRC}/meson.build
64
	@${REINPLACE_CMD} -e 's|%%FCPREFERREDHINTING%%|${PREFERRED_HINTING}|g' \
65
	    ${PATCH_WRKSRC}/conf.d/meson.build
71
66
72
post-install:
67
post-install:
73
	${INSTALL_MAN} ${WRKSRC}/fc-*/*.1 \
68
	${MV} ${STAGEDIR}${PREFIX}/etc/fonts/fonts.conf ${STAGEDIR}${PREFIX}/etc/fonts/fonts.conf.sample
74
		${STAGEDIR}${PREFIX}/man/man1
69
	@${MKDIR} ${STAGEDIR}/var/db/fontconfig
75
	${INSTALL_MAN} ${WRKSRC}/doc/*.5 \
76
		${STAGEDIR}${PREFIX}/man/man5
77
	${INSTALL_DATA} ${WRKSRC}/fonts.conf \
78
		${STAGEDIR}${PREFIX}/etc/fonts/fonts.conf.sample
79
	@${SED} -e 's|%%PREFIX%%|${PREFIX}| ; \
80
		s|%%LOCALBASE%%|${LOCALBASE}|' < ${FILESDIR}/pkg-install.in \
81
		> ${PKGINSTALL}
82
83
post-install-DOCS-on:
84
	@${MKDIR} ${STAGEDIR}${DOCSDIR}
85
	${INSTALL_DATA} ${PORTDOCS:S|^|${WRKSRC}/doc/|} ${STAGEDIR}${DOCSDIR}
86
70
87
.include <bsd.port.mk>
71
post-install-BITMAPS-off:
72
	${RLN} ${STAGEDIR}${PREFIX}/etc/fonts/conf.avail/70-no-bitmaps.conf ${STAGEDIR}${PREFIX}/etc/fonts/conf.d/70-no-bitmaps.conf
73
74
post-install-BITMAPS-on:
75
	${RM} ${STAGEDIR}${PREFIX}/etc/fonts/conf.d/70-no-bitmaps.conf
76
	${RLN} ${STAGEDIR}${PREFIX}/etc/fonts/conf.avail/70-yes-bitmaps.conf ${STAGEDIR}${PREFIX}/etc/fonts/conf.d/70-yes-bitmaps.conf
88
77
89
.endif
78
.include <bsd.port.mk>
(-)b/x11-fonts/fontconfig/distinfo (-3 / +3 lines)
Lines 1-3 Link Here
1
TIMESTAMP = 1565349179
1
TIMESTAMP = 1612204906
2
SHA256 (fontconfig-2.13.92.tar.xz) = 506e61283878c1726550bc94f2af26168f1e9f2106eac77eaaf0b2cdfad66e4e
2
SHA256 (fontconfig-2.13.93.tar.xz) = ea968631eadc5739bc7c8856cef5c77da812d1f67b763f5e51b57b8026c1a0a0
3
SIZE (fontconfig-2.13.92.tar.xz) = 1413128
3
SIZE (fontconfig-2.13.93.tar.xz) = 1418288
(-)a/x11-fonts/fontconfig/files/patch-2.13.92.diff (-1795 lines)
Removed Link Here
1
# Affect FC_FONT_HAS_HINT property to score on matcher
2
# https://cgit.freedesktop.org/fontconfig/commit/?id=cb1036a7c7f1cb79fa799b1db368c86b018ec368
3
# Add missing return type for FcFontSet* functions
4
# https://cgit.freedesktop.org/fontconfig/commit/?id=7172f08d4231c59cf14dab9ebab714df37e352ac
5
# Do not return FcFalse from FcConfigParseAndLoad*() if complain is set to false
6
# https://cgit.freedesktop.org/fontconfig/commit/?id=fcada522913e5e07efa6367eff87ace9f06d24c8
7
# conf: Add JoyPixels emoji font
8
# https://cgit.freedesktop.org/fontconfig/commit/?id=65087ac7ce4cc5f2109967c1380b474955dcb590
9
# Warn as well if no directory name for cachedir provided
10
# https://cgit.freedesktop.org/fontconfig/commit/?id=75eadca26648abf69497691ff0f4c7803b9ff23c
11
# Take effect sysroot functionality to the default config file
12
# https://cgit.freedesktop.org/fontconfig/commit/?id=cd51cb241aad7b362b793200ca7d42595c14f52b
13
# Read latest cache in paths
14
# https://cgit.freedesktop.org/fontconfig/commit/?id=c9862b6ea7c3234b29f6500c7d07359847e55ed7
15
# Fix a memory leak caused by the previous commit
16
# https://cgit.freedesktop.org/fontconfig/commit/?id=a45fc8a33256d9d3ea0ea7947f33c8e5e3cc7238
17
# Use FcConfigReference/Destroy appropriately instead of FcConfigGetCurrent
18
# https://cgit.freedesktop.org/fontconfig/commit/?id=b5bcf61fe789e66df2de609ec246cb7e4d326180
19
# Fix potential race condition in FcConfigSetCurrent and FcConfigReference
20
# https://cgit.freedesktop.org/fontconfig/commit/?id=aa8c8cfa9fb2563482336249e3f56459099fcf6e
21
# Correct reset-dirs in DTD
22
# https://cgit.freedesktop.org/fontconfig/commit/?id=a4aa66a858f1ecd375c5efe5916398281f73f794
23
# Don't add a value for FC_FULLNAME in meta face
24
# https://cgit.freedesktop.org/fontconfig/commit/?id=8249f871b373db5c6559f8c48242beed612b23a0
25
# Add proper fullname for named-instances
26
# https://cgit.freedesktop.org/fontconfig/commit/?id=452be8125f0e2a18a7dfef469e05d19374d36307
27
# Fix the process substitution doesn't work with FONTCONFIG_FILE
28
# https://cgit.freedesktop.org/fontconfig/commit/?id=71d6866d381a0ab3585eb9ee760aeec98e722359
29
# Fix memory leaks
30
# https://cgit.freedesktop.org/fontconfig/commit/?id=61573ad5f7c4dd0860d613d99d0086433240eb75
31
# Set name_mapping to NULL after freeing to avoid risk of double-free.
32
# https://cgit.freedesktop.org/fontconfig/commit/?id=6edaaa4d1823518a97fb4cc3004d110b1046f742
33
# Fix assertion in FcFini()
34
# https://cgit.freedesktop.org/fontconfig/commit/?id=fbc05949ef52c8a8d69233eed77f6636dffec280
35
# Set exact boolean value to color property
36
# https://cgit.freedesktop.org/fontconfig/commit/?id=d3bfbea7dc53aa7fa52aa9616235a23d4507da1b
37
# Fix assertion in FcCacheFini() again
38
# https://cgit.freedesktop.org/fontconfig/commit/?id=6f6b39780215714386606ca1c5457a7106639ff4
39
40
Excluding changes for the following files: test/Makefile.am, test/run-test.sh,
41
test/test-bz1744377.c, test/test-crbug1004254.c, test/test-issue180.c.
42
43
--- conf.d/45-generic.conf.orig	2018-06-05 10:36:38 UTC
44
+++ conf.d/45-generic.conf
45
@@ -38,6 +38,10 @@
46
 		<default><family>emoji</family></default>
47
 	</alias>
48
 	<alias binding="same">
49
+		<family>JoyPixels</family>
50
+		<default><family>emoji</family></default>
51
+	</alias>
52
+	<alias binding="same">
53
 		<family>Emoji One</family>
54
 		<default><family>emoji</family></default>
55
 	</alias>
56
--- conf.d/60-generic.conf.orig	2018-06-05 10:36:38 UTC
57
+++ conf.d/60-generic.conf
58
@@ -42,6 +42,7 @@
59
 			<family>EmojiOne Mozilla</family> <!-- Mozilla -->
60
 			<!-- Third-Party fonts -->
61
 			<family>Emoji Two</family>
62
+			<family>JoyPixels</family>
63
 			<family>Emoji One</family>
64
 			<!-- Non-color -->
65
 			<family>Noto Emoji</family> <!-- Google -->
66
--- doc/fcconfig.fncs.orig	2019-05-08 08:22:25 UTC
67
+++ doc/fcconfig.fncs
68
@@ -174,6 +174,10 @@ Returns one of the two sets of fonts fro
69
 by <parameter>set</parameter>. This font set is owned by the library and must
70
 not be modified or freed.
71
 If <parameter>config</parameter> is NULL, the current configuration is used.
72
+    </para><para>
73
+This function isn't MT-safe. <function>FcConfigReference</function> must be called
74
+before using this and then <function>FcConfigDestroy</function> when
75
+the return value is no longer referenced.
76
 @@
77
 
78
 @RET@           FcBlanks *
79
@@ -344,6 +348,15 @@ to be up to date, and used.
80
 @TYPE1@         const FcChar8 *			@ARG1@          name
81
 @PURPOSE@	Find a config file
82
 @DESC@
83
+This function is deprecated and is replaced by <function>FcConfigGetFilename</function>.
84
+@@
85
+
86
+@RET@           FcChar8 *
87
+@FUNC@          FcConfigGetFilename
88
+@TYPE1@         FcConfig *			@ARG1@          config
89
+@TYPE2@         const FcChar8 *			@ARG2@          name
90
+@PURPOSE@	Find a config file
91
+@DESC@
92
 Given the specified external entity name, return the associated filename.
93
 This provides applications a way to convert various configuration file
94
 references into filename form.
95
@@ -355,6 +368,8 @@ refers to a file in the current users ho
96
 doesn't start with '/', it refers to a file in the default configuration
97
 directory; the built-in default directory can be overridden with the
98
 FONTCONFIG_PATH environment variable.
99
+    </para><para>
100
+The result of this function is affected by the FONTCONFIG_SYSROOT environment variable or equivalent functionality.
101
 @@
102
 
103
 @RET@		FcBool
104
@@ -396,6 +411,10 @@ parse error, semantic error or allocatio
105
 Obtains the system root directory in 'config' if available. All files
106
 (including file properties in patterns) obtained from this 'config' are
107
 relative to this system root directory.
108
+    </para><para>
109
+This function isn't MT-safe. <function>FcConfigReference</function> must be called
110
+before using this and then <function>FcConfigDestroy</function> when
111
+the return value is no longer referenced.
112
 @SINCE@		2.10.92
113
 @@
114
 
115
@@ -422,6 +441,10 @@ When setting this on the current config 
116
 @PURPOSE@	Initialize the iterator
117
 @DESC@
118
 Initialize 'iter' with the first iterator in the config file information list.
119
+    </para><para>
120
+This function isn't MT-safe. <function>FcConfigReference</function> must be called
121
+before using this and then <function>FcConfigDestroy</function> when the relevant
122
+values are no longer referenced.
123
 @SINCE@		2.12.91
124
 @@
125
 
126
@@ -433,6 +456,10 @@ Initialize 'iter' with the first iterato
127
 @DESC@
128
 Set 'iter' to point to the next node in the config file information list.
129
 If there is no next node, FcFalse is returned.
130
+    </para><para>
131
+This function isn't MT-safe. <function>FcConfigReference</function> must be called
132
+before using <function>FcConfigFileInfoIterInit</function> and then
133
+<function>FcConfigDestroy</function> when the relevant values are no longer referenced.
134
 @SINCE@		2.12.91
135
 @@
136
 
137
@@ -448,5 +475,9 @@ If there is no next node, FcFalse is ret
138
 Obtain the filename, the description and the flag whether it is enabled or not
139
 for 'iter' where points to current configuration file information.
140
 If the iterator is invalid, FcFalse is returned.
141
+    </para><para>
142
+This function isn't MT-safe. <function>FcConfigReference</function> must be called
143
+before using <function>FcConfigFileInfoIterInit</function> and then
144
+<function>FcConfigDestroy</function> when the relevant values are no longer referenced.
145
 @SINCE@		2.12.91
146
 @@
147
--- doc/fcfontset.fncs.orig	2016-07-11 02:41:05 UTC
148
+++ doc/fcfontset.fncs
149
@@ -97,7 +97,7 @@ of the output is designed to be of help 
150
 change at any time.
151
 @@
152
 
153
-@RET@		
154
+@RET@		FcFontSet *
155
 @FUNC@		FcFontSetSort
156
 @TYPE1@         FcConfig *			@ARG1@		config
157
 @TYPE2@		FcFontSet **			@ARG2@		sets
158
@@ -128,7 +128,7 @@ modify these patterns.  Instead, they sh
159
 The FcFontSet returned by FcFontSetSort is destroyed by calling FcFontSetDestroy.
160
 @@
161
 
162
-@RET@		
163
+@RET@		void
164
 @FUNC@		FcFontSetSortDestroy
165
 @TYPE1@		FcFontSet *			@ARG1@		set
166
 @PURPOSE@	DEPRECATED destroy a font set
167
--- fontconfig/fontconfig.h.orig	2019-08-09 11:09:32 UTC
168
+++ fontconfig/fontconfig.h
169
@@ -375,7 +375,7 @@ FcPublic FcBool
170
 FcDirCacheClean (const FcChar8 *cache_dir, FcBool verbose);
171
 
172
 FcPublic void
173
-FcCacheCreateTagFile (const FcConfig *config);
174
+FcCacheCreateTagFile (FcConfig *config);
175
 
176
 FcPublic FcBool
177
 FcDirCacheCreateUUID (FcChar8  *dir,
178
@@ -394,6 +394,10 @@ FcPublic FcBool
179
 FcConfigEnableHome (FcBool enable);
180
 
181
 FcPublic FcChar8 *
182
+FcConfigGetFilename (FcConfig      *config,
183
+		     const FcChar8 *url);
184
+
185
+FcPublic FcChar8 *
186
 FcConfigFilename (const FcChar8 *url);
187
     
188
 FcPublic FcConfig *
189
@@ -433,7 +437,7 @@ FcPublic FcBlanks *
190
 FcConfigGetBlanks (FcConfig *config);
191
 
192
 FcPublic FcStrList *
193
-FcConfigGetCacheDirs (const FcConfig	*config);
194
+FcConfigGetCacheDirs (FcConfig	*config);
195
 
196
 FcPublic int
197
 FcConfigGetRescanInterval (FcConfig *config);
198
--- fonts.dtd.orig	2019-05-08 08:22:25 UTC
199
+++ fonts.dtd
200
@@ -124,7 +124,7 @@
201
 <!--
202
     Reset the list of fonts directories
203
 -->
204
-<!ELEMENT reset-dirs >
205
+<!ELEMENT reset-dirs EMPTY>
206
 
207
 <!--
208
     Periodically rescan the font configuration and
209
--- src/fccache.c.orig	2019-07-29 05:17:34 UTC
210
+++ src/fccache.c
211
@@ -58,11 +58,15 @@ FcDirCacheDeleteUUID (const FcChar8  *di
212
 {
213
     FcBool ret = FcTrue;
214
 #ifndef _WIN32
215
-    const FcChar8 *sysroot = FcConfigGetSysRoot (config);
216
+    const FcChar8 *sysroot;
217
     FcChar8 *target, *d;
218
     struct stat statb;
219
     struct timeval times[2];
220
 
221
+    config = FcConfigReference (config);
222
+    if (!config)
223
+	return FcFalse;
224
+    sysroot = FcConfigGetSysRoot (config);
225
     if (sysroot)
226
 	d = FcStrBuildFilename (sysroot, dir, NULL);
227
     else
228
@@ -94,6 +98,7 @@ FcDirCacheDeleteUUID (const FcChar8  *di
229
 bail:
230
     FcStrFree (d);
231
 #endif
232
+    FcConfigDestroy (config);
233
 
234
     return ret;
235
 }
236
@@ -265,7 +270,13 @@ FcDirCacheUnlink (const FcChar8 *dir, Fc
237
 #endif
238
     FcStrList	*list;
239
     FcChar8	*cache_dir;
240
-    const FcChar8 *sysroot = FcConfigGetSysRoot (config);
241
+    const FcChar8 *sysroot;
242
+    FcBool	ret = FcTrue;
243
+
244
+    config = FcConfigReference (config);
245
+    if (!config)
246
+	return FcFalse;
247
+    sysroot = FcConfigGetSysRoot (config);
248
 
249
     FcDirCacheBasenameMD5 (config, dir, cache_base);
250
 #ifndef _WIN32
251
@@ -274,7 +285,10 @@ FcDirCacheUnlink (const FcChar8 *dir, Fc
252
 
253
     list = FcStrListCreate (config->cacheDirs);
254
     if (!list)
255
-        return FcFalse;
256
+    {
257
+	ret = FcFalse;
258
+	goto bail;
259
+    }
260
 	
261
     while ((cache_dir = FcStrListNext (list)))
262
     {
263
@@ -304,8 +318,11 @@ FcDirCacheUnlink (const FcChar8 *dir, Fc
264
     FcDirCacheDeleteUUID (dir, config);
265
     /* return FcFalse if something went wrong */
266
     if (cache_dir)
267
-	return FcFalse;
268
-    return FcTrue;
269
+	ret = FcFalse;
270
+bail:
271
+    FcConfigDestroy (config);
272
+
273
+    return ret;
274
 }
275
 
276
 static int
277
@@ -338,7 +355,7 @@ FcDirCacheOpenFile (const FcChar8 *cache
278
 static FcBool
279
 FcDirCacheProcess (FcConfig *config, const FcChar8 *dir,
280
 		   FcBool (*callback) (FcConfig *config, int fd, struct stat *fd_stat,
281
-				       struct stat *dir_stat, void *closure),
282
+				       struct stat *dir_stat, struct timeval *cache_mtime, void *closure),
283
 		   void *closure, FcChar8 **cache_file_ret)
284
 {
285
     int		fd = -1;
286
@@ -348,6 +365,7 @@ FcDirCacheProcess (FcConfig *config, con
287
     struct stat file_stat, dir_stat;
288
     FcBool	ret = FcFalse;
289
     const FcChar8 *sysroot = FcConfigGetSysRoot (config);
290
+    struct timeval latest_mtime = (struct timeval){ 0 };
291
 
292
     if (sysroot)
293
 	d = FcStrBuildFilename (sysroot, dir, NULL);
294
@@ -372,6 +390,7 @@ FcDirCacheProcess (FcConfig *config, con
295
 #ifndef _WIN32
296
 	FcBool retried = FcFalse;
297
 #endif
298
+
299
 	if (sysroot)
300
 	    cache_hashed = FcStrBuildFilename (sysroot, cache_dir, cache_base, NULL);
301
 	else
302
@@ -383,16 +402,21 @@ FcDirCacheProcess (FcConfig *config, con
303
 #endif
304
         fd = FcDirCacheOpenFile (cache_hashed, &file_stat);
305
         if (fd >= 0) {
306
-	    ret = (*callback) (config, fd, &file_stat, &dir_stat, closure);
307
+	    ret = (*callback) (config, fd, &file_stat, &dir_stat, &latest_mtime, closure);
308
 	    close (fd);
309
 	    if (ret)
310
 	    {
311
 		if (cache_file_ret)
312
+		{
313
+		    if (*cache_file_ret)
314
+			FcStrFree (*cache_file_ret);
315
 		    *cache_file_ret = cache_hashed;
316
+		}
317
 		else
318
 		    FcStrFree (cache_hashed);
319
-		break;
320
 	    }
321
+	    else
322
+		FcStrFree (cache_hashed);
323
 	}
324
 #ifndef _WIN32
325
 	else if (!retried)
326
@@ -412,12 +436,17 @@ FcDirCacheProcess (FcConfig *config, con
327
 		    break;
328
 		goto retry;
329
 	    }
330
+	    else
331
+		FcStrFree (cache_hashed);
332
 	}
333
 #endif
334
-    	FcStrFree (cache_hashed);
335
+	else
336
+	    FcStrFree (cache_hashed);
337
     }
338
     FcStrListDone (list);
339
 
340
+    if (closure)
341
+	return !!(*((FcCache **)closure) != NULL);
342
     return ret;
343
 }
344
 
345
@@ -765,7 +794,18 @@ FcCacheFini (void)
346
     int		    i;
347
 
348
     for (i = 0; i < FC_CACHE_MAX_LEVEL; i++)
349
-	assert (fcCacheChains[i] == NULL);
350
+    {
351
+	if (FcDebug() & FC_DBG_CACHE)
352
+	{
353
+	    if (fcCacheChains[i] != NULL)
354
+	    {
355
+		FcCacheSkip *s = fcCacheChains[i];
356
+		printf("Fontconfig error: not freed %p (dir: %s, refcount %d)\n", s->cache, FcCacheDir(s->cache), s->ref.count);
357
+	    }
358
+	}
359
+	else
360
+	    assert (fcCacheChains[i] == NULL);
361
+    }
362
     assert (fcCacheMaxLevel == 0);
363
 
364
     free_lock ();
365
@@ -998,12 +1038,31 @@ FcDirCacheUnload (FcCache *cache)
366
 }
367
 
368
 static FcBool
369
-FcDirCacheMapHelper (FcConfig *config, int fd, struct stat *fd_stat, struct stat *dir_stat, void *closure)
370
+FcDirCacheMapHelper (FcConfig *config, int fd, struct stat *fd_stat, struct stat *dir_stat, struct timeval *latest_cache_mtime, void *closure)
371
 {
372
     FcCache *cache = FcDirCacheMapFd (config, fd, fd_stat, dir_stat);
373
+    struct timeval cache_mtime;
374
 
375
     if (!cache)
376
 	return FcFalse;
377
+    cache_mtime.tv_sec = fd_stat->st_mtime;
378
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
379
+    cache_mtime.tv_usec = fd_stat->st_mtim.tv_nsec / 1000;
380
+#else
381
+    cache_mtime.tv_usec = 0;
382
+#endif
383
+    if (timercmp (latest_cache_mtime, &cache_mtime, <))
384
+    {
385
+	if (*((FcCache **) closure))
386
+	    FcDirCacheUnload (*((FcCache **) closure));
387
+    }
388
+    else
389
+    {
390
+	FcDirCacheUnload (cache);
391
+	return FcFalse;
392
+    }
393
+    latest_cache_mtime->tv_sec = cache_mtime.tv_sec;
394
+    latest_cache_mtime->tv_usec = cache_mtime.tv_usec;
395
     *((FcCache **) closure) = cache;
396
     return FcTrue;
397
 }
398
@@ -1013,10 +1072,15 @@ FcDirCacheLoad (const FcChar8 *dir, FcCo
399
 {
400
     FcCache *cache = NULL;
401
 
402
+    config = FcConfigReference (config);
403
+    if (!config)
404
+	return NULL;
405
     if (!FcDirCacheProcess (config, dir,
406
 			    FcDirCacheMapHelper,
407
 			    &cache, cache_file))
408
-	return NULL;
409
+	cache = NULL;
410
+
411
+    FcConfigDestroy (config);
412
 
413
     return cache;
414
 }
415
@@ -1027,13 +1091,18 @@ FcDirCacheLoadFile (const FcChar8 *cache
416
     int	fd;
417
     FcCache *cache;
418
     struct stat	my_file_stat;
419
+    FcConfig *config;
420
 
421
     if (!file_stat)
422
 	file_stat = &my_file_stat;
423
+    config = FcConfigReference (NULL);
424
+    if (!config)
425
+	return NULL;
426
     fd = FcDirCacheOpenFile (cache_file, file_stat);
427
     if (fd < 0)
428
 	return NULL;
429
-    cache = FcDirCacheMapFd (FcConfigGetCurrent (), fd, file_stat, NULL);
430
+    cache = FcDirCacheMapFd (config, fd, file_stat, NULL);
431
+    FcConfigDestroy (config);
432
     close (fd);
433
     return cache;
434
 }
435
@@ -1093,7 +1162,7 @@ FcDirChecksumNano (struct stat *statb)
436
  * the magic number and the size field
437
  */
438
 static FcBool
439
-FcDirCacheValidateHelper (FcConfig *config, int fd, struct stat *fd_stat, struct stat *dir_stat, void *closure FC_UNUSED)
440
+FcDirCacheValidateHelper (FcConfig *config, int fd, struct stat *fd_stat, struct stat *dir_stat, struct timeval *latest_cache_mtime, void *closure FC_UNUSED)
441
 {
442
     FcBool  ret = FcTrue;
443
     FcCache	c;
444
@@ -1127,12 +1196,16 @@ FcBool
445
 FcDirCacheValid (const FcChar8 *dir)
446
 {
447
     FcConfig	*config;
448
+    FcBool	ret;
449
 
450
-    config = FcConfigGetCurrent ();
451
+    config = FcConfigReference (NULL);
452
     if (!config)
453
         return FcFalse;
454
 
455
-    return FcDirCacheValidConfig (dir, config);
456
+    ret = FcDirCacheValidConfig (dir, config);
457
+    FcConfigDestroy (config);
458
+
459
+    return ret;
460
 }
461
 
462
 /*
463
@@ -1410,9 +1483,13 @@ FcDirCacheClean (const FcChar8 *cache_di
464
     FcCache	*cache;
465
     struct stat	target_stat;
466
     const FcChar8 *sysroot;
467
+    FcConfig	*config;
468
 
469
+    config = FcConfigReference (NULL);
470
+    if (!config)
471
+	return FcFalse;
472
     /* FIXME: this API needs to support non-current FcConfig */
473
-    sysroot = FcConfigGetSysRoot (NULL);
474
+    sysroot = FcConfigGetSysRoot (config);
475
     if (sysroot)
476
 	dir = FcStrBuildFilename (sysroot, cache_dir, NULL);
477
     else
478
@@ -1420,7 +1497,8 @@ FcDirCacheClean (const FcChar8 *cache_di
479
     if (!dir)
480
     {
481
 	fprintf (stderr, "Fontconfig error: %s: out of memory\n", cache_dir);
482
-	return FcFalse;
483
+	ret = FcFalse;
484
+	goto bail;
485
     }
486
     if (access ((char *) dir, W_OK) != 0)
487
     {
488
@@ -1497,8 +1575,10 @@ FcDirCacheClean (const FcChar8 *cache_di
489
     }
490
 
491
     closedir (d);
492
-  bail0:
493
+bail0:
494
     FcStrFree (dir);
495
+bail:
496
+    FcConfigDestroy (config);
497
 
498
     return ret;
499
 }
500
@@ -1940,15 +2020,20 @@ FcDirCacheCreateTagFile (const FcChar8 *
501
 }
502
 
503
 void
504
-FcCacheCreateTagFile (const FcConfig *config)
505
+FcCacheCreateTagFile (FcConfig *config)
506
 {
507
     FcChar8   *cache_dir = NULL, *d = NULL;
508
     FcStrList *list;
509
-    const FcChar8 *sysroot = FcConfigGetSysRoot (config);
510
+    const FcChar8 *sysroot;
511
+
512
+    config = FcConfigReference (config);
513
+    if (!config)
514
+	return;
515
+    sysroot = FcConfigGetSysRoot (config);
516
 
517
     list = FcConfigGetCacheDirs (config);
518
     if (!list)
519
-	return;
520
+	goto bail;
521
 
522
     while ((cache_dir = FcStrListNext (list)))
523
     {
524
@@ -1964,6 +2049,8 @@ FcCacheCreateTagFile (const FcConfig *co
525
     if (d)
526
 	FcStrFree (d);
527
     FcStrListDone (list);
528
+bail:
529
+    FcConfigDestroy (config);
530
 }
531
 
532
 #define __fccache__
533
--- src/fccfg.c.orig	2019-05-08 08:22:25 UTC
534
+++ src/fccfg.c
535
@@ -33,6 +33,49 @@
536
 #endif
537
 
538
 static FcConfig    *_fcConfig; /* MT-safe */
539
+static FcMutex	   *_lock;
540
+
541
+static void
542
+lock_config (void)
543
+{
544
+    FcMutex *lock;
545
+retry:
546
+    lock = fc_atomic_ptr_get (&_lock);
547
+    if (!lock)
548
+    {
549
+	lock = (FcMutex *) malloc (sizeof (FcMutex));
550
+	FcMutexInit (lock);
551
+	if (!fc_atomic_ptr_cmpexch (&_lock, NULL, lock))
552
+	{
553
+	    FcMutexFinish (lock);
554
+	    goto retry;
555
+	}
556
+	FcMutexLock (lock);
557
+	/* Initialize random state */
558
+	FcRandom ();
559
+	return;
560
+    }
561
+    FcMutexLock (lock);
562
+}
563
+
564
+static void
565
+unlock_config (void)
566
+{
567
+    FcMutexUnlock (_lock);
568
+}
569
+
570
+static void
571
+free_lock (void)
572
+{
573
+    FcMutex *lock;
574
+
575
+    lock = fc_atomic_ptr_get (&_lock);
576
+    if (lock && fc_atomic_ptr_cmpexch (&_lock, lock, NULL))
577
+    {
578
+	FcMutexFinish (lock);
579
+	free (lock);
580
+    }
581
+}
582
 
583
 static FcConfig *
584
 FcConfigEnsure (void)
585
@@ -44,8 +87,9 @@ retry:
586
     {
587
 	config = FcInitLoadConfigAndFonts ();
588
 
589
-	if (!fc_atomic_ptr_cmpexch (&_fcConfig, NULL, config)) {
590
-	    FcConfigDestroy (config);
591
+	if (!config || !fc_atomic_ptr_cmpexch (&_fcConfig, NULL, config)) {
592
+	    if (config)
593
+		FcConfigDestroy (config);
594
 	    goto retry;
595
 	}
596
     }
597
@@ -76,6 +120,7 @@ FcConfigFini (void)
598
     FcConfig *cfg = fc_atomic_ptr_get (&_fcConfig);
599
     if (cfg && fc_atomic_ptr_cmpexch (&_fcConfig, cfg, NULL))
600
 	FcConfigDestroy (cfg);
601
+    free_lock ();
602
 }
603
 
604
 static FcChar8 *
605
@@ -237,12 +282,12 @@ FcConfigUptoDate (FcConfig *config)
606
 {
607
     FcFileTime	config_time, config_dir_time, font_time;
608
     time_t	now = time(0);
609
+    FcBool	ret = FcTrue;
610
+
611
+    config = FcConfigReference (config);
612
     if (!config)
613
-    {
614
-	config = FcConfigGetCurrent ();
615
-	if (!config)
616
-	    return FcFalse;
617
-    }
618
+	return FcFalse;
619
+
620
     config_time = FcConfigNewestFile (config->configFiles);
621
     config_dir_time = FcConfigNewestFile (config->configDirs);
622
     font_time = FcConfigNewestFile (config->fontDirs);
623
@@ -258,13 +303,19 @@ FcConfigUptoDate (FcConfig *config)
624
 	    fprintf (stderr,
625
                     "Fontconfig warning: Directory/file mtime in the future. New fonts may not be detected.\n");
626
 	    config->rescanTime = now;
627
-	    return FcTrue;
628
+	    goto bail;
629
 	}
630
 	else
631
-	    return FcFalse;
632
+	{
633
+	    ret = FcFalse;
634
+	    goto bail;
635
+	}
636
     }
637
     config->rescanTime = now;
638
-    return FcTrue;
639
+bail:
640
+    FcConfigDestroy (config);
641
+
642
+    return ret;
643
 }
644
 
645
 FcExpr *
646
@@ -291,12 +342,31 @@ FcConfigReference (FcConfig *config)
647
 {
648
     if (!config)
649
     {
650
-	config = FcConfigGetCurrent ();
651
+	/* lock during obtaining the value from _fcConfig and count up refcount there,
652
+	 * there are the race between them.
653
+	 */
654
+	lock_config ();
655
+    retry:
656
+	config = fc_atomic_ptr_get (&_fcConfig);
657
 	if (!config)
658
-	    return 0;
659
-    }
660
+	{
661
+	    unlock_config ();
662
 
663
-    FcRefInc (&config->ref);
664
+	    config = FcInitLoadConfigAndFonts ();
665
+	    if (!config)
666
+		goto retry;
667
+	    lock_config ();
668
+	    if (!fc_atomic_ptr_cmpexch (&_fcConfig, NULL, config))
669
+	    {
670
+		FcConfigDestroy (config);
671
+		goto retry;
672
+	    }
673
+	}
674
+	FcRefInc (&config->ref);
675
+	unlock_config ();
676
+    }
677
+    else
678
+	FcRefInc (&config->ref);
679
 
680
     return config;
681
 }
682
@@ -475,25 +545,32 @@ FcBool
683
 FcConfigBuildFonts (FcConfig *config)
684
 {
685
     FcFontSet	    *fonts;
686
+    FcBool	    ret = FcTrue;
687
 
688
+    config = FcConfigReference (config);
689
     if (!config)
690
-    {
691
-	config = FcConfigGetCurrent ();
692
-	if (!config)
693
-	    return FcFalse;
694
-    }
695
+	return FcFalse;
696
 	
697
     fonts = FcFontSetCreate ();
698
     if (!fonts)
699
-	return FcFalse;
700
+    {
701
+	ret = FcFalse;
702
+	goto bail;
703
+    }
704
 
705
     FcConfigSetFonts (config, fonts, FcSetSystem);
706
 
707
     if (!FcConfigAddDirList (config, FcSetSystem, config->fontDirs))
708
-	return FcFalse;
709
+    {
710
+	ret = FcFalse;
711
+	goto bail;
712
+    }
713
     if (FcDebug () & FC_DBG_FONTSET)
714
 	FcFontSetPrint (fonts);
715
-    return FcTrue;
716
+bail:
717
+    FcConfigDestroy (config);
718
+
719
+    return ret;
720
 }
721
 
722
 FcBool
723
@@ -501,20 +578,29 @@ FcConfigSetCurrent (FcConfig *config)
724
 {
725
     FcConfig *cfg;
726
 
727
+    if (config)
728
+    {
729
+	if (!config->fonts[FcSetSystem])
730
+	    if (!FcConfigBuildFonts (config))
731
+		return FcFalse;
732
+	FcRefInc (&config->ref);
733
+    }
734
+
735
+    lock_config ();
736
 retry:
737
     cfg = fc_atomic_ptr_get (&_fcConfig);
738
 
739
     if (config == cfg)
740
+    {
741
+	unlock_config ();
742
+	if (config)
743
+	    FcConfigDestroy (config);
744
 	return FcTrue;
745
-
746
-    if (config && !config->fonts[FcSetSystem])
747
-	if (!FcConfigBuildFonts (config))
748
-	    return FcFalse;
749
+    }
750
 
751
     if (!fc_atomic_ptr_cmpexch (&_fcConfig, cfg, config))
752
 	goto retry;
753
-
754
-    FcConfigReference (config);
755
+    unlock_config ();
756
     if (cfg)
757
 	FcConfigDestroy (cfg);
758
 
759
@@ -537,13 +623,15 @@ FcConfigAddConfigDir (FcConfig	    *conf
760
 FcStrList *
761
 FcConfigGetConfigDirs (FcConfig   *config)
762
 {
763
+    FcStrList *ret;
764
+
765
+    config = FcConfigReference (config);
766
     if (!config)
767
-    {
768
-	config = FcConfigGetCurrent ();
769
-	if (!config)
770
-	    return 0;
771
-    }
772
-    return FcStrListCreate (config->configDirs);
773
+	return NULL;
774
+    ret = FcStrListCreate (config->configDirs);
775
+    FcConfigDestroy (config);
776
+
777
+    return ret;
778
 }
779
 
780
 FcBool
781
@@ -579,13 +667,15 @@ FcConfigResetFontDirs (FcConfig *config)
782
 FcStrList *
783
 FcConfigGetFontDirs (FcConfig	*config)
784
 {
785
+    FcStrList *ret;
786
+
787
+    config = FcConfigReference (config);
788
     if (!config)
789
-    {
790
-	config = FcConfigGetCurrent ();
791
-	if (!config)
792
-	    return 0;
793
-    }
794
-    return FcStrListCreate (config->fontDirs);
795
+	return NULL;
796
+    ret = FcStrListCreate (config->fontDirs);
797
+    FcConfigDestroy (config);
798
+
799
+    return ret;
800
 }
801
 
802
 static FcBool
803
@@ -670,15 +760,17 @@ FcConfigAddCacheDir (FcConfig	    *confi
804
 }
805
 
806
 FcStrList *
807
-FcConfigGetCacheDirs (const FcConfig *config)
808
+FcConfigGetCacheDirs (FcConfig *config)
809
 {
810
+    FcStrList *ret;
811
+
812
+    config = FcConfigReference (config);
813
     if (!config)
814
-    {
815
-	config = FcConfigGetCurrent ();
816
-	if (!config)
817
-	    return 0;
818
-    }
819
-    return FcStrListCreate (config->cacheDirs);
820
+	return NULL;
821
+    ret = FcStrListCreate (config->cacheDirs);
822
+    FcConfigDestroy (config);
823
+
824
+    return ret;
825
 }
826
 
827
 FcBool
828
@@ -686,7 +778,7 @@ FcConfigAddConfigFile (FcConfig	    *con
829
 		       const FcChar8   *f)
830
 {
831
     FcBool	ret;
832
-    FcChar8	*file = FcConfigFilename (f);
833
+    FcChar8	*file = FcConfigGetFilename (config, f);
834
 
835
     if (!file)
836
 	return FcFalse;
837
@@ -699,13 +791,15 @@ FcConfigAddConfigFile (FcConfig	    *con
838
 FcStrList *
839
 FcConfigGetConfigFiles (FcConfig    *config)
840
 {
841
+    FcStrList *ret;
842
+
843
+    config = FcConfigReference (config);
844
     if (!config)
845
-    {
846
-	config = FcConfigGetCurrent ();
847
-	if (!config)
848
-	    return 0;
849
-    }
850
-    return FcStrListCreate (config->configFiles);
851
+	return NULL;
852
+    ret = FcStrListCreate (config->configFiles);
853
+    FcConfigDestroy (config);
854
+
855
+    return ret;
856
 }
857
 
858
 FcChar8 *
859
@@ -784,25 +878,26 @@ FcConfigAddBlank (FcConfig	*config FC_UN
860
 int
861
 FcConfigGetRescanInterval (FcConfig *config)
862
 {
863
+    int ret;
864
+
865
+    config = FcConfigReference (config);
866
     if (!config)
867
-    {
868
-	config = FcConfigGetCurrent ();
869
-	if (!config)
870
-	    return 0;
871
-    }
872
-    return config->rescanInterval;
873
+	return 0;
874
+    ret = config->rescanInterval;
875
+    FcConfigDestroy (config);
876
+
877
+    return ret;
878
 }
879
 
880
 FcBool
881
 FcConfigSetRescanInterval (FcConfig *config, int rescanInterval)
882
 {
883
+    config = FcConfigReference (config);
884
     if (!config)
885
-    {
886
-	config = FcConfigGetCurrent ();
887
-	if (!config)
888
-	    return FcFalse;
889
-    }
890
+	return FcFalse;
891
     config->rescanInterval = rescanInterval;
892
+    FcConfigDestroy (config);
893
+
894
     return FcTrue;
895
 }
896
 
897
@@ -1670,15 +1765,13 @@ FcConfigSubstituteWithPat (FcConfig    *
898
     FcBool	    retval = FcTrue;
899
     FcTest	    **tst = NULL;
900
 
901
-    if (!config)
902
-    {
903
-	config = FcConfigGetCurrent ();
904
-	if (!config)
905
-	    return FcFalse;
906
-    }
907
-
908
     if (kind < FcMatchKindBegin || kind >= FcMatchKindEnd)
909
 	return FcFalse;
910
+
911
+    config = FcConfigReference (config);
912
+    if (!config)
913
+	return FcFalse;
914
+
915
     s = config->subst[kind];
916
     if (kind == FcMatchPattern)
917
     {
918
@@ -1973,6 +2066,7 @@ bail1:
919
 	free (value);
920
     if (tst)
921
 	free (tst);
922
+    FcConfigDestroy (config);
923
 
924
     return retval;
925
 }
926
@@ -2284,10 +2378,16 @@ FcConfigEnableHome (FcBool enable)
927
 }
928
 
929
 FcChar8 *
930
-FcConfigFilename (const FcChar8 *url)
931
+FcConfigGetFilename (FcConfig      *config,
932
+		     const FcChar8 *url)
933
 {
934
     FcChar8    *file, *dir, **path, **p;
935
+    const FcChar8 *sysroot;
936
 
937
+    config = FcConfigReference (config);
938
+    if (!config)
939
+	return NULL;
940
+    sysroot = FcConfigGetSysRoot (config);
941
     if (!url || !*url)
942
     {
943
 	url = (FcChar8 *) getenv ("FONTCONFIG_FILE");
944
@@ -2297,13 +2397,26 @@ FcConfigFilename (const FcChar8 *url)
945
     file = 0;
946
 
947
     if (FcStrIsAbsoluteFilename(url))
948
-	return FcConfigFileExists (0, url);
949
+    {
950
+	file = FcConfigFileExists (sysroot, url);
951
+	goto bail;
952
+    }
953
 
954
     if (*url == '~')
955
     {
956
 	dir = FcConfigHome ();
957
 	if (dir)
958
-	    file = FcConfigFileExists (dir, url + 1);
959
+	{
960
+	    FcChar8 *s;
961
+
962
+	    if (sysroot)
963
+		s = FcStrBuildFilename (sysroot, dir, NULL);
964
+	    else
965
+		s = dir;
966
+	    file = FcConfigFileExists (s, url + 1);
967
+	    if (sysroot)
968
+		FcStrFree (s);
969
+	}
970
 	else
971
 	    file = 0;
972
     }
973
@@ -2311,45 +2424,64 @@ FcConfigFilename (const FcChar8 *url)
974
     {
975
 	path = FcConfigGetPath ();
976
 	if (!path)
977
-	    return NULL;
978
+	{
979
+	    file = NULL;
980
+	    goto bail;
981
+	}
982
 	for (p = path; *p; p++)
983
 	{
984
-	    file = FcConfigFileExists (*p, url);
985
+	    FcChar8 *s;
986
+
987
+	    if (sysroot)
988
+		s = FcStrBuildFilename (sysroot, *p, NULL);
989
+	    else
990
+		s = *p;
991
+	    file = FcConfigFileExists (s, url);
992
+	    if (sysroot)
993
+		FcStrFree (s);
994
 	    if (file)
995
 		break;
996
 	}
997
 	FcConfigFreePath (path);
998
     }
999
+bail:
1000
+    FcConfigDestroy (config);
1001
+
1002
     return file;
1003
 }
1004
 
1005
 FcChar8 *
1006
+FcConfigFilename (const FcChar8 *url)
1007
+{
1008
+    return FcConfigGetFilename (NULL, url);
1009
+}
1010
+
1011
+FcChar8 *
1012
 FcConfigRealFilename (FcConfig		*config,
1013
 		      const FcChar8	*url)
1014
 {
1015
-    const FcChar8 *sysroot = FcConfigGetSysRoot (config);
1016
-    FcChar8 *n = FcConfigFilename (url);
1017
-    FcChar8 *nn = NULL;
1018
+    FcChar8 *n = FcConfigGetFilename (config, url);
1019
 
1020
     if (n)
1021
     {
1022
 	FcChar8 buf[FC_PATH_MAX];
1023
 	ssize_t len;
1024
+	struct stat sb;
1025
 
1026
-	if (sysroot)
1027
-	    nn = FcStrBuildFilename (sysroot, n, NULL);
1028
-	else
1029
-	    nn = FcStrdup (n);
1030
-	FcStrFree (n);
1031
-
1032
-	if ((len = FcReadLink (nn, buf, sizeof (buf) - 1)) != -1)
1033
+	if ((len = FcReadLink (n, buf, sizeof (buf) - 1)) != -1)
1034
 	{
1035
 	    buf[len] = 0;
1036
 
1037
-	    if (!FcStrIsAbsoluteFilename (buf))
1038
+	    /* We try to pick up a config from FONTCONFIG_FILE
1039
+	     * when url is null. don't try to address the real filename
1040
+	     * if it is a named pipe.
1041
+	     */
1042
+	    if (!url && FcStat (n, &sb) == 0 && S_ISFIFO (sb.st_mode))
1043
+		return n;
1044
+	    else if (!FcStrIsAbsoluteFilename (buf))
1045
 	    {
1046
-		FcChar8 *dirname = FcStrDirname (nn);
1047
-		FcStrFree (nn);
1048
+		FcChar8 *dirname = FcStrDirname (n);
1049
+		FcStrFree (n);
1050
 		if (!dirname)
1051
 		    return NULL;
1052
 
1053
@@ -2358,18 +2490,18 @@ FcConfigRealFilename (FcConfig		*config,
1054
 		if (!path)
1055
 		    return NULL;
1056
 
1057
-		nn = FcStrCanonFilename (path);
1058
+		n = FcStrCanonFilename (path);
1059
 		FcStrFree (path);
1060
 	    }
1061
 	    else
1062
 	    {
1063
-		FcStrFree (nn);
1064
-		nn = FcStrdup (buf);
1065
+		FcStrFree (n);
1066
+		n = FcStrdup (buf);
1067
 	    }
1068
 	}
1069
     }
1070
 
1071
-    return nn;
1072
+    return n;
1073
 }
1074
 
1075
 /*
1076
@@ -2384,17 +2516,18 @@ FcConfigAppFontAddFile (FcConfig    *con
1077
     FcStrSet	*subdirs;
1078
     FcStrList	*sublist;
1079
     FcChar8	*subdir;
1080
+    FcBool	ret = FcTrue;
1081
 
1082
+    config = FcConfigReference (config);
1083
     if (!config)
1084
-    {
1085
-	config = FcConfigGetCurrent ();
1086
-	if (!config)
1087
-	    return FcFalse;
1088
-    }
1089
+	return FcFalse;
1090
 
1091
     subdirs = FcStrSetCreateEx (FCSS_GROW_BY_64);
1092
     if (!subdirs)
1093
-	return FcFalse;
1094
+    {
1095
+	ret = FcFalse;
1096
+	goto bail;
1097
+    }
1098
 
1099
     set = FcConfigGetFonts (config, FcSetApplication);
1100
     if (!set)
1101
@@ -2403,7 +2536,8 @@ FcConfigAppFontAddFile (FcConfig    *con
1102
 	if (!set)
1103
 	{
1104
 	    FcStrSetDestroy (subdirs);
1105
-	    return FcFalse;
1106
+	    ret = FcFalse;
1107
+	    goto bail;
1108
 	}
1109
 	FcConfigSetFonts (config, set, FcSetApplication);
1110
     }
1111
@@ -2411,7 +2545,8 @@ FcConfigAppFontAddFile (FcConfig    *con
1112
     if (!FcFileScanConfig (set, subdirs, file, config))
1113
     {
1114
 	FcStrSetDestroy (subdirs);
1115
-	return FcFalse;
1116
+	ret = FcFalse;
1117
+	goto bail;
1118
     }
1119
     if ((sublist = FcStrListCreate (subdirs)))
1120
     {
1121
@@ -2422,7 +2557,10 @@ FcConfigAppFontAddFile (FcConfig    *con
1122
 	FcStrListDone (sublist);
1123
     }
1124
     FcStrSetDestroy (subdirs);
1125
-    return FcTrue;
1126
+bail:
1127
+    FcConfigDestroy (config);
1128
+
1129
+    return ret;
1130
 }
1131
 
1132
 FcBool
1133
@@ -2431,17 +2569,18 @@ FcConfigAppFontAddDir (FcConfig	    *con
1134
 {
1135
     FcFontSet	*set;
1136
     FcStrSet	*dirs;
1137
+    FcBool	ret = FcTrue;
1138
 
1139
+    config = FcConfigReference (config);
1140
     if (!config)
1141
-    {
1142
-	config = FcConfigGetCurrent ();
1143
-	if (!config)
1144
-	    return FcFalse;
1145
-    }
1146
+	return FcFalse;
1147
 
1148
     dirs = FcStrSetCreateEx (FCSS_GROW_BY_64);
1149
     if (!dirs)
1150
-	return FcFalse;
1151
+    {
1152
+	ret = FcFalse;
1153
+	goto bail;
1154
+    }
1155
 
1156
     set = FcConfigGetFonts (config, FcSetApplication);
1157
     if (!set)
1158
@@ -2450,7 +2589,8 @@ FcConfigAppFontAddDir (FcConfig	    *con
1159
 	if (!set)
1160
 	{
1161
 	    FcStrSetDestroy (dirs);
1162
-	    return FcFalse;
1163
+	    ret = FcFalse;
1164
+	    goto bail;
1165
 	}
1166
 	FcConfigSetFonts (config, set, FcSetApplication);
1167
     }
1168
@@ -2460,23 +2600,26 @@ FcConfigAppFontAddDir (FcConfig	    *con
1169
     if (!FcConfigAddDirList (config, FcSetApplication, dirs))
1170
     {
1171
 	FcStrSetDestroy (dirs);
1172
-	return FcFalse;
1173
+	ret = FcFalse;
1174
+	goto bail;
1175
     }
1176
     FcStrSetDestroy (dirs);
1177
-    return FcTrue;
1178
+bail:
1179
+    FcConfigDestroy (config);
1180
+
1181
+    return ret;
1182
 }
1183
 
1184
 void
1185
 FcConfigAppFontClear (FcConfig	    *config)
1186
 {
1187
+    config = FcConfigReference (config);
1188
     if (!config)
1189
-    {
1190
-	config = FcConfigGetCurrent ();
1191
-	if (!config)
1192
-	    return;
1193
-    }
1194
+	return;
1195
 
1196
     FcConfigSetFonts (config, 0, FcSetApplication);
1197
+
1198
+    FcConfigDestroy (config);
1199
 }
1200
 
1201
 /*
1202
@@ -2571,7 +2714,9 @@ FcConfigSetSysRoot (FcConfig      *confi
1203
 {
1204
     FcChar8 *s = NULL;
1205
     FcBool init = FcFalse;
1206
+    int nretry = 3;
1207
 
1208
+retry:
1209
     if (!config)
1210
     {
1211
 	/* We can't use FcConfigGetCurrent() here to ensure
1212
@@ -2603,6 +2748,17 @@ FcConfigSetSysRoot (FcConfig      *confi
1213
     if (init)
1214
     {
1215
 	config = FcInitLoadOwnConfigAndFonts (config);
1216
+	if (!config)
1217
+	{
1218
+	    /* Something failed. this is usually unlikely. so retrying */
1219
+	    init = FcFalse;
1220
+	    if (--nretry == 0)
1221
+	    {
1222
+		fprintf (stderr, "Fontconfig warning: Unable to initialize config and retry limit exceeded. sysroot functionality may not work as expected.\n");
1223
+		return;
1224
+	    }
1225
+	    goto retry;
1226
+	}
1227
 	FcConfigSetCurrent (config);
1228
 	/* FcConfigSetCurrent() increases the refcount.
1229
 	 * decrease it here to avoid the memory leak.
1230
--- src/fcdir.c.orig	2019-05-08 08:22:25 UTC
1231
+++ src/fcdir.c
1232
@@ -167,7 +167,16 @@ FcFileScan (FcFontSet	    *set,
1233
 	    const FcChar8   *file,
1234
 	    FcBool	    force FC_UNUSED)
1235
 {
1236
-    return FcFileScanConfig (set, dirs, file, FcConfigGetCurrent ());
1237
+    FcConfig *config;
1238
+    FcBool ret;
1239
+
1240
+    config = FcConfigReference (NULL);
1241
+    if (!config)
1242
+	return FcFalse;
1243
+    ret = FcFileScanConfig (set, dirs, file, config);
1244
+    FcConfigDestroy (config);
1245
+
1246
+    return ret;
1247
 }
1248
 
1249
 /*
1250
@@ -271,10 +280,19 @@ FcDirScan (FcFontSet	    *set,
1251
 	   const FcChar8    *dir,
1252
 	   FcBool	    force FC_UNUSED)
1253
 {
1254
+    FcConfig *config;
1255
+    FcBool ret;
1256
+
1257
     if (cache || !force)
1258
 	return FcFalse;
1259
 
1260
-    return FcDirScanConfig (set, dirs, dir, force, FcConfigGetCurrent ());
1261
+    config = FcConfigReference (NULL);
1262
+    if (!config)
1263
+	return FcFalse;
1264
+    ret = FcDirScanConfig (set, dirs, dir, force, config);
1265
+    FcConfigDestroy (config);
1266
+
1267
+    return ret;
1268
 }
1269
 
1270
 /*
1271
@@ -353,12 +371,16 @@ FcDirCacheRescan (const FcChar8 *dir, Fc
1272
     FcCache *new = NULL;
1273
     struct stat dir_stat;
1274
     FcStrSet *dirs;
1275
-    const FcChar8 *sysroot = FcConfigGetSysRoot (config);
1276
+    const FcChar8 *sysroot;
1277
     FcChar8 *d = NULL;
1278
 #ifndef _WIN32
1279
     int fd = -1;
1280
 #endif
1281
 
1282
+    config = FcConfigReference (config);
1283
+    if (!config)
1284
+	return NULL;
1285
+    sysroot = FcConfigGetSysRoot (config);
1286
     cache = FcDirCacheLoad (dir, config, NULL);
1287
     if (!cache)
1288
 	goto bail;
1289
@@ -401,6 +423,7 @@ bail1:
1290
 bail:
1291
     if (d)
1292
 	FcStrFree (d);
1293
+    FcConfigDestroy (config);
1294
 
1295
     return new;
1296
 }
1297
@@ -413,6 +436,7 @@ FcDirCacheRead (const FcChar8 *dir, FcBo
1298
 {
1299
     FcCache		*cache = NULL;
1300
 
1301
+    config = FcConfigReference (config);
1302
     /* Try to use existing cache file */
1303
     if (!force)
1304
 	cache = FcDirCacheLoad (dir, config, NULL);
1305
@@ -420,6 +444,7 @@ FcDirCacheRead (const FcChar8 *dir, FcBo
1306
     /* Not using existing cache file, construct new cache */
1307
     if (!cache)
1308
 	cache = FcDirCacheScan (dir, config);
1309
+    FcConfigDestroy (config);
1310
 
1311
     return cache;
1312
 }
1313
--- src/fcfreetype.c.orig	2019-08-09 10:47:03 UTC
1314
+++ src/fcfreetype.c
1315
@@ -1294,7 +1294,7 @@ FcFreeTypeQueryFaceInternal (const FT_Fa
1316
 	if (!FcPatternObjectAddBool (pat, FC_OUTLINE_OBJECT, has_outline))
1317
 	    goto bail1;
1318
 
1319
-	has_color = FT_HAS_COLOR (face);
1320
+	has_color = !!FT_HAS_COLOR (face);
1321
 	if (!FcPatternObjectAddBool (pat, FC_COLOR_OBJECT, has_color))
1322
 	    goto bail1;
1323
 
1324
@@ -1495,7 +1495,8 @@ FcFreeTypeQueryFaceInternal (const FT_Fa
1325
 		 * and treat the instance's nameid as FONT_SUBFAMILY.
1326
 		 * Postscript name is automatically handled by FreeType. */
1327
 		if (nameid == TT_NAME_ID_WWS_SUBFAMILY ||
1328
-		    nameid == TT_NAME_ID_PREFERRED_SUBFAMILY)
1329
+		    nameid == TT_NAME_ID_PREFERRED_SUBFAMILY ||
1330
+		    nameid == TT_NAME_ID_FULL_NAME)
1331
 		    continue;
1332
 
1333
 		if (nameid == TT_NAME_ID_FONT_SUBFAMILY)
1334
@@ -1528,6 +1529,8 @@ FcFreeTypeQueryFaceInternal (const FT_Fa
1335
 		    break;
1336
 		case TT_NAME_ID_MAC_FULL_NAME:
1337
 		case TT_NAME_ID_FULL_NAME:
1338
+		    if (variable)
1339
+			break;
1340
 		    if (FcDebug () & FC_DBG_SCANV)
1341
 			printf ("found full   (n %2d p %d e %d l 0x%04x)",
1342
 				sname.name_id, sname.platform_id,
1343
@@ -1624,7 +1627,10 @@ FcFreeTypeQueryFaceInternal (const FT_Fa
1344
 	}
1345
     }
1346
     if (!nm_share)
1347
+    {
1348
 	free (name_mapping);
1349
+	name_mapping = NULL;
1350
+    }
1351
 
1352
     if (!nfamily && face->family_name &&
1353
 	FcStrCmpIgnoreBlanksAndCase ((FcChar8 *) face->family_name, (FcChar8 *) "") != 0)
1354
@@ -1679,6 +1682,61 @@ FcFreeTypeQueryFaceInternal (const FT_Fa
1355
 	++nfamily;
1356
     }
1357
 
1358
+    /* Add the fullname into the cache */
1359
+    if (!variable && !nfullname)
1360
+    {
1361
+	FcChar8 *family, *style, *lang;
1362
+	int n = 0;
1363
+	size_t len, i;
1364
+	FcStrBuf sbuf;
1365
+
1366
+	while (FcPatternObjectGetString (pat, FC_FAMILYLANG_OBJECT, n, &lang) == FcResultMatch)
1367
+	{
1368
+	    if (FcStrCmp (lang, (const FcChar8 *) "en") == 0)
1369
+		break;
1370
+	    n++;
1371
+	    lang = NULL;
1372
+	}
1373
+	if (!lang)
1374
+	    n = 0;
1375
+	if (FcPatternObjectGetString (pat, FC_FAMILY_OBJECT, n, &family) != FcResultMatch)
1376
+	    goto bail1;
1377
+	len = strlen ((const char *) family);
1378
+	for (i = len; i > 0; i--)
1379
+	{
1380
+	    if (!isspace (family[i]))
1381
+		break;
1382
+	}
1383
+	family[i] = 0;
1384
+	while (FcPatternObjectGetString (pat, FC_STYLELANG_OBJECT, n, &lang) == FcResultMatch)
1385
+	{
1386
+	    if (FcStrCmp (lang, (const FcChar8 *) "en") == 0)
1387
+		break;
1388
+	    n++;
1389
+	    lang = NULL;
1390
+	}
1391
+	if (!lang)
1392
+	    n = 0;
1393
+	if (FcPatternObjectGetString (pat, FC_STYLE_OBJECT, n, &style) != FcResultMatch)
1394
+	    goto bail1;
1395
+	len = strlen ((const char *) style);
1396
+	for (i = 0; style[i] != 0 && isspace (style[i]); i++)
1397
+	    break;
1398
+	memcpy (style, &style[i], len - i);
1399
+	FcStrBufInit (&sbuf, NULL, 0);
1400
+	FcStrBufString (&sbuf, family);
1401
+	FcStrBufChar (&sbuf, ' ');
1402
+	FcStrBufString (&sbuf, style);
1403
+	if (!FcPatternObjectAddString (pat, FC_FULLNAME_OBJECT, FcStrBufDoneStatic (&sbuf)))
1404
+	{
1405
+	    FcStrBufDestroy (&sbuf);
1406
+	    goto bail1;
1407
+	}
1408
+	FcStrBufDestroy (&sbuf);
1409
+	if (!FcPatternObjectAddString (pat, FC_FULLNAMELANG_OBJECT, (const FcChar8 *) "en"))
1410
+	    goto bail1;
1411
+	++nfullname;
1412
+    }
1413
     /* Add the PostScript name into the cache */
1414
     if (!variable)
1415
     {
1416
@@ -2142,6 +2200,17 @@ bail2:
1417
     FcCharSetDestroy (cs);
1418
 bail1:
1419
     FcPatternDestroy (pat);
1420
+    if (master)
1421
+    {
1422
+#ifdef HAVE_FT_DONE_MM_VAR
1423
+	if (face->glyph)
1424
+	    FT_Done_MM_Var (face->glyph->library, master);
1425
+#else
1426
+	free (master);
1427
+#endif
1428
+    }
1429
+    if (!nm_share && name_mapping)
1430
+	free (name_mapping);
1431
     if (foundry_)
1432
 	free (foundry_);
1433
 bail0:
1434
@@ -2302,6 +2371,8 @@ bail:
1435
     if (face)
1436
 	FT_Done_Face (face);
1437
     FT_Done_FreeType (ftLibrary);
1438
+    if (nm)
1439
+	free (nm);
1440
 
1441
     return ret;
1442
 }
1443
--- src/fcinit.c.orig	2018-06-05 10:36:38 UTC
1444
+++ src/fcinit.c
1445
@@ -199,10 +199,10 @@ void
1446
 FcFini (void)
1447
 {
1448
     FcConfigFini ();
1449
-    FcCacheFini ();
1450
+    FcConfigPathFini ();
1451
     FcDefaultFini ();
1452
     FcObjectFini ();
1453
-    FcConfigPathFini ();
1454
+    FcCacheFini ();
1455
 }
1456
 
1457
 /*
1458
@@ -229,7 +229,8 @@ FcInitReinitialize (void)
1459
 FcBool
1460
 FcInitBringUptoDate (void)
1461
 {
1462
-    FcConfig	*config = FcConfigGetCurrent ();
1463
+    FcConfig	*config = FcConfigReference (NULL);
1464
+    FcBool	ret = FcTrue;
1465
     time_t	now;
1466
 
1467
     if (!config)
1468
@@ -238,19 +239,23 @@ FcInitBringUptoDate (void)
1469
      * rescanInterval == 0 disables automatic up to date
1470
      */
1471
     if (config->rescanInterval == 0)
1472
-	return FcTrue;
1473
+	goto bail;
1474
     /*
1475
      * Check no more often than rescanInterval seconds
1476
      */
1477
     now = time (0);
1478
     if (config->rescanTime + config->rescanInterval - now > 0)
1479
-	return FcTrue;
1480
+	goto bail;
1481
     /*
1482
      * If up to date, don't reload configuration
1483
      */
1484
     if (FcConfigUptoDate (0))
1485
-	return FcTrue;
1486
-    return FcInitReinitialize ();
1487
+	goto bail;
1488
+    ret = FcInitReinitialize ();
1489
+bail:
1490
+    FcConfigDestroy (config);
1491
+
1492
+    return ret;
1493
 }
1494
 
1495
 #define __fcinit__
1496
--- src/fclist.c.orig	2018-07-19 03:15:01 UTC
1497
+++ src/fclist.c
1498
@@ -491,11 +491,10 @@ FcFontSetList (FcConfig	    *config,
1499
     {
1500
 	if (!FcInitBringUptoDate ())
1501
 	    goto bail0;
1502
-
1503
-	config = FcConfigGetCurrent ();
1504
-	if (!config)
1505
-	    goto bail0;
1506
     }
1507
+    config = FcConfigReference (config);
1508
+    if (!config)
1509
+	goto bail0;
1510
     FcListHashTableInit (&table);
1511
 
1512
     if (!os)
1513
@@ -558,7 +557,7 @@ FcFontSetList (FcConfig	    *config,
1514
      */
1515
     ret = FcFontSetCreate ();
1516
     if (!ret)
1517
-	goto bail0;
1518
+	goto bail1;
1519
     for (i = 0; i < FC_LIST_HASH_SIZE; i++)
1520
 	while ((bucket = table.buckets[i]))
1521
 	{
1522
@@ -570,6 +569,7 @@ FcFontSetList (FcConfig	    *config,
1523
 
1524
     if (destroy_os)
1525
         FcObjectSetDestroy (os);
1526
+    FcConfigDestroy (config);
1527
 
1528
     return ret;
1529
 
1530
@@ -577,6 +577,7 @@ bail2:
1531
     FcFontSetDestroy (ret);
1532
 bail1:
1533
     FcListHashTableCleanup (&table);
1534
+    FcConfigDestroy (config);
1535
 bail0:
1536
     if (destroy_os)
1537
 	FcObjectSetDestroy (os);
1538
@@ -588,24 +589,26 @@ FcFontList (FcConfig	*config,
1539
 	    FcPattern	*p,
1540
 	    FcObjectSet *os)
1541
 {
1542
-    FcFontSet	*sets[2];
1543
+    FcFontSet	*sets[2], *ret;
1544
     int		nsets;
1545
 
1546
     if (!config)
1547
     {
1548
 	if (!FcInitBringUptoDate ())
1549
 	    return 0;
1550
-
1551
-	config = FcConfigGetCurrent ();
1552
-	if (!config)
1553
-	    return 0;
1554
     }
1555
+    config = FcConfigReference (config);
1556
+    if (!config)
1557
+	return NULL;
1558
     nsets = 0;
1559
     if (config->fonts[FcSetSystem])
1560
 	sets[nsets++] = config->fonts[FcSetSystem];
1561
     if (config->fonts[FcSetApplication])
1562
 	sets[nsets++] = config->fonts[FcSetApplication];
1563
-    return FcFontSetList (config, sets, nsets, p, os);
1564
+    ret = FcFontSetList (config, sets, nsets, p, os);
1565
+    FcConfigDestroy (config);
1566
+
1567
+    return ret;
1568
 }
1569
 #define __fclist__
1570
 #include "fcaliastail.h"
1571
--- src/fcmatch.c.orig	2018-07-19 08:28:09 UTC
1572
+++ src/fcmatch.c
1573
@@ -342,6 +342,7 @@ typedef enum _FcMatcherPriority {
1574
     PRI1(SLANT),
1575
     PRI1(WEIGHT),
1576
     PRI1(WIDTH),
1577
+    PRI1(FONT_HAS_HINT),
1578
     PRI1(DECORATIVE),
1579
     PRI1(ANTIALIAS),
1580
     PRI1(RASTERIZER),
1581
@@ -844,7 +845,7 @@ FcFontSetMatch (FcConfig    *config,
1582
 		FcPattern   *p,
1583
 		FcResult    *result)
1584
 {
1585
-    FcPattern	    *best;
1586
+    FcPattern	    *best, *ret = NULL;
1587
 
1588
     assert (sets != NULL);
1589
     assert (p != NULL);
1590
@@ -852,17 +853,16 @@ FcFontSetMatch (FcConfig    *config,
1591
 
1592
     *result = FcResultNoMatch;
1593
 
1594
+    config = FcConfigReference (config);
1595
     if (!config)
1596
-    {
1597
-	config = FcConfigGetCurrent ();
1598
-	if (!config)
1599
-	    return 0;
1600
-    }
1601
+	    return NULL;
1602
     best = FcFontSetMatchInternal (sets, nsets, p, result);
1603
     if (best)
1604
-	return FcFontRenderPrepare (config, p, best);
1605
-    else
1606
-	return NULL;
1607
+	ret = FcFontRenderPrepare (config, p, best);
1608
+
1609
+    FcConfigDestroy (config);
1610
+
1611
+    return ret;
1612
 }
1613
 
1614
 FcPattern *
1615
@@ -872,19 +872,16 @@ FcFontMatch (FcConfig	*config,
1616
 {
1617
     FcFontSet	*sets[2];
1618
     int		nsets;
1619
-    FcPattern   *best;
1620
+    FcPattern   *best, *ret = NULL;
1621
 
1622
     assert (p != NULL);
1623
     assert (result != NULL);
1624
 
1625
     *result = FcResultNoMatch;
1626
 
1627
+    config = FcConfigReference (config);
1628
     if (!config)
1629
-    {
1630
-	config = FcConfigGetCurrent ();
1631
-	if (!config)
1632
-	    return 0;
1633
-    }
1634
+	return NULL;
1635
     nsets = 0;
1636
     if (config->fonts[FcSetSystem])
1637
 	sets[nsets++] = config->fonts[FcSetSystem];
1638
@@ -893,9 +890,11 @@ FcFontMatch (FcConfig	*config,
1639
 
1640
     best = FcFontSetMatchInternal (sets, nsets, p, result);
1641
     if (best)
1642
-	return FcFontRenderPrepare (config, p, best);
1643
-    else
1644
-	return NULL;
1645
+	ret = FcFontRenderPrepare (config, p, best);
1646
+
1647
+    FcConfigDestroy (config);
1648
+
1649
+    return ret;
1650
 }
1651
 
1652
 typedef struct _FcSortNode {
1653
@@ -1182,7 +1181,7 @@ FcFontSort (FcConfig	*config,
1654
 	    FcCharSet	**csp,
1655
 	    FcResult	*result)
1656
 {
1657
-    FcFontSet	*sets[2];
1658
+    FcFontSet	*sets[2], *ret;
1659
     int		nsets;
1660
 
1661
     assert (p != NULL);
1662
@@ -1190,18 +1189,18 @@ FcFontSort (FcConfig	*config,
1663
 
1664
     *result = FcResultNoMatch;
1665
 
1666
+    config = FcConfigReference (config);
1667
     if (!config)
1668
-    {
1669
-	config = FcConfigGetCurrent ();
1670
-	if (!config)
1671
-	    return 0;
1672
-    }
1673
+	return NULL;
1674
     nsets = 0;
1675
     if (config->fonts[FcSetSystem])
1676
 	sets[nsets++] = config->fonts[FcSetSystem];
1677
     if (config->fonts[FcSetApplication])
1678
 	sets[nsets++] = config->fonts[FcSetApplication];
1679
-    return FcFontSetSort (config, sets, nsets, p, trim, csp, result);
1680
+    ret = FcFontSetSort (config, sets, nsets, p, trim, csp, result);
1681
+    FcConfigDestroy (config);
1682
+
1683
+    return ret;
1684
 }
1685
 #define __fcmatch__
1686
 #include "fcaliastail.h"
1687
--- src/fcobjs.h.orig	2019-07-30 11:03:27 UTC
1688
+++ src/fcobjs.h
1689
@@ -72,5 +72,5 @@ FC_OBJECT (COLOR,		FcTypeBool,	FcCompare
1690
 FC_OBJECT (SYMBOL,		FcTypeBool,	FcCompareBool)
1691
 FC_OBJECT (FONT_VARIATIONS,	FcTypeString,	NULL)
1692
 FC_OBJECT (VARIABLE,		FcTypeBool,	FcCompareBool)
1693
-FC_OBJECT (FONT_HAS_HINT,	FcTypeBool,	NULL)
1694
+FC_OBJECT (FONT_HAS_HINT,	FcTypeBool,	FcCompareBool)
1695
 /* ^-------------- Add new objects here. */
1696
--- src/fcxml.c.orig	2019-07-29 05:17:34 UTC
1697
+++ src/fcxml.c
1698
@@ -2301,6 +2301,11 @@ FcParseCacheDir (FcConfigParse *parse)
1699
 	data = prefix;
1700
 	goto bail;
1701
     }
1702
+    if (data[0] == 0)
1703
+    {
1704
+	FcConfigMessage (parse, FcSevereWarning, "empty cache directory name ignored");
1705
+	return;
1706
+    }
1707
     if (prefix)
1708
     {
1709
 	size_t plen = strlen ((const char *)prefix);
1710
@@ -2536,7 +2541,7 @@ FcParseInclude (FcConfigParse *parse)
1711
         FcChar8 *filename;
1712
 	static FcBool warn_conf = FcFalse, warn_confd = FcFalse;
1713
 
1714
-        filename = FcConfigFilename(s);
1715
+        filename = FcConfigGetFilename(parse->config, s);
1716
 	if (deprecated == FcTrue &&
1717
 	    filename != NULL &&
1718
 	    userdir != NULL &&
1719
@@ -3526,8 +3531,10 @@ _FcConfigParse (FcConfig	*config,
1720
     int		    len;
1721
     FcStrBuf	    sbuf;
1722
     char            buf[BUFSIZ];
1723
-    FcBool	    ret = FcFalse;
1724
+    FcBool	    ret = FcFalse, complain_again = complain;
1725
+    FcStrBuf	    reason;
1726
 
1727
+    FcStrBufInit (&reason, NULL, 0);
1728
 #ifdef _WIN32
1729
     if (!pGetSystemWindowsDirectory)
1730
     {
1731
@@ -3544,12 +3551,20 @@ _FcConfigParse (FcConfig	*config,
1732
     }
1733
 #endif
1734
 
1735
-    filename = FcConfigFilename (name);
1736
+    filename = FcConfigGetFilename (config, name);
1737
     if (!filename)
1738
+    {
1739
+	FcStrBufString (&reason, (FcChar8 *)"No such file: ");
1740
+	FcStrBufString (&reason, name ? name : (FcChar8 *)"(null)");
1741
 	goto bail0;
1742
+    }
1743
     realfilename = FcConfigRealFilename (config, name);
1744
     if (!realfilename)
1745
+    {
1746
+	FcStrBufString (&reason, (FcChar8 *)"No such realfile: ");
1747
+	FcStrBufString (&reason, name ? name : (FcChar8 *)"(null)");
1748
 	goto bail0;
1749
+    }
1750
     if (FcStrSetMember (config->availConfigFiles, realfilename))
1751
     {
1752
         FcStrFree (filename);
1753
@@ -3577,7 +3592,11 @@ _FcConfigParse (FcConfig	*config,
1754
 
1755
     fd = FcOpen ((char *) realfilename, O_RDONLY);
1756
     if (fd == -1)
1757
+    {
1758
+	FcStrBufString (&reason, (FcChar8 *)"Unable to open ");
1759
+	FcStrBufString (&reason, realfilename);
1760
 	goto bail1;
1761
+    }
1762
 
1763
     do {
1764
 	len = read (fd, buf, BUFSIZ);
1765
@@ -3605,7 +3624,7 @@ _FcConfigParse (FcConfig	*config,
1766
     close (fd);
1767
 
1768
     ret = FcConfigParseAndLoadFromMemoryInternal (config, filename, FcStrBufDoneStatic (&sbuf), complain, load);
1769
-    complain = FcFalse; /* no need to reclaim here */
1770
+    complain_again = FcFalse; /* no need to reclaim here */
1771
 bail1:
1772
     FcStrBufDestroy (&sbuf);
1773
 bail0:
1774
@@ -3613,14 +3632,18 @@ bail0:
1775
 	FcStrFree (filename);
1776
     if (realfilename)
1777
 	FcStrFree (realfilename);
1778
-    if (!ret && complain)
1779
+    if (!complain)
1780
+	return FcTrue;
1781
+    if (!ret && complain_again)
1782
     {
1783
 	if (name)
1784
-	    FcConfigMessage (0, FcSevereError, "Cannot %s config file \"%s\"", load ? "load" : "scan", name);
1785
+	    FcConfigMessage (0, FcSevereError, "Cannot %s config file \"%s\": %s", load ? "load" : "scan", name, FcStrBufDoneStatic (&reason));
1786
 	else
1787
-	    FcConfigMessage (0, FcSevereError, "Cannot %s default config file", load ? "load" : "scan");
1788
+	    FcConfigMessage (0, FcSevereError, "Cannot %s default config file: %s", load ? "load" : "scan", FcStrBufDoneStatic (&reason));
1789
+	FcStrBufDestroy (&reason);
1790
 	return FcFalse;
1791
     }
1792
+    FcStrBufDestroy (&reason);
1793
     return ret;
1794
 }
1795
 
(-)a/x11-fonts/fontconfig/files/patch-Makefile.in (-31 lines)
Removed Link Here
1
--- Makefile.in.orig	2016-08-05 05:49:13 UTC
2
+++ Makefile.in
3
@@ -1027,28 +1027,6 @@ fonts.conf: fonts.conf.in Makefile
4
 	mv $@.tmp $@
5
 
6
 install-data-local: fonts.conf
7
-	$(mkinstalldirs) $(DESTDIR)$(baseconfigdir) $(DESTDIR)$(fc_cachedir)
8
-	if [ -f $(DESTDIR)$(baseconfigdir)/fonts.conf ]; then \
9
-	  echo "backing up existing $(DESTDIR)$(baseconfigdir)/fonts.conf"; \
10
-	  mv $(DESTDIR)$(baseconfigdir)/fonts.conf $(DESTDIR)$(baseconfigdir)/fonts.conf.bak; \
11
-	fi
12
-	if [ -f $(srcdir)/fonts.conf ]; then \
13
-	  echo " $(INSTALL_DATA) $(srcdir)/fonts.conf $(DESTDIR)$(baseconfigdir)/fonts.conf"; \
14
-	  $(INSTALL_DATA) $(srcdir)/fonts.conf $(DESTDIR)$(baseconfigdir)/fonts.conf; \
15
-	else if [ -f fonts.conf ]; then \
16
-	  echo " $(INSTALL_DATA) fonts.conf $(DESTDIR)$(baseconfigdir)/fonts.conf"; \
17
-	  $(INSTALL_DATA) fonts.conf $(DESTDIR)$(baseconfigdir)/fonts.conf; \
18
-	fi; fi
19
-	@(if $(RUN_FC_CACHE_TEST); then \
20
-	    echo "fc-cache$(EXEEXT) -s -f -v"; \
21
-	    fc-cache/fc-cache$(EXEEXT) -s -f -v; \
22
-	else \
23
-	    echo "***"; \
24
-	    echo "*** Warning: fonts.cache not built"; \
25
-	    echo "***"; \
26
-	    echo "*** Generate this file manually on host system using fc-cache"; \
27
-	    echo "***"; \
28
-	fi)
29
 
30
 uninstall-local:
31
 	if [ -f $(srcdir)/fonts.conf ]; then \
(-)b/x11-fonts/fontconfig/files/patch-conf.d_60-latin.conf (+62 lines)
Added Link Here
1
--- conf.d/60-latin.conf.orig	2020-11-28 01:56:42 UTC
2
+++ conf.d/60-latin.conf
3
@@ -5,44 +5,47 @@
4
 	<alias>
5
 		<family>serif</family>
6
 		<prefer>
7
+			<family>Liberation Serif</family>
8
 			<family>DejaVu Serif</family>
9
 			<family>Times New Roman</family>
10
-			<family>Thorndale AMT</family>
11
 			<family>Luxi Serif</family>
12
 			<family>Nimbus Roman No9 L</family>
13
 			<family>Nimbus Roman</family>
14
 			<family>Times</family>
15
+			<family>Thorndale AMT</family>
16
 		</prefer>
17
 	</alias>
18
 	<alias>
19
 		<family>sans-serif</family>
20
 		<prefer>
21
+			<family>Liberation Sans</family>
22
 			<family>DejaVu Sans</family>
23
-			<family>Verdana</family>
24
 			<family>Arial</family>
25
-			<family>Albany AMT</family>
26
 			<family>Luxi Sans</family>
27
 			<family>Nimbus Sans L</family>
28
 			<family>Nimbus Sans</family>
29
 			<family>Helvetica</family>
30
 			<family>Lucida Sans Unicode</family>
31
 			<family>BPG Glaho International</family> <!-- lat,cyr,arab,geor -->
32
+			<family>Verdana</family>
33
 			<family>Tahoma</family> <!-- lat,cyr,greek,heb,arab,thai -->
34
+			<family>Albany AMT</family>
35
 		</prefer>
36
 	</alias>
37
 	<alias>
38
 		<family>monospace</family>
39
 		<prefer>
40
+			<family>Liberation Mono</family>
41
 			<family>DejaVu Sans Mono</family>
42
 			<family>Inconsolata</family>
43
 			<family>Andale Mono</family>
44
 			<family>Courier New</family>
45
-			<family>Cumberland AMT</family>
46
 			<family>Luxi Mono</family>
47
 			<family>Nimbus Mono L</family>
48
 			<family>Nimbus Mono</family>
49
 			<family>Nimbus Mono PS</family>
50
 			<family>Courier</family>
51
+			<family>Cumberland AMT</family>
52
 		</prefer>
53
 	</alias>
54
 <!--
55
@@ -63,6 +66,7 @@
56
 	<alias>
57
 		<family>cursive</family>
58
 		<prefer>
59
+			<family>Comic Neue</family>
60
 			<family>ITC Zapf Chancery Std</family>
61
 			<family>Zapfino</family>
62
 			<family>Comic Sans MS</family>
(-)b/x11-fonts/fontconfig/files/patch-conf.d_meson.build (+33 lines)
Added Link Here
1
--- conf.d/meson.build.orig	2020-11-28 01:56:42 UTC
2
+++ conf.d/meson.build
3
@@ -37,7 +37,7 @@ conf_files = [
4
   '90-synthetic.conf',
5
 ]
6
 
7
-preferred_hinting = 'slight'
8
+preferred_hinting = '%%FCPREFERREDHINTING%%'
9
 
10
 conf_links = [
11
   '10-hinting-@0@.conf'.format(preferred_hinting),
12
@@ -59,10 +59,10 @@ conf_links = [
13
   '90-synthetic.conf',
14
 ]
15
 
16
-install_data(conf_files, install_dir: join_paths(get_option('datadir'), 'fontconfig/conf.avail'))
17
+install_data(conf_files, install_dir: join_paths(get_option('sysconfdir'), 'fonts/conf.avail'))
18
 
19
 meson.add_install_script('link_confs.py',
20
-  join_paths(get_option('prefix'), get_option('datadir'), 'fontconfig/conf.avail'),
21
+  join_paths(get_option('prefix'), get_option('sysconfdir'), 'fonts/conf.avail'),
22
   join_paths(get_option('sysconfdir'), 'fonts', 'conf.d'),
23
   conf_links,
24
 )
25
@@ -79,7 +79,7 @@ endforeach
26
 custom_target('35-lang-normalize.conf',
27
   output: '35-lang-normalize.conf',
28
   command: [find_program('write-35-lang-normalize-conf.py'), ','.join(orths), '@OUTPUT@'],
29
-  install_dir: join_paths(get_option('datadir'), 'fontconfig/conf.avail'),
30
+  install_dir: join_paths(get_option('sysconfdir'), 'fonts/conf.avail'),
31
   install: true)
32
 
33
 # README
(-)a/x11-fonts/fontconfig/files/patch-configure (-10 lines)
Removed Link Here
1
--- configure.orig	2016-08-05 05:49:14 UTC
2
+++ configure
3
@@ -654,6 +654,7 @@ ax_pthread_config
4
 XMLDIR
5
 CONFIGDIR
6
 BASECONFIGDIR
7
+baseconfigdir
8
 TEMPLATEDIR
9
 FC_FONTDATE
10
 FC_CACHEDIR
(-)b/x11-fonts/fontconfig/files/patch-meson.build (+36 lines)
Added Link Here
1
--- meson.build.orig	2020-11-28 02:38:31 UTC
2
+++ meson.build
3
@@ -212,19 +212,19 @@ else
4
     conf.set_quoted('FC_DEFAULT_FONTS', '<dir>/System/Library/Fonts</dir> <dir>/Library/Fonts</dir> <dir>~/Library/Fonts</dir> <dir>/System/Library/Assets/com_apple_MobileAsset_Font3</dir> <dir>/System/Library/Assets/com_apple_MobileAsset_Font4</dir>')
5
     fonts_conf.set('FC_DEFAULT_FONTS', '<dir>/System/Library/Fonts</dir> <dir>/Library/Fonts</dir> <dir>~/Library/Fonts</dir> <dir>/System/Library/Assets/com_apple_MobileAsset_Font3</dir> <dir>/System/Library/Assets/com_apple_MobileAsset_Font4</dir>')
6
   else
7
-    conf.set_quoted('FC_DEFAULT_FONTS', '<dir>/usr/share/fonts</dir>')
8
-    fonts_conf.set('FC_DEFAULT_FONTS', '<dir>/usr/share/fonts</dir>')
9
+    conf.set_quoted('FC_DEFAULT_FONTS', '<dir>%%FCDEFAULTFONTS%%</dir> <dir>%%FCADDFONTS%%</dir>')
10
+    fonts_conf.set('FC_DEFAULT_FONTS', '<dir>%%FCDEFAULTFONTS%%</dir> <dir>%%FCADDFONTS%%</dir>')
11
   endif
12
-  fc_cachedir = join_paths(prefix, get_option('localstatedir'), 'cache', meson.project_name())
13
+  fc_cachedir = '/var/db/fontconfig'
14
   thread_dep = dependency('threads')
15
   conf.set('HAVE_PTHREAD', 1)
16
   deps += [thread_dep]
17
 endif
18
 
19
-fc_templatedir = join_paths(prefix, get_option('datadir'), 'fontconfig/conf.avail')
20
+fc_templatedir = join_paths(prefix, get_option('sysconfdir'), 'fonts/conf.avail')
21
 fc_baseconfigdir = join_paths(prefix, get_option('sysconfdir'), 'fonts')
22
 fc_configdir = join_paths(fc_baseconfigdir, 'conf.d')
23
-fc_xmldir = join_paths(prefix, get_option('datadir'), 'xml/fontconfig')
24
+fc_xmldir = join_paths(prefix, get_option('sysconfdir'), 'fonts')
25
 
26
 
27
 conf.set_quoted('CONFIGDIR', fc_configdir)
28
@@ -361,7 +361,7 @@ configure_file(output: 'fonts.conf',
29
   install: true)
30
 
31
 install_data('fonts.dtd',
32
-  install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'xml/fontconfig')
33
+  install_dir: join_paths(get_option('prefix'), get_option('sysconfdir'), 'fonts')
34
 )
35
 
36
 fc_headers = [
(-)a/x11-fonts/fontconfig/files/patch-src__fccompat.c (-17 lines)
Removed Link Here
1
There is an undiagnosed ARMv6 core dump in this code
2
as discovered in FreeBSD Bug 183536 when using clang.
3
Removing this code from ARM builds resolves it.
4
5
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=183536
6
7
--- src/fccompat.c.orig	2016-07-11 02:41:06 UTC
8
+++ src/fccompat.c
9
@@ -191,7 +191,7 @@ FcRandom(void)
10
 #else
11
     random_r (&fcrandbuf, &result);
12
 #endif
13
-#elif HAVE_RANDOM
14
+#elif HAVE_RANDOM && !defined(__arm__)
15
     static char statebuf[256];
16
     char *state;
17
     static FcBool initialized = FcFalse;
(-)a/x11-fonts/fontconfig/files/patch-src_fcatomic.h (-20 lines)
Removed Link Here
1
--- src/fcatomic.h.orig	2016-07-11 02:41:06 UTC
2
+++ src/fcatomic.h
3
@@ -96,7 +96,17 @@ typedef int fc_atomic_int_t;
4
 #define fc_atomic_int_add(AI, V)	__sync_fetch_and_add (&(AI), (V))
5
 
6
 #define fc_atomic_ptr_get(P)		(void *) (__sync_synchronize (), *(P))
7
+#if defined(__FreeBSD__) && defined(__mips_n64)
8
+#include <sys/types.h>
9
+#include <machine/atomic.h>
10
+#define fc_atomic_ptr_cmpexch(P,O,N)	atomic_cmpset_rel_64 ((uint64_t *)(P), (uint64_t)(O), (uint64_t)(N))
11
+#elif defined(__FreeBSD__) && defined(__mips)
12
+#include <sys/types.h>
13
+#include <machine/atomic.h>
14
+#define fc_atomic_ptr_cmpexch(P,O,N)	atomic_cmpset_rel_32 ((uint32_t *)(P), (uint32_t)(O), (uint32_t)(N))
15
+#else
16
 #define fc_atomic_ptr_cmpexch(P,O,N)	__sync_bool_compare_and_swap ((P), (O), (N))
17
+#endif /* defined(__FreeBSD__) && defined(__mips__) */
18
 
19
 
20
 #elif !defined(FC_NO_MT) && defined(HAVE_SOLARIS_ATOMIC_OPS)
(-)b/x11-fonts/fontconfig/files/patch-src_fclang.c (-1 / +1 lines)
Lines 1-4 Link Here
1
--- src/fclang.c.orig	2017-09-21 04:44:27 UTC
1
--- src/fclang.c.orig	2020-11-28 01:56:42 UTC
2
+++ src/fclang.c
2
+++ src/fclang.c
3
@@ -183,6 +183,7 @@ FcLangNormalize (const FcChar8 *lang)
3
@@ -183,6 +183,7 @@ FcLangNormalize (const FcChar8 *lang)
4
 {
4
 {
(-)b/x11-fonts/fontconfig/files/patch-src_meson.build (+12 lines)
Added Link Here
1
--- src/meson.build.orig	2020-11-28 01:56:42 UTC
2
+++ src/meson.build
3
@@ -88,7 +88,7 @@ pkgmod.generate(libfontconfig,
4
   version: fc_version,
5
   variables: [
6
     'sysconfdir=@0@'.format(join_paths(prefix, get_option('sysconfdir'))),
7
-    'localstatedir=@0@'.format(join_paths(prefix, get_option('localstatedir'))),
8
+    'localstatedir=/var',
9
     'confdir=${sysconfdir}/fonts',
10
-    'cachedir=${localstatedir}/cache/fontconfig',
11
+    'cachedir=/var/db/fontconfig',
12
   ])
(-)b/x11-fonts/fontconfig/pkg-plist (-11 / +1 lines)
Lines 60-65 etc/fonts/conf.d/65-fonts-persian.conf Link Here
60
etc/fonts/conf.d/65-nonlatin.conf
60
etc/fonts/conf.d/65-nonlatin.conf
61
etc/fonts/conf.d/69-unifont.conf
61
etc/fonts/conf.d/69-unifont.conf
62
%%NO_BITMAPS%%etc/fonts/conf.d/70-no-bitmaps.conf
62
%%NO_BITMAPS%%etc/fonts/conf.d/70-no-bitmaps.conf
63
%%BITMAPS%%etc/fonts/conf.d/70-yes-bitmaps.conf
63
etc/fonts/conf.d/80-delicious.conf
64
etc/fonts/conf.d/80-delicious.conf
64
etc/fonts/conf.d/90-synthetic.conf
65
etc/fonts/conf.d/90-synthetic.conf
65
etc/fonts/conf.d/README
66
etc/fonts/conf.d/README
Lines 73-88 lib/libfontconfig.so Link Here
73
lib/libfontconfig.so.1
74
lib/libfontconfig.so.1
74
lib/libfontconfig.so.1.12.0
75
lib/libfontconfig.so.1.12.0
75
libdata/pkgconfig/fontconfig.pc
76
libdata/pkgconfig/fontconfig.pc
76
man/man1/fc-cache.1.gz
77
man/man1/fc-cat.1.gz
78
man/man1/fc-conflist.1.gz
79
man/man1/fc-list.1.gz
80
man/man1/fc-match.1.gz
81
man/man1/fc-pattern.1.gz
82
man/man1/fc-query.1.gz
83
man/man1/fc-scan.1.gz
84
man/man1/fc-validate.1.gz
85
man/man5/fonts-conf.5.gz
86
share/gettext/its/fontconfig.its
77
share/gettext/its/fontconfig.its
87
share/gettext/its/fontconfig.loc
78
share/gettext/its/fontconfig.loc
88
%%NLS%%share/locale/zh_CN/LC_MESSAGES/fontconfig-conf.mo
79
%%NLS%%share/locale/zh_CN/LC_MESSAGES/fontconfig-conf.mo
89
- 

Return to bug 253212