Skip to content

Commit

Permalink
Adds ABI version field to compiledFunction and memoryInfo structures
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo Dias <[email protected]>
  • Loading branch information
rjd15372 committed Feb 4, 2025
1 parent 1e39181 commit 575449a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
37 changes: 19 additions & 18 deletions src/valkeymodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion tests/modules/helloscripting.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 575449a

Please sign in to comment.