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 {...@@ -141,7 +141,7 @@ const ObjectArray = struct {
141141
142 if (control.default_value) |value| {142 if (control.default_value) |value| {
143 // default value: copy the content to newly allocated object.143 // default value: copy the content to newly allocated object.
144 @memcpy(data, @ptrCast([*]u8, value), size);144 @memcpy(data, @ptrCast([*]const u8, value), size);
145 } else {145 } else {
146 // no default: return zeroed memory.146 // no default: return zeroed memory.
147 @memset(data, 0, size);147 @memset(data, 0, size);
...@@ -236,7 +236,7 @@ const emutls_control = extern struct {...@@ -236,7 +236,7 @@ const emutls_control = extern struct {
236 },236 },
237237
238 // null or non-zero initial value for the object238 // null or non-zero initial value for the object
239 default_value: ?*anyopaque,239 default_value: ?*const anyopaque,
240240
241 // global Mutex used to serialize control.index initialization.241 // global Mutex used to serialize control.index initialization.
242 var mutex: std.c.pthread_mutex_t = std.c.PTHREAD_MUTEX_INITIALIZER;242 var mutex: std.c.pthread_mutex_t = std.c.PTHREAD_MUTEX_INITIALIZER;
...@@ -291,7 +291,7 @@ const emutls_control = extern struct {...@@ -291,7 +291,7 @@ const emutls_control = extern struct {
291 }291 }
292292
293 /// Simple helper for testing purpose.293 /// 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 {
295 return emutls_control{295 return emutls_control{
296 .size = @sizeOf(T),296 .size = @sizeOf(T),
297 .alignment = @alignOf(T),297 .alignment = @alignOf(T),
...@@ -362,7 +362,7 @@ test "__emutls_get_address zeroed" {...@@ -362,7 +362,7 @@ test "__emutls_get_address zeroed" {
362test "__emutls_get_address with default_value" {362test "__emutls_get_address with default_value" {
363 if (!builtin.link_libc or builtin.os.tag != .openbsd) return error.SkipZigTest;363 if (!builtin.link_libc or builtin.os.tag != .openbsd) return error.SkipZigTest;
364364
365 var value: usize = 5678; // default value365 const value: usize = 5678; // default value
366 var ctl = emutls_control.init(usize, &value);366 var ctl = emutls_control.init(usize, &value);
367 try expect(ctl.object.index == 0);367 try expect(ctl.object.index == 0);
368368
...@@ -384,8 +384,7 @@ test "test default_value with differents sizes" {...@@ -384,8 +384,7 @@ test "test default_value with differents sizes" {
384384
385 const testType = struct {385 const testType = struct {
386 fn _testType(comptime T: type, value: T) !void {386 fn _testType(comptime T: type, value: T) !void {
387 var def: T = value;387 var ctl = emutls_control.init(T, &value);
388 var ctl = emutls_control.init(T, &def);
389 var x = ctl.get_typed_pointer(T);388 var x = ctl.get_typed_pointer(T);
390 try expect(x.* == value);389 try expect(x.* == value);
391 }390 }