refactor(argparse): 将null替换为nullptr以提高C++兼容性
- 在argparse库中将所有null指针常量替换为nullptr - 更新头文件和源文件中的指针初始化和比较操作 - 修改测试文件中的相关断言检查 - 更新AST定义文件中的注释说明
This commit is contained in:
@@ -10,9 +10,9 @@
|
||||
#ifndef __KLLIST_H__
|
||||
#define __KLLIST_H__
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL (0)
|
||||
#define __NULL_KLIST_DEFINED__
|
||||
#ifndef nullptr
|
||||
#define nullptr (0)
|
||||
#define __nullptr_KLIST_DEFINED__
|
||||
#endif
|
||||
|
||||
#ifndef container_of
|
||||
@@ -88,8 +88,8 @@ static inline void __list_del(struct list_head *prev, struct list_head *next) {
|
||||
|
||||
static inline void list_del(struct list_head *entry) {
|
||||
__list_del(entry->prev, entry->next);
|
||||
entry->next = NULL;
|
||||
entry->prev = NULL;
|
||||
entry->next = nullptr;
|
||||
entry->prev = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,8 +159,9 @@ typedef int (*list_cmp_func_t)(void *, const struct list_head *,
|
||||
static void list_sort(void *priv, struct list_head *head, list_cmp_func_t cmp);
|
||||
#endif
|
||||
|
||||
#if defined(__NULL_KLIST_DEFINED__) && !defined(__NULL_KLIST_DEFINED_NOMOVE__)
|
||||
#undef NULL
|
||||
#if defined(__nullptr_KLIST_DEFINED__) && \
|
||||
!defined(__nullptr_KLIST_DEFINED_NOMOVE__)
|
||||
#undef nullptr
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -76,7 +76,7 @@ void scc_hashtable_init(scc_hashtable_t *ht,
|
||||
* @param ht 哈希表实例指针
|
||||
* @param key 键指针
|
||||
* @param value 值指针
|
||||
* @return 被替换的旧值指针(无替换返回NULL)
|
||||
* @return 被替换的旧值指针(无替换返回nullptr)
|
||||
*/
|
||||
void *scc_hashtable_set(scc_hashtable_t *ht, const void *key, void *value);
|
||||
|
||||
@@ -84,7 +84,7 @@ void *scc_hashtable_set(scc_hashtable_t *ht, const void *key, void *value);
|
||||
* @brief 查找键对应值
|
||||
* @param ht 哈希表实例指针
|
||||
* @param key 查找键指针
|
||||
* @return 找到返回值指针,未找到返回NULL
|
||||
* @return 找到返回值指针,未找到返回nullptr
|
||||
*/
|
||||
void *scc_hashtable_get(scc_hashtable_t *ht, const void *key);
|
||||
|
||||
@@ -92,7 +92,7 @@ void *scc_hashtable_get(scc_hashtable_t *ht, const void *key);
|
||||
* @brief 删除键值对
|
||||
* @param ht 哈希表实例指针
|
||||
* @param key 要删除的键指针
|
||||
* @return 被删除的值指针(不存在返回NULL)
|
||||
* @return 被删除的值指针(不存在返回nullptr)
|
||||
*
|
||||
* @note 实际采用墓碑标记方式删除
|
||||
*/
|
||||
|
||||
@@ -13,7 +13,7 @@ void scc_hashtable_init(scc_hashtable_t *ht,
|
||||
ht->tombstone_count = 0;
|
||||
ht->cmp_func = cmp_func;
|
||||
ht->hash_func = hash_func;
|
||||
Assert(ht->cmp_func != null && ht->hash_func != null);
|
||||
Assert(ht->cmp_func != nullptr && ht->hash_func != nullptr);
|
||||
}
|
||||
|
||||
static int next_power_of_two(int n) {
|
||||
@@ -29,12 +29,12 @@ static int next_power_of_two(int n) {
|
||||
static scc_hashtable_entry_t *find_entry(scc_hashtable_t *ht, const void *key,
|
||||
u32 hash) {
|
||||
if (ht->entries.cap == 0)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
u32 index = hash & (ht->entries.cap - 1); // 容量是2的幂
|
||||
u32 probe = 0;
|
||||
|
||||
scc_hashtable_entry_t *tombstone = NULL;
|
||||
scc_hashtable_entry_t *tombstone = nullptr;
|
||||
|
||||
while (1) {
|
||||
scc_hashtable_entry_t *entry = &scc_vec_at(ht->entries, index);
|
||||
@@ -56,7 +56,7 @@ static scc_hashtable_entry_t *find_entry(scc_hashtable_t *ht, const void *key,
|
||||
break;
|
||||
}
|
||||
LOG_ERROR("hashset_find: hash table is full");
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void adjust_capacity(scc_hashtable_t *ht, usize new_cap) {
|
||||
@@ -71,7 +71,7 @@ static void adjust_capacity(scc_hashtable_t *ht, usize new_cap) {
|
||||
ht->entries.size = new_cap;
|
||||
ht->entries.cap = new_cap;
|
||||
ht->entries.data =
|
||||
scc_realloc(NULL, new_cap * sizeof(scc_hashtable_entry_t));
|
||||
scc_realloc(nullptr, new_cap * sizeof(scc_hashtable_entry_t));
|
||||
scc_memset(ht->entries.data, 0, new_cap * sizeof(scc_hashtable_entry_t));
|
||||
|
||||
// rehash the all of the old data
|
||||
@@ -99,7 +99,7 @@ void *scc_hashtable_set(scc_hashtable_t *ht, const void *key, void *value) {
|
||||
u32 hash = ht->hash_func(key);
|
||||
scc_hashtable_entry_t *entry = find_entry(ht, key, hash);
|
||||
|
||||
void *old_value = NULL;
|
||||
void *old_value = nullptr;
|
||||
if (entry->state == ENTRY_ACTIVE) {
|
||||
old_value = entry->value;
|
||||
} else {
|
||||
@@ -117,22 +117,22 @@ void *scc_hashtable_set(scc_hashtable_t *ht, const void *key, void *value) {
|
||||
|
||||
void *scc_hashtable_get(scc_hashtable_t *ht, const void *key) {
|
||||
if (ht->entries.cap == 0)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
u32 hash = ht->hash_func(key);
|
||||
scc_hashtable_entry_t *entry = find_entry(ht, key, hash);
|
||||
return (entry && entry->state == ENTRY_ACTIVE) ? entry->value : NULL;
|
||||
return (entry && entry->state == ENTRY_ACTIVE) ? entry->value : nullptr;
|
||||
}
|
||||
|
||||
void *scc_hashtable_del(scc_hashtable_t *ht, const void *key) {
|
||||
if (ht->entries.cap == 0)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
u32 hash = ht->hash_func(key);
|
||||
scc_hashtable_entry_t *entry = find_entry(ht, key, hash);
|
||||
|
||||
if (entry == NULL || entry->state != ENTRY_ACTIVE)
|
||||
return NULL;
|
||||
if (entry == nullptr || entry->state != ENTRY_ACTIVE)
|
||||
return nullptr;
|
||||
|
||||
void *value = entry->value;
|
||||
entry->state = ENTRY_TOMBSTONE;
|
||||
|
||||
@@ -15,7 +15,7 @@ const char *scc_strpool_intern(scc_strpool_t *pool, const char *str) {
|
||||
char *new_str = scc_malloc(len);
|
||||
if (!new_str) {
|
||||
LOG_ERROR("strpool: Failed to allocate memory for string");
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
scc_memcpy(new_str, str, len);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user