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 // generate new index
NameBucket* entry = PK_MALLOC(sizeof(NameBucket) + name.size + 1); NameBucket* bucket = PK_MALLOC(sizeof(NameBucket) + name.size + 1);
entry->next = NULL; bucket->next = NULL;
entry->hash = hash; bucket->hash = hash;
entry->size = name.size; bucket->size = name.size;
memcpy(entry->data, name.data, name.size); memcpy(bucket->data, name.data, name.size);
entry->data[name.size] = '\0'; bucket->data[name.size] = '\0';
if(p == NULL) { if(p == NULL) {
pk_string_table.table[index] = entry; pk_string_table.table[index] = bucket;
} else { } else {
assert(p->next == NULL); assert(p->next == NULL);
p->next = entry; p->next = bucket;
} }
atomic_store(&pk_string_table.lock, false); atomic_store(&pk_string_table.lock, false);
return (py_Name)entry; return (py_Name)bucket;
} }
c11_sv py_name2sv(py_Name index) { 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); py_TypeInfo* ti = pk__type_info(val->type);
do { do {
py_Ref slot_hash = py_getdict(&ti->self, __hash__); 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__); py_Ref slot_eq = py_getdict(&ti->self, __eq__);
if(slot_eq) { if(slot_eq) {
if(!slot_hash) break;
if(!py_call(slot_hash, 1, val)) return false; if(!py_call(slot_hash, 1, val)) return false;
if(!py_checkint(py_retval())) return false; if(!py_checkint(py_retval())) return false;
*out = py_toint(py_retval()); *out = py_toint(py_retval());