Back to index

lightning-sunbird  0.9+nobinonly
text_cache_crash.c
Go to the documentation of this file.
00001 /*
00002  * Copyright © 2004 Red Hat, Inc.
00003  *
00004  * Permission to use, copy, modify, distribute, and sell this software
00005  * and its documentation for any purpose is hereby granted without
00006  * fee, provided that the above copyright notice appear in all copies
00007  * and that both that copyright notice and this permission notice
00008  * appear in supporting documentation, and that the name of
00009  * Red Hat, Inc. not be used in advertising or publicity pertaining to
00010  * distribution of the software without specific, written prior
00011  * permission. Red Hat, Inc. makes no representations about the
00012  * suitability of this software for any purpose.  It is provided "as
00013  * is" without express or implied warranty.
00014  *
00015  * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
00016  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
00017  * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
00018  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
00019  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
00020  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
00021  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00022  *
00023  * Author: Carl D. Worth <cworth@cworth.org>
00024  */
00025 
00026 /* Bug history
00027  *
00028  * 2004-11-04 Ned Konz <ned@squeakland.org>
00029  *
00030  *   Reported bug on mailing list:
00031  *
00032  *     From: Ned Konz <ned@squeakland.org>
00033  *     To: cairo@cairographics.org
00034  *     Date: Thu, 4 Nov 2004 09:49:38 -0800
00035  *     Subject: [cairo] getting assertions [cairo_cache.c:143: _entry_destroy:
00036  *             Assertion `cache->used_memory > entry->memory' failed]
00037  *
00038  *     The attached program dies on me with the assert
00039  *
00040  *     $ ./testCairo
00041  *     testCairo: cairo_cache.c:143: _entry_destroy: Assertion `cache->used_memory > entry->memory' failed.
00042  *
00043  * 2004-11-04 Carl Worth <cworth@cworth.org>
00044  *
00045  *   I trimmed down Ned's example to the folllowing test while still
00046  *   maintaining the assertion.
00047  *
00048  *   Oh, actually, it looks like I may have triggered something
00049  *   slightly different:
00050  *
00051  *     text_cache_crash: cairo_cache.c:422: _cairo_cache_lookup: Assertion `cache->max_memory >= (cache->used_memory + new_entry->memory)' failed.
00052  *
00053  *   I'll have to go back and try the original test after I fix this.
00054  *
00055  * 2004-11-13 Carl Worth <cworth@cworth.org>
00056  *
00057  *   Found the bug. cairo_gstate_select_font was noticing when the
00058  *   same font was selected twice in a row and was erroneously failing
00059  *   to free the old reference. Committed a fix and verified it also
00060  *   fixed the orginal test case.
00061  */
00062 
00063 #include "cairo_test.h"
00064 
00065 cairo_test_t test = {
00066     "text_cache_crash",
00067     "Test case for bug causing an assertion failure in _cairo_cache_lookup",
00068     0, 0,
00069 };
00070 #include <cairo.h>
00071 
00072 static void
00073 draw (cairo_t *cr, int width, int height)
00074 {
00075     /* Once there was a bug that choked when selecting the same font twice. */
00076     cairo_select_font(cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
00077     cairo_scale_font(cr, 40.0);
00078 
00079     cairo_select_font(cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
00080     cairo_scale_font(cr, 40.0);
00081     cairo_move_to(cr, 10, 50);
00082     cairo_show_text(cr, "hello");
00083 
00084     /* Then there was a bug that choked when selecting a font too big
00085      * for the cache. */
00086 
00087 /* XXX: Sometimes this leads to an assertion:
00088 
00089 _cairo_cache_lookup: Assertion `cache->max_memory >= (cache->used_memory + new_entry->memory)' failed.
00090 Aborted
00091 
00092    But other times my machine hangs completely only to return to life
00093    several minutes later with some programs missing. This seems like
00094    the out-of-memory killer to me.
00095 
00096    It seems like I usually get the assertion when I run
00097    ./text_cache_crash directly and I usually get the machine hang when
00098    I run "make check" but I don't know if there's a perfect
00099    correlation there.
00100 
00101    So there's a bad bug here somewhere that really needs to be fixed.
00102    But in the meantime, I need "make check" not to destory work, so
00103    I'm commenting this test out for now.
00104 
00105     cairo_scale_font (cr, 500);
00106     cairo_show_text (cr, "hello");
00107 */
00108 }
00109 
00110 int
00111 main (void)
00112 {
00113     int ret;
00114 
00115     ret = cairo_test (&test, draw);
00116 
00117     /* It's convenient to be able to free all memory (including
00118      * statically allocated memory). This makes it quite easy to use
00119      * tools such as valgrind to verify that there are no memory leaks
00120      * whatsoever.
00121      *
00122      * But I'm not sure what would be a sensible cairo API function
00123      * for this. The cairo_destroy_caches call below is just something
00124      * I made as a local modification to cairo.
00125      */
00126     /*
00127     cairo_destroy_caches ();
00128     FcFini ();
00129     */
00130 
00131     return ret;
00132 }
00133