bikeshed: rename util.allocator to util.gpa

This is less typing and more clear. A definite win.
This commit is contained in:
Isaac Freund 2020-06-19 14:31:53 +02:00
parent aae89356a1
commit 12d34d4ded
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
18 changed files with 47 additions and 47 deletions

View file

@ -56,13 +56,13 @@ pub fn init(self: *Self) !void {
self.view_padding = 8;
self.outer_padding = 8;
self.mode_to_id = std.StringHashMap(usize).init(util.allocator);
self.mode_to_id = std.StringHashMap(usize).init(util.gpa);
try self.mode_to_id.putNoClobber("normal", 0);
self.modes = std.ArrayList(std.ArrayList(Mapping)).init(util.allocator);
try self.modes.append(std.ArrayList(Mapping).init(util.allocator));
self.modes = std.ArrayList(std.ArrayList(Mapping)).init(util.gpa);
try self.modes.append(std.ArrayList(Mapping).init(util.gpa));
self.float_filter = std.ArrayList([*:0]const u8).init(util.allocator);
self.float_filter = std.ArrayList([*:0]const u8).init(util.gpa);
// Float views with app_id "float"
try self.float_filter.append("float");
@ -71,7 +71,7 @@ pub fn init(self: *Self) !void {
pub fn deinit(self: Self) void {
self.mode_to_id.deinit();
for (self.modes.items) |mode| {
for (mode.items) |mapping| mapping.deinit(util.allocator);
for (mode.items) |mapping| mapping.deinit(util.gpa);
mode.deinit();
}
self.modes.deinit();

View file

@ -49,7 +49,7 @@ pub fn init(self: *Self, server: *Server) !void {
bind,
) orelse return error.CantCreateWlGlobal;
self.args_map = std.AutoHashMap(u32, std.ArrayList([]const u8)).init(util.allocator);
self.args_map = std.AutoHashMap(u32, std.ArrayList([]const u8)).init(util.gpa);
self.listen_display_destroy.notify = handleDisplayDestroy;
c.wl_display_add_destroy_listener(server.wl_display, &self.listen_display_destroy);
@ -73,7 +73,7 @@ fn bind(wl_client: ?*c.wl_client, data: ?*c_void, version: u32, id: u32) callcon
c.wl_client_post_no_memory(wl_client);
return;
};
self.args_map.putNoClobber(id, std.ArrayList([]const u8).init(util.allocator)) catch {
self.args_map.putNoClobber(id, std.ArrayList([]const u8).init(util.gpa)) catch {
c.wl_resource_destroy(wl_resource);
c.wl_client_post_no_memory(wl_client);
return;
@ -98,14 +98,14 @@ fn addArgument(wl_client: ?*c.wl_client, wl_resource: ?*c.wl_resource, arg: ?[*:
const self = util.voidCast(Self, c.wl_resource_get_user_data(wl_resource).?);
const id = c.wl_resource_get_id(wl_resource);
const owned_slice = std.mem.dupe(util.allocator, u8, std.mem.span(arg.?)) catch {
const owned_slice = std.mem.dupe(util.gpa, u8, std.mem.span(arg.?)) catch {
c.wl_client_post_no_memory(wl_client);
return;
};
self.args_map.get(id).?.value.append(owned_slice) catch {
c.wl_client_post_no_memory(wl_client);
util.allocator.free(owned_slice);
util.gpa.free(owned_slice);
return;
};
}
@ -135,14 +135,14 @@ fn runCommand(
const args = self.args_map.get(c.wl_resource_get_id(wl_resource)).?.value.items;
var failure_message: []const u8 = undefined;
command.run(util.allocator, seat, args, &failure_message) catch |err| {
command.run(util.gpa, seat, args, &failure_message) catch |err| {
if (err == command.Error.CommandFailed) {
defer util.allocator.free(failure_message);
const out = std.cstr.addNullByte(util.allocator, failure_message) catch {
defer util.gpa.free(failure_message);
const out = std.cstr.addNullByte(util.gpa, failure_message) catch {
c.zriver_command_callback_v1_send_failure(callback_resource, "out of memory");
return;
};
defer util.allocator.free(out);
defer util.gpa.free(out);
c.zriver_command_callback_v1_send_failure(callback_resource, out);
} else {
c.zriver_command_callback_v1_send_failure(

View file

@ -53,7 +53,7 @@ fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const node = @fieldParentPtr(std.SinglyLinkedList(Self).Node, "data", self);
self.decoration_manager.decorations.remove(node);
util.allocator.destroy(node);
util.gpa.destroy(node);
}
fn handleRequestMode(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {

View file

@ -46,7 +46,7 @@ fn handleNewToplevelDecoration(listener: ?*c.wl_listener, data: ?*c_void) callco
const self = @fieldParentPtr(Self, "listen_new_toplevel_decoration", listener.?);
const wlr_xdg_toplevel_decoration = util.voidCast(c.wlr_xdg_toplevel_decoration_v1, data.?);
const node = self.decorations.allocateNode(util.allocator) catch unreachable;
const node = self.decorations.allocateNode(util.gpa) catch unreachable;
node.data.init(self, wlr_xdg_toplevel_decoration);
self.decorations.prepend(node);
}

View file

@ -51,7 +51,7 @@ pub fn init(self: *Self, server: *Server) !void {
self.seats = std.TailQueue(Seat).init();
const seat_node = try util.allocator.create(std.TailQueue(Seat).Node);
const seat_node = try util.gpa.create(std.TailQueue(Seat).Node);
try seat_node.data.init(self, default_seat_name);
self.default_seat = &seat_node.data;
self.seats.prepend(seat_node);
@ -78,7 +78,7 @@ pub fn init(self: *Self, server: *Server) !void {
pub fn deinit(self: *Self) void {
while (self.seats.pop()) |seat_node| {
seat_node.data.deinit();
util.allocator.destroy(seat_node);
util.gpa.destroy(seat_node);
}
}

View file

@ -87,7 +87,7 @@ fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
c.wl_list_remove(&self.listen_unmap.link);
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
util.allocator.destroy(node);
util.gpa.destroy(node);
}
fn handleMap(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
@ -191,6 +191,6 @@ fn handleNewPopup(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const wlr_xdg_popup = util.voidCast(c.wlr_xdg_popup, data.?);
// This will free itself on destroy
var xdg_popup = util.allocator.create(XdgPopup) catch unreachable;
var xdg_popup = util.gpa.create(XdgPopup) catch unreachable;
xdg_popup.init(self.output, &self.box, wlr_xdg_popup);
}

View file

@ -111,7 +111,7 @@ pub fn init(self: *Self, root: *Root, wlr_output: *c.wlr_output) !void {
self.master_factor = 0.6;
self.layout = try std.fmt.allocPrint(util.allocator, "full", .{});
self.layout = try std.fmt.allocPrint(util.gpa, "full", .{});
self.status_trackers = std.SinglyLinkedList(OutputStatus).init();
@ -234,7 +234,7 @@ fn layoutExternal(self: *Self, visible_count: u32, output_tags: u32) !void {
const layout_width = @intCast(u32, self.usable_box.width) - config.outer_padding * 2;
const layout_height = @intCast(u32, self.usable_box.height) - config.outer_padding * 2;
var arena = std.heap.ArenaAllocator.init(util.allocator);
var arena = std.heap.ArenaAllocator.init(util.gpa);
defer arena.deinit();
// Assemble command
@ -619,7 +619,7 @@ fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
// Remove the destroyed output from the list
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
root.outputs.remove(node);
util.allocator.destroy(node);
util.gpa.destroy(node);
// Arrange the root in case evacuated views affect the layout
root.arrange();

View file

@ -57,7 +57,7 @@ fn destroy(wl_client: ?*c.wl_client, wl_resource: ?*c.wl_resource) callconv(.C)
/// Send the current tags of each view on the output to the client.
pub fn sendViewTags(self: Self) void {
var view_tags = std.ArrayList(u32).init(util.allocator);
var view_tags = std.ArrayList(u32).init(util.gpa);
defer view_tags.deinit();
var it = ViewStack(View).iterator(self.output.views.first, std.math.maxInt(u32));

View file

@ -95,7 +95,7 @@ pub fn deinit(self: *Self) void {
pub fn addOutput(self: *Self, wlr_output: *c.wlr_output) void {
// TODO: Handle failure
const node = self.outputs.allocateNode(util.allocator) catch unreachable;
const node = self.outputs.allocateNode(util.gpa) catch unreachable;
node.data.init(self, wlr_output) catch unreachable;
self.outputs.append(node);

View file

@ -103,11 +103,11 @@ pub fn init(self: *Self, input_manager: *InputManager, name: []const u8) !void {
pub fn deinit(self: *Self) void {
self.cursor.deinit();
while (self.keyboards.pop()) |node| util.allocator.destroy(node);
while (self.keyboards.pop()) |node| util.gpa.destroy(node);
while (self.focus_stack.first) |node| {
self.focus_stack.remove(node);
util.allocator.destroy(node);
util.gpa.destroy(node);
}
}
@ -152,7 +152,7 @@ pub fn focus(self: *Self, _view: ?*View) void {
}
} else {
// The view is not in the stack, so allocate a new node and prepend it
const new_focus_node = util.allocator.create(
const new_focus_node = util.gpa.create(
ViewStack(*View).Node,
) catch unreachable;
new_focus_node.view = view_to_focus;
@ -256,7 +256,7 @@ pub fn handleViewUnmap(self: *Self, view: *View) void {
while (it) |node| : (it = node.next) {
if (node.view == view) {
self.focus_stack.remove(node);
util.allocator.destroy(node);
util.gpa.destroy(node);
break;
}
}
@ -277,10 +277,10 @@ pub fn handleMapping(self: *Self, keysym: c.xkb_keysym_t, modifiers: u32) bool {
if (modifiers == mapping.modifiers and keysym == mapping.keysym) {
// Execute the bound command
var failure_message: []const u8 = undefined;
command.run(util.allocator, self, mapping.command_args, &failure_message) catch |err| {
command.run(util.gpa, self, mapping.command_args, &failure_message) catch |err| {
// TODO: log the error
if (err == command.Error.CommandFailed)
util.allocator.free(failure_message);
util.gpa.free(failure_message);
};
return true;
}
@ -311,7 +311,7 @@ pub fn addDevice(self: *Self, device: *c.wlr_input_device) !void {
fn addKeyboard(self: *Self, device: *c.wlr_input_device) !void {
c.wlr_seat_set_keyboard(self.wlr_seat, device);
const node = try util.allocator.create(std.TailQueue(Keyboard).Node);
const node = try util.gpa.create(std.TailQueue(Keyboard).Node);
try node.data.init(self, device);
self.keyboards.append(node);
}

View file

@ -186,7 +186,7 @@ fn handleNewXdgSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) v
// The View will add itself to the output's view stack on map
const output = self.input_manager.default_seat.focused_output;
const node = util.allocator.create(ViewStack(View).Node) catch unreachable;
const node = util.gpa.create(ViewStack(View).Node) catch unreachable;
node.view.init(output, output.current_focused_tags, wlr_xdg_surface);
}
@ -236,7 +236,7 @@ fn handleNewLayerSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C)
// The layer surface will add itself to the proper list of the output on map
const output = util.voidCast(Output, wlr_layer_surface.output.*.data.?);
const node = util.allocator.create(std.TailQueue(LayerSurface).Node) catch unreachable;
const node = util.gpa.create(std.TailQueue(LayerSurface).Node) catch unreachable;
node.data.init(output, wlr_layer_surface);
}
@ -248,7 +248,7 @@ fn handleNewXwaylandSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(
log.debug(.server, "new unmanaged xwayland surface", .{});
// The unmanged surface will add itself to the list of unmanaged views
// in Root when it is mapped.
const node = util.allocator.create(std.TailQueue(XwaylandUnmanaged).Node) catch unreachable;
const node = util.gpa.create(std.TailQueue(XwaylandUnmanaged).Node) catch unreachable;
node.data.init(&self.root, wlr_xwayland_surface);
return;
}
@ -261,6 +261,6 @@ fn handleNewXwaylandSurface(listener: ?*c.wl_listener, data: ?*c_void) callconv(
// The View will add itself to the output's view stack on map
const output = self.input_manager.default_seat.focused_output;
const node = util.allocator.create(ViewStack(View).Node) catch unreachable;
const node = util.gpa.create(ViewStack(View).Node) catch unreachable;
node.view.init(output, output.current_focused_tags, wlr_xwayland_surface);
}

View file

@ -93,7 +93,7 @@ fn getRiverOutputStatus(
const wlr_output = c.wlr_output_from_resource(output_wl_resource) orelse return;
const output = util.voidCast(Output, wlr_output.*.data.?);
const node = util.allocator.create(std.SinglyLinkedList(OutputStatus).Node) catch {
const node = util.gpa.create(std.SinglyLinkedList(OutputStatus).Node) catch {
c.wl_client_post_no_memory(wl_client);
log.crit(.river_status, "out of memory", .{});
return;
@ -106,7 +106,7 @@ fn getRiverOutputStatus(
new_id,
) orelse {
c.wl_client_post_no_memory(wl_client);
util.allocator.destroy(node);
util.gpa.destroy(node);
log.crit(.river_status, "out of memory", .{});
return;
};
@ -126,7 +126,7 @@ fn getRiverSeatStatus(
const wlr_seat_client = c.wlr_seat_client_from_resource(seat_wl_resource) orelse return;
const seat = util.voidCast(Seat, wlr_seat_client.*.seat.*.data.?);
const node = util.allocator.create(std.SinglyLinkedList(SeatStatus).Node) catch {
const node = util.gpa.create(std.SinglyLinkedList(SeatStatus).Node) catch {
c.wl_client_post_no_memory(wl_client);
log.crit(.river_status, "out of memory", .{});
return;
@ -139,7 +139,7 @@ fn getRiverSeatStatus(
new_id,
) orelse {
c.wl_client_post_no_memory(wl_client);
util.allocator.destroy(node);
util.gpa.destroy(node);
log.crit(.river_status, "out of memory", .{});
return;
};

View file

@ -108,7 +108,7 @@ pub fn init(self: *Self, output: *Output, tags: u32, surface: var) void {
self.pending_serial = null;
self.saved_buffers = std.ArrayList(SavedBuffer).init(util.allocator);
self.saved_buffers = std.ArrayList(SavedBuffer).init(util.gpa);
if (@TypeOf(surface) == *c.wlr_xdg_surface) {
self.impl = .{ .xdg_toplevel = undefined };
@ -318,5 +318,5 @@ pub fn unmap(self: *Self) void {
pub fn destroy(self: *const Self) void {
self.deinit();
const node = @fieldParentPtr(ViewStack(Self).Node, "view", self);
util.allocator.destroy(node);
util.gpa.destroy(node);
}

View file

@ -67,7 +67,7 @@ fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
c.wl_list_remove(&self.listen_destroy.link);
c.wl_list_remove(&self.listen_new_popup.link);
util.allocator.destroy(self);
util.gpa.destroy(self);
}
/// Called when a new xdg popup is requested by the client
@ -76,6 +76,6 @@ fn handleNewPopup(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const wlr_xdg_popup = util.voidCast(c.wlr_xdg_popup, data.?);
// This will free itself on destroy
var xdg_popup = util.allocator.create(Self) catch unreachable;
var xdg_popup = util.gpa.create(Self) catch unreachable;
xdg_popup.init(self.output, self.parent_box, wlr_xdg_popup);
}

View file

@ -246,6 +246,6 @@ fn handleNewPopup(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
const wlr_xdg_popup = util.voidCast(c.wlr_xdg_popup, data.?);
// This will free itself on destroy
var xdg_popup = util.allocator.create(XdgPopup) catch unreachable;
var xdg_popup = util.gpa.create(XdgPopup) catch unreachable;
xdg_popup.init(self.view.output, &self.view.current_box, wlr_xdg_popup);
}

View file

@ -92,7 +92,7 @@ fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
// Deallocate the node
const node = @fieldParentPtr(std.TailQueue(Self).Node, "data", self);
util.allocator.destroy(node);
util.gpa.destroy(node);
}
/// Called when the xwayland surface is mapped, or ready to display on-screen.

View file

@ -77,7 +77,7 @@ pub fn main() !void {
if (startup_command) |cmd| {
const child_args = [_][]const u8{ "/bin/sh", "-c", cmd };
const child = try std.ChildProcess.init(&child_args, util.allocator);
const child = try std.ChildProcess.init(&child_args, util.gpa);
defer child.deinit();
try std.ChildProcess.spawn(child);
}

View file

@ -18,7 +18,7 @@
const std = @import("std");
/// The global general-purpose allocator used throughout river's code
pub const allocator = std.heap.c_allocator;
pub const gpa = std.heap.c_allocator;
/// Take a pointer to c_void and cast it to a pointer to T. This function
/// exists to avoid having the verbosity of the required alignment casts all