mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-10-29 05:40:12 -04:00
treewide: Migrate from sizeof(struct) to sizeof(*pointer) where practical
This commit is contained in:
parent
a09d649439
commit
1b0694b794
99 changed files with 224 additions and 355 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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);
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -270,7 +270,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);
|
||||
|
|
@ -317,7 +317,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);
|
||||
|
|
@ -340,7 +340,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
|
|||
xkb_context_unref(context);
|
||||
break;
|
||||
case WLR_INPUT_DEVICE_TABLET_PAD:;
|
||||
struct tablet_pad_state *pstate = calloc(sizeof(struct tablet_pad_state), 1);
|
||||
struct tablet_pad_state *pstate = calloc(1, sizeof(*pstate));
|
||||
pstate->wlr_tablet_pad = wlr_tablet_pad_from_input_device(device);
|
||||
pstate->sample = sample;
|
||||
pstate->destroy.notify = tablet_pad_destroy_notify;
|
||||
|
|
@ -358,7 +358,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
|
|||
sample->height_mm = tablet->height_mm == 0 ?
|
||||
10 : tablet->height_mm;
|
||||
|
||||
struct tablet_tool_state *tstate = calloc(sizeof(struct tablet_tool_state), 1);
|
||||
struct tablet_tool_state *tstate = calloc(1, sizeof(*tstate));
|
||||
tstate->wlr_tablet = tablet;
|
||||
tstate->sample = sample;
|
||||
tstate->destroy.notify = tablet_tool_destroy_notify;
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ static void show_status(void) {
|
|||
for (unsigned i = 0; i < utf8_strlen(buffer); i++) {
|
||||
printf(" ");
|
||||
}
|
||||
char *cursor_mark = calloc(utf8_strlen(preedit_text) + 2, sizeof(char));
|
||||
char *cursor_mark = calloc(utf8_strlen(preedit_text) + 2, sizeof(*cursor_mark));
|
||||
for (unsigned i = 0; i < utf8_strlen(preedit_text); i++) {
|
||||
cursor_mark[i] = '.';
|
||||
}
|
||||
|
|
@ -249,7 +249,7 @@ static void text_input_handle_done(void *data,
|
|||
commit_string = "";
|
||||
}
|
||||
size_t new_size = strlen(buffer) + strlen(commit_string) + 1;
|
||||
char *new_buffer = calloc(new_size, sizeof(char)); // realloc may fail anyway
|
||||
char *new_buffer = calloc(new_size, sizeof(*new_buffer)); // realloc may fail anyway
|
||||
snprintf(new_buffer, new_size, "%s%s", buffer, commit_string);
|
||||
free(buffer);
|
||||
buffer = new_buffer;
|
||||
|
|
@ -333,7 +333,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
}
|
||||
|
||||
buffer = calloc(1, sizeof(char));
|
||||
buffer = calloc(1, sizeof(*buffer));
|
||||
|
||||
display = wl_display_connect(NULL);
|
||||
if (display == NULL) {
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ static void touch_down_notify(struct wl_listener *listener, void *data) {
|
|||
struct wlr_touch_down_event *event = data;
|
||||
struct touch_state *tstate = wl_container_of(listener, tstate, down);
|
||||
struct sample_state *sample = tstate->sample;
|
||||
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;
|
||||
|
|
@ -175,7 +175,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);
|
||||
|
|
@ -222,7 +222,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);
|
||||
|
|
@ -245,7 +245,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
|
|||
xkb_context_unref(context);
|
||||
break;
|
||||
case WLR_INPUT_DEVICE_TOUCH:;
|
||||
struct touch_state *tstate = calloc(sizeof(struct touch_state), 1);
|
||||
struct touch_state *tstate = calloc(1, sizeof(*tstate));
|
||||
tstate->wlr_touch = wlr_touch_from_input_device(device);
|
||||
tstate->sample = sample;
|
||||
tstate->destroy.notify = touch_destroy_notify;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue