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

Re: patch for compiling cmocka with sdcc


Hi

I edited the first patch, it is now future proof to changes in the
struct content.

Regards,
Adrian


On 06/26/17 18:31, Adrian Friedli wrote:
> 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 9692dbd0fc9f18a951da0d5e4290c6e6cfc7f741 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 | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/cmocka.c b/src/cmocka.c
index f02e412..bac4009 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -885,7 +885,7 @@ 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;
+        memcpy(&global_last_mock_value_location, &symbol->location, sizeof(global_last_mock_value_location));
         if (rc == 1) {
             free(symbol);
         }
@@ -1533,7 +1533,7 @@ void _check_expected(
     if (rc) {
         CheckParameterEvent * const check = (CheckParameterEvent*)result;
         int check_succeeded;
-        global_last_parameter_location = check->location;
+        memcpy(&global_last_parameter_location, &check->location, sizeof(global_last_parameter_location));
         check_succeeded = check->check_value(value, check->check_value_data);
         if (rc == 1) {
             free(check);
@@ -2800,11 +2800,12 @@ 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) {
+            struct CMUnitTestState cmtest = {
                 .test = &tests[i],
                 .status = CM_TEST_NOT_STARTED,
                 .state = NULL,
             };
+            memcpy(&cm_tests[i], &cmtest , sizeof(cm_tests[i]));
             total_tests++;
         }
     }
-- 
2.11.0


References:
patch for compiling cmocka with sdccAdrian Friedli <adrian.friedli@xxxxxxxxxxxxxxxxxx>