|
10 | 10 | #include <string.h>
|
11 | 11 | #include <iostream>
|
12 | 12 | #include <vector>
|
13 |
| -#include <random> |
| 13 | +#include <bits/stdc++.h> |
14 | 14 |
|
15 | 15 | using namespace std;
|
16 | 16 |
|
17 |
| -/* use std generation */ |
| 17 | +/* |
| 18 | + * there is a unsigned integer overflow in |
| 19 | + * /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/random.tcc:416 |
| 20 | + * |
| 21 | + * use srand() and rand() instead |
| 22 | + */ |
| 23 | + |
| 24 | +static int32_t |
| 25 | +generate_random_int32() |
| 26 | +{ |
| 27 | + return (int32_t)rand(); |
| 28 | +} |
| 29 | + |
| 30 | +static int64_t |
| 31 | +generate_random_int64() |
| 32 | +{ |
| 33 | + return ((int64_t)rand() << 32) | rand(); |
| 34 | +} |
| 35 | + |
| 36 | +static float |
| 37 | +generate_random_float() |
| 38 | +{ |
| 39 | + return (float)rand() / (float)RAND_MAX; |
| 40 | +} |
| 41 | + |
| 42 | +static double |
| 43 | +generate_random_double() |
| 44 | +{ |
| 45 | + return (double)rand() / (double)RAND_MAX; |
| 46 | +} |
| 47 | + |
18 | 48 | static wasm_val_t
|
19 | 49 | random_gen_val(wasm_valkind_t kind)
|
20 | 50 | {
|
21 |
| - static std::random_device rd; |
22 |
| - static std::mt19937 gen(rd()); |
| 51 | + srand(1024); |
| 52 | + |
23 | 53 | if (kind == WASM_I32) {
|
24 |
| - std::uniform_int_distribution<int32_t> dis; |
25 |
| - return wasm_val_t{ .kind = WASM_I32, .of = { .i32 = dis(gen) } }; |
| 54 | + return wasm_val_t{ .kind = WASM_I32, |
| 55 | + .of = { .i32 = generate_random_int32() } }; |
26 | 56 | }
|
27 | 57 | else if (kind == WASM_I64) {
|
28 |
| - std::uniform_int_distribution<int64_t> dis; |
29 |
| - return wasm_val_t{ .kind = WASM_I64, .of = { .i64 = dis(gen) } }; |
| 58 | + return wasm_val_t{ .kind = WASM_I64, |
| 59 | + .of = { .i64 = generate_random_int64() } }; |
30 | 60 | }
|
31 | 61 | else if (kind == WASM_F32) {
|
32 |
| - std::uniform_real_distribution<float> dis; |
33 |
| - return wasm_val_t{ .kind = WASM_F32, .of = { .f32 = dis(gen) } }; |
| 62 | + return wasm_val_t{ .kind = WASM_F32, |
| 63 | + .of = { .f32 = generate_random_float() } }; |
34 | 64 | }
|
35 | 65 | else if (kind == WASM_F64) {
|
36 |
| - std::uniform_real_distribution<double> dis; |
37 |
| - return wasm_val_t{ .kind = WASM_F64, .of = { .f64 = dis(gen) } }; |
| 66 | + return wasm_val_t{ .kind = WASM_F64, |
| 67 | + .of = { .f64 = generate_random_double() } }; |
38 | 68 | }
|
39 | 69 | else if (kind == WASM_EXTERNREF) {
|
40 |
| - std::uniform_int_distribution<uintptr_t> dis; |
41 | 70 | return wasm_val_t{ .kind = WASM_EXTERNREF,
|
42 |
| - .of = { .foreign = dis(gen) } }; |
| 71 | + .of = { .foreign = |
| 72 | + (uintptr_t)generate_random_int64() } }; |
43 | 73 | }
|
44 | 74 | else if (kind == WASM_FUNCREF) {
|
45 | 75 | return wasm_val_t{ .kind = WASM_FUNCREF, .of = { .ref = nullptr } };
|
@@ -124,9 +154,8 @@ execute_export_functions(wasm_module_t module, wasm_module_inst_t inst)
|
124 | 154 | std::cout << ")";
|
125 | 155 | }
|
126 | 156 |
|
127 |
| - bool ret = |
128 |
| - wasm_runtime_call_wasm_a(exec_env, func, result_count, |
129 |
| - results.data(), param_count, args.data()); |
| 157 | + bool ret = wasm_runtime_call_wasm_a(exec_env, func, result_count, |
| 158 | + &results[0], param_count, &args[0]); |
130 | 159 | if (!ret) {
|
131 | 160 | const char *exception = wasm_runtime_get_exception(inst);
|
132 | 161 | if (!exception) {
|
|
0 commit comments