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

Add VaList API #5103

Merged
merged 2 commits into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/intrinsics.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ lib Intrinsics

# TODO: uncomment and use in int.cr after Crystal 0.23.1
# fun popcount128 = "llvm.ctpop.i128"(src : Int128) : Int128

fun va_start = "llvm.va_start"(ap : Void*)
fun va_end = "llvm.va_end"(ap : Void*)
end

macro debugger
Expand Down
3 changes: 3 additions & 0 deletions src/lib_c/aarch64-linux-gnu/c/stdarg.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib LibC
type VaList = Void*
end
10 changes: 10 additions & 0 deletions src/lib_c/amd64-unknown-openbsd/c/stdarg.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
lib LibC
struct VaListTag
gp_offset : UInt
fp_offset : UInt
overflow_arg_area : Void*
reg_save_area : Void*
end

type VaList = VaListTag[1]
end
3 changes: 3 additions & 0 deletions src/lib_c/arm-linux-gnueabihf/c/stdarg.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib LibC
type VaList = Void*
end
3 changes: 3 additions & 0 deletions src/lib_c/i686-linux-gnu/c/stdarg.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib LibC
type VaList = Void*
end
10 changes: 10 additions & 0 deletions src/lib_c/x86_64-linux-gnu/c/stdarg.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
lib LibC
struct VaListTag
gp_offset : UInt
fp_offset : UInt
overflow_arg_area : Void*
reg_save_area : Void*
end

type VaList = VaListTag[1]
end
10 changes: 10 additions & 0 deletions src/lib_c/x86_64-linux-musl/c/stdarg.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
lib LibC
struct VaListTag
gp_offset : UInt
fp_offset : UInt
overflow_arg_area : Void*
reg_save_area : Void*
end

type VaList = VaListTag[1]
end
10 changes: 10 additions & 0 deletions src/lib_c/x86_64-macosx-darwin/c/stdarg.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
lib LibC
struct VaListTag
gp_offset : UInt
fp_offset : UInt
overflow_arg_area : Void*
reg_save_area : Void*
end

type VaList = VaListTag[1]
end
10 changes: 10 additions & 0 deletions src/lib_c/x86_64-portbld-freebsd/c/stdarg.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
lib LibC
struct VaListTag
gp_offset : UInt
fp_offset : UInt
overflow_arg_area : Void*
reg_save_area : Void*
end

type VaList = VaListTag[1]
end
1 change: 1 addition & 0 deletions src/prelude.cr
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ require "time"
require "tuple"
require "unicode"
require "union"
require "va_list"
require "value"
20 changes: 20 additions & 0 deletions src/va_list.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "c/stdarg"

class VaList
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a struct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

# :nodoc:
getter to_unsafe

# :nodoc:
def initialize(@to_unsafe : LibC::VaList)
end

def self.open
ap = uninitialized LibC::VaList
Intrinsics.va_start pointerof(ap)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use out ap here?

Copy link
Contributor Author

@makenowjust makenowjust Oct 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because va_start needs Void* but ap must be VaList.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, makes sense.

begin
yield new(ap)
ensure
Intrinsics.va_end pointerof(ap)
end
end
end