Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a tool to generate the native configuration #777

Merged
merged 13 commits into from
Nov 28, 2017
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public void initializeValuesForJavaThread(DynamicObject rubyThread, Thread threa
}

if (isRubyManagedThread(thread)) {
final long pThreadID = ((Number) pthread_self.call()).longValue();
final Object pThreadID = pthread_self.call();
final int SIGVTALRM = jnr.constants.platform.Signal.SIGVTALRM.intValue();

blockingNativeCallUnblockingAction.set(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public long asPointer(TruffleObject function) {

public String resolveType(NativePlatform nativePlatform, String type) {
final Object typedef = nativePlatform.getRubiniusConfiguration().get("rbx.platform.typedef." + type);
if (typedef == null) {
throw new UnsupportedOperationException("Type " + type + " is not defined in the native configuration");
}
return toNFIType(StringOperations.getString((DynamicObject) typedef));
}

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/main/ruby/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@ def section(section)
end
end

def [](name)
def lookup(name)
get_variable(name)
end

def [](name)
value = get_variable(name)
raise KeyError, "key #{name} not found" if value.nil?
value
end

alias_method :get, :[]
end

Expand Down
4 changes: 2 additions & 2 deletions src/main/ruby/core/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ module Constants
NONBLOCK = Rubinius::Config['rbx.platform.file.O_NONBLOCK']
SYNC = Rubinius::Config['rbx.platform.file.O_SYNC']

if Rubinius::Config['rbx.platform.file.O_TMPFILE']
TMPFILE = Rubinius::Config['rbx.platform.file.O_TMPFILE']
if value = Rubinius::Config.lookup('rbx.platform.file.O_TMPFILE')
TMPFILE = value
end

# TODO: these flags should probably be imported from Platform
Expand Down
2 changes: 1 addition & 1 deletion src/main/ruby/core/posix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module Truffle::POSIX
def self.to_nfi_type(type)
if found = TYPES[type]
found
elsif typedef = Rubinius::Config["rbx.platform.typedef.#{type}"]
elsif typedef = Rubinius::Config.lookup("rbx.platform.typedef.#{type}")
TYPES[type] = to_nfi_type(typedef.to_sym)
else
TYPES[type] = type
Expand Down
13 changes: 7 additions & 6 deletions src/main/ruby/core/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ module Constants
RLIMIT_CPU = Rubinius::Config['rbx.platform.process.RLIMIT_CPU']
RLIMIT_DATA = Rubinius::Config['rbx.platform.process.RLIMIT_DATA']
RLIMIT_FSIZE = Rubinius::Config['rbx.platform.process.RLIMIT_FSIZE']
RLIMIT_MEMLOCK = Rubinius::Config['rbx.platform.process.RLIMIT_MEMLOCK']
RLIMIT_NOFILE = Rubinius::Config['rbx.platform.process.RLIMIT_NOFILE']
RLIMIT_NPROC = Rubinius::Config['rbx.platform.process.RLIMIT_NPROC']
RLIMIT_RSS = Rubinius::Config['rbx.platform.process.RLIMIT_RSS']
RLIMIT_SBSIZE = Rubinius::Config['rbx.platform.process.RLIMIT_SBSIZE']
RLIMIT_STACK = Rubinius::Config['rbx.platform.process.RLIMIT_STACK']

has_rlimit_rtprio = Rubinius::Config['rbx.platform.process.RLIMIT_RTPRIO']
if has_rlimit_rtprio
%i[RLIMIT_MEMLOCK RLIMIT_NPROC RLIMIT_RSS RLIMIT_SBSIZE].each do |limit|
if value = Rubinius::Config.lookup("rbx.platform.process.#{limit}")
const_set limit, value
end
end

if Rubinius::Config.lookup('rbx.platform.process.RLIMIT_RTPRIO')
RLIMIT_RTPRIO = Rubinius::Config['rbx.platform.process.RLIMIT_RTPRIO']
RLIMIT_RTTIME = Rubinius::Config['rbx.platform.process.RLIMIT_RTTIME']
RLIMIT_SIGPENDING = Rubinius::Config['rbx.platform.process.RLIMIT_SIGPENDING']
Expand Down
1 change: 0 additions & 1 deletion src/main/ruby/core/stat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class Buffer < Rubinius::FFI::Struct
S_IFREG = Rubinius::Config['rbx.platform.file.S_IFREG']
S_IFLNK = Rubinius::Config['rbx.platform.file.S_IFLNK']
S_IFSOCK = Rubinius::Config['rbx.platform.file.S_IFSOCK']
S_IFWHT = Rubinius::Config['rbx.platform.file.S_IFWHT']
S_ISUID = Rubinius::Config['rbx.platform.file.S_ISUID']
S_ISGID = Rubinius::Config['rbx.platform.file.S_ISGID']
S_ISVTX = Rubinius::Config['rbx.platform.file.S_ISVTX']
Expand Down
2 changes: 1 addition & 1 deletion src/main/ruby/core/truffle/ffi/ffi_struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def self.config(base, *fields)
field = field.to_sym
offset = Rubinius::Config["#{base}.#{field}.offset"]
size = Rubinius::Config["#{base}.#{field}.size"]
type = Rubinius::Config["#{base}.#{field}.type"]
type = Rubinius::Config.lookup("#{base}.#{field}.type")
type = type ? type.to_sym : FFI.size_to_type(size)

code = FFI.find_type type
Expand Down
Loading