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

jl_value_ptr function and '&' operator errror on Windows #2850

Closed
joa-quim opened this issue Apr 13, 2013 · 7 comments
Closed

jl_value_ptr function and '&' operator errror on Windows #2850

joa-quim opened this issue Apr 13, 2013 · 7 comments
Labels
kind:bug Indicates an unexpected problem or unintended behavior system:windows Affects only Windows

Comments

@joa-quim
Copy link

This error came out on the tread

https://groups.google.com/forum/?fromgroups=#!topic/julia-dev/-w5SRAMNSmU

and can be resumed in

julia> type Foo; bar::Int; end
julia> foo = Foo(1)
Foo(1)

julia> ccall(:jl_value_ptr, Ptr{Void}, (Ptr{Foo},), &(foo::Foo))
ERROR: error compiling anonymous: unsupported or misplaced expression & in function anonymous

Apparently this occurs only on Windows. It did with
Version 0.2.0
Commit e912b26

[pao: formatting]

@stevengj
Copy link
Member

I can confirm that this code works on MacOS 10.7.5 and on Debian GNU/Linux (x86_64) with commit b66fcaa, so this seems to be a Windows-specific problem.

@pao
Copy link
Member

pao commented Apr 13, 2013

cc @loladiro @vtjnash

@vtjnash
Copy link
Sponsor Member

vtjnash commented Apr 13, 2013

ah, jl_value_ptr is a special intrinsic function and is not supposed to be used like that. It's only supposed to be called through the pointer_from_objref function. the error detected on windows is correct.

@stevengj
Copy link
Member

This has nothing to do with jl_value_ptr (which is just an identity function, not an intrinsic last I checked, and gets no special treatment in ccall as far as I can tell). The error occurs in the parser before any function is called.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Apr 13, 2013

ccall tries to inline that function (jl_value_ptr) -- but it is currently broken/disabled

@stevengj
Copy link
Member

I see, ccall.cpp has special-case code:

    if (fptr == &jl_value_ptr) {
        assert(lrt->isPointerTy());
        Value *ary = emit_expr(args[4], ctx);
        JL_GC_POP();
        return mark_julia_type(builder.CreateBitCast(ary,lrt),rt);
    }

My inclination would be to remove this code, and just add a pointerfromref intrinsic (like pointertoref), since what we really want here is an intrinsic function and not a "blessed" C API function.

The underlying issue is that ccall can do magical things that ordinary Julia code cannot. It can convert jl_value_t* pointers to/from references, and it can use & to get pointers to struct-like member data. An identity function in C (like jl_value_ptr) provides a workaround to access this functionality from Julia.

Right now, PyCall is using jl_value_ptr to get access to the &foo pointer, in order to insert a pointer to a struct (Julia composite type) in another struct. A much cleaner solution will be provided by #2818 once it lands, but until then the above special-case code apparently breaks this on Windows.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Apr 23, 2013

I see it is also causing this test to fail: @test unsafe_pointer_to_objref(pointer_from_objref(e+pi)) == e+pi, presumably because the special-case code assumes that the object is actually an object (but is missing a call to boxed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Indicates an unexpected problem or unintended behavior system:windows Affects only Windows
Projects
None yet
Development

No branches or pull requests

4 participants