Closed Bug 1482828 Opened 8 years ago Closed 8 years ago

Introduce C++ analogs of Rust's nsA[C]StringBulkWriteHandle

Categories

(Core :: XPCOM, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla63
Tracking Status
firefox63 --- fixed

People

(Reporter: hsivonen, Assigned: hsivonen)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Starting a bulk write on an nsA[C]String in Rust gives you a RAII handle that puts the string in a valid state in case an error causes an early return before the bulk write is successfully finished. Rust's borrow system also prevents access to the string by other means while the bulk write remains unfinished. C++ can't replicate the latter point, but it can replicate the former point about handling early returns before successful bulk write finish. We could introduce C++ RAII types (for nsAString and nsACString) that take care of this.
I failed to figure out how mozilla::BulkWriteHandle, which is supposed to have move semantics, can be used as the success type wrapped in mozilla::Result. Is it possible? How? https://phabricator.services.mozilla.com/D3405#inline-12152
Flags: needinfo?(nfroyd)
I guess you encountered some sort of compilation error? It's hard to say what the problem is without further details about the error. I did file bug 1418624 about some replacement/addition for Result::unwrap which is friendlier to move-only types, which I think might address your concern?
Flags: needinfo?(nfroyd)
(In reply to Nathan Froyd [:froydnj] from comment #2) > I guess you encountered some sort of compilation error? Yes. mozilla::Result wants a copy constructor and the compiler tells me I've deleted it. > I did file bug > 1418624 about some replacement/addition for Result::unwrap which is > friendlier to move-only types, which I think might address your concern? Thanks. It looks like I can't use mozilla::Result for this until that bug is fixed. :-( I'll use an outparam for error.
MozReview-Commit-ID: BZyHd4VzNur
Blocks: 1483603
No longer blocks: 1483603
Blocks: 1484668
Blocks: 1485026
Comment on attachment 9001235 [details] Bug 1482828 - Introduce C++ analogs of Rust's nsA[C]StringBulkWriteHandle. Nathan Froyd [:froydnj] has approved the revision.
Attachment #9001235 - Flags: review+
Pushed by hsivonen@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/400d4a90fe04 Introduce C++ analogs of Rust's nsA[C]StringBulkWriteHandle. r=froydnj
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla63
Component: String → XPCOM
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: