Affix
view release on metacpan or search on metacpan
infix/include/infix/infix.h view on Meta::CPAN
/**
* 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
*/
/**
* @file infix.h
* @brief The public interface for the infix FFI library.
*
* @mainpage infix FFI Library
*
* @section intro_sec Introduction
*
* `infix` is a powerful, modern, and lightweight C library for creating Foreign
* Function Interface (FFI) trampolines at runtime. It allows you to dynamically
* call C functions or create C callbacks from any language or environment, using
* a simple, human-readable string-based syntax to describe function signatures.
*
* @section features_sec Key Features
*
* - **Simple Signature Syntax:** Describe complex C types, structs, and function
* prototypes with an intuitive string format.
* - **Forward & Reverse Calls:** Create "forward" trampolines to call C from your
* code, and "reverse" trampolines (callbacks) to allow C to call back into your code.
* - **Named Type Registry:** Define, reuse, and link complex, recursive, and
* mutually-dependent structs by name.
* - **Cross-Platform:** Supports major architectures (x86-64, AArch64) and operating
* systems (Linux, macOS, Windows).
* - **Secure:** Designed with modern security principles like W^X (Write XOR Execute)
* and hardened against memory corruption.
* - **Lightweight & Embeddable:** A small, dependency-free library ideal for
* embedding in language runtimes, plugins, and other applications.
*
* @section usage_sec Basic Usage
*
* ```c
* #include <infix/infix.h>
* #include <stdio.h>
*
* // The C function we want to call.
* int add(int a, int b) { return a + b; }
*
* int main() {
* infix_forward_t* trampoline = NULL;
* const char* signature = "(int, int) -> int";
*
* // Create a "bound" trampoline JIT-compiled for the `add` function.
* infix_forward_create(&trampoline, signature, (void*)add, NULL);
*
* // Get the callable function pointer from the trampoline.
* infix_cif_func cif = infix_forward_get_code(trampoline);
*
* // Prepare arguments as an array of pointers.
* int a = 10, b = 32;
* void* args[] = { &a, &b };
* int result;
*
* // Call the function through the FFI interface.
* cif(&result, args);
*
* printf("Result: %d\n", result); // Output: Result: 42
*
* infix_forward_destroy(trampoline);
* return 0;
* }
* ```
*/
#pragma once
( run in 2.543 seconds using v1.01-cache-2.11-cpan-f56aa216473 )