Skip to content

Commit 7c7b7b0

Browse files
committedSep 6, 2012
Remove Xcalloc/Xmalloc/Xfree calls
These calls allowed Xlib to use a custom memory allocator, but Xlib has used the standard C library functions since at least its initial import into git in 2003. It seems unlikely that it will grow a custom memory allocator. The functions now just add extra overhead. Replacing them will make future Coccinelle patches simpler. This patch has been generated by the following Coccinelle semantic patch: // Remove Xcalloc/Xmalloc/Xfree calls @@ expression E1, E2; @@ - Xcalloc (E1, E2) + calloc (E1, E2) @@ expression E; @@ - Xmalloc (E) + malloc (E) @@ expression E; @@ - Xfree (E) + free (E) @@ expression E; @@ - XFree (E) + free (E) Reviewed-by: Brian Paul <[email protected]>
1 parent 17a574d commit 7c7b7b0

31 files changed

+191
-192
lines changed
 

‎src/egl/drivers/glx/egl_glx.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,9 @@ GLX_eglTerminate(_EGLDriver *drv, _EGLDisplay *disp)
656656
_eglCleanupDisplay(disp);
657657

658658
if (GLX_dpy->visuals)
659-
XFree(GLX_dpy->visuals);
659+
free(GLX_dpy->visuals);
660660
if (GLX_dpy->fbconfigs)
661-
XFree(GLX_dpy->fbconfigs);
661+
free(GLX_dpy->fbconfigs);
662662

663663
if (!disp->PlatformDisplay)
664664
XCloseDisplay(GLX_dpy->dpy);
@@ -909,7 +909,7 @@ GLX_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *disp,
909909
if (vinfo) {
910910
GLX_surf->glx_drawable = GLX_drv->glXCreateGLXPixmap(GLX_dpy->dpy,
911911
vinfo, GLX_surf->drawable);
912-
XFree(vinfo);
912+
free(vinfo);
913913
}
914914
}
915915
else {

‎src/gallium/state_trackers/egl/x11/glxinit.c

+16-16
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ _gl_context_modes_destroy(__GLcontextModes * modes)
8585
while (modes != NULL) {
8686
__GLcontextModes *const next = modes->next;
8787

88-
Xfree(modes);
88+
free(modes);
8989
modes = next;
9090
}
9191
}
@@ -101,7 +101,7 @@ _gl_context_modes_create(unsigned count, size_t minimum_size)
101101

102102
next = &base;
103103
for (i = 0; i < count; i++) {
104-
*next = (__GLcontextModes *) Xmalloc(size);
104+
*next = (__GLcontextModes *) malloc(size);
105105
if (*next == NULL) {
106106
_gl_context_modes_destroy(base);
107107
base = NULL;
@@ -165,7 +165,7 @@ __glXQueryServerString(Display * dpy, int opcode, CARD32 screen, CARD32 name)
165165
length = reply.length * 4;
166166
numbytes = reply.size;
167167

168-
buf = (char *) Xmalloc(numbytes);
168+
buf = (char *) malloc(numbytes);
169169
if (buf != NULL) {
170170
_XRead(dpy, buf, numbytes);
171171
length -= numbytes;
@@ -200,9 +200,9 @@ FreeScreenConfigs(__GLXdisplayPrivate * priv)
200200
_gl_context_modes_destroy(psc->configs);
201201
psc->configs = NULL; /* NOTE: just for paranoia */
202202
}
203-
Xfree((char *) psc->serverGLXexts);
203+
free((char *) psc->serverGLXexts);
204204
}
205-
XFree((char *) priv->screenConfigs);
205+
free((char *) priv->screenConfigs);
206206
priv->screenConfigs = NULL;
207207
}
208208

@@ -218,9 +218,9 @@ __glXFreeDisplayPrivate(XExtData * extension)
218218
priv = (__GLXdisplayPrivate *) extension->private_data;
219219
FreeScreenConfigs(priv);
220220
if (priv->serverGLXversion)
221-
Xfree((char *) priv->serverGLXversion);
221+
free((char *) priv->serverGLXversion);
222222

223-
Xfree((char *) priv);
223+
free((char *) priv);
224224
return 0;
225225
}
226226

