@@ -117,6 +117,9 @@ def self.attach_function_eagerly(native_name, argument_types, return_type,
117
117
string_args . freeze
118
118
119
119
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
120
123
121
124
bound_func = func . bind ( "(#{ nfi_args_types . join ( ',' ) } ):#{ nfi_return_type } " )
122
125
@@ -151,6 +154,12 @@ def self.attach_function_eagerly(native_name, argument_types, return_type,
151
154
result = Truffle ::FFI ::Pointer . new ( Truffle ::Interop . as_pointer ( result ) )
152
155
elsif return_type == :ssize_t
153
156
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
154
163
end
155
164
156
165
result
@@ -181,7 +190,7 @@ def self.attach_function_eagerly(native_name, argument_types, return_type,
181
190
attach_function :fcntl , [ :int , :int , :int ] , :int
182
191
attach_function :truffleposix_flock , [ :int , :int ] , :int , LIBTRUFFLEPOSIX , true
183
192
attach_function :truffleposix_fstat , [ :int , :pointer ] , :int , LIBTRUFFLEPOSIX
184
- attach_function :truffleposix_fstat_mode , [ :int ] , :long , LIBTRUFFLEPOSIX
193
+ attach_function :truffleposix_fstat_mode , [ :int ] , :mode_t , LIBTRUFFLEPOSIX
185
194
attach_function :truffleposix_fstat_size , [ :int ] , :long , LIBTRUFFLEPOSIX
186
195
attach_function :fsync , [ :int ] , :int
187
196
attach_function :ftruncate , [ :int , :off_t ] , :int
@@ -193,7 +202,7 @@ def self.attach_function_eagerly(native_name, argument_types, return_type,
193
202
attach_function :link , [ :string , :string ] , :int
194
203
attach_function :lseek , [ :int , :off_t , :int ] , :off_t
195
204
attach_function :truffleposix_lstat , [ :string , :pointer ] , :int , LIBTRUFFLEPOSIX
196
- attach_function :truffleposix_lstat_mode , [ :string ] , :long , LIBTRUFFLEPOSIX
205
+ attach_function :truffleposix_lstat_mode , [ :string ] , :mode_t , LIBTRUFFLEPOSIX
197
206
attach_function :truffleposix_major , [ :dev_t ] , :uint , LIBTRUFFLEPOSIX
198
207
attach_function :truffleposix_minor , [ :dev_t ] , :uint , LIBTRUFFLEPOSIX
199
208
attach_function :mkdir , [ :string , :mode_t ] , :int
@@ -210,7 +219,7 @@ def self.attach_function_eagerly(native_name, argument_types, return_type,
210
219
attach_function :seekdir , [ :pointer , :long ] , :void
211
220
attach_function :truffleposix_select , [ :int , :pointer , :int , :pointer , :int , :pointer , :long ] , :int , LIBTRUFFLEPOSIX
212
221
attach_function :truffleposix_stat , [ :string , :pointer ] , :int , LIBTRUFFLEPOSIX
213
- attach_function :truffleposix_stat_mode , [ :string ] , :long , LIBTRUFFLEPOSIX
222
+ attach_function :truffleposix_stat_mode , [ :string ] , :mode_t , LIBTRUFFLEPOSIX
214
223
attach_function :truffleposix_stat_size , [ :string ] , :long , LIBTRUFFLEPOSIX
215
224
attach_function :symlink , [ :string , :string ] , :int
216
225
attach_function :telldir , [ :pointer ] , :long
0 commit comments