markused: add _result_ok (#14495)

master
Daniel Däschle 2022-05-22 13:52:38 +02:00 committed by GitHub
parent 3647fb4def
commit d3ffd983c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 10 deletions

View File

@ -113,14 +113,6 @@ struct Option {
// derived Option_xxx types // derived Option_xxx types
} }
fn opt_ok(data voidptr, mut option Option, size int) {
unsafe {
*option = Option{}
// use err to get the end of OptionBase and then memcpy into it
vmemcpy(&u8(&option.err) + sizeof(IError), data, size)
}
}
// option is the base of V's internal optional return system. // option is the base of V's internal optional return system.
struct _option { struct _option {
state u8 state u8
@ -130,6 +122,14 @@ struct _option {
// derived _option_xxx types // derived _option_xxx types
} }
fn _option_ok(data voidptr, mut option _option, size int) {
unsafe {
*option = _option{}
// use err to get the end of OptionBase and then memcpy into it
vmemcpy(&u8(&option.err) + sizeof(IError), data, size)
}
}
fn opt_ok2(data voidptr, mut option _option, size int) { fn opt_ok2(data voidptr, mut option _option, size int) {
unsafe { unsafe {
*option = _option{} *option = _option{}

View File

@ -5237,7 +5237,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty
styp := g.typ(g.fn_decl.return_type) styp := g.typ(g.fn_decl.return_type)
err_obj := g.new_tmp_var() err_obj := g.new_tmp_var()
g.writeln('\t$styp $err_obj;') g.writeln('\t$styp $err_obj;')
g.writeln('\tmemcpy(&$err_obj, &$cvar_name, sizeof(Option));') g.writeln('\tmemcpy(&$err_obj, &$cvar_name, sizeof(_option));')
g.writeln('\treturn $err_obj;') g.writeln('\treturn $err_obj;')
} }
} }

View File

@ -35,8 +35,9 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.F
'tos2', 'tos2',
'tos3', 'tos3',
'isnil', 'isnil',
'opt_ok',
'opt_ok2', 'opt_ok2',
'_option_ok',
'_result_ok',
'error', 'error',
// utf8_str_visible_length is used by c/str.v // utf8_str_visible_length is used by c/str.v
'utf8_str_visible_length', 'utf8_str_visible_length',