From 800d3210040b2f7bfda185760e54e46c2d00b186 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 6 Sep 2015 21:20:19 -0500 Subject: [PATCH] Moved toward elimination of shared library usages. --- CMakeLists.txt | 2 ++ src/memfs.cpp | 17 +++++++++++++---- src/memfs.hpp | 4 ++-- src/types.hpp | 8 ++++++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc44e4158..b4551eeca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,8 @@ add_definitions( -Wall -Wsign-compare -nostdlib + -fno-exceptions + -fno-rtti #-Werror #--analyze #-Os # GCC size optimization flag diff --git a/src/memfs.cpp b/src/memfs.cpp index 4469a20f0..9465e6d76 100644 --- a/src/memfs.cpp +++ b/src/memfs.cpp @@ -5,7 +5,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include +#include #include "_memops.hpp" #include "memfs.hpp" @@ -28,9 +28,18 @@ void MemFs::Record::setData(uint8_t *data, int size) { m_data = size; } -MemFs::MemFs(uint8_t *begin, uint8_t *end): m_version(*((uint32_t*) begin)), m_lastRec(*(MemFsPtr*) (begin + sizeof(m_version))) { - if (version != m_version) { - throw "MemFs version mismatch"; + +// MemFs + +MemFs::MemFs(uint8_t *begin, uint8_t *end, uint32_t *error): m_version(*((uint32_t*) begin)), m_lastRec(*(MemFsPtr*) (begin + sizeof(m_version))) { + if (error) { + if (version != m_version) { + // version mismatch + *error = 1; + } else { + // ok + *error = 0; + } } m_begin = begin; m_end = end; diff --git a/src/memfs.hpp b/src/memfs.hpp index 5aa81c605..8c1e2a49a 100644 --- a/src/memfs.hpp +++ b/src/memfs.hpp @@ -8,7 +8,6 @@ #ifndef MEMPHIS_MEMFS_HPP #define MEMPHIS_MEMFS_HPP -#include #include "types.hpp" namespace memphis { @@ -46,8 +45,9 @@ class MemFs { * Constructor * @param begin pointer to the beginning of this MemFs's memory chunk * @param end pointer to the end of this MemFs's memory chunk + * @param error pointer to a integer return errors into */ - MemFs(uint8_t *begin, uint8_t *end); + MemFs(uint8_t *begin, uint8_t *end, uint32_t *error = nullptr); /** * Initializes the memory chunk of this MemFs was given. diff --git a/src/types.hpp b/src/types.hpp index dcdc8861a..7c94635f8 100644 --- a/src/types.hpp +++ b/src/types.hpp @@ -15,10 +15,18 @@ typedef unsigned char uint8_t; typedef short int16_t; typedef unsigned short uint16_t; typedef int int32_t; +typedef unsigned int uint32_t; typedef unsigned uint_t; typedef long long int64_t; typedef unsigned long long uint64_t; +#ifdef _LP64 +typedef uint64_t size_t; +#elif _LP32 +typedef uint32_t size_t; +#endif + + } #endif