-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
change field names in @typeInfo
to be [:0]const u8
(null-terminated) instead of []const u8
#16072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is the current blocker for Bun to upgrade Zig Unrelated: there's an issue with GenericPoison that hadn't happened in zig of a month ago when passing an anytype param to a function pointer when the type is known at comptime |
I think I've found the code responsible for this! I'm going to keep at it for a few more hours and if I don't have a fix tonight I'll post my findings. |
Well I haven't been able to get it to work. I was looking in Sema.zig: zirTypeInfo, under the The last patch I tried was this: diff --git a/src/Sema.zig b/src/Sema.zig
index 36fe5a6ee..fc8dff605 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -17234,9 +17234,9 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
// TODO: write something like getCoercedInts to avoid needing to dupe
const bytes = if (tuple.names.len != 0)
// https://github.com/ziglang/zig/issues/15709
- try sema.arena.dupe(u8, ip.stringToSlice(ip.indexToKey(struct_ty.toIntern()).anon_struct_type.names[i]))
+ try sema.arena.dupeZ(u8, ip.stringToSlice(ip.indexToKey(struct_ty.toIntern()).anon_struct_type.names[i]))
else
- try std.fmt.allocPrint(sema.arena, "{d}", .{i});
+ try std.fmt.allocPrintZ(sema.arena, "{d}", .{i});
const new_decl_ty = try mod.arrayType(.{
.len = bytes.len,
.child = .u8_type,
@@ -17290,7 +17290,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
struct_obj.fields.values(),
) |*field_val, name_nts, field| {
// TODO: write something like getCoercedInts to avoid needing to dupe
- const name = try sema.arena.dupe(u8, ip.stringToSlice(name_nts));
+ const name = try sema.arena.dupeZ(u8, ip.stringToSlice(name_nts));
const name_val = v: {
var anon_decl = try block.startAnonDecl();
defer anon_decl.deinit(); Trying to update the values without updating the types. But this seemed to have no effect. |
I'm passing field names to the win32 GetProcAddress function and plan on doing something similar to load Vulkan symbols. Null-terminated strings are very helpful here. |
I'm a bit confused here; the type of field names has always been Line 316 in 9eb0087
That said, if we consider this a proposal to change that to be |
@typeInfo
no longer contain null terminator \x00
.@typeInfo
to be [:0]const u8
(null-terminated) instead of []const u8
Sounds like a case of Hryum’s Law
…On Tue, Jun 20, 2023 at 11:43 AM Andrew Kelley ***@***.***> wrote:
I'm a bit confused here; the type of field names has always been []const
u8, so I'm not sure where y'all think this null terminator was coming
from.
https://github.com/ziglang/zig/blob/9eb008717b2786e885f4110503dc461d0bf2e682/lib/std/builtin.zig#L316
That said, if we consider this a proposal to change that to be name:
[:0]const u8 instead, then I'm in favor of that.
—
Reply to this email directly, view it on GitHub
<#16072 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFNGS6END6J7MX4W2EYQALXMHVONANCNFSM6AAAAAAZKDIGJU>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
There is also #9182 |
Zig Version
0.11.0-dev.3655+a2f54fce5
worked in0.11.0-dev.3395+1e7dcaa3a
Steps to Reproduce and Observed Behavior
Output:
In my project I was using field names to automatically generate calls to OpenGL's
glGetUniformLocation
.Expected Behavior
I expect field names to be null-terminated, given that most other compiler-generated strings(string literals,
@embedFile
,@errorName
) are also null-terminated for C compatibility.The text was updated successfully, but these errors were encountered: