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

copy byte arrays upon string construction #102

Closed
StefanKarpinski opened this issue Jul 8, 2011 · 4 comments
Closed

copy byte arrays upon string construction #102

StefanKarpinski opened this issue Jul 8, 2011 · 4 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@StefanKarpinski
Copy link
Member

Strings are immutable by interface even though manipulation of their underlying data is not prevented. This violates that abstraction:

julia> bytes = linspace(uint8('A'),uint8('F'))
[65,66,67,68,69,70]

julia> str = ASCIIString(bytes)
"ABCDEF"

julia> bytes[1] += 32
[97,66,67,68,69,70]

julia> str
"aBCDEF"

Here, changing a mutable object affects the state of a string object whose interface is immutable.

@ghost ghost assigned StefanKarpinski Jul 8, 2011
@JeffBezanson
Copy link
Member

This is extremely nasty. How can we avoid allocating two byte arrays for every string constructed?
And it is still possible to pull out str.data and mutate it, so it's not like this overhead fixes the problem completely.
I'm inclined to pretend this bug is a feature.

@StefanKarpinski
Copy link
Member Author

I'd be ok with that. It basically just need to be stated in BIG RED LETTERS that if you pass a byte array to ASCIIString or UTF8String that you no longer own that array. It's gone. Belongs to the string.

In general, I feel like the private vs. public contract in Julia is this: an object's state is private — if you access it directly and change it, you had better know what you're doing; if you just manipulate an object with functions that are provided to manipulate it, then that's safe because those are its public interface. So the fact that str's state can be mutated "illegally" by accessing and changing str.data doesn't really bother me.

@JeffBezanson
Copy link
Member

Fine. Close it!

@StefanKarpinski
Copy link
Member Author

We could also make copying and non-copying versions with the default being copying.

