@@ -105,6 +105,9 @@ def self.convert_native_to_ruby(type, val)
105
105
end
106
106
end
107
107
108
+ RTLD_NEXT = Truffle ::Config [ 'platform.dlopen.RTLD_NEXT' ]
109
+ RTLD_DEFAULT = Truffle ::Config [ 'platform.dlopen.RTLD_DEFAULT' ]
110
+
108
111
end
109
112
110
113
module Fiddle
@@ -234,14 +237,19 @@ def self.[](*args)
234
237
RTLD_LAZY = Truffle ::Config [ 'platform.dlopen.RTLD_LAZY' ]
235
238
RTLD_NOW = Truffle ::Config [ 'platform.dlopen.RTLD_NOW' ]
236
239
RTLD_GLOBAL = Truffle ::Config [ 'platform.dlopen.RTLD_GLOBAL' ]
237
- RTLD_NEXT = Truffle ::Config [ 'platform.dlopen.RTLD_NEXT' ]
238
- RTLD_DEFAULT = Truffle ::Config [ 'platform.dlopen.RTLD_DEFAULT' ]
239
240
240
241
def initialize ( library = nil , flags = RTLD_LAZY | RTLD_GLOBAL )
241
242
raise DLError , 'unsupported dlopen flags' if flags != RTLD_LAZY | RTLD_GLOBAL
242
- @handle = Polyglot . eval ( 'nfi' , library ? "load #{ library } " : 'default' )
243
- rescue RuntimeError
244
- raise DLError , "#{ library } : cannot open shared object file: No such file or directory"
243
+ if library == Truffle ::FiddleBackend ::RTLD_NEXT
244
+ @handle = :rtld_next
245
+ else
246
+ library = nil if library == Truffle ::FiddleBackend ::RTLD_DEFAULT
247
+ begin
248
+ @handle = Polyglot . eval ( 'nfi' , library ? "load #{ library } " : 'default' )
249
+ rescue RuntimeError
250
+ raise DLError , "#{ library } : cannot open shared object file: No such file or directory"
251
+ end
252
+ end
245
253
end
246
254
247
255
def to_i ( *args )
@@ -253,9 +261,13 @@ def close(*args)
253
261
end
254
262
255
263
def sym ( name )
256
- sym = @handle [ name ]
257
- raise DLError , "unknown symbol \" #{ name } \" " unless sym
258
- Truffle ::Interop . as_pointer ( sym )
264
+ if :rtld_next == @handle
265
+ raise DLError , 'RTLD_NEXT is not supported'
266
+ else
267
+ sym = @handle [ name ]
268
+ raise DLError , "unknown symbol \" #{ name } \" " unless sym
269
+ Truffle ::Interop . as_pointer ( sym )
270
+ end
259
271
end
260
272
261
273
alias_method :[] , :sym
@@ -272,6 +284,9 @@ def close_enabled?(*args)
272
284
raise NotImplementedError
273
285
end
274
286
287
+ DEFAULT = Handle . new ( Truffle ::FiddleBackend ::RTLD_DEFAULT )
288
+ NEXT = Handle . new ( Truffle ::FiddleBackend ::RTLD_NEXT )
289
+
275
290
end
276
291
277
292
class Pointer
0 commit comments