[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

patch for compiling cmocka with sdcc


Hi

I wanted to compile cmocka with sdcc, but sdcc does not support
assignment of values to aggregates, so I patched cmocka to remove the
three occurrences of it. This is the first attached patch.

Also I removed a cast from a const variable where it was easy to keep it
const. This is in the second patch and is completely optional. Sdcc
warns about one other occurrence of this, but that is not that easy to
remove.

Kind regards,
Adrian


The information in this email may be confidential and/or legally privileged. It has been sent for the sole use of the intended recipient(s). If you are not an intended recipient, you are strictly prohibited from reading, disclosing, distributing, copying or using this email or any of its contents, in any way whatsoever. If you have received this email in error, please contact the sender by reply email and destroy all copies of the original message. Please also be advised that emails are not a secure form for communication, and may contain errors.
From 887e8a249bbbee6d6ea1efd78132f19329f48822 Mon Sep 17 00:00:00 2001
From: Adrian Friedli <adrian.friedli@xxxxxxxxxxxxxxxxxx>
Date: Thu, 15 Jun 2017 17:28:36 +0200
Subject: [PATCH 1/2] allow compiling with sdcc

sdcc does not support assignment of values to aggregates.
---
 src/cmocka.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/cmocka.c b/src/cmocka.c
index f02e412..3ada1e6 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -885,7 +885,8 @@ LargestIntegralType _mock(const char * const function, const char* const file,
     if (rc) {
         SymbolValue * const symbol = (SymbolValue*)result;
         const LargestIntegralType value = symbol->value;
-        global_last_mock_value_location = symbol->location;
+        global_last_mock_value_location.file = symbol->location.file;
+        global_last_mock_value_location.line = symbol->location.line;
         if (rc == 1) {
             free(symbol);
         }
@@ -1533,7 +1534,8 @@ void _check_expected(
     if (rc) {
         CheckParameterEvent * const check = (CheckParameterEvent*)result;
         int check_succeeded;
-        global_last_parameter_location = check->location;
+        global_last_parameter_location.file = check->location.file;
+        global_last_parameter_location.line = check->location.line;
         check_succeeded = check->check_value(value, check->check_value_data);
         if (rc == 1) {
             free(check);
@@ -2800,11 +2802,13 @@ int _cmocka_run_group_tests(const char *group_name,
             (tests[i].test_func != NULL
              || tests[i].setup_func != NULL
              || tests[i].teardown_func != NULL)) {
-            cm_tests[i] = (struct CMUnitTestState) {
-                .test = &tests[i],
-                .status = CM_TEST_NOT_STARTED,
-                .state = NULL,
-            };
+            struct CMUnitTestState *cmtest = &cm_tests[i];
+            cmtest->check_point = NULL;
+            cmtest->test = &tests[i];
+            cmtest->state = NULL;
+            cmtest->error_message = NULL;
+            cmtest->status = CM_TEST_NOT_STARTED;
+            cmtest->runtime = 0;
             total_tests++;
         }
     }
-- 
2.11.0

From a71c60a746b3d80a8bad037f4ed3befb5b9a5431 Mon Sep 17 00:00:00 2001
From: Adrian Friedli <adrian.friedli@xxxxxxxxxxxxxxxxxx>
Date: Wed, 21 Jun 2017 16:54:10 +0200
Subject: [PATCH 2/2] remove cast from const in get_symbol_value

---
 src/cmocka.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/cmocka.c b/src/cmocka.c
index 3ada1e6..b6af8a7 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -237,7 +237,7 @@ static void add_symbol_value(
     const size_t number_of_symbol_names, const void* value, const int count);
 static int get_symbol_value(
     ListNode * const symbol_map_head, const char * const symbol_names[],
-    const size_t number_of_symbol_names, void **output);
+    const size_t number_of_symbol_names, const void **output);
 static void free_value(const void *value, void *cleanup_value_data);
 static void free_symbol_map_value(
     const void *value, void *cleanup_value_data);
@@ -707,7 +707,7 @@ static void add_symbol_value(ListNode * const symbol_map_head,
  */
 static int get_symbol_value(
         ListNode * const head, const char * const symbol_names[],
-        const size_t number_of_symbol_names, void **output) {
+        const size_t number_of_symbol_names, const void **output) {
     const char* symbol_name;
     ListNode *target_node;
     assert_non_null(head);
@@ -730,7 +730,7 @@ static int get_symbol_value(
             ListNode *value_node = NULL;
             return_value = list_first(child_list, &value_node);
             assert_true(return_value);
-            *output = (void*) value_node->value;
+            *output = value_node->value;
             return_value = value_node->refcount;
             if (value_node->refcount - 1 == 0) {
                 list_remove_free(value_node, NULL, NULL);
@@ -879,7 +879,7 @@ static int check_for_leftover_values(
 /* Get the next return value for the specified mock function. */
 LargestIntegralType _mock(const char * const function, const char* const file,
                           const int line) {
-    void *result;
+    const void *result;
     const int rc = get_symbol_value(&global_function_result_map_head,
                                     &function, 1, &result);
     if (rc) {
@@ -1527,7 +1527,7 @@ void _expect_any(
 void _check_expected(
         const char * const function_name, const char * const parameter_name,
         const char* file, const int line, const LargestIntegralType value) {
-    void *result;
+    const void *result;
     const char* symbols[] = {function_name, parameter_name};
     const int rc = get_symbol_value(&global_function_parameter_map_head,
                                     symbols, 2, &result);
-- 
2.11.0


Follow-Ups:
Re: patch for compiling cmocka with sdccAdrian Friedli <adrian.friedli@xxxxxxxxxxxxxxxxxx>
Re: patch for compiling cmocka with sdccAndreas Schneider <asn@xxxxxxxxxxxxxx>