Fix memory leaks and remove logging messages.

This commit is contained in:
Jordan Bancino 2023-08-01 22:36:52 +00:00
parent d9f5ca3e0d
commit 20b4896f86
1 changed files with 7 additions and 20 deletions

View File

@ -142,8 +142,6 @@ Main(Array * args)
goto finish; goto finish;
} }
Log(LOG_INFO, "j2s: Cytoplasm Json -> C Struct Converter");
ArgParseStateInit(&arg); ArgParseStateInit(&arg);
while ((opt = ArgParse(&arg, args, "s:h:c:")) != -1) while ((opt = ArgParse(&arg, args, "s:h:c:")) != -1)
{ {
@ -202,12 +200,6 @@ Main(Array * args)
goto finish; goto finish;
} }
Log(LOG_INFO, "Schema File: %s", schema);
Log(LOG_INFO, "Output:");
Log(LOG_INFO, " Header: %s", header);
Log(LOG_INFO, " C Source: %s", impl);
Log(LOG_NOTICE, "Parsing type schema...");
schemaJson = JsonDecode(schemaFile); schemaJson = JsonDecode(schemaFile);
if (!schemaJson) if (!schemaJson)
{ {
@ -218,7 +210,6 @@ Main(Array * args)
StreamClose(schemaFile); StreamClose(schemaFile);
schemaFile = NULL; schemaFile = NULL;
Log(LOG_NOTICE, "Validating type schema...");
val = HashMapGet(schemaJson, "guard"); val = HashMapGet(schemaJson, "guard");
if (!val) if (!val)
@ -324,6 +315,7 @@ Main(Array * args)
while (HashMapIterate(typeFields, &fieldName, (void **) &fieldVal)) while (HashMapIterate(typeFields, &fieldName, (void **) &fieldVal))
{ {
char *fieldType; char *fieldType;
int isArrType = 0;
JsonValue *requiredVal; JsonValue *requiredVal;
if (JsonValueType(fieldVal) != JSON_OBJECT) if (JsonValueType(fieldVal) != JSON_OBJECT)
@ -341,11 +333,11 @@ Main(Array * args)
goto finish; goto finish;
} }
fieldType = StrDuplicate(fieldType);
if (*fieldType == '[' && fieldType[strlen(fieldType) - 1] == ']') if (*fieldType == '[' && fieldType[strlen(fieldType) - 1] == ']')
{ {
fieldType++; fieldType++;
fieldType[strlen(fieldType) - 1] = '\0'; fieldType[strlen(fieldType) - 1] = '\0';
isArrType = 1;
} }
if (!StrEquals(fieldType, "object") && if (!StrEquals(fieldType, "object") &&
@ -361,14 +353,15 @@ Main(Array * args)
node = Malloc(sizeof(Node)); node = Malloc(sizeof(Node));
*node = ArraySize(requiredTypes); *node = ArraySize(requiredTypes);
HashMapSet(typeToNode, fieldType, node); HashMapSet(typeToNode, fieldType, node);
ArrayAdd(requiredTypes, fieldType); ArrayAdd(requiredTypes, StrDuplicate(fieldType));
} }
GraphEdgeSet(dependencyGraph, *node, *typeNode, 1); GraphEdgeSet(dependencyGraph, *node, *typeNode, 1);
} }
else
if (isArrType)
{ {
Free(fieldType); fieldType[strlen(fieldType)] = ']';
} }
requiredVal = HashMapGet(fieldObj, "required"); requiredVal = HashMapGet(fieldObj, "required");
@ -413,8 +406,6 @@ Main(Array * args)
*/ */
} }
Log(LOG_NOTICE, "Resolving referenced types...");
sortedNodes = GraphTopologicalSort(dependencyGraph, &sortedNodesLen); sortedNodes = GraphTopologicalSort(dependencyGraph, &sortedNodesLen);
GraphFree(dependencyGraph); GraphFree(dependencyGraph);
@ -435,8 +426,6 @@ Main(Array * args)
} }
} }
Log(LOG_NOTICE, "Writing header...");
guard = JsonValueAsString(HashMapGet(schemaJson, "guard")); guard = JsonValueAsString(HashMapGet(schemaJson, "guard"));
StreamPrintf(headerFile, "/* Generated by j2s */\n\n"); StreamPrintf(headerFile, "/* Generated by j2s */\n\n");
@ -579,8 +568,6 @@ Main(Array * args)
} }
HashMapFree(typeToNode); HashMapFree(typeToNode);
Log(LOG_INFO, "Writing implementation code...");
headerName = JsonValueAsString(HashMapGet(schemaJson, "header")); headerName = JsonValueAsString(HashMapGet(schemaJson, "header"));
StreamPrintf(implFile, "/* Generated by j2s */\n\n"); StreamPrintf(implFile, "/* Generated by j2s */\n\n");
@ -961,9 +948,9 @@ Main(Array * args)
StreamPrintf(implFile, "}\n\n"); StreamPrintf(implFile, "}\n\n");
StreamPutc(headerFile, '\n'); StreamPutc(headerFile, '\n');
ArrayFree(keys);
} }
ArrayFree(keys);
} }
StreamPrintf(headerFile, "#endif /* %s */\n", guard); StreamPrintf(headerFile, "#endif /* %s */\n", guard);