unroll XCALLOC/XMALLOC macros; since we use xcalloc/xmalloc all over the

place anyway, this makes things a bit more consistent; from Thomas Pfaff

ok oga@
This commit is contained in:
okan 2009-06-20 00:22:39 +00:00
parent 18c7d89c98
commit 58d12134b1
9 changed files with 17 additions and 21 deletions

View File

@ -111,7 +111,7 @@ x_setup(void)
int i; int i;
for (i = 0; i < ScreenCount(X_Dpy); i++) { for (i = 0; i < ScreenCount(X_Dpy); i++) {
XCALLOC(sc, struct screen_ctx); sc = xcalloc(1, sizeof(*sc));
x_setupscreen(sc, i); x_setupscreen(sc, i);
TAILQ_INSERT_TAIL(&Screenq, sc, entry); TAILQ_INSERT_TAIL(&Screenq, sc, entry);
} }

View File

@ -395,9 +395,6 @@ void *xmalloc(size_t);
void *xcalloc(size_t, size_t); void *xcalloc(size_t, size_t);
char *xstrdup(const char *); char *xstrdup(const char *);
#define XMALLOC(p, t) ((p) = (t *)xmalloc(sizeof * (p)))
#define XCALLOC(p, t) ((p) = (t *)xcalloc(1, sizeof * (p)))
struct screen_ctx *screen_fromroot(Window); struct screen_ctx *screen_fromroot(Window);
struct screen_ctx *screen_current(void); struct screen_ctx *screen_current(void);
void screen_updatestackingorder(void); void screen_updatestackingorder(void);

View File

@ -56,7 +56,7 @@ client_new(Window win, struct screen_ctx *sc, int mapped)
if (win == None) if (win == None)
return (NULL); return (NULL);
XCALLOC(cc, struct client_ctx); cc = xcalloc(1, sizeof(*cc));
XGrabServer(X_Dpy); XGrabServer(X_Dpy);
@ -462,7 +462,7 @@ client_setname(struct client_ctx *cc)
goto match; goto match;
} }
XMALLOC(wn, struct winname); wn = xmalloc(sizeof(*wn));
wn->name = newname; wn->name = newname;
TAILQ_INSERT_TAIL(&cc->nameq, wn, entry); TAILQ_INSERT_TAIL(&cc->nameq, wn, entry);
cc->nameqlen++; cc->nameqlen++;

7
conf.c
View File

@ -41,8 +41,7 @@ conf_cmd_add(struct conf *c, char *image, char *label, int flags)
else if (strcmp(label, "lock") == 0) else if (strcmp(label, "lock") == 0)
strlcpy(c->lockpath, image, sizeof(c->lockpath)); strlcpy(c->lockpath, image, sizeof(c->lockpath));
else { else {
struct cmd *cmd; struct cmd *cmd = xmalloc(sizeof(*cmd));
XMALLOC(cmd, struct cmd);
cmd->flags = flags; cmd->flags = flags;
strlcpy(cmd->image, image, sizeof(cmd->image)); strlcpy(cmd->image, image, sizeof(cmd->image));
strlcpy(cmd->label, label, sizeof(cmd->label)); strlcpy(cmd->label, label, sizeof(cmd->label));
@ -429,7 +428,7 @@ conf_bindname(struct conf *c, char *name, char *binding)
char *substring; char *substring;
int iter; int iter;
XCALLOC(current_binding, struct keybinding); current_binding = xcalloc(1, sizeof(*current_binding));
if (strchr(name, 'C') != NULL && if (strchr(name, 'C') != NULL &&
strchr(name, 'C') < strchr(name, '-')) strchr(name, 'C') < strchr(name, '-'))
@ -541,7 +540,7 @@ conf_mousebind(struct conf *c, char *name, char *binding)
const char *errstr; const char *errstr;
int iter; int iter;
XCALLOC(current_binding, struct mousebinding); current_binding = xcalloc(1, sizeof(*current_binding));
if (strchr(name, 'C') != NULL && if (strchr(name, 'C') != NULL &&
strchr(name, 'C') < strchr(name, '-')) strchr(name, 'C') < strchr(name, '-'))

View File

@ -304,7 +304,7 @@ group_menu(XButtonEvent *e)
if (TAILQ_EMPTY(&gc->clients)) if (TAILQ_EMPTY(&gc->clients))
continue; continue;
XCALLOC(mi, struct menu); mi = xcalloc(1, sizeof(*mi));
if (gc->hidden) if (gc->hidden)
snprintf(mi->text, sizeof(mi->text), "%d: [%s]", snprintf(mi->text, sizeof(mi->text), "%d: [%s]",
gc->shortcut, shortcut_to_name[gc->shortcut]); gc->shortcut, shortcut_to_name[gc->shortcut]);

View File

@ -135,7 +135,7 @@ kbfunc_client_search(struct client_ctx *scratch, union arg *arg)
TAILQ_INIT(&menuq); TAILQ_INIT(&menuq);
TAILQ_FOREACH(cc, &Clientq, entry) { TAILQ_FOREACH(cc, &Clientq, entry) {
XCALLOC(mi, struct menu); mi = xcalloc(1, sizeof(*mi));
strlcpy(mi->text, cc->name, sizeof(mi->text)); strlcpy(mi->text, cc->name, sizeof(mi->text));
mi->ctx = cc; mi->ctx = cc;
TAILQ_INSERT_TAIL(&menuq, mi, entry); TAILQ_INSERT_TAIL(&menuq, mi, entry);
@ -168,7 +168,7 @@ kbfunc_menu_search(struct client_ctx *scratch, union arg *arg)
TAILQ_INIT(&menuq); TAILQ_INIT(&menuq);
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) { TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
XCALLOC(mi, struct menu); mi = xcalloc(1, sizeof(*mi));
strlcpy(mi->text, cmd->label, sizeof(mi->text)); strlcpy(mi->text, cmd->label, sizeof(mi->text));
mi->ctx = cmd; mi->ctx = cmd;
TAILQ_INSERT_TAIL(&menuq, mi, entry); TAILQ_INSERT_TAIL(&menuq, mi, entry);
@ -304,7 +304,7 @@ kbfunc_exec(struct client_ctx *scratch, union arg *arg)
continue; continue;
executable: executable:
/* the thing in tpath, we may execute */ /* the thing in tpath, we may execute */
XCALLOC(mi, struct menu); mi = xcalloc(1, sizeof(*mi));
strlcpy(mi->text, dp->d_name, sizeof(mi->text)); strlcpy(mi->text, dp->d_name, sizeof(mi->text));
TAILQ_INSERT_TAIL(&menuq, mi, entry); TAILQ_INSERT_TAIL(&menuq, mi, entry);
} }
@ -380,7 +380,7 @@ kbfunc_ssh(struct client_ctx *scratch, union arg *arg)
if (p - buf + 1 > sizeof(hostbuf)) if (p - buf + 1 > sizeof(hostbuf))
continue; continue;
(void) strlcpy(hostbuf, buf, p - buf + 1); (void) strlcpy(hostbuf, buf, p - buf + 1);
XCALLOC(mi, struct menu); mi = xcalloc(1, sizeof(*mi));
(void) strlcpy(mi->text, hostbuf, sizeof(mi->text)); (void) strlcpy(mi->text, hostbuf, sizeof(mi->text));
TAILQ_INSERT_TAIL(&menuq, mi, entry); TAILQ_INSERT_TAIL(&menuq, mi, entry);
} }

