Skip to content

Commit

Permalink
examples: add module search path initialization and freeing
Browse files Browse the repository at this point in the history
Since commit 3c168b5 ("vm, cli: move search path into global config...")
it is required to explicitly initialize the module search path in the
configuration structure for compile time module imports and run time
require operations to work.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
  • Loading branch information
jow- committed Aug 24, 2022
1 parent ee1946f commit bcdd2cb
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/exception-handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ int main(int argc, char **argv)
return 1;
}

/* initialize default module search path */
uc_search_path_init(&config.module_search_path);

/* initialize VM context */
uc_vm_t vm = { 0 };
uc_vm_init(&vm, &config);
Expand All @@ -96,5 +99,8 @@ int main(int argc, char **argv)
/* free VM context */
uc_vm_free(&vm);

/* free search module path vector */
uc_search_path_free(&config.module_search_path);

return exit_code;
}
6 changes: 6 additions & 0 deletions examples/execute-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ int main(int argc, char **argv)
return 1;
}

/* initialize default module search path */
uc_search_path_init(&config.module_search_path);

/* initialize VM context */
uc_vm_t vm = { 0 };
uc_vm_init(&vm, &config);
Expand Down Expand Up @@ -114,5 +117,8 @@ int main(int argc, char **argv)
/* free VM context */
uc_vm_free(&vm);

/* free search module path vector */
uc_search_path_free(&config.module_search_path);

return exit_code;
}
6 changes: 6 additions & 0 deletions examples/execute-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ int main(int argc, char **argv)
return 1;
}

/* initialize default module search path */
uc_search_path_init(&config.module_search_path);

/* initialize VM context */
uc_vm_t vm = { 0 };
uc_vm_init(&vm, &config);
Expand Down Expand Up @@ -127,5 +130,8 @@ int main(int argc, char **argv)
/* free VM context */
uc_vm_free(&vm);

/* free search module path vector */
uc_search_path_free(&config.module_search_path);

return exit_code;
}
6 changes: 6 additions & 0 deletions examples/native-function.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ int main(int argc, char **argv)
return 1;
}

/* initialize default module search path */
uc_search_path_init(&config.module_search_path);

/* initialize VM context */
uc_vm_t vm = { 0 };
uc_vm_init(&vm, &config);
Expand All @@ -103,5 +106,8 @@ int main(int argc, char **argv)
/* free VM context */
uc_vm_free(&vm);

/* free search module path vector */
uc_search_path_free(&config.module_search_path);

return exit_code;
}
6 changes: 6 additions & 0 deletions examples/state-reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ int main(int argc, char **argv)
return 1;
}

/* initialize default module search path */
uc_search_path_init(&config.module_search_path);

/* execute compiled program function five times */
for (int i = 0; i < 5; i++) {
/* initialize VM context */
Expand Down Expand Up @@ -87,5 +90,8 @@ int main(int argc, char **argv)
/* release program function */
uc_program_put(program);

/* free search module path vector */
uc_search_path_free(&config.module_search_path);

return exit_code;
}
6 changes: 6 additions & 0 deletions examples/state-reuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ int main(int argc, char **argv)
return 1;
}

/* initialize default module search path */
uc_search_path_init(&config.module_search_path);

/* initialize VM context */
uc_vm_t vm = { 0 };
uc_vm_init(&vm, &config);
Expand Down Expand Up @@ -91,5 +94,8 @@ int main(int argc, char **argv)
/* free VM context */
uc_vm_free(&vm);

/* free search module path vector */
uc_search_path_free(&config.module_search_path);

return exit_code;
}

0 comments on commit bcdd2cb

Please sign in to comment.