Some cleanup
This commit is contained in:
parent
dec98d4d0b
commit
1c09678635
2
Makefile
2
Makefile
|
@ -137,5 +137,3 @@ run-cli: all
|
|||
@bin/gem-graph-ctl
|
||||
run-tests: tests
|
||||
@bin/tests/scheduler
|
||||
|
||||
include $(DEPS)
|
||||
|
|
17
src/main.c
17
src/main.c
|
@ -28,7 +28,7 @@
|
|||
|
||||
static Server_t *server;
|
||||
|
||||
static void SigIntTermHandler(int signum)
|
||||
static void sigtermHandler(int signum)
|
||||
{
|
||||
server->pleaseStop = true;
|
||||
printLog("Server stopping\n");
|
||||
|
@ -37,9 +37,6 @@ static void SigIntTermHandler(int signum)
|
|||
printLog("All model shutted down\n");
|
||||
}
|
||||
|
||||
// TODO parse args to discover :
|
||||
// - config files directory
|
||||
// - models & users directories
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int options;
|
||||
|
@ -51,17 +48,17 @@ int main(int argc, char **argv)
|
|||
switch (options) {
|
||||
case 'C':
|
||||
printLog("Config : %s\n", optarg);
|
||||
parameters.configDir = (char*) calloc(1, strlen(optarg) + 1);
|
||||
parameters.configDir = calloc(1, strlen(optarg) + 1);
|
||||
strcpy(parameters.configDir, optarg);
|
||||
break;
|
||||
case 'M':
|
||||
printLog("Models : %s\n", optarg);
|
||||
parameters.modelDir = (char*) calloc(1, strlen(optarg) + 1);
|
||||
parameters.modelDir = calloc(1, strlen(optarg) + 1);
|
||||
strcpy(parameters.modelDir, optarg);
|
||||
break;
|
||||
case 'U':
|
||||
printLog("Users : %s\n", optarg);
|
||||
parameters.userDir = (char*) calloc(1, strlen(optarg) + 1);
|
||||
parameters.userDir = calloc(1, strlen(optarg) + 1);
|
||||
strcpy(parameters.userDir, optarg);
|
||||
break;
|
||||
case ':':
|
||||
|
@ -112,14 +109,14 @@ int main(int argc, char **argv)
|
|||
printLog("Starting gem-graph-server...\n");
|
||||
|
||||
// Register new interrupt handler
|
||||
signal(SIGINT, SigIntTermHandler);
|
||||
signal(SIGTERM, SigIntTermHandler);
|
||||
signal(SIGINT, sigtermHandler);
|
||||
signal(SIGTERM, sigtermHandler);
|
||||
|
||||
// Initializing random generator
|
||||
t = time(&t);
|
||||
srand((unsigned) t);
|
||||
|
||||
server = (Server_t*) calloc(1, sizeof(Server_t));
|
||||
server = calloc(1, sizeof(*server));
|
||||
|
||||
// Initializing model system
|
||||
ModelSystemInit(¶meters);
|
||||
|
|
19
src/model.c
19
src/model.c
|
@ -67,7 +67,8 @@ int ModelLoad(int id)
|
|||
|
||||
|
||||
// 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++;
|
||||
|
||||
|
@ -165,9 +166,9 @@ void ModelAddToKnown(Model_t **newModel)
|
|||
knownModelSize++;
|
||||
// create socket
|
||||
knownModel =
|
||||
(Model_t**) realloc(knownModel, knownModelSize * sizeof(Model_t*));
|
||||
(Model_t**) realloc(knownModel, knownModelSize * sizeof(*knownModel));
|
||||
// populate socket
|
||||
knownModel[knownModelSize-1] = (Model_t*) calloc(1, sizeof(Model_t));
|
||||
knownModel[knownModelSize-1] = calloc(1, sizeof(**knownModel));
|
||||
// populate model
|
||||
knownModel[knownModelSize-1]->id = knownModelSize;
|
||||
// return value
|
||||
|
@ -177,16 +178,16 @@ void ModelAddToKnown(Model_t **newModel)
|
|||
|
||||
// continue. model population
|
||||
knownModel[knownModelSize-1]->name =
|
||||
(char *) calloc(1, sizeof(char) * MODEL_STRING_SIZE);
|
||||
calloc(1, sizeof(char) * MODEL_STRING_SIZE);
|
||||
|
||||
knownModel[knownModelSize-1]->filename =
|
||||
(char *) calloc(1, sizeof(char) * MODEL_STRING_SIZE);
|
||||
calloc(1, sizeof(char) * MODEL_STRING_SIZE);
|
||||
|
||||
knownModel[knownModelSize-1]->owner =
|
||||
(char *) calloc(1, sizeof(char) * MODEL_STRING_SIZE);
|
||||
calloc(1, sizeof(char) * MODEL_STRING_SIZE);
|
||||
|
||||
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_yMax = YMAX;
|
||||
|
@ -233,9 +234,9 @@ void ModelSystemInit(Parameters_t *parameters)
|
|||
Model_t *newModel;
|
||||
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;
|
||||
loadedModelSize = 0;
|
||||
|
|
|
@ -353,7 +353,7 @@ int ParseModelIdentityXML(Model_t *model, Parameters_t *params)
|
|||
};
|
||||
|
||||
// Allocating space for schema file path
|
||||
schemPath = (char*) calloc(1, strlen(params->modelDir)
|
||||
schemPath = calloc(1, strlen(params->modelDir)
|
||||
+ strlen("/schemas/model_ .xmls"));
|
||||
|
||||
printLog("Preparsing model %s\n", model->name);
|
||||
|
|
|
@ -52,7 +52,7 @@ static Center_t *findWorkArea(Center_t *centersList, Arrow_t *electedArrow,
|
|||
register Center_t *currentCenter, *newCenter;
|
||||
|
||||
currentCenter = centersList->next;
|
||||
newCenter = (Center_t*) malloc(sizeof(Center_t));
|
||||
newCenter = malloc(sizeof(Center_t));
|
||||
|
||||
while (currentCenter){
|
||||
if ( (xmax && (abs(electedArrow->x - currentCenter->x) <= ruleRadius))
|
||||
|
@ -101,9 +101,9 @@ static void *schedulerMain(void *scheduler)
|
|||
printLog("%d threads available.\n", ncpu);
|
||||
|
||||
// Data structures
|
||||
workerArray = (Worker_t*) calloc(ncpu, sizeof(Worker_t));
|
||||
workerArray = calloc(ncpu, sizeof(*workerArray));
|
||||
nworker = 0;
|
||||
centersList = (Center_t*) calloc(1, sizeof(Center_t));
|
||||
centersList = calloc(1, sizeof(*centersList));
|
||||
|
||||
// Initiate the arrowArray lock
|
||||
if (err = ArrowsInitLock(args->arrowArray), err != 0) {
|
||||
|
|
|
@ -46,14 +46,14 @@ bool TestCenterRemove
|
|||
Center_t *anyCenter = NULL;
|
||||
|
||||
// adding a something to a bad pointer
|
||||
centerRemove(anyCenter);
|
||||
CenterRemove(anyCenter);
|
||||
|
||||
//printf("* Status of centers list after deleting NULL\n");
|
||||
//printCenters(anyCenter);
|
||||
|
||||
assert(anyCenter == NULL);
|
||||
|
||||
anyCenter = (Center_t*) calloc(1, sizeof(Center_t));
|
||||
anyCenter = calloc(1, sizeof(*anyCenter));
|
||||
|
||||
//printf("* Initial status of centers list\n");
|
||||
//printCenters(anyCenter);
|
||||
|
@ -63,25 +63,20 @@ bool TestCenterRemove
|
|||
assert(anyCenter != NULL);
|
||||
|
||||
// Deleting a lonely pointer
|
||||
centerRemove(anyCenter);
|
||||
CenterRemove(anyCenter);
|
||||
|
||||
//printf("* Status of centers list after deleting a lonely center\n");
|
||||
//printCenters(anyCenter);
|
||||
|
||||
|
||||
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)));
|
||||
centerAdd(anyCenter, (Center_t*) calloc(1, sizeof(Center_t)));
|
||||
anyCenter = calloc(1, sizeof(*anyCenter));
|
||||
|
||||
Center_t *oldfirst = anyCenter->next;
|
||||
Center_t *oldsecond = anyCenter->next->next;
|
||||
|
||||
|
||||
// Deleting a the first pointer
|
||||
centerRemove(anyCenter->next);
|
||||
CenterRemove(anyCenter->next);
|
||||
|
||||
//printf("* Status of centers list after deleting the head center\n");
|
||||
//printCenters(anyCenter);
|
||||
|
@ -96,14 +91,14 @@ bool TestCenterAdd(void)
|
|||
Center_t *anyCenter = NULL;
|
||||
|
||||
// adding a something to a bad pointer
|
||||
centerAdd(anyCenter, NULL);
|
||||
CenterAdd(anyCenter, NULL);
|
||||
|
||||
//printf("* Status of centers list after adding something to NULL\n");
|
||||
//printCenters(anyCenter);
|
||||
|
||||
assert(anyCenter == NULL);
|
||||
|
||||
anyCenter = (Center_t*) calloc(1, sizeof(Center_t));
|
||||
anyCenter = calloc(1, sizeof(Center_t));
|
||||
|
||||
//printf("* Initial status of centers list\n");
|
||||
//printCenters(anyCenter);
|
||||
|
@ -113,7 +108,7 @@ bool TestCenterAdd(void)
|
|||
assert(anyCenter != NULL);
|
||||
|
||||
// adding a bad pointer
|
||||
centerAdd(anyCenter, NULL);
|
||||
CenterAdd(anyCenter, NULL);
|
||||
|
||||
//printf("* Status of centers list after adding NULL\n");
|
||||
//printCenters(anyCenter);
|
||||
|
@ -123,8 +118,8 @@ bool TestCenterAdd(void)
|
|||
assert(anyCenter != NULL);
|
||||
|
||||
// adding a good pointer
|
||||
Center_t *goodpointer = (Center_t*) calloc(1, sizeof(Center_t));
|
||||
centerAdd(anyCenter, goodpointer);
|
||||
Center_t *goodpointer = calloc(1, sizeof(Center_t));
|
||||
CenterAdd(anyCenter, goodpointer);
|
||||
|
||||
//printf("* Status of centers list after adding a center\n");
|
||||
//printCenters(anyCenter);
|
||||
|
@ -136,8 +131,8 @@ bool TestCenterAdd(void)
|
|||
assert(goodpointer->next == NULL);
|
||||
|
||||
// adding another good pointer
|
||||
Center_t *newgoodpointer = (Center_t*) calloc(1, sizeof(Center_t));
|
||||
centerAdd(anyCenter, newgoodpointer);
|
||||
Center_t *newgoodpointer = calloc(1, sizeof(Center_t));
|
||||
CenterAdd(anyCenter, newgoodpointer);
|
||||
|
||||
//printf("* Status of centers list after adding another center\n");
|
||||
//printCenters(anyCenter);
|
||||
|
@ -149,10 +144,10 @@ bool TestCenterAdd(void)
|
|||
assert(newgoodpointer->next == goodpointer);
|
||||
|
||||
// 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->prev = (Center_t*)0xCAFEBABE;
|
||||
centerAdd(anyCenter, strangepointer);
|
||||
CenterAdd(anyCenter, strangepointer);
|
||||
|
||||
//printf("* Status of centers list after adding a strange center\n");
|
||||
//printCenters(anyCenter);
|
||||
|
@ -170,13 +165,13 @@ bool TestCenterAdd(void)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
printf("\n==== Testing centers.c/centerAdd() ====\n");
|
||||
printf("\n==== Testing centers.c/CenterAdd() ====\n");
|
||||
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();
|
||||
printf("\n==== Testing centers.c/centerRemove() ==== : OK\n");
|
||||
printf("\n==== Testing centers.c/CenterRemove() ==== : OK\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue