Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
treewide: Migrate from sizeof(struct) to sizeof(*pointer) where pract…
Browse files Browse the repository at this point in the history
…ical
  • Loading branch information
Nefsen402 committed Oct 3, 2023
1 parent a09d649 commit 1b0694b
Show file tree
Hide file tree
Showing 99 changed files with 224 additions and 355 deletions.
4 changes: 2 additions & 2 deletions backend/drm/atomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bool create_gamma_lut_blob(struct wlr_drm_backend *drm,
return true;
}

struct drm_color_lut *gamma = malloc(size * sizeof(struct drm_color_lut));
struct drm_color_lut *gamma = malloc(size * sizeof(*gamma));
if (gamma == NULL) {
wlr_log(WLR_ERROR, "Failed to allocate gamma table");
return false;
Expand All @@ -133,7 +133,7 @@ bool create_gamma_lut_blob(struct wlr_drm_backend *drm,
}

if (drmModeCreatePropertyBlob(drm->fd, gamma,
size * sizeof(struct drm_color_lut), blob_id) != 0) {
size * sizeof(*gamma), blob_id) != 0) {
wlr_log_errno(WLR_ERROR, "Unable to create gamma LUT property blob");
free(gamma);
return false;
Expand Down
2 changes: 1 addition & 1 deletion backend/drm/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
wlr_log(WLR_INFO, "Initializing DRM backend for %s (%s)", name, version->name);
drmFreeVersion(version);

struct wlr_drm_backend *drm = calloc(1, sizeof(struct wlr_drm_backend));
struct wlr_drm_backend *drm = calloc(1, sizeof(*drm));
if (!drm) {
wlr_log_errno(WLR_ERROR, "Allocation failed");
return NULL;
Expand Down
3 changes: 1 addition & 2 deletions backend/drm/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ struct wlr_drm_backend_monitor *drm_backend_monitor_create(
struct wlr_backend *multi,
struct wlr_backend *primary_drm,
struct wlr_session *session) {
struct wlr_drm_backend_monitor *monitor =
calloc(1, sizeof(struct wlr_drm_backend_monitor));
struct wlr_drm_backend_monitor *monitor = calloc(1, sizeof(*monitor));
if (!monitor) {
wlr_log_errno(WLR_ERROR, "Allocation failed");
return NULL;
Expand Down
3 changes: 1 addition & 2 deletions backend/headless/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
struct wlr_backend *wlr_headless_backend_create(struct wl_display *display) {
wlr_log(WLR_INFO, "Creating headless backend");

struct wlr_headless_backend *backend =
calloc(1, sizeof(struct wlr_headless_backend));
struct wlr_headless_backend *backend = calloc(1, sizeof(*backend));
if (!backend) {
wlr_log(WLR_ERROR, "Failed to allocate wlr_headless_backend");
return NULL;
Expand Down
3 changes: 1 addition & 2 deletions backend/headless/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend,
struct wlr_headless_backend *backend =
headless_backend_from_backend(wlr_backend);

struct wlr_headless_output *output =
calloc(1, sizeof(struct wlr_headless_output));
struct wlr_headless_output *output = calloc(1, sizeof(*output));
if (output == NULL) {
wlr_log(WLR_ERROR, "Failed to allocate wlr_headless_output");
return NULL;
Expand Down
3 changes: 1 addition & 2 deletions backend/libinput/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {

struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display,
struct wlr_session *session) {
struct wlr_libinput_backend *backend =
calloc(1, sizeof(struct wlr_libinput_backend));
struct wlr_libinput_backend *backend = calloc(1, sizeof(*backend));
if (!backend) {
wlr_log(WLR_ERROR, "Allocation failed: %s", strerror(errno));
return NULL;
Expand Down
3 changes: 1 addition & 2 deletions backend/libinput/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ static void handle_device_added(struct wlr_libinput_backend *backend,
const char *name = libinput_device_get_name(libinput_dev);
wlr_log(WLR_DEBUG, "Adding %s [%d:%d]", name, vendor, product);

struct wlr_libinput_input_device *dev =
calloc(1, sizeof(struct wlr_libinput_input_device));
struct wlr_libinput_input_device *dev = calloc(1, sizeof(*dev));
if (dev == NULL) {
wlr_log_errno(WLR_ERROR, "failed to allocate wlr_libinput_input_device");
return;
Expand Down
3 changes: 1 addition & 2 deletions backend/libinput/tablet_pad.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ static void add_pad_group_from_libinput(struct wlr_tablet_pad *pad,
struct libinput_device *device, unsigned int index) {
struct libinput_tablet_pad_mode_group *li_group =
libinput_device_tablet_pad_get_mode_group(device, index);
struct wlr_tablet_pad_group *group =
calloc(1, sizeof(struct wlr_tablet_pad_group));
struct wlr_tablet_pad_group *group = calloc(1, sizeof(*group));
if (!group) {
wlr_log_errno(WLR_ERROR, "failed to allocate wlr_tablet_pad_group");
return;
Expand Down
2 changes: 1 addition & 1 deletion backend/libinput/tablet_tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static struct tablet_tool *get_tablet_tool(
return tool;
}

tool = calloc(1, sizeof(struct tablet_tool));
tool = calloc(1, sizeof(*tool));
if (tool == NULL) {
wlr_log_errno(WLR_ERROR, "failed to allocate wlr_libinput_tablet_tool");
return NULL;
Expand Down
5 changes: 2 additions & 3 deletions backend/multi/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
}

struct wlr_backend *wlr_multi_backend_create(struct wl_display *display) {
struct wlr_multi_backend *backend =
calloc(1, sizeof(struct wlr_multi_backend));
struct wlr_multi_backend *backend = calloc(1, sizeof(*backend));
if (!backend) {
wlr_log(WLR_ERROR, "Backend allocation failed");
return NULL;
Expand Down Expand Up @@ -191,7 +190,7 @@ bool wlr_multi_backend_add(struct wlr_backend *_multi,
return true;
}

struct subbackend_state *sub = calloc(1, sizeof(struct subbackend_state));
struct subbackend_state *sub = calloc(1, sizeof(*sub));
if (sub == NULL) {
wlr_log(WLR_ERROR, "Could not add backend: allocation failed");
return false;
Expand Down
2 changes: 1 addition & 1 deletion backend/wayland/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ static char *get_render_name(const char *name) {
wlr_log(WLR_ERROR, "drmGetDevices2 failed: %s", strerror(-devices_len));
return NULL;
}
drmDevice **devices = calloc(devices_len, sizeof(drmDevice *));
drmDevice **devices = calloc(devices_len, sizeof(*devices));
if (devices == NULL) {
wlr_log_errno(WLR_ERROR, "Allocation failed");
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion backend/wayland/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ static struct wlr_wl_buffer *create_wl_buffer(struct wlr_wl_backend *wl,
return NULL;
}

struct wlr_wl_buffer *buffer = calloc(1, sizeof(struct wlr_wl_buffer));
struct wlr_wl_buffer *buffer = calloc(1, sizeof(*buffer));
if (buffer == NULL) {
wl_buffer_destroy(wl_buffer);
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion backend/wayland/pointer.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ void create_pointer(struct wlr_wl_seat *seat, struct wlr_wl_output *output) {
wlr_log(WLR_DEBUG, "creating pointer for output '%s' from seat '%s'",
output->wlr_output.name, seat->name);

struct wlr_wl_pointer *pointer = calloc(1, sizeof(struct wlr_wl_pointer));
struct wlr_wl_pointer *pointer = calloc(1, sizeof(*pointer));
if (pointer == NULL) {
wlr_log(WLR_ERROR, "failed to allocate wlr_wl_pointer");
return;
Expand Down
2 changes: 1 addition & 1 deletion backend/wayland/seat.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ static const struct wl_seat_listener seat_listener;

bool create_wl_seat(struct wl_seat *wl_seat, struct wlr_wl_backend *wl,
uint32_t global_name) {
struct wlr_wl_seat *seat = calloc(1, sizeof(struct wlr_wl_seat));
struct wlr_wl_seat *seat = calloc(1, sizeof(*seat));
if (!seat) {
wlr_log_errno(WLR_ERROR, "Allocation failed");
return false;
Expand Down
11 changes: 4 additions & 7 deletions backend/wayland/tablet_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ static void handle_tablet_pad_group_ring(void *data,
struct zwp_tablet_pad_group_v2 *pad_group,
struct zwp_tablet_pad_ring_v2 *ring) {
struct tablet_pad_group *group = data;
struct tablet_pad_ring *tablet_ring =
calloc(1, sizeof(struct tablet_pad_ring));
struct tablet_pad_ring *tablet_ring = calloc(1, sizeof(*tablet_ring));
if (!tablet_ring) {
zwp_tablet_pad_ring_v2_destroy(ring);
return;
Expand All @@ -227,8 +226,7 @@ static void handle_tablet_pad_group_strip(void *data,
struct zwp_tablet_pad_group_v2 *pad_group,
struct zwp_tablet_pad_strip_v2 *strip) {
struct tablet_pad_group *group = data;
struct tablet_pad_strip *tablet_strip =
calloc(1, sizeof(struct tablet_pad_strip));
struct tablet_pad_strip *tablet_strip = calloc(1, sizeof(*tablet_strip));
if (!tablet_strip) {
zwp_tablet_pad_strip_v2_destroy(strip);
return;
Expand Down Expand Up @@ -296,8 +294,7 @@ static void handle_tablet_pad_group(void *data,
struct wlr_wl_seat *seat = data;
struct wlr_tablet_pad *pad = &seat->wlr_tablet_pad;

struct tablet_pad_group *group =
calloc(1, sizeof(struct tablet_pad_group));
struct tablet_pad_group *group = calloc(1, sizeof(*group));
if (!group) {
wlr_log_errno(WLR_ERROR, "failed to allocate tablet_pad_group");
zwp_tablet_pad_group_v2_destroy(pad_group);
Expand Down Expand Up @@ -788,7 +785,7 @@ static void handle_tool_added(void *data,

wl_signal_init(&seat->wlr_tablet_tool.events.destroy);

struct tablet_tool *tool = calloc(1, sizeof(struct tablet_tool));
struct tablet_tool *tool = calloc(1, sizeof(*tool));
if (tool == NULL) {
wlr_log_errno(WLR_ERROR, "failed to allocate tablet_tool");
zwp_tablet_tool_v2_destroy(zwp_tablet_tool_v2);
Expand Down
2 changes: 1 addition & 1 deletion backend/x11/input_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void handle_x11_xinput_event(struct wlr_x11_backend *x11,
id = last_touchpoint->wayland_id + 1;
}

struct wlr_x11_touchpoint *touchpoint = calloc(1, sizeof(struct wlr_x11_touchpoint));
struct wlr_x11_touchpoint *touchpoint = calloc(1, sizeof(*touchpoint));
touchpoint->x11_id = ev->detail;
touchpoint->wayland_id = id;
wl_list_init(&touchpoint->link);
Expand Down
4 changes: 2 additions & 2 deletions backend/x11/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ static struct wlr_x11_buffer *create_x11_buffer(struct wlr_x11_output *output,
return NULL;
}

struct wlr_x11_buffer *buffer = calloc(1, sizeof(struct wlr_x11_buffer));
struct wlr_x11_buffer *buffer = calloc(1, sizeof(*buffer));
if (!buffer) {
xcb_free_pixmap(x11->xcb, pixmap);
return NULL;
Expand Down Expand Up @@ -535,7 +535,7 @@ struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) {
return NULL;
}

struct wlr_x11_output *output = calloc(1, sizeof(struct wlr_x11_output));
struct wlr_x11_output *output = calloc(1, sizeof(*output));
if (output == NULL) {
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/cairo-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static void server_handle_new_output(struct wl_listener *listener, void *data) {

wlr_output_init_render(wlr_output, server->allocator, server->renderer);

struct output *output = calloc(1, sizeof(struct output));
struct output *output = calloc(1, sizeof(*output));
output->wlr = wlr_output;
output->server = server;
output->frame.notify = output_handle_frame;
Expand Down
2 changes: 1 addition & 1 deletion examples/foreign-toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ static const struct zwlr_foreign_toplevel_handle_v1_listener toplevel_impl = {
static void toplevel_manager_handle_toplevel(void *data,
struct zwlr_foreign_toplevel_manager_v1 *toplevel_manager,
struct zwlr_foreign_toplevel_handle_v1 *zwlr_toplevel) {
struct toplevel_v1 *toplevel = calloc(1, sizeof(struct toplevel_v1));
struct toplevel_v1 *toplevel = calloc(1, sizeof(*toplevel));
if (!toplevel) {
fprintf(stderr, "Failed to allocate memory for toplevel\n");
return;
Expand Down
3 changes: 1 addition & 2 deletions examples/fullscreen-shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ static void server_handle_new_output(struct wl_listener *listener, void *data) {

wlr_output_init_render(wlr_output, server->allocator, server->renderer);

struct fullscreen_output *output =
calloc(1, sizeof(struct fullscreen_output));
struct fullscreen_output *output = calloc(1, sizeof(*output));
output->wlr_output = wlr_output;
output->server = server;
output->frame.notify = output_handle_frame;
Expand Down
2 changes: 1 addition & 1 deletion examples/gamma-control.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static const struct zwlr_gamma_control_v1_listener gamma_control_listener = {
static void registry_handle_global(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version) {
if (strcmp(interface, wl_output_interface.name) == 0) {
struct output *output = calloc(1, sizeof(struct output));
struct output *output = calloc(1, sizeof(*output));
output->wl_output = wl_registry_bind(registry, name,
&wl_output_interface, 1);
wl_list_insert(&outputs, &output->link);
Expand Down
4 changes: 2 additions & 2 deletions examples/output-layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static void new_output_notify(struct wl_listener *listener, void *data) {

wlr_output_init_render(output, sample->allocator, sample->renderer);

struct sample_output *sample_output = calloc(1, sizeof(struct sample_output));
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
wlr_output_layout_add_auto(sample->layout, output);
sample_output->output = output;
sample_output->sample = sample;
Expand Down Expand Up @@ -236,7 +236,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
struct sample_state *sample = wl_container_of(listener, sample, new_input);
switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_keyboard));
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
keyboard->sample = sample;
wl_signal_add(&device->events.destroy, &keyboard->destroy);
Expand Down
2 changes: 1 addition & 1 deletion examples/output-power-management.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static const struct zwlr_output_power_v1_listener output_power_listener = {
static void registry_handle_global(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version) {
if (strcmp(interface, wl_output_interface.name) == 0) {
struct output *output = calloc(1, sizeof(struct output));
struct output *output = calloc(1, sizeof(*output));
output->wl_output = wl_registry_bind(registry, name,
&wl_output_interface, 1);
wl_list_insert(&outputs, &output->link);
Expand Down
6 changes: 3 additions & 3 deletions examples/pointer.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static void handle_touch_up(struct wl_listener *listener, void *data) {
static void handle_touch_down(struct wl_listener *listener, void *data) {
struct sample_state *sample = wl_container_of(listener, sample, touch_down);
struct wlr_touch_down_event *event = data;
struct touch_point *point = calloc(1, sizeof(struct touch_point));
struct touch_point *point = calloc(1, sizeof(*point));
point->touch_id = event->touch_id;
point->x = event->x;
point->y = event->y;
Expand Down Expand Up @@ -266,7 +266,7 @@ static void new_output_notify(struct wl_listener *listener, void *data) {

wlr_output_init_render(output, sample->allocator, sample->renderer);

struct sample_output *sample_output = calloc(1, sizeof(struct sample_output));
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
sample_output->output = output;
sample_output->state = sample;
wl_signal_add(&output->events.frame, &sample_output->frame);
Expand Down Expand Up @@ -305,7 +305,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
break;

case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_keyboard));
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
keyboard->state = state;
wl_signal_add(&device->events.destroy, &keyboard->destroy);
Expand Down
4 changes: 2 additions & 2 deletions examples/relative-pointer-unstable-v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ int main(int argc, char **argv) {

/* Initialize EGL context */

struct egl_info *e = calloc(1, sizeof(struct egl_info));
struct egl_info *e = calloc(1, sizeof(*e));
e->width = e->height = 512;

egl_init(display);
Expand Down Expand Up @@ -465,7 +465,7 @@ int main(int argc, char **argv) {

/* Setup global state and render */

struct window *w = calloc(1, sizeof(struct window));
struct window *w = calloc(1, sizeof(*w));
w->egl_info = e;

draw_init(e);
Expand Down
4 changes: 2 additions & 2 deletions examples/rotation.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static void new_output_notify(struct wl_listener *listener, void *data) {

wlr_output_init_render(output, sample->allocator, sample->renderer);

struct sample_output *sample_output = calloc(1, sizeof(struct sample_output));
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
sample_output->x_offs = sample_output->y_offs = 0;
sample_output->x_vel = sample_output->y_vel = 128;

Expand Down Expand Up @@ -187,7 +187,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
struct sample_state *sample = wl_container_of(listener, sample, new_input);
switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard = calloc(1, sizeof(struct sample_keyboard));
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
keyboard->sample = sample;
wl_signal_add(&device->events.destroy, &keyboard->destroy);
Expand Down
5 changes: 2 additions & 3 deletions examples/scene-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ static void server_handle_new_output(struct wl_listener *listener, void *data) {

wlr_output_init_render(wlr_output, server->allocator, server->renderer);

struct output *output =
calloc(1, sizeof(struct output));
struct output *output = calloc(1, sizeof(*output));
output->wlr = wlr_output;
output->server = server;
output->frame.notify = output_handle_frame;
Expand Down Expand Up @@ -118,7 +117,7 @@ static void server_handle_new_surface(struct wl_listener *listener,
int pos = server->surface_offset;
server->surface_offset += 50;

struct surface *surface = calloc(1, sizeof(struct surface));
struct surface *surface = calloc(1, sizeof(*surface));
surface->wlr = wlr_surface;
surface->commit.notify = surface_handle_commit;
wl_signal_add(&wlr_surface->events.commit, &surface->commit);
Expand Down
6 changes: 2 additions & 4 deletions examples/simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ static void new_output_notify(struct wl_listener *listener, void *data) {

wlr_output_init_render(output, sample->allocator, sample->renderer);

struct sample_output *sample_output =
calloc(1, sizeof(struct sample_output));
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
sample_output->output = output;
sample_output->sample = sample;
wl_signal_add(&output->events.frame, &sample_output->frame);
Expand Down Expand Up @@ -146,8 +145,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
struct sample_state *sample = wl_container_of(listener, sample, new_input);
switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:;
struct sample_keyboard *keyboard =
calloc(1, sizeof(struct sample_keyboard));
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
keyboard->sample = sample;
wl_signal_add(&device->events.destroy, &keyboard->destroy);
Expand Down
Loading

0 comments on commit 1b0694b

Please sign in to comment.