Skip to content

Commit

Permalink
Some early return fixes and documentation improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
PengZheng committed Jan 31, 2024
1 parent ca7dab2 commit 90d643a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 35 deletions.
8 changes: 4 additions & 4 deletions libs/dfi/include/dyn_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ typedef struct _dyn_interface_type dyn_interface_type;

TAILQ_HEAD(methods_head, method_entry);
struct method_entry {
int index;
char* id;
dyn_function_type* dynFunc;
int index; ///< The index of the method in the interface
char* id; ///< The signature of the method
dyn_function_type* dynFunc; ///< The function type of the method

TAILQ_ENTRY(method_entry) entries;
};
Expand Down Expand Up @@ -141,7 +141,7 @@ CELIX_DFI_EXPORT int dynInterface_nrOfMethods(const dyn_interface_type* intf);
* The dynamic interface type instance is the owner of the returned method_entry structure and it should not be freed.
*
* @param[in] intf The dynamic interface type instance.
* @param[in] id The id of the method to find.
* @param[in] id The id of the method to find, which is currently the signature of the method.
* @return The method_entry structure for the given method id, or NULL if no matching method is found.
*/
CELIX_DFI_EXPORT const struct method_entry* dynInterface_findMethod(const dyn_interface_type* intf, const char* id);
Expand Down
30 changes: 14 additions & 16 deletions libs/dfi/src/dyn_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,20 @@ static int dynCommon_parseNameValue(FILE* stream, char** outName, char** outValu
int status;
celix_autofree char* name = NULL;
celix_autofree char* value = NULL;
do {
if ((status = dynCommon_parseName(stream, &name)) != OK) {
break;
}
if ((status = dynCommon_eatChar(stream, '=')) != OK) {
break;
}
const char *valueAcceptedChars = ".<>{}[]?;:~!@#$%^&*()_+-=,./\\'\"";
//NOTE use different more lenient function e.g. only stop at '\n' ?
if ((status = dynCommon_parseNameAlsoAccept(stream, valueAcceptedChars, &value)) != OK) {
break;
}
*outName = celix_steal_ptr(name);
*outValue = celix_steal_ptr(value);
} while(false);
return status;
if ((status = dynCommon_parseName(stream, &name)) != OK) {
return status;
}
if ((status = dynCommon_eatChar(stream, '=')) != OK) {
return status;
}
const char *valueAcceptedChars = ".<>{}[]?;:~!@#$%^&*()_+-=,./\\'\"";
//NOTE use different more lenient function e.g. only stop at '\n' ?
if ((status = dynCommon_parseNameAlsoAccept(stream, valueAcceptedChars, &value)) != OK) {
return status;
}
*outName = celix_steal_ptr(name);
*outValue = celix_steal_ptr(value);
return OK;
}

int dynCommon_eatChar(FILE* stream, int expected) {
Expand Down
22 changes: 7 additions & 15 deletions libs/dfi/src/dyn_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ static int dynType_parseAny(FILE* stream, dyn_type* type) {
status = dynType_parseMetaInfo(stream, type);
if (status == OK) {
status = dynType_parseAny(stream, type);
} else {
celix_err_push("Failed to parse meta properties");
}
break;
default :
Expand All @@ -188,39 +190,29 @@ static int dynType_parseAny(FILE* stream, dyn_type* type) {
}

static int dynType_parseMetaInfo(FILE* stream, dyn_type* type) {
int status = OK;
celix_autofree char* name = NULL;
celix_autofree char* value = NULL;

if (dynCommon_parseName(stream, &name) != OK) {
status = PARSE_ERROR;
goto bail_out;
return PARSE_ERROR;
}
if (dynCommon_eatChar(stream, '=') != OK) {
status = PARSE_ERROR;
goto bail_out;
return PARSE_ERROR;
}
if (dynCommon_parseName(stream, &value) != OK) {
status = PARSE_ERROR;
goto bail_out;
return PARSE_ERROR;
}
if (dynCommon_eatChar(stream, ';') != OK) {
status = PARSE_ERROR;
goto bail_out;
return PARSE_ERROR;
}
struct meta_entry *entry = calloc(1, sizeof(*entry));
if (entry == NULL) {
status = MEM_ERROR;
goto bail_out;
return MEM_ERROR;
}
entry->name = celix_steal_ptr(name);
entry->value = celix_steal_ptr(value);
TAILQ_INSERT_TAIL(&type->metaProperties, entry, entries);
return OK;

bail_out:
celix_err_push("Failed to parse meta properties");
return status;
}

static int dynType_parseText(FILE* stream, dyn_type* type) {
Expand Down

0 comments on commit 90d643a

Please sign in to comment.