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

implement reinterpret using jl_reshape_array #232

Closed
StefanKarpinski opened this issue Oct 17, 2011 · 8 comments
Closed

implement reinterpret using jl_reshape_array #232

StefanKarpinski opened this issue Oct 17, 2011 · 8 comments
Assignees
Labels
breaking This change will break code
Milestone

Comments

@StefanKarpinski
Copy link
Member

This should as a side-effect allow the result array to share memory with the argument array.

@ghost ghost assigned StefanKarpinski Oct 17, 2011
@JeffBezanson
Copy link
Member

Here's a non-obvious issue: I currently allocate all byte arrays with a hidden extra 0 at the end so they can be passed to C as strings without worrying about it. If an array is reinterpreted in place to a byte array, that 0 won't be there.

@StefanKarpinski
Copy link
Member Author

Good call. That would certainly be a subtle nasty bug at some point. Two possibly options I can think of:

  • put a zero byte at the end of all arrays
  • only add the zero byte when the array is made part of a ByteString object

For the latter, the way that makes the most sense to me is that when an array of bytes is "given" to a byte string (ASCII or UTF-8) we grow the array by one byte which is set to zero and then the length of the string object is one less than its data buffer. This has the advantage of not adding extra overhead to all byte arrays and being far less magical than what we have now.

@StefanKarpinski
Copy link
Member Author

The downside, of course is that it doesn't address actual Array{Uint8} objects.

@StefanKarpinski
Copy link
Member Author

This would actually be breaking since it changes the semantics of reinterpret. Idea: maybe we should have reshape! and reinterpret! as the memory-sharing versions and have reshape and reinterpret as the copying versions. The above issues with reinterpret still exist.

@JeffBezanson
Copy link
Member

I think it's pretty important NOT to name this reinterpret!, because code that uses it can still be purely functional. Same with reshape of course.

@StefanKarpinski
Copy link
Member Author

How should we handle the trailing NUL thing?

@JeffBezanson
Copy link
Member

We should probably just put a zero at the end of all arrays, that's simplest.

@JeffBezanson
Copy link
Member

Ok, I'm changing my mind now. That extra byte will require an extra word, which is really not ok for small arrays. Plus, reinterpreting a non-byte array to a byte array and then using it as a string is an extremely strange thing to do. Indeed I can't think of a single use case for that. We might just have to document that only arrays originally allocated as byte arrays have the extra 0.

cmcaine added a commit to cmcaine/julia that referenced this issue Sep 24, 2020
cmcaine added a commit to cmcaine/julia that referenced this issue Sep 24, 2020
cmcaine added a commit to cmcaine/julia that referenced this issue Sep 24, 2020
cmcaine added a commit to cmcaine/julia that referenced this issue Sep 24, 2020
cmcaine added a commit to cmcaine/julia that referenced this issue Sep 24, 2020
IanButterworth pushed a commit that referenced this issue Aug 28, 2024
…1061ecc (#55615)

Stdlib: Downloads
URL: https://github.com/JuliaLang/Downloads.jl.git
Stdlib branch: master
Julia branch: backports-release-1.11
Old commit: a9d274f
New commit: 1061ecc
Julia version: 1.11.0-rc2
Downloads version: 1.6.0(It's okay that it doesn't match)
Bump invoked by: @IanButterworth
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaLang/Downloads.jl@a9d274f...1061ecc

```
$ git log --oneline a9d274f..1061ecc
1061ecc Fix setting atexit. Fixes trailing download tasks during precompilation (#257)
b871386 Add debug information to `setopt` commands (#248)
51e5321 fix: use invokelatest for easy_hook, avoid race (#241)
05f9ec2 make precompile workload relocatable (#236)
2dd891a Hardcode doc edit backlink (#232)
```

Co-authored-by: Dilum Aluthge <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code
Projects
None yet
Development

No branches or pull requests

2 participants