1
0
Fork 0
forked from fun/fun

Throw error if -DFUN_WITH_INI=ON is not set at build time. (0.37.41)

This commit is contained in:
Johannes Findeisen 2026-01-03 01:11:35 +01:00
commit 2a20b6f01a
4 changed files with 120 additions and 7 deletions

View file

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.10)
project(fun VERSION 0.37.40 LANGUAGES C)
project(fun VERSION 0.37.41 LANGUAGES C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
@ -555,14 +555,14 @@ add_custom_target(ops-quiet
)
add_custom_target(examples
COMMAND ${CMAKE_COMMAND} -E env FUN_LIB_DIR="${FUN_LIB}" ${CMAKE_SOURCE_DIR}/scripts/run_examples.sh
COMMAND ${CMAKE_COMMAND} -E env FUN_LIB_DIR="${FUN_LIB}" FUN_WITH_INI=$<IF:$<BOOL:${FUN_WITH_INI}>,1,0> ${CMAKE_SOURCE_DIR}/scripts/run_examples.sh
DEPENDS fun
USES_TERMINAL
COMMENT "Build and run all examples"
)
add_custom_target(run-examples
COMMAND ${CMAKE_COMMAND} -E env FUN_LIB_DIR="${FUN_LIB}" ${CMAKE_SOURCE_DIR}/scripts/run_examples.sh
COMMAND ${CMAKE_COMMAND} -E env FUN_LIB_DIR="${FUN_LIB}" FUN_WITH_INI=$<IF:$<BOOL:${FUN_WITH_INI}>,1,0> ${CMAKE_SOURCE_DIR}/scripts/run_examples.sh
DEPENDS fun
USES_TERMINAL
COMMENT "Build and run all examples"

View file

@ -69,16 +69,23 @@ fi
rc=0
for f in "${files[@]}"; do
base_name="$(basename "$f")"
# If INI support is disabled, skip INI examples to avoid expected failures
if [[ "${FUN_WITH_INI:-}" =~ ^(0|OFF|off|false|False)$ ]]; then
if [[ "$base_name" == ini_*.fun ]]; then
echo "=== Skipping (INI disabled): examples/$base_name ==="
continue
fi
fi
echo "=== Running: ${f#$ROOT/} ==="
if ! "$BIN" "$f"; then
echo "FAILED: ${f#$ROOT/}"
base="$(basename "$f")"
dest="$EX_DIR/error/$base"
dest="$EX_DIR/error/$base_name"
# Move the failing example to the error folder
if mv -f "$f" "$dest"; then
echo "Moved to: examples/error/$base"
echo "Moved to: examples/error/$base_name"
else
echo "warning: failed to move $base to examples/error/" >&2
echo "warning: failed to move $base_name to examples/error/" >&2
fi
rc=1
fi

View file

@ -741,6 +741,8 @@ void vm_run(VM *vm, Bytecode *entry) {
#include "vm/ini/set.c"
#include "vm/ini/unset.c"
#include "vm/ini/save.c"
#else
#include "vm/ini/stubs.c"
#endif
/* CURL ops */

104
src/vm/ini/stubs.c Normal file
View file

@ -0,0 +1,104 @@
/*
* This file provides stub handlers for INI opcodes when FUN_WITH_INI is disabled.
* Each opcode reports a clear runtime error and returns a safe default.
*/
/* OP_INI_LOAD: pops path string; pushes 0 (invalid handle) */
case OP_INI_LOAD: {
Value vpath = pop_value(vm);
(void)vpath; /* unused */
free_value(vpath);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
push_value(vm, make_int(0));
break;
}
/* OP_INI_FREE: pops handle; pushes 0 */
case OP_INI_FREE: {
Value vh = pop_value(vm);
free_value(vh);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
push_value(vm, make_int(0));
break;
}
/* Getters: pop args; push defaults (string:"", int:0, double:0.0, bool:0) */
case OP_INI_GET_STRING: {
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh); free_value(vsec); free_value(vkey);
/* cannot convert here; return empty string */
push_value(vm, make_string(""));
free_value(vdef);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
break;
}
case OP_INI_GET_INT: {
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh); free_value(vsec); free_value(vkey);
(void)vdef; /* unused */
push_value(vm, make_int(0));
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
break;
}
case OP_INI_GET_DOUBLE: {
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh); free_value(vsec); free_value(vkey);
(void)vdef; /* unused */
push_value(vm, make_float(0.0));
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
break;
}
case OP_INI_GET_BOOL: {
Value vdef = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh); free_value(vsec); free_value(vkey);
(void)vdef; /* unused */
push_value(vm, make_int(0));
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
break;
}
/* Mutators: return 0 */
case OP_INI_SET: {
Value vval = pop_value(vm);
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh); free_value(vsec); free_value(vkey); free_value(vval);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
push_value(vm, make_int(0));
break;
}
case OP_INI_UNSET: {
Value vkey = pop_value(vm);
Value vsec = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh); free_value(vsec); free_value(vkey);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
push_value(vm, make_int(0));
break;
}
case OP_INI_SAVE: {
Value vpath = pop_value(vm);
Value vh = pop_value(vm);
free_value(vh); free_value(vpath);
fun_vm_fprintf(stderr, "Runtime error: INI support disabled (rebuild with -DFUN_WITH_INI=ON)\n");
push_value(vm, make_int(0));
break;
}