Some cleanup

This commit is contained in:
Adrien Bourmault 2021-10-14 08:34:19 +02:00
parent dec98d4d0b
commit 1c09678635
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
7 changed files with 40 additions and 49 deletions

View File

@ -137,5 +137,3 @@ run-cli: all
@bin/gem-graph-ctl @bin/gem-graph-ctl
run-tests: tests run-tests: tests
@bin/tests/scheduler @bin/tests/scheduler
include $(DEPS)

View File

@ -28,7 +28,7 @@
static Server_t *server; static Server_t *server;
static void SigIntTermHandler(int signum) static void sigtermHandler(int signum)
{ {
server->pleaseStop = true; server->pleaseStop = true;
printLog("Server stopping\n"); printLog("Server stopping\n");
@ -37,9 +37,6 @@ static void SigIntTermHandler(int signum)
printLog("All model shutted down\n"); printLog("All model shutted down\n");
} }
// TODO parse args to discover :
// - config files directory
// - models & users directories
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int options; int options;
@ -51,17 +48,17 @@ int main(int argc, char **argv)
switch (options) { switch (options) {
case 'C': case 'C':
printLog("Config : %s\n", optarg); printLog("Config : %s\n", optarg);
parameters.configDir = (char*) calloc(1, strlen(optarg) + 1); parameters.configDir = calloc(1, strlen(optarg) + 1);
strcpy(parameters.configDir, optarg); strcpy(parameters.configDir, optarg);
break; break;
case 'M': case 'M':
printLog("Models : %s\n", optarg); printLog("Models : %s\n", optarg);
parameters.modelDir = (char*) calloc(1, strlen(optarg) + 1); parameters.modelDir = calloc(1, strlen(optarg) + 1);
strcpy(parameters.modelDir, optarg); strcpy(parameters.modelDir, optarg);
break; break;
case 'U': case 'U':
printLog("Users : %s\n", optarg); printLog("Users : %s\n", optarg);
parameters.userDir = (char*) calloc(1, strlen(optarg) + 1); parameters.userDir = calloc(1, strlen(optarg) + 1);
strcpy(parameters.userDir, optarg); strcpy(parameters.userDir, optarg);
break; break;
case ':': case ':':
@ -112,14 +109,14 @@ int main(int argc, char **argv)
printLog("Starting gem-graph-server...\n"); printLog("Starting gem-graph-server...\n");
// Register new interrupt handler // Register new interrupt handler
signal(SIGINT, SigIntTermHandler); signal(SIGINT, sigtermHandler);
signal(SIGTERM, SigIntTermHandler); signal(SIGTERM, sigtermHandler);
// Initializing random generator // Initializing random generator
t = time(&t); t = time(&t);
srand((unsigned) t); srand((unsigned) t);
server = (Server_t*) calloc(1, sizeof(Server_t)); server = calloc(1, sizeof(*server));
// Initializing model system // Initializing model system
ModelSystemInit(&parameters); ModelSystemInit(&parameters);

View File

@ -67,7 +67,8 @@ int ModelLoad(int id)
// Creating structure for the Scheduler // Creating structure for the Scheduler
knownModel[id-1]->scheduler = (Scheduler_t*) calloc(1, sizeof(Scheduler_t)); knownModel[id-1]->scheduler =
calloc(1, sizeof(*knownModel[id-1]->scheduler));
loadedModelSize++; loadedModelSize++;
@ -165,9 +166,9 @@ void ModelAddToKnown(Model_t **newModel)
knownModelSize++; knownModelSize++;
// create socket // create socket
knownModel = knownModel =
(Model_t**) realloc(knownModel, knownModelSize * sizeof(Model_t*)); (Model_t**) realloc(knownModel, knownModelSize * sizeof(*knownModel));
// populate socket // populate socket
knownModel[knownModelSize-1] = (Model_t*) calloc(1, sizeof(Model_t)); knownModel[knownModelSize-1] = calloc(1, sizeof(**knownModel));
// populate model // populate model
knownModel[knownModelSize-1]->id = knownModelSize; knownModel[knownModelSize-1]->id = knownModelSize;
// return value // return value
@ -177,16 +178,16 @@ void ModelAddToKnown(Model_t **newModel)
// continue. model population // continue. model population
knownModel[knownModelSize-1]->name = knownModel[knownModelSize-1]->name =
(char *) calloc(1, sizeof(char) * MODEL_STRING_SIZE); calloc(1, sizeof(char) * MODEL_STRING_SIZE);
knownModel[knownModelSize-1]->filename = knownModel[knownModelSize-1]->filename =
(char *) calloc(1, sizeof(char) * MODEL_STRING_SIZE); calloc(1, sizeof(char) * MODEL_STRING_SIZE);
knownModel[knownModelSize-1]->owner = knownModel[knownModelSize-1]->owner =
(char *) calloc(1, sizeof(char) * MODEL_STRING_SIZE); calloc(1, sizeof(char) * MODEL_STRING_SIZE);
knownModel[knownModelSize-1]->version = knownModel[knownModelSize-1]->version =
(char *) calloc(1, sizeof(char) * MODEL_STRING_SIZE); calloc(1, sizeof(char) * MODEL_STRING_SIZE);
knownModel[knownModelSize-1]->space_xMax = XMAX; knownModel[knownModelSize-1]->space_xMax = XMAX;
knownModel[knownModelSize-1]->space_yMax = YMAX; knownModel[knownModelSize-1]->space_yMax = YMAX;
@ -233,9 +234,9 @@ void ModelSystemInit(Parameters_t *parameters)
Model_t *newModel; Model_t *newModel;
char *extensionPosition; char *extensionPosition;
loadedModel = (Model_t**) calloc(1, sizeof(Model_t*)); loadedModel = calloc(1, sizeof(*loadedModel));
knownModel = (Model_t**) calloc(1, sizeof(Model_t*)); knownModel = calloc(1, sizeof(*knownModel));
knownModelSize = 0; knownModelSize = 0;
loadedModelSize = 0; loadedModelSize = 0;

View File

@ -353,7 +353,7 @@ int ParseModelIdentityXML(Model_t *model, Parameters_t *params)
}; };
// Allocating space for schema file path // Allocating space for schema file path
schemPath = (char*) calloc(1, strlen(params->modelDir) schemPath = calloc(1, strlen(params->modelDir)
+ strlen("/schemas/model_ .xmls")); + strlen("/schemas/model_ .xmls"));
printLog("Preparsing model %s\n", model->name); printLog("Preparsing model %s\n", model->name);

View File

@ -52,7 +52,7 @@ static Center_t *findWorkArea(Center_t *centersList, Arrow_t *electedArrow,
register Center_t *currentCenter, *newCenter; register Center_t *currentCenter, *newCenter;
currentCenter = centersList->next; currentCenter = centersList->next;
newCenter = (Center_t*) malloc(sizeof(Center_t)); newCenter = malloc(sizeof(Center_t));
while (currentCenter){ while (currentCenter){
if ( (xmax && (abs(electedArrow->x - currentCenter->x) <= ruleRadius)) if ( (xmax && (abs(electedArrow->x - currentCenter->x) <= ruleRadius))
@ -101,9 +101,9 @@ static void *schedulerMain(void *scheduler)
printLog("%d threads available.\n", ncpu); printLog("%d threads available.\n", ncpu);
// Data structures // Data structures
workerArray = (Worker_t*) calloc(ncpu, sizeof(Worker_t)); workerArray = calloc(ncpu, sizeof(*workerArray));
nworker = 0; nworker = 0;
centersList = (Center_t*) calloc(1, sizeof(Center_t)); centersList = calloc(1, sizeof(*centersList));
// Initiate the arrowArray lock // Initiate the arrowArray lock
if (err = ArrowsInitLock(args->arrowArray), err != 0) { if (err = ArrowsInitLock(args->arrowArray), err != 0) {

View File

@ -46,14 +46,14 @@ bool TestCenterRemove
Center_t *anyCenter = NULL; Center_t *anyCenter = NULL;
// adding a something to a bad pointer // adding a something to a bad pointer
centerRemove(anyCenter); CenterRemove(anyCenter);
//printf("* Status of centers list after deleting NULL\n"); //printf("* Status of centers list after deleting NULL\n");
//printCenters(anyCenter); //printCenters(anyCenter);
assert(anyCenter == NULL); assert(anyCenter == NULL);
anyCenter = (Center_t*) calloc(1, sizeof(Center_t)); anyCenter = calloc(1, sizeof(*anyCenter));
//printf("* Initial status of centers list\n"); //printf("* Initial status of centers list\n");
//printCenters(anyCenter); //printCenters(anyCenter);
@ -63,25 +63,20 @@ bool TestCenterRemove
assert(anyCenter != NULL); assert(anyCenter != NULL);
// Deleting a lonely pointer // Deleting a lonely pointer
centerRemove(anyCenter); CenterRemove(anyCenter);
//printf("* Status of centers list after deleting a lonely center\n"); //printf("* Status of centers list after deleting a lonely center\n");
//printCenters(anyCenter); //printCenters(anyCenter);
anyCenter = (Center_t*) calloc(1, sizeof(Center_t)); anyCenter = calloc(1, sizeof(*anyCenter));
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
Center_t *oldfirst = anyCenter->next; Center_t *oldfirst = anyCenter->next;
Center_t *oldsecond = anyCenter->next->next; Center_t *oldsecond = anyCenter->next->next;
// Deleting a the first pointer // Deleting a the first pointer
centerRemove(anyCenter->next); CenterRemove(anyCenter->next);
//printf("* Status of centers list after deleting the head center\n"); //printf("* Status of centers list after deleting the head center\n");
//printCenters(anyCenter); //printCenters(anyCenter);
@ -96,14 +91,14 @@ bool TestCenterAdd(void)
Center_t *anyCenter = NULL; Center_t *anyCenter = NULL;
// adding a something to a bad pointer // adding a something to a bad pointer
centerAdd(anyCenter, NULL); CenterAdd(anyCenter, NULL);
//printf("* Status of centers list after adding something to NULL\n"); //printf("* Status of centers list after adding something to NULL\n");
//printCenters(anyCenter); //printCenters(anyCenter);
assert(anyCenter == NULL); assert(anyCenter == NULL);
anyCenter = (Center_t*) calloc(1, sizeof(Center_t)); anyCenter = calloc(1, sizeof(Center_t));
//printf("* Initial status of centers list\n"); //printf("* Initial status of centers list\n");
//printCenters(anyCenter); //printCenters(anyCenter);
@ -113,7 +108,7 @@ bool TestCenterAdd(void)
assert(anyCenter != NULL); assert(anyCenter != NULL);
// adding a bad pointer // adding a bad pointer
centerAdd(anyCenter, NULL); CenterAdd(anyCenter, NULL);
//printf("* Status of centers list after adding NULL\n"); //printf("* Status of centers list after adding NULL\n");
//printCenters(anyCenter); //printCenters(anyCenter);
@ -123,8 +118,8 @@ bool TestCenterAdd(void)
assert(anyCenter != NULL); assert(anyCenter != NULL);
// adding a good pointer // adding a good pointer
Center_t *goodpointer = (Center_t*) calloc(1, sizeof(Center_t)); Center_t *goodpointer = calloc(1, sizeof(Center_t));
centerAdd(anyCenter, goodpointer); CenterAdd(anyCenter, goodpointer);
//printf("* Status of centers list after adding a center\n"); //printf("* Status of centers list after adding a center\n");
//printCenters(anyCenter); //printCenters(anyCenter);
@ -136,8 +131,8 @@ bool TestCenterAdd(void)
assert(goodpointer->next == NULL); assert(goodpointer->next == NULL);
// adding another good pointer // adding another good pointer
Center_t *newgoodpointer = (Center_t*) calloc(1, sizeof(Center_t)); Center_t *newgoodpointer = calloc(1, sizeof(Center_t));
centerAdd(anyCenter, newgoodpointer); CenterAdd(anyCenter, newgoodpointer);
//printf("* Status of centers list after adding another center\n"); //printf("* Status of centers list after adding another center\n");
//printCenters(anyCenter); //printCenters(anyCenter);
@ -149,10 +144,10 @@ bool TestCenterAdd(void)
assert(newgoodpointer->next == goodpointer); assert(newgoodpointer->next == goodpointer);
// adding another good pointer // adding another good pointer
Center_t *strangepointer = (Center_t*) calloc(1, sizeof(Center_t)); Center_t *strangepointer = calloc(1, sizeof(Center_t));
strangepointer->next = (Center_t*)0xCAFEBABE; strangepointer->next = (Center_t*)0xCAFEBABE;
strangepointer->prev = (Center_t*)0xCAFEBABE; strangepointer->prev = (Center_t*)0xCAFEBABE;
centerAdd(anyCenter, strangepointer); CenterAdd(anyCenter, strangepointer);
//printf("* Status of centers list after adding a strange center\n"); //printf("* Status of centers list after adding a strange center\n");
//printCenters(anyCenter); //printCenters(anyCenter);
@ -170,13 +165,13 @@ bool TestCenterAdd(void)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
printf("\n==== Testing centers.c/centerAdd() ====\n"); printf("\n==== Testing centers.c/CenterAdd() ====\n");
TestCenterAdd(); TestCenterAdd();
printf("\n==== Testing centers.c/centerAdd() ==== : OK\n"); printf("\n==== Testing centers.c/CenterAdd() ==== : OK\n");
printf("\n==== Testing centers.c/centerRemove() ====\n"); printf("\n==== Testing centers.c/CenterRemove() ====\n");
TestCenterRemove(); TestCenterRemove();
printf("\n==== Testing centers.c/centerRemove() ==== : OK\n"); printf("\n==== Testing centers.c/CenterRemove() ==== : OK\n");
return 0; return 0;
} }

View File

@ -3,7 +3,7 @@
int main(void) int main(void)
{ {
int *a = (int*) malloc(7 * sizeof(int)); int *a = malloc(7 * sizeof(int));
printf("Salut! Tableau d'entiers à l'adresse %p\n", a); printf("Salut! Tableau d'entiers à l'adresse %p\n", a);