[Mesa-dev] [PATCH 3/4] replace reallocs with MACRO
marvin24 at gmx.de
marvin24 at gmx.de
Sat Jun 12 13:13:34 PDT 2010
---
src/mesa/drivers/dri/r600/r600_cmdbuf.c | 8 ++++----
src/mesa/drivers/dri/r600/r700_assembler.c | 23 ++++++++---------------
src/mesa/drivers/dri/radeon/radeon_bo_legacy.c | 2 +-
src/mesa/drivers/dri/radeon/radeon_cs_legacy.c | 6 +++---
src/mesa/drivers/dri/radeon/radeon_debug.h | 9 +++++++++
src/mesa/main/imports.h | 2 ++
6 files changed, 27 insertions(+), 23 deletions(-)
diff --git a/src/mesa/drivers/dri/r600/r600_cmdbuf.c b/src/mesa/drivers/dri/r600/r600_cmdbuf.c
index d2b59ab..1f0f185 100644
--- a/src/mesa/drivers/dri/r600/r600_cmdbuf.c
+++ b/src/mesa/drivers/dri/r600/r600_cmdbuf.c
@@ -137,9 +137,9 @@ static int r600_cs_write_reloc(struct radeon_cs_int *csi,
relocs[i].base.write_domain |= write_domain;
/* save indice */
relocs[i].cindices++;
- indices = (uint32_t*)realloc(relocs[i].indices,
+ indices = (uint32_t*)REALLOC(relocs[i].indices,
relocs[i].cindices * 4);
- reloc_indices = (uint32_t*)realloc(relocs[i].reloc_indices,
+ reloc_indices = (uint32_t*)REALLOC(relocs[i].reloc_indices,
relocs[i].cindices * 4);
if ( (indices == NULL) || (reloc_indices == NULL) ) {
relocs[i].cindices -= 1;
@@ -157,7 +157,7 @@ static int r600_cs_write_reloc(struct radeon_cs_int *csi,
}
/* add bo to reloc */
relocs = (struct r600_cs_reloc_legacy*)
- realloc(csi->relocs,
+ REALLOC(csi->relocs,
sizeof(struct r600_cs_reloc_legacy) * (csi->crelocs + 1));
if (relocs == NULL) {
return -ENOMEM;
@@ -212,7 +212,7 @@ static int r600_cs_begin(struct radeon_cs_int *csi,
int num = (ndw > 0x400) ? ndw : 0x400;
tmp = (csi->cdw + num + 0x3FF) & (~0x3FF);
- ptr = (uint32_t*)realloc(csi->packets, 4 * tmp);
+ ptr = (uint32_t*)REALLOC(csi->packets, 4 * tmp);
if (ptr == NULL) {
return -ENOMEM;
}
diff --git a/src/mesa/drivers/dri/r600/r700_assembler.c b/src/mesa/drivers/dri/r600/r700_assembler.c
index 7b4d478..70f263d 100644
--- a/src/mesa/drivers/dri/r600/r700_assembler.c
+++ b/src/mesa/drivers/dri/r600/r700_assembler.c
@@ -4801,9 +4801,8 @@ GLboolean assemble_ELSE(r700_AssemblerBase *pAsm)
pAsm->cf_current_cf_clause_ptr->m_Word1.f.barrier = 0x1;
- pAsm->fc_stack[pAsm->FCSP].mid = (R700ControlFlowGenericClause **)_mesa_realloc( (void *)pAsm->fc_stack[pAsm->FCSP].mid,
- 0,
- sizeof(R700ControlFlowGenericClause *) );
+ pAsm->fc_stack[pAsm->FCSP].mid = (R700ControlFlowGenericClause **)REALLOC( (void *)pAsm->fc_stack[pAsm->FCSP].mid,
+ sizeof(R700ControlFlowGenericClause *) );
pAsm->fc_stack[pAsm->FCSP].mid[0] = pAsm->cf_current_cf_clause_ptr;
//pAsm->fc_stack[pAsm->FCSP].unNumMid = 1;
@@ -4923,9 +4922,8 @@ GLboolean assemble_BRK(r700_AssemblerBase *pAsm)
pAsm->cf_current_cf_clause_ptr->m_Word1.f.barrier = 0x1;
- pAsm->fc_stack[unFCSP].mid = (R700ControlFlowGenericClause **)_mesa_realloc(
+ pAsm->fc_stack[unFCSP].mid = (R700ControlFlowGenericClause **)REALLOC(
(void *)pAsm->fc_stack[unFCSP].mid,
- sizeof(R700ControlFlowGenericClause *) * pAsm->fc_stack[unFCSP].unNumMid,
sizeof(R700ControlFlowGenericClause *) * (pAsm->fc_stack[unFCSP].unNumMid + 1) );
pAsm->fc_stack[unFCSP].mid[pAsm->fc_stack[unFCSP].unNumMid] = pAsm->cf_current_cf_clause_ptr;
pAsm->fc_stack[unFCSP].unNumMid++;
@@ -4993,9 +4991,8 @@ GLboolean assemble_CONT(r700_AssemblerBase *pAsm)
pAsm->cf_current_cf_clause_ptr->m_Word1.f.barrier = 0x1;
- pAsm->fc_stack[unFCSP].mid = (R700ControlFlowGenericClause **)_mesa_realloc(
+ pAsm->fc_stack[unFCSP].mid = (R700ControlFlowGenericClause **)REALLOC(
(void *)pAsm->fc_stack[unFCSP].mid,
- sizeof(R700ControlFlowGenericClause *) * pAsm->fc_stack[unFCSP].unNumMid,
sizeof(R700ControlFlowGenericClause *) * (pAsm->fc_stack[unFCSP].unNumMid + 1) );
pAsm->fc_stack[unFCSP].mid[pAsm->fc_stack[unFCSP].unNumMid] = pAsm->cf_current_cf_clause_ptr;
pAsm->fc_stack[unFCSP].unNumMid++;
@@ -5124,8 +5121,7 @@ GLboolean assemble_BGNSUB(r700_AssemblerBase *pAsm, GLint nILindex, GLuint uiIL_
/* Put in sub */
if( (pAsm->unSubArrayPointer + 1) > pAsm->unSubArraySize )
{
- pAsm->subs = (SUB_OFFSET*)_mesa_realloc( (void *)pAsm->subs,
- sizeof(SUB_OFFSET) * pAsm->unSubArraySize,
+ pAsm->subs = (SUB_OFFSET*)REALLOC( (void *)pAsm->subs,
sizeof(SUB_OFFSET) * (pAsm->unSubArraySize + 10) );
if(NULL == pAsm->subs)
{
@@ -5254,8 +5250,7 @@ GLboolean assemble_CAL(r700_AssemblerBase *pAsm,
/* Put in caller */
if( (pAsm->unCallerArrayPointer + 1) > pAsm->unCallerArraySize )
{
- pAsm->callers = (CALLER_POINTER*)_mesa_realloc( (void *)pAsm->callers,
- sizeof(CALLER_POINTER) * pAsm->unCallerArraySize,
+ pAsm->callers = (CALLER_POINTER*)REALLOC( (void *)pAsm->callers,
sizeof(CALLER_POINTER) * (pAsm->unCallerArraySize + 10) );
if(NULL == pAsm->callers)
{
@@ -5461,9 +5456,8 @@ GLboolean breakLoopOnFlag(r700_AssemblerBase *pAsm, GLuint unFCSP)
pAsm->cf_current_cf_clause_ptr->m_Word1.f.barrier = 0x1;
- pAsm->fc_stack[unFCSP].mid = (R700ControlFlowGenericClause **)_mesa_realloc(
+ pAsm->fc_stack[unFCSP].mid = (R700ControlFlowGenericClause **)REALLOC(
(void *)pAsm->fc_stack[unFCSP].mid,
- sizeof(R700ControlFlowGenericClause *) * pAsm->fc_stack[unFCSP].unNumMid,
sizeof(R700ControlFlowGenericClause *) * (pAsm->fc_stack[unFCSP].unNumMid + 1) );
pAsm->fc_stack[unFCSP].mid[pAsm->fc_stack[unFCSP].unNumMid] = pAsm->cf_current_cf_clause_ptr;
pAsm->fc_stack[unFCSP].unNumMid++;
@@ -6185,8 +6179,7 @@ GLboolean callPreSub(r700_AssemblerBase* pAsm,
/* alloc in presub */
if( (pAsm->unNumPresub + 1) > pAsm->unPresubArraySize )
{
- pAsm->presubs = (PRESUB_DESC*)_mesa_realloc( (void *)pAsm->presubs,
- sizeof(PRESUB_DESC) * pAsm->unPresubArraySize,
+ pAsm->presubs = (PRESUB_DESC*)REALLOC( (void *)pAsm->presubs,
sizeof(PRESUB_DESC) * (pAsm->unPresubArraySize + 4) );
if(NULL == pAsm->presubs)
{
diff --git a/src/mesa/drivers/dri/radeon/radeon_bo_legacy.c b/src/mesa/drivers/dri/radeon/radeon_bo_legacy.c
index 02eff1c..c57acce 100644
--- a/src/mesa/drivers/dri/radeon/radeon_bo_legacy.c
+++ b/src/mesa/drivers/dri/radeon/radeon_bo_legacy.c
@@ -158,7 +158,7 @@ static int legacy_free_handle(struct bo_manager_legacy *bom, uint32_t handle)
return 0;
}
bom->nfree_handles += 0x100;
- handles = (uint32_t*)realloc(bom->free_handles, bom->nfree_handles * 4);
+ handles = (uint32_t*)REALLOC(bom->free_handles, bom->nfree_handles * 4);
if (handles == NULL) {
bom->nfree_handles -= 0x100;
return -ENOMEM;
diff --git a/src/mesa/drivers/dri/radeon/radeon_cs_legacy.c b/src/mesa/drivers/dri/radeon/radeon_cs_legacy.c
index d6f535b..b257c8a 100644
--- a/src/mesa/drivers/dri/radeon/radeon_cs_legacy.c
+++ b/src/mesa/drivers/dri/radeon/radeon_cs_legacy.c
@@ -123,7 +123,7 @@ static int cs_write_reloc(struct radeon_cs_int *cs,
relocs[i].base.write_domain |= write_domain;
/* save indice */
relocs[i].cindices++;
- indices = (uint32_t*)realloc(relocs[i].indices,
+ indices = (uint32_t*)REALLOC(relocs[i].indices,
relocs[i].cindices * 4);
if (indices == NULL) {
relocs[i].cindices -= 1;
@@ -136,7 +136,7 @@ static int cs_write_reloc(struct radeon_cs_int *cs,
}
/* add bo to reloc */
relocs = (struct cs_reloc_legacy*)
- realloc(cs->relocs,
+ REALLOC(cs->relocs,
sizeof(struct cs_reloc_legacy) * (cs->crelocs + 1));
if (relocs == NULL) {
return -ENOMEM;
@@ -182,7 +182,7 @@ static int cs_begin(struct radeon_cs_int *cs,
uint32_t tmp, *ptr;
tmp = (cs->cdw + ndw + 0x3ff) & (~0x3ff);
- ptr = (uint32_t*)realloc(cs->packets, 4 * tmp);
+ ptr = (uint32_t*)REALLOC(cs->packets, 4 * tmp);
if (ptr == NULL) {
return -ENOMEM;
}
diff --git a/src/mesa/drivers/dri/radeon/radeon_debug.h b/src/mesa/drivers/dri/radeon/radeon_debug.h
index 7de54d2..e5cb5ec 100644
--- a/src/mesa/drivers/dri/radeon/radeon_debug.h
+++ b/src/mesa/drivers/dri/radeon/radeon_debug.h
@@ -204,16 +204,25 @@ static inline void *myc(size_t T, const char *fi, const char *fu, unsigned l)
return a;
}
+static inline void *myrea(void *p, size_t T, const char *fi, const char *fu, unsigned l)
+{
+ void *a = realloc(p, T);
+ radeon_error("realloc of %zu bytes in %p (%s@%s:%d)\n", T, p, fu, fi, l);
+ return a;
+}
+
#undef CALLOC_STRUCT
#undef CALLOC
#undef MALLOC
#undef MALLOC_STRUCT
+#undef REALLOC
#undef FREE
#define CALLOC_STRUCT(T) mycs(sizeof(struct T), __FILE__, __func__, __LINE__)
#define MALLOC_STRUCT(T) myms(sizeof(struct T), __FILE__, __func__, __LINE__)
#define CALLOC(BYTES) myc(BYTES, __FILE__, __func__, __LINE__)
#define MALLOC(BYTES) mym(BYTES, __FILE__, __func__, __LINE__)
+#define REALLOC(PTR, BYTES) myrea(PTR, BYTES, __FILE__, __func__, __LINE__)
#define FREE(PTR) \
do { \
radeon_error("free of %p in %s@%s:%d\n", PTR, __func__, __FILE__, __LINE__); \
diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h
index da825a0..c98e323 100644
--- a/src/mesa/main/imports.h
+++ b/src/mesa/main/imports.h
@@ -57,6 +57,8 @@ extern "C" {
#define MALLOC_STRUCT(T) (struct T *) malloc(sizeof(struct T))
/** Allocate and zero a structure of type \p T */
#define CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
+/** Reallocate memory */
+#define REALLOC(PTR, BYTES) realloc(PTR, BYTES)
/** Free memory */
#define FREE(PTR) free(PTR)
--
1.7.0.4
More information about the mesa-dev
mailing list