Skip to content

Commit

Permalink
Some more review improvements + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Meisrimel authored and Peter Meisrimel committed Aug 1, 2024
1 parent 1c7bdfe commit 6647b64
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Config.cmake/test_fmi2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ set_target_properties(
set(FAIL_NAME_CHECK 0)
set(PASS_NAME_CHECK 1)

add_test(ctest_fmi2_xml_parsing_test fmi2_xml_parsing_test ${FMI2_TEST_XML_DIR}/)
add_test(ctest_fmi2_xml_parsing_test fmi2_xml_parsing_test ${FMI2_TEST_XML_DIR}/) # Trailing '/' necessary (for building system independent path)
add_test(ctest_fmi2_import_xml_test_brief fmi2_import_xml_test ${FMU2_DUMMY_FOLDER}) # 'brief' as in close to minimal XML
add_test(ctest_fmi2_import_xml_test_me fmi2_import_xml_test ${TEST_OUTPUT_FOLDER}/BouncingBall2_me)
add_test(ctest_fmi2_import_xml_test_cs fmi2_import_xml_test ${TEST_OUTPUT_FOLDER}/BouncingBall2_cs)
Expand Down
3 changes: 3 additions & 0 deletions Test/fmi_testutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ extern "C" {
else if (strcmp(S1, S2) != 0) { FAIL(S1 << " != " << S2); } \
} while (0);

// XXX: Currently cotains duplicated code for FMI 2 & 3 (also in fmi_testutil.c)
// Could replace via macros

typedef struct fmi2_testutil_import_t {
fmi2_import_t* fmu;
jm_vector(jm_voidp) log; // All logged messages
Expand Down
58 changes: 29 additions & 29 deletions src/XML/src/FMI3/fmi3_xml_vendor_annotations.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ static const char* module = "FMI3XML";
int fmi3_xml_handle_VendorAnnotations(fmi3_xml_parser_context_t *context, const char* data) {
if(!data) {
jm_log_verbose(context->callbacks, module, "Parsing XML element VendorAnnotations");
}
else {
} else {
/* might give out a warning if(data[0] != 0) */
}
return 0;
Expand All @@ -34,39 +33,39 @@ int fmi3_xml_handle_VendorAnnotations(fmi3_xml_parser_context_t *context, const
int fmi3_xml_handle_Annotations(fmi3_xml_parser_context_t *context, const char* data) {
if(!data) {
jm_log_verbose(context->callbacks, module, "Parsing XML element Annotations");
}
else {
} else {
/* might give out a warning if(data[0] != 0) */
}
return 0;
}

int fmi3_xml_handle_VariableTool(fmi3_xml_parser_context_t *context, const char* data) {
if(!data) {
size_t len;
fmi3_xml_model_description_t* md = context->modelDescription;
jm_vector(char)* bufName = fmi3_xml_reserve_parse_buffer(context,1,100);
jm_string *pvendor;
char* vendor = 0;

if(!bufName) return -1;
/* <xs:attribute name="name" type="xs:normalizedString" use="required"> */
if( fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_Tool, fmi_attr_id_name, 1, bufName))
return -1;
pvendor = jm_vector_push_back(jm_string)(&md->vendorList, vendor);
len = jm_vector_get_size(char)(bufName);
if(pvendor )
*pvendor = vendor = (char*)(context->callbacks->malloc(len + 1));
if(!pvendor || !vendor) {
fmi3_xml_parse_fatal(context, "Could not allocate memory");
return -1;
}
memcpy(vendor, jm_vector_get_itemp(char)(bufName,0), len);
vendor[len] = 0;

context->anyToolName = vendor;
context->anyParent = jm_vector_get_last(jm_voidp)(&md->variablesOrigOrder);
context->useAnyHandleFlg = 1;
size_t len;
fmi3_xml_model_description_t* md = context->modelDescription;
jm_vector(char)* bufName = fmi3_xml_reserve_parse_buffer(context,1,100);
jm_string *pvendor;
char* vendor = 0;

if(!bufName) return -1;
/* <xs:attribute name="name" type="xs:normalizedString" use="required"> */
if( fmi3_xml_parse_attr_as_string(context, fmi3_xml_elmID_Tool, fmi_attr_id_name, 1, bufName))
return -1;
pvendor = jm_vector_push_back(jm_string)(&md->vendorList, vendor);
len = jm_vector_get_size(char)(bufName);
if (pvendor) {
*pvendor = vendor = (char*)(context->callbacks->malloc(len + 1));
}
if (!pvendor || !vendor) {
fmi3_xml_parse_fatal(context, "Could not allocate memory");
return -1;
}
memcpy(vendor, jm_vector_get_itemp(char)(bufName,0), len);
vendor[len] = 0;

context->anyToolName = vendor;
context->anyParent = jm_vector_get_last(jm_voidp)(&md->variablesOrigOrder);
context->useAnyHandleFlg = 1;
}
else {
/* don't do anything. might give out a warning if(data[0] != 0) */
Expand All @@ -90,8 +89,9 @@ int fmi3_xml_handle_Tool(fmi3_xml_parser_context_t *context, const char* data) {
return -1;
pvendor = jm_vector_push_back(jm_string)(&md->vendorList, vendor);
len = jm_vector_get_size(char)(bufName);
if (pvendor)
if (pvendor) {
*pvendor = vendor = (char*)(context->callbacks->malloc(len + 1));
}
if (!pvendor || !vendor) {
fmi3_xml_parse_fatal(context, "Could not allocate memory");
return -1;
Expand Down

0 comments on commit 6647b64

Please sign in to comment.