| author | |
| committer | |
| log | 32a77a6047d378e3bf5b9e8d071f182dc64823f8 |
| tree | 4a99d0c2b2599095c1af48365d5e445cbefe66ed |
| parent | 41bbadbb9a27107da539e27e175f5bdb52656bd5 |
| parent | abe672956ed037077b23ac6aa29df3dd99795539 |
| signature |
Support allocating 0 bit types2 files changed, 5 insertions(+), 1 deletions(-)
lib/std/heap.zig+4| ... | ... | @@ -915,6 +915,10 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void { |
| 915 | 915 | testing.expect(slice.len == 10); |
| 916 | 916 | |
| 917 | 917 | allocator.free(slice); |
| 918 | ||
| 919 | const zero_bit_ptr = try allocator.create(u0); | |
| 920 | zero_bit_ptr.* = 0; | |
| 921 | allocator.destroy(zero_bit_ptr); | |
| 918 | 922 | } |
| 919 | 923 | |
| 920 | 924 | pub fn testAllocatorAligned(base_allocator: *mem.Allocator, comptime alignment: u29) !void { |
lib/std/mem/Allocator.zig+1-1| ... | ... | @@ -159,7 +159,7 @@ fn moveBytes( |
| 159 | 159 | /// Returns a pointer to undefined memory. |
| 160 | 160 | /// Call `destroy` with the result to free the memory. |
| 161 | 161 | pub fn create(self: *Allocator, comptime T: type) Error!*T { |
| 162 | if (@sizeOf(T) == 0) return &(T{}); | |
| 162 | if (@sizeOf(T) == 0) return @as(*T, undefined); | |
| 163 | 163 | const slice = try self.allocAdvancedWithRetAddr(T, null, 1, .exact, @returnAddress()); |
| 164 | 164 | return &slice[0]; |
| 165 | 165 | } |