From 8cd96d2da29d35f88718792d1d9f01610bd29009 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 26 Apr 2019 12:40:51 +0300 Subject: [PATCH] C backend: fix passing NULL arrays to native methods --- .../org/teavm/backend/c/generate/CodeGenerationVisitor.java | 2 +- core/src/main/resources/org/teavm/backend/c/runtime.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/teavm/backend/c/generate/CodeGenerationVisitor.java b/core/src/main/java/org/teavm/backend/c/generate/CodeGenerationVisitor.java index da210fe33..5ea242c35 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/CodeGenerationVisitor.java +++ b/core/src/main/java/org/teavm/backend/c/generate/CodeGenerationVisitor.java @@ -507,7 +507,7 @@ public class CodeGenerationVisitor implements ExprVisitor, StatementVisitor { writer.print(")"); stringTemporaries.add(tmp); } else if (isPrimitiveArray(type)) { - writer.print("ARRAY_DATA("); + writer.print("ARRAY_DATAN("); expr.getArguments().get(i).acceptVisitor(this); writer.print(", ").printStrictType(((ValueType.Array) type).getItemType()).print(")"); } else if (isPrimitiveBuffer(type)) { diff --git a/core/src/main/resources/org/teavm/backend/c/runtime.c b/core/src/main/resources/org/teavm/backend/c/runtime.c index a44e42a12..9f3321980 100644 --- a/core/src/main/resources/org/teavm/backend/c/runtime.c +++ b/core/src/main/resources/org/teavm/backend/c/runtime.c @@ -66,6 +66,7 @@ static inline int32_t compare_double(double a, double b) { #define ALIGN(addr, alignment) ((void*) (((uintptr_t) (addr) + ((alignment) - 1)) / (alignment) * (alignment))) #define ARRAY_LENGTH(array) (((JavaArray*) (array))->size) #define ARRAY_DATA(array, type) ((type*) ALIGN((((JavaArray*) (array)) + 1), sizeof(type))) +#define ARRAY_DATAN(array, type) (array != NULL ? ARRAY_DATA(array, type) : NULL) #define ARRAY_AT(array, type, index) (((type*) ARRAY_DATA(array, type))[index]) static void* throwClassCastException();