Compare commits

...

11 commits

Author SHA1 Message Date
8987802437 Merge pull request 'Fix LMDB use-after-free' (#53) from lda/Cytoplasm:fix-deadlock into master
Some checks failed
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Has been cancelled
Reviewed-on: Telodendria/Cytoplasm#53
2024-09-13 20:11:12 -04:00
LDA
9fed42d2ac [FIX] Fix LMDB use-after-free 2024-09-09 13:05:30 +02:00
9c6781c458 Merge pull request 'Fix j2s generation issue' (#52) from lda/Cytoplasm:master into master
Some checks failed
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Has been cancelled
Reviewed-on: Telodendria/Cytoplasm#52
2024-09-02 14:38:02 -04:00
LDA
33139510b9 [FIX] Fix j2s generation issue
Aie...
2024-08-27 18:50:56 +02:00
4831f2e03d Merge pull request 'Add key->[known structure] schemas to j2s' (#50) from lda/Cytoplasm:master into master
Some checks failed
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Has been cancelled
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Has been cancelled
Reviewed-on: Telodendria/Cytoplasm#50
2024-08-27 12:34:49 -04:00
lda
cc665ac7fc Merge branch 'master' into master 2024-08-27 12:25:28 -04:00
a121793795 Merge pull request 'Fix out the configure for the AUR' (#51) from lda/Cytoplasm:fix-configure into master
Some checks are pending
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Waiting to run
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Waiting to run
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Waiting to run
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Waiting to run
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Waiting to run
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Waiting to run
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Waiting to run
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Waiting to run
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Waiting to run
Reviewed-on: Telodendria/Cytoplasm#51
2024-08-27 09:44:49 -04:00
9e1026d893 Merge pull request 'Add raw SHA inputs and hashtypes to ShaToHex' (#47) from lda/Cytoplasm:sha-revamp into master
Some checks are pending
Compile Cytoplasm / Compile Cytoplasm (x86, alpine-v3.19) (push) Waiting to run
Compile Cytoplasm / Compile Cytoplasm (x86, debian-v12.4) (push) Waiting to run
Compile Cytoplasm / Compile Cytoplasm (x86, freebsd-v14.0) (push) Waiting to run
Compile Cytoplasm / Compile Cytoplasm (x86, netbsd-v9.3) (push) Waiting to run
Compile Cytoplasm / Compile Cytoplasm (x86_64, alpine-v3.19) (push) Waiting to run
Compile Cytoplasm / Compile Cytoplasm (x86_64, debian-v12.4) (push) Waiting to run
Compile Cytoplasm / Compile Cytoplasm (x86_64, freebsd-v14.0) (push) Waiting to run
Compile Cytoplasm / Compile Cytoplasm (x86_64, netbsd-v9.3) (push) Waiting to run
Compile Cytoplasm / Compile Cytoplasm (x86_64, openbsd-v7.4) (push) Waiting to run
Reviewed-on: Telodendria/Cytoplasm#47
2024-08-27 09:38:26 -04:00
LDA
5889bec95f [MOD] Use macro to determine if it is delimited 2024-08-27 11:24:18 +02:00
lda
d0b5c441dd [FIX] Fix out the configure 2024-08-26 21:28:44 +02:00
LDA
d3379d8157 [ADD] {Field}s in j2s 2024-08-26 15:38:20 +02:00
3 changed files with 266 additions and 11 deletions

3
configure vendored
View file

@ -269,7 +269,8 @@ ${TAB}done
${LIB_NAME}: ${OUT}/lib/lib${LIB_NAME}.a ${OUT}/lib/lib${LIB_NAME}.so
install: ${LIB_NAME}
${TAB}mkdir -p ${OUT}/lib
${TAB}mkdir -p \$(PREFIX)/${OUT}/lib
${TAB}mkdir -p \$(PREFIX)/lib
${TAB}cp ${OUT}/lib/lib${LIB_NAME}.a \$(PREFIX)/lib/lib${LIB_NAME}.a
${TAB}cp ${OUT}/lib/lib${LIB_NAME}.so \$(PREFIX)/lib/lib${LIB_NAME}.so
$(collect ${INCLUDE}/ '' '' \$\(PREFIX\)/include/${LIB_NAME}/ install_out)

View file

@ -293,6 +293,7 @@ LMDBUnlock(Db *d, DbRef *r)
Stream *stream;
MDB_val key, val;
bool ret = true;
DbHint hint = r ? r->hint : 0;
if (!d || !r)
{
@ -324,7 +325,7 @@ LMDBUnlock(Db *d, DbRef *r)
{
free(val.mv_data);
}
if (ret && r->hint == DB_HINT_WRITE)
if (ret && hint == DB_HINT_WRITE)
{
pthread_mutex_unlock(&d->lock);
}

View file

@ -38,6 +38,7 @@
#define MAX_DEPENDENCIES 32
#define IsDelimited(field, c1, c2) (*field == c1 && field[strlen(field) - 1] == c2)
static char *
Trim(char c, char *str)
{
@ -75,10 +76,14 @@ TypeToJsonType(char *type)
}
else
{
if (*type == '[' && type[strlen(type) - 1] == ']')
if (IsDelimited(type, '[', ']'))
{
return JSON_ARRAY;
}
else if (IsDelimited(type, '{', '}'))
{
return JSON_OBJECT;
}
else
{
return JSON_OBJECT;
@ -91,7 +96,7 @@ JsonTypeToStr(JsonType type)
{
switch (type)
{
case JSON_OBJECT:
case JSON_OBJECT:
return "JSON_OBJECT";
case JSON_ARRAY:
return "JSON_ARRAY";
@ -325,6 +330,7 @@ Main(Array * args)
{
char *fieldType;
bool isArrType = false;
bool isObjType = false;
JsonValue *requiredVal;
JsonValue *ignoreVal;
@ -343,12 +349,18 @@ Main(Array * args)
goto finish;
}
if (*fieldType == '[' && fieldType[strlen(fieldType) - 1] == ']')
if (IsDelimited(fieldType, '[', ']'))
{
fieldType++;
fieldType[strlen(fieldType) - 1] = '\0';
isArrType = true;
}
else if (IsDelimited(fieldType, '{', '}'))
{
fieldType++;
fieldType[strlen(fieldType) - 1] = '\0';
isObjType = true;
}
if (!StrEquals(fieldType, "object") &&
!StrEquals(fieldType, "array") &&
@ -374,6 +386,10 @@ Main(Array * args)
{
fieldType[strlen(fieldType)] = ']';
}
else if (isObjType)
{
fieldType[strlen(fieldType)] = '}';
}
requiredVal = HashMapGet(fieldObj, "required");
if (requiredVal && JsonValueType(requiredVal) != JSON_BOOLEAN)
@ -529,11 +545,13 @@ Main(Array * args)
{
cType = "double";
}
else if (StrEquals(fieldType, "object"))
else if (StrEquals(fieldType, "object") ||
IsDelimited(fieldType, '{', '}'))
{
cType = "HashMap *";
}
else if (StrEquals(fieldType, "array") || (*fieldType == '[' && fieldType[strlen(fieldType) - 1] == ']'))
else if (StrEquals(fieldType, "array") ||
IsDelimited(fieldType, '[', ']'))
{
cType = "Array *";
}
@ -542,7 +560,20 @@ Main(Array * args)
cType = fieldType;
}
StreamPrintf(headerFile, " %s %s;\n", cType, field);
if (IsDelimited(fieldType, '{', '}') ||
IsDelimited(fieldType, '[', ']'))
{
char end = fieldType[strlen(fieldType) - 1];
fieldType[strlen(fieldType) - 1] = '\0';
StreamPrintf(headerFile, " %s /* of %s */ %s;\n", cType, fieldType + 1, field);
fieldType[strlen(fieldType)] = end;
}
else
{
StreamPrintf(headerFile, " %s %s;\n", cType, field);
}
}
StreamPrintf(headerFile, "} %s;\n\n", type);
@ -673,7 +704,134 @@ Main(Array * args)
StreamPrintf(implFile, " out->%s = JsonValueAsObject(val);\n", key);
StreamPrintf(implFile, " Free(val); /* Not JsonValueFree() because we want the inner value. */\n");
}
else if (*fieldType == '[' && fieldType[strlen(fieldType) - 1] == ']')
else if (IsDelimited(fieldType, '{', '}'))
{
fieldType++;
fieldType[strlen(fieldType) - 1] = '\0';
isEnum = StrEquals(JsonValueAsString(JsonGet(types, 2, fieldType, "type")), "enum");
jsonType = isEnum ? JSON_STRING : TypeToJsonType(fieldType);
StreamPrintf(implFile, " out->%s = HashMapCreate();\n", key);
StreamPrintf(implFile, " if (!out->%s)\n", key);
StreamPrintf(implFile, " {\n");
StreamPrintf(implFile, " *errp = \"Failed to allocate memory for %s.%s.\";\n", type, key);
StreamPrintf(implFile, " return false;\n");
StreamPrintf(implFile, " }\n");
StreamPrintf(implFile, " else\n");
StreamPrintf(implFile, " {\n");
StreamPrintf(implFile, " HashMap *obj = JsonValueAsObject(val);\n");
StreamPrintf(implFile, " char *objKey;\n");
StreamPrintf(implFile, " JsonValue *v;\n");
StreamPrintf(implFile, "\n");
StreamPrintf(implFile, " while (HashMapIterate(obj, &objKey, (void **) &v))\n");
StreamPrintf(implFile, " {\n");
if (StrEquals(fieldType, "integer") ||
StrEquals(fieldType, "float") ||
StrEquals(fieldType, "boolean"))
{
char *cType;
if (StrEquals(fieldType, "integer"))
{
cType = "int64_t";
}
else if (StrEquals(fieldType, "float"))
{
cType = "double";
}
else if (StrEquals(fieldType, "boolean"))
{
cType = "bool";
}
else
{
/* Should never happen */
cType = NULL;
}
*fieldType = toupper(*fieldType);
StreamPrintf(implFile, " %s *ref;\n", cType);
StreamPrintf(implFile, " if (JsonValueType(v) != %s)\n", JsonTypeToStr(jsonType));
StreamPrintf(implFile, " {\n");
StreamPrintf(implFile, " *errp = \"%s.%s{} contains an invalid value.\";\n", type, key);
StreamPrintf(implFile, " return false;\n");
StreamPrintf(implFile, " }\n");
StreamPrintf(implFile, " ref = Malloc(sizeof(%s));\n", cType);
StreamPrintf(implFile, " if (!ref)\n");
StreamPrintf(implFile, " {\n");
StreamPrintf(implFile, " *errp = \"Unable to allocate memory for object value.\";\n");
StreamPrintf(implFile, " return false;\n");
StreamPrintf(implFile, " }\n");
StreamPrintf(implFile, " *ref = JsonValueAs%s(v);\n", fieldType);
StreamPrintf(implFile, " HashMapSet(out->%s, objKey, ref);\n", key);
*fieldType = tolower(*fieldType);
}
else if (StrEquals(fieldType, "string"))
{
StreamPrintf(implFile, " if (JsonValueType(v) != %s)\n", JsonTypeToStr(jsonType));
StreamPrintf(implFile, " {\n");
StreamPrintf(implFile, " *errp = \"%s.%s[] contains an invalid value.\";\n", type, key);
StreamPrintf(implFile, " return false;\n");
StreamPrintf(implFile, " }\n");
StreamPrintf(implFile, " HashMapSet(out->%s, objKey, StrDuplicate(JsonValueAsString(v)));\n", key);
}
else if (StrEquals(fieldType, "object"))
{
StreamPrintf(implFile, " if (JsonValueType(v) != %s)\n", JsonTypeToStr(jsonType));
StreamPrintf(implFile, " {\n");
StreamPrintf(implFile, " *errp = \"%s.%s[] contains an invalid value.\";\n", type, key);
StreamPrintf(implFile, " return false;\n");
StreamPrintf(implFile, " }\n");
StreamPrintf(implFile, " HashMapSet(out->%s, objKey, JsonDuplicate(JsonValueAsObject(v)));\n", key);
}
else
{
if (isEnum)
{
StreamPrintf(implFile, " int parseResult;\n");
}
StreamPrintf(implFile, " %s *parsed;\n", fieldType);
StreamPrintf(implFile, " if (JsonValueType(v) != %s)\n", JsonTypeToStr(jsonType));
StreamPrintf(implFile, " {\n");
StreamPrintf(implFile, " *errp = \"%s.%s[] contains an invalid value.\";\n", type, key);
StreamPrintf(implFile, " return false;\n");
StreamPrintf(implFile, " }\n");
StreamPrintf(implFile, " parsed = Malloc(sizeof(%s));\n", fieldType);
StreamPrintf(implFile, " if (!parsed)\n");
StreamPrintf(implFile, " {\n");
StreamPrintf(implFile, " *errp = \"Unable to allocate memory for array value.\";\n");
StreamPrintf(implFile, " return false;\n");
StreamPrintf(implFile, " }\n");
if (isEnum)
{
StreamPrintf(implFile, " parseResult = %sFromStr(JsonValueAsString(v));\n", fieldType);
StreamPrintf(implFile, " *parsed = parseResult;\n");
StreamPrintf(implFile, " if (parseResult == -1)\n");
}
else
{
StreamPrintf(implFile, " if (!%sFromJson(JsonValueAsObject(v), parsed, errp))\n", fieldType);
}
StreamPrintf(implFile, " {\n");
if (!isEnum)
{
StreamPrintf(implFile, " %sFree(parsed);\n", fieldType);
}
StreamPrintf(implFile, " Free(parsed);\n");
StreamPrintf(implFile, " return false;\n");
StreamPrintf(implFile, " }\n");
StreamPrintf(implFile, " HashMapSet(out->%s, objKey, parsed);\n", key);
}
StreamPrintf(implFile, " }\n");
StreamPrintf(implFile, " }\n");
fieldType[strlen(fieldType)] = '}';
}
else if (IsDelimited(fieldType, '[', ']'))
{
fieldType++;
fieldType[strlen(fieldType) - 1] = '\0';
@ -915,7 +1073,73 @@ Main(Array * args)
{
StreamPrintf(implFile, " HashMapSet(json, \"%s\", JsonValueObject(JsonDuplicate(val->%s)));\n", Trim('_', key), key);
}
else if (*fieldType == '[' && fieldType[strlen(fieldType) - 1] == ']')
else if (IsDelimited(fieldType, '{', '}'))
{
int isPrimitive;
fieldType++;
fieldType[strlen(fieldType) - 1] = '\0';
isEnum = StrEquals(JsonValueAsString(JsonGet(types, 2, fieldType, "type")), "enum");
isPrimitive = StrEquals(fieldType, "integer") ||
StrEquals(fieldType, "boolean") ||
StrEquals(fieldType, "float");
StreamPrintf(implFile, " if (val->%s)\n", key);
StreamPrintf(implFile, " {\n");
StreamPrintf(implFile, " char *objKey;\n");
StreamPrintf(implFile, " void *objVal;\n");
StreamPrintf(implFile, " HashMap *jsonObj = HashMapCreate();\n");
StreamPrintf(implFile, " if (!jsonObj)\n");
StreamPrintf(implFile, " {\n");
StreamPrintf(implFile, " JsonFree(json);\n");
StreamPrintf(implFile, " return NULL;\n");
StreamPrintf(implFile, " }\n");
StreamPrintf(implFile, " while (HashMapIterate(val->%s, &objKey, &objVal))\n", key);
StreamPrintf(implFile, " {\n");
if (StrEquals(fieldType, "string"))
{
StreamPrintf(implFile, " HashMapSet(jsonObj, objKey, JsonValueString(objVal));\n", key);
}
else if (!isPrimitive)
{
StreamPrintf(implFile, " HashMapSet(jsonObj, objKey, JsonValueObject(%sToJson(objVal)));\n", fieldType, key);
}
else
{
char *cType;
if (StrEquals(fieldType, "integer"))
{
cType = "int64_t";
}
else if (StrEquals(fieldType, "float"))
{
cType = "double";
}
else if (StrEquals(fieldType, "boolean"))
{
cType = "bool";
}
else
{
/* Should never happen */
cType = NULL;
}
*fieldType = toupper(*fieldType);
StreamPrintf(implFile, " HashMapSet(jsonObj, objKey, (JsonValue%s(*((%s *) objVal))));\n", fieldType, cType, key);
*fieldType = tolower(*fieldType);
}
StreamPrintf(implFile, " }\n");
StreamPrintf(implFile, " HashMapSet(json, \"%s\", JsonValueObject(jsonObj));\n", Trim('_', key));
StreamPrintf(implFile, " }\n");
fieldType[strlen(fieldType)] = '}';
}
else if (IsDelimited(fieldType, '[', ']'))
{
int isPrimitive;
@ -1036,7 +1260,36 @@ Main(Array * args)
{
StreamPrintf(implFile, " Free(val->%s);\n", key);
}
else if (*fieldType == '[' && fieldType[strlen(fieldType) - 1] == ']')
else if (IsDelimited(fieldType, '{', '}'))
{
int isPrimitive;
fieldType++;
fieldType[strlen(fieldType) - 1] = '\0';
isEnum = StrEquals(JsonValueAsString(JsonGet(types, 2, fieldType, "type")), "enum");
isPrimitive = StrEquals(fieldType, "boolean") ||
StrEquals(fieldType, "float") ||
StrEquals(fieldType, "integer") ||
StrEquals(fieldType, "string");
StreamPrintf(implFile, " if (val->%s)\n", key);
StreamPrintf(implFile, " {\n");
StreamPrintf(implFile, " char *objKey;\n");
StreamPrintf(implFile, " void *objVal;\n");
StreamPrintf(implFile, " while (HashMapIterate(val->%s, &objKey, &objVal))\n", key);
StreamPrintf(implFile, " {\n");
StreamPrintf(implFile, " %sFree(objVal);\n", (!isEnum && !isPrimitive) ? fieldType : "", key);
if (!isEnum && !isPrimitive)
{
StreamPrintf(implFile, " Free(objVal);\n", key);
}
StreamPrintf(implFile, " }\n");
StreamPrintf(implFile, " HashMapFree(val->%s);\n", key);
StreamPrintf(implFile, " }\n");
fieldType[strlen(fieldType)] = '}';
}
else if (IsDelimited(fieldType, '[', ']'))
{
int isPrimitive;