Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions spec/ffi/fixtures/FunctionTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void testBlockingClose(struct testBlockingData *self) {
}

static int sum_varargs(va_list args) {
char sum = 0;
int sum = 0;
int arg;
while ((arg = va_arg(args, int)) != 0) {
sum += arg;
Expand All @@ -76,27 +76,27 @@ static int sum_varargs(va_list args) {
/* Write c to pipe1 and return the value read from pipe2, or 0 if there’s
* an error such as a timeout, or if c does not equal the sum of the
* zero-terminated list of char arguments. */
char testBlockingWRva(struct testBlockingData *self, char c, ...) {
char testBlockingWRva(struct testBlockingData *self, int c, ...) {
va_list args;
va_start(args, c);
if (sum_varargs(args) != c) {
return 0;
}

if( pipeHelperWriteChar(self->pipe1[1], c) != 1)
if( pipeHelperWriteChar(self->pipe1[1], (char)c) != 1)
return 0;
return pipeHelperReadChar(self->pipe2[0], 10);
}

char testBlockingRWva(struct testBlockingData *self, char c, ...) {
char testBlockingRWva(struct testBlockingData *self, int c, ...) {
va_list args;
va_start(args, c);
if (sum_varargs(args) != c) {
return 0;
}

char d = pipeHelperReadChar(self->pipe1[0], 10);
if( pipeHelperWriteChar(self->pipe2[1], c) != 1)
if( pipeHelperWriteChar(self->pipe2[1], (char)c) != 1)
return 0;
return d;
}
Expand Down
6 changes: 3 additions & 3 deletions spec/ffi/variadic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module LibTest
callback :cbVrL, [:long], :long

attach_function :testBlockingOpen, [ ], :pointer
attach_function :testBlockingRWva, [ :pointer, :char, :varargs ], :char, :blocking => true
attach_function :testBlockingWRva, [ :pointer, :char, :varargs ], :char, :blocking => true
attach_function :testBlockingRWva, [ :pointer, :int, :varargs ], :char, :blocking => true
attach_function :testBlockingWRva, [ :pointer, :int, :varargs ], :char, :blocking => true
attach_function :testBlockingClose, [ :pointer ], :void
attach_function :testCallbackVrDva, :testClosureVrDva, [ :double, :varargs ], :double
attach_function :testCallbackVrILva, :testClosureVrILva, [ :int, :long, :varargs ], :long
Expand All @@ -44,7 +44,7 @@ module LibTest
skip 'this is not yet implemented on Truffleruby' if RUBY_ENGINE == 'truffleruby'

fun = LibTest.attached_functions[:testBlockingWRva]
expect(fun.param_types).to eq([FFI::Type::POINTER, FFI::Type::CHAR, FFI::Type::VARARGS])
expect(fun.param_types).to eq([FFI::Type::POINTER, FFI::Type::INT, FFI::Type::VARARGS])
expect(fun.return_type).to eq(FFI::Type::INT8)
end

Expand Down