@@ -491,7 +491,7 @@ createConfigsFromProperties(Display * dpy, int nvisuals, int nprops,
491491
if (prop_size <= sizeof(buf))
492492
props = buf;
493493
else
494-
props = Xmalloc(prop_size);
494+
props = malloc(prop_size);
495495

496496
/* Read each config structure and convert it into our format */
497497
m = modes;
@@ -506,7 +506,7 @@ createConfigsFromProperties(Display * dpy, int nvisuals, int nprops,
506506
}
507507

508508
if (props != buf)
509-
Xfree(props);
509+
free(props);
510510

511511
return modes;
512512
}
@@ -568,7 +568,7 @@ AllocAndFetchScreenConfigs(Display * dpy, __GLXdisplayPrivate * priv)
568568
** First allocate memory for the array of per screen configs.
569569
*/
570570
screens = ScreenCount(dpy);
571-
priv->screenConfigs = Xmalloc(screens * sizeof *priv->screenConfigs);
571+
priv->screenConfigs = malloc(screens * sizeof *priv->screenConfigs);
572572
if (!priv->screenConfigs) {
573573
return GL_FALSE;
574574
}
@@ -581,7 +581,7 @@ AllocAndFetchScreenConfigs(Display * dpy, __GLXdisplayPrivate * priv)
581581
}
582582

583583
for (i = 0; i < screens; i++) {
584-
psc = Xcalloc(1, sizeof *psc);
584+
psc = calloc(1, sizeof *psc);
585585
if (!psc)
586586
return GL_FALSE;
587587
getFBConfigs(psc, priv, i);
@@ -619,12 +619,12 @@ __glXInitialize(Display * dpy)
619619
/*
620620
** Allocate memory for all the pieces needed for this buffer.
621621
*/
622-
private = (XExtData *) Xmalloc(sizeof(XExtData));
622+
private = (XExtData *) malloc(sizeof(XExtData));
623623
if (!private)
624624
return NULL;
625-
dpyPriv = (__GLXdisplayPrivate *) Xcalloc(1, sizeof(__GLXdisplayPrivate));
625+
dpyPriv = (__GLXdisplayPrivate *) calloc(1, sizeof(__GLXdisplayPrivate));
626626
if (!dpyPriv) {
627-
Xfree(private);
627+
free(private);
628628
return NULL;
629629
}
630630

@@ -636,8 +636,8 @@ __glXInitialize(Display * dpy)
636636
dpyPriv->dpy = dpy;
637637

638638
if (!AllocAndFetchScreenConfigs(dpy, dpyPriv)) {
639-
Xfree(dpyPriv);
640-
Xfree(private);
639+
free(dpyPriv);
640+
free(private);
641641
return NULL;
642642
}
643643

‎src/gallium/state_trackers/egl/x11/x11_screen.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ x11_screen_destroy(struct x11_screen *xscr)
9696
if (xscr->dri_fd >= 0)
9797
close(xscr->dri_fd);
9898
if (xscr->dri_driver)
99-
Xfree(xscr->dri_driver);
99+
free(xscr->dri_driver);
100100
if (xscr->dri_device)
101-
Xfree(xscr->dri_device);
101+
free(xscr->dri_device);
102102

103103
#ifdef GLX_DIRECT_RENDERING
104104
/* xscr->glx_dpy will be destroyed with the X display */
@@ -107,7 +107,7 @@ x11_screen_destroy(struct x11_screen *xscr)
107107
#endif
108108

109109
if (xscr->visuals)
110-
XFree(xscr->visuals);
110+
free(xscr->visuals);
111111
FREE(xscr);
112112
}
113113

‎src/gallium/state_trackers/glx/xlib/glx_api.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ get_visual( Display *dpy, int scr, unsigned int depth, int xclass )
409409
return vis;
410410
}
411411
else {
412-
XFree((void *) vis);
412+
free((void *) vis);
413413
return NULL;
414414
}
415415
}

‎src/gallium/state_trackers/xvmc/context.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static Status Validate(Display *dpy, XvPortID port, int surface_type_id,
113113
*mc_type, *surface_flags, *subpic_max_w, *subpic_max_h);
114114
}
115115

116-
XFree(surface_info);
116+
free(surface_info);
117117
}
118118
}
119119

‎src/gallium/state_trackers/xvmc/subpicture.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static Status Validate(Display *dpy, XvPortID port, int surface_type_id, int xvi
116116
subpictures = XvMCListSubpictureTypes(dpy, port, surface_type_id, &num_subpics);
117117
if (num_subpics < 1) {
118118
if (subpictures)
119-
XFree(subpictures);
119+
free(subpictures);
120120
return BadMatch;
121121
}
122122
if (!subpictures)
@@ -161,7 +161,7 @@ static Status Validate(Display *dpy, XvPortID port, int surface_type_id, int xvi
161161
}
162162
}
163163

