| ... | @@ -141,7 +141,7 @@ const ObjectArray = struct { | ... | @@ -141,7 +141,7 @@ const ObjectArray = struct { |
| 141 | | 141 | |
| 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 | }, |
| 237 | | 237 | |
| 238 | // null or non-zero initial value for the object | 238 | // null or non-zero initial value for the object |
| 239 | default_value: ?*anyopaque, | 239 | default_value: ?*const anyopaque, |
| 240 | | 240 | |
| 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 | } |
| 292 | | 292 | |
| 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" { |
| 362 | test "__emutls_get_address with default_value" { | 362 | test "__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; |
| 364 | | 364 | |
| 365 | var value: usize = 5678; // default value | 365 | 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); |
| 368 | | 368 | |
| ... | @@ -384,8 +384,7 @@ test "test default_value with differents sizes" { | ... | @@ -384,8 +384,7 @@ test "test default_value with differents sizes" { |
| 384 | | 384 | |
| 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 | } |