refactor(argparse): 将null替换为nullptr以提高C++兼容性

- 在argparse库中将所有null指针常量替换为nullptr
- 更新头文件和源文件中的指针初始化和比较操作
- 修改测试文件中的相关断言检查
- 更新AST定义文件中的注释说明
This commit is contained in:
zzy
2026-04-05 20:18:09 +08:00
parent 27d86d5685
commit 4144f7841c
76 changed files with 1430 additions and 998 deletions

View File

@@ -384,7 +384,7 @@ typedef struct _IMAGE_SECTION_HEADER {
// 导入表相关
typedef struct _IMAGE_IMPORT_DESCRIPTOR {
union {
DWORD Characteristics; // 0 for terminating null import descriptor
DWORD Characteristics; // 0 for terminating nullptr import descriptor
DWORD OriginalFirstThunk; // RVA to original unbound IAT
// (PIMAGE_THUNK_DATA)
} DUMMYUNIONNAME;
@@ -680,7 +680,7 @@ typedef IMAGE_SYMBOL UNALIGNED *PIMAGE_SYMBOL;
// 符号存储类
#define IMAGE_SYM_CLASS_END_OF_FUNCTION (BYTE) - 1
#define IMAGE_SYM_CLASS_NULL 0x0000
#define IMAGE_SYM_CLASS_nullptr 0x0000
#define IMAGE_SYM_CLASS_AUTOMATIC 0x0001
#define IMAGE_SYM_CLASS_EXTERNAL 0x0002
#define IMAGE_SYM_CLASS_STATIC 0x0003

View File

@@ -355,7 +355,7 @@ scc_pe_section_range scc_pe_reserve_section_header(scc_pe_builder_t *builder,
void scc_pe_write_section(scc_pe_builder_t *builder,
scc_pe_section_range *range, u8 *data,
usize data_size) {
if (range == null || data == null || data_size == 0) {
if (range == nullptr || data == nullptr || data_size == 0) {
return;
}
padding_util(builder, range->file_offset);

View File

@@ -156,11 +156,12 @@ scc_pe_buffer_t scc_pe_construct_idata(scc_pe_idata_builder_t *builder,
&scc_vec_at(lookup_table, 0), table_size);
}
// 添加NULL终止的目录项
IMAGE_IMPORT_DESCRIPTOR null_entry = image_import_descriptor_init(0, 0, 0);
// 添加nullptr终止的目录项
IMAGE_IMPORT_DESCRIPTOR nullptr_entry =
image_import_descriptor_init(0, 0, 0);
scc_memcpy(&scc_vec_at(builder->buffer,
import_file_count * sizeof(IMAGE_IMPORT_DESCRIPTOR)),
&null_entry, sizeof(IMAGE_IMPORT_DESCRIPTOR));
&nullptr_entry, sizeof(IMAGE_IMPORT_DESCRIPTOR));
// 填充Hint/Name表
scc_memcpy(&scc_vec_at(builder->buffer, hnt_offset),

View File

@@ -22,14 +22,14 @@ static void load_from_def(pe_idata_lib_ctx_t *ctx, const char *file_path,
scc_str_append_cstr(&fpath, ".def", 4);
const char *fname = scc_str_as_cstr(&fpath);
scc_file_t fp = scc_fopen(fname, SCC_FILE_READ);
if (fp == null) {
if (fp == nullptr) {
LOG_ERROR("load_from_def file read error: %s", fname);
return;
}
usize fsize = scc_fsize(fp);
char *buffer = scc_malloc(fsize);
Assert(buffer != null);
Assert(buffer != nullptr);
usize read_size = scc_fread(fp, buffer, fsize);
Assert(read_size == fsize);
@@ -71,11 +71,11 @@ static void pe_idata_lib_init(pe_idata_lib_ctx_t *ctx, const char *find_path) {
static cbool pe_idata_get(pe_idata_lib_ctx_t *ctx, const char *name) {
const char *lib_name = scc_hashtable_get(&ctx->str2libsym, name);
if (lib_name == null) {
if (lib_name == nullptr) {
return false;
}
scc_pe_idata_lib_t *lib = null;
scc_pe_idata_lib_t *lib = nullptr;
scc_vec_foreach(ctx->idata_libs, i) {
scc_pe_idata_lib_t *idata_lib = &scc_vec_at(ctx->idata_libs, i);
if (scc_strcmp(lib_name, idata_lib->name) == 0) {
@@ -83,7 +83,7 @@ static cbool pe_idata_get(pe_idata_lib_ctx_t *ctx, const char *name) {
break;
}
}
if (lib == null) {
if (lib == nullptr) {
scc_pe_idata_lib_t new_lib;
new_lib.name = lib_name;
scc_vec_init(new_lib.symbol_names);
@@ -104,8 +104,8 @@ void sccf2pe(scc_pe_builder_t *builder, const sccf_t *sccf) {
sccf_sym_vec_t symtab;
scc_vec_init(symtab);
sccf_sect_data_t *code_data = null;
sccf_sect_data_t *data_data = null;
sccf_sect_data_t *code_data = nullptr;
sccf_sect_data_t *data_data = nullptr;
int num_of_section = 1;
scc_vec_foreach(sccf->sect_headers, i) {
sccf_sect_header_t *sect_header = &scc_vec_at(sccf->sect_headers, i);
@@ -221,18 +221,18 @@ void sccf2pe(scc_pe_builder_t *builder, const sccf_t *sccf) {
TODO();
}
rva -= code_range.virual_address + reloc->offset + reloc->addend;
Assert(code_data != null);
Assert(code_data != nullptr);
// FIXME 需要确保宿主机与目标机器大小端一致
*(u32 *)(scc_vec_unsafe_get_data(*code_data) + reloc->offset) = rva;
}
scc_pe_write_header(builder, &config);
if (code_data != null) {
if (code_data != nullptr) {
scc_pe_write_section(builder, &code_range,
(u8 *)scc_vec_unsafe_get_data(*code_data),
scc_vec_size(*code_data));
}
if (data_data != null) {
if (data_data != nullptr) {
scc_pe_write_section(builder, &data_range,
(u8 *)scc_vec_unsafe_get_data(*data_data),
scc_vec_size(*data_data));