Fix some promise memory handling.

Adjust disabled-test printing in `?`.
Disable part of async testing (with comment explanation).
This commit is contained in:
Sage Vaillancourt 2022-04-11 21:42:00 -04:00
parent 96d759a7e6
commit 0fd58832bf
3 changed files with 10 additions and 6 deletions

View File

@ -399,7 +399,7 @@ Object help(Object* params, int length, struct Environment* env)
const char* test = h.tests[ti];
const char* expected = h.tests[ti + 1];
if (test[0] == ';') {
textCursor += sprintf(textCursor, "\n%s %s", test + 1, expected);
textCursor += sprintf(textCursor, "\n %s => %s", test + 1, expected);
continue;
}
textCursor += sprintf(textCursor, "\n %s => ", test);

View File

@ -35,6 +35,7 @@ void cleanPromise(struct Promise* promise)
promise->refs -= 1;
if (promise->refs == 0) {
deleteEnv(promise->env);
cleanObject(&promise->object);
free(promise);
}
}
@ -53,16 +54,18 @@ void* doAsync(void* args)
{
struct Promise* promise = args;
Object cloned = cloneObject(promise->object);
Object cloned = promise->object;
Object first_eval = eval(&cloned, promise->env);
Object e = funcyEval(&first_eval, NULL, 0, promise->env);
cleanObject(&cloned);
promise->object = e;
promise->done = 1;
cleanPromise(promise);
deleteEnv(promise->env);
cleanObject(&cloned);
//cleanObject(&first_eval);
//cleanObject(&cloned);
return NULL;
}

View File

@ -15,14 +15,15 @@ int isPromise(Object src);
fn(async, "async",
"Run the given lambda on a separate thread, returning a promise.",
"(def sleepy (fn () ((sys \"sleep 0.01\") \"Hiya\"))) (def x (async sleepy)) x", "<PENDING>",
"(def sleepy (fn () ((sys \"sleep 0.01\") \"Hiya\"))) (def x (async sleepy)) (await x)", "Hiya",
// Disabled because the test ends while memory is still allocated, causing valgrind to report errors
";(def sleepy (fn () ((sys \"sleep 0.02\") \"Hiya\"))) (def x (async sleepy)) x", "=> <PENDING>",
"(def sleepy (fn () ((sys \"sleep 0.02\") \"Hiya\"))) (def x (async sleepy)) (await x)", "Hiya",
);
tfn(await, "await",
({ expect(isPromise), anyType }),
"Waits for a promise to resolve before proceeding.",
"(def sleepy (fn () ((sys \"sleep 0.01\") \"Hiya\"))) (def x (async sleepy)) (await x)", "Hiya",
"(def sleepy (fn () ((sys \"sleep 0.02\") \"Hiya\"))) (def x (async sleepy)) (await x)", "Hiya",
);
#endif // PEBBLISP_THREADS_H