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

No copy or move in NanCallback and NanAsyncWorker #331

Merged
merged 5 commits into from
May 5, 2015
Merged

Conversation

kkoopa
Copy link
Collaborator

@kkoopa kkoopa commented May 5, 2015

Fixes #330
Made the same changes to NanAsyncWorker, since it too contains a Persistent<T>.
PTAL

@bnoordhuis
Copy link
Member

Instead of declaring the copy/move constructors and operators by hand, perhaps it's better to capture the logic in a NAN_DISALLOW_COPY_MOVE_ASSIGN macro, with one commit introducing the macro and updating existing declarations, and a second commit to update NanAsyncWorker.

@kkoopa
Copy link
Collaborator Author

kkoopa commented May 5, 2015

Seems reasonable. This code exists in three places already, and I know there are some other classes (maybe NanAsciiString and friends) that prohibit some form of copying and assignment. I'll do that later today.

@agnat
Copy link
Collaborator

agnat commented May 5, 2015

Not sure about this.

Maybe it has been discussed elsewhere but isn't this a perfect application for a persistent with copy semantics?

Non-copyable objects are so... awkward.

@bnoordhuis
Copy link
Member

Maybe it has been discussed elsewhere but isn't this a perfect application for a persistent with copy semantics?

One problem with copyable persistent handles (at least, how they are currently implemented in V8), is that only the storage cell is cloned, not the auxiliary data.

You can, for example, copy a weak persistent handle but the resulting handle will be strongly persistent. That may be a non-issue for NanCallback but it's a big headache in general. Non-copyable is just easier to reason about.

@kkoopa
Copy link
Collaborator Author

kkoopa commented May 5, 2015

_NanWeakCallbackInfo, NanCallback, NanAsyncWorker and NanAsyncProgressWorker all contain Persistent members. Out of these, only NanAsyncProgressWorker is non-copyable, non-assignable and non-movable at the moment. Additionally, NanAsciiString, NanUtf8String and NanUcs2String prohibit copying and assignment but not moving.

Should all of these be made to disallow copy, assign and move?

@bnoordhuis
Copy link
Member

The default v8::Persistent is non-copyable in io.js and node.js v0.12 so their containers should be effectively non-copyable either.

Apropos move semantics, I think it should be alright to allow that but I haven't tested and I'm not 100% sure.

@kkoopa
Copy link
Collaborator Author

kkoopa commented May 5, 2015

It was you who originally suggested disallowing move for NanAsyncProgressWorker https://github.com/iojs/nan/pull/197/files#r19300699 but maybe that was because of libuv.

@kkoopa
Copy link
Collaborator Author

kkoopa commented May 5, 2015

There.

@bnoordhuis
Copy link
Member

I think in that particular case it was to make sure that ExecutionState doesn't outlive the scope of the Execute callback. That's probably not a consideration for v8::Persistent. At any rate, I don't mind taking a reactive approach and keep everything non-moveable until someone complains.

@bnoordhuis
Copy link
Member

LGTM with two suggestions.

@kkoopa
Copy link
Collaborator Author

kkoopa commented May 5, 2015

Done. I'll leave this open for a while.

@bnoordhuis
Copy link
Member

LGTM with one more suggestion.

@kkoopa
Copy link
Collaborator Author

kkoopa commented May 5, 2015

Thanks. Merging,

kkoopa added a commit that referenced this pull request May 5, 2015
No assign, copy or move in classes that can't handle it.
@kkoopa kkoopa merged commit 94c50aa into master May 5, 2015
@kkoopa kkoopa deleted the copymove branch May 5, 2015 17:11
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.

NanCallback copy semantics should be clarified
3 participants