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

introduce va_list #6661

Open
vtjnash opened this issue Apr 27, 2014 · 6 comments
Open

introduce va_list #6661

vtjnash opened this issue Apr 27, 2014 · 6 comments
Assignees
Labels
kind:julep Julia Enhancement Proposal

Comments

@vtjnash
Copy link
Sponsor Member

vtjnash commented Apr 27, 2014

proposal: introduce va_list type for ccall / cfunction

usage:

ccall(:abc, Int, (A, B, va_list{(C,D,E)}), a,b,c,d,e)
# int abc(A, B, ...) {}
# {
# abc(a,b,c,d,e);
# }

va = va_list(c,d,e)
ccall(:abc, Int, (A, B, va_list), a, b, va)
ccall(:abc, Int, (A, B, va_list{()}), a, b, va)
# int abc(A, B, va_list) {}
# {
# va_list ap;
# va_start(ap, X);
# abc(A,B, ap);
# }

definitions:

immutable va_list{T<:Tuple}
  # opaque
  va_list(args...) = (T == () ? new(magic...) : error("cannot construct a typed va_list"))
end
va_list(values...) = va_list{()}(values...)

thoughts? improvements? should I make a pull request?

@vtjnash vtjnash added the julep label Apr 27, 2014
@vtjnash vtjnash added this to the 0.4 milestone Apr 27, 2014
@JeffBezanson
Copy link
Sponsor Member

I'm not sure a va_list can or should be a constructable, first-class object. The only reason to have a va_list object is if you get one via a cfunction callback and want to pass it to another C function taking a va_list. The special () value is kind of strange.

I guess there are C compilers where the first case is different from

ccall(:abc, Int, (A, B, C, D, E)}), a,b,c,d,e)

?

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Apr 27, 2014

I guess there are C compilers where the first case is different from

yeah, but nobody uses them, just x86_64 ABI, Win64 ABI, and newer ARM specifications

That special value should be mostly invisible to the user -- the idea is to only allow the user to construct untyped versions, but to have the type parameter only for ccall. since va_list and va_list{(...)} have different meanings in ccall, this is enforced by only allowing construction of one of them.

The parser would need to be altered to recognize va_list{(...)} and apply cconvert correctly.

I was looking at making va_list constructable objects for passing to c functions that take that argument. Deconstructing them could be handled through llvm intrinsics, but it wasn't on my priority list.

@vtjnash vtjnash self-assigned this May 9, 2014
@timholy
Copy link
Sponsor Member

timholy commented Jun 11, 2014

Rather than squashing both meanings into a single va_list, what about va_types and va_args?

@Gnimuc
Copy link
Contributor

Gnimuc commented Jan 15, 2019

Any update on this? C interop in Julia would be perfect if we could support this.

@KristofferC
Copy link
Sponsor Member

Perhaps can be closed. Or only after #32748 is merged?

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Oct 15, 2019

va_list is only tangentially related to varargs, although the exact details of the proposal above need to be revisited.

@DilumAluthge DilumAluthge removed this from the 1.x milestone Mar 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:julep Julia Enhancement Proposal
Projects
None yet
Development

No branches or pull requests

7 participants