| ... | @@ -376,11 +376,16 @@ const PosixThreadImpl = struct { | ... | @@ -376,11 +376,16 @@ const PosixThreadImpl = struct { |
| 376 | fn spawn(config: SpawnConfig, comptime f: anytype, args: anytype) !Impl { | 376 | fn spawn(config: SpawnConfig, comptime f: anytype, args: anytype) !Impl { |
| 377 | const Args = @TypeOf(args); | 377 | const Args = @TypeOf(args); |
| 378 | const allocator = std.heap.c_allocator; | 378 | const allocator = std.heap.c_allocator; |
| | 379 | |
| 379 | const Instance = struct { | 380 | const Instance = struct { |
| 380 | fn entryFn(raw_arg: ?*c_void) callconv(.C) ?*c_void { | 381 | fn entryFn(raw_arg: ?*c_void) callconv(.C) ?*c_void { |
| 381 | const args_ptr = @ptrCast(*Args, @alignCast(@alignOf(Args), raw_arg orelse unreachable)); | 382 | if (@sizeOf(Args) < 1) { |
| 382 | defer allocator.destroy(args_ptr); | 383 | return callFn(f, @as(Args, undefined)); |
| 383 | return callFn(f, args_ptr.*); | 384 | } |
| | 385 | |
| | 386 | const args_ptr = @ptrCast(*Args, @alignCast(@alignOf(Args), raw_arg)); |
| | 387 | defer allocator.destroy(args_ptr); |
| | 388 | return callFn(f, args_ptr.*); |
| 384 | } | 389 | } |
| 385 | }; | 390 | }; |
| 386 | | 391 | |
| ... | @@ -402,7 +407,7 @@ const PosixThreadImpl = struct { | ... | @@ -402,7 +407,7 @@ const PosixThreadImpl = struct { |
| 402 | &handle, | 407 | &handle, |
| 403 | &attr, | 408 | &attr, |
| 404 | Instance.entryFn, | 409 | Instance.entryFn, |
| 405 | @ptrCast(*c_void, args_ptr), | 410 | if (@sizeOf(Args) > 1) @ptrCast(*c_void, args_ptr) else undefined, |
| 406 | )) { | 411 | )) { |
| 407 | 0 => return Impl{ .handle = handle }, | 412 | 0 => return Impl{ .handle = handle }, |
| 408 | os.EAGAIN => return error.SystemResources, | 413 | os.EAGAIN => return error.SystemResources, |