-
Notifications
You must be signed in to change notification settings - Fork 67
SWIFT-779 Funnel all bson_t access through helper methods #453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## master #453 +/- ##
==========================================
+ Coverage 76.21% 76.35% +0.14%
==========================================
Files 117 117
Lines 12820 12896 +76
==========================================
+ Hits 9771 9847 +76
Misses 3049 3049
Continue to review full report at Codecov.
|
|
made a few changes in my latest commit:
|
mbroadst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
patrickfreed
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great!
By the way, this also closes SWIFT-739 since the pointers are all accessed from Document.
Putting this up as a draft as we should probably talk through the approach more but I figured I'd let you all talk a look.
This seems like a mostly reasonable approach to me aside from the fact that we really end up in nested closure hell in places where a libmongoc method takes in 3+ arguments.
I think there is more work to do to ensure these problems don't plague any other types. for example I think we might be vulnerable to similar issues with
ReadPreferenceas it follows the same "struct backed by a private class wrapping a C type" pattern.To summarize main changes here:
BSONValueprotocol'sencodemethod now takes in aninout Documentrather than aDocumentStorageDocumentStorageis aprivatetype, and its property_bsonis nowfileprivate. this means both are only accessible withinDocument.swift.Document's underlyingbson_tis via helpers, all of which usewithExtendedLifetimeto guarantee theDocumentstays valid for the duration of the provided closure. These are:withMutableBSONPointerwithBSONPointer, same as the previous but the pointer is immutablewithOptionalBSONPointer, which is to simplify usage in places where we have an optional document we may need to pass to a libmongoc API (basically this is just used for options documents)DocumentIteratorpreviously stored a reference to theDocumentStorageit came from. however I don't think this is really different than it just storing a copy of theDocumentit's iterating over -- in both cases we should get CoW behavior if someone tries to modify a copy of that document which is backed by the same storage. changing this this enabled me to make the change in the previous bullet point.