Skip to content

Fix g++ 11 incompatibility issue - #16512

Merged
yingfeng merged 1 commit into
infiniflow:mainfrom
yingfeng:spacy
Jul 1, 2026
Merged

yingfeng merged 1 commit into
infiniflow:mainfrom
yingfeng:spacy

Conversation

@yingfeng

@yingfeng yingfeng commented Jul 1, 2026

Copy link
Copy Markdown
Member

No description provided.

@yingfeng yingfeng added the ci Continue Integration label Jul 1, 2026
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 1, 2026
@yingfeng
yingfeng marked this pull request as draft July 1, 2026 01:41
@yingfeng
yingfeng marked this pull request as ready for review July 1, 2026 01:41
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0d3b13d6-ebb5-4898-bbdf-067de535f2b7

📥 Commits

Reviewing files that changed from the base of the PR and between 989dbe4 and 5677221.

📒 Files selected for processing (2)
  • internal/cpp/thinc_ner.cpp
  • internal/cpp/thinc_parser.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/cpp/thinc_ner.cpp
  • internal/cpp/thinc_parser.cpp

📝 Walkthrough

Walkthrough

This PR changes the internal JSON object representation in two C++ files. JVal now stores object data through a heap-allocated JObjMap* with explicit copy, move, and destruction handling. Parser and label-loading code were updated to use the new pointer-backed storage.

Changes

JVal Pointer-Based Object Storage

Layer / File(s) Summary
JVal core representation and parser changes
internal/cpp/thinc_parser.cpp
JVal now owns object data through JObjMap*, with cleanup, deep-copy, move transfer, get() null handling, and JParser::po allocating and filling obj->m.
Mirrored rework and label loading update
internal/cpp/thinc_ner.cpp
The same JVal storage and parser changes are applied, and load_labels() now iterates am->obj->m while preserving label sizing and bounded assignment.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

A rabbit hops through pointers new,
Where maps once lived, now heaps grew.
Copy, move, delete with care,
No dangling paws left in the air.
🐇✨ JVal's home rebuilt so neat,
Two files in sync, a tidy feat!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning No PR description was provided, so the required Summary section and context are missing. Add a Summary section describing the g++ 11 incompatibility, the parser/JVal changes, and why the fix is needed.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: fixing a g++ 11 compatibility problem in the C++ JSON parser.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/cpp/thinc_ner.cpp`:
- Around line 34-38: The copy-assignment operator in JVal is not exception-safe
because it deletes obj before the replacement allocation succeeds, which can
leave a dangling pointer and cause double-free in ~JVal. Update JVal::operator=
to allocate the new JObjMap copy into a temporary first, then replace obj only
after the allocation succeeds. Keep the self-assignment check and preserve the
existing copies of type, str, arr, and num in JVal.

In `@internal/cpp/thinc_parser.cpp`:
- Line 27: The JVal copy-assignment operator is not exception-safe and can leave
obj dangling if copying the JObjMap allocation fails. Update JVal::operator= to
allocate the new JObjMap before deleting the existing obj, then swap or assign
the new pointer only after successful allocation. Keep the existing
self-assignment check and ensure the ownership of obj remains valid throughout
the assignment.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a16053fc-7bb7-4791-974c-6cdd20d8d46c

📥 Commits

Reviewing files that changed from the base of the PR and between f60245f and 989dbe4.

📒 Files selected for processing (2)
  • internal/cpp/thinc_ner.cpp
  • internal/cpp/thinc_parser.cpp

Comment thread internal/cpp/thinc_ner.cpp Outdated
Comment on lines +34 to +38
JVal& operator=(const JVal& o) {
if (this != &o) { delete obj; type=o.type; str=o.str; arr=o.arr; num=o.num;
obj = o.obj ? new JObjMap(*o.obj) : nullptr; }
return *this;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Copy-assignment is not exception-safe → double-free (UB).

Same issue as thinc_parser.cpp: delete obj executes before the new allocation, so if new JObjMap(*o.obj) throws, obj is left dangling and ~JVal will delete it a second time. Allocate into a temporary first, then delete.

🛡️ Proposed fix (allocate-then-delete)
     JVal& operator=(const JVal& o) {
-        if (this != &o) { delete obj; type=o.type; str=o.str; arr=o.arr; num=o.num;
-            obj = o.obj ? new JObjMap(*o.obj) : nullptr; }
+        if (this != &o) { JObjMap* tmp = o.obj ? new JObjMap(*o.obj) : nullptr;
+            delete obj; obj = tmp; type=o.type; str=o.str; arr=o.arr; num=o.num; }
         return *this;
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
JVal& operator=(const JVal& o) {
if (this != &o) { delete obj; type=o.type; str=o.str; arr=o.arr; num=o.num;
obj = o.obj ? new JObjMap(*o.obj) : nullptr; }
return *this;
}
JVal& operator=(const JVal& o) {
if (this != &o) { JObjMap* tmp = o.obj ? new JObjMap(*o.obj) : nullptr;
delete obj; obj = tmp; type=o.type; str=o.str; arr=o.arr; num=o.num; }
return *this;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/cpp/thinc_ner.cpp` around lines 34 - 38, The copy-assignment
operator in JVal is not exception-safe because it deletes obj before the
replacement allocation succeeds, which can leave a dangling pointer and cause
double-free in ~JVal. Update JVal::operator= to allocate the new JObjMap copy
into a temporary first, then replace obj only after the allocation succeeds.
Keep the self-assignment check and preserve the existing copies of type, str,
arr, and num in JVal.

