refactor(argparse): 将null替换为nullptr以提高C++兼容性
- 在argparse库中将所有null指针常量替换为nullptr - 更新头文件和源文件中的指针初始化和比较操作 - 修改测试文件中的相关断言检查 - 更新AST定义文件中的注释说明
This commit is contained in:
@@ -57,7 +57,7 @@
|
||||
break; \
|
||||
} \
|
||||
usize phys_tail = _scc_ring_phys(ring, (ring).tail); \
|
||||
if ((ring).fill == null || \
|
||||
if ((ring).fill == nullptr || \
|
||||
!(ring).fill(&((ring).data[phys_tail]), (ring).userdata)) { \
|
||||
ok = 0; \
|
||||
break; \
|
||||
@@ -97,14 +97,14 @@
|
||||
* @brief 初始化环形缓冲区
|
||||
* @param ring 环形缓冲区变量
|
||||
* @param cap 容量
|
||||
* @param fill_func 填充回调函数 (可传 NULL) 返回true表示成功
|
||||
* @param fill_func 填充回调函数 (可传 nullptr) 返回true表示成功
|
||||
*
|
||||
* 内存分配失败由 scc_malloc 内部处理 (如 LOG_FATAL)
|
||||
*/
|
||||
#define scc_ring_init(ring, _cap, fill_func, _userdata) \
|
||||
do { \
|
||||
(ring).data = \
|
||||
(_cap) != 0 ? scc_malloc((_cap) * sizeof(*(ring).data)) : null; \
|
||||
(_cap) != 0 ? scc_malloc((_cap) * sizeof(*(ring).data)) : nullptr; \
|
||||
(ring).cap = (_cap); \
|
||||
(ring).head = 0; \
|
||||
(ring).probe = 0; \
|
||||
@@ -120,8 +120,8 @@
|
||||
(ring).head = 0; \
|
||||
(ring).probe = 0; \
|
||||
(ring).tail = (size); \
|
||||
(ring).fill = null; \
|
||||
(ring).userdata = null; \
|
||||
(ring).fill = nullptr; \
|
||||
(ring).userdata = nullptr; \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
@@ -131,7 +131,7 @@
|
||||
#define scc_ring_free(ring) \
|
||||
do { \
|
||||
scc_free((ring).data); \
|
||||
(ring).data = NULL; \
|
||||
(ring).data = nullptr; \
|
||||
(ring).cap = (ring).head = (ring).probe = (ring).tail = 0; \
|
||||
} while (0)
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@ typedef struct scc_str {
|
||||
* @return cstring_t 初始化后的对象
|
||||
*/
|
||||
static inline scc_str_t scc_str_empty(void) {
|
||||
return (scc_str_t){.data = null, .size = 0, .cap = 0};
|
||||
return (scc_str_t){.data = nullptr, .size = 0, .cap = 0};
|
||||
}
|
||||
|
||||
static inline void scc_str_init(scc_str_t *string) {
|
||||
Assert(string != null);
|
||||
string->data = null;
|
||||
Assert(string != nullptr);
|
||||
string->data = nullptr;
|
||||
string->size = 0;
|
||||
string->cap = 0;
|
||||
}
|
||||
@@ -39,7 +39,7 @@ static inline void scc_str_init(scc_str_t *string) {
|
||||
* @return cstring_t 新建对象,包含输入字符串的副本
|
||||
*/
|
||||
static inline scc_str_t scc_str_from_cstr(const char *s) {
|
||||
if (s == null) {
|
||||
if (s == nullptr) {
|
||||
return scc_str_empty();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ static inline scc_str_t scc_str_from_cstr(const char *s) {
|
||||
len++;
|
||||
|
||||
char *data = (char *)scc_malloc(len + 1);
|
||||
Assert(data != null);
|
||||
Assert(data != nullptr);
|
||||
scc_memcpy(data, s, len);
|
||||
data[len] = '\0';
|
||||
|
||||
@@ -66,12 +66,12 @@ static inline scc_str_t scc_str_copy(const scc_str_t *s) {
|
||||
* @param str 要被释放的字符串指针
|
||||
*/
|
||||
static inline void scc_str_drop(scc_str_t *str) {
|
||||
if (str == null) {
|
||||
if (str == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (str->data != null) {
|
||||
if (str->data != nullptr) {
|
||||
scc_free(str->data);
|
||||
str->data = null;
|
||||
str->data = nullptr;
|
||||
}
|
||||
str->size = 0;
|
||||
str->cap = 0;
|
||||
@@ -86,7 +86,7 @@ static inline void scc_str_drop(scc_str_t *str) {
|
||||
*/
|
||||
static inline void scc_str_append_cstr(scc_str_t *str, const char *data,
|
||||
usize len) {
|
||||
if (str == null || data == null || len == 0) {
|
||||
if (str == nullptr || data == nullptr || len == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ static inline void scc_str_append_cstr(scc_str_t *str, const char *data,
|
||||
}
|
||||
|
||||
char *new_data = (char *)scc_realloc(str->data, new_cap);
|
||||
Assert(new_data != null);
|
||||
Assert(new_data != nullptr);
|
||||
|
||||
str->data = new_data;
|
||||
str->cap = new_cap;
|
||||
@@ -117,7 +117,7 @@ static inline void scc_str_append_cstr(scc_str_t *str, const char *data,
|
||||
|
||||
scc_memcpy(str->data + str->size - 1, data, len);
|
||||
str->size += len;
|
||||
Assert(str->data != null);
|
||||
Assert(str->data != nullptr);
|
||||
str->data[str->size - 1] = '\0'; // 保证 C 字符串兼容性
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ static inline void scc_str_append(scc_str_t *str, const scc_str_t *other) {
|
||||
static inline void scc_str_append_fmt(scc_str_t *str, const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
usize needed = scc_vsnprintf(null, 0, fmt, args);
|
||||
usize needed = scc_vsnprintf(nullptr, 0, fmt, args);
|
||||
va_end(args);
|
||||
if (needed == 0)
|
||||
return;
|
||||
@@ -148,7 +148,7 @@ static inline void scc_str_append_fmt(scc_str_t *str, const char *fmt, ...) {
|
||||
new_cap = new_cap ? new_cap * 2 : (needed + 16);
|
||||
}
|
||||
char *new_data = (char *)scc_realloc(str->data, new_cap);
|
||||
Assert(new_data != NULL);
|
||||
Assert(new_data != nullptr);
|
||||
str->data = new_data;
|
||||
str->cap = new_cap;
|
||||
}
|
||||
@@ -178,7 +178,7 @@ static inline void scc_str_append_ch(scc_str_t *str, char ch) {
|
||||
* @return usize 字符串实际长度
|
||||
*/
|
||||
static inline usize scc_str_len(const scc_str_t *str) {
|
||||
if (str == null) {
|
||||
if (str == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
if (str->size == 0) {
|
||||
@@ -194,7 +194,7 @@ static inline usize scc_str_len(const scc_str_t *str) {
|
||||
* @return cbool
|
||||
*/
|
||||
static inline cbool scc_str_is_empty(const scc_str_t *str) {
|
||||
return str == null || str->size == 0;
|
||||
return str == nullptr || str->size == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,8 +218,8 @@ static inline void scc_str_clear(scc_str_t *str) {
|
||||
* @return char* 返回指向内部缓冲区的 C 风格字符串指针
|
||||
*/
|
||||
static inline char *scc_str_as_cstr(const scc_str_t *str) {
|
||||
if (str == null || str->data == null) {
|
||||
return null;
|
||||
if (str == nullptr || str->data == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return str->data;
|
||||
}
|
||||
@@ -229,11 +229,11 @@ static inline int scc_str_equal(const scc_str_t *str1, const scc_str_t *str2) {
|
||||
}
|
||||
|
||||
static inline char *scc_str_move_cstr(scc_str_t *str) {
|
||||
if (str == null || str->data == null) {
|
||||
return null;
|
||||
if (str == nullptr || str->data == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
char *ret = str->data;
|
||||
str->data = null;
|
||||
str->data = nullptr;
|
||||
str->cap = 0;
|
||||
str->size = 0;
|
||||
return ret;
|
||||
|
||||
@@ -26,14 +26,14 @@ typedef float f32;
|
||||
typedef double f64;
|
||||
|
||||
typedef bool cbool;
|
||||
/// void / null
|
||||
#define null NULL
|
||||
/// void / nullptr
|
||||
#ifndef nullptr
|
||||
#define nullptr NULL
|
||||
#endif
|
||||
|
||||
/* clang-format on */
|
||||
static_assert(sizeof(cbool) == 1, "cbool size must 1");
|
||||
|
||||
#else
|
||||
/* clang-format off */
|
||||
#else
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
@@ -58,8 +58,8 @@ typedef double f64;
|
||||
|
||||
typedef bool cbool;
|
||||
|
||||
#ifndef null
|
||||
#define null NULL
|
||||
#ifndef nullptr
|
||||
#define nullptr nullptr
|
||||
#endif
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
@@ -106,7 +106,7 @@ typedef size_t usize;
|
||||
int cap = (vec).cap ? (vec).cap * 2 : 4; \
|
||||
scc_vec_realloc(vec, cap); \
|
||||
} \
|
||||
Assert((vec).data != null); \
|
||||
Assert((vec).data != nullptr); \
|
||||
(vec).data[(vec).size++] = value; \
|
||||
} while (0)
|
||||
|
||||
@@ -147,7 +147,7 @@ typedef size_t usize;
|
||||
#define scc_vec_free(vec) \
|
||||
do { \
|
||||
__scc_vec_free((vec).data); \
|
||||
(vec).data = NULL; \
|
||||
(vec).data = nullptr; \
|
||||
(vec).size = (vec).cap = 0; \
|
||||
} while (0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user