Commitbe365905Recorded9 Nov 2026Repositorysigil-fontconfig
Keep Fontconfig isolation ordered and qualify weak values
Changed
README.md | 9 +++++++++
scripts/ci-test.sgl | 13 ++++++++++---
src/sigil/fontconfig.sgl | 3 ++-
test/test-00-isolation.sgl | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------
test/test-value-abi.sgl | 35 +++++++++++++++++++++++++++++++++++
test/value-abi.c | 10 ++++++++++
6 files changed, 126 insertions(+), 53 deletions(-)Diff
README.mdmodified
@@ -64,6 +64,8 @@ locale, normalized without a default configuration, with a weak English fallback
64
The legacy system API still calls Fontconfig's default-substitution function. 65
The owned path never calls it, including on Fontconfig 2.17 and later where 66
that function initializes the process default.+67
The uint64 string-union representation assumes little-endian LP64 targets;+68
the driver checks its layout and weak binding against the native header. 69
70
`fc-context-match` returns one copied record or `#f`. 71
`fc-context-list` optionally accepts one pattern.@@ -111,4 +113,11 @@ initialization fail the test. Plain `sigil test` is not the ordered gate: file
113
discovery order is unspecified. The separate default pointer-identity control 114
checks preservation after initialization. 115
+116
The driver sets `SIGIL_FONTCONFIG_ISOLATION_FIRST=1` only for the fresh+117
isolation process. Without that marker, plain `sigil test` skips isolation+118
with a clear message; marked runs still reject prior default initialization.+119
It compiles `test/value-abi.c`, exports `SIGIL_FONTCONFIG_VALUE_ABI`, and runs+120
the separate by-value layout/weak-binding test. That test reports a skip when+121
no receipt is supplied by the driver.+122
123
BSD-3-Clause.scripts/ci-test.sglmodified
@@ -1,6 +1,6 @@
1
;;; Run isolation in a fresh process, then the suites that initialize defaults. 2
(import (sigil shell prelude) (sigil fs))−3
(requires (tools sigil))+3
(requires (tools sigil gcc)) 4
(define root (dirname (script-dir))) 5
(define profile (getenv "GUIX_ENVIRONMENT")) 6
(define (xml text)@@ -39,7 +39,14 @@
39
(setenv! "FONTCONFIG_SYSROOT" #f) 40
(setenv! "XDG_CACHE_HOME" default-cache) 41
(when profile (setenv! "LD_LIBRARY_PATH" (path profile "lib")))+42
(define abi (path work "value-abi.sgl"))+43
($ gcc -std=c11 ,@(if profile (list "-I" (path profile "include")) '())+44
,(path root "test/value-abi.c") -o ,(path work "value-abi") timeout: 30)+45
($ ,(path work "value-abi") out: ,abi timeout: 5)+46
(setenv! "SIGIL_FONTCONFIG_VALUE_ABI" abi) 47
(println "Fontconfig CI: fresh-process isolation first")−43
($ sigil test test/test-00-isolation.sgl cwd: ,root timeout: 900)+48
($ sigil test test/test-00-isolation.sgl cwd: ,root+49
env: ,(dict "SIGIL_FONTCONFIG_ISOLATION_FIRST" "1") timeout: 900) 50
(println "Fontconfig CI: legacy and owned-context suites")−45
($ sigil test test/test-fontconfig.sgl test/test-context.sgl cwd: ,root timeout: 900))+51
($ sigil test test/test-fontconfig.sgl test/test-context.sgl cwd: ,root timeout: 900)+52
($ sigil test test/test-value-abi.sgl cwd: ,root timeout: 900))src/sigil/fontconfig.sglmodified
@@ -15,6 +15,7 @@
15
(family default: #f) (style default: #f) (size default: #f)) 16
(define-struct fc-font (file) (index) (family) (style)) 17
(define-struct fc-context (handle mutable: #t) (max-fonts))+18
(define fc-type-string 3) 19
20
;; Static compilation tools may import layouts without a dynamic loader. 21
;; Preserve the load failure and report it only on a native operation.@@ -282,7 +283,7 @@
283
(lambda () 284
(for-each (lambda (name) 285
(check-native (pattern-add-weak pattern name−285
(dict type: 3 value: (pointer-address fallback)) 1)+286
(dict type: fc-type-string value: (pointer-address fallback)) 1) 287
"FcPatternAddWeak")) 288
'("familylang" "stylelang" "fullnamelang"))) 289
(lambda () (c-free fallback))))))test/test-00-isolation.sglmodified
@@ -2,52 +2,63 @@
2
(import (sigil test) (sigil fontconfig) (sigil ffi) (sigil fs) (sigil string) 3
(sigil process) (sigil path)) 4
−5
(define inventory−6
(or (getenv "SIGIL_FONTCONFIG_TEST_DIRECTORY") (error "Select the owned font inventory")))−7
(test "fresh isolated queries never initialize the process default config"−8
(define work (or (make-temp-directory) (error "Cannot create the sentinel fixture")))−9
(define sentinel-cache (path-join work "default-cache"))−10
(define sentinel-file (path-join work "sentinel-default-config.conf"))−11
(define (xml text)−12
(string-replace (string-replace (string-replace text "&" "&") "<" "<") ">" ">"))−13
(ensure-directory sentinel-cache)−14
(write-file-string sentinel-file−15
(string-append "<fontconfig><dir>" (xml inventory) "</dir><cachedir>"−16
(xml sentinel-cache) "</cachedir></fontconfig>"))−17
(define previous−18
(map (lambda (name) (cons name (getenv name)))−19
'("FONTCONFIG_FILE" "FONTCONFIG_PATH" "XDG_CACHE_HOME")))−20
(assert-equal '() (directory-list sentinel-cache))−21
(dynamic-wind−22
(lambda ()−23
(setenv! "FONTCONFIG_FILE" sentinel-file)−24
(setenv! "FONTCONFIG_PATH" (path-dirname sentinel-file))−25
(setenv! "XDG_CACHE_HOME" sentinel-cache))−26
(lambda ()−27
;; FcGetVersion reports the loaded library without touching FcConfig.−28
(let* ((library (c-library "libfontconfig"))−29
(version (c-function library "FcGetVersion" '() ffi/int)))−30
(display "ISOLATION_FONTCONFIG_VERSION=") (display (version)) (newline))−31
(let ((context−32
(make-fc-context files:−33
(list (path-join inventory "JetBrainsMono-Regular.ttf")−34
(path-join inventory "JetBrainsMono-Bold.ttf")))))−35
(dynamic-wind (lambda () #f)−36
(lambda ()−37
(assert-equal "Regular" (fc-font-style−38
(fc-context-match context (fc-pattern family: "JetBrains Mono"))))−39
(assert-equal "Bold" (fc-font-style−40
(fc-context-match context (fc-pattern family: "JetBrains Mono" style: "Bold" size: 16))))−41
(assert-true (pair? (fc-context-sort context (fc-pattern family: "JetBrains Mono"))))−42
(assert-equal 2 (length (fc-context-list context))))−43
(lambda () (fc-context-close! context))))−44
(assert-equal '() (directory-list sentinel-cache))−45
;; This must initialize the sentinel default now. If another test already−46
;; initialized it, the new cache stays empty and this test must fail.−47
(display "ISOLATION_DEFAULT_CONTROL_BEGIN\n")−48
(let* ((library (c-library "libfontconfig"))−49
(current (c-function library "FcConfigGetCurrent" '() ffi/pointer)))−50
(assert-true (pointer? (current))))−51
(assert-true (pair? (directory-list sentinel-cache))))−52
(lambda ()−53
(for-each (lambda (entry) (setenv! (car entry) (cdr entry))) previous))))+5
(define (register-isolation!)+6
(define inventory+7
(or (getenv "SIGIL_FONTCONFIG_TEST_DIRECTORY") (error "Select the owned font inventory")))+8
(test "fresh isolated queries never initialize the process default config"+9
(define work (or (make-temp-directory) (error "Cannot create the sentinel fixture")))+10
(define sentinel-cache (path-join work "default-cache"))+11
(define sentinel-file (path-join work "sentinel-default-config.conf"))+12
(define (xml text)+13
(string-replace (string-replace (string-replace text "&" "&") "<" "<") ">" ">"))+14
(ensure-directory sentinel-cache)+15
(write-file-string sentinel-file+16
(string-append "<fontconfig><dir>" (xml inventory) "</dir><cachedir>"+17
(xml sentinel-cache) "</cachedir></fontconfig>"))+18
(define previous+19
(map (lambda (name) (cons name (getenv name)))+20
'("FONTCONFIG_FILE" "FONTCONFIG_PATH" "XDG_CACHE_HOME")))+21
(assert-equal '() (directory-list sentinel-cache))+22
(dynamic-wind+23
(lambda ()+24
(setenv! "FONTCONFIG_FILE" sentinel-file)+25
(setenv! "FONTCONFIG_PATH" (path-dirname sentinel-file))+26
(setenv! "XDG_CACHE_HOME" sentinel-cache))+27
(lambda ()+28
;; FcGetVersion reports the loaded library without touching FcConfig.+29
(let* ((library (c-library "libfontconfig"))+30
(version (c-function library "FcGetVersion" '() ffi/int)))+31
(display "ISOLATION_FONTCONFIG_VERSION=") (display (version)) (newline))+32
(let ((context+33
(make-fc-context files:+34
(list (path-join inventory "JetBrainsMono-Regular.ttf")+35
(path-join inventory "JetBrainsMono-Bold.ttf")))))+36
(dynamic-wind (lambda () #f)+37
(lambda ()+38
(assert-equal "Regular" (fc-font-style+39
(fc-context-match context (fc-pattern family: "JetBrains Mono"))))+40
(assert-equal "Bold" (fc-font-style+41
(fc-context-match context (fc-pattern family: "JetBrains Mono" style: "Bold" size: 16))))+42
(assert-true (pair? (fc-context-sort context (fc-pattern family: "JetBrains Mono"))))+43
(assert-equal 2 (length (fc-context-list context))))+44
(lambda () (fc-context-close! context))))+45
(assert-equal '() (directory-list sentinel-cache))+46
;; This must initialize the sentinel default now. If another test already+47
;; initialized it, the new cache stays empty and this test must fail.+48
(display "ISOLATION_DEFAULT_CONTROL_BEGIN\n")+49
(let* ((library (c-library "libfontconfig"))+50
(current (c-function library "FcConfigGetCurrent" '() ffi/pointer)))+51
(assert-true (pointer? (current))))+52
(assert-true (pair? (directory-list sentinel-cache))))+53
(lambda ()+54
(for-each (lambda (entry) (setenv! (car entry) (cdr entry))) previous)+55
(let remove ((file work))+56
(if (and (directory? file) (not (symlink? file)))+57
(begin+58
(for-each (lambda (name) (remove (path-join file name))) (directory-list file))+59
(delete-directory file))+60
(delete-file file)))))))+61
+62
(if (equal? (getenv "SIGIL_FONTCONFIG_ISOLATION_FIRST") "1")+63
(register-isolation!)+64
(display "SKIP: fresh Fontconfig isolation requires scripts/ci-test.sgl\n"))test/test-value-abi.sgladded
@@ -0,0 +1,35 @@
+1
(import (sigil test) (sigil ffi) (sigil process) (sigil io))+2
+3
(if (getenv "SIGIL_FONTCONFIG_VALUE_ABI")+4
(test "FcValue string union layout and weak binding match the native header"+5
(define receipt (call-with-input-file (getenv "SIGIL_FONTCONFIG_VALUE_ABI") read))+6
(define layout (c-struct-layout type: ffi/int value: ffi/uint64))+7
(assert-equal (car receipt) (c-struct-size layout))+8
(assert-equal (cadr receipt) (c-alignof ffi/uint64))+9
(assert-equal (caddr receipt) (c-struct-offset layout value:))+10
(define library (c-library "libfontconfig"))+11
(define create (c-function library "FcPatternCreate" '() ffi/pointer))+12
(define destroy (c-function library "FcPatternDestroy" (list ffi/pointer) ffi/void))+13
(define add (c-function library "FcPatternAddWeak"+14
(list ffi/pointer ffi/string layout ffi/int) ffi/int))+15
(define get (c-function library "FcPatternGetWithBinding"+16
(list ffi/pointer ffi/string ffi/int ffi/pointer ffi/pointer) ffi/int))+17
(define pattern (create))+18
(define text (string->pointer "en-us"))+19
(define value (c-alloc-struct layout))+20
(define binding (c-alloc (c-sizeof ffi/int)))+21
(dynamic-wind (lambda () #f)+22
(lambda ()+23
(assert-equal 3 (list-ref receipt 3))+24
(assert-equal 1 (add pattern "familylang"+25
(dict type: 3 value: (pointer-address text)) 1))+26
(assert-equal 0 (get pattern "familylang" 0 value binding))+27
(assert-equal (list-ref receipt 4) (pointer-ref binding ffi/int 0))+28
(assert-equal "en-us" (pointer->string+29
(make-pointer (c-struct-ref value layout value:)))))+30
(lambda ()+31
(destroy pattern)+32
(c-free text)+33
(c-free value)+34
(c-free binding))))+35
(display "SKIP: FcValue ABI receipt requires scripts/ci-test.sgl\n"))test/value-abi.cadded
@@ -0,0 +1,10 @@
+1
#include <fontconfig/fontconfig.h>+2
#include <stddef.h>+3
#include <stdio.h>+4
+5
int main(void)+6
{+7
printf("(%zu %zu %zu %d %d)\n", sizeof(FcValue), _Alignof(FcValue),+8
offsetof(FcValue, u), FcTypeString, FcValueBindingWeak);+9
return 0;+10
}