blueloveTH 1 سال پیش
والد
کامیت
99bb8a5351
2فایلهای تغییر یافته به همراه5 افزوده شده و 6 حذف شده
  1. 2 2
      include/pocketpy/pocketpy.h
  2. 3 4
      src/public/internal.c

+ 2 - 2
include/pocketpy/pocketpy.h

@@ -90,8 +90,8 @@ PK_EXPORT int py_currentvm();
 /// Switch to a VM.
 /// @param index index of the VM ranging from 0 to 16 (exclusive). `0` is the default VM.
 PK_EXPORT void py_switchvm(int index);
-/// Reset a VM.
-PK_EXPORT void py_resetvm(int index);
+/// Reset the current VM.
+PK_EXPORT void py_resetvm();
 /// Set `sys.argv`. Used for storing command-line arguments.
 PK_EXPORT void py_sys_setargv(int argc, char** argv);
 /// Setup the callbacks for the current VM.

+ 3 - 4
src/public/internal.c

@@ -61,11 +61,10 @@ void py_switchvm(int index) {
     pk_current_vm = pk_all_vm[index];
 }
 
-void py_resetvm(int index){
-    if(index < 0 || index >= 16) c11__abort("invalid vm index");
-    VM* vm = pk_all_vm[index];
-    if(!vm) c11__abort("vm not initialized");
+void py_resetvm() {
+    VM* vm = pk_current_vm;
     VM__dtor(vm);
+    memset(vm, 0, sizeof(VM));
     VM__ctor(vm);
 }