On Wed, 31 May 2023 22:44:52 GMT, Jorn Vernee <jver...@openjdk.org> wrote:

>> In C, arguments smaller than `int` are promoted to (`unsigned`) `int`, and 
>> `float` is promoted to `double`, when being passed as variadic argument (see 
>> e.g. 
>> https://en.cppreference.com/w/c/language/conversion#Default_argument_promotions).
>>  This patch restricts the layouts that can be used as variadic layouts to 
>> what is allowed by the C specification.
>> 
>> The fallback linker is also updated to use to correct function to link 
>> variadic calls (not doing this turned out not to be a problem so far, but it 
>> is problematic for instance on Mac/AArch64 when using the fallback linker). 
>> Adding the restriction on layouts for all linkers is also partly motivated 
>> by the fallback linker rejecting such unsupported variadic layouts already.
>> 
>> I've added a small paragraph to the Linker javadoc as well that explains the 
>> restriction. Comments on that are welcome, but please explain.
>> 
>> The tests are updated to no longer try to link variadic functions with the 
>> illegal layouts, and I've added some more negative tests to TestIllegalLink.
>> 
>> Testing:
>> - local testing on Windows/x64
>> - tier1-3 + jdk-tier5 (ongoing)
>> - manual test run on mac/aarch64 with the fallback linker to verify the 
>> correctness of the fallback linker changes.
>
> Jorn Vernee has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   review comments

src/java.base/share/classes/java/lang/foreign/Linker.java line 368:

> 366:  * <h3 id="variadic-funcs">Variadic functions</h3>
> 367:  *
> 368:  * Variadic functions (e.g. a C function declared with a trailing 
> ellipses {@code ...} at the end of the formal parameter

Optional suggestion for improvement (maybe now, or maybe later). When reading 
this great para, I understand that there are two things that fall under the 
"variadic function" umbrella. Some are declared with `...` and some with `()`. 
This is a very good definition and I wonder if we should expand a bit more on 
it - e.g. in a way, we never explain what a variadic function is - we merely 
define it by saying how it is declared in C. I wonder if we might very very 
briefly explain that in C, some functions (variadic functions) can take a 
variable number of parameters. Then we go on to say that these functions can be 
declared in two ways (e.g. ellipsis and prototype-less). Perhaps if we used a 
bullet-list to define the two ways in which variadic function can be declared, 
the definition could stand out even more?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/14225#discussion_r1212415909

Reply via email to