Skip to content
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

Avoid unexpected behavior if move/copy is incorrectly implemented #577

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

BerndAmend
Copy link
Contributor

ChaiScript 6 always used a shared_ptr to wrap C++ objects created in
ChaiScript. Newer versions avoid this by only wrapping objects that cannot
be copied. This has the side effect that ChaiScript depends on correctly
implemented C++ copy and move constructors in unexpected locations.
I don't think the reduced overhead (by avoiding the shared_ptr) justifies
the new behavior in every case.
Therefore, I suggest we temporarily only perform this optimization if the class
is trivially destructible, until unexpected copies and moves in ChaiScript
are fixed (if this is even possible), or there is a sanitizer/compiler warning
that can detect these cases.
Before the change the following code will call the ctor once, move once,
and the dtor twice:
auto obj = MoveableObject();
After this change it will only call the ctor once and the dtor once.

ChaiScript 6 always used a shared_ptr to wrap C++ objects created in
ChaiScript. Newer versions avoid this by only wrapping objects that cannot
be copied. This has the side effect that ChaiScript depends on correctly
implemented C++ copy and move constructors in unexpected locations.
I don't think the reduced overhead (by avoiding the shared_ptr) justifies
the new behavior in every case.
Therefore, I suggest we temporarily only perform this optimization if the class
is trivially destructible, until unexpected copies and moves in ChaiScript
are fixed (if this is even possible), or there is a sanitizer/compiler warning
that can detect these cases.
Before the change the following code will call the ctor once, move once,
and the dtor twice:
  auto obj = MoveableObject();
After this change it will only call the ctor once and the dtor once.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant