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

Cannot call pointerset at toplevel #31182

Open
timholy opened this issue Feb 26, 2019 · 7 comments
Open

Cannot call pointerset at toplevel #31182

timholy opened this issue Feb 26, 2019 · 7 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@timholy
Copy link
Member

timholy commented Feb 26, 2019

julia> TT = Union{UInt8, Int8}
Union{Int8, UInt8}

julia> a = TT[0x0, 0x1]
2-element Array{Union{Int8, UInt8},1}:
 0x00
 0x01

julia> pa = pointer(a)
Ptr{Union{Int8, UInt8}} @0x00007fc52a508bf0

julia> Base.pointerset(pa, 0x01, 2, 1)
ERROR: pointerset: invalid pointer
Stacktrace:
 [1] top-level scope at none:0

but

julia> unsafe_store!(pa, 0x01, 2)
Ptr{Union{Int8, UInt8}} @0x00007fc52a508bf0

Ref JuliaDebug/JuliaInterpreter.jl#76

@timholy
Copy link
Member Author

timholy commented Feb 26, 2019

If this isn't trivially fixable, "calls to pointerset must be compiled" would be a clearer error message.

@Keno
Copy link
Member

Keno commented Feb 26, 2019

Seems like this should be disallowed in the compiled version also and whatever the users are of this should be fixed.

@timholy
Copy link
Member Author

timholy commented Feb 26, 2019

Comes from

julia/test/arrayops.jl

Lines 2506 to 2519 in 4b01e6a

let TT = Union{UInt8, Int8}
a = TT[0x0, 0x1]
b = TT[0x0, 0x0]
pa = pointer(a)
pb = pointer(b)
resize!(a, 1) # sets a[2] = 0
resize!(b, 1)
@assert pointer(a) == pa
@assert pointer(b) == pb
unsafe_store!(pa, 0x1, 2) # reset a[2] to 1
@test length(a) == length(b) == 1
@test a[1] == b[1] == 0x0
@test a == b
end

@JeffBezanson
Copy link
Member

Yeah, that code doesn't even work:

julia> a = TT[0x0,0x0];

julia> pa = pointer(a);

julia> unsafe_store!(pa, 0x1, 2);

julia> a
2-element Array{Union{Int8, UInt8},1}:
 0x00
 0x00

@JeffBezanson
Copy link
Member

I think we could allow it though, since we do have a defined memory layout for this. It would be a bit silly to allow this for references (we do, though of course there's a strong case against it) but not bits unions.

@vtjnash
Copy link
Member

vtjnash commented Mar 4, 2019

We can't entirely make it valid there—we have no possible way to know where the metadata for the value is located.

@JeffBezanson
Copy link
Member

Right, it would not update the metadata. It would just be a way to manipulate the raw data representation. One can of course question the wisdom of that, but that's what the unsafe part is for :)

@JeffBezanson JeffBezanson added the bug Indicates an unexpected problem or unintended behavior label Mar 7, 2019
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

4 participants