diff -Naur cara-1.9.1.5-base/CARA/AidaCentralAgent.cpp cara-1.9.1.5-mod/CARA/AidaCentralAgent.cpp --- cara-1.9.1.5-base/CARA/AidaCentralAgent.cpp 2016-01-11 05:13:52.000000000 -0600 +++ cara-1.9.1.5-mod/CARA/AidaCentralAgent.cpp 2016-05-12 11:27:54.254665010 -0500 @@ -873,7 +873,7 @@ str += " "; } Root::MessageLog::inst()->warning( "Import Atom List", str ); - str.sprintf( "The atom list contains %d spins which are already defined in project. " + str.sprintf( "The atom list contains %zu spins which are already defined in project. " "Continue anyway?", doubles.size() ); if( QMessageBox::warning( this, "Import Atom List", str, "&Import", "&Cancel", QString::null, 1, 1 ) != 0 ) @@ -999,7 +999,7 @@ str += " "; } Root::MessageLog::inst()->warning( "Import Atom List", str ); - str.sprintf( "%d spins could not be assigned to their spin system " + str.sprintf( "%zu spins could not be assigned to their spin system " "due to label uniqueness violation. Check message log for details.", doubles.size() ); QMessageBox::warning( this, "Import Atom List", diff -Naur cara-1.9.1.5-base/CARA/MonoScope.cpp cara-1.9.1.5-mod/CARA/MonoScope.cpp --- cara-1.9.1.5-base/CARA/MonoScope.cpp 2016-01-11 05:13:52.000000000 -0600 +++ cara-1.9.1.5-mod/CARA/MonoScope.cpp 2016-05-12 11:27:54.255665007 -0500 @@ -1121,7 +1121,7 @@ if( !res.empty() ) { Root::MessageLog::inst()->warning( "Report Degenerate Peaks", str.toLatin1() ); - str.sprintf( "The peaklist contains %d degenerate peaks. " + str.sprintf( "The peaklist contains %zu degenerate peaks. " "Check message log for details.", res.size() ); QMessageBox::information( getQt(), "Report Degenerate Peaks", str.toLatin1(), "&OK" ); }else diff -Naur cara-1.9.1.5-base/CARA/SingleAlignmentView.cpp cara-1.9.1.5-mod/CARA/SingleAlignmentView.cpp --- cara-1.9.1.5-base/CARA/SingleAlignmentView.cpp 2016-01-11 05:13:52.000000000 -0600 +++ cara-1.9.1.5-mod/CARA/SingleAlignmentView.cpp 2016-05-12 11:27:54.256665004 -0500 @@ -251,7 +251,7 @@ } } - g_temp.sprintf( "%d Matches out of %d possible", count, // d_ass->getMatchCount(), + g_temp.sprintf( "%d Matches out of %zu possible", count, // d_ass->getMatchCount(), d_ass->getBase()->getSeq()->getResi().size() - d_ass->getFragment().size() + 1 ); d_label->setText( g_temp ); // nein, neu Fixed: d_list->resizeColumnToContents( 0 ); diff -Naur cara-1.9.1.5-base/CARA/SpectrumListView.cpp cara-1.9.1.5-mod/CARA/SpectrumListView.cpp --- cara-1.9.1.5-base/CARA/SpectrumListView.cpp 2016-01-11 05:13:52.000000000 -0600 +++ cara-1.9.1.5-mod/CARA/SpectrumListView.cpp 2016-05-12 11:27:54.257665001 -0500 @@ -844,7 +844,7 @@ QString str; if( !ambig.empty() ) { - str.sprintf( "Cannot import. There are %d ambiguous shifts for " + str.sprintf( "Cannot import. There are %zu ambiguous shifts for " "the following atom numbers (see message log):\n", ambig.size() ); for( p3 = ambig.begin(); p3 != ambig.end(); ++p3 ) @@ -858,7 +858,7 @@ } if( !wrongColor.empty() ) { - str.sprintf( "Cannot import. The %d following atom numbers " + str.sprintf( "Cannot import. The %zu following atom numbers " "have another atom type than the referenced spin (see message log):\n", wrongColor.size() ); for( p3 = wrongColor.begin(); p3 != wrongColor.end(); ++p3 ) @@ -878,7 +878,7 @@ return false; // Cancel }else if( !ali.empty() ) { - str.sprintf( "Do you really want to import %d alias shifts? Cannot be undone!", ali.size() ); + str.sprintf( "Do you really want to import %zu alias shifts? Cannot be undone!", ali.size() ); if( QMessageBox::warning( w, "Import Alias Shifts", str, "&Import", "&Cancel", QString::null, 1, 1 ) != 0 ) return false; // Cancel }else @@ -953,7 +953,7 @@ QString str; if( !wrongColor.empty() ) { - str.sprintf( "Cannot import. The %d following atom numbers " + str.sprintf( "Cannot import. The %zu following atom numbers " "have another atom type than the referenced spin (see message log):\n", wrongColor.size() ); for( p3 = wrongColor.begin(); p3 != wrongColor.end(); ++p3 ) diff -Naur cara-1.9.1.5-base/Expat/xmlparse.cpp cara-1.9.1.5-mod/Expat/xmlparse.cpp --- cara-1.9.1.5-base/Expat/xmlparse.cpp 2015-07-13 11:20:58.000000000 -0500 +++ cara-1.9.1.5-mod/Expat/xmlparse.cpp 2016-05-12 11:27:54.259664995 -0500 @@ -6216,7 +6216,7 @@ XML_Content *ret; XML_Content *cpos; XML_Char * str; - int allocsize = (dtd->scaffCount * sizeof(XML_Content) + size_t allocsize = (dtd->scaffCount * sizeof(XML_Content) + (dtd->contentStringLen * sizeof(XML_Char))); ret = (XML_Content *)MALLOC(allocsize); diff -Naur cara-1.9.1.5-base/Lua/luaconf.h cara-1.9.1.5-mod/Lua/luaconf.h --- cara-1.9.1.5-base/Lua/luaconf.h 2008-02-11 10:25:08.000000000 -0600 +++ cara-1.9.1.5-mod/Lua/luaconf.h 2016-05-12 11:27:54.260664992 -0500 @@ -140,7 +140,7 @@ ** CHANGE that if ptrdiff_t is not adequate on your machine. (On most ** machines, ptrdiff_t gives a good choice between int or long.) */ -#define LUA_INTEGER ptrdiff_t +#define LUA_INTEGER int /* diff -Naur cara-1.9.1.5-base/NAF/Lexi/Superpose.cpp cara-1.9.1.5-mod/NAF/Lexi/Superpose.cpp --- cara-1.9.1.5-base/NAF/Lexi/Superpose.cpp 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/Lexi/Superpose.cpp 2016-05-12 11:27:54.260664992 -0500 @@ -44,7 +44,7 @@ void Superpose::request( const RequisitionVector& request, Requisition& result ) { - for( long i = 0; i < d_layouts.size(); ++i ) + for( int i = 0; i < d_layouts.size(); ++i ) { d_layouts[ i ]->request( request, result ); } @@ -53,7 +53,7 @@ void Superpose::allocate( const Allocation& given, const RequisitionVector& requisition, AllocationVector& result ) { - for( long i = 0; i < d_layouts.size(); ++i ) + for( int i = 0; i < d_layouts.size(); ++i ) { d_layouts[ i ]->allocate( given, requisition, result ); } diff -Naur cara-1.9.1.5-base/NAF/LuaQt2/LuaFrame2.cpp cara-1.9.1.5-mod/NAF/LuaQt2/LuaFrame2.cpp --- cara-1.9.1.5-base/NAF/LuaQt2/LuaFrame2.cpp 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/LuaQt2/LuaFrame2.cpp 2016-05-12 11:27:54.261664989 -0500 @@ -329,7 +329,7 @@ { Q3WidgetStack* obj = ObjectHelper::check( L, 1 ); QWidget* w = ObjectHelper::check( L, 2 ); - obj->addWidget( w, int( w ) ); + obj->addWidget( w, -1 ); return 0; } diff -Naur cara-1.9.1.5-base/NAF/LuaQt3/LuaFrame2.cpp cara-1.9.1.5-mod/NAF/LuaQt3/LuaFrame2.cpp --- cara-1.9.1.5-base/NAF/LuaQt3/LuaFrame2.cpp 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/LuaQt3/LuaFrame2.cpp 2016-05-12 11:27:54.261664989 -0500 @@ -226,7 +226,7 @@ { Q3WidgetStack* obj = QtObject::check( L, 1 ); QWidget* w = QtObject::check( L, 2 ); - obj->addWidget( w, int( w ) ); + obj->addWidget( w, -1 ); return 0; } diff -Naur cara-1.9.1.5-base/NAF/Root/Any.cpp cara-1.9.1.5-mod/NAF/Root/Any.cpp --- cara-1.9.1.5-base/NAF/Root/Any.cpp 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/Root/Any.cpp 2016-05-13 15:22:41.793909519 -0500 @@ -64,26 +64,26 @@ static const int g_sizes[] = { 0, // Null - 1, // Boolean - 1, // Char - 1, // UChar - 2, // Short - 2, // UShort - 4, // Long - 4, // ULong - 4, // Float - 8, // Double + sizeof(Root::UChar), // Boolean + sizeof(Root::Char), // Char + sizeof(Root::UChar), // UChar + sizeof(Root::Short), // Short + sizeof(Root::UShort), // UShort + sizeof(Root::Long), // Long + sizeof(Root::ULong), // ULong + sizeof(Root::Float), // Float + sizeof(Root::Double), // Double NullTerminated, // String - 8, // DateTime - 4, // Date - 4, // Time - 16, // Complex + 2 * sizeof(Root::ULong), // DateTime + sizeof(Root::ULong), // Date + sizeof(Root::ULong), // Time + 2 * sizeof(Root::Double), // Complex NullTerminated, // Memo - 4, // OID - 4, // Literal + sizeof(Root::ULong), // OID + sizeof(void *), // Literal LeadingCounter, // Bytes - 4, // Object - 4, // Pointer + sizeof(void *), // Object + sizeof(void *), // Pointer NullTerminated, // XML NullTerminated, // HTML }; @@ -92,7 +92,7 @@ //. Es sind dies ausschliesslich die Fixlängentypen mit Länge <= 4. static const bool g_direct[] = { - false, // Null + true, // Null true, // Boolean true, // Char true, // UChar @@ -101,9 +101,9 @@ true, // Long true, // ULong true, // Float - false, // Double + true, // Double false, // String - false, // DateTime + true, // DateTime true, // Date true, // Time false, // Complex @@ -121,9 +121,9 @@ { int size = g_sizes[ t ]; if( size == NullTerminated ) - return ::strlen( (char*) d ) + 1; + return ::strlen( (const char*) d ) + 1; else if( size == LeadingCounter ) - return ( *(Root::ULong*) d ) + 4; + return ( *(Root::ULong*) d ) + sizeof(Root::ULong); else return size; } @@ -138,11 +138,11 @@ switch( d_type ) { case Any::DateTime: - return Root::DateTime( *(Root::ULong*) d_data, *(Root::ULong*) ( d_data + 4 ) ); + return Root::DateTime( d_data_u.dt[0], d_data_u.dt[1] ); case Any::Time: - return Root::DateTime( 0, getWord() ); + return Root::DateTime( 0, d_data_u.ulng ); case Any::Date: - return Root::DateTime( getWord(), 0 ); + return Root::DateTime( d_data_u.ulng, 0 ); default: break; } @@ -154,9 +154,9 @@ switch( d_type ) { case Any::DateTime: - return Root::Date( *(Root::ULong*) d_data ); + return Root::Date( d_data_u.dt[0] ); case Any::Date: - return Root::Date( getWord() ); + return Root::Date( d_data_u.ulng ); default: break; } @@ -168,9 +168,9 @@ switch( d_type ) { case Any::DateTime: - return Root::Time( *(Root::ULong*) ( d_data + 4 ) ); + return Root::Time( d_data_u.dt[1] ); case Any::Time: - return Root::Time( getWord() ); + return Root::Time( d_data_u.ulng ); default: break; } @@ -179,33 +179,33 @@ void Any::setTime(Root::Time t) { - setWord( t.getValue() ); + resize(0); + d_data_u.ulng = t.getValue(); d_type = Any::Time; } void Any::setDate(Root::Date d) { - setWord( d.getValue() ); + resize(0); + d_data_u.ulng = d.getValue(); d_type = Any::Date; } Any::Any(Root::Date d) { - d_data = 0; d_type = Any::Null; setDate( d ); } Any::Any(Root::Time t) { - d_data = 0; d_type = Any::Null; setTime( t ); } Any::Any() { - d_data = 0; + d_data_u.ptr = 0; d_type = Any::Null; } @@ -216,48 +216,42 @@ Boolean Any::getBoolean() const { - return ( getChar() != 0 ); + return ( getUChar() != 0 ); } Char Any::getChar() const { - switch( d_type ) - { - case Any::Char: - case Any::UChar: - case Any::Boolean: - return (Root::Char) getWord(); - default: + if ( d_type == Any::Char ) + return d_data_u.ch; + else return (Root::Char) getLong(); - } } Short Any::getShort() const { - switch( d_type ) - { - case Any::Short: - case Any::UShort: - return (Root::Short) getWord(); - default: + if ( d_type == Any::Short ) + return d_data_u.shrt; + else return (Root::Short) getLong(); - } } Long Any::getLong() const { switch( d_type ) { - case Any::Long: case Any::ULong: case Any::OID: - return (Root::Long) getWord(); + return d_data_u.ulng; + case Any::Long: + return d_data_u.lng; case Any::Short: - case Any::UShort: return getShort(); + case Any::UShort: + return getUShort(); case Any::Char: - case Any::UChar: return getChar(); + case Any::UChar: + return getUChar(); case Any::Null: return 0; case Any::Boolean: @@ -269,7 +263,8 @@ case Any::CStr: case Any::Literal: { - Root::Long res = ::strtol( (const char*) d_data, 0, 10 ); + errno = 0; + Root::Long res = ::strtol( (const char*) d_data_u.ptr, 0, 10 ); if( errno == ERANGE ) throw Root::Exception( "Not a number" ); return res; @@ -282,56 +277,48 @@ UChar Any::getUChar() const { - return getChar(); + switch( d_type ) + { + case Any::UChar: + case Any::Boolean: + return d_data_u.uch; + default: + return (Root::UChar) getLong(); + } } UShort Any::getUShort() const { - return getShort(); + if ( d_type == Any::UShort ) + return d_data_u.ushrt; + else + return (Root::UShort) getLong(); } ULong Any::getULong() const { - return getLong(); + if ( d_type == Any::ULong) + return d_data_u.ulng; + else + return (Root::ULong) getLong(); } Float Any::getFloat() const { - switch( d_type ) - { - case Any::Double: - return (Root::Float)*(Root::Double*) d_data; - case Any::Float: - { - Root::Float f; - ::memcpy( &f, &d_data, 4 ); - return f; - } - //return (Root::Float) getWord(); - case Any::CStr: - { - double res = ::strtod( (const char*) d_data, 0 ); - if( errno == ERANGE ) - throw Root::Exception( "" ); // RISK - return (Root::Float) res; - } - default: - return (Root::Float) getLong(); - } - return 0; + return (Root::Float) getDouble(); } Double Any::getDouble() const { switch( d_type ) { - case Any::Double: - return *(Root::Double*) d_data; case Any::Float: - return (Root::Float) getFloat(); + case Any::Double: + return d_data_u.dbl; case Any::CStr: { - double res = ::strtod( (const char*) d_data, 0 ); + errno = 0; + double res = ::strtod( (const char*) d_data_u.ptr, 0 ); if( errno == ERANGE ) throw Root::Exception( "" ); // RISK return res; @@ -344,6 +331,13 @@ const char* Any::getCStr() const { + + // Note: casts are required because most of the Root typedefs correspond to + // explicit-width types, but sprintf() field descriptors describe types + // in terms of the underlying system's default types. The correspondance + // between these is not specified. + // Moreover, promotion rules for the function arguments may produce different + // results depending on the width of the underlying type. switch( d_type ) { case Any::CStr: @@ -351,7 +345,7 @@ case Any::Html: case Any::Xml: case Any::Literal: - return (const Root::CStr) d_data; + return (const Root::CStr) d_data_u.ptr; case Any::Boolean: if( getBoolean() ) return "true"; @@ -361,38 +355,40 @@ return ""; // null case Any::Object: case Any::Pointer: - ::sprintf( g_buffer, "#%x", (unsigned int)getObject() ); + // size_t is very likely to be wide enough for a pointer, but + // that is not guaranteed. + // It would be more appropriate to cast to void* and use a %p field + // descriptor, but that would cause slightly different formatting. + ::sprintf( g_buffer, "#%zx", (size_t) getObject() ); return g_buffer; case Any::Short: case Any::Long: - ::sprintf( g_buffer, "%d", getLong() ); + ::sprintf( g_buffer, "%ld", long( getLong() )); return g_buffer; case Any::UShort: case Any::ULong: case Any::OID: - ::sprintf( g_buffer, "%u", getULong() ); + ::sprintf( g_buffer, "%lu", (unsigned long) getULong() ); return g_buffer; case Any::Char: case Any::UChar: - ::sprintf( g_buffer, "%c", getLong() ); + ::sprintf( g_buffer, "%c", char( getLong() ) ); return g_buffer; case Any::Float: - ::sprintf( g_buffer, "%f", double( getFloat() ) ); - return g_buffer; case Any::Double: ::sprintf( g_buffer, "%f", getDouble() ); return g_buffer; case Any::DateTime: ::sprintf( g_buffer, "%s %s", - Root::Date( *(Root::ULong*) d_data ).getString( true ).data(), // RISK - Root::Time( *(Root::ULong*) ( d_data + 4 ) ).getString().data() ); + Root::Date( d_data_u.dt[0] ).getString( true ).data(), // RISK + Root::Time( d_data_u.dt[1] ).getString().data() ); return g_buffer; case Any::Time: - ::sprintf( g_buffer, "%s", Root::Time( getWord() ).getString().data() ); + ::sprintf( g_buffer, "%s", Root::Time( d_data_u.ulng ).getString().data() ); return g_buffer; case Any::Date: ::sprintf( g_buffer, "%s", - Root::Date( getWord() ).getString( true ).data() ); // RISK + Root::Date( d_data_u.ulng ).getString( true ).data() ); // RISK return g_buffer; default: break; @@ -406,7 +402,7 @@ { case Any::Object: case Any::Pointer: - return (Root::Resource*) getWord(); + return (Root::Resource*) d_data_u.ptr; default: break; } @@ -415,53 +411,58 @@ void Any::setBoolean(Root::Boolean d) { - setWord( d ); + resize(0); + d_data_u.uch = (Root::UChar) d; d_type = Any::Boolean; } void Any::setChar( Root::Char d ) { - setWord( d ); + resize(0); + d_data_u.ch = d; d_type = Any::Char; } void Any::setUChar(Root::UChar d) { - setWord( d ); + resize(0); + d_data_u.uch = d; d_type = Any::UChar; } void Any::setCStr(const char* d) { - int len = ::strlen( d ) + 1; + Root::ULong len = ::strlen( d ) + 1; resize( len ); - ::memcpy( d_data, (void*) d, len ); + ::memcpy( d_data_u.ptr, (void*) d, len ); d_type = Any::CStr; } void Any::setDouble(Root::Double d) { - resize( 8 ); - ::memcpy( d_data, (void*) &d, 8 ); + resize( 0 ); + d_data_u.dbl = d; d_type = Any::Double; } void Any::setFloat(Root::Float d) { resize( 0 ); - ::memcpy( &d_data, &d, 4 ); + d_data_u.dbl = d; d_type = Any::Float; } void Any::setLong(Root::Long d) { - setWord( d ); + resize(0); + d_data_u.lng = d; d_type = Any::Long; } void Any::setULong(Root::ULong d) { - setWord( d ); + resize(0); + d_data_u.ulng = d; d_type = Any::ULong; } @@ -469,7 +470,8 @@ { if( refcount ) Resource::addRef( o ); // Zuerst, falls man selbes Objekt zuordnet, es nicht zuerst gelöscht wird. - setWord( (long)o ); + resize(0); + d_data_u.ptr = o; if( refcount ) d_type = Any::Object; else @@ -478,13 +480,15 @@ void Any::setShort(Root::Short d) { - setWord( d ); + resize(0); + d_data_u.shrt = d; d_type = Any::Short; } void Any::setUShort(Root::UShort d) { - setWord( d ); + resize(0); + d_data_u.ushrt = d; d_type = Any::UShort; } @@ -494,9 +498,8 @@ return *this; resize( 0 ); - d_data = rhs.d_data; + ::memcpy(&d_data_u, &rhs.d_data_u, sizeof(d_data_u)); d_type = rhs.d_type; - rhs.d_data = 0; rhs.d_type = Any::Null; return *this; } @@ -506,24 +509,23 @@ // für target==direct wird resize immer mit 0 aufgerufen. if( d_type == Any::Object ) - Resource::release( (Root::Resource*)getWord() ); + Resource::release( (Root::Resource*) d_data_u.ptr ); - if( g_direct[ d_type ] || sizeOf( d_type, d_data ) != size ) + if( g_direct[ d_type ] || sizeOf( d_type, (Root::Byte*) d_data_u.ptr ) != size ) { // Im Falle des Vorgängers von direct immer hierher, da sonst // ev. für len(string)<4 kein data alloziiert wird. - if( d_data && !g_direct[ d_type ] ) - Mem::free( d_data ); + if( !g_direct[ d_type ] ) + Mem::free( d_data_u.ptr ); if( size > 0 ) // TODO: nur wenn neuer Type direct ist. - d_data = (Root::Byte*) Mem::alloc( size ); + d_data_u.ptr = Mem::alloc( size ); else - d_data = 0; + d_data_u.ptr = 0; } } Any::Any(const char * str) { - d_data = 0; d_type = Any::Null; setCStr( str ); } @@ -536,114 +538,102 @@ Any::Any( const Any & rhs ) { - d_data = 0; d_type = Any::Null; *this = rhs; } Any& Any::operator =( const Any & rhs) { + if (&rhs != this) { // else it's a self-assignment if( g_direct[ rhs.d_type ] ) { resize( 0 ); - d_data = rhs.d_data; + ::memcpy(&d_data_u, &rhs.d_data_u, sizeof(d_data_u)); d_type = rhs.d_type; }else { - Root::ULong size = sizeOf( rhs.d_type, rhs.d_data ); + Root::ULong size = sizeOf( rhs.d_type, (Root::Byte*) rhs.d_data_u.ptr ); resize( size ); - if( size ) - ::memcpy( d_data, rhs.d_data, size ); + ::memcpy( d_data_u.ptr, rhs.d_data_u.ptr, size ); d_type = rhs.d_type; } if( rhs.d_type == Any::Object ) - Resource::addRef( (Root::Resource*)getWord() ); + Resource::addRef( (Root::Resource*) d_data_u.ptr ); + } return *this; } Any::Any(Root::Resource * v, bool refcount ) { - d_data = 0; d_type = Any::Null; setObject( v, refcount ); } Any::Any(const Root::Double v) { - d_data = 0; d_type = Any::Null; setDouble( v ); } Any::Any(const Root::Float v) { - d_data = 0; d_type = Any::Null; setFloat( v ); } Any::Any(const Root::Long v) { - d_data = 0; d_type = Any::Null; setLong( v ); } Any::Any(const Root::Short v) { - d_data = 0; d_type = Any::Null; setShort( v ); } Any::Any(const Root::Char v) { - d_data = 0; d_type = Any::Null; setChar( v ); } Any::Any(const Root::ULong v) { - d_data = 0; d_type = Any::Null; setULong( v ); } Any::Any(const Root::UShort v) { - d_data = 0; d_type = Any::Null; setUShort( v ); } Any::Any(const Root::UChar v) { - d_data = 0; d_type = Any::Null; setUChar( v ); } Any::Any(const Root::Boolean v) { - d_data = 0; d_type = Any::Null; setBoolean( v ); } void Any::setDateTime(const Root::DateTime & v) { - resize( 8 ); - Root::ULong d = v.getDate().getValue(); - Root::ULong t = v.getTime().getValue(); - ::memcpy( d_data, (void*) &d, 4 ); - ::memcpy( d_data + 4, (void*) &t, 4 ); + resize( 0 ); + d_data_u.dt[0] = v.getDate().getValue(); + d_data_u.dt[1] = v.getTime().getValue(); d_type = Any::DateTime; } Root::ULong Any::getSize() const { - return sizeOf( d_type, d_data ); + return sizeOf( d_type, (Root::Byte*) d_data_u.ptr ); } const Root::Byte* Any::getBytes() const @@ -651,23 +641,22 @@ if( d_type != Any::Bytes ) return nil; - if( *(Root::ULong*) d_data > 0 ) - return ( d_data + 4 ); + if( *(Root::ULong*) d_data_u.ptr > 0 ) + return ( (Root::Byte*) d_data_u.ptr + sizeof(Root::ULong) ); else return nil; } void Any::setBytes(const Root::Byte * d, Root::ULong size) { - resize( size + 4 ); - ::memcpy( d_data, (void*) &size, 4 ); - ::memcpy( d_data + 4, (void*) &d, size ); + resize( size + sizeof(Root::ULong) ); + ::memcpy( d_data_u.ptr, (void*) &size, sizeof(size) ); + ::memcpy( (Root::Byte*)d_data_u.ptr + sizeof(size), (void*) &d, size ); d_type = Any::Bytes; } Any::Any(const Root::Byte * data, Root::ULong size) { - d_data = 0; d_type = Any::Null; setBytes( data, size ); @@ -681,22 +670,21 @@ Root::Complex Any::getComplex() const { - return Root::Complex( *(Root::Double*) d_data, *(Root::Double*) ( d_data + 8 ) ); + Root::Double *p = (Root::Double *) d_data_u.ptr; + return Root::Complex( p[0], p[1] ); } void Any::setComplex(const Root::Complex & c) { - resize( 16 ); - double real = c.real(); - double imag = c.imag(); - ::memcpy( d_data, (void*) &real, 8 ); - ::memcpy( d_data + 8, (void*) &imag, 8 ); + resize( 2 * sizeof(Root::Double) ); + Root::Double *p = (Root::Double *) d_data_u.ptr; + p[0] = c.real(); + p[1] = c.imag(); d_type = Any::Complex; } Any::Any(const Root::Complex & c) { - d_data = 0; d_type = Any::Null; setComplex( c ); } @@ -740,6 +728,7 @@ bool Any::isString() const { + // XXX: not Any::Literal? return d_type == Any::Memo || d_type == Any::CStr; } @@ -833,13 +822,6 @@ } break; case Any::Float: - d = ::strtod( value, 0 ); - if( errno == 0 ) - { - setFloat( d ); - return true; - } - break; case Any::Double: d = ::strtod( value, 0 ); if( errno == 0 ) @@ -932,6 +914,7 @@ case Long: return getLong() == rhs.getLong(); case ULong: + case OID: return getULong() == rhs.getULong(); case Float: return getFloat() == rhs.getFloat(); @@ -946,11 +929,9 @@ return getTime().getValue() == rhs.getTime().getValue(); case Complex: return getComplex() == rhs.getComplex(); - case OID: case Literal: - return getWord() == rhs.getWord(); + return d_data_u.ptr == rhs.d_data_u.ptr; case Object: - return getObject() == rhs.getObject(); case Pointer: return getObject() == rhs.getObject(); default: @@ -1173,19 +1154,21 @@ Root::ULong Any::getOid() const { if( d_type == Any::OID ) - return getWord(); + return d_data_u.ulng; else return 0; } void Any::setOid(Root::ULong d) { - setWord( d ); + resize(0); + d_data_u.ulng = d; d_type = Any::OID; } void Any::setLiteral(const char * str) { - setWord( (long)str ); + resize(0); + d_data_u.cptr = str; d_type = Any::Literal; } diff -Naur cara-1.9.1.5-base/NAF/Root/Any.h cara-1.9.1.5-mod/NAF/Root/Any.h --- cara-1.9.1.5-base/NAF/Root/Any.h 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/Root/Any.h 2016-05-13 15:22:41.793909519 -0500 @@ -138,10 +138,19 @@ static const Any null; protected: void resize( Root::ULong size ); - Root::Byte* d_data; + union { + void *ptr; + const void *cptr; + Root::Long lng; + Root::Short shrt; + Root::Char ch; + Root::ULong ulng; /* omit? */ + Root::UShort ushrt; /* omit? */ + Root::UChar uch; /* omit? */ + Root::Double dbl; + Root::ULong dt[2]; + } d_data_u; Type d_type; - void setWord( long v ) { resize( 0 ); d_data = (Root::Byte*) v; } - long getWord() const { return (long) d_data; } }; Any operator*( const Any& lhs, const Any& rhs ); diff -Naur cara-1.9.1.5-base/NAF/Root/SymbolString.cpp cara-1.9.1.5-mod/NAF/Root/SymbolString.cpp --- cara-1.9.1.5-base/NAF/Root/SymbolString.cpp 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/Root/SymbolString.cpp 2016-05-12 11:27:54.262664986 -0500 @@ -23,8 +23,9 @@ using namespace Root; uint qHash( const Root::SymbolString& s ) -{ - return (uint) s.data(); +{ + // Not too terrible a hash function for our purpose even when s.data() is a 64-bit pointer + return (uint) s.getSymbol(); } // TODO Threadsafe diff -Naur cara-1.9.1.5-base/NAF/Root/SymbolString.h cara-1.9.1.5-mod/NAF/Root/SymbolString.h --- cara-1.9.1.5-base/NAF/Root/SymbolString.h 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/Root/SymbolString.h 2016-05-12 11:27:54.263664983 -0500 @@ -41,7 +41,7 @@ class SymbolString { public: - typedef Root::UInt32 Symbol; + typedef Root::UIntPtr Symbol; SymbolString(); SymbolString( const QString& ); @@ -69,7 +69,7 @@ const char* data() const { return d_str; } bool empty() const { return d_str == 0 || *d_str == 0; } bool isNull() const { return d_str == 0 || *d_str == 0; } - Symbol getSymbol() const { return (Symbol) d_str; } // RISK + Symbol getSymbol() const { return (Symbol) d_str; } private: const char* d_str; }; diff -Naur cara-1.9.1.5-base/NAF/Root/Units.cpp cara-1.9.1.5-mod/NAF/Root/Units.cpp --- cara-1.9.1.5-base/NAF/Root/Units.cpp 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/Root/Units.cpp 2016-05-12 11:27:54.263664983 -0500 @@ -19,7 +19,6 @@ */ #include "Units.h" -#include #include using namespace Root; @@ -27,19 +26,19 @@ const void* Root::null_pointer = 0; const double Math::Pi = 3.14159265359; -const UInt32 Math::maxULong = ULONG_MAX; +const UInt32 Math::maxULong = 0xffffffff; const UInt32 Math::minULong = 0; -const Int32 Math::maxLong = LONG_MAX; -const Int32 Math::minLong = LONG_MIN; -const UInt16 Math::maxUShort = USHRT_MAX; +const Int32 Math::maxLong = 0x7fffffff; +const Int32 Math::minLong = -Math::maxLong - 1; +const UInt16 Math::maxUShort = 0xffff; const UInt16 Math::minUShort = 0; -const Int16 Math::maxShort = SHRT_MAX; -const Int16 Math::minShort = SHRT_MIN; -const UInt8 Math::maxUByte = UCHAR_MAX; +const Int16 Math::maxShort = 0x7fff; +const Int16 Math::minShort = -Math::maxShort - 1; +const UInt8 Math::maxUByte = 0xff; const UInt8 Math::minUByte = 0; -const Int8 Math::maxByte = SCHAR_MAX; -const Int8 Math::minByte = SCHAR_MIN; -const Int8 Math::maxChar = SCHAR_MAX; -const Int8 Math::minChar = SCHAR_MIN; +const Int8 Math::maxByte = 0x7f; +const Int8 Math::minByte = -Math::maxByte - 1; +const Int8 Math::maxChar = 0x7f; +const Int8 Math::minChar = -Math::maxChar - 1; diff -Naur cara-1.9.1.5-base/NAF/Root/Units.h cara-1.9.1.5-mod/NAF/Root/Units.h --- cara-1.9.1.5-base/NAF/Root/Units.h 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/Root/Units.h 2016-05-13 10:51:28.406221676 -0500 @@ -74,6 +74,9 @@ typedef float F32; typedef double F64; + typedef quintptr UIntPtr; + typedef qlonglong IntMax; + typedef qint64 Int64; typedef qint32 Long; typedef qint32 Int32; diff -Naur cara-1.9.1.5-base/NAF/Script/Engine2.cpp cara-1.9.1.5-mod/NAF/Script/Engine2.cpp --- cara-1.9.1.5-base/NAF/Script/Engine2.cpp 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/Script/Engine2.cpp 2016-05-12 11:27:54.264664980 -0500 @@ -593,7 +593,7 @@ static QByteArray _toHex(const void *p) { - return "0x" + QByteArray::number((quint32)p, 16 ); // table, thread, function, userdata + return "0x" + QByteArray::number((quintptr)p, 16 ); // table, thread, function, userdata } QByteArray Engine2::getValueString(int arg) const diff -Naur cara-1.9.1.5-base/NAF/Spec/BrukerSpectrum.cpp cara-1.9.1.5-mod/NAF/Spec/BrukerSpectrum.cpp --- cara-1.9.1.5-base/NAF/Spec/BrukerSpectrum.cpp 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/Spec/BrukerSpectrum.cpp 2016-05-13 09:10:20.987548963 -0500 @@ -247,7 +247,7 @@ { // 4-Byte-Integer: -2'147'483'647 .. 2'147'483'647 // Float: max 3.40282347 e38 - long val = *(long*)data; + Root::Int32 val = *(Root::Int32*)data; if( turn ) Host::turnSex( (Root::Byte*) &val, 4 ); return val / s_scf * factor; diff -Naur cara-1.9.1.5-base/NAF/Spec/CaraSpectrum.cpp cara-1.9.1.5-mod/NAF/Spec/CaraSpectrum.cpp --- cara-1.9.1.5-base/NAF/Spec/CaraSpectrum.cpp 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/Spec/CaraSpectrum.cpp 2016-05-13 10:06:28.100249313 -0500 @@ -99,6 +99,7 @@ static inline void putF( QFile& out, Root::Byte* buf, Root::Float val ) { + // Note: assumes sizeof Root::Float == 4 ::memcpy( buf, &val, 4 ); if( !s_big ) Root::Host::turnSex( buf, 4 ); @@ -107,6 +108,7 @@ static inline int getF( const Root::Byte* buf, Root::Float& val ) { + // Note: assumes sizeof Root::Float == 4 ::memcpy( &val, buf, 4 ); if( !s_big ) Root::Host::turnSex( (Root::Byte*)&val, 4 ); @@ -115,6 +117,7 @@ static inline int getF( Stream* s, Root::Float& val ) { + // Note: assumes sizeof Root::Float == 4 s->read( s_buf, 4 ); return getF( s_buf, val ); } diff -Naur cara-1.9.1.5-base/NAF/Spec/PipeSpectrum.cpp cara-1.9.1.5-mod/NAF/Spec/PipeSpectrum.cpp --- cara-1.9.1.5-base/NAF/Spec/PipeSpectrum.cpp 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/Spec/PipeSpectrum.cpp 2016-05-13 10:10:03.880514679 -0500 @@ -299,6 +299,7 @@ static inline int getF( const Root::Byte* buf, Root::Float& val ) { + // Note: assumes sizeof Root::Float == 4 ::memcpy( &val, buf, 4 ); if( !s_big ) Root::Host::turnSex( (Root::Byte*)&val, 4 ); @@ -307,6 +308,7 @@ static inline int getF( const Root::Byte* buf, Root::Float& val, bool turn ) { + // Note: assumes sizeof Root::Float == 4 ::memcpy( &val, buf, 4 ); if( !turn ) Root::Host::turnSex( (Root::Byte*)&val, 4 ); diff -Naur cara-1.9.1.5-base/NAF/Spec/UcsfSpectrum.cpp cara-1.9.1.5-mod/NAF/Spec/UcsfSpectrum.cpp --- cara-1.9.1.5-base/NAF/Spec/UcsfSpectrum.cpp 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/Spec/UcsfSpectrum.cpp 2016-05-13 10:13:31.303870105 -0500 @@ -75,6 +75,7 @@ static inline int getF( const Root::Byte* buf, Root::Float& val ) { + // Note: assumes sizeof Root::Float == 4 ::memcpy( &val, buf, 4 ); if( !s_big ) Root::Host::turnSex( (Root::Byte*)&val, 4 ); @@ -83,6 +84,7 @@ static inline int getI( const Root::Byte* buf, int& val ) { + // Note: assumes sizeof Root::Float == 4 ::memcpy( &val, buf, 4 ); if( !s_big ) Root::Host::turnSex( (Root::Byte*)&val, 4 ); diff -Naur cara-1.9.1.5-base/NAF/SpecView/PeakPlaneView.cpp cara-1.9.1.5-mod/NAF/SpecView/PeakPlaneView.cpp --- cara-1.9.1.5-base/NAF/SpecView/PeakPlaneView.cpp 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/SpecView/PeakPlaneView.cpp 2016-05-12 11:27:54.265664977 -0500 @@ -501,7 +501,7 @@ if( v->d_found != 0 && v->d_found != int(sel.size()) && sel.size() == 1 ) str.sprintf( "Found %d peaks, one selected: ", v->d_found ); else - str.sprintf( "Selected %d peaks: ", sel.size() ); + str.sprintf( "Selected %zu peaks: ", sel.size() ); int i = 0; PeakPlaneView::Selection::const_iterator p; PeakSpace* ps = v->getModel(); diff -Naur cara-1.9.1.5-base/NAF/SpecView/SpinPointView.cpp cara-1.9.1.5-mod/NAF/SpecView/SpinPointView.cpp --- cara-1.9.1.5-base/NAF/SpecView/SpinPointView.cpp 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/SpecView/SpinPointView.cpp 2016-05-12 11:27:54.265664977 -0500 @@ -109,7 +109,7 @@ if( v->d_found != 0 && v->d_found != int(sel.size()) && sel.size() == 1 ) str.sprintf( "Found %d peaks, one selected: ", v->d_found ); else - str.sprintf( "Selected %d peaks: ", sel.size() ); + str.sprintf( "Selected %zu peaks: ", sel.size() ); int i = 0; SpinPointView::Selection::const_iterator p; for( p = sel.begin(); p != sel.end(); ++p, i++ ) @@ -138,7 +138,7 @@ qDebug( "**** Dump Point" ); while( i < p.maxSize() && p[i] ) { - qDebug( "adr=%x id=%d", (unsigned int)p[i], p[i]->getId() ); + qDebug( "adr=%zx id=%d", (size_t)p[i], p[i]->getId() ); i++; } } diff -Naur cara-1.9.1.5-base/NAF/SpecView3/PeakPlaneView3.cpp cara-1.9.1.5-mod/NAF/SpecView3/PeakPlaneView3.cpp --- cara-1.9.1.5-base/NAF/SpecView3/PeakPlaneView3.cpp 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/SpecView3/PeakPlaneView3.cpp 2016-05-12 11:27:54.265664977 -0500 @@ -533,7 +533,7 @@ if( v->d_found != 0 && v->d_found != int(sel.size()) && sel.size() == 1 ) str.sprintf( "Found %d peaks, one selected: ", v->d_found ); else - str.sprintf( "Selected %d peaks: ", sel.size() ); + str.sprintf( "Selected %zu peaks: ", sel.size() ); int i = 0; PeakPlaneView3::Selection::const_iterator p; PeakSpace* ps = v->getModel(); diff -Naur cara-1.9.1.5-base/NAF/SpecView3/SpinPointView3.cpp cara-1.9.1.5-mod/NAF/SpecView3/SpinPointView3.cpp --- cara-1.9.1.5-base/NAF/SpecView3/SpinPointView3.cpp 2016-01-10 05:53:17.000000000 -0600 +++ cara-1.9.1.5-mod/NAF/SpecView3/SpinPointView3.cpp 2016-05-12 11:27:54.266664974 -0500 @@ -101,7 +101,7 @@ if( v->d_found != 0 && v->d_found != int(sel.size()) && sel.size() == 1 ) str.sprintf( "Found %d points, one selected: ", v->d_found ); else - str.sprintf( "Selected %d points: ", sel.size() ); + str.sprintf( "Selected %zu points: ", sel.size() ); int i = 0; SpinPointView3::Selection::const_iterator p; for( p = sel.begin(); p != sel.end(); ++p, i++ ) @@ -128,7 +128,7 @@ qDebug( "**** Dump Point" ); while( i < p.maxSize() && p[i] ) { - qDebug( "adr=%x id=%d", (unsigned int)p[i], p[i]->getId() ); + qDebug( "adr=%zx id=%d", (size_t)p[i], p[i]->getId() ); i++; } }