Skip to content
Merged
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
12 changes: 10 additions & 2 deletions lib/prism/ffi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ module LibRubyParser # :nodoc:

# Define the library that we will be pulling functions from. Note that this
# must align with the build shared library from make/rake.
ffi_lib File.expand_path("../../build/libprism.#{RbConfig::CONFIG["SOEXT"]}", __dir__)
libprism_in_build = File.expand_path("../../build/libprism.#{RbConfig::CONFIG["SOEXT"]}", __dir__)
libprism_in_libdir = "#{RbConfig::CONFIG["libdir"]}/prism/libprism.#{RbConfig::CONFIG["SOEXT"]}"
if File.exist? libprism_in_build
INCLUDE_DIR = File.expand_path("../../include", __dir__)
ffi_lib libprism_in_build
else
INCLUDE_DIR = "#{RbConfig::CONFIG["libdir"]}/prism/include"
Copy link
Member Author

Choose a reason for hiding this comment

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

As a note I used libdir here and not includedir on purpose, those headers should not be reachable with C include statements and should not be mixed with Ruby C API headers.

ffi_lib libprism_in_libdir
end

# Convert a native C type declaration into a symbol that FFI understands.
# For example:
Expand All @@ -38,7 +46,7 @@ def self.resolve_type(type, callbacks)
# given functions. For each one, define a function with the same name and
# signature as the C function.
def self.load_exported_functions_from(header, *functions, callbacks)
File.foreach(File.expand_path("../../include/#{header}", __dir__)) do |line|
File.foreach("#{INCLUDE_DIR}/#{header}") do |line|
# We only want to attempt to load exported functions.
next unless line.start_with?("PRISM_EXPORTED_FUNCTION ")

Expand Down