Reorder some code so we don't upset program state when there's a parsing error.

Be sure to assign program.Base.String pointer.
This commit is contained in:
Brian Paul 2004-03-30 15:55:10 +00:00
parent 41d389909b
commit a7f52a9ba1
3 changed files with 22 additions and 21 deletions

View file

@ -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 */
/*

View file

@ -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 =

View file

@ -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 */
/*