Inlinec — a new way to use C code in Python scripts

Project inlinec a new method for inline integration of C code into Python scripts has been proposed. C functions are defined directly in a single file with Python code, marked by the decorator "@inlinec". The combined script is executed as is by the interpreter with spython and parsed using the mechanism provided in Python of the codecs., which allows the parser to be connected to transform the script before it is parsed by the interpreter (usually, the codecs module is used for transparent text re-encoding but also allows arbitrary transformations of the script content).

The parser connects as a module ("from inlinec import inlinec"), which performs preliminary processing and on-the-fly translates the definitions of C functions marked with the @inlinec annotations into ctypes wrappers and replaces the body of the C function with calls to these wrappers. After such transformation, the Python interpreter receives a correctly transformed source text of the script, in which C functions are called via ctypes. A similar method is also used in the project Pyxl4, which allows mixing HTML and Python code in a single file.

# coding: inlinec
from inlinec import inlinec

@inlinec
def test():
#include<stdio.h>
void test() {
printf("Hello, world");
}

The development is currently presented as an experimental prototype, which has issues such as the lack of support for passing pointers to functions (except for strings), the need to run
"gcc -E" for preprocessing the code, saving intermediate *.so, *.o, and *.c files in the current directory, the absence of caching for the transformed version, and unnecessary parsing stages (leading to significant delays on each run).

Source: opennet.ru

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster