Skip to content

Commit 9945b0c

Browse files
committed
Various fixes
1 parent 9ac2641 commit 9945b0c

File tree

7 files changed

+21
-10
lines changed

7 files changed

+21
-10
lines changed

kt/api-generator/src/main/kotlin/godot/codegen/poet/GenericClassNameInfo.kt

+10-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,16 @@ class GenericClassNameInfo(
6565
ParameterSpec.builder("p$index", typeVariableName).build()
6666
}
6767

68-
fun toLambdaTypeName(returnType: TypeVariableName) = LambdaTypeName.get(
68+
fun toArgumentsString(template: String, indexKey: String): String {
69+
return buildString {
70+
genericTypes.mapIndexed { index: Int, typeVariableName: TypeVariableName ->
71+
if (index != 0) append("")
72+
append(template.replace(indexKey, index.toString()))
73+
}
74+
}
75+
}
76+
77+
fun toLambdaTypeName(returnType: TypeVariableName) = LambdaTypeName.get(
6978
receiver = null,
7079
parameters = genericTypes
7180
.mapIndexed { index: Int, typeVariableName: TypeVariableName ->

kt/api-generator/src/main/kotlin/godot/codegen/services/impl/LambdaCallableGenerationService.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package godot.codegen.services.impl
22

33
import com.squareup.kotlinpoet.ANY
4+
import com.squareup.kotlinpoet.ARRAY
45
import com.squareup.kotlinpoet.AnnotationSpec
56
import com.squareup.kotlinpoet.ClassName
67
import com.squareup.kotlinpoet.CodeBlock
@@ -175,7 +176,7 @@ object LambdaCallableGenerationService : ILambdaCallableGenerationService {
175176
)
176177
.addProperty(
177178
PropertySpec
178-
.builder("container", lambdaContainerClassName.parameterizedBy(genericParameterWithReturn))
179+
.builder(CONTAINER_ARGUMENT_NAME, lambdaContainerClassName.parameterizedBy(genericParameterWithReturn))
179180
.addModifiers(KModifier.OVERRIDE)
180181
.initializer(
181182
CodeBlock.of(
@@ -193,7 +194,7 @@ object LambdaCallableGenerationService : ILambdaCallableGenerationService {
193194
.addCode(
194195
CodeBlock.of(
195196
buildString {
196-
append("return·container.unsafeInvoke(")
197+
append("return·$CONTAINER_ARGUMENT_NAME.unsafeInvoke(")
197198
append(classInfo.toArgumentsString("pINDEX", "INDEX"))
198199
append(')')
199200
}
@@ -251,15 +252,15 @@ object LambdaCallableGenerationService : ILambdaCallableGenerationService {
251252
)
252253
.addCode(
253254
buildString {
254-
append("return·%T(container.returnConverter,·container.typeConverters.take(${remainingParameters}).toTypedArray())·{")
255+
append("return·%T($CONTAINER_ARGUMENT_NAME.returnConverter,·$CONTAINER_ARGUMENT_NAME.typeConverters.take(${remainingParameters}).toTypedArray())·{")
255256

256257
for (index in (0..<remainingParameters)) {
257258
if (index != 0) append("")
258259

259260
append("p${index}:·%T")
260261
}
261262

262-
append("·->·container.unsafeInvoke(")
263+
append("·->·$CONTAINER_ARGUMENT_NAME.unsafeInvoke(")
263264

264265
for (i in genericParameters.indices) {
265266
if (i != 0) append("")

src/jvm_wrapper/kotlin_callable_custom.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ bool LambdaContainer::equals(const LambdaContainer& other) const {
3131

3232
LambdaContainer::LambdaContainer(jni::Env& p_env, jni::JObject p_wrapped, Variant::Type return_type, int p_hash_code, bool p_has_on_cancel) :
3333
JvmInstanceWrapper(p_env, p_wrapped),
34-
has_return_value {return_type != Variant::NIL},
3534
hash_code {p_hash_code},
35+
has_return_value {return_type != Variant::NIL},
3636
has_on_cancel {p_has_on_cancel},
3737
has_been_called {false} {}
3838

src/jvm_wrapper/memory/transfer_context.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ void TransferContext::icall(JNIEnv* rawEnv, jobject instance, jlong j_ptr, jlong
8787

8888
Callable::CallError r_error {Callable::CallError::CALL_OK};
8989

90-
Variant ret_value;
9190
if (unlikely(stack_offset + args_size > MAX_STACK_SIZE)) {
9291
Variant args[MAX_FUNCTION_ARG_COUNT];
9392
read_args_to_array(buffer, args, args_size);
@@ -97,7 +96,7 @@ void TransferContext::icall(JNIEnv* rawEnv, jobject instance, jlong j_ptr, jlong
9796
args_ptr[i] = &args[i];
9897
}
9998

100-
method_bind->validated_call(ptr, args_ptr, &ret_value);
99+
const Variant& ret_value {method_bind->call(ptr, args_ptr, args_size, r_error)};
101100
buffer->rewind();
102101

103102
VariantToBuffer::write_variant(ret_value, buffer);
@@ -108,7 +107,7 @@ void TransferContext::icall(JNIEnv* rawEnv, jobject instance, jlong j_ptr, jlong
108107
const Variant** args_ptr {variant_args_ptr + stack_offset};
109108

110109
stack_offset += args_size;
111-
method_bind->validated_call(ptr, args_ptr, &ret_value);
110+
const Variant& ret_value {method_bind->call(ptr, args_ptr, args_size, r_error)};
112111
// Remove Variants so memory can be freed immediately after method call.
113112
for (uint32_t i = 0; i < args_size; i++) {
114113
args[i] = Variant();

src/jvm_wrapper/registration/kt_class.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ void KtClass::fetch_methods(jni::Env& env) {
100100
for (int i = 0; i < functionsArray.length(env); i++) {
101101
jni::JObject object = functionsArray.get(env, i);
102102
auto* ktFunction {new KtFunction(env, object)};
103-
auto test = methods[ktFunction->get_name()];
104103
methods[ktFunction->get_name()] = ktFunction;
105104
JVM_DEV_VERBOSE("Fetched method %s for class %s", ktFunction->get_name(), registered_class_name);
106105
}

src/lifecycle/jvm_manager.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ CreateJavaVM get_create_jvm_function(void* lib_handle) {
4343
#else
4444
// Sanity check in case we mess up preprocessors
4545
JVM_DEV_ASSERT(false, "Current configuration doesn't provide a way to create a JVM!");
46+
return nullptr;
4647
#endif
4748
}
4849

src/lifecycle/jvm_user_configuration.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,11 @@ void JvmUserConfiguration::parse_command_line(const List<String>& args, HashMap<
278278
configuration_map[JVM_ARGUMENTS_CMD_IDENTIFIER] = arr;
279279
}
280280

281+
#ifdef DEV_ENABLED
281282
for (const auto& map_element : configuration_map) {
282283
JVM_DEV_VERBOSE("Value for commandline argument: %s -> %s", map_element.key, map_element.value);
283284
}
285+
#endif
284286
}
285287
}
286288

0 commit comments

Comments
 (0)