aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2022-10-16 14:44:51 -0400
committerAndrew Kelley <andrew@ziglang.org>2022-10-17 07:50:01 -0400
commit1e0f74a9e6a9071bfb82fa3ce5a40ac90bdb91cd (patch)
tree0130fa70beea11de638540bc095522364b145fa3
parent059e397ffcf5ad348dae6de1cd552f8a742a2fbc (diff)
downloadzig-1e0f74a9e6a9071bfb82fa3ce5a40ac90bdb91cd.tar.gz
zig-1e0f74a9e6a9071bfb82fa3ce5a40ac90bdb91cd.zip
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.
-rw-r--r--lib/compiler_rt/emutls.zig11
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/compiler_rt/emutls.zig b/lib/compiler_rt/emutls.zig
index 2a49fa564f..379be7e23f 100644
--- a/lib/compiler_rt/emutls.zig
+++ b/lib/compiler_rt/emutls.zig
@@ -141,7 +141,7 @@ const ObjectArray = struct {
if (control.default_value) |value| {
// default value: copy the content to newly allocated object.
- @memcpy(data, @ptrCast([*]u8, value), size);
+ @memcpy(data, @ptrCast([*]const u8, value), size);
} else {
// no default: return zeroed memory.
@memset(data, 0, size);
@@ -236,7 +236,7 @@ const emutls_control = extern struct {
},
// null or non-zero initial value for the object
- default_value: ?*anyopaque,
+ default_value: ?*const anyopaque,
// global Mutex used to serialize control.index initialization.
var mutex: std.c.pthread_mutex_t = std.c.PTHREAD_MUTEX_INITIALIZER;
@@ -291,7 +291,7 @@ const emutls_control = extern struct {
}
/// Simple helper for testing purpose.
- pub fn init(comptime T: type, default_value: ?*T) emutls_control {
+ pub fn init(comptime T: type, default_value: ?*const T) emutls_control {
return emutls_control{
.size = @sizeOf(T),
.alignment = @alignOf(T),
@@ -362,7 +362,7 @@ test "__emutls_get_address zeroed" {
test "__emutls_get_address with default_value" {
if (!builtin.link_libc or builtin.os.tag != .openbsd) return error.SkipZigTest;
- var value: usize = 5678; // default value
+ const value: usize = 5678; // default value
var ctl = emutls_control.init(usize, &value);
try expect(ctl.object.index == 0);
@@ -384,8 +384,7 @@ test "test default_value with differents sizes" {
const testType = struct {
fn _testType(comptime T: type, value: T) !void {
- var def: T = value;
- var ctl = emutls_control.init(T, &def);
+ var ctl = emutls_control.init(T, &value);
var x = ctl.get_typed_pointer(T);
try expect(x.* == value);
}