cmcaine pushed a commit to cmcaine/julia that referenced this issue Sep 24, 2020
fredrikekre added a commit that referenced this issue Feb 26, 2021
$ git log --pretty=oneline --abbrev=commit 2b4bed9..6bb8306
6bb83068bd796c4890baaeb39628ff79a4979374 Stop the grace timer iff adding first handle (fix #99) (#102)
af6864d8872247faf2a402d6b2baca5cb74ab96e fix ssh_key_pass bug (fix #91) (#100)
KristofferC pushed a commit that referenced this issue Feb 26, 2021
$ git log --pretty=oneline --abbrev=commit 2b4bed9..6bb8306
6bb83068bd796c4890baaeb39628ff79a4979374 Stop the grace timer iff adding first handle (fix #99) (#102)
af6864d8872247faf2a402d6b2baca5cb74ab96e fix ssh_key_pass bug (fix #91) (#100)
KristofferC pushed a commit that referenced this issue Mar 2, 2021
$ git log --pretty=oneline --abbrev=commit 2b4bed9..6bb8306
6bb83068bd796c4890baaeb39628ff79a4979374 Stop the grace timer iff adding first handle (fix #99) (#102)
af6864d8872247faf2a402d6b2baca5cb74ab96e fix ssh_key_pass bug (fix #91) (#100)

(cherry picked from commit fb500b0)
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this issue May 4, 2021
…uliaLang#39833)

$ git log --pretty=oneline --abbrev=commit 2b4bed9..6bb8306
6bb83068bd796c4890baaeb39628ff79a4979374 Stop the grace timer iff adding first handle (fix JuliaLang#99) (JuliaLang#102)
af6864d8872247faf2a402d6b2baca5cb74ab96e fix ssh_key_pass bug (fix JuliaLang#91) (JuliaLang#100)
antoine-levitt pushed a commit to antoine-levitt/julia that referenced this issue May 9, 2021
…uliaLang#39833)

$ git log --pretty=oneline --abbrev=commit 2b4bed9..6bb8306
6bb83068bd796c4890baaeb39628ff79a4979374 Stop the grace timer iff adding first handle (fix JuliaLang#99) (JuliaLang#102)
af6864d8872247faf2a402d6b2baca5cb74ab96e fix ssh_key_pass bug (fix JuliaLang#91) (JuliaLang#100)
staticfloat pushed a commit that referenced this issue Dec 23, 2022
$ git log --pretty=oneline --abbrev=commit 2b4bed9..6bb8306
6bb83068bd796c4890baaeb39628ff79a4979374 Stop the grace timer iff adding first handle (fix #99) (#102)
af6864d8872247faf2a402d6b2baca5cb74ab96e fix ssh_key_pass bug (fix #91) (#100)

(cherry picked from commit fb500b0)
Keno pushed a commit that referenced this issue Oct 9, 2023
* An export-worthy API for break_on_error

Some day we hope to have more possibilities for triggering automatic
breakpoints (issue #102). For now, let's at least establish an
extensible user-level API.
NHDaly pushed a commit that referenced this issue May 22, 2024
This needed updating for 1.10 (#102).

* port pool stats to 1.10

* increment/decrement current_pg_count

---------

Co-authored-by: K Pamnany <kpamnany@users.noreply.github.com>
Keno added a commit that referenced this issue Jun 5, 2024
Stdlib: Distributed
URL: https://github.com/JuliaLang/Distributed.jl
Stdlib branch: master
Julia branch: master
Old commit: 6a07d98
New commit: 6c7cdb5
Julia version: 1.12.0-DEV
Distributed version: 1.11.0(Does not match)
Bump invoked by: @Keno
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaLang/Distributed.jl@6a07d98...6c7cdb5

```
$ git log --oneline 6a07d98..6c7cdb5
6c7cdb5 Don't rely on implicit binding creation by setglobal (#102)
3b889ee Create dependabot.yml (#82)
```

Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
Co-authored-by: Keno Fischer <keno@juliacomputing.com>
KristofferC pushed a commit that referenced this issue Jun 7, 2024
Stdlib: Distributed
URL: https://github.com/JuliaLang/Distributed.jl
Stdlib branch: master
Julia branch: master
Old commit: 6a07d98
New commit: 6c7cdb5
Julia version: 1.12.0-DEV
Distributed version: 1.11.0(Does not match)
Bump invoked by: @Keno
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaLang/Distributed.jl@6a07d98...6c7cdb5

```
$ git log --oneline 6a07d98..6c7cdb5
6c7cdb5 Don't rely on implicit binding creation by setglobal (#102)
3b889ee Create dependabot.yml (#82)
```

Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
Co-authored-by: Keno Fischer <keno@juliacomputing.com>
(cherry picked from commit 06a90c5)
KristofferC pushed a commit that referenced this issue Jun 7, 2024
Stdlib: Distributed
URL: https://github.com/JuliaLang/Distributed.jl
Stdlib branch: master
Julia branch: master
Old commit: 6a07d98
New commit: 6c7cdb5
Julia version: 1.12.0-DEV
Distributed version: 1.11.0(Does not match)
Bump invoked by: @Keno
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaLang/Distributed.jl@6a07d98...6c7cdb5

```
$ git log --oneline 6a07d98..6c7cdb5
6c7cdb5 Don't rely on implicit binding creation by setglobal (#102)
3b889ee Create dependabot.yml (#82)
```

Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
Co-authored-by: Keno Fischer <keno@juliacomputing.com>
(cherry picked from commit 06a90c5)
inkydragon pushed a commit that referenced this issue Dec 15, 2024
Stdlib: SHA
URL: https://github.com/JuliaCrypto/SHA.jl.git
Stdlib branch: master
Julia branch: master
Old commit: aaf2df6
New commit: 8fa221d
Julia version: 1.12.0-DEV
SHA version: 0.7.0(Does not match)
Bump invoked by: @inkydragon
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaCrypto/SHA.jl@aaf2df6...8fa221d

```
$ git log --oneline aaf2df6..8fa221d
8fa221d ci: update doctest config (#120)
346b359 ci: Update ci config (#115)
aba9014 Fix type mismatch for `shake/digest!` and setup x86 ci (#117)
0b76d04 Merge pull request #114 from JuliaCrypto/dependabot/github_actions/codecov/codecov-action-5
5094d9d Update .github/workflows/CI.yml
45596b1 Bump codecov/codecov-action from 4 to 5
230ab51 test: remove outdate tests (#113)
7f25aa8 rm: Duplicated const alias (#111)
aa72f73 [SHA3] Fix padding special-case (#108)
3a01401 Delete Manifest.toml (#109)
da351bb Remvoe all getproperty funcs (#99)
4eee84f Bump codecov/codecov-action from 3 to 4 (#104)
15f7dbc Bump codecov/codecov-action from 1 to 3 (#102)
860e6b9 Bump actions/checkout from 2 to 4 (#103)
8e5f0ea Add dependabot to auto update github actions (#100)
4ab324c Merge pull request #98 from fork4jl/sha512-t
a658829 SHA-512: add ref to NIST standard
11a4c73 Apply suggestions from code review
969f867 Merge pull request #97 from fingolfin/mh/Vector
b1401fb SHA-512: add NIST test
4d7091b SHA-512: add to docs
09fef9a SHA-512: test SHA-512/224, SHA-512/256
7201b74 SHA-512: impl SHA-512/224, SHA-512/256
4ab85ad Array -> Vector
8ef91b6 fixed bug in padding for shake, addes testcases for full code coverage (#95)
88e1c83 Remove non-existent property (#75)
068f85d shake128,shake256: fixed typo in export declarations (#93)
176baaa SHA3 xof shake128 and shake256  (#92)
e1af7dd Hardcode doc edit backlink
```

Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants