ref: 95b60462d104de5f64bdf5cfba9a1ffab6e77e73
parent: dd1055daf99d53d1d16ed1ae37a7dd24e68f1f93
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Mar 20 17:50:51 EDT 2021
turn exit() into a func pointer
--- a/include/npe/npe.h
+++ b/include/npe/npe.h
@@ -31,14 +31,8 @@
#include <thread.h>
#define main npe_main_renamed
#pragma lib "libthread.a"
-#ifndef exit
-#define exit(x) threadexitsall(x == 0 ? nil : "error")
#endif
-#endif
-#ifndef exit
-void exits(char *);
-#define exit(x) exits(x == 0 ? nil : "error")
-#endif
+extern void (*exit)(int);
#endif
--- a/libnpe/_main.c
+++ b/libnpe/_main.c
@@ -3,13 +3,21 @@
#include <thread.h>
int npe_main_renamed(int argc, char *argv[]);
-
int mainstacksize = 256*1024;
+extern void (*exit)(int);
+static void
+npe_threadexit(int x)
+{
+ threadexitsall(x == 0 ? nil : "error");
+}
+
void
threadmain(int argc, char *argv[])
{
setfcr(getfcr() & ~(FPINVAL|FPOVFL));
+
+ exit = npe_threadexit;
argv0 = *argv; /* for sdl to set at least some kind of label */
--- a/libnpe/_npe.c
+++ b/libnpe/_npe.c
@@ -3,7 +3,14 @@
#include <sys/stat.h>
#include "_npe.h"
+static void
+npe_exit(int x)
+{
+ exits(x == 0 ? nil : "error");
+}
+
int errno = 0;
+void (*exit)(int) = npe_exit;
/*
* nsec() is wallclock and can be adjusted by timesync