From: Brian Paul Date: Tue, 30 Mar 2004 15:55:10 +0000 (+0000) Subject: Reorder some code so we don't upset program state when there's a parsing error. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a7f52a9ba1175174efb98a145248da331c9d4c54;p=mesa.git Reorder some code so we don't upset program state when there's a parsing error. Be sure to assign program.Base.String pointer. --- diff --git a/src/mesa/shader/arbfragparse.c b/src/mesa/shader/arbfragparse.c index d876946a251..7192156463e 100644 --- a/src/mesa/shader/arbfragparse.c +++ b/src/mesa/shader/arbfragparse.c @@ -192,9 +192,19 @@ _mesa_parse_arb_fragment_program(GLcontext * ctx, GLenum target, retval = _mesa_parse_arb_program(ctx, str, len, &ap); + /* XXX: Parse error. Cleanup things and return */ + if (retval) + { + program->Instructions = (struct fp_instruction *) _mesa_malloc ( + sizeof(struct fp_instruction) ); + program->Instructions[0].Opcode = FP_OPCODE_END; + return; + } + /* copy the relvant contents of the arb_program struct into the * fragment_program struct */ + program->Base.String = ap.Base.String; program->Base.NumInstructions = ap.Base.NumInstructions; program->Base.NumTemporaries = ap.Base.NumTemporaries; program->Base.NumParameters = ap.Base.NumParameters; @@ -211,15 +221,6 @@ _mesa_parse_arb_fragment_program(GLcontext * ctx, GLenum target, program->Parameters = ap.Parameters; program->FogOption = ap.FogOption; - /* XXX: Parse error. Cleanup things and return */ - if (retval) - { - program->Instructions = (struct fp_instruction *) _mesa_malloc ( - sizeof(struct fp_instruction) ); - program->Instructions[0].Opcode = FP_OPCODE_END; - return; - } - /* XXX: Eh.. we parsed something that wasn't a fragment program. doh! */ /* this wont happen any more */ /* diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c index c2365a281c1..9099fd8f42c 100644 --- a/src/mesa/shader/arbprogparse.c +++ b/src/mesa/shader/arbprogparse.c @@ -3872,11 +3872,9 @@ _mesa_parse_arb_program (GLcontext * ctx, const GLubyte * str, GLsizei len, #endif err = grammar_check (arbprogram_syn_id, strz, &parsed, &parsed_len); - _mesa_free (strz); - strz = NULL; - /* Syntax parse error */ if (err == 0) { + _mesa_free (strz); grammar_get_last_error ((GLubyte *) error_msg, 300, &error_pos); _mesa_set_program_error (ctx, error_pos, error_msg); _mesa_error (ctx, GL_INVALID_OPERATION, "Parse Error"); @@ -3891,6 +3889,7 @@ _mesa_parse_arb_program (GLcontext * ctx, const GLubyte * str, GLsizei len, grammar_destroy (arbprogram_syn_id); /* Initialize the arb_program struct */ + program->Base.String = strz; program->Base.NumInstructions = program->Base.NumTemporaries = program->Base.NumParameters = diff --git a/src/mesa/shader/arbvertparse.c b/src/mesa/shader/arbvertparse.c index 5f011106ef5..cfad87b5b1b 100644 --- a/src/mesa/shader/arbvertparse.c +++ b/src/mesa/shader/arbvertparse.c @@ -181,9 +181,19 @@ _mesa_parse_arb_vertex_program(GLcontext * ctx, GLenum target, retval = _mesa_parse_arb_program(ctx, str, len, &ap); + /* Parse error. Allocate a dummy program and return */ + if (retval) + { + program->Instructions = (struct vp_instruction *) _mesa_malloc ( + sizeof(struct vp_instruction) ); + program->Instructions[0].Opcode = VP_OPCODE_END; + return; + } + /* copy the relvant contents of the arb_program struct into the * fragment_program struct */ + program->Base.String = ap.Base.String; program->Base.NumInstructions = ap.Base.NumInstructions; program->Base.NumTemporaries = ap.Base.NumTemporaries; program->Base.NumParameters = ap.Base.NumParameters; @@ -195,15 +205,6 @@ _mesa_parse_arb_vertex_program(GLcontext * ctx, GLenum target, program->OutputsWritten = ap.OutputsWritten; program->Parameters = ap.Parameters; - /* Parse error. Allocate a dummy program and return */ - if (retval) - { - program->Instructions = (struct vp_instruction *) _mesa_malloc ( - sizeof(struct vp_instruction) ); - program->Instructions[0].Opcode = VP_OPCODE_END; - return; - } - /* Eh.. we parsed something that wasn't a vertex program. doh! */ /* this wont happen any more */ /*