Repository: valkey-io/valkey
File: src/valkeymodule.h (C/C++)

Code before:
    ValkeyModuleScriptingEngineCtx *engine_ctx,
    ValkeyModuleScriptingEngineSubsystemType type);

/* Current ABI version for scripting engine modules. */
#define VALKEYMODULE_SCRIPTING_ENGINE_ABI_VERSION 2UL

typedef struct ValkeyModuleScriptingEngineMethods {
    uint64_t version; /* Version of this structure for ABI compat. */

    /* Compile code function callback. When a new script is loaded, this
     * callback will be called with the script code, compiles it, and returns a
     * list of `ValkeyModuleScriptingEngineCompiledFunc` objects. */
    union {
        ValkeyModuleScriptingEngineCompileCodeFuncV1 compile_code_v1;
        ValkeyModuleScriptingEngineCompileCodeFunc compile_code;
    };
    /* Function callback to free the memory of a registered engine function. */
    ValkeyModuleScriptingEngineFreeFunctionFunc free_function;

    /* The callback function called when `FCALL` command is called on a function
     * registered in this engine. */
    ValkeyModuleScriptingEngineCallFunctionFunc call_function;

    /* Function callback to return memory overhead for a given function. */
    ValkeyModuleScriptingEngineGetFunctionMemoryOverheadFunc get_function_memory_overhead;

    /* The callback function used to reset the runtime environment used
     * by the scripting engine for EVAL scripts or FUNCTION scripts. */
    ValkeyModuleScriptingEngineResetEnvFunc reset_env;

    /* Function callback to get the used memory by the engine. */
    ValkeyModuleScriptingEngineGetMemoryInfoFunc get_memory_info;

} ValkeyModuleScriptingEngineMethodsV1;

#define ValkeyModuleScriptingEngineMethods ValkeyModuleScriptingEngineMethodsV1

/* ------------------------- End of common defines ------------------------ */

/* ----------- The rest of the defines are only for modules ----------------- */
#if !defined VALKEYMODULE_CORE || defined VALKEYMODULE_CORE_MODULE
/* Things defined for modules and core-modules. */

/* Macro definitions specific to individual compilers */
#ifndef VALKEYMODULE_ATTR_UNUSED
#ifdef __GNUC__
#define VALKEYMODULE_ATTR_UNUSED __attribute__((unused))
#else
#define VALKEYMODULE_ATTR_UNUSED
#endif
#endif

Review comment (suggestion):
This should changed using the same method as the compile code function pointer above.

Like this:
```c
union {
    ValkeyModuleScriptingEngineResetEvalEnvFunc reset_eval_env;
    ValkeyModuleScriptingEngineResetEnvFunc reset_env;
}
```

This also requires to bump the `VALKEYMODULE_SCRIPTING_ENGINE_ABI_VERSION` version, in order for the code that uses this field to decide which branch of the union it should use.

Code after:
 */
typedef ValkeyModuleScriptingEngineCallableLazyEnvReset *(*ValkeyModuleScriptingEngineResetEnvFunc)(
    ValkeyModuleCtx *module_ctx,
    ValkeyModuleScriptingEngineCtx *engine_ctx,
    ValkeyModuleScriptingEngineSubsystemType type,
    int async);

/* Return the current used memory by the engine.
 *
 * - `module_ctx`: the module runtime context.
 *
 * - `engine_ctx`: the scripting engine runtime context.
 *
 * - `type`: the subsystem type.
 */
typedef ValkeyModuleScriptingEngineMemoryInfo (*ValkeyModuleScriptingEngineGetMemoryInfoFunc)(
    ValkeyModuleCtx *module_ctx,
    ValkeyModuleScriptingEngineCtx *engine_ctx,
    ValkeyModuleScriptingEngineSubsystemType type);

/* Current ABI version for scripting engine modules. */
/* Version Changelog:
 *  1. Initial version.
 *  2. Changed the `compile_code` callback to support binary data in the source code.
 *  3. Renamed reset_eval_env callback to reset_env and added a type parameter to be
 *     able to reset both EVAL or FUNCTION scripts env.
 */
#define VALKEYMODULE_SCRIPTING_ENGINE_ABI_VERSION 3L

typedef struct ValkeyModuleScriptingEngineMethods {
    uint64_t version; /* Version of this structure for ABI compat. */

    /* Compile code function callback. When a new script is loaded, this
     * callback will be called with the script code, compiles it, and returns a
     * list of `ValkeyModuleScriptingEngineCompiledFunc` objects. */
    union {
        ValkeyModuleScriptingEngineCompileCodeFuncV1 compile_code_v1;
        ValkeyModuleScriptingEngineCompileCodeFunc compile_code;
    };
    /* Function callback to free the memory of a registered engine function. */
    ValkeyModuleScriptingEngineFreeFunctionFunc free_function;

    /* The callback function called when `FCALL` command is called on a function
     * registered in this engine. */
    ValkeyModuleScriptingEngineCallFunctionFunc call_function;

    /* Function callback to return memory overhead for a given function. */
    ValkeyModuleScriptingEngineGetFunctionMemoryOverheadFunc get_function_memory_overhead;

    /* The callback function used to reset the runtime environment used
     * by the scripting engine for EVAL scripts or FUNCTION scripts. */