This commit is contained in:
blueloveTH 2025-06-05 19:40:29 +08:00
parent 2404c6fe2b
commit 59e60cf3c0
2 changed files with 13 additions and 5 deletions

View File

@ -46,15 +46,16 @@ py_Name py_namev(c11_sv name) {
uint64_t hash = c11_sv__hash(name);
int index = hash & 0xFFFF;
NameBucket* p = pk_string_table.table[index];
NameBucket* prev = NULL;
bool found = false;
while(p) {
c11_sv p_sv = {p->data, p->size};
if(p->hash == hash && c11__sveq(p_sv, name)) {
found = true;
break;
} else {
p = p->next;
}
prev = p;
p = p->next;
}
if(found) {
atomic_store(&pk_string_table.lock, false);
@ -68,11 +69,11 @@ py_Name py_namev(c11_sv name) {
bucket->size = name.size;
memcpy(bucket->data, name.data, name.size);
bucket->data[name.size] = '\0';
if(p == NULL) {
if(prev == NULL) {
pk_string_table.table[index] = bucket;
} else {
assert(p->next == NULL);
p->next = bucket;
assert(prev->next == NULL);
prev->next = bucket;
}
atomic_store(&pk_string_table.lock, false);
return (py_Name)bucket;

View File

@ -225,6 +225,13 @@ char* py_formatexc() {
}
bool py_exception(py_Type type, const char* fmt, ...) {
#ifndef NDEBUG
if(py_checkexc(true)) {
const char* name = py_tpname(pk_current_vm->curr_exception.type);
c11__abort("py_exception(): `%s` was already set!", name);
}
#endif
c11_sbuf buf;
c11_sbuf__ctor(&buf);
va_list args;