| ... | ... | @@ -376,11 +376,16 @@ const PosixThreadImpl = struct { |
| 376 | 376 | fn spawn(config: SpawnConfig, comptime f: anytype, args: anytype) !Impl { |
| 377 | 377 | const Args = @TypeOf(args); |
| 378 | 378 | const allocator = std.heap.c_allocator; |
| 379 | |
| 379 | 380 | const Instance = struct { |
| 380 | 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 | | defer allocator.destroy(args_ptr); |
| 383 | | return callFn(f, args_ptr.*); |
| 382 | if (@sizeOf(Args) < 1) { |
| 383 | return callFn(f, @as(Args, undefined)); |
| 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 | 407 | &handle, |
| 403 | 408 | &attr, |
| 404 | 409 | Instance.entryFn, |
| 405 | | @ptrCast(*c_void, args_ptr), |
| 410 | if (@sizeOf(Args) > 1) @ptrCast(*c_void, args_ptr) else undefined, |
| 406 | 411 | )) { |
| 407 | 412 | 0 => return Impl{ .handle = handle }, |
| 408 | 413 | os.EAGAIN => return error.SystemResources, |