Skip to content

Commit b7627a6

Browse files
itamarhaberlantiga
authored andcommitted
Script fixes and enhancement (#93)
* Minor fix to comment Signed-off-by: Itamar Haber <itamar@redislabs.com> * Tries to prevent a leak Signed-off-by: Itamar Haber <itamar@redislabs.com> * Adds RAI_ScriptRunCtxCreateEx Perhaps should just be in RAI_ScriptRunCtxCreate Signed-off-by: Itamar Haber <itamar@redislabs.com> * Refactors Ex to nonEx Signed-off-by: Itamar Haber <itamar@redislabs.com>
1 parent aac7e36 commit b7627a6

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

src/redisai.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ int RedisAI_StartRunThread() {
809809
return REDISMODULE_OK;
810810
}
811811

812-
// script key, INPUTS, key1, key2 ... OUTPUTS, key1, key2 ...
812+
// script key, fnname, INPUTS, key1, key2 ... OUTPUTS, key1, key2 ...
813813
int RedisAI_ScriptRun_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
814814
if (RedisModule_IsKeysPositionRequest(ctx)) {
815815
RedisModule_KeyAtPos(ctx, 1);
@@ -834,11 +834,7 @@ int RedisAI_ScriptRun_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv
834834

835835
RAI_Script *sto = RedisModule_ModuleTypeGetValue(key);
836836

837-
RAI_ScriptRunCtx *sctx = RAI_ScriptRunCtxCreate(sto);
838-
839-
size_t fnname_len = strlen(fnname);
840-
sctx->fnname = RedisModule_Calloc(fnname_len, sizeof(char));
841-
memcpy(sctx->fnname, fnname, fnname_len);
837+
RAI_ScriptRunCtx *sctx = RAI_ScriptRunCtxCreate(sto, fnname);
842838

843839
RedisModuleString **outkeys;
844840

src/redisai.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ RAI_Model* MODULE_API_FUNC(RedisAI_ModelGetShallowCopy)(RAI_Model* model);
5353

5454
RAI_Script* MODULE_API_FUNC(RedisAI_ScriptCreate)(int backend, int device, const char* modeldef, size_t modellen);
5555
void MODULE_API_FUNC(RedisAI_ScriptFree)(RAI_Script* model);
56-
RAI_ScriptRunCtx* MODULE_API_FUNC(RedisAI_ScriptRunCtxCreate)(RAI_Script* model);
56+
RAI_ScriptRunCtx* MODULE_API_FUNC(RedisAI_ScriptRunCtxCreate)(RAI_Script* model, const char *fnname);
5757
int MODULE_API_FUNC(RedisAI_ScriptRunCtxAddInput)(RAI_ScriptRunCtx* mctx, const char* inputName, RAI_Tensor* inputTensor);
5858
int MODULE_API_FUNC(RedisAI_ScriptRunCtxAddOutput)(RAI_ScriptRunCtx* mctx, const char* outputName);
5959
size_t MODULE_API_FUNC(RedisAI_ScriptRunCtxNumOutputs)(RAI_ScriptRunCtx* mctx);

src/script.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,15 @@ void RAI_ScriptFree(RAI_Script* script, RAI_Error* err) {
8787
RAI_ScriptFreeTorch(script, err);
8888
}
8989

90-
RAI_ScriptRunCtx* RAI_ScriptRunCtxCreate(RAI_Script* script) {
90+
RAI_ScriptRunCtx* RAI_ScriptRunCtxCreate(RAI_Script* script, const char *fnname) {
9191
#define PARAM_INITIAL_SIZE 10
9292
RAI_ScriptRunCtx* sctx = RedisModule_Calloc(1, sizeof(*sctx));
9393
sctx->script = RAI_ScriptGetShallowCopy(script);
9494
sctx->inputs = array_new(RAI_ScriptCtxParam, PARAM_INITIAL_SIZE);
9595
sctx->outputs = array_new(RAI_ScriptCtxParam, PARAM_INITIAL_SIZE);
96+
size_t fnname_len = strlen(fnname);
97+
sctx->fnname = RedisModule_Calloc(fnname_len, sizeof(char));
98+
memcpy(sctx->fnname, fnname, fnname_len);
9699
return sctx;
97100
}
98101

@@ -136,6 +139,8 @@ void RAI_ScriptRunCtxFree(RAI_ScriptRunCtx* sctx) {
136139
}
137140
array_free(sctx->outputs);
138141

142+
RedisModule_Free(sctx->fnname);
143+
139144
RAI_Error err = {0};
140145
RAI_ScriptFree(sctx->script, &err);
141146

src/script.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int RAI_ScriptInit(RedisModuleCtx* ctx);
1313
RAI_Script* RAI_ScriptCreate(RAI_Device device, const char* scriptdef, RAI_Error* err);
1414
void RAI_ScriptFree(RAI_Script* script, RAI_Error* err);
1515

16-
RAI_ScriptRunCtx* RAI_ScriptRunCtxCreate(RAI_Script* script);
16+
RAI_ScriptRunCtx* RAI_ScriptRunCtxCreate(RAI_Script* script, const char *fnname);
1717
int RAI_ScriptRunCtxAddInput(RAI_ScriptRunCtx* sctx, RAI_Tensor* inputTensor);
1818
int RAI_ScriptRunCtxAddOutput(RAI_ScriptRunCtx* sctx);
1919
size_t RAI_ScriptRunCtxNumOutputs(RAI_ScriptRunCtx* sctx);

0 commit comments

Comments
 (0)