Replace X-allocation functions with their C89 counterparts

The only remaining X-functions used in server are XNF*, the rest is converted to
plain alloc/calloc/realloc/free/strdup.

X* functions are still exported from server and x* macros are still defined in
header file, so both ABI and API are not affected by this change.

Signed-off-by: Mikhail Gusarov <dottedmag@dottedmag.net>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Mikhail Gusarov
2010-05-06 01:44:06 +07:00
parent 96c7ab27c3
commit 3f3ff971ec
345 changed files with 3011 additions and 3011 deletions

View File

@@ -130,7 +130,7 @@ add_option(InputOption **options, const char *key, const char *value)
for (; *options; options = &(*options)->next)
;
*options = xcalloc(sizeof(**options), 1);
*options = calloc(sizeof(**options), 1);
if (!*options) /* Yeesh. */
return;
(*options)->key = xstrdup(key);

View File

@@ -81,7 +81,7 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
MALFORMED_MESSAGE();
}
options = xcalloc(sizeof(*options), 1);
options = calloc(sizeof(*options), 1);
if (!options) {
ErrorF("[config/dbus] couldn't allocate option\n");
return BadAlloc;
@@ -97,7 +97,7 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
/* signature should be [ss][ss]... */
while (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_ARRAY) {
tmpo = xcalloc(sizeof(*tmpo), 1);
tmpo = calloc(sizeof(*tmpo), 1);
if (!tmpo) {
ErrorF("[config/dbus] couldn't allocate option\n");
ret = BadAlloc;
@@ -185,10 +185,10 @@ unwind:
tmpo = options;
options = options->next;
if (tmpo->key)
xfree(tmpo->key);
free(tmpo->key);
if (tmpo->value)
xfree(tmpo->value);
xfree(tmpo);
free(tmpo->value);
free(tmpo);
}
return ret;

View File

@@ -63,14 +63,14 @@ device_removed(LibHalContext *ctx, const char *udi)
{
char *value;
value = xalloc(strlen(udi) + 5); /* "hal:" + NULL */
value = malloc(strlen(udi) + 5); /* "hal:" + NULL */
if (!value)
return;
sprintf(value, "hal:%s", udi);
remove_devices("hal", value);
xfree(value);
free(value);
}
static char *
@@ -102,7 +102,7 @@ get_prop_string_array(LibHalContext *hal_ctx, const char *udi, const char *prop)
for (i = 0; props[i]; i++)
len += strlen(props[i]);
ret = xcalloc(sizeof(char), len + i); /* i - 1 commas, 1 NULL */
ret = calloc(sizeof(char), len + i); /* i - 1 commas, 1 NULL */
if (!ret) {
libhal_free_string_array(props);
return NULL;
@@ -179,7 +179,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
if (libhal_device_query_capability(hal_ctx, udi, "input.touchscreen", NULL))
attrs.flags |= ATTR_TOUCHSCREEN;
options = xcalloc(sizeof(*options), 1);
options = calloc(sizeof(*options), 1);
if (!options){
LogMessage(X_ERROR, "config/hal: couldn't allocate space for input options!\n");
goto unwind;
@@ -200,7 +200,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
add_option(&options, "driver", driver);
add_option(&options, "name", name);
config_info = xalloc(strlen(udi) + 5); /* "hal:" and NULL */
config_info = malloc(strlen(udi) + 5); /* "hal:" and NULL */
if (!config_info) {
LogMessage(X_ERROR, "config/hal: couldn't allocate name\n");
goto unwind;
@@ -252,34 +252,34 @@ device_added(LibHalContext *hal_ctx, const char *udi)
if (!strcasecmp(&tmp[3], "layout"))
{
if (xkb_opts.layout)
xfree(xkb_opts.layout);
free(xkb_opts.layout);
xkb_opts.layout = strdup(tmp_val);
} else if (!strcasecmp(&tmp[3], "model"))
{
if (xkb_opts.model)
xfree(xkb_opts.model);
free(xkb_opts.model);
xkb_opts.model = strdup(tmp_val);
} else if (!strcasecmp(&tmp[3], "rules"))
{
if (xkb_opts.rules)
xfree(xkb_opts.rules);
free(xkb_opts.rules);
xkb_opts.rules = strdup(tmp_val);
} else if (!strcasecmp(&tmp[3], "variant"))
{
if (xkb_opts.variant)
xfree(xkb_opts.variant);
free(xkb_opts.variant);
xkb_opts.variant = strdup(tmp_val);
} else if (!strcasecmp(&tmp[3], "options"))
{
if (xkb_opts.options)
xfree(xkb_opts.options);
free(xkb_opts.options);
xkb_opts.options = strdup(tmp_val);
}
} else
{
/* all others */
add_option(&options, psi_key + sizeof(LIBHAL_PROP_KEY)-1, tmp_val);
xfree(tmp_val);
free(tmp_val);
}
} else
{
@@ -290,7 +290,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
(tmp_val = get_prop_string_array(hal_ctx, udi, psi_key)))
{
if (xkb_opts.options)
xfree(xkb_opts.options);
free(xkb_opts.options);
xkb_opts.options = strdup(tmp_val);
}
}
@@ -325,7 +325,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
if (!xkb_opts.options)
xkb_opts.options = strdup(tmp_val);
}
xfree(tmp_val);
free(tmp_val);
} else
{
/* server 1.4 had xkb options as strlist */
@@ -367,7 +367,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
for (; dev; dev = dev->next){
if (dev->config_info)
xfree(dev->config_info);
free(dev->config_info);
dev->config_info = xstrdup(config_info);
}
@@ -375,42 +375,42 @@ unwind:
if (set)
libhal_free_property_set(set);
if (path)
xfree(path);
free(path);
if (driver)
xfree(driver);
free(driver);
if (name)
xfree(name);
free(name);
if (config_info)
xfree(config_info);
free(config_info);
while (!dev && (tmpo = options)) {
options = tmpo->next;
xfree(tmpo->key);
xfree(tmpo->value);
xfree(tmpo);
free(tmpo->key);
free(tmpo->value);
free(tmpo);
}
xfree(attrs.product);
xfree(attrs.vendor);
xfree(attrs.device);
free(attrs.product);
free(attrs.vendor);
free(attrs.device);
if (attrs.tags) {
char **tag = attrs.tags;
while (*tag) {
xfree(*tag);
free(*tag);
tag++;
}
xfree(attrs.tags);
free(attrs.tags);
}
if (xkb_opts.layout)
xfree(xkb_opts.layout);
free(xkb_opts.layout);
if (xkb_opts.rules)
xfree(xkb_opts.rules);
free(xkb_opts.rules);
if (xkb_opts.model)
xfree(xkb_opts.model);
free(xkb_opts.model);
if (xkb_opts.variant)
xfree(xkb_opts.variant);
free(xkb_opts.variant);
if (xkb_opts.options)
xfree(xkb_opts.options);
free(xkb_opts.options);
dbus_error_free(&error);

View File

@@ -63,7 +63,7 @@ device_added(struct udev_device *udev_device)
if (!udev_device_get_property_value(udev_device, "ID_INPUT"))
return;
options = xcalloc(sizeof(*options), 1);
options = calloc(sizeof(*options), 1);
if (!options)
return;
@@ -141,26 +141,26 @@ device_added(struct udev_device *udev_device)
goto unwind;
for (; dev; dev = dev->next) {
xfree(dev->config_info);
free(dev->config_info);
dev->config_info = xstrdup(config_info);
}
unwind:
xfree(config_info);
free(config_info);
while (!dev && (tmpo = options)) {
options = tmpo->next;
xfree(tmpo->key);
xfree(tmpo->value);
xfree(tmpo);
free(tmpo->key);
free(tmpo->value);
free(tmpo);
}
if (attrs.tags) {
char **tag = attrs.tags;
while (*tag) {
xfree(*tag);
free(*tag);
tag++;
}
xfree(attrs.tags);
free(attrs.tags);
}
return;
@@ -178,7 +178,7 @@ device_removed(struct udev_device *device)
remove_devices("udev", value);
xfree(value);
free(value);
}
static void