r300: Use _mesa_alloc_instructions/_mesa_init_instructions instead of malloc.
authorOliver McFadden <z3ro.geek@gmail.com>
Thu, 15 Mar 2007 19:49:10 +0000 (19:49 +0000)
committerOliver McFadden <z3ro.geek@gmail.com>
Thu, 15 Mar 2007 19:49:10 +0000 (19:49 +0000)
Note that insert_wpos in r300_vertexprog.c is still a little flaky and could be
improved.

src/mesa/drivers/dri/r300/r300_fragprog.c
src/mesa/drivers/dri/r300/r300_vertexprog.c

index 82fb5b66ed27f3e08848e3e3ea17dcd637e95c03..e05abdb7c6108836d7201de3ebe62ab34f9a87e7 100644 (file)
@@ -1798,12 +1798,8 @@ static void insert_wpos(struct gl_program *prog)
        /* should do something else if no temps left... */
        prog->NumTemporaries++;
 
-       
-       fpi = malloc((prog->NumInstructions + 3) * sizeof(struct prog_instruction));
-       /* all including END */
-       memcpy(&fpi[3], prog->Instructions, prog->NumInstructions * sizeof(struct prog_instruction));
-       
-       memset(fpi, 0, 3 * sizeof(struct prog_instruction));
+       fpi = _mesa_alloc_instructions (prog->NumInstructions + 3);
+       _mesa_init_instructions (fpi, prog->NumInstructions + 3);
 
        /* perspective divide */
        fpi[i].Opcode = OPCODE_RCP;
@@ -1857,6 +1853,8 @@ static void insert_wpos(struct gl_program *prog)
        fpi[i].SrcReg[2].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ZERO);
        i++;
 
+       _mesa_memcpy(&fpi[i], prog->Instructions, prog->NumInstructions * sizeof(struct prog_instruction));
+
        free(prog->Instructions);
 
        prog->Instructions = fpi;
index 9257ff44e3e36dc0a24f59cf1fbc2d6ad1f89693..0c43270d757eff3acff36e0ad985d71d578192c1 100644 (file)
@@ -889,8 +889,8 @@ static void position_invariant(struct gl_program *prog)
 #endif
        paramList = prog->Parameters;
 
-       vpi = malloc((prog->NumInstructions + 4) * sizeof(struct prog_instruction));
-       memset(vpi, 0, 4 * sizeof(struct prog_instruction));
+       vpi = _mesa_alloc_instructions (prog->NumInstructions + 4);
+       _mesa_init_instructions (vpi, prog->NumInstructions + 4);
 
        for (i=0; i < 4; i++) {
                GLint idx;
@@ -946,7 +946,7 @@ static void position_invariant(struct gl_program *prog)
 #endif                                 
        }
 
-       memcpy(&vpi[i], prog->Instructions, prog->NumInstructions * sizeof(struct prog_instruction));
+       _mesa_memcpy(&vpi[i], prog->Instructions, prog->NumInstructions * sizeof(struct prog_instruction));
 
        free(prog->Instructions);
 
@@ -966,15 +966,14 @@ static void insert_wpos(struct r300_vertex_program *vp,
        struct prog_instruction *vpi_insert;
        int i = 0;
        
-       vpi = malloc((prog->NumInstructions + 2) * sizeof(struct prog_instruction));
+       vpi = _mesa_alloc_instructions (prog->NumInstructions + 2);
+       _mesa_init_instructions (vpi, prog->NumInstructions + 2);
        /* all but END */
-       memcpy(vpi, prog->Instructions, (prog->NumInstructions - 1) * sizeof(struct prog_instruction));
+       _mesa_memcpy(vpi, prog->Instructions, (prog->NumInstructions - 1) * sizeof(struct prog_instruction));
        /* END */
-       memcpy(&vpi[prog->NumInstructions + 1], &prog->Instructions[prog->NumInstructions - 1],
+       _mesa_memcpy(&vpi[prog->NumInstructions + 1], &prog->Instructions[prog->NumInstructions - 1],
                sizeof(struct prog_instruction));
-       
        vpi_insert = &vpi[prog->NumInstructions - 1];
-       memset(vpi_insert, 0, 2 * sizeof(struct prog_instruction));
 
        vpi_insert[i].Opcode = OPCODE_MOV;