From 0c7b9a511da08280d7bc97534b541de339f3e89a Mon Sep 17 00:00:00 2001 From: Sebastiaan Fernandez Date: Mon, 4 Mar 2024 14:37:26 +0100 Subject: [PATCH] Refactor usage of PhysFS --- src/VM/VM.cpp | 6 +++++- src/VM/VM.h | 2 +- src/main.cpp | 8 +------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/VM/VM.cpp b/src/VM/VM.cpp index da9e6f0..0964856 100644 --- a/src/VM/VM.cpp +++ b/src/VM/VM.cpp @@ -18,6 +18,7 @@ #include "Configuration.h" #include "Memory.h" #include "Library/Builtin.h" +#include "physfs.h" #include #include @@ -28,9 +29,11 @@ VM::VM(const Configuration configuration) noexcept { } -void VM::start() +void VM::start(const char* commandLineName) { Platform::initialize(); + PHYSFS_init(commandLineName); + PHYSFS_permitSymbolicLinks(1); registerBuiltinRegisterNatives(); getClass("java/lang/OutOfMemoryError", &m_mainThread); @@ -357,6 +360,7 @@ void VM::runMain() void VM::shutdown() { + PHYSFS_deinit(); Platform::cleanup(); } diff --git a/src/VM/VM.h b/src/VM/VM.h index 9485469..70b0643 100644 --- a/src/VM/VM.h +++ b/src/VM/VM.h @@ -40,7 +40,7 @@ class VM { void updateVariableFromVariable(Variable* variable, const char* descriptor, Variable operand, Variable operand2, VMThread* thread); static std::vector createVariableForDescriptor(const char* descriptor); [[nodiscard]] static u1 getDescriptorVarCategory(const char* descriptor) noexcept; - void start(); + void start(const char* commandLineName); ClassInfo* getClass(const char* className, VMThread* thread); void executeNativeMethod(const ClassInfo* targetClass, const MethodInfo* methodInfo, JavaHeap* heap, VMThread* thread); void runMain(); diff --git a/src/main.cpp b/src/main.cpp index ded59b2..65ed905 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,7 +15,6 @@ #include "VM/Configuration.h" #include "VM/VM.h" -#include "physfs.h" #include #include @@ -53,19 +52,14 @@ static Configuration parseArguments(const std::span args) int main(const int argc, const char* argv[]) { - PHYSFS_init(argv[0]); - PHYSFS_permitSymbolicLinks(1); - const size_t size = argc; const std::span args{argv, size}; const Configuration config = parseArguments(args); VM vm(config); - vm.start(); + vm.start(argv[0]); vm.runMain(); vm.shutdown(); - PHYSFS_deinit(); - return 0; }