[SERVER-69915] Consider calling getOwned for object_owned idl type Created: 22/Sep/22 Updated: 20/Mar/23 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Randolph Tan | Assignee: | Backlog - Service Architecture |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | lowcontext | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||
| Assigned Teams: |
Service Arch
|
||||||||||||
| Participants: | |||||||||||||
| Description |
|
when generating the constructor. Generates code looks like this:
Instead of
consider doing this instead:
|
| Comments |
| Comment by Billy Donahue [ 23/Sep/22 ] | ||||||||||||||
|
I see. Thanks Max. I'm wondering how the "owned" guarantee should be enforced now. The owned-ness is dynamic, which is something that keeps causing bugs like this one. Taking ownership is basically free if the object is already owned. Suppose there was an "OwnedBSONObj" type. Obviously it would have a constructor that takes BSONObj. So for these setters and constructors, it's not clear that an unowned BSONObj should be accepted at all. | ||||||||||||||
| Comment by Max Hirschhorn [ 23/Sep/22 ] | ||||||||||||||
|
The object_owned type is meant to guarantee the BSONObj underlying the struct member is an owned BSONObj. That is, the IDL struct participates in keeping the underlying BSONObj alive. However, getOwned() only ends up being called when parsing and not in the constructor. This means the constructor + setters on the IDL struct allow the members to be unowned BSONObj still.
| ||||||||||||||
| Comment by Billy Donahue [ 22/Sep/22 ] | ||||||||||||||
|
Why would getOwned() be better than a std::move ? Asking for real. I don't know what the "object_owned" type means exactly. |