164-
XFree(subpictures);
164+
free(subpictures);
165165

166166
return i < num_subpics ? Success : BadMatch;
167167
}

‎src/gallium/state_trackers/xvmc/tests/test_subpicture.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ int main(int argc, char **argv)
174174

175175
assert(XvMCDestroyContext(display, &context) == Success);
176176

177-
XFree(subpics);
177+
free(subpics);
178178
XvUngrabPort(display, port_num, CurrentTime);
179179
XCloseDisplay(display);
180180

‎src/gallium/state_trackers/xvmc/tests/testlib.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ int GetPort
102102
}
103103
}
104104

105-
XFree(surface_info);
105+
free(surface_info);
106106
}
107107
}
108108
}

‎src/gallium/targets/graw-xlib/graw_xlib.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ graw_create_window_and_screen( int x,
147147
if (screen == NULL)
148148
goto fail;
149149

150-
XFree(visinfo);
150+
free(visinfo);
151151
return screen;
152152

153153
fail:
@@ -158,7 +158,7 @@ graw_create_window_and_screen( int x,
158158
FREE(xlib_handle);
159159

160160
if (visinfo)
161-
XFree(visinfo);
161+
free(visinfo);
162162

163163
if (win)
164164
XDestroyWindow(graw.display, win);

‎src/glx/XF86dri.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ XF86DRIOpenConnection(Display * dpy, int screen, drm_handle_t * hSAREA,
201201
}
202202

203203
if (rep.length) {
204-
if (!(*busIdString = (char *) Xcalloc(rep.busIdStringLength + 1, 1))) {
204+
if (!(*busIdString = (char *) calloc(rep.busIdStringLength + 1, 1))) {
205205
_XEatData(dpy, ((rep.busIdStringLength + 3) & ~3));
206206
UnlockDisplay(dpy);
207207
SyncHandle();
@@ -302,7 +302,7 @@ XF86DRIGetClientDriverName(Display * dpy, int screen,
302302
if (rep.length) {
303303
if (!
304304
(*clientDriverName =
305-
(char *) Xcalloc(rep.clientDriverNameLength + 1, 1))) {
305+
(char *) calloc(rep.clientDriverNameLength + 1, 1))) {
306306
_XEatData(dpy, ((rep.clientDriverNameLength + 3) & ~3));
307307
UnlockDisplay(dpy);
308308
SyncHandle();
@@ -521,7 +521,7 @@ XF86DRIGetDrawableInfo(Display * dpy, int screen, Drawable drawable,
521521
if (*numClipRects) {
522522
int len = sizeof(drm_clip_rect_t) * (*numClipRects);
523523

524-
*pClipRects = (drm_clip_rect_t *) Xcalloc(len, 1);
524+
*pClipRects = (drm_clip_rect_t *) calloc(len, 1);
525525
if (*pClipRects)
526526
_XRead(dpy, (char *) *pClipRects, len);
527527
}
@@ -532,7 +532,7 @@ XF86DRIGetDrawableInfo(Display * dpy, int screen, Drawable drawable,
532532
if (*numBackClipRects) {
533533
int len = sizeof(drm_clip_rect_t) * (*numBackClipRects);
534534

535-
*pBackClipRects = (drm_clip_rect_t *) Xcalloc(len, 1);
535+
*pBackClipRects = (drm_clip_rect_t *) calloc(len, 1);
536536
if (*pBackClipRects)
537537
_XRead(dpy, (char *) *pBackClipRects, len);
538538
}
@@ -582,7 +582,7 @@ XF86DRIGetDeviceInfo(Display * dpy, int screen, drm_handle_t * hFrameBuffer,
582582
*devPrivateSize = rep.devPrivateSize;
583583

584584
if (rep.length) {
585-
if (!(*pDevPrivate = (void *) Xcalloc(rep.devPrivateSize, 1))) {
585+
if (!(*pDevPrivate = (void *) calloc(rep.devPrivateSize, 1))) {
586586
_XEatData(dpy, ((rep.devPrivateSize + 3) & ~3));
587587
UnlockDisplay(dpy);
588588
SyncHandle();

‎src/glx/apple/glxreply.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ __glXReadPixelReply(Display * dpy, struct glx_context * gc, unsigned max_dim,
7979

8080
size = reply.length * 4;
8181
if (size != 0) {
82-
void *buf = Xmalloc(size);
82+
void *buf = malloc(size);
8383

8484
if (buf == NULL) {
8585
_XEatData(dpy, size);
@@ -94,7 +94,7 @@ __glXReadPixelReply(Display * dpy, struct glx_context * gc, unsigned max_dim,
9494
}
9595

9696
__glEmptyImage(gc, 3, width, height, depth, format, type, buf, dest);
97-
Xfree(buf);
97+
free(buf);
9898
}
9999
}
100100
}

‎src/glx/applegl_glx.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ applegl_create_context(struct glx_screen *psc,
134134
/* TODO: Integrate this with apple_glx_create_context and make
135135
* struct apple_glx_context inherit from struct glx_context. */
136136

137-
gc = Xcalloc(1, sizeof (*gc));
137+
gc = calloc(1, sizeof(*gc));
138138
if (gc == NULL)
139139
return NULL;
140140

141141
if (!glx_context_init(gc, psc, config)) {
142-
Xfree(gc);
142+
free(gc);
143143
return NULL;
144144
}
145145

@@ -173,7 +173,7 @@ applegl_create_screen(int screen, struct glx_display * priv)
173173
{
174174
struct glx_screen *psc;
175175

176-
psc = Xmalloc(sizeof *psc);
176+
psc = malloc(sizeof *psc);
177177
if (psc == NULL)
178178
return NULL;
179179

‎src/glx/clientattrib.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ __indirect_glPushClientAttrib(GLuint mask)
7575

7676
if (spp < &gc->attributes.stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]) {
7777
if (!(sp = *spp)) {
78-
sp = (__GLXattribute *) Xmalloc(sizeof(__GLXattribute));
78+
sp = (__GLXattribute *) malloc(sizeof(__GLXattribute));
7979
*spp = sp;
8080
}
8181
sp->mask = mask;
@@ -135,7 +135,7 @@ __glFreeAttributeState(struct glx_context * gc)
135135
spp < &gc->attributes.stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]; spp++) {
136136
sp = *spp;
137137
if (sp) {
138-
XFree((char *) sp);
138+
free((char *) sp);
139139
}
140140
else {
141141
break;

‎src/glx/clientinfo.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,5 @@ __glX_send_client_info(struct glx_display *glx_dpy)
152152
gl_extension_string);
153153
}
154154

155-
Xfree(gl_extension_string);
155+
free(gl_extension_string);
156156
}

‎src/glx/dri2.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName)
303303
return False;
304304
}
305305

306-
*driverName = Xmalloc(rep.driverNameLength + 1);
306+
*driverName = malloc(rep.driverNameLength + 1);
307307
if (*driverName == NULL) {
308308
_XEatData(dpy,
309309
((rep.driverNameLength + 3) & ~3) +
@@ -315,9 +315,9 @@ DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName)
315315
_XReadPad(dpy, *driverName, rep.driverNameLength);
316316
(*driverName)[rep.driverNameLength] = '\0';
317317

318-
*deviceName = Xmalloc(rep.deviceNameLength + 1);
318+
*deviceName = malloc(rep.deviceNameLength + 1);
319319
if (*deviceName == NULL) {
320-
Xfree(*driverName);
320+
free(*driverName);
321321
_XEatData(dpy, ((rep.deviceNameLength + 3) & ~3));
322322
UnlockDisplay(dpy);
323323
SyncHandle();
@@ -431,7 +431,7 @@ DRI2GetBuffers(Display * dpy, XID drawable,
431431
*height = rep.height;
432432
*outCount = rep.count;
433433

434-
buffers = Xmalloc(rep.count * sizeof buffers[0]);
434+
buffers = malloc(rep.count * sizeof buffers[0]);
435435
if (buffers == NULL) {
436436
_XEatData(dpy, rep.count * sizeof repBuffer);
437437
UnlockDisplay(dpy);
@@ -490,7 +490,7 @@ DRI2GetBuffersWithFormat(Display * dpy, XID drawable,
490490
*height = rep.height;
491491
*outCount = rep.count;
492492

493-
buffers = Xmalloc(rep.count * sizeof buffers[0]);
493+
buffers = malloc(rep.count * sizeof buffers[0]);
494494
if (buffers == NULL) {
495495
_XEatData(dpy, rep.count * sizeof repBuffer);
496496
UnlockDisplay(dpy);

0 commit comments

Comments
 (0)
Please sign in to comment.