From 575449afdaf9ef7a780ea3c63f5fb84269ff8f00 Mon Sep 17 00:00:00 2001 From: Ricardo Dias Date: Tue, 4 Feb 2025 11:33:14 +0000 Subject: [PATCH] Adds ABI version field to compiledFunction and memoryInfo structures Signed-off-by: Ricardo Dias --- src/valkeymodule.h | 37 +++++++++++++++++----------------- tests/modules/helloscripting.c | 5 ++++- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/valkeymodule.h b/src/valkeymodule.h index 50516616c2..59f2469f81 100644 --- a/src/valkeymodule.h +++ b/src/valkeymodule.h @@ -795,41 +795,40 @@ typedef void (*ValkeyModuleInfoFunc)(ValkeyModuleInfoCtx *ctx, int for_crash_rep typedef void (*ValkeyModuleDefragFunc)(ValkeyModuleDefragCtx *ctx); typedef void (*ValkeyModuleUserChangedFunc)(uint64_t client_id, void *privdata); -/* Current ABI version for scripting engine modules. */ -#define VALKEYMODULE_SCRIPTING_ENGINE_ABI_VERSION 1UL - /* Type definitions for implementing scripting engines modules. */ typedef void ValkeyModuleScriptingEngineCtx; typedef void ValkeyModuleScriptingEngineServerRuntimeCtx; +/* Current ABI version for scripting engine compiled functions structure. */ +#define VALKEYMODULE_SCRIPTING_ENGINE_ABI_COMPILED_FUNCTION_VERSION 1UL + /* This struct represents a scripting engine function that results from the * compilation of a script by the engine implementation. - * - * IMPORTANT: If we ever need to add/remove fields from this struct, we need - * to bump the version number defined in the - * `VALKEYMODULE_SCRIPTING_ENGINE_ABI_VERSION` constant. */ typedef struct ValkeyModuleScriptingEngineCompiledFunction { + uint64_t version; /* Version of this structure for ABI compat. */ ValkeyModuleString *name; /* Function name */ void *function; /* Opaque object representing a function, usually it's the function compiled code. */ ValkeyModuleString *desc; /* Function description */ uint64_t f_flags; /* Function flags */ -} ValkeyModuleScriptingEngineCompiledFunction; +} ValkeyModuleScriptingEngineCompiledFunctionV1; + +#define ValkeyModuleScriptingEngineCompiledFunction ValkeyModuleScriptingEngineCompiledFunctionV1 + +/* Current ABI version for scripting engine memory info structure. */ +#define VALKEYMODULE_SCRIPTING_ENGINE_ABI_MEMORY_INFO_VERSION 1UL /* This struct is used to return the memory information of the scripting * engine. - * - * IMPORTANT: If we ever need to add/remove fields from this struct, we need - * to bump the version number defined in the - * `VALKEYMODULE_SCRIPTING_ENGINE_ABI_VERSION` constant. */ typedef struct ValkeyModuleScriptingEngineMemoryInfo { - /* The memory used by the scripting engine runtime. */ - size_t used_memory; - /* The memory used by the scripting engine data structures. */ - size_t engine_memory_overhead; -} ValkeyModuleScriptingEngineMemoryInfo; + uint64_t version; /* Version of this structure for ABI compat. */ + size_t used_memory; /* The memory used by the scripting engine runtime. */ + size_t engine_memory_overhead; /* The memory used by the scripting engine data structures. */ +} ValkeyModuleScriptingEngineMemoryInfoV1; + +#define ValkeyModuleScriptingEngineMemoryInfo ValkeyModuleScriptingEngineMemoryInfoV1 typedef enum ValkeyModuleScriptingEngineSubsystemType { VMSE_EVAL, @@ -980,8 +979,10 @@ typedef ValkeyModuleScriptingEngineMemoryInfo (*ValkeyModuleScriptingEngineGetMe ValkeyModuleScriptingEngineCtx *engine_ctx, ValkeyModuleScriptingEngineSubsystemType type); +/* Current ABI version for scripting engine modules. */ +#define VALKEYMODULE_SCRIPTING_ENGINE_ABI_VERSION 1UL -typedef struct ValkeyModuleScriptingEngineMethodsV1 { +typedef struct ValkeyModuleScriptingEngineMethods { uint64_t version; /* Version of this structure for ABI compat. */ /* Compile code function callback. When a new script is loaded, this diff --git a/tests/modules/helloscripting.c b/tests/modules/helloscripting.c index fff4179e3c..92ad0a6c44 100644 --- a/tests/modules/helloscripting.c +++ b/tests/modules/helloscripting.c @@ -298,7 +298,9 @@ static ValkeyModuleScriptingEngineMemoryInfo engineGetMemoryInfo(ValkeyModuleCtx VALKEYMODULE_NOT_USED(module_ctx); VALKEYMODULE_NOT_USED(type); HelloLangCtx *ctx = (HelloLangCtx *)engine_ctx; - ValkeyModuleScriptingEngineMemoryInfo mem_info = {0}; + ValkeyModuleScriptingEngineMemoryInfo mem_info = { + .version = VALKEYMODULE_SCRIPTING_ENGINE_ABI_MEMORY_INFO_VERSION + }; if (ctx->program != NULL) { mem_info.used_memory += ValkeyModule_MallocSize(ctx->program); @@ -385,6 +387,7 @@ static ValkeyModuleScriptingEngineCompiledFunction **createHelloLangEngine(Valke ValkeyModuleScriptingEngineCompiledFunction *cfunc = ValkeyModule_Alloc(sizeof(ValkeyModuleScriptingEngineCompiledFunction)); *cfunc = (ValkeyModuleScriptingEngineCompiledFunction) { + .version = VALKEYMODULE_SCRIPTING_ENGINE_ABI_COMPILED_FUNCTION_VERSION, .name = ValkeyModule_CreateString(NULL, func->name, strlen(func->name)), .function = func, .desc = NULL,