Skip to content

Commit ec2a26c

Browse files
committed
libfoundation: Make java ffi map int types correctly
This patch ensures that java uses appropriate mappings to the sized integer types. Additionally it adds J* type definitions to the java lcb module to make foreign methods types clearer to express.
1 parent 2cd7735 commit ec2a26c

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

libfoundation/src/foundation-java-private.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,14 @@ int MCJavaMapTypeCode(MCStringRef p_type_code)
4444

4545
static bool __GetExpectedTypeCode(MCTypeInfoRef p_type, MCJavaType& r_code)
4646
{
47-
if (p_type == kMCIntTypeInfo)
47+
if (p_type == kMCInt8TypeInfo)
48+
r_code = kMCJavaTypeByte;
49+
else if (p_type == kMCInt16TypeInfo)
50+
r_code = kMCJavaTypeShort;
51+
else if (p_type == kMCInt32TypeInfo)
4852
r_code = kMCJavaTypeInt;
53+
else if (p_type == kMCInt64TypeInfo)
54+
r_code = kMCJavaTypeLong;
4955
else if (p_type == kMCBoolTypeInfo)
5056
r_code = kMCJavaTypeBoolean;
5157
else if (p_type == kMCFloatTypeInfo)
@@ -80,11 +86,6 @@ static bool __MCTypeInfoConformsToJavaType(MCTypeInfoRef p_type, MCJavaType p_co
8086
if (!__GetExpectedTypeCode(p_type, t_code))
8187
return false;
8288

83-
// Just allow long and int interchangeably for now
84-
if (t_code == kMCJavaTypeInt &&
85-
p_code == kMCJavaTypeLong)
86-
return true;
87-
8889
return t_code == p_code;
8990
}
9091

libscript/src/java.lcb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ module com.livecode.java
3434

3535
use com.livecode.foreign
3636

37+
public type JBoolean is CBool
38+
public type JByte is Int8
39+
public type JShort is Int16
40+
public type JInt is Int32
41+
public type JLong is Int64
42+
public type JFloat is CFloat
43+
public type JDouble is CDouble
44+
3745
public foreign type JObject binds to "MCJavaObjectTypeInfo"
3846
public type JString is JObject
3947
public type JByteArray is JObject

tests/lcb/stdlib/java.lcb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public handler TestGetConstant()
120120
when tPiTrunc is 3
121121
end handler
122122

123-
foreign handler CallJavaAdd(in pLeft as CInt, in pRight as CInt) returns CInt binds to "java:java.lang.Math>addExact(JJ)J!static"
123+
foreign handler CallJavaAdd(in pLeft as JLong, in pRight as JLong) returns JLong binds to "java:java.lang.Math>addExact(JJ)J!static"
124124

125125
public handler TestCallStaticMethod()
126126
variable tLeft as Number

0 commit comments

Comments
 (0)