(PS3) (GCM GL) Use calloc when we need to memset directly after

This commit is contained in:
twinaphex 2014-10-17 01:10:39 +02:00
parent 3b3b990796
commit 5a93f90c46
2 changed files with 18 additions and 32 deletions

View File

@ -141,8 +141,7 @@ static void rglTexNameSpaceInit(void *data,
rglTexNameSpace *ns = (rglTexNameSpace*)data;
ns->capacity = CAPACITY_INCREMENT;
ns->data = (void **)malloc( ns->capacity * sizeof( void* ) );
memset( ns->data, 0, ns->capacity*sizeof( void* ) );
ns->data = (void **)calloc(ns->capacity, sizeof(void*));
ns->create = create;
ns->destroy = destroy;
}
@ -264,13 +263,11 @@ static GmmFixedAllocData *pGmmFixedAllocData = NULL;
static uint32_t gmmInitFixedAllocator(void)
{
pGmmFixedAllocData = (GmmFixedAllocData *)malloc(sizeof(GmmFixedAllocData));
pGmmFixedAllocData = (GmmFixedAllocData *)calloc(1, sizeof(GmmFixedAllocData));
if (!pGmmFixedAllocData)
return GMM_ERROR;
memset(pGmmFixedAllocData, 0, sizeof(GmmFixedAllocData));
for (int i=0; i<2; i++)
{
int blockCount = (i==0) ? GMM_BLOCK_COUNT : GMM_TILE_BLOCK_COUNT;
@ -424,12 +421,7 @@ static uint32_t gmmInit(const void *localMemoryBase, const void *localStartAddre
alignedLocalSize = localEndAddress - (uint32_t)localStartAddress;
pAllocator = (GmmAllocator *)malloc(sizeof(GmmAllocator));
if (!pAllocator)
return GMM_ERROR;
memset(pAllocator, 0, sizeof(GmmAllocator));
pAllocator = (GmmAllocator *)calloc(1, sizeof(GmmAllocator));
if (!pAllocator)
return GMM_ERROR;
@ -1683,13 +1675,13 @@ RGL_EXPORT RGLdevice* rglPlatformCreateDeviceAuto( GLenum colorFormat, GLenum de
RGL_EXPORT RGLdevice* rglPlatformCreateDeviceExtended (const void *data)
{
RGLdeviceParameters *parameters = (RGLdeviceParameters*)data;
RGLdevice *device = (RGLdevice*)malloc( sizeof( RGLdevice ) + sizeof( rglGcmDevice ) );
RGLdevice *device = (RGLdevice*)calloc(1, sizeof( RGLdevice ) + sizeof( rglGcmDevice ) );
if ( !device )
{
rglSetError( GL_OUT_OF_MEMORY );
return NULL;
}
memset( device, 0, sizeof( RGLdevice ) + sizeof(rglGcmDevice) );
// initialize fields
memcpy( &device->deviceParameters, parameters, sizeof( RGLdeviceParameters ) );
@ -2841,12 +2833,11 @@ GLAPI void RGL_EXPORT psglSwap (void)
static rglBufferObject *rglCreateBufferObject (void)
{
GLuint size = sizeof( rglBufferObject ) + sizeof(rglGcmBufferObject);
rglBufferObject *buffer = (rglBufferObject*)malloc(size);
rglBufferObject *buffer = (rglBufferObject*)calloc(1, size);
if(!buffer )
return NULL;
memset(buffer, 0, size);
buffer->refCount = 1;
new( &buffer->textureReferences ) RGL::Vector<rglTexture *>();
@ -3653,8 +3644,7 @@ static void rglResetContext (void *data)
static rglTexture *rglAllocateTexture(void)
{
rglTexture *texture = (rglTexture*)malloc(sizeof(rglTexture) + sizeof(rglGcmTexture));
memset( texture, 0, sizeof(rglTexture) + sizeof(rglGcmTexture));
rglTexture *texture = (rglTexture*)calloc(1, sizeof(rglTexture) + sizeof(rglGcmTexture));
texture->target = 0;
texture->minFilter = GL_NEAREST_MIPMAP_LINEAR;
texture->magFilter = GL_LINEAR;
@ -3701,13 +3691,11 @@ static void rglFreeTexture (void *data)
RGLcontext* psglCreateContext(void)
{
RGLcontext* LContext = (RGLcontext*)malloc(sizeof(RGLcontext));
RGLcontext* LContext = (RGLcontext*)calloc(1, sizeof(RGLcontext));
if (!LContext)
return NULL;
memset(LContext, 0, sizeof(RGLcontext));
LContext->error = GL_NO_ERROR;
rglTexNameSpaceInit( &LContext->textureNameSpace, ( rglTexNameSpaceCreateFunction )rglAllocateTexture, ( rglTexNameSpaceDestroyFunction )rglFreeTexture );
@ -4418,8 +4406,10 @@ void RGL_EXPORT psglMakeCurrent (RGLcontext *context, RGLdevice *device)
rglGcmSetInvalidateVertexCache(thisContext);
rglGcmFifoFinish(fifo, ref, offset_bytes);
rglGcmDriver *driver = (rglGcmDriver*)malloc(sizeof(rglGcmDriver));
memset(driver, 0, sizeof(rglGcmDriver));
rglGcmDriver *driver = (rglGcmDriver*)calloc(1, sizeof(rglGcmDriver));
if (!driver)
return;
driver->rt.yInverted = true;
driver->invalidateVertexCache = GL_FALSE;

View File

@ -1346,15 +1346,14 @@ CG_API CGcontext cgCreateContext( void )
{
// create a context out of thin air and add it to the hidden global list.
_CGcontext* ptr = (_CGcontext*)malloc(sizeof(_CGcontext));
if ( NULL == ptr )
_CGcontext* ptr = (_CGcontext*)calloc(1, sizeof(_CGcontext));
if (!ptr)
{
rglCgRaiseError( CG_MEMORY_ALLOC_ERROR );
return ( CGcontext )NULL;
}
// initialise member variables
memset(ptr, 0, sizeof( *ptr));
ptr->compileType = CG_UNKNOWN;
// get a new id for the object
@ -2768,16 +2767,13 @@ CGprogram rglCgCreateProgram( CGcontext ctx, CGprofile profile, const CgProgramH
// as well as the profile.
// The parameters and the actual program are generated from the ABI specific calls.
_CGprogram* prog = ( _CGprogram* )malloc( sizeof( _CGprogram ) );
if ( NULL == prog )
_CGprogram* prog = ( _CGprogram* )calloc(1, sizeof( _CGprogram));
if (!prog)
{
rglCgRaiseError( CG_MEMORY_ALLOC_ERROR );
return NULL;
}
// zero out the fields
memset( prog, 0, sizeof( _CGprogram ) );
// fill in the fields we know
prog->parentContext = _cgGetContextPtr( ctx );
prog->header.profile = profile;
@ -3208,7 +3204,7 @@ CG_API CGprogram cgCopyProgram( CGprogram program )
newprog = ( _CGprogram* )malloc( sizeof( _CGprogram ) );
}
if ( NULL == newprog )
if (!newprog)
{
rglCgRaiseError( CG_MEMORY_ALLOC_ERROR );
return ( CGprogram )NULL;