diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-01-07 22:28:24 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-07 22:28:24 -0800 |
| commit | 3176fdc0b921b36ee7d8346ef302d0817b980cfa (patch) | |
| tree | 213a34bd1618ff429ec54efbc6652b2ee9940ff9 /lib/std | |
| parent | 2115d7d1beeba32f975d8a032e5f5068e96e74f4 (diff) | |
| parent | 01b48e938198a206b95ed06f3a7e530e859c1cbc (diff) | |
| download | zig-3176fdc0b921b36ee7d8346ef302d0817b980cfa.tar.gz zig-3176fdc0b921b36ee7d8346ef302d0817b980cfa.zip | |
Merge pull request #18470 from castholm/typeInfo-sentinels
Make `@typeInfo` return null-terminated strings
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/builtin.zig | 10 | ||||
| -rw-r--r-- | lib/std/enums.zig | 2 | ||||
| -rw-r--r-- | lib/std/io.zig | 2 | ||||
| -rw-r--r-- | lib/std/meta.zig | 6 |
4 files changed, 10 insertions, 10 deletions
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 19c704c9a5..24c6036d60 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -314,7 +314,7 @@ pub const Type = union(enum) { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. pub const StructField = struct { - name: []const u8, + name: [:0]const u8, type: type, default_value: ?*const anyopaque, is_comptime: bool, @@ -348,7 +348,7 @@ pub const Type = union(enum) { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. pub const Error = struct { - name: []const u8, + name: [:0]const u8, }; /// This data structure is used by the Zig language code generation and @@ -358,7 +358,7 @@ pub const Type = union(enum) { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. pub const EnumField = struct { - name: []const u8, + name: [:0]const u8, value: comptime_int, }; @@ -374,7 +374,7 @@ pub const Type = union(enum) { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. pub const UnionField = struct { - name: []const u8, + name: [:0]const u8, type: type, alignment: comptime_int, }; @@ -436,7 +436,7 @@ pub const Type = union(enum) { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. pub const Declaration = struct { - name: []const u8, + name: [:0]const u8, }; }; diff --git a/lib/std/enums.zig b/lib/std/enums.zig index 839781ffb7..872b752a40 100644 --- a/lib/std/enums.zig +++ b/lib/std/enums.zig @@ -14,7 +14,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def var fields: []const StructField = &[_]StructField{}; for (std.meta.fields(E)) |field| { fields = fields ++ &[_]StructField{.{ - .name = field.name, + .name = field.name ++ "", .type = Data, .default_value = if (field_default) |d| @as(?*const anyopaque, @ptrCast(&d)) else null, .is_comptime = false, diff --git a/lib/std/io.zig b/lib/std/io.zig index e19b2e0e16..912e834a75 100644 --- a/lib/std/io.zig +++ b/lib/std/io.zig @@ -635,7 +635,7 @@ pub fn PollFiles(comptime StreamEnum: type) type { var struct_fields: [enum_fields.len]std.builtin.Type.StructField = undefined; for (&struct_fields, enum_fields) |*struct_field, enum_field| { struct_field.* = .{ - .name = enum_field.name, + .name = enum_field.name ++ "", .type = fs.File, .default_value = null, .is_comptime = false, diff --git a/lib/std/meta.zig b/lib/std/meta.zig index 5531242e30..94d5f962bc 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -556,7 +556,7 @@ pub fn FieldEnum(comptime T: type) type { var decls = [_]std.builtin.Type.Declaration{}; inline for (field_infos, 0..) |field, i| { enumFields[i] = .{ - .name = field.name, + .name = field.name ++ "", .value = i, }; } @@ -628,7 +628,7 @@ pub fn DeclEnum(comptime T: type) type { var enumDecls: [fieldInfos.len]std.builtin.Type.EnumField = undefined; var decls = [_]std.builtin.Type.Declaration{}; inline for (fieldInfos, 0..) |field, i| { - enumDecls[i] = .{ .name = field.name, .value = i }; + enumDecls[i] = .{ .name = field.name ++ "", .value = i }; } return @Type(.{ .Enum = .{ @@ -1015,7 +1015,7 @@ fn CreateUniqueTuple(comptime N: comptime_int, comptime types: [N]type) type { @setEvalBranchQuota(10_000); var num_buf: [128]u8 = undefined; tuple_fields[i] = .{ - .name = std.fmt.bufPrint(&num_buf, "{d}", .{i}) catch unreachable, + .name = std.fmt.bufPrintZ(&num_buf, "{d}", .{i}) catch unreachable, .type = T, .default_value = null, .is_comptime = false, |
