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

“first argument not a pointer or valid constant expression” in ccall, v0.7-alpha #27477

Closed
jonathanBieler opened this issue Jun 7, 2018 · 6 comments
Assignees
Labels
kind:regression Regression in behavior compared to a previous version

Comments

@jonathanBieler
Copy link

jonathanBieler commented Jun 7, 2018

This seems to be a bug:

module B
    using Cairo

    test() = ccall((:cairo_version_string,Cairo._jl_libcairo),Cstring,()) 
end

julia> B.test()
ERROR: TypeError: in test, in ccall: first argument not a pointer or valid constant expression, expected Ptr, got Tuple{Symbol,String}
@JeffBezanson JeffBezanson added the kind:regression Regression in behavior compared to a previous version label Jun 7, 2018
@JeffBezanson
Copy link
Sponsor Member

I looked into this; it's due to the fact that we have special evaluation for getfield calls in ccall but not for getproperty.

@cuihantao
Copy link

I'm new to Julia, and I ran into a similar issue. The slightly modified code from the op's doesn't work.

Please kindly suggest if I made a mistake. Thank you! @JeffBezanson

      module B
           using Cairo
           lib_path = Cairo._jl_libcairo
           test() = ccall((:cairo_version_string, lib_path),Cstring,())
       end

julia> B.test()
ERROR: TypeError: in ccall: first argument not a pointer or valid constant expression, expected Ptr, got Tuple{Symbol,String}
Stacktrace:
 [1] test() at ./REPL[1]:4
 [2] top-level scope at none:0

@cuihantao
Copy link

Running Julia 1.1.0 on darwin64 by the way. I found a workaround:

module B
    using Cairo
    lib_path = Cairo._jl_libcairo
    test() = eval(:(ccall((:cairo_version_string, $lib_path),Cstring,())))
end

julia> B.test()
Cstring(0x000000012c08bc49)

@cuihantao
Copy link

cuihantao commented Apr 22, 2019

I'm trying to parametrize the argument type but ran into another issue. See the sample code below

julia> module B
           using Cairo
           lib_path = Cairo._jl_libcairo
           arg_type = ()
           call_str =:(ccall((:cairo_version_string, $lib_path),Cstring,$arg_type))
           dump(call_str)
           test() = eval(call_str)
       end
WARNING: replacing module B.
Expr
  head: Symbol call
  args: Array{Any}((4,))
    1: Symbol ccall
    2: Expr
      head: Symbol tuple
      args: Array{Any}((2,))
        1: QuoteNode
          value: Symbol cairo_version_string
        2: String "/Users/hcui7/.julia/packages/Homebrew/s09IX/deps/usr/lib/libcairo.dylib"
    3: Symbol Cstring
    4: Tuple{} ()
Main.B

julia> B.test()
ERROR: syntax: ccall argument types must be a tuple; try "(T,)"
Stacktrace:
 [1] eval at ./boot.jl:328 [inlined]
 [2] eval at ./REPL[10]:1 [inlined]
 [3] test() at ./REPL[10]:7
 [4] top-level scope at none:0

But if I hard-code the arg_type like in the last post, it works:

julia> module B
           using Cairo
           lib_path = Cairo._jl_libcairo
           arg_type = ()
           call_str =:(ccall((:cairo_version_string, $lib_path),Cstring,()))
           dump(call_str)
           test() = eval(call_str)
       end
WARNING: replacing module B.
Expr
  head: Symbol call
  args: Array{Any}((4,))
    1: Symbol ccall
    2: Expr
      head: Symbol tuple
      args: Array{Any}((2,))
        1: QuoteNode
          value: Symbol cairo_version_string
        2: String "/Users/hcui7/.julia/packages/Homebrew/s09IX/deps/usr/lib/libcairo.dylib"
    3: Symbol Cstring
    4: Expr
      head: Symbol tuple
      args: Array{Any}((0,))
Main.B

julia> B.test()
Cstring(0x0000000123892c49)

Julia>

@yuyichao
Copy link
Contributor

Please use discourse for questions.

@cuihantao
Copy link

Ok, just posted to discourse @yuyichao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

4 participants