From 5529ab1e105f44a57c3007e595d36dc053a54e79 Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Thu, 4 Apr 2019 15:10:19 +0800 Subject: [PATCH] use mg_slice for TEXTRUNS, TEXTLAYOUT, GlyphRun, TextRun, LayoutRun, and so on --- include/minigui.h | 6 +++--- src/newgdi/layout-ellipsize.c | 2 +- src/newgdi/layout-utils.c | 19 ++++++++++--------- src/newgdi/layoutinfo.c | 14 +++++++------- src/newgdi/textrunsinfo.c | 28 ++++++++++++++-------------- 5 files changed, 35 insertions(+), 34 deletions(-) diff --git a/include/minigui.h b/include/minigui.h index 7114bf3d..1433cbd2 100644 --- a/include/minigui.h +++ b/include/minigui.h @@ -3737,11 +3737,11 @@ MG_EXPORT void mg_slice_free_chain_with_offset(size_t block_size, #define mg_slice_new0(type) ((type*)mg_slice_alloc0(sizeof (type))) /* MemoryBlockType * - * mg_slice_dup (MemoryBlockType, + * mg_slice_dup (MemoryBlockType, * MemoryBlockType *mem_block); - * mg_slice_delete (MemoryBlockType, + * mg_slice_delete (MemoryBlockType, * MemoryBlockType *mem_block); - * mg_slice_delete_chain (MemoryBlockType, + * mg_slice_delete_chain (MemoryBlockType, * MemoryBlockType *first_chain_block, * memory_block_next_field); * pseudo prototypes for the macro definitions following below. diff --git a/src/newgdi/layout-ellipsize.c b/src/newgdi/layout-ellipsize.c index 96953e8e..f40565c0 100644 --- a/src/newgdi/layout-ellipsize.c +++ b/src/newgdi/layout-ellipsize.c @@ -320,7 +320,7 @@ static void shape_ellipsis (EllipsizeState *state) /* Create/reset state->ellipsis_grun */ if (!state->ellipsis_grun) { - state->ellipsis_grun = malloc (sizeof(GlyphRun)); + state->ellipsis_grun = mg_slice_new(GlyphRun); state->ellipsis_grun->gstr = __mg_glyph_string_new (); state->ellipsis_grun->lrun = NULL; } diff --git a/src/newgdi/layout-utils.c b/src/newgdi/layout-utils.c index 5b83de86..3442db56 100644 --- a/src/newgdi/layout-utils.c +++ b/src/newgdi/layout-utils.c @@ -205,7 +205,7 @@ LayoutRun* __mg_layout_run_new_ellipsis(const LAYOUTINFO* layout, if (lf == NULL) return NULL; - lrun = malloc(sizeof(LayoutRun)); + lrun = mg_slice_new(LayoutRun); lrun->lf = lf; lrun->ucs = ucs; lrun->si = trun->si; @@ -232,7 +232,7 @@ LayoutRun* __mg_layout_run_new_from(const LAYOUTINFO* layout, if (lf == NULL) return NULL; - lrun = malloc(sizeof(LayoutRun)); + lrun = mg_slice_new(LayoutRun); lrun->lf = lf; lrun->si = trun->si; lrun->ucs = layout->truninfo->ucs + lrun->si; @@ -265,7 +265,7 @@ LayoutRun* __mg_layout_run_new_from_offset(const LAYOUTINFO* layout, if (lf == NULL) return NULL; - lrun = malloc(sizeof(LayoutRun)); + lrun = mg_slice_new(LayoutRun); lrun->lf = lf; lrun->si = trun->si + offset; @@ -289,7 +289,7 @@ void __mg_layout_run_free(LayoutRun* lrun) ReleaseRes(font_res->key); } - free(lrun); + mg_slice_delete(LayoutRun, lrun); } LayoutRun* __mg_layout_run_copy(const LayoutRun* lrun) @@ -299,7 +299,7 @@ LayoutRun* __mg_layout_run_copy(const LayoutRun* lrun) if (lrun == NULL) return NULL; - result = malloc(sizeof(LayoutRun)); + result = mg_slice_new(LayoutRun); memcpy(result, lrun, sizeof(LayoutRun)); // must increase the reference count of LOGFONT @@ -332,7 +332,7 @@ LayoutRun* __mg_layout_run_split(LayoutRun *orig, int split_index) GlyphString* __mg_glyph_string_new (void) { - GlyphString *string = calloc(1, sizeof(GlyphString)); + GlyphString *string = mg_slice_new0(GlyphString); return string; } @@ -345,7 +345,8 @@ void __mg_glyph_string_free (GlyphString *string) free (string->glyphs); if (string->log_clusters) free (string->log_clusters); - free (string); + + mg_slice_delete(GlyphString, string); } void __mg_glyph_string_set_size (GlyphString* string, int new_len) @@ -413,7 +414,7 @@ void __mg_glyph_run_free(GlyphRun* run) __mg_glyph_string_free(run->gstr); } - free(run); + mg_slice_delete(GlyphRun, run); } #define LTR(glyph_run) (((glyph_run)->lrun->el & 1) == 0) @@ -483,7 +484,7 @@ GlyphRun *__mg_glyph_run_split (GlyphRun *orig, int split_index) num_remaining = orig->gstr->nr_glyphs - nr_glyphs; - new_grun = malloc (sizeof(GlyphRun)); + new_grun = mg_slice_new(GlyphRun); new_grun->lrun = __mg_layout_run_split(orig->lrun, split_index); new_grun->gstr = __mg_glyph_string_new (); diff --git a/src/newgdi/layoutinfo.c b/src/newgdi/layoutinfo.c index d5ac5176..3efb1e2c 100644 --- a/src/newgdi/layoutinfo.c +++ b/src/newgdi/layoutinfo.c @@ -116,7 +116,7 @@ LAYOUTINFO* GUIAPI CreateLayoutInfo( return NULL; } - layout = (LAYOUTINFO*)calloc(1, sizeof(LAYOUTINFO)); + layout = (LAYOUTINFO*)mg_slice_new0(LAYOUTINFO); if (layout == NULL) { return NULL; } @@ -135,7 +135,7 @@ LAYOUTINFO* GUIAPI CreateLayoutInfo( layout->lf_upright = __mg_create_logfont_for_layout(layout, NULL, GLYPH_ORIENT_UPRIGHT); if (layout->lf_upright == NULL) { - free(layout); + mg_slice_delete(LAYOUTINFO, layout); return NULL; } @@ -204,7 +204,7 @@ static void release_line(LAYOUTLINE* line) free(line->log_widths); } - free(line); + mg_slice_delete(LAYOUTLINE, line); } BOOL GUIAPI DestroyLayoutInfo(LAYOUTINFO* layout) @@ -221,7 +221,7 @@ BOOL GUIAPI DestroyLayoutInfo(LAYOUTINFO* layout) release_line(line); } - free(layout); + mg_slice_delete(LAYOUTINFO, layout); return TRUE; } @@ -602,7 +602,7 @@ static void free_glyph_run (GlyphRun *grun) } __mg_glyph_string_free(grun->gstr); - free(grun); + mg_slice_delete(GlyphRun, grun); } #ifdef _DEBUG @@ -711,7 +711,7 @@ static void uninsert_run(LAYOUTLINE *line) static GlyphRun* insert_run(LAYOUTLINE *line, LayoutState *state, LayoutRun *layout_run, BOOL last_run) { - GlyphRun *glyph_run = malloc(sizeof(GlyphRun)); + GlyphRun *glyph_run = mg_slice_new(GlyphRun); glyph_run->lrun = layout_run; @@ -957,7 +957,7 @@ retry_break: static LAYOUTLINE *layout_line_new(LAYOUTINFO *layout) { - LAYOUTLINE *line = calloc (1, sizeof (LAYOUTLINE)); + LAYOUTLINE *line = mg_slice_new0(LAYOUTLINE); line->layout = layout; INIT_LIST_HEAD(&line->gruns); diff --git a/src/newgdi/textrunsinfo.c b/src/newgdi/textrunsinfo.c index 62108c94..25739509 100644 --- a/src/newgdi/textrunsinfo.c +++ b/src/newgdi/textrunsinfo.c @@ -182,7 +182,7 @@ static void state_add_character(TextRunState *state, } } - state->run = malloc(sizeof(TextRun)); + state->run = mg_slice_new(TextRun); state->run->fontname = NULL; state->run->si = pos - state->text; state->run->len = 1; @@ -306,7 +306,7 @@ static BOOL create_text_runs(TEXTRUNSINFO* runinfo, BidiLevel* els) types_buff = local_types_buff; } else { - types_buff = malloc(sizeof(Uint8)* runinfo->nr_ucs); + types_buff = malloc(sizeof(Uint8) * runinfo->nr_ucs); } if (!types_buff) @@ -458,7 +458,7 @@ TEXTRUNSINFO* GUIAPI CreateTextRunsInfo(const Uchar32* ucs, int nr_ucs, return NULL; } - runinfo = (TEXTRUNSINFO*)calloc(1, sizeof(TEXTRUNSINFO)); + runinfo = (TEXTRUNSINFO*)mg_slice_new0(TEXTRUNSINFO); if (runinfo == NULL) { return NULL; } @@ -466,7 +466,7 @@ TEXTRUNSINFO* GUIAPI CreateTextRunsInfo(const Uchar32* ucs, int nr_ucs, if (nr_ucs < LOCAL_ARRAY_SIZE) els = local_els; else - els = (BidiLevel*)malloc (nr_ucs * sizeof(BidiLevel)); + els = (BidiLevel*)malloc(nr_ucs * sizeof(BidiLevel)); if (!els) { _ERR_PRINTF("%s: failed to allocate space for embedding levels.\n", @@ -533,7 +533,7 @@ out: if (ok) return runinfo; - free(runinfo); + mg_slice_delete(TEXTRUNSINFO, runinfo); return NULL; } @@ -589,7 +589,7 @@ TextRun* __mg_text_run_copy(const TextRun *trun) if (trun == NULL) return NULL; - result = malloc(sizeof(TextRun)); + result = mg_slice_new(TextRun); memcpy(result, trun, sizeof(TextRun)); return result; @@ -756,12 +756,12 @@ BOOL GUIAPI SetTextColorInTextRuns(TEXTRUNSINFO* runinfo, while (!list_empty(&runinfo->fg_colors.list)) { TextColorMap* entry = (TextColorMap*)runinfo->fg_colors.list.prev; list_del(runinfo->fg_colors.list.prev); - free(entry); + mg_slice_delete(TextColorMap, entry); } return TRUE; } - color_entry = calloc(1, sizeof(TextColorMap)); + color_entry = mg_slice_new0(TextColorMap); if (color_entry == NULL) { goto error; } @@ -817,12 +817,12 @@ BOOL GUIAPI SetBackgroundColorInTextRuns(TEXTRUNSINFO* runinfo, while (!list_empty(&runinfo->bg_colors.list)) { TextColorMap* entry = (TextColorMap*)runinfo->bg_colors.list.prev; list_del(runinfo->bg_colors.list.prev); - free(entry); + mg_slice_delete(TextColorMap, entry); } return TRUE; } - color_entry = calloc(1, sizeof(TextColorMap)); + color_entry = mg_slice_new0(TextColorMap); if (color_entry == NULL) { goto error; } @@ -863,13 +863,13 @@ BOOL GUIAPI DestroyTextRunsInfo(TEXTRUNSINFO* runinfo) while (!list_empty(&runinfo->bg_colors.list)) { TextColorMap* entry = (TextColorMap*)runinfo->bg_colors.list.prev; list_del(runinfo->bg_colors.list.prev); - free(entry); + mg_slice_delete(TextColorMap, entry); } while (!list_empty(&runinfo->fg_colors.list)) { TextColorMap* entry = (TextColorMap*)runinfo->fg_colors.list.prev; list_del(runinfo->fg_colors.list.prev); - free(entry); + mg_slice_delete(TextColorMap, entry); } while (!list_empty(&runinfo->truns)) { @@ -877,7 +877,7 @@ BOOL GUIAPI DestroyTextRunsInfo(TEXTRUNSINFO* runinfo) list_del(runinfo->truns.prev); if (run->fontname) free(run->fontname); - free(run); + mg_slice_delete(TextRun, run); } if (runinfo->sei.inst) { @@ -885,7 +885,7 @@ BOOL GUIAPI DestroyTextRunsInfo(TEXTRUNSINFO* runinfo) } free(runinfo->fontname); - free(runinfo); + mg_slice_delete(TEXTRUNSINFO, runinfo); return TRUE; }