2
menu.c
View File

@ -383,7 +383,7 @@ menu_handle_release(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc,
if (entry == i++) if (entry == i++)
break; break;
if (mi == NULL) { if (mi == NULL) {
XMALLOC(mi, struct menu); mi = xmalloc(sizeof(*mi));
mi->text[0] = '\0'; mi->text[0] = '\0';
mi->dummy = 1; mi->dummy = 1;
} }

View File

@ -234,7 +234,7 @@ mousefunc_menu_unhide(struct client_ctx *cc, void *arg)
if (wname == NULL) if (wname == NULL)
continue; continue;
XCALLOC(mi, struct menu); mi = xcalloc(1, sizeof(*mi));
strlcpy(mi->text, wname, sizeof(mi->text)); strlcpy(mi->text, wname, sizeof(mi->text));
mi->ctx = cc; mi->ctx = cc;
TAILQ_INSERT_TAIL(&menuq, mi, entry); TAILQ_INSERT_TAIL(&menuq, mi, entry);
@ -268,7 +268,7 @@ mousefunc_menu_cmd(struct client_ctx *cc, void *arg)
TAILQ_INIT(&menuq); TAILQ_INIT(&menuq);
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) { TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
XCALLOC(mi, struct menu); mi = xcalloc(1, sizeof(*mi));
strlcpy(mi->text, cmd->label, sizeof(mi->text)); strlcpy(mi->text, cmd->label, sizeof(mi->text));
mi->ctx = cmd; mi->ctx = cmd;
TAILQ_INSERT_TAIL(&menuq, mi, entry); TAILQ_INSERT_TAIL(&menuq, mi, entry);

View File

@ -132,7 +132,7 @@ main : FONTNAME STRING {
YYERROR; YYERROR;
} }
XCALLOC(aw, struct autogroupwin); aw = xcalloc(1, sizeof(*aw));
if ((p = strchr($3, ',')) == NULL) { if ((p = strchr($3, ',')) == NULL) {
aw->name = NULL; aw->name = NULL;
@ -151,7 +151,7 @@ main : FONTNAME STRING {
| IGNORE STRING { | IGNORE STRING {
struct winmatch *wm; struct winmatch *wm;
XCALLOC(wm, struct winmatch); wm = xcalloc(1, sizeof(*wm));
strlcpy(wm->title, $2, sizeof(wm->title)); strlcpy(wm->title, $2, sizeof(wm->title));
TAILQ_INSERT_TAIL(&conf->ignoreq, wm, entry); TAILQ_INSERT_TAIL(&conf->ignoreq, wm, entry);
@ -503,7 +503,7 @@ parse_config(const char *filename, struct conf *xconf)
{ {
int errors = 0; int errors = 0;
XCALLOC(conf, struct conf); conf = xcalloc(1, sizeof(*conf));
if ((file = pushfile(filename)) == NULL) { if ((file = pushfile(filename)) == NULL) {
free(conf); free(conf);