Comment thread internal/cpp/thinc_parser.cpp Outdated
~JVal(){delete obj;}
JVal()=default;
JVal(const JVal& o):type(o.type),str(o.str),arr(o.arr),num(o.num){if(o.obj)obj=new JObjMap(*o.obj);}
JVal& operator=(const JVal& o){if(this!=&o){delete obj;type=o.type;str=o.str;arr=o.arr;num=o.num;obj=o.obj?new JObjMap(*o.obj):nullptr;}return*this;}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Copy-assignment is not exception-safe → double-free (UB).

delete obj runs first, leaving obj dangling. If the subsequent new JObjMap(*o.obj) throws (e.g. bad_alloc), obj still points at freed memory, and the eventual ~JVal(){delete obj;} deletes it again. Allocate before deleting.

🛡️ Proposed fix (allocate-then-delete)
-    JVal& operator=(const JVal& o){if(this!=&o){delete obj;type=o.type;str=o.str;arr=o.arr;num=o.num;obj=o.obj?new JObjMap(*o.obj):nullptr;}return*this;}
+    JVal& operator=(const JVal& o){if(this!=&o){JObjMap* tmp=o.obj?new JObjMap(*o.obj):nullptr;delete obj;obj=tmp;type=o.type;str=o.str;arr=o.arr;num=o.num;}return*this;}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
JVal& operator=(const JVal& o){if(this!=&o){delete obj;type=o.type;str=o.str;arr=o.arr;num=o.num;obj=o.obj?new JObjMap(*o.obj):nullptr;}return*this;}
JVal& operator=(const JVal& o){if(this!=&o){JObjMap* tmp=o.obj?new JObjMap(*o.obj):nullptr;delete obj;obj=tmp;type=o.type;str=o.str;arr=o.arr;num=o.num;}return*this;}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/cpp/thinc_parser.cpp` at line 27, The JVal copy-assignment operator
is not exception-safe and can leave obj dangling if copying the JObjMap
allocation fails. Update JVal::operator= to allocate the new JObjMap before
deleting the existing obj, then swap or assign the new pointer only after
successful allocation. Keep the existing self-assignment check and ensure the
ownership of obj remains valid throughout the assignment.

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (3633d08) to head (5677221).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16512   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yingfeng
yingfeng merged commit 6648fe4 into infiniflow:main Jul 1, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant