Kolten Pearson 2 лет назад
Родитель
Сommit
ceab1e0609
5 измененных файлов с 23 добавлено и 2 удалено
  1. 9 0
      c_bindings/pocketpy_c.cpp
  2. 7 0
      c_bindings/pocketpy_c.h
  3. 2 0
      c_bindings/test.c
  4. 3 0
      c_bindings/test_answers.txt
  5. 2 2
      run_c_binding_test.sh

+ 9 - 0
c_bindings/pocketpy_c.cpp

@@ -550,3 +550,12 @@ bool pkpy_push(pkpy_vm* vm_handle, int index) {
     vm->c_data->push(vm->c_data->begin()[index]);
     return true;
 }
+
+
+bool pkpy_error(pkpy_vm* vm_handle, const char* message) {
+    CVM* vm = (CVM*) vm_handle;
+    ERRHANDLER_OPEN
+    throw Exception("CBindingError", message);
+    ERRHANDLER_CLOSE
+}
+

+ 7 - 0
c_bindings/pocketpy_c.h

@@ -22,6 +22,13 @@ typedef struct pkpy_vm_handle pkpy_vm;
 bool pkpy_clear_error(pkpy_vm*, char** message);
 //NOTE you are responsible for freeing message 
 
+//this will cause the vm to enter an error state and report the given message
+//when queried
+//note that at the moment this is more like a panic than throwing an error
+//the user will not be able to catch it with python code
+bool pkpy_error(pkpy_vm*, const char* message);
+
+
 pkpy_vm* pkpy_vm_create(bool use_stdio, bool enable_os);
 bool pkpy_vm_run(pkpy_vm*, const char* source);
 void pkpy_vm_destroy(pkpy_vm*);

+ 2 - 0
c_bindings/test.c

@@ -317,6 +317,8 @@ int main(int argc, char** argv) {
     //maybe worth fixing someday, but for now it is functionating as implemented
     error(pkpy_vm_run(vm, "try : test_error_propagate(); except NameError : pass"));
 
+    error(pkpy_error(vm, "test direct error mechanism"));
+
 
     //more complicated error handling
     //

+ 3 - 0
c_bindings/test_answers.txt

@@ -61,3 +61,6 @@ NameError: testing error throwing from python
 successfully errored with this message: 
 Traceback (most recent call last):
 NameError: could not find requested global
+successfully errored with this message: 
+Traceback (most recent call last):
+CBindingError: test direct error mechanism

+ 2 - 2
run_c_binding_test.sh

@@ -19,8 +19,8 @@ echo "checking results (they should be identical)"
 diff -q -s  binding_test_scratch c_bindings/test_answers.txt
 
 echo "cleaning up"
-rm pocketpy_c.o
+#rm pocketpy_c.o
 rm test.o
 rm binding_test_scratch
-rm c_binding_test
+#rm c_binding_test