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

Document copying of type instances #194

Closed
cthulhu-rider opened this issue Apr 6, 2022 · 1 comment · Fixed by #512
Closed

Document copying of type instances #194

cthulhu-rider opened this issue Apr 6, 2022 · 1 comment · Fixed by #512
Assignees
Labels
documentation Improvements or additions to documentation enhancement Improving existing functionality
Milestone

Comments

@cthulhu-rider
Copy link
Contributor

cthulhu-rider commented Apr 6, 2022

Context

Struct type instances can be copied in two ways - Go assignment/passing to func or chan and dedicated methods (if provided). There are also two kinds of copying - shallow and deep. By default, shallow copying through assignment is expected by user if no particular methods or docs were provided.

Overview

It's unsafe to do shallow copy some of SDK message types through assignment (e.g. session.Token which was encountered in #193: direct copying was not prevented by docs, and no Copy method was provided, so mutability bug has been risen). We must protect the user from data corruption due to the mutability of copies.

Proposal

Explore copying safety of all SDK types, and prevent direct copying by adding corresponding type docs and methods:

// T ...
//
// T MUST NOT be copied by value: make a copy using `CopyTo` method.
//
// ...
type T struct { ... }

// CopyTo writes deep copy of the T to dst.
func (x T) CopyTo(dst *T) { ... }
@cthulhu-rider cthulhu-rider added documentation Improvements or additions to documentation enhancement Improving existing functionality triage labels Apr 6, 2022
@cthulhu-rider cthulhu-rider added this to the v1.0.0 milestone Apr 6, 2022
@roman-khimov roman-khimov modified the milestones: v1.0.0, v1.0.0-rc11 Aug 30, 2023
@smallhive smallhive self-assigned this Sep 1, 2023
@cthulhu-rider
Copy link
Contributor Author

need only deep copy only, shallow copy can be done via :=

smallhive added a commit that referenced this issue Sep 5, 2023
closes #194

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
smallhive added a commit that referenced this issue Sep 6, 2023
closes #194

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
smallhive added a commit that referenced this issue Sep 6, 2023
closes #194

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
smallhive added a commit that referenced this issue Sep 6, 2023
closes #194

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
smallhive added a commit that referenced this issue Sep 6, 2023
closes #194

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
smallhive added a commit that referenced this issue Sep 7, 2023
closes #194

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
smallhive added a commit that referenced this issue Sep 7, 2023
closes #194

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
smallhive added a commit that referenced this issue Sep 7, 2023
closes #194

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
smallhive added a commit that referenced this issue Sep 7, 2023
closes #194

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
smallhive added a commit that referenced this issue Sep 7, 2023
closes #194

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
roman-khimov added a commit that referenced this issue Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement Improving existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants