Skip to content

Safely add to arrays + fix for #443 #449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/backends/tensorflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,12 @@ RAI_Model *RAI_ModelCreateTF(RAI_Backend backend, const char* devicestr, RAI_Mod

char **inputs_ = array_new(char*, ninputs);
for (long long i=0; i<ninputs; i++) {
array_append(inputs_, RedisModule_Strdup(inputs[i]));
inputs_ = array_append(inputs_, RedisModule_Strdup(inputs[i]));
}

char **outputs_ = array_new(char*, noutputs);
for (long long i=0; i<noutputs; i++) {
array_append(outputs_, RedisModule_Strdup(outputs[i]));
outputs_ = array_append(outputs_, RedisModule_Strdup(outputs[i]));
}

char* buffer = RedisModule_Calloc(modellen, sizeof(*buffer));
Expand Down
8 changes: 4 additions & 4 deletions src/background_workers.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ void *RedisAI_Run_ThreadMain(void *arg) {

// We add the current item to the list of evicted items. If it's the
// first time around this will be the queue front.
array_append(evicted_items, item);
array_append(batch_rinfo, rinfo);
evicted_items = array_append(evicted_items, item);
batch_rinfo = array_append(batch_rinfo, rinfo);

// If the item is a scriptrun, we stop looking for matching items to
// batch because there's no batching for script
Expand Down Expand Up @@ -208,8 +208,8 @@ void *RedisAI_Run_ThreadMain(void *arg) {

// If all previous checks pass, then keep track of the item
// in the list of evicted items
array_append(evicted_items, next_item);
array_append(batch_rinfo, next_rinfo);
evicted_items = array_append(evicted_items, next_item);
batch_rinfo = array_append(batch_rinfo, next_rinfo);

// Update the batchsize and go to the next item to see if
// there's anything else to batch
Expand Down
8 changes: 4 additions & 4 deletions src/dag.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void RedisAI_DagRunSession_TensorGet_Step(RedisAI_RunInfo *rinfo, RAI_DagOp *cur
RAI_Tensor *outTensor = NULL;
// TODO: check tensor copy return value
RAI_TensorDeepCopy(t, &outTensor);
array_append(currentOp->outTensors, outTensor);
currentOp->outTensors = array_append(currentOp->outTensors, outTensor);
}
}

Expand Down Expand Up @@ -624,7 +624,7 @@ int RedisAI_DagRunSyntaxParser(RedisModuleCtx *ctx, RedisModuleString **argv,
rinfo->use_local_context = 1;
RAI_DagOp *currentDagOp = NULL;
RAI_InitDagOp(&currentDagOp);
array_append(rinfo->dagOps, currentDagOp);
rinfo->dagOps = array_append(rinfo->dagOps, currentDagOp);

int persistFlag = 0;
int loadFlag = 0;
Expand Down Expand Up @@ -666,7 +666,7 @@ int RedisAI_DagRunSyntaxParser(RedisModuleCtx *ctx, RedisModuleString **argv,
rinfo->dagNumberCommands++;
RAI_DagOp *currentDagOp = NULL;
RAI_InitDagOp(&currentDagOp);
array_append(rinfo->dagOps, currentDagOp);
rinfo->dagOps = array_append(rinfo->dagOps, currentDagOp);
}
chainingOpCount++;
} else {
Expand Down Expand Up @@ -878,7 +878,7 @@ int RedisAI_DagRunSyntaxParser(RedisModuleCtx *ctx, RedisModuleString **argv,
const char* devicestr = rinfo->dagOps[i]->devicestr;
bool found = false;
for (long long j=0; j<array_len(devices); j++) {
if (strcmp(devicestr, devices[j]) == 0) {
if (strcasecmp(devicestr, devices[j]) == 0) {
found = true;
break;
}
Expand Down
6 changes: 3 additions & 3 deletions src/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ static void RAI_Model_AofRewrite(RedisModuleIO *aof, RedisModuleString *key, voi
RedisModuleCtx *ctx = RedisModule_GetContextFromIO(aof);

for (size_t i=0; i<model->ninputs; i++) {
array_append(inputs_, RedisModule_CreateString(ctx, model->inputs[i], strlen(model->inputs[i])));
inputs_ = array_append(inputs_, RedisModule_CreateString(ctx, model->inputs[i], strlen(model->inputs[i])));
}

for (size_t i=0; i<model->noutputs; i++) {
array_append(outputs_, RedisModule_CreateString(ctx, model->outputs[i], strlen(model->outputs[i])));
outputs_ = array_append(outputs_, RedisModule_CreateString(ctx, model->outputs[i], strlen(model->outputs[i])));
}

long long chunk_size = getModelChunkSize();
Expand All @@ -206,7 +206,7 @@ static void RAI_Model_AofRewrite(RedisModuleIO *aof, RedisModuleString *key, voi

for (size_t i=0; i<n_chunks; i++) {
size_t chunk_len = i < n_chunks - 1 ? chunk_size : len % chunk_size;
array_append(buffers_, RedisModule_CreateString(ctx, buffer + i * chunk_size, chunk_len));
buffers_ = array_append(buffers_, RedisModule_CreateString(ctx, buffer + i * chunk_size, chunk_len));
}

if (buffer) {
Expand Down
2 changes: 1 addition & 1 deletion src/tensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ int RAI_parseTensorSetArgs(RedisModuleCtx *ctx, RedisModuleString **argv, int ar
return -1;
}
ndims++;
array_append(dims, dimension);
dims = array_append(dims, dimension);
len *= dimension;
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/tests_sanitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_sanitizer_dagrun_mobilenet_v1(env):
if (not TEST_TF or not TEST_PT):
return
con = env.getConnection()
mem_allocator = con.execute_command('info', 'memory')['mem_allocator']
mem_allocator = con.info()['mem_allocator']
if 'jemalloc' in mem_allocator:
print("exiting sanitizer test given we're not using stdlib allocator")
return
Expand Down Expand Up @@ -48,7 +48,7 @@ def test_sanitizer_modelrun_mobilenet_v1(env):
if (not TEST_TF or not TEST_PT):
return
con = env.getConnection()
mem_allocator = con.execute_command('info', 'memory')['mem_allocator']
mem_allocator = con.info()['mem_allocator']
if 'jemalloc' in mem_allocator:
print("exiting sanitizer test given we're not using stdlib allocator")
return
Expand Down