Hi Andrew, A very similar issue came up in https://github.com/JuliaLang/julia/issues/4592, which was addressed by
https://github.com/JuliaLang/julia/commit/2570b4a60e5ab5c438c57ed9a3eafa5c881bc39a If you look at the fix, you'll see that the error in your code comes from array_try_unshare or jl_array_grow_end. In either case, unsharing/resizing doesn't work for arrays sharing data with "how == 3", which means that the data being resized is actually just a pointer to the original data (defined here <https://github.com/JuliaLang/julia/blob/master/src/julia.h#L104-L108> ). In your case, what is happening is that a string is created ("hello world"), and the variable a simply gets a pointer to the underlying string data (the b_str macro does just that <https://github.com/JuliaLang/julia/blob/master/base/string.jl#L1077>), so it's sharing data (with a string that isn't referenced anymore), and therefore can't be resized. At a minimum, it would be great to have this information somewhere in the docs. A more informative error might also be useful. Would you mind opening up an issue (and/or if you're so motivated, a pull request)? Cheers, Kevin On Thu, Feb 19, 2015 at 2:39 AM, andrew cooke <[email protected]> wrote: > Hi, > > I'm trying to understand the bug report at > https://github.com/andrewcooke/CRC.jl/issues/4 which has > > julia> using CRC > > julia> crc32c = crc(CRC_32_C) > handler (generic function with 3 methods) > > julia> a = b"hello world"; > > julia> crc32c(a) > 0xc99465aa > > julia> resize!(a, 5) > ERROR: cannot resize array with shared data > in resize! at ./array.jl:545 > > but I can find no docs on what "shared data" for arrays means. All I have > found is the C code at > https://github.com/JuliaLang/julia/blob/master/src/array.c which, tbh, is > a little opaque (what is a->how? how can i reset a->shared?) > > It sounds like the array code is doing something like reference counting > and refusing to be mutable when there are references? How do I decrement > the count? > > Is there any documentation on sharing of arrays? > > My guess is that a caller could work round this by making a copy, but that > seems inefficient. Especially since my code simply iterates through the > data and then "no longer cares". > > Sorry, this email is very vague. Given the lack of docs (nothing about > sharing in the manual i can see) I wonder if I've stumbled over some > internal detail that should not be exposed to users? > > Any help appreciated, > Andrew >
