Skip to content

Commit 92ce89d

Browse files
committed
Fix the result when the return value is an unsigned integer type in Truffle::POSIX
1 parent aab7618 commit 92ce89d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/main/ruby/core/posix.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ def self.attach_function_eagerly(native_name, argument_types, return_type,
117117
string_args.freeze
118118

119119
nfi_return_type = to_nfi_type(return_type)
120+
if nfi_return_type.to_s.start_with?('uint')
121+
unsigned_return_type = 1 << nfi_return_type[-2..-1].to_i
122+
end
120123

121124
bound_func = func.bind("(#{nfi_args_types.join(',')}):#{nfi_return_type}")
122125

@@ -151,6 +154,12 @@ def self.attach_function_eagerly(native_name, argument_types, return_type,
151154
result = Truffle::FFI::Pointer.new(Truffle::Interop.as_pointer(result))
152155
elsif return_type == :ssize_t
153156
result = Truffle.invoke_primitive(:integer_lower, result)
157+
elsif unsigned_return_type
158+
if result >= 0
159+
result
160+
else
161+
result += unsigned_return_type
162+
end
154163
end
155164

156165
result

0 commit comments

Comments
 (0)