From de3e2e7efc982b316227c96dcab57293922b1e26 Mon Sep 17 00:00:00 2001 From: Fred Bauer Date: Fri, 14 Oct 2011 20:35:52 +0000 Subject: Remove font_reset() which tried to fetch font *pfs from uninitiaized buflib_allocations. Change handle locking to track number of locks applied. Remove some duplicated code from internal_load_font() git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30752 a1c6a512-1295-4272-9138-f99709370657 --- firmware/font.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/firmware/font.c b/firmware/font.c index dfc8aba..577fb8a 100644 --- a/firmware/font.c +++ b/firmware/font.c @@ -77,7 +77,7 @@ extern struct font sysfont; struct buflib_alloc_data { struct font font; - bool handle_locked; /* is the buflib handle currently locked? */ + int handle_locks; /* is the buflib handle currently locked? */ int refcount; /* how many times has this font been loaded? */ unsigned char buffer[]; }; @@ -90,7 +90,7 @@ static int buflibmove_callback(int handle, void* current, void* new) struct buflib_alloc_data *alloc = (struct buflib_alloc_data*)current; ptrdiff_t diff = new - current; - if (alloc->handle_locked) + if (alloc->handle_locks > 0) return BUFLIB_CB_CANNOT_MOVE; #define UPDATE(x) if (x) { x = PTR_ADD(x, diff); } @@ -111,7 +111,10 @@ static int buflibmove_callback(int handle, void* current, void* new) static void lock_font_handle(int handle, bool lock) { struct buflib_alloc_data *alloc = core_get_data(handle); - alloc->handle_locked = lock; + if ( lock ) + alloc->handle_locks++; + else + alloc->handle_locks--; } static struct buflib_callbacks buflibops = {buflibmove_callback, NULL }; @@ -342,15 +345,6 @@ static struct font* font_load_cached(struct font* pf) return pf; } -static void font_reset(int font_id) -{ - struct font *pf = pf_from_handle(buflib_allocations[font_id]); - // fixme - memset(pf, 0, sizeof(struct font)); - pf->fd = -1; -} - - static bool internal_load_font(int font_id, const char *path, char *buf, size_t buf_size, int handle @@ -358,13 +352,6 @@ static bool internal_load_font(int font_id, const char *path, { size_t size; struct font* pf = pf_from_handle(handle); - /* save loaded glyphs */ - glyph_cache_save(pf); - /* Close font file handle */ - if (pf->fd >= 0) - close(pf->fd); - - font_reset(font_id); /* open and read entire font file*/ pf->fd = open(path, O_RDONLY|O_BINARY); @@ -455,8 +442,7 @@ static int alloc_and_init(int font_idx, const char* name, size_t size) return handle; pdata = core_get_data(handle); pf = &pdata->font; - font_reset(font_idx); - pdata->handle_locked = false; + pdata->handle_locks = 0; pdata->refcount = 1; pf->buffer_position = pf->buffer_start = buffer_from_handle(handle); pf->buffer_size = size; -- cgit v1.1