Skip to content

Update OpenCC's vendored RapidJSON to align with 1.1.0.bcr.20250205 - #1368

Merged
frankslin merged 2 commits into
BYVoid:masterfrom
frankslin:bcr-rapidjson
Jun 30, 2026
Merged

frankslin merged 2 commits into
BYVoid:masterfrom
frankslin:bcr-rapidjson

Conversation

@frankslin

@frankslin frankslin commented Jun 30, 2026 •

Copy link
Copy Markdown
Collaborator

CrtAllocator 改動(小)

  • std::malloc/free/realloc → RAPIDJSON_MALLOC/FREE/REALLOC 巨集 — 更可客製化,行為等價
  • 加了 operator==/!= — 供 StdAllocator 使用,純新增

MemoryPoolAllocator 結構改動(大,但相容)

核心變化是引入 SharedData(含 refcount),讓 allocator 可以被 copy:

面向 舊版 新版
copy 行為 編譯期禁止 允許,reference-counted
初始分配 惰性(AddChunk 時才分配) 構造時立即分配 SharedData + ChunkHeader
Clear() 語意 釋放到 user buffer 為止 只 reset size,不釋放第一個 chunk
預設 chunk 大小 static const int = 64*1024 #define + static const size_t,值相同
AlignBuffer 無對齊調整 按 pointer-width 對齊 user buffer

純新增(無破壞性)

  • internal::Realloc/Malloc/Free 函式模板
  • 全新 StdAllocator — 讓 rapidjson allocator 可接入 STL 容器

對 OpenCC 的影響評估

OpenCC 只用 rapidjson 做 JSON config parsing(rapidjson::Document),走預設
MemoryPoolAllocator,不直接複製 allocator 也不用 user buffer
構造函式。唯一可感知的行為差異是:現在每次 MemoryPoolAllocator
構造時就會立即分配一小塊記憶體(SharedData + 第一個 ChunkHeader header,共約 64
bytes),而舊版是惰性的。解析 config 期間記憶體本來就夠用,這個差異對 OpenCC 沒有影響。

結論:安全。 這些改動是 rapidjson upstream master 多年累積的 bugfix + 功能增強,BCR
只是把它們打包進來。對 OpenCC 現有的使用方式完全向後相容。

Sync deps/rapidjson-1.1.0/rapidjson/ with the BCR module version that
MODULE.bazel already depends on, so the vendored copy used by CMake and
wasm-lib build.sh stays consistent with the Bazel build.  The BCR
version already includes all previously local patches (Win ARM64,
GenericStringRef assignment, iterator deprecation).  Adds three new
files: cursorstreamwrapper.h, internal/clzll.h, uri.h.
rapidjson 1.1.0.bcr.20250205 already includes all three fixes we carried
in deps/rapidjson-1.1.0: the Win ARM64 endianness fix, the GenericStringRef
assignment removal, and the std::iterator deprecation fix for C++17.
No local patch is needed.

- MODULE.bazel: add bazel_dep for rapidjson 1.1.0.bcr.20250205
- src/BUILD.bazel: //deps/rapidjson-1.1.0:rapidjson → @rapidjson//:rapidjson
@frankslin
frankslin merged commit c1ab1c2 into BYVoid:master Jun 30, 2026
32 of 33 checks passed
@frankslin
frankslin deleted the bcr-rapidjson branch June 30, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant