Skip to content

Commit cd0f19d

Browse files
committed
Use Truffle::Config to resolve type aliases for sizes
1 parent beef109 commit cd0f19d

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

lib/truffle/truffle/fiddle_backend.rb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,12 @@ def self.type_to_nfi(type)
5050
end
5151
end
5252

53-
def self.int_type(size)
54-
case size
55-
when SIZEOF_INT
56-
Fiddle::TYPE_INT
57-
when SIZEOF_LONG
53+
def self.type_from_config(type)
54+
case type
55+
when 'long'
5856
Fiddle::TYPE_LONG
5957
else
60-
raise NotImplementedError, "no integer of size #{size}"
58+
raise NotImplementedError, "integer #{type} not known"
6159
end
6260
end
6361

@@ -140,10 +138,10 @@ class DLError < StandardError
140138
SIZEOF_INTPTR_T = Truffle.invoke_primitive(:pointer_find_type_size, :intptr_t)
141139
SIZEOF_UINTPTR_T = Truffle.invoke_primitive(:pointer_find_type_size, :uintptr_t)
142140

143-
TYPE_SSIZE_T = Truffle::FiddleBackend.int_type(SIZEOF_SIZE_T)
141+
TYPE_SSIZE_T = Truffle::FiddleBackend.type_from_config(Truffle::Config.lookup('platform.typedef.ssize_t'))
144142
TYPE_SIZE_T = -1 * Truffle::FiddleBackend::SIGNEDNESS_OF_SIZE_T * TYPE_SSIZE_T
145-
TYPE_PTRDIFF_T = Truffle::FiddleBackend.int_type(SIZEOF_PTRDIFF_T)
146-
TYPE_INTPTR_T = Truffle::FiddleBackend.int_type(SIZEOF_INTPTR_T)
143+
TYPE_PTRDIFF_T = Truffle::FiddleBackend.type_from_config(Truffle::Config.lookup('platform.typedef.ptrdiff_t'))
144+
TYPE_INTPTR_T = Truffle::FiddleBackend.type_from_config(Truffle::Config.lookup('platform.typedef.intptr_t'))
147145
TYPE_UINTPTR_T = -TYPE_INTPTR_T
148146

149147
# Alignment assumed to be the same as size

0 commit comments

Comments
 (0)