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

Proper ccalls with variadic arguments. #101

Open
rschwarz opened this issue Mar 2, 2019 · 8 comments
Open

Proper ccalls with variadic arguments. #101

rschwarz opened this issue Mar 2, 2019 · 8 comments
Milestone

Comments

@rschwarz
Copy link
Collaborator

rschwarz commented Mar 2, 2019

We need to call SCIPexprCreate which has variadic arguments. This is supported by Julia's ccall, but only for variadic arguments of the same type.

This was already discussed in #100 and on Discourse.

The suggested solution is to create a thin C wrapper, which exposes function without variadic arguments. Unfortunately, we still need those for SCIP_EXPR_SUM and SCIP_EXPR_PRODUCT.

@rschwarz
Copy link
Collaborator Author

rschwarz commented Mar 2, 2019

See gist for an incomplete solution sketch.

@rschwarz
Copy link
Collaborator Author

rschwarz commented Mar 3, 2019

It seems that in CSIP, we were just passing a pointer to an array as the "last" argument to SCIPexprCreate. I did not know that this is valid.

I guess usually, this array needs to be 0-terminated or something, but in this case of n-ary operators, the number of children is passed explicitly, so it might work out.

@rschwarz rschwarz added this to the 1.0 milestone Mar 3, 2019
@bhalonen
Copy link

look into CBinding for a solution to this problem: https://github.com/analytech-solutions/CBinding.jl

@rschwarz
Copy link
Collaborator Author

Thanks for the hint. I understand that the issue stems from a limitation of Julia's ccall, so I would be surprised to find a solution in a Julia package, but you never know...

@bhalonen
Copy link

julia> func = Cfunction{Cint, Tuple{Cstring, Vararg}}(lib, :printf)    # int (*func)(char *, ...) = dlsym(lib, "printf");
Ptr{Cfunction{Nothing,Tuple{Cstring,Vararg{Any,N} where N}}} @0x000061eefc388930

julia> func("%s i%c %ld great demo of CBinding.jl v%3.1lf%c\n", "this", 's', 1, 0.1, '!')
this is 1 great demo of CBinding.jl v0.1!

@bhalonen
Copy link

bhalonen commented Aug 27, 2019

He actually has it working, and is adding functionality over ccall. I really don't understand how it works, to be totally honest.

Scroll to the bottom of the README.md

@bhalonen
Copy link

It is some manual memory mapping onto C types. Very impressive.

@rschwarz
Copy link
Collaborator Author

OK, great, so it does support variadic arguments of mixed types properly 😮

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants