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

View File

@ -225,6 +225,13 @@ char* py_formatexc() {
} }
bool py_exception(py_Type type, const char* fmt, ...) { 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 buf;
c11_sbuf__ctor(&buf); c11_sbuf__ctor(&buf);
va_list args; va_list args;