This test creates surfaces and patterns that it never cleans up. Found via
running:
CAIRO_TEST_TARGET=image valgrind --leak-check=full ./cairo-test-suite -f bug-431
Output before this commit:
==21310==
==21310== HEAP SUMMARY:
==21310== in use at exit: 569,788 bytes in 26 blocks
==21310== total heap usage: 1,523 allocs, 1,497 frees, 2,034,252 bytes allocated
==21310==
==21310== 336 bytes in 2 blocks are definitely lost in loss record 5 of 17
==21310== at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==21310== by 0x48BE2B0: _cairo_pattern_create_solid (cairo-pattern.c:614)
==21310== by 0x48BE4B1: cairo_pattern_create_rgba (cairo-pattern.c:720)
==21310== by 0x1358C6: draw (bug-431.c:50)
==21310== by 0x129EDB: cairo_test_for_target (cairo-test.c:938)
==21310== by 0x12B36A: _cairo_test_context_run_for_target (cairo-test.c:1545)
==21310== by 0x12C370: _cairo_test_runner_draw (cairo-test-runner.c:258)
==21310== by 0x12DEA0: main (cairo-test-runner.c:962)
==21310==
==21310== 278,534 (144 direct, 278,390 indirect) bytes in 1 blocks are definitely lost in loss record 15 of 17
==21310== at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==21310== by 0x48BE51E: cairo_pattern_create_for_surface (cairo-pattern.c:756)
==21310== by 0x135838: draw (bug-431.c:41)
==21310== by 0x129EDB: cairo_test_for_target (cairo-test.c:938)
==21310== by 0x12B36A: _cairo_test_context_run_for_target (cairo-test.c:1545)
==21310== by 0x12C370: _cairo_test_runner_draw (cairo-test-runner.c:258)
==21310== by 0x12DEA0: main (cairo-test-runner.c:962)
==21310==
==21310== 278,534 (144 direct, 278,390 indirect) bytes in 1 blocks are definitely lost in loss record 16 of 17
==21310== at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==21310== by 0x48BE51E: cairo_pattern_create_for_surface (cairo-pattern.c:756)
==21310== by 0x488274D: _cairo_default_context_set_source_surface (cairo-default-context.c:327)
==21310== by 0x49063DB: cairo_set_source_surface (cairo.c:977)
==21310== by 0x1AC1DD: _cairo_boilerplate_get_image_surface (cairo-boilerplate.c:337)
==21310== by 0x12A486: cairo_test_for_target (cairo-test.c:1145)
==21310== by 0x12B36A: _cairo_test_context_run_for_target (cairo-test.c:1545)
==21310== by 0x12C370: _cairo_test_runner_draw (cairo-test-runner.c:258)
==21310== by 0x12DEA0: main (cairo-test-runner.c:962)
==21310==
==21310== LEAK SUMMARY:
==21310== definitely lost: 624 bytes in 4 blocks
==21310== indirectly lost: 556,780 bytes in 16 blocks
==21310== possibly lost: 0 bytes in 0 blocks
==21310== still reachable: 12,384 bytes in 6 blocks
==21310== suppressed: 0 bytes in 0 blocks
==21310== Reachable blocks (those to which a pointer was found) are not shown.
==21310== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==21310==
==21310== For lists of detected and suppressed errors, rerun with: -s
==21310== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)
Signed-off-by: Uli Schlachter <psychon@znc.in>
A scaled font contains font options. Since commit 67eeed44, this can
contain an extra allocation for a custom palette. Since commit
edf9497c3a, this contains an extra allocation for a string. Before these
commit, font options could just be dropped, but now they need to be
freed.
This commit makes the relevant code for creating and finishing scaled
fonts also clean up the font options.
The test added in the previous commit also hits this bug (I only found
these leaks accidentially!). Running "valgrind --leak-check=full
./cairo-test-suite -f leaks-set-scaled-font" no longer reports the following
after this change:
40 bytes in 1 blocks are definitely lost in loss record 1 of 11
at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4886C62: _cairo_font_options_init_copy (cairo-font-options.c:105)
by 0x48DAFFB: _cairo_scaled_font_init_key (cairo-scaled-font.c:675)
by 0x48DC077: cairo_scaled_font_create (cairo-scaled-font.c:1096)
by 0x15BF08: leaks_set_scaled_font (leaks.c:43)
by 0x129EF0: cairo_test_for_target (cairo-test.c:938)
by 0x12B37F: _cairo_test_context_run_for_target (cairo-test.c:1545)
by 0x12C385: _cairo_test_runner_draw (cairo-test-runner.c:258)
by 0x12DEB5: main (cairo-test-runner.c:962)
40 bytes in 1 blocks are definitely lost in loss record 2 of 11
at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4886C62: _cairo_font_options_init_copy (cairo-font-options.c:105)
by 0x49337BB: _cairo_ft_font_face_scaled_font_create (cairo-ft-font.c:2073)
by 0x48DC340: cairo_scaled_font_create (cairo-scaled-font.c:1176)
by 0x15BF08: leaks_set_scaled_font (leaks.c:43)
by 0x129EF0: cairo_test_for_target (cairo-test.c:938)
by 0x12B37F: _cairo_test_context_run_for_target (cairo-test.c:1545)
by 0x12C385: _cairo_test_runner_draw (cairo-test-runner.c:258)
by 0x12DEB5: main (cairo-test-runner.c:962)
40 bytes in 1 blocks are definitely lost in loss record 3 of 11
at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4886C62: _cairo_font_options_init_copy (cairo-font-options.c:105)
by 0x48DB280: _cairo_scaled_font_init (cairo-scaled-font.c:742)
by 0x4933804: _cairo_ft_font_face_scaled_font_create (cairo-ft-font.c:2076)
by 0x48DC340: cairo_scaled_font_create (cairo-scaled-font.c:1176)
by 0x15BF08: leaks_set_scaled_font (leaks.c:43)
by 0x129EF0: cairo_test_for_target (cairo-test.c:938)
by 0x12B37F: _cairo_test_context_run_for_target (cairo-test.c:1545)
by 0x12C385: _cairo_test_runner_draw (cairo-test-runner.c:258)
by 0x12DEB5: main (cairo-test-runner.c:962)
Signed-off-by: Uli Schlachter <psychon@znc.in>
cairo_gstate_t contains a cairo_font_options_t. Since commit 67eeed44,
this can contain an extra allocation for a custom palette. Since commit
edf9497c3a, this contains an extra allocation for a string. Before these
commit, font options could just be dropped, but now they need to be
freed.
This commit makes _cairo_gstate_fini() finish the font options to free
the memory allocation.
The new test was run via "valgrind --leak-check=full ./cairo-test-suite
-f leaks-set-scaled-font". The following reported leak goes away thanks
to this commit:
1,040 bytes in 26 blocks are definitely lost in loss record 6 of 12
at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4886C62: _cairo_font_options_init_copy (cairo-font-options.c:105)
by 0x488C029: _cairo_gstate_set_font_options (cairo-gstate.c:1757)
by 0x48841D7: _cairo_default_context_set_scaled_font (cairo-default-context.c:1310)
by 0x490809A: cairo_set_scaled_font (cairo.c:3318)
by 0x15BF1F: leaks_set_scaled_font (leaks.c:45)
by 0x129EF0: cairo_test_for_target (cairo-test.c:938)
by 0x12B37F: _cairo_test_context_run_for_target (cairo-test.c:1545)
by 0x12C385: _cairo_test_runner_draw (cairo-test-runner.c:258)
by 0x12DEB5: main (cairo-test-runner.c:962)
Fixes: https://gitlab.freedesktop.org/cairo/cairo/-/issues/795
Signed-off-by: Uli Schlachter <psychon@znc.in>
The ctype(3) character classification and mapping functions have a
peculiarly limited definition (C11, Sec. 7.4 `Character handling
<ctype.h>', p. 200):
`The header <ctype.h> declares several functions useful for
classifying and mapping characters. In all cases the
argument is an int, the value of which shall be
representable as an unsigned char or shall equal the value
of the macro EOF. If the argument has any other value, the
behavior is undefined.'
In other words, in the most common case of 8-bit char and EOF = -1,
the domain of the 257 allowed arguments is:
-1, 0, 1, 2, ..., 254, 255
The ctype(3) functions are designed for use with stdio functions like
getchar and fgetc which return int values in the same domain.
In an ABI where char is signed (e.g., x86 SysV ABI used by most
Unixish operating systems), passing an argument of type char as is
can go wrong in two ways:
1. The value of a non-EOF input octet interpreted as `char' may
coincide, as an integer, with the value of EOF, leading to wrong
answers for some non-EOF inputs.
E.g., if EOF = 1, and an input octet has all bits set, i.e., 255
as an unsigned char, then as a char the value is -1, which will be
confused with EOF. In the ISO-8859-1 locale, the code point 255
is (in Unicode terminology) LATIN SMALL LETTER Y WITH DIAERESIS,
for which isprint, isalpha, &c., are true. But isprint, isalpha,
&c., are false for EOF. So if char *s points to a string with
that character, isprint(*s) will return false when it should
return true.
2. Passing a negative char whose value does not coincide with EOF is
undefined behaviour.
This isn't purely theoretical: often the functions are implemented
by an array lookup, #define isprint(c) (ctypetab[c] & ISPRINT).
If c is out of range (e.g., 192, ISO-8859-1 for LATIN CAPITAL
LETTER A WITH GRAVE, which convers to (signed) char as -64), then
you can get garbage answers by reading uninitialized memory or
application crashes with SIGSEGV if the page preceding the table
is unmapped.
If what you have is an arbitrary char (e.g., from a char * string
pointing at user input), then the only correct way to use the
ctype(3) functions is by converting to unsigned char first -- e.g.,
isprint((unsigned char)*s). (If the functions were defined as macros
that convert to unsigned char first, they would then spuriously
interpret EOF as a non-EOF, so they can't do that themselves.)
It is possible, in some cases, to prove that the input always
actually lies in {0, 1, 2, ..., 127}, so the conversion to unsigned
char is not necessary. I didn't check whether this was the case --
it's safer to just adopt the habit of always casting char to unsigned
char first before using the ctype(3) macros, which satisfies a
compiler warning on some systems designed to detect this class of
application errors at compile-time.
The code is doing "if (!double_buf_equal () != 0)" which seems to be a
convoluted way to do "if (!double_buf_equal ())". Fixes:
../test/pattern-getters.c:153:6: warning: logical not is only applied to the left hand side of this comparison [-Wlogical-not-parentheses]
if (!double_buf_equal (ctx, new_buf, expected_values,
^
../test/pattern-getters.c:153:6: note: add parentheses after the '!' to evaluate the comparison first
if (!double_buf_equal (ctx, new_buf, expected_values,
^
(
../test/pattern-getters.c:153:6: note: add parentheses around left hand side expression to silence this warning
if (!double_buf_equal (ctx, new_buf, expected_values,
^
(
../test/cairo-test-runner.c:730:48: warning: parameter 'str' set but not used [-Wunused-but-set-parameter]
_has_required_ghostscript_version (const char *str)
This implements Type 3 color fonts for PDF for any font with a
CAIRO_SCALED_GLYPH_INFO_RECORDING_SURFACE. This includes user-fonts,
SVG fonts, and COLR fonts.
Glyphs with foreground colors are not yet implemented as Type 3 glyphs
and will be rendered as images by cairo-surface.
The GL support in Cairo has always been a prototype, and
nothing happened in the past 10+ years to make it work as
it was meant to.
GL support is not enabled by any downstream packagers of
Cairo, so nobody should notice its absence.
There is a bug in the recording surface where if one recording surface
is used as the same source on different paginated targets that support
fine grained fallbacks, the output may be incorrect because the
analysis results of a previous target are re-used on another target.
The base image has 16 bits per channel, with colors that do not
have an exact corresponding 8 bit representation. The reference
image uses 8bpc, like the rgb24/argb32 formatted images which
the test outputs.
The check-refs.sh script detects duplicate reference images. This commit
adds it to be run by CI. For this, the script is extended with a proper
exit code.
Signed-off-by: Uli Schlachter <psychon@znc.in>
Running test/check-refs.sh reports:
redundant: arc-direction.pdf.ref.png and arc-direction.ref.png are byte-by-byte identical files
redundant: big-little-triangle.traps.argb32.ref.png and big-little-triangle.argb32.ref.png are byte-by-byte identical files
redundant: big-little-triangle.traps.rgb24.ref.png and big-little-triangle.rgb24.ref.png are byte-by-byte identical files
redundant: clip-fill-rule.pdf.rgb24.ref.png and clip-fill-rule.rgb24.ref.png are byte-by-byte identical files
redundant: dash-offset-negative.pdf.ref.png and dash-offset-negative.ref.png are byte-by-byte identical files
redundant: font-matrix-translation.traps.ref.png and font-matrix-translation.ref.png are byte-by-byte identical files
redundant: ft-show-glyphs-positioning.traps.ref.png and ft-show-glyphs-positioning.ref.png are byte-by-byte identical files
redundant: ft-show-glyphs-table.traps.ref.png and ft-show-glyphs-table.ref.png are byte-by-byte identical files
redundant: glyph-cache-pressure.traps.ref.png and glyph-cache-pressure.ref.png are byte-by-byte identical files
redundant: inverse-text.traps.ref.png and inverse-text.ref.png are byte-by-byte identical files
redundant: line-width-large-overlap-offset.ps.ref.png and line-width-large-overlap-offset.ref.png are byte-by-byte identical files
redundant: partial-clip-text-right.traps.ref.png and partial-clip-text-right.ref.png are byte-by-byte identical files
redundant: partial-clip-text-top.traps.ref.png and partial-clip-text-top.ref.png are byte-by-byte identical files
redundant: record90-fill-alpha.pdf.ref.png and record90-fill-alpha.ref.png are byte-by-byte identical files
redundant: record90-paint-alpha-clip.quartz.ref.png and record90-paint-alpha-clip.ref.png are byte-by-byte identical files
redundant: record-fill-alpha.pdf.ref.png and record-fill-alpha.ref.png are byte-by-byte identical files
redundant: recordflip-whole-fill-alpha.quartz.ref.png and recordflip-whole-fill-alpha.ref.png are byte-by-byte identical files
redundant: recordflip-whole-paint-alpha-clip-mask.quartz.ref.png and recordflip-whole-paint-alpha-clip-mask.ref.png are byte-by-byte identical files
redundant: record-mesh.ps.ref.png and record-mesh.ref.png are byte-by-byte identical files
redundant: select-font-face.traps.ref.png and select-font-face.ref.png are byte-by-byte identical files
redundant: show-glyphs-advance.traps.ref.png and show-glyphs-advance.ref.png are byte-by-byte identical files
redundant: show-text-current-point.traps.ref.png and show-text-current-point.ref.png are byte-by-byte identical files
redundant: text-antialias-gray.traps.ref.png and text-antialias-gray.ref.png are byte-by-byte identical files
This commit removes these redundant files.
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit changes the height of the coverage-column-triangles test by
using a smaller height for the test. Previously the image was 40 pixels
in height and the test took 517 seconds for me. Now, the image has a
height of 4 pixels and the test takes 55 seconds.
This is possible since column_triangles() does the same thing for each y
coordinate. Thus, previously this test just did the same thing 40 times.
Times are measured with the backends I happened to have enabled locally:
script, xcb, xlib, image, recording.
Thanks a lot to Christian Rohlfs for coming up with this idea in
https://gitlab.freedesktop.org/cairo/cairo/-/issues/498#note_1700197
Possibly-fixes: https://gitlab.freedesktop.org/cairo/cairo/-/issues/498
Signed-off-by: Uli Schlachter <psychon@znc.in>
The tests in coverage.c have #defines for WIDTH and HEIGHT, but also
have function arguments for these numbers. This commit changes the tests
to use the function arguments instead of the defines.
One complication is the rhombus test that already had a factor 2 between
these two numbers. A new variable is added to get back the previous
value.
Signed-off-by: Uli Schlachter <psychon@znc.in>
This adds the necessary dependencies for testing cairo-ps to CI and sets
up jobs for testing the ps2 and ps3 backends.
Signed-off-by: Uli Schlachter <psychon@znc.in>