Skip to content

Commit

Permalink
fix(generator) invalid annotation on primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Spasi committed Jan 9, 2025
1 parent b91d4b4 commit 7634074
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class Func(

private fun ReturnValue.nativeMethodType(nullable: Boolean): String =
if (this.isStructValue) "void" else this.nativeType.nativeMethodType.let {
if (nullable) it.nullable else it
if (nullable && !this.nativeType.mapping.nativeMethodType.isPrimitive) it.nullable else it
}

private val ReturnValue.jniFunctionType
Expand Down Expand Up @@ -811,7 +811,7 @@ class Func(
// TODO: This implementation has not been tested with too many different signatures and probably contains bugs.
println("""$t${t}MemoryStack stack = stackGet(); int stackPointer = stack.getPointer();
try {
${if (hasReturnStatement) { """long __result = stack.n${when {
${if (hasReturnStatement) { """long $RESULT = stack.n${when {
returns.nativeType is PointerType<*> -> "pointer"
returns.nativeType.mapping == PrimitiveMapping.POINTER -> "pointer"
returns.nativeType.mapping == PrimitiveMapping.BOOLEAN -> "byte"
Expand Down Expand Up @@ -846,14 +846,14 @@ class Func(
}
}
nffi_call(${name}CIF.address(), $FUNCTION_ADDRESS, ${if (returns.isVoid) "NULL" else "__result"}, arguments);${if (hasReturnStatement) {
nffi_call(${name}CIF.address(), $FUNCTION_ADDRESS, ${if (returns.isVoid) "NULL" else RESULT}, arguments);${if (hasReturnStatement) {
"""
return memGet${when {
returns.nativeType.mapping == PrimitiveMapping.BOOLEAN -> "Byte"
returns.nativeType is PointerType<*> -> "Address"
else -> returns.nativeType.nativeMethodType.upperCaseFirst
}}(__result)${if (returns.nativeType.mapping.isBoolean()) " != 0" else ""};"""
}}($RESULT)${if (returns.nativeType.mapping.isBoolean()) " != 0" else ""};"""
} else ""}
} finally {
stack.setPointer(stackPointer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ public static long nmethod_copyArgumentType(long m, int index) {
/** {@code char * method_copyArgumentType(Method m, unsigned int index)} */
@NativeType("char *")
public static @Nullable String method_copyArgumentType(@NativeType("Method") long m, @NativeType("unsigned int") int index) {
@Nullable long __result = NULL;
long __result = NULL;
try {
__result = nmethod_copyArgumentType(m, index);
return memUTF8Safe(__result);
Expand Down Expand Up @@ -1496,7 +1496,7 @@ public static long nproperty_copyAttributeValue(long property, long attributeNam
if (CHECKS) {
checkNT1(attributeName);
}
@Nullable long __result = NULL;
long __result = NULL;
try {
__result = nproperty_copyAttributeValue(property, memAddress(attributeName));
return memUTF8Safe(__result);
Expand All @@ -1509,7 +1509,7 @@ public static long nproperty_copyAttributeValue(long property, long attributeNam
@NativeType("char *")
public static @Nullable String property_copyAttributeValue(@NativeType("objc_property_t") long property, @NativeType("char const *") CharSequence attributeName) {
MemoryStack stack = stackGet(); int stackPointer = stack.getPointer();
@Nullable long __result = NULL;
long __result = NULL;
try {
stack.nUTF8(attributeName, true);
long attributeNameEncoded = stack.getPointerAddress();
Expand Down

0 comments on commit 7634074

Please sign in to comment.