Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork56.4k
Added a copy constructor and an overloaded assignment operator to FileStorage#17458
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…EricFlorin/opencv into FileStorage_Assignment_Operator_Fix
asmorkalov commentedJun 4, 2020
@EricFlorin Thanks for the patch! Please take a look on CI status, buildbot reports compiler warnings: |
asmorkalov commentedJun 4, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Could you also add simple test for the new functions to ensure stability in future. |
EricFlorin commentedJun 6, 2020
Hey@asmorkalov! I wanted to say thanks for the review! I also want to ask about what kinds of tests you may be looking for when it comes to the copy and assignment operators for |
asmorkalov commentedJun 8, 2020
XML/JSON/YAML formats handling is done by different |
asmorkalov commentedJun 8, 2020
@EricFlorin Please take a look on CI status:https://pullrequest.opencv.org/buildbot/builders/precommit_linux64/builds/26297/steps/compile%20release/logs/warnings%20%282%29. CI bot reports build warnings: |
…d added new checks to copy constructor and assignment operator
EricFlorin commentedJun 9, 2020
Hey@asmorkalov, I got around to fixing the warnings on my side (we will see what the CI bot says). I also modified the reproducer code to act as a test, as well as create my own test script to test different types of cases. The scripts and support files arein this repository that I created.
If I am missing a case in my custom test script, please let me know and I will add it! |
alalek 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.
Thank you for the contribution!
Please avoid implementing of "deep-copy" logic forFileStorage.
Could you please add simple tests (including from the original issue) to test_io.cpp?
| /** @brief Copy constructor for FileStorage | ||
| Copy constructor that creates deep copies of passed in cv::FileStorage objects. Based off the full | ||
| constructor. |
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.
Almost all non-trivial OpenCV classes are designed as a smart pointers (this behavior is aligned with other language bindings):
- assignment operation means increasing object lifetime (through refcounter)
- optional deep-copy is through
.clone()operations
Deep copy is over-complicated thing forFileStorage (especially in case of write mode), so let avoid that completely.
asmorkalov commentedJun 26, 2020
@EricFlorin Do you have chance to implement proposal from@alalek |
EricFlorin commentedJun 26, 2020
Hey@asmorkalov and@alalek, Sorry for the long silence this week as I was having final exams. I did look at the proposal made by@alalek and I did roll back the deep-copy implementation on my end. However, I am stuck on coming up with a solution using smart pointers. Here's what I found so far using the reproducer code given in#17412 :
From there, I am not sure what should I do. I was thinking of having the Any thoughts? |
vpisarev commentedJul 14, 2020
@EricFlorin, thank you for the detailed research. I fixed the problem in#17841. The solution was simple – just remove "p.release()" from FileStorage destructor, because otherwise the smart pointer was released twice |
EricFlorin commentedJul 15, 2020
Thanks for letting me know@vpisarev! I was wondering what the error could be. |
tl:dr ->Fixes#17412
Hello everyone,
This is going to be my first pull request, so I'm sorry if I missed something in my submission. I appreciate any feedback as this is my first time contributing to an open source project.
Quick summary of issue#17412: a
cv::FileStorageobject that was assigned by anothercv::FileStorageobject was unusable as it was causing segfaults every time an access occurs.I look over the issue replication code provided in#17412, and I noticed that
fswas being assigned to a temporarycv::FileStorageobject. I went through the execution path of the assignment using my debugger, and noticed thatfswas not being assigned a deep copy of the temporarycv::FileStorageobject.Since
fswas not given a deep copy of the temporarycv::FileStorageobject, it loses access to the file reference in the temporarycv::FileStorageobject after the temporary object is destroyed upon assignment completion.I fixed the issue by adding a copy constructor and an overloaded assignment operator to
cv::FileStoragethat creates deep copies ofcv::FileStorageobjects. I feel that there is probably a better way of fixing this issue, but this is what I came up with for now.Thank you for reading!
Eric
Pull Request Readiness Checklist
See details athttps://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.