[PATCH 07/16] dmx: __glXMalloc -> malloc, etc.

Alex Deucher alexdeucher at gmail.com
Tue May 25 22:20:43 PDT 2010


On Tue, May 25, 2010 at 7:53 PM, Jamey Sharp <jamey at minilop.net> wrote:
> Kristian made equivalent edits to the reference GLX implementation in
> 2006, with commit 2d2d38d17cc2558f8a41166a4a1578bc4c663c37.
>
> Signed-off-by: Jamey Sharp <jamey at minilop.net>
> ---
>  hw/dmx/glxProxy/glxcmds.c     |   50 +++++++++++++-------------
>  hw/dmx/glxProxy/glxcmdsswap.c |    4 +-
>  hw/dmx/glxProxy/glxext.c      |   36 +++++++++---------
>  hw/dmx/glxProxy/glxutil.c     |   77 -----------------------------------------
>  hw/dmx/glxProxy/glxutil.h     |    6 ---
>  5 files changed, 45 insertions(+), 128 deletions(-)
>
> diff --git a/hw/dmx/glxProxy/glxcmds.c b/hw/dmx/glxProxy/glxcmds.c
> index d9b884a..fbd1c03 100644
> --- a/hw/dmx/glxProxy/glxcmds.c
> +++ b/hw/dmx/glxProxy/glxcmds.c
> @@ -144,7 +144,7 @@ static int CreateContext(__GLXclientState *cl,
>     /*
>     ** Allocate memory for the new context
>     */
> -    glxc = __glXCalloc(1, sizeof(__GLXcontext));
> +    glxc = calloc(1, sizeof(__GLXcontext));
>     if (!glxc) {
>        return BadAlloc;
>     }
> @@ -156,7 +156,7 @@ static int CreateContext(__GLXclientState *cl,
>        glxc->pFBConfig = glxLookupFBConfig( fbconfigId );
>        if (!glxc->pFBConfig) {
>          client->errorValue = fbconfigId;
> -         __glXFree( glxc );
> +         free( glxc );
>          return BadValue;
>        }
>        visual = glxc->pFBConfig->associatedVisualId;
> @@ -177,7 +177,7 @@ static int CreateContext(__GLXclientState *cl,
>        }
>        if (i == pScreen->numVisuals) {
>          client->errorValue = visual;
> -         __glXFree( glxc );
> +         free( glxc );
>          return BadValue;
>        }
>
> @@ -192,7 +192,7 @@ static int CreateContext(__GLXclientState *cl,
>           ** Visual not support on this screen by this OpenGL implementation.
>           */
>          client->errorValue = visual;
> -         __glXFree( glxc );
> +         free( glxc );
>          return BadValue;
>        }
>
> @@ -203,7 +203,7 @@ static int CreateContext(__GLXclientState *cl,
>              /*
>                * visual does not have an FBConfig ???
>              client->errorValue = visual;
> -             __glXFree( glxc );
> +             free( glxc );
>              return BadValue;
>               */
>           }
> @@ -223,11 +223,11 @@ static int CreateContext(__GLXclientState *cl,
>      * allocate memory for back-end servers info
>      */
>     num_be_screens = to_screen - from_screen + 1;
> -    glxc->real_ids = (XID *)__glXMalloc(sizeof(XID) * num_be_screens);
> +    glxc->real_ids = (XID *)malloc(sizeof(XID) * num_be_screens);
>     if (!glxc->real_ids) {
>        return BadAlloc;
>     }
> -    glxc->real_vids = (XID *)__glXMalloc(sizeof(XID) * num_be_screens);
> +    glxc->real_vids = (XID *)malloc(sizeof(XID) * num_be_screens);
>     if (!glxc->real_vids) {
>        return BadAlloc;
>     }
> @@ -252,9 +252,9 @@ static int CreateContext(__GLXclientState *cl,
>
>          if (!be_vid) {
>             /* visual is not supported on the back-end server */
> -            __glXFree( glxc->real_ids );
> -            __glXFree( glxc->real_vids );
> -            __glXFree( glxc );
> +            free( glxc->real_ids );
> +            free( glxc->real_vids );
> +            free( glxc );
>             return BadValue;
>          }
>        }
> @@ -346,9 +346,9 @@ static int CreateContext(__GLXclientState *cl,
>     ** Register this context as a resource.
>     */
>     if (!AddResource(gcId, __glXContextRes, (pointer)glxc)) {
> -       __glXFree( glxc->real_ids );
> -       __glXFree( glxc->real_vids );
> -       __glXFree( glxc );
> +       free( glxc->real_ids );
> +       free( glxc->real_vids );
> +       free( glxc );
>        client->errorValue = gcId;
>        return BadAlloc;
>     }
> @@ -585,16 +585,16 @@ static int AddCurrentContext(__GLXclientState *cl, __GLXcontext *glxc, DrawableP
>     ** Didn't find a free slot, so we'll have to grow the table.
>     */
>     if (!num) {
> -       table = (__GLXcontext **) __glXMalloc(sizeof(__GLXcontext *));
> -       cl->currentDrawables = (DrawablePtr *) __glXMalloc(sizeof(DrawablePtr));
> -       cl->be_currentCTag = (GLXContextTag *) __glXMalloc(screenInfo.numScreens *sizeof(GLXContextTag));
> +       table = (__GLXcontext **) malloc(sizeof(__GLXcontext *));
> +       cl->currentDrawables = (DrawablePtr *) malloc(sizeof(DrawablePtr));
> +       cl->be_currentCTag = (GLXContextTag *) malloc(screenInfo.numScreens *sizeof(GLXContextTag));
>     } else {
> -       table = (__GLXcontext **) __glXRealloc(table,
> +       table = (__GLXcontext **) realloc(table,
>                                           (num+1)*sizeof(__GLXcontext *));
> -       cl->currentDrawables = (DrawablePtr *) __glXRealloc(
> +       cl->currentDrawables = (DrawablePtr *) realloc(
>                                                  cl->currentDrawables ,
>                                                  (num+1)*sizeof(DrawablePtr));
> -       cl->be_currentCTag = (GLXContextTag *) __glXRealloc(cl->be_currentCTag,
> +       cl->be_currentCTag = (GLXContextTag *) realloc(cl->be_currentCTag,
>                    (num+1)*screenInfo.numScreens*sizeof(GLXContextTag));
>     }
>     table[num] = glxc;
> @@ -1721,13 +1721,13 @@ static int CreateGLXPixmap(__GLXclientState *cl,
>        pGlxVisual = NULL;
>     }
>
> -    pGlxPixmap = (__GLXpixmap *) __glXMalloc(sizeof(__GLXpixmap));
> +    pGlxPixmap = (__GLXpixmap *) malloc(sizeof(__GLXpixmap));
>     if (!pGlxPixmap) {
>        return BadAlloc;
>     }
> -    pGlxPixmap->be_xids = (XID *) __glXMalloc(sizeof(XID) * screenInfo.numScreens);
> +    pGlxPixmap->be_xids = (XID *) malloc(sizeof(XID) * screenInfo.numScreens);
>     if (!pGlxPixmap->be_xids) {
> -        __glXFree( pGlxPixmap );
> +        free( pGlxPixmap );
>        return BadAlloc;
>     }
>
> @@ -1832,7 +1832,7 @@ static int CreateGLXPixmap(__GLXclientState *cl,
>        }
>        else {
>          client->errorValue = ( visual ? visual : fbconfigId );
> -          __glXFree( pGlxPixmap );
> +          free( pGlxPixmap );
>          return BadValue;
>        }
>
> @@ -1840,7 +1840,7 @@ static int CreateGLXPixmap(__GLXclientState *cl,
>     }
>
>     if (!(AddResource(glxpixmapId, __glXPixmapRes, pGlxPixmap))) {
> -        __glXFree( pGlxPixmap );
> +        free( pGlxPixmap );
>        return BadAlloc;
>     }
>
> @@ -2570,7 +2570,7 @@ int __glXClientInfo(__GLXclientState *cl, GLbyte *pc)
>
>     cl->GLClientmajorVersion = req->major;
>     cl->GLClientminorVersion = req->minor;
> -    if (cl->GLClientextensions) __glXFree(cl->GLClientextensions);
> +    if (cl->GLClientextensions) free(cl->GLClientextensions);
>     buf = (const char *)(req+1);
>     cl->GLClientextensions = strdup(buf);
>
> diff --git a/hw/dmx/glxProxy/glxcmdsswap.c b/hw/dmx/glxProxy/glxcmdsswap.c
> index b3720f6..6ab17a0 100644
> --- a/hw/dmx/glxProxy/glxcmdsswap.c
> +++ b/hw/dmx/glxProxy/glxcmdsswap.c
> @@ -695,9 +695,9 @@ int __glXSwapRenderLarge(__GLXclientState *cl, GLbyte *pc)
>        */
>        if (cl->largeCmdBufSize < hdr->length) {
>            if (!cl->largeCmdBuf) {
> -               cl->largeCmdBuf = (GLbyte *) __glXMalloc(hdr->length);
> +               cl->largeCmdBuf = (GLbyte *) malloc(hdr->length);
>            } else {
> -               cl->largeCmdBuf = (GLbyte *) __glXRealloc(cl->largeCmdBuf, hdr->length);
> +               cl->largeCmdBuf = (GLbyte *) realloc(cl->largeCmdBuf, hdr->length);
>            }
>            if (!cl->largeCmdBuf) {
>               cl->largeCmdRequestsTotal = 0;
> diff --git a/hw/dmx/glxProxy/glxext.c b/hw/dmx/glxProxy/glxext.c
> index 36a79ef..a8fc0a8 100644
> --- a/hw/dmx/glxProxy/glxext.c
> +++ b/hw/dmx/glxProxy/glxext.c
> @@ -77,10 +77,10 @@ static void ResetClientState(int clientIndex)
>     Display **keep_be_displays;
>     int i;
>
> -    if (cl->returnBuf) __glXFree(cl->returnBuf);
> -    if (cl->currentContexts) __glXFree(cl->currentContexts);
> -    if (cl->currentDrawables) __glXFree(cl->currentDrawables);
> -    if (cl->largeCmdBuf) __glXFree(cl->largeCmdBuf);
> +    if (cl->returnBuf) free(cl->returnBuf);
> +    if (cl->currentContexts) free(cl->currentContexts);
> +    if (cl->currentDrawables) free(cl->currentDrawables);
> +    if (cl->largeCmdBuf) free(cl->largeCmdBuf);
>
>     for (i=0; i< screenInfo.numScreens; i++) {
>        if (cl->be_displays[i])
> @@ -97,7 +97,7 @@ static void ResetClientState(int clientIndex)
>     */
>     cl->GLClientmajorVersion = 1;
>     cl->GLClientminorVersion = 0;
> -    if (cl->GLClientextensions) __glXFree(cl->GLClientextensions);
> +    if (cl->GLClientextensions) free(cl->GLClientextensions);
>
>     memset(cl->be_displays, 0, screenInfo.numScreens * sizeof(Display *));
>  }
> @@ -167,8 +167,8 @@ void __glXFreeGLXPixmap( __GLXpixmap *pGlxPixmap )
>        ** only if it's zero.
>        */
>        (*pGlxPixmap->pScreen->DestroyPixmap)(pPixmap);
> -       __glXFree(pGlxPixmap->be_xids);
> -       __glXFree(pGlxPixmap);
> +       free(pGlxPixmap->be_xids);
> +       free(pGlxPixmap);
>     }
>
>  }
> @@ -222,10 +222,10 @@ GLboolean __glXFreeContext(__GLXcontext *cx)
>  {
>     if (cx->idExists || cx->isCurrent) return GL_FALSE;
>
> -    if (cx->feedbackBuf) __glXFree(cx->feedbackBuf);
> -    if (cx->selectBuf) __glXFree(cx->selectBuf);
> -    if (cx->real_ids) __glXFree(cx->real_ids);
> -    if (cx->real_vids) __glXFree(cx->real_vids);
> +    if (cx->feedbackBuf) free(cx->feedbackBuf);
> +    if (cx->selectBuf) free(cx->selectBuf);
> +    if (cx->real_ids) free(cx->real_ids);
> +    if (cx->real_vids) free(cx->real_vids);
>
>     if (cx->pGlxPixmap) {
>        /*
> @@ -263,7 +263,7 @@ GLboolean __glXFreeContext(__GLXcontext *cx)
>        cx->pGlxReadWindow = 0;
>     }
>
> -    __glXFree(cx);
> +    free(cx);
>
>     if (cx == __glXLastContext) {
>        __glXFlushContextCache();
> @@ -387,15 +387,15 @@ static int __glXDispatch(ClientPtr client)
>     opcode = stuff->glxCode;
>     cl = __glXClients[client->index];
>     if (!cl) {
> -       cl = __glXCalloc(1, sizeof(__GLXclientState));
> +       cl = calloc(1, sizeof(__GLXclientState));
>         __glXClients[client->index] = cl;
>        if (!cl) {
>            return BadAlloc;
>        }
>
> -       cl->be_displays = __glXCalloc(screenInfo.numScreens, sizeof(Display *));
> +       cl->be_displays = calloc(screenInfo.numScreens, sizeof(Display *));
>        if (!cl->be_displays) {
> -           __glXFree( cl );
> +           free( cl );
>            return BadAlloc;
>        }
>     }
> @@ -439,15 +439,15 @@ static int __glXSwapDispatch(ClientPtr client)
>     opcode = stuff->glxCode;
>     cl = __glXClients[client->index];
>     if (!cl) {
> -       cl = __glXCalloc(1, sizeof(__GLXclientState));
> +       cl = calloc(1, sizeof(__GLXclientState));
>         __glXClients[client->index] = cl;
>        if (!cl) {
>            return BadAlloc;
>        }
>
> -       cl->be_displays = __glXCalloc(screenInfo.numScreens, sizeof(Display *));
> +       cl->be_displays = calloc(screenInfo.numScreens, sizeof(Display *));
>        if (!cl->be_displays) {
> -           __glXFree( cl );
> +           free( cl );
>            return BadAlloc;
>        }
>     }
> diff --git a/hw/dmx/glxProxy/glxutil.c b/hw/dmx/glxProxy/glxutil.c
> index cfd0269..c519d14 100644
> --- a/hw/dmx/glxProxy/glxutil.c
> +++ b/hw/dmx/glxProxy/glxutil.c
> @@ -29,83 +29,6 @@
>  */
>
>  #include "glxserver.h"
> -#include <GL/glxtokens.h>
> -#include <pixmapstr.h>
> -#include <windowstr.h>
>  #include "glxutil.h"
> -#include <stdlib.h>
> -
> -/************************************************************************/
>
>  void __glXNop(void) {}
> -
> -/************************************************************************/
> -
> -/* Memory Allocation for GLX */
> -
> -void *
> -__glXMalloc(size_t size)
> -{
> -    void *addr;
> -
> -    if (size == 0) {
> -       return NULL;
> -    }
> -    addr = malloc(size);
> -    if (addr == NULL) {
> -       /* XXX: handle out of memory error */
> -       return NULL;
> -    }
> -    return addr;
> -}
> -
> -void *
> -__glXCalloc(size_t numElements, size_t elementSize)
> -{
> -    void *addr;
> -    size_t size;
> -
> -    if ((numElements == 0) || (elementSize == 0)) {
> -       return NULL;
> -    }
> -    addr = calloc(numElements, elementSize);
> -    if (addr == NULL) {
> -       /* XXX: handle out of memory error */
> -       return NULL;
> -    }
> -    return addr;
> -}
> -
> -void *
> -__glXRealloc(void *addr, size_t newSize)
> -{
> -    void *newAddr;
> -
> -    if (addr) {
> -       if (newSize == 0) {
> -           free(addr);
> -           return NULL;
> -       } else {
> -           newAddr = realloc(addr, newSize);
> -       }
> -    } else {
> -       if (newSize == 0) {
> -           return NULL;
> -       } else {
> -           newAddr = malloc(newSize);
> -       }
> -    }
> -    if (newAddr == NULL) {
> -       return NULL;    /* XXX: out of memory */
> -    }
> -
> -    return newAddr;
> -}
> -
> -void
> -__glXFree(void *addr)
> -{
> -    if (addr) {
> -       free(addr);
> -    }
> -}
> diff --git a/hw/dmx/glxProxy/glxutil.h b/hw/dmx/glxProxy/glxutil.h
> index 6487ca7..5458212 100644
> --- a/hw/dmx/glxProxy/glxutil.h
> +++ b/hw/dmx/glxProxy/glxutil.h
> @@ -33,12 +33,6 @@
>
>  extern void __glXNop(void);
>
> -/* memory management */
> -extern void *__glXMalloc(size_t size);
> -extern void *__glXCalloc(size_t numElements, size_t elementSize);
> -extern void *__glXRealloc(void *addr, size_t newSize);
> -extern void __glXFree(void *ptr);
> -
>  /* context helper routines */
>  extern __GLXcontext *__glXLookupContextByTag(__GLXclientState*, GLXContextTag);
>  extern DrawablePtr __glXLookupDrawableByTag(__GLXclientState *cl, GLXContextTag tag);
> --
> 1.7.0
>

Reviewed-by: Alex Deucher <alexdeucher at gmail.com>


More information about the xorg-devel mailing list