authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-04-20 10:31:02+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-25 13:21:15-04:00
log5a94794b73c8f9d042bc7928d071cc1004487983
tree8e1ed3d94464ccf97088dfc6c5c2d0cc8c262fd0
parent3a55cda14d38a2f83e3c6a9ecb782fcb81d1347d

std: Fix thread creation with field-less context type

Closes #8524

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

lib/std/Thread.zig+6-3
...@@ -199,7 +199,8 @@ pub fn spawn(comptime startFn: anytype, context: SpawnContextType(@TypeOf(startF...@@ -199,7 +199,8 @@ pub fn spawn(comptime startFn: anytype, context: SpawnContextType(@TypeOf(startF
199 inner: Context,199 inner: Context,
200 };200 };
201 fn threadMain(raw_arg: windows.LPVOID) callconv(.C) windows.DWORD {201 fn threadMain(raw_arg: windows.LPVOID) callconv(.C) windows.DWORD {
202 const arg = if (@sizeOf(Context) == 0) {} else @ptrCast(*Context, @alignCast(@alignOf(Context), raw_arg)).*;202 const arg = if (@sizeOf(Context) == 0) undefined //
203 else @ptrCast(*Context, @alignCast(@alignOf(Context), raw_arg)).*;
203204
204 switch (@typeInfo(@typeInfo(@TypeOf(startFn)).Fn.return_type.?)) {205 switch (@typeInfo(@typeInfo(@TypeOf(startFn)).Fn.return_type.?)) {
205 .NoReturn => {206 .NoReturn => {
...@@ -260,7 +261,8 @@ pub fn spawn(comptime startFn: anytype, context: SpawnContextType(@TypeOf(startF...@@ -260,7 +261,8 @@ pub fn spawn(comptime startFn: anytype, context: SpawnContextType(@TypeOf(startF
260261
261 const MainFuncs = struct {262 const MainFuncs = struct {
262 fn linuxThreadMain(ctx_addr: usize) callconv(.C) u8 {263 fn linuxThreadMain(ctx_addr: usize) callconv(.C) u8 {
263 const arg = if (@sizeOf(Context) == 0) {} else @intToPtr(*const Context, ctx_addr).*;264 const arg = if (@sizeOf(Context) == 0) undefined //
265 else @intToPtr(*Context, ctx_addr).*;
264266
265 switch (@typeInfo(@typeInfo(@TypeOf(startFn)).Fn.return_type.?)) {267 switch (@typeInfo(@typeInfo(@TypeOf(startFn)).Fn.return_type.?)) {
266 .NoReturn => {268 .NoReturn => {
...@@ -292,7 +294,8 @@ pub fn spawn(comptime startFn: anytype, context: SpawnContextType(@TypeOf(startF...@@ -292,7 +294,8 @@ pub fn spawn(comptime startFn: anytype, context: SpawnContextType(@TypeOf(startF
292 }294 }
293 }295 }
294 fn posixThreadMain(ctx: ?*c_void) callconv(.C) ?*c_void {296 fn posixThreadMain(ctx: ?*c_void) callconv(.C) ?*c_void {
295 const arg = if (@sizeOf(Context) == 0) {} else @ptrCast(*Context, @alignCast(@alignOf(Context), ctx)).*;297 const arg = if (@sizeOf(Context) == 0) undefined //
298 else @ptrCast(*Context, @alignCast(@alignOf(Context), ctx)).*;
296299
297 switch (@typeInfo(@typeInfo(@TypeOf(startFn)).Fn.return_type.?)) {300 switch (@typeInfo(@typeInfo(@TypeOf(startFn)).Fn.return_type.?)) {
298 .NoReturn => {301 .NoReturn => {