So that it acts like ordinary free(). This lets us remove a bunch of if statements where the function is called. v2: - Avoiding compile error on MSVC and possible warnings on other compilers. - Added comment regards passing NULL pointer being safe. Reviewed-by: Brian Paul <brianp@vmware.com>tags/mesa-10.1-rc1
| @@ -168,6 +168,8 @@ _mesa_align_calloc(size_t bytes, unsigned long alignment) | |||
| * \param ptr pointer to the memory to be freed. | |||
| * The actual address to free is stored in the word immediately before the | |||
| * address the client sees. | |||
| * Note that it is legal to pass NULL pointer to this function and will be | |||
| * handled accordingly. | |||
| */ | |||
| void | |||
| _mesa_align_free(void *ptr) | |||
| @@ -177,9 +179,11 @@ _mesa_align_free(void *ptr) | |||
| #elif defined(_WIN32) && defined(_MSC_VER) | |||
| _aligned_free(ptr); | |||
| #else | |||
| void **cubbyHole = (void **) ((char *) ptr - sizeof(void *)); | |||
| void *realAddr = *cubbyHole; | |||
| free(realAddr); | |||
| if (ptr) { | |||
| void **cubbyHole = (void **) ((char *) ptr - sizeof(void *)); | |||
| void *realAddr = *cubbyHole; | |||
| free(realAddr); | |||
| } | |||
| #endif /* defined(HAVE_POSIX_MEMALIGN) */ | |||
| } | |||
| @@ -199,8 +203,8 @@ _mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize, | |||
| if (newBuf && oldBuffer && copySize > 0) { | |||
| memcpy(newBuf, oldBuffer, copySize); | |||
| } | |||
| if (oldBuffer) | |||
| _mesa_align_free(oldBuffer); | |||
| _mesa_align_free(oldBuffer); | |||
| return newBuf; | |||
| #endif | |||
| } | |||
| @@ -1488,14 +1488,11 @@ _math_matrix_ctr( GLmatrix *m ) | |||
| void | |||
| _math_matrix_dtr( GLmatrix *m ) | |||
| { | |||
| if (m->m) { | |||
| _mesa_align_free( m->m ); | |||
| m->m = NULL; | |||
| } | |||
| if (m->inv) { | |||
| _mesa_align_free( m->inv ); | |||
| m->inv = NULL; | |||
| } | |||
| _mesa_align_free( m->m ); | |||
| m->m = NULL; | |||
| _mesa_align_free( m->inv ); | |||
| m->inv = NULL; | |||
| } | |||
| /*@}*/ | |||
| @@ -83,8 +83,7 @@ _mesa_free_parameter_list(struct gl_program_parameter_list *paramList) | |||
| free((void *)paramList->Parameters[i].Name); | |||
| } | |||
| free(paramList->Parameters); | |||
| if (paramList->ParameterValues) | |||
| _mesa_align_free(paramList->ParameterValues); | |||
| _mesa_align_free(paramList->ParameterValues); | |||
| free(paramList); | |||
| } | |||
| @@ -175,10 +175,8 @@ st_FreeTextureImageBuffer(struct gl_context *ctx, | |||
| pipe_resource_reference(&stImage->pt, NULL); | |||
| } | |||
| if (stImage->TexData) { | |||
| _mesa_align_free(stImage->TexData); | |||
| stImage->TexData = NULL; | |||
| } | |||
| _mesa_align_free(stImage->TexData); | |||
| stImage->TexData = NULL; | |||
| } | |||
| @@ -164,10 +164,9 @@ _swrast_free_texture_image_buffer(struct gl_context *ctx, | |||
| struct gl_texture_image *texImage) | |||
| { | |||
| struct swrast_texture_image *swImage = swrast_texture_image(texImage); | |||
| if (swImage->Buffer) { | |||
| _mesa_align_free(swImage->Buffer); | |||
| swImage->Buffer = NULL; | |||
| } | |||
| _mesa_align_free(swImage->Buffer); | |||
| swImage->Buffer = NULL; | |||
| free(swImage->ImageSlices); | |||
| swImage->ImageSlices = NULL; | |||
| @@ -546,10 +546,8 @@ void _tnl_free_vertices( struct gl_context *ctx ) | |||
| struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx); | |||
| struct tnl_clipspace_fastpath *fp, *tmp; | |||
| if (vtx->vertex_buf) { | |||
| _mesa_align_free(vtx->vertex_buf); | |||
| vtx->vertex_buf = NULL; | |||
| } | |||
| _mesa_align_free(vtx->vertex_buf); | |||
| vtx->vertex_buf = NULL; | |||
| for (fp = vtx->fastpath ; fp ; fp = tmp) { | |||
| tmp = fp->next; | |||
| @@ -990,11 +990,10 @@ void vbo_use_buffer_objects(struct gl_context *ctx) | |||
| /* Make sure this func is only used once */ | |||
| assert(exec->vtx.bufferobj == ctx->Shared->NullBufferObj); | |||
| if (exec->vtx.buffer_map) { | |||
| _mesa_align_free(exec->vtx.buffer_map); | |||
| exec->vtx.buffer_map = NULL; | |||
| exec->vtx.buffer_ptr = NULL; | |||
| } | |||
| _mesa_align_free(exec->vtx.buffer_map); | |||
| exec->vtx.buffer_map = NULL; | |||
| exec->vtx.buffer_ptr = NULL; | |||
| /* Allocate a real buffer object now */ | |||
| _mesa_reference_buffer_object(ctx, &exec->vtx.bufferobj, NULL); | |||