From: <sv...@ww...> - 2006-06-01 06:47:54
|
Author: mkrose Date: 2006-05-31 23:47:42 -0700 (Wed, 31 May 2006) New Revision: 1949 Modified: trunk/csp/__init__.py trunk/csp/csplib/data/Link.cpp trunk/csp/csplib/util/StringTools.cpp trunk/csp/csplib/util/Trace.cpp trunk/csp/csplib/util/Uniform.h trunk/csp/cspsim/f16/MultiFunctionDisplay.cpp Log: Various fixes for amd64 compilation errors under gcc. Also patch __init__.py to try setting dlopenflags even if the dl module isn't found. The latter probably won't help but shouldn't hurt. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1949 Modified: trunk/csp/__init__.py =================================================================== --- trunk/csp/__init__.py 2006-05-31 04:23:27 UTC (rev 1948) +++ trunk/csp/__init__.py 2006-06-01 06:47:42 UTC (rev 1949) @@ -23,12 +23,19 @@ def _configureModules(): if os.name == 'posix': + # 0x101 is fairly standard, but try to load the correct values from + # the dl module if available. + GLOBAL_AND_LAZY = 0x101 try: import dl + GLOBAL_AND_LAZY = dl.RTLD_GLOBAL|dl.RTLD_LAZY + except ImportError: + sys.stderr.write('warning: import dl failed; assuming standard dl flags\n') + try: # enable lazy loading of shared library modules if available. - sys.setdlopenflags(dl.RTLD_GLOBAL|dl.RTLD_LAZY) - except ImportError: - sys.stderr.write('import dl failed; lazy module loading not enabled.\n') + sys.setdlopenflags(GLOBAL_AND_LAZY) + except: + sys.stderr.write('warning: setdlopenflags failed; lazy module loading not enabled.\n') else: # if CSPDEVPACK is defined in the environment, add the devpack bin # directory to the execution path. this ensures that devpack libraries Modified: trunk/csp/csplib/data/Link.cpp =================================================================== --- trunk/csp/csplib/data/Link.cpp 2006-05-31 04:23:27 UTC (rev 1948) +++ trunk/csp/csplib/data/Link.cpp 2006-06-01 06:47:42 UTC (rev 1949) @@ -141,7 +141,7 @@ */ assert(_ppb.valid()); Object *obj = _ppb._reference; - CSPLOG(DEBUG, ARCHIVE) << "loaded " << obj->getClassName() << " @ 0x" << std::hex << reinterpret_cast<int>(obj); + CSPLOG(DEBUG, ARCHIVE) << "loaded " << obj->getClassName() << " @ " << obj; return _ppb; } Modified: trunk/csp/csplib/util/StringTools.cpp =================================================================== --- trunk/csp/csplib/util/StringTools.cpp 2006-05-31 04:23:27 UTC (rev 1948) +++ trunk/csp/csplib/util/StringTools.cpp 2006-06-01 06:47:42 UTC (rev 1949) @@ -254,11 +254,8 @@ return formatIntegerType<int64>(out, spec, x_val.ui64, false, base, lower); } case TYPE_PTR: { - if (sizeof(void*) == sizeof(unsigned)) { - return formatIntegerType<unsigned>(out, spec, reinterpret_cast<unsigned>(x_val.p), false, base, lower); - } else { - return formatIntegerType<uint64>(out, spec, reinterpret_cast<uint64>(x_val.p), false, base, lower); - } + uintptr_t val = alias_cast<uintptr_t>(x_val.p); + return formatIntegerType<uintptr_t>(out, spec, val, false, base, lower); } default: return false; Modified: trunk/csp/csplib/util/Trace.cpp =================================================================== --- trunk/csp/csplib/util/Trace.cpp 2006-05-31 04:23:27 UTC (rev 1948) +++ trunk/csp/csplib/util/Trace.cpp 2006-06-01 06:47:42 UTC (rev 1949) @@ -91,9 +91,9 @@ for (int i = _skip; i < _stack_depth; ++i) { Dl_info info; if (dladdr(_trace[i], &info) != 0) { - const int addr = reinterpret_cast<int>(_trace[i]); - const int sofs = addr - reinterpret_cast<int>(info.dli_saddr); - const int bofs = addr - reinterpret_cast<int>(info.dli_fbase); + const uintptr_t addr = alias_cast<uintptr_t>(_trace[i]); + const uintptr_t sofs = addr - alias_cast<uintptr_t>(info.dli_saddr); + const uintptr_t bofs = addr - alias_cast<uintptr_t>(info.dli_fbase); if (!info.dli_fname) info.dli_fname = "??"; if (!info.dli_sname) info.dli_sname = ""; os << std::hex Modified: trunk/csp/csplib/util/Uniform.h =================================================================== --- trunk/csp/csplib/util/Uniform.h 2006-05-31 04:23:27 UTC (rev 1948) +++ trunk/csp/csplib/util/Uniform.h 2006-06-01 06:47:42 UTC (rev 1949) @@ -28,6 +28,8 @@ #include <csp/csplib/util/Config.h> #include <csp/csplib/util/Namespace.h> +#include <cstring> // for memcpy + CSP_NAMESPACE @@ -90,6 +92,25 @@ # define CSP_UNUSED #endif +/* Borrow a minimal version of Boost's STATIC_ASSERT mechanism. + */ +template <bool> struct static_assert_failure; +template <> struct static_assert_failure<true> {}; +template <int> struct static_assert_test {}; +#define CSP_STATIC_ASSERT(expr) \ + typedef static_assert_test<sizeof(static_assert_failure<(bool)(expr)>)> static_assertion_##__LINE__ + +/* Portable cast operator for type-punning. Optimizes extremely well + * under gcc; haven't checked msvc assembly though. + */ +template <typename T1, typename T2> +inline T1 alias_cast(T2 src) { + CSP_STATIC_ASSERT(sizeof(T1) == sizeof(T2)); + T1 dst; + std::memcpy(&dst, &src, sizeof(dst)); + return dst; +} + //@} CSP_NAMESPACE_END Modified: trunk/csp/cspsim/f16/MultiFunctionDisplay.cpp =================================================================== --- trunk/csp/cspsim/f16/MultiFunctionDisplay.cpp 2006-05-31 04:23:27 UTC (rev 1948) +++ trunk/csp/cspsim/f16/MultiFunctionDisplay.cpp 2006-06-01 06:47:42 UTC (rev 1949) @@ -223,7 +223,7 @@ void DisplayText::setText(std::string const &text, bool invert) { TokenQueue tokens(text, "\n"); m_Lines.reserve(tokens.size()); - unsigned widest = 0; + size_t widest = 0; for (unsigned i = 0; i < tokens.size(); ++i) { widest = std::max(tokens[i].size(), widest); display::ElementText *text = (i < m_Lines.size()) ? m_Lines[i].get() : 0; |