fix zig argument passing changes in str module

This commit is contained in:
Folkert 2022-04-06 15:38:47 +02:00
parent a69bf971f0
commit 5e0b724854
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 23 additions and 7 deletions

View file

@ -5337,7 +5337,17 @@ fn run_low_level<'a, 'ctx, 'env>(
let string = load_symbol(scope, &args[0]); let string = load_symbol(scope, &args[0]);
call_bitcode_fn(env, &[string], intrinsic) let result = call_bitcode_fn(env, &[string], intrinsic);
// zig passes the result as a packed integer sometimes, instead of a struct. So we cast
let expected_type = basic_type_from_layout(env, layout);
let actual_type = result.get_type();
if expected_type != actual_type {
complex_bitcast_check_size(env, result, expected_type, "str_to_num_cast")
} else {
result
}
} }
StrFromInt => { StrFromInt => {
// Str.fromInt : Int -> Str // Str.fromInt : Int -> Str

View file

@ -155,16 +155,22 @@ pub fn str_from_utf8_range<'a, 'ctx, 'env>(
let result_type = env.module.get_struct_type("str.FromUtf8Result").unwrap(); let result_type = env.module.get_struct_type("str.FromUtf8Result").unwrap();
let result_ptr = builder.build_alloca(result_type, "alloca_utf8_validate_bytes_result"); let result_ptr = builder.build_alloca(result_type, "alloca_utf8_validate_bytes_result");
let count = env
.builder
.build_extract_value(count_and_start, 0, "get_count")
.unwrap();
let start = env
.builder
.build_extract_value(count_and_start, 1, "get_count")
.unwrap();
call_void_bitcode_fn( call_void_bitcode_fn(
env, env,
&[ &[
list_symbol_to_c_abi(env, scope, list).into(), list_symbol_to_c_abi(env, scope, list).into(),
complex_bitcast( count,
env.builder, start,
count_and_start.into(),
env.twice_ptr_int().into(),
"to_i128",
),
result_ptr.into(), result_ptr.into(),
], ],
bitcode::STR_FROM_UTF8_RANGE, bitcode::STR_FROM_UTF8_RANGE,