From 6c724fb7c14de3088b51748a781983e76c5d8ee1 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 19 Jan 2018 20:57:24 -0700 Subject: [PATCH] mesa: simplify _mesa_delete_list() a bit, add some assertions All but two cases of the switch did the same n += InstSize[n[0].opcode] instruction. Just move it after the switch. Add some sanity check assertions. Reviewed-by: Roland Scheidegger --- src/mesa/main/dlist.c | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c index a6b212e25e5..2086611aa39 100644 --- a/src/mesa/main/dlist.c +++ b/src/mesa/main/dlist.c @@ -961,79 +961,60 @@ _mesa_delete_list(struct gl_context *ctx, struct gl_display_list *dlist) /* for some commands, we need to free malloc'd memory */ case OPCODE_MAP1: free(get_pointer(&n[6])); - n += InstSize[n[0].opcode]; break; case OPCODE_MAP2: free(get_pointer(&n[10])); - n += InstSize[n[0].opcode]; break; case OPCODE_CALL_LISTS: free(get_pointer(&n[3])); - n += InstSize[n[0].opcode]; break; case OPCODE_DRAW_PIXELS: free(get_pointer(&n[5])); - n += InstSize[n[0].opcode]; break; case OPCODE_BITMAP: free(get_pointer(&n[7])); - n += InstSize[n[0].opcode]; break; case OPCODE_POLYGON_STIPPLE: free(get_pointer(&n[1])); - n += InstSize[n[0].opcode]; break; case OPCODE_TEX_IMAGE1D: free(get_pointer(&n[8])); - n += InstSize[n[0].opcode]; break; case OPCODE_TEX_IMAGE2D: free(get_pointer(&n[9])); - n += InstSize[n[0].opcode]; break; case OPCODE_TEX_IMAGE3D: free(get_pointer(&n[10])); - n += InstSize[n[0].opcode]; break; case OPCODE_TEX_SUB_IMAGE1D: free(get_pointer(&n[7])); - n += InstSize[n[0].opcode]; break; case OPCODE_TEX_SUB_IMAGE2D: free(get_pointer(&n[9])); - n += InstSize[n[0].opcode]; break; case OPCODE_TEX_SUB_IMAGE3D: free(get_pointer(&n[11])); - n += InstSize[n[0].opcode]; break; case OPCODE_COMPRESSED_TEX_IMAGE_1D: free(get_pointer(&n[7])); - n += InstSize[n[0].opcode]; break; case OPCODE_COMPRESSED_TEX_IMAGE_2D: free(get_pointer(&n[8])); - n += InstSize[n[0].opcode]; break; case OPCODE_COMPRESSED_TEX_IMAGE_3D: free(get_pointer(&n[9])); - n += InstSize[n[0].opcode]; break; case OPCODE_COMPRESSED_TEX_SUB_IMAGE_1D: free(get_pointer(&n[7])); - n += InstSize[n[0].opcode]; break; case OPCODE_COMPRESSED_TEX_SUB_IMAGE_2D: free(get_pointer(&n[9])); - n += InstSize[n[0].opcode]; break; case OPCODE_COMPRESSED_TEX_SUB_IMAGE_3D: free(get_pointer(&n[11])); - n += InstSize[n[0].opcode]; break; case OPCODE_PROGRAM_STRING_ARB: free(get_pointer(&n[4])); /* program string */ - n += InstSize[n[0].opcode]; break; case OPCODE_UNIFORM_1FV: case OPCODE_UNIFORM_2FV: @@ -1048,7 +1029,6 @@ _mesa_delete_list(struct gl_context *ctx, struct gl_display_list *dlist) case OPCODE_UNIFORM_3UIV: case OPCODE_UNIFORM_4UIV: free(get_pointer(&n[3])); - n += InstSize[n[0].opcode]; break; case OPCODE_UNIFORM_MATRIX22: case OPCODE_UNIFORM_MATRIX33: @@ -1060,7 +1040,6 @@ _mesa_delete_list(struct gl_context *ctx, struct gl_display_list *dlist) case OPCODE_UNIFORM_MATRIX34: case OPCODE_UNIFORM_MATRIX43: free(get_pointer(&n[4])); - n += InstSize[n[0].opcode]; break; case OPCODE_PROGRAM_UNIFORM_1FV: case OPCODE_PROGRAM_UNIFORM_2FV: @@ -1075,7 +1054,6 @@ _mesa_delete_list(struct gl_context *ctx, struct gl_display_list *dlist) case OPCODE_PROGRAM_UNIFORM_3UIV: case OPCODE_PROGRAM_UNIFORM_4UIV: free(get_pointer(&n[4])); - n += InstSize[n[0].opcode]; break; case OPCODE_PROGRAM_UNIFORM_MATRIX22F: case OPCODE_PROGRAM_UNIFORM_MATRIX33F: @@ -1087,15 +1065,12 @@ _mesa_delete_list(struct gl_context *ctx, struct gl_display_list *dlist) case OPCODE_PROGRAM_UNIFORM_MATRIX34F: case OPCODE_PROGRAM_UNIFORM_MATRIX43F: free(get_pointer(&n[5])); - n += InstSize[n[0].opcode]; break; case OPCODE_PIXEL_MAP: free(get_pointer(&n[3])); - n += InstSize[n[0].opcode]; break; case OPCODE_WINDOW_RECTANGLES: free(get_pointer(&n[3])); - n += InstSize[n[0].opcode]; break; case OPCODE_CONTINUE: n = (Node *) get_pointer(&n[1]); @@ -1107,9 +1082,13 @@ _mesa_delete_list(struct gl_context *ctx, struct gl_display_list *dlist) done = GL_TRUE; break; default: - /* Most frequent case */ - n += InstSize[n[0].opcode]; - break; + /* just increment 'n' pointer, below */ + ; + } + + if (opcode != OPCODE_CONTINUE) { + assert(InstSize[opcode] > 0); + n += InstSize[opcode]; } } } @@ -1325,6 +1304,8 @@ dlist_alloc(struct gl_context *ctx, OpCode opcode, GLuint bytes, bool align8) GLuint nopNode; Node *n; + assert(bytes <= BLOCK_SIZE * sizeof(Node)); + if (opcode < OPCODE_EXT_0) { if (InstSize[opcode] == 0) { /* save instruction size now */ @@ -9177,6 +9158,7 @@ execute_list(struct gl_context *ctx, GLuint list) /* increment n to point to next compiled command */ if (opcode != OPCODE_CONTINUE) { + assert(InstSize[opcode] > 0); n += InstSize[opcode]; } } @@ -10385,6 +10367,7 @@ print_list(struct gl_context *ctx, GLuint list, const char *fname) } /* increment n to point to next compiled command */ if (opcode != OPCODE_CONTINUE) { + assert(InstSize[opcode] > 0); n += InstSize[opcode]; } } -- 2.30.2