authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-10-16 14:44:51-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-17 07:50:01-04:00
log1e0f74a9e6a9071bfb82fa3ce5a40ac90bdb91cd
tree0130fa70beea11de638540bc095522364b145fa3
parent059e397ffcf5ad348dae6de1cd552f8a742a2fbc

emutls: add const to default_value field

Commit f14cc75 accidentally added a const when grepping for assignments to `std.builtin.Type.StructField.default_value`, however when looking into it further, I noticed that even though this default_value field is emitted into the .data section, the value it points to is actually emitted into the .rodata section, so it seems correct to use const here.

1 files changed, 5 insertions(+), 6 deletions(-)

lib/compiler_rt/emutls.zig+5-6
......@@ -141,7 +141,7 @@ const ObjectArray = struct {
141141
142142 if (control.default_value) |value| {
143143 // default value: copy the content to newly allocated object.
144 @memcpy(data, @ptrCast([*]u8, value), size);
144 @memcpy(data, @ptrCast([*]const u8, value), size);
145145 } else {
146146 // no default: return zeroed memory.
147147 @memset(data, 0, size);
......@@ -236,7 +236,7 @@ const emutls_control = extern struct {
236236 },
237237
238238 // null or non-zero initial value for the object
239 default_value: ?*anyopaque,
239 default_value: ?*const anyopaque,
240240
241241 // global Mutex used to serialize control.index initialization.
242242 var mutex: std.c.pthread_mutex_t = std.c.PTHREAD_MUTEX_INITIALIZER;
......@@ -291,7 +291,7 @@ const emutls_control = extern struct {
291291 }
292292
293293 /// Simple helper for testing purpose.
294 pub fn init(comptime T: type, default_value: ?*T) emutls_control {
294 pub fn init(comptime T: type, default_value: ?*const T) emutls_control {
295295 return emutls_control{
296296 .size = @sizeOf(T),
297297 .alignment = @alignOf(T),
......@@ -362,7 +362,7 @@ test "__emutls_get_address zeroed" {
362362test "__emutls_get_address with default_value" {
363363 if (!builtin.link_libc or builtin.os.tag != .openbsd) return error.SkipZigTest;
364364
365 var value: usize = 5678; // default value
365 const value: usize = 5678; // default value
366366 var ctl = emutls_control.init(usize, &value);
367367 try expect(ctl.object.index == 0);
368368
......@@ -384,8 +384,7 @@ test "test default_value with differents sizes" {
384384
385385 const testType = struct {
386386 fn _testType(comptime T: type, value: T) !void {
387 var def: T = value;
388 var ctl = emutls_control.init(T, &def);
387 var ctl = emutls_control.init(T, &value);
389388 var x = ctl.get_typed_pointer(T);
390389 try expect(x.* == value);
391390 }