aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorCarl Åstholm <carl@astholm.se>2024-01-07 15:35:18 +0100
committerCarl Åstholm <carl@astholm.se>2024-01-07 15:35:18 +0100
commita02bd81760166d679ccee0e190bf62115272ffbe (patch)
treee800cf9fec8bf55898a966ca2bae2d4707707db2 /lib/std
parent804cee3b93cb7084c16ee61d3bcb57f7d3c9f0bc (diff)
downloadzig-a02bd81760166d679ccee0e190bf62115272ffbe.tar.gz
zig-a02bd81760166d679ccee0e190bf62115272ffbe.zip
Make `@typeInfo` return null-terminated strings
Changes the types of `std.builtin.Type` `name` fields from `[]const u8` to `[:0]const u8`, which should make them easier to pass to C APIs expecting null-terminated strings. This will break code that reifies types using `[]const u8` strings, such as code that uses `std.mem.tokenize()` to construct types from strings at comptime. Luckily, the fix is simple: simply concatenate the `[]const u8` string with an empty string literal (`name ++ ""`) to explicitly coerce it to `[:0]const u8`. Co-authored-by: Krzysztof Wolicki <der.teufel.mail@gmail.com>
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/builtin.zig10
1 files changed, 5 insertions, 5 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,
};
};