@@ -49,6 +49,7 @@ const char* NAME = "cliffi";
4949const char * VERSION = "v1.10.19" ;
5050const char * BASIC_USAGE_STRING = "<library> <return_typeflag> <function_name> [[-typeflag] <arg>.. [ ... <varargs>..] ]\n" ;
5151
52+ bool isTestEnvExit1OnFail = false;
5253sigjmp_buf jmpBuffer ;
5354
5455#ifdef use_backtrace
@@ -80,6 +81,9 @@ void exit_or_restart(int status) {
8081#ifdef use_backtrace
8182 if (status != 0 ) printStackTrace ();
8283#endif
84+ if (isTestEnvExit1OnFail ) {
85+ exit (1 );
86+ }
8387 siglongjmp (jmpBuffer , status );
8488}
8589
@@ -100,6 +104,9 @@ void handleSegfault(int signal) {
100104 // Log the segfault
101105 logSegfault ();
102106
107+ if (isTestEnvExit1OnFail ) {
108+ exit (1 );
109+ }
103110 // Perform cleanup if needed
104111
105112 // Jump back to the REPL loop
@@ -750,6 +757,7 @@ int main(int argc, char* argv[]) {
750757 }
751758 if (argc > 1 && strcmp (argv [1 ], "--repltest" ) == 0 ) {
752759 #if !defined(_WIN32 ) && !defined(_WIN64 )
760+ isTestEnvExit1OnFail = true;
753761 int pipefd [2 ];
754762 if (pipe (pipefd ) == -1 ) {
755763 perror ("pipe" );
@@ -766,6 +774,7 @@ int main(int argc, char* argv[]) {
766774 close (pipefd [1 ]); // Close write end of pipe
767775 dup2 (pipefd [0 ], STDIN_FILENO ); // Redirect STDIN to read from pipe
768776 close (pipefd [0 ]); // Close read end, not needed anymore
777+ isTestEnvExit1OnFail = true;
769778 goto replmode ;
770779 } else { // Parent process
771780 close (pipefd [0 ]); // Close the write end of the pipe
@@ -774,8 +783,9 @@ int main(int argc, char* argv[]) {
774783 write (pipefd [1 ], " " , 1 );
775784 }
776785 close (pipefd [1 ]); // Close the write end of the pipe
777- waitpid (pid , NULL , 0 );
778- return 0 ;
786+ int status ;
787+ waitpid (pid , & status , 0 );
788+ exit (WEXITSTATUS (status ));
779789 }
780790#else // a simpler version for windows
781791 checkAndRunCliffiInits ();
0 commit comments