Skip to content

Commit

Permalink
Merge pull request #721 from CakeML/exit_stderr
Browse files Browse the repository at this point in the history
tweak basis_ffi.c around exit and cml_exit
  • Loading branch information
myreen committed Feb 2, 2020
2 parents f5a25c5 + 645918a commit 742e79a
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions basis/basis_ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
#include <sys/time.h>
#include <assert.h>

/* This flag is on by default. It catches CakeML's out-of-memory exit codes
* and prints a helpful message to stderr.
* Note that this is not specified by the basis library.
* */
#define STDERR_MEM_EXHAUST

/* clFFI (command line) */

/* argc and argv are exported in cake.S */
Expand Down Expand Up @@ -145,19 +151,28 @@ int numGC = 0;
int hasT = 0;

void cml_exit(int arg) {

#ifdef STDERR_MEM_EXHAUST
if(arg == 1) {
fprintf(stderr,"CakeML heap space exhausted.\n");
}
else if(arg == 2) {
fprintf(stderr,"CakeML stack space exhausted.\n");
}
#endif

#ifdef DEBUG_FFI
{
fprintf(stderr,"GCNum: %d, GCTime(us): %ld\n",numGC,microsecs);
}
#endif

exit(arg);
}

void ffiexit (unsigned char *c, long clen, unsigned char *a, long alen) {
if(alen > 0) {
cml_exit((int)a[0]);
}
cml_exit(EXIT_FAILURE);
assert(alen == 1);
exit((int)a[0]);
}


Expand Down

0 comments on commit 742e79a

Please sign in to comment.