Skip to content

Commit 274b478

Browse files
committed
[GR-28079] Allow NULL for result in poly_context_eval / poly_value_execute.
PullRequest: graal/7823
2 parents 5f48270 + 0d15bba commit 274b478

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

substratevm/src/org.graalvm.polyglot.nativeapi/src/org/graalvm/polyglot/nativeapi/PolyglotNativeAPI.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ public static PolyglotStatus poly_context_close(PolyglotIsolateThread thread, Po
467467
" @param language_id the language identifier.",
468468
" @param name_utf8 given to the evaluate source code.",
469469
" @param source_utf8 the source code to be evaluated.",
470-
" @param result <code>poly_value</code> that is the result of the evaluation.",
470+
" @param result <code>poly_value</code> that is the result of the evaluation. You can pass <code>NULL</code> if you just want to evaluate the source and you can ignore the result.",
471471
" @return poly_ok if all works, poly_generic_error if there is a failure.",
472472
" @see org::graalvm::polyglot::Context::eval",
473473
" @since 19.0",
@@ -481,7 +481,10 @@ public static PolyglotStatus poly_context_eval(PolyglotIsolateThread thread, Pol
481481
String jCode = CTypeConversion.toJavaString(source_utf8);
482482

483483
Source sourceCode = Source.newBuilder(languageName, jCode, jName).build();
484-
result.write(createHandle(c.eval(sourceCode)));
484+
Value evalResult = c.eval(sourceCode);
485+
if (result.isNonNull()) {
486+
result.write(createHandle(evalResult));
487+
}
485488
});
486489
}
487490

@@ -570,6 +573,7 @@ public static PolyglotStatus poly_value_can_execute(PolyglotIsolateThread thread
570573
" @param value to be executed.",
571574
" @param args array of poly_value.",
572575
" @param args_size length of the args array.",
576+
" @param result <code>poly_value</code> that is the result of the execution. You can pass <code>NULL</code> if you just want to execute the source and you can ignore the result.",
573577
" @return poly_ok if all works, poly_generic_error if the underlying context was closed, if a wrong ",
574578
" number of arguments was provided or one of the arguments was not applicable, if this value cannot be executed,",
575579
" and if a guest language error occurred during execution.",
@@ -587,7 +591,9 @@ public static PolyglotStatus poly_value_execute(PolyglotIsolateThread thread, Po
587591
}
588592

589593
Value resultValue = function.execute(jArgs);
590-
result.write(createHandle(resultValue));
594+
if (result.isNonNull()) {
595+
result.write(createHandle(resultValue));
596+
}
591597
});
592598
}
593599

0 commit comments

Comments
 (0)