From 98ef10d257ed9db2f5fba00dd30a06643f857a72 Mon Sep 17 00:00:00 2001
From: "Dmitriy A. Gerasimov" <dmitriy.gerasimov@demlabs.net>
Date: Wed, 13 May 2020 14:51:00 +0700
Subject: [PATCH] [*] Fixes for platforms without 128 int

---
 CMakeLists.txt                            |  2 +-
 dap-sdk/core/include/dap_math_ops.h       | 12 ++++++++----
 dap-sdk/core/libdap.pri                   |  4 ++--
 modules/common/include/dap_chain_common.h | 12 +++++++++++-
 4 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 88ef2c6dcd..a5a304ef07 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,7 @@ project(cellframe-sdk C)
 cmake_minimum_required(VERSION 2.8)
 
 set(CMAKE_C_STANDARD 11)
-set(CELLFRAME_SDK_NATIVE_VERSION "2.3-2")
+set(CELLFRAME_SDK_NATIVE_VERSION "2.3-3")
 add_definitions ("-DCELLFRAME_SDK_VERSION=\"${CELLFRAME_SDK_NATIVE_VERSION}\"")
 
 set(DAPSDK_MODULES "")
diff --git a/dap-sdk/core/include/dap_math_ops.h b/dap-sdk/core/include/dap_math_ops.h
index 4d88dbcfb8..d67bad88e1 100755
--- a/dap-sdk/core/include/dap_math_ops.h
+++ b/dap-sdk/core/include/dap_math_ops.h
@@ -1,5 +1,6 @@
 #pragma once
 #include <stdint.h>
+
 #include "dap_common.h"
 //#include "common/int-util.h"
 
@@ -12,18 +13,21 @@ typedef __int128 _dap_int128_t;
 
 #if !defined (int128_t)
 typedef __int128 int128_t;
-#else
-typedef unsigned int64_t[2] int128_t;
 #endif
 
 #if !defined (uint128_t)
 typedef unsigned __int128 uint128_t;
-#else
-typedef unsigned uint64_t[2] uint128_t;
 #endif
 
+#endif
+
+#if __SIZEOF_INT128__ != 16
+typedef union uint128{uint64_t u64[2];} uint128_t;
+typedef union int128{int64_t i64[2];} int128_t;
 
 #endif
+
+
 #endif
 
 typedef union dap_uint128{
diff --git a/dap-sdk/core/libdap.pri b/dap-sdk/core/libdap.pri
index bf87862a3c..8aa16a0fa3 100755
--- a/dap-sdk/core/libdap.pri
+++ b/dap-sdk/core/libdap.pri
@@ -1,5 +1,5 @@
-QMAKE_CFLAGS_DEBUG = -std=gnu11
-QMAKE_CFLAGS_RELEASE = -std=gnu11
+QMAKE_CFLAGS_DEBUG = -std=gnu11  -fforce-enable-int128
+QMAKE_CFLAGS_RELEASE = -std=gnu11  -fforce-enable-int128
 unix {
     include(src/unix/unix.pri)
     DEFINES += DAP_OS_UNIX
diff --git a/modules/common/include/dap_chain_common.h b/modules/common/include/dap_chain_common.h
index 059855fbfe..c2b2d7651c 100644
--- a/modules/common/include/dap_chain_common.h
+++ b/modules/common/include/dap_chain_common.h
@@ -210,11 +210,21 @@ void dap_chain_addr_fill(dap_chain_addr_t *a_addr, dap_enc_key_t *a_key, dap_cha
 int dap_chain_addr_check_sum(const dap_chain_addr_t *a_addr);
 
 static inline long double dap_chain_balance_to_coins( uint128_t a_balance){
-    return (long double) a_balance / DATOSHI_LD;
+#ifdef DAP_GLOBAL_IS_INT128
+        return (long double) a_balance / DATOSHI_LD;
+#else
+    return (long double)   (a_balance.u64[0] / DATOSHI_LD);
+#endif
 }
 
 static inline uint128_t dap_chain_coins_to_balance( long double a_balance){
+#ifdef DAP_GLOBAL_IS_INT128
     return (uint128_t)( a_balance * DATOSHI_LD) ;
+#else
+    uint128_t l_ret={0};
+    l_ret.u64[0]=a_balance *DATOSHI_LD;
+    return l_ret;
+#endif
 }
 
 /**
-- 
GitLab