This commit is contained in:
blueloveTH 2025-06-05 01:48:37 +08:00
parent b0323bfab5
commit 51047f07a5
2 changed files with 11 additions and 10 deletions

View File

@ -62,20 +62,20 @@ py_Name py_namev(c11_sv name) {
}
// generate new index
NameBucket* entry = PK_MALLOC(sizeof(NameBucket) + name.size + 1);
entry->next = NULL;
entry->hash = hash;
entry->size = name.size;
memcpy(entry->data, name.data, name.size);
entry->data[name.size] = '\0';
NameBucket* bucket = PK_MALLOC(sizeof(NameBucket) + name.size + 1);
bucket->next = NULL;
bucket->hash = hash;
bucket->size = name.size;
memcpy(bucket->data, name.data, name.size);
bucket->data[name.size] = '\0';
if(p == NULL) {
pk_string_table.table[index] = entry;
pk_string_table.table[index] = bucket;
} else {
assert(p->next == NULL);
p->next = entry;
p->next = bucket;
}
atomic_store(&pk_string_table.lock, false);
return (py_Name)entry;
return (py_Name)bucket;
}
c11_sv py_name2sv(py_Name index) {

View File

@ -55,9 +55,10 @@ bool py_hash(py_Ref val, int64_t* out) {
py_TypeInfo* ti = pk__type_info(val->type);
do {
py_Ref slot_hash = py_getdict(&ti->self, __hash__);
if(!slot_hash || py_isnone(slot_hash)) break;
if(slot_hash && py_isnone(slot_hash)) break;
py_Ref slot_eq = py_getdict(&ti->self, __eq__);
if(slot_eq) {
if(!slot_hash) break;
if(!py_call(slot_hash, 1, val)) return false;
if(!py_checkint(py_retval())) return false;
*out = py_toint(py_retval());