Implementation:2akouwu Reverify compile candidate
| Knowledge Sources | |
|---|---|
| Domains | Compilation, Sandboxed_Execution |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
Concrete tool for compiling C source to an executable under a sandbox, returning the binary path or None on failure, provided by the Reverify library.
Description
The compile_candidate function compiles C source code to an executable using a specified compiler (default gcc) under sandbox limits. It is gated: returns None when the compiler is absent or the compile fails (timeout, error). The companion _prepare generalizes to C or Python: for C it calls compile_candidate; for Python it syntax-checks via compile() and writes to a .py file, returning the argv prefix to run it.
Usage
Import this function when you need to:
- Compile C candidate code for
functions_equiv_verify. - Prepare C or Python implementations for sandboxed differential testing.
Code Reference
Source Location
- Repository: Reverify
- File: reverify/exebench.py
- Lines:
compile_candidateat L87-120;_prepareat L196-211
Signature
def compile_candidate(
c_source: str,
*,
cc: str = "gcc",
extra_flags: Optional[Sequence[str]] = None,
timeout: int = 30,
workdir: Optional[str] = None,
) -> Optional[str]:
"""Compile c_source to an executable; return the binary path or None."""
def _prepare(
source: str, subdir: str, lang: str, cc: str, timeout: int
) -> Optional[List[str]]:
"""Make source runnable; return the argv prefix to run it, or None."""
Import
from reverify.exebench import compile_candidate
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| c_source | str | Yes | C source code string |
| cc | str | No | Compiler name (default "gcc") |
| extra_flags | Sequence[str] | No | Extra compiler flags |
| timeout | int | No | Compile timeout seconds (default 30) |
| workdir | str | No | Temp dir for artifacts (default: fresh mkdtemp) |
Outputs
| Name | Type | Description |
|---|---|---|
| return | Optional[str] | Path to compiled binary, or None (compiler missing / compile failed) |
Usage Examples
Compile C Source
from reverify.exebench import compile_candidate
source = "int main(int argc, char **argv) { return 0; }"
binary = compile_candidate(source, cc="gcc")
if binary:
print(f"Compiled to: {binary}")
else:
print("Compilation failed or gcc not found")