From 2b15821a6524b5a5231b97d5d4c0cb5a459711e8 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Tue, 2 Jun 2020 17:21:06 -0700 Subject: fix: remaining raw free calls --- sys/libfont/font.c | 58 +++++++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'sys/libfont/font.c') diff --git a/sys/libfont/font.c b/sys/libfont/font.c index 1492b61..9424946 100644 --- a/sys/libfont/font.c +++ b/sys/libfont/font.c @@ -1979,30 +1979,33 @@ typedef struct hheap { struct hheap_chunk *head; void *first_free; - int num_remaining_in_head_chunk; + int nrem; } hheap; static void * hheap_alloc(hheap *hh, uintptr size, mem·Allocator mem, void *heap) { - if (hh->first_free) { - void *p = hh->first_free; - hh->first_free = * (void **) p; - return p; - } else { - if (hh->num_remaining_in_head_chunk == 0) { - int count = (size < 32 ? 2000 : size < 128 ? 800 : 100); - hheap_chunk *c = mem.alloc(heap, 1, sizeof(hheap_chunk) + size * count); - if (c == nil) - return nil; - c->next = hh->head; - hh->head = c; - hh->num_remaining_in_head_chunk = count; - } - --hh->num_remaining_in_head_chunk; - return (char *) (hh->head) + sizeof(hheap_chunk) + size * hh->num_remaining_in_head_chunk; - } + int n; + void *p; + if (hh->first_free) { + p = hh->first_free; + hh->first_free = * (void **) p; + return p; + } else { + if (hh->nrem == 0) { + n = (size < 32 ? 2000 : size < 128 ? 800 : 100); + hheap_chunk *c = mem.alloc(heap, 1, sizeof(hheap_chunk) + size * n); + if (c == nil) + return nil; + + c->next = hh->head; + hh->head = c; + hh->nrem = n; + } + --hh->nrem; + return (char *)(hh->head) + sizeof(hheap_chunk) + size * hh->nrem; + } } static @@ -2033,7 +2036,8 @@ new_active(hheap *hh, Edge *e, int off_x, float start_point, mem·Allocator mem, float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0); assert(z != nil); //assert(e->y0 <= start_point); - if (!z) return z; + if (!z) + return z; z->fdx = dxdy; z->fdy = dxdy != 0.0f ? (1.0f/dxdy) : 0.0f; z->fx = e->x0 + dxdy * (start_point - e->y0); @@ -2254,7 +2258,7 @@ static void rasterize_sorted_edges(font·Bitmap *result, Edge *e, int n, int vsubsample, int off_x, int off_y, mem·Allocator mem, void *heap) { - hheap hh = { 0, 0, 0 }; + hheap hh = { 0 }; ActiveEdge *active = nil; int y,j=0, i; float scanline_data[129], *scanline, *scanline2; @@ -2480,9 +2484,9 @@ rasterize_points(font·Bitmap *result, Point *pts, int *wcount, int windings, fl e[n].invert = 1; a=j,b=k; } - e[n].x0 = p[a].x * scale_x + shift_x; + e[n].x0 = p[a].x * scale_x + shift_x; e[n].y0 = (p[a].y * y_scale_inv + shift_y) * vsubsample; - e[n].x1 = p[b].x * scale_x + shift_x; + e[n].x1 = p[b].x * scale_x + shift_x; e[n].y1 = (p[b].y * y_scale_inv + shift_y) * vsubsample; ++n; } @@ -2544,7 +2548,7 @@ tesselate_cubic(Point *points, int *num_points, float x0, float y0, float x1, fl float dy2 = y3-y2; float dx = x3-x0; float dy = y3-y0; - float longlen = (float) (sqrt(dx0*dx0+dy0*dy0)+sqrt(dx1*dx1+dy1*dy1)+sqrt(dx2*dx2+dy2*dy2)); + float longlen = (float) (sqrt(dx0*dx0+dy0*dy0)+sqrt(dx1*dx1+dy1*dy1)+sqrt(dx2*dx2+dy2*dy2)); float shortlen = (float) sqrt(dx*dx+dy*dy); float flatness_squared = longlen*longlen-shortlen*shortlen; @@ -2667,15 +2671,15 @@ rasterize(font·Bitmap *result, float flatness_in_pixels, font·Vertex *verts, i Point *windings = flatten(verts, num_verts, flatness_in_pixels / scale, &winding_lengths, &winding_count, mal, heap); if (windings) { rasterize_points(result, windings, winding_lengths, winding_count, scale_x, scale_y, shift_x, shift_y, x_off, y_off, invert, mal, heap); - free(winding_lengths); - free(windings); + mal.free(heap, windings); + mal.free(heap, winding_lengths); } } void -font·freebitmap(uchar *bm, void *userdata) +font·freebitmap(font·Info *info, uchar *bm) { - free(bm); + info->free(info->heap, bm); } uchar * -- cgit v1.2.1