infix
A JIT-Powered FFI Library for C
|
Tests FFI calls for variadic functions. More...
#include "common/double_tap.h"
#include "common/infix_config.h"
#include "types.h"
#include <infix/infix.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
Macros | |
#define | DBLTAP_IMPLEMENTATION |
Functions | |
int | forward_variadic_checker (char *buffer, size_t size, const char *format,...) |
A custom checker function to transparently validate variadic arguments. | |
int | forward_variadic_aggregate_checker (int fixed_arg,...) |
A custom checker for variadic aggregate arguments. | |
int | variadic_reverse_handler (const char *topic,...) |
A handler for a reverse trampoline with a variadic signature. | |
subtest ("Forward variadic call") | |
subtest ("Forward variadic call (aggregates)") | |
subtest ("Reverse variadic callback") | |
subtest ("Platform ABI: macOS AArch64 variadic struct passing") | |
subtest ("Platform ABI: Windows x64 variadic float/double passing") | |
Variables | |
TEST | |
Tests FFI calls for variadic functions.
Copyright (c) 2025 Sanko Robinson
This source code is dual-licensed under the Artistic License 2.0 or the MIT License. You may choose to use this code under the terms of either license.
SPDX-License-Identifier: (Artistic-2.0 OR MIT)
The documentation blocks within this file are licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).
SPDX-License-Identifier: CC-BY-4.0
This test suite verifies the library's ability to handle variadic functions (those with ...
in their signature) for both forward and reverse FFI calls. Variadic argument passing involves special ABI rules that differ significantly between platforms, making this a critical area to test.
This file consolidates all previous variadic tests and covers:
forward_variadic_checker
) is called with a mix of fixed and variadic arguments (const char*
, int
, double
) to verify the basic mechanism. Using a custom checker provides clearer diagnostics than calling an opaque library function like snprintf
.double
is correctly passed in both a GPR (for va_arg
) and an XMM register (for direct use by the callee).#define DBLTAP_IMPLEMENTATION |
int forward_variadic_aggregate_checker | ( | int | fixed_arg, |
... | |||
) |
A custom checker for variadic aggregate arguments.
This function's behavior depends on the ABI.
va_arg
retrieves the struct directly.va_arg(args, Point*)
and dereference it. int forward_variadic_checker | ( | char * | buffer, |
size_t | size, | ||
const char * | format, | ||
... | |||
) |
A custom checker function to transparently validate variadic arguments.
This function replaces snprintf
from previous tests. It accepts a variadic argument list and uses the double_tap
harness to ok()
each argument it receives. This provides precise feedback on which argument, if any, is being passed incorrectly.
subtest | ( | "Forward variadic call (aggregates)" | ) |
subtest | ( | "Forward variadic call" | ) |
subtest | ( | "Platform ABI: macOS AArch64 variadic struct passing" | ) |
subtest | ( | "Platform ABI: Windows x64 variadic float/double passing" | ) |
subtest | ( | "Reverse variadic callback" | ) |
int variadic_reverse_handler | ( | const char * | topic, |
... | |||
) |
A handler for a reverse trampoline with a variadic signature.