| ... | ... | @@ -32,15 +32,7 @@ pub const Allocator = struct { |
| 32 | 32 | freeFn: fn (self: *Allocator, old_mem: []u8) void, |
| 33 | 33 | |
| 34 | 34 | /// Call destroy with the result |
| 35 | | pub fn create(self: *Allocator, comptime T: type) !*T { |
| 36 | | if (@sizeOf(T) == 0) return *{}; |
| 37 | | const slice = try self.alloc(T, 1); |
| 38 | | return &slice[0]; |
| 39 | | } |
| 40 | | |
| 41 | | /// Call destroy with the result |
| 42 | | /// TODO once #733 is solved, this will replace create |
| 43 | | pub fn construct(self: *Allocator, init: var) Error!*@typeOf(init) { |
| 35 | pub fn create(self: *Allocator, init: var) Error!*@typeOf(init) { |
| 44 | 36 | const T = @typeOf(init); |
| 45 | 37 | if (@sizeOf(T) == 0) return &{}; |
| 46 | 38 | const slice = try self.alloc(T, 1); |
| ... | ... | @@ -49,6 +41,13 @@ pub const Allocator = struct { |
| 49 | 41 | return ptr; |
| 50 | 42 | } |
| 51 | 43 | |
| 44 | /// Alias of create |
| 45 | /// Call destroy with the result |
| 46 | pub fn construct(self: *Allocator, init: var) Error!*@typeOf(init) { |
| 47 | debug.warn("std.mem.Allocator.construct is deprecated;\n"); |
| 48 | return self.create(init); |
| 49 | } |
| 50 | |
| 52 | 51 | /// `ptr` should be the return value of `construct` or `create` |
| 53 | 52 | pub fn destroy(self: *Allocator, ptr: var) void { |
| 54 | 53 | const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr)); |