core: Use crypto_generichash. We don't need to roll our own FNV32a.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 36m37s

This commit is contained in:
2025-06-25 21:10:05 -04:00
parent cef526bcf3
commit 37e1c5d97b
5 changed files with 9 additions and 23 deletions

View File

@ -22,6 +22,7 @@
#include "ares.h"
#include "backtrace.h"
#include "quickjs.h"
#include "sodium/crypto_generichash.h"
#include "sqlite3.h"
#include "unzip.h"
#include "uv.h"
@ -1255,6 +1256,8 @@ static void _tf_task_free_promise(tf_task_t* task, promiseid_t id)
JSValue tf_task_allocate_promise(tf_task_t* task, promiseid_t* out_promise)
{
uint32_t stack_hash = 0;
crypto_generichash_state state;
crypto_generichash_init(&state, NULL, 0, sizeof(stack_hash));
if (task->_promise_stack_debug)
{
JSValue error = JS_ThrowInternalError(task->_context, "promise callstack");
@ -1262,16 +1265,17 @@ JSValue tf_task_allocate_promise(tf_task_t* task, promiseid_t* out_promise)
JSValue stack_value = JS_GetPropertyStr(task->_context, exception, "stack");
size_t length = 0;
const char* stack = JS_ToCStringLen(task->_context, &length, stack_value);
stack_hash = tf_util_fnv32a((const void*)stack, (int)length, 0);
crypto_generichash_update(&state, (const void*)stack, (int)length);
void* buffer[31];
int count = tf_util_backtrace(buffer, sizeof(buffer) / sizeof(*buffer));
stack_hash = tf_util_fnv32a((const void*)buffer, sizeof(void*) * count, stack_hash);
crypto_generichash_update(&state, (const void*)buffer, sizeof(void*) * count);
_add_promise_stack(task, stack_hash, stack, buffer, count);
JS_FreeCString(task->_context, stack);
JS_FreeValue(task->_context, stack_value);
JS_FreeValue(task->_context, exception);
JS_FreeValue(task->_context, error);
}
crypto_generichash_final(&state, (void*)&stack_hash, sizeof(stack_hash));
promiseid_t promise_id;
do