Pull segfault-handling into a dedicated function and ifdef.
Some stringing tweaks.
This commit is contained in:
parent
b419826b8e
commit
61b9f79c36
13
src/object.c
13
src/object.c
|
@ -129,7 +129,8 @@ Object* nf_addToList(Object* dest, const Object src)
|
|||
}
|
||||
|
||||
#ifndef SIMPLE_ERRORS
|
||||
static const char* errorText[] = {"MISMATCHED_PARENS",
|
||||
static const char* errorText[] = {
|
||||
"MISMATCHED_PARENS",
|
||||
"NULL_ENV",
|
||||
"EMPTY_ENV",
|
||||
"NULL_PARSE",
|
||||
|
@ -246,20 +247,20 @@ int stringNObj(struct string* s, const Object* obj)
|
|||
case TYPE_BOOL:
|
||||
s->cursor += sprintf(s->cursor, "%s", obj->number ? "T" : "F");
|
||||
break;
|
||||
case TYPE_SYMBOL:
|
||||
case TYPE_STRING: {
|
||||
size_t stringLen = strlen(obj->string);
|
||||
inflate(s, stringLen);
|
||||
s->cursor += sprintf(s->cursor, "%s", obj->string);
|
||||
const char* format = obj->type == TYPE_STRING ? "%s" : "`%s`";
|
||||
s->cursor += sprintf(s->cursor, format, obj->string);
|
||||
break;
|
||||
}
|
||||
case TYPE_SYMBOL:
|
||||
s->cursor += sprintf(s->cursor, "`%s`", obj->string);
|
||||
break;
|
||||
case TYPE_STRUCT:
|
||||
stringStruct(s, obj);
|
||||
break;
|
||||
case TYPE_LIST:
|
||||
case TYPE_SLIST:
|
||||
s->cursor += sprintf(s->cursor, "'");
|
||||
case TYPE_LIST:
|
||||
stringList(s, obj);
|
||||
break;
|
||||
case TYPE_ERROR: {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#define printd(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define printd(...) do { } while (0)
|
||||
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -15,9 +15,6 @@
|
|||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <ucontext.h>
|
||||
|
||||
#include "web.h"
|
||||
|
||||
#endif
|
||||
|
@ -677,6 +674,10 @@ void loadArgsIntoEnv(int argc, const char* argv[], struct Environment* env)
|
|||
addToEnv(env, "args", args);
|
||||
}
|
||||
|
||||
#ifdef __x86_64__
|
||||
#include <signal.h>
|
||||
#include <ucontext.h>
|
||||
|
||||
int nestedSegfault = 0;
|
||||
|
||||
void handler(int nSignum, siginfo_t* si, void* vcontext)
|
||||
|
@ -697,10 +698,29 @@ void handler(int nSignum, siginfo_t* si, void* vcontext)
|
|||
context->uc_mcontext.gregs[REG_RIP]++;
|
||||
exit(139);
|
||||
}
|
||||
void setupSegfaultHandler()
|
||||
{
|
||||
struct sigaction action;
|
||||
memset(&action, 0, sizeof(struct sigaction));
|
||||
action.sa_flags = SA_SIGINFO;
|
||||
action.sa_sigaction = handler;
|
||||
sigaction(SIGSEGV, &action, NULL);
|
||||
|
||||
// TODO: Track crashes in ~/.plcrash or some such
|
||||
}
|
||||
#else
|
||||
void setupSegfaultHandler()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
// TODO: add --no-lib and --no-config and/or --config=
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
setupSegfaultHandler();
|
||||
|
||||
const char* const home = getenv("HOME");
|
||||
char config[strlen(home) + 15];
|
||||
|
||||
struct Environment env = defaultEnv();
|
||||
setGlobal(&env);
|
||||
|
||||
|
@ -714,12 +734,6 @@ int main(int argc, const char* argv[])
|
|||
}
|
||||
}
|
||||
|
||||
struct sigaction action;
|
||||
memset(&action, 0, sizeof(struct sigaction));
|
||||
action.sa_flags = SA_SIGINFO;
|
||||
action.sa_sigaction = handler;
|
||||
sigaction(SIGSEGV, &action, NULL);
|
||||
|
||||
readFile(SCRIPTDIR "/lib.pbl", &env);
|
||||
|
||||
Object o = parseEval("(def prompt \"pebblisp::> \")", &env);
|
||||
|
@ -727,8 +741,6 @@ int main(int argc, const char* argv[])
|
|||
o = parseEval("(def preprocess (fn (text) (text)))", &env);
|
||||
cleanObject(&o);
|
||||
|
||||
const char* const home = getenv("HOME");
|
||||
char config[strlen(home) + 15];
|
||||
sprintf(config, "%s/.pebblisp.pbl", home);
|
||||
readFile(config, &env);
|
||||
|
||||
|
@ -753,9 +765,9 @@ int main(int argc, const char* argv[])
|
|||
}
|
||||
deleteEnv(&env);
|
||||
shredDictionary();
|
||||
// fprintf(stderr, "totalSearchDepth: %d of %d searches\n", getTotalSearchDepth(), getTotalSearches());
|
||||
// fprintf(stderr, "\nHEAP-ALLOCATED OBJECTS: %d\n", getAllocations());
|
||||
// fprintf(stderr, "TOTAL OBJECT.C ALLOC: %zu\n", getBytes());
|
||||
// eprintf("totalSearchDepth: %d of %d searches\n", getTotalSearchDepth(), getTotalSearches());
|
||||
// eprintf("\nHEAP-ALLOCATED OBJECTS: %d\n", getAllocations());
|
||||
// eprintf("TOTAL OBJECT.C ALLOC: %zu\n", getBytes());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue