Skip to content

Commit

Permalink
small cleanup after rebasing over master
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Jan 15, 2025
1 parent 29f1283 commit 1764442
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions vlib/v/gen/c/spawn_and_go.v
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
if g.pref.os == .windows && call_ret_type != ast.void_type {
g.writeln('${arg_tmp_var}->ret_ptr = (void *) _v_malloc(sizeof(${s_ret_typ}));')
}
gohandle_name := g.gen_gohandle_name(node.call_expr.return_type)
gohandle_name := g.gen_gohandle_name(call_ret_type)
if is_spawn {
if g.pref.os == .windows {
simple_handle := if node.is_expr && call_ret_type != ast.void_type {
Expand Down Expand Up @@ -228,12 +228,13 @@ fn (mut g Gen) create_waiter_handler(call_expr ast.CallExpr, s_ret_typ string, g
g.waiter_fn_definitions.writeln('${s_ret_typ} ${waiter_fn_name}(${gohandle_name} thread);')
g.gowrappers.writeln('\n${s_ret_typ} ${waiter_fn_name}(${gohandle_name} thread) {')
mut c_ret_ptr_ptr := 'NULL'
if call_expr.return_type != ast.void_type {
call_ret_type := call_expr.return_type
if call_ret_type != ast.void_type {
g.gowrappers.writeln('\t${s_ret_typ}* ret_ptr;')
c_ret_ptr_ptr = '&ret_ptr'
}
if g.pref.os == .windows {
if call_expr.return_type == ast.void_type {
if call_ret_type == ast.void_type {
g.gowrappers.writeln('\tu32 stat = WaitForSingleObject(thread, INFINITE);')
} else {
g.gowrappers.writeln('\tu32 stat = WaitForSingleObject(thread.handle, INFINITE);')
Expand All @@ -244,13 +245,13 @@ fn (mut g Gen) create_waiter_handler(call_expr ast.CallExpr, s_ret_typ string, g
}
g.gowrappers.writeln('\tif (stat != 0) { _v_panic(_SLIT("unable to join thread")); }')
if g.pref.os == .windows {
if call_expr.return_type == ast.void_type {
if call_ret_type == ast.void_type {
g.gowrappers.writeln('\tCloseHandle(thread);')
} else {
g.gowrappers.writeln('\tCloseHandle(thread.handle);')
}
}
if call_expr.return_type != ast.void_type {
if call_ret_type != ast.void_type {
g.gowrappers.writeln('\t${s_ret_typ} ret = *ret_ptr;')
g.gowrappers.writeln('\t_v_free(ret_ptr);')
g.gowrappers.writeln('\treturn ret;')
Expand All @@ -271,6 +272,7 @@ fn (mut g Gen) create_thread_type(call_expr ast.CallExpr, s_ret_typ string, name
}
wrapper_struct_name := 'thread_arg_' + name
wrapper_fn_name := name + '_thread_wrapper'
call_ret_type := call_expr.return_type

g.type_definitions.writeln('\ntypedef struct ${wrapper_struct_name} {')
mut fn_var := ''
Expand Down Expand Up @@ -326,7 +328,7 @@ fn (mut g Gen) create_thread_type(call_expr ast.CallExpr, s_ret_typ string, name
styp := g.styp(call_expr.receiver_type)
g.type_definitions.writeln('\t${styp} arg0;')
}
need_return_ptr := g.pref.os == .windows && call_expr.return_type != ast.void_type
need_return_ptr := g.pref.os == .windows && call_ret_type != ast.void_type
for i, arg in call_expr.args {
arg_sym := g.table.sym(arg.typ)
if arg_sym.info is ast.FnType {
Expand All @@ -345,7 +347,7 @@ fn (mut g Gen) create_thread_type(call_expr ast.CallExpr, s_ret_typ string, name
thread_ret_type := if g.pref.os == .windows { 'u32' } else { 'void*' }
g.type_definitions.writeln('${g.static_modifier} ${thread_ret_type} ${wrapper_fn_name}(${wrapper_struct_name} *arg);')
g.gowrappers.writeln('${thread_ret_type} ${wrapper_fn_name}(${wrapper_struct_name} *arg) {')
if call_expr.return_type != ast.void_type {
if call_ret_type != ast.void_type {
if g.pref.os == .windows {
g.gowrappers.write_string('\t*((${s_ret_typ}*)(arg->ret_ptr)) = ')
} else {
Expand Down Expand Up @@ -435,7 +437,7 @@ fn (mut g Gen) create_thread_type(call_expr ast.CallExpr, s_ret_typ string, name
if is_spawn {
g.gowrappers.writeln('\t_v_free(arg);')
}
if g.pref.os != .windows && call_expr.return_type != ast.void_type {
if g.pref.os != .windows && call_ret_type != ast.void_type {
g.gowrappers.writeln('\treturn ret_ptr;')
} else {
g.gowrappers.writeln('\treturn 0;')
Expand Down

0 comments on commit 1764442

Please sign in to comment.