Skip to content

Commit

Permalink
cleanup of compilerspecifics, ancient compilers arent supported.
Browse files Browse the repository at this point in the history
ran tidy to use bools instead of ints
  • Loading branch information
turleypol committed Nov 3, 2018
1 parent 614f038 commit 0d4cca7
Show file tree
Hide file tree
Showing 22 changed files with 46 additions and 109 deletions.
1 change: 0 additions & 1 deletion pol-core/bscript/eprog.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <vector>

#include "../clib/boostutils.h"
#include "../clib/compilerspecifics.h"
#include "../clib/rawtypes.h"
#include "../clib/refptr.h"
#include "executortype.h"
Expand Down
1 change: 0 additions & 1 deletion pol-core/bscript/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <string>

#include "../clib/clib.h"
#include "../clib/compilerspecifics.h"
#include "../clib/fixalloc.h"
#include "../clib/logfacility.h"
#include "../clib/random.h"
Expand Down
13 changes: 6 additions & 7 deletions pol-core/clib/cfgelem.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#ifndef CLIB_CFGELEM_H
#define CLIB_CFGELEM_H
#include "compilerspecifics.h"
#include "maputil.h"

#include <map>
Expand Down Expand Up @@ -102,7 +101,7 @@ class ConfigElem : public ConfigElemBase
void add_prop( std::string propname, unsigned short sval );
void add_prop( std::string propname, short sval );

POL_NORETURN void throw_error( const std::string& errmsg ) const;
[[noreturn]] void throw_error( const std::string& errmsg ) const;
void warn( const std::string& errmsg ) const;
void warn_with_line( const std::string& errmsg ) const;

Expand All @@ -112,7 +111,7 @@ class ConfigElem : public ConfigElemBase
void set_source( const ConfigSource* source );

protected:
POL_NORETURN void prop_not_found( const char* propname ) const;
[[noreturn]] void prop_not_found( const char* propname ) const;
typedef std::multimap<std::string, std::string, ci_cmp_pred> Props;
Props properties;
};
Expand Down Expand Up @@ -164,14 +163,14 @@ class VectorConfigElem : public ConfigElemBase
void add_prop( std::string propname, unsigned int lval );
void add_prop( std::string propname, unsigned short sval );

POL_NORETURN void throw_error( const std::string& errmsg ) const;
[[noreturn]] void throw_error( const std::string& errmsg ) const;
void warn( const std::string& errmsg ) const;

void set_rest( const char* newrest );
void set_source( const ConfigElem& elem );

protected:
POL_NORETURN void prop_not_found( const char* propname ) const;
[[noreturn]] void prop_not_found( const char* propname ) const;
std::string type_;
std::string rest_;

Expand All @@ -180,6 +179,6 @@ class VectorConfigElem : public ConfigElemBase

ConfigSource* source_;
};
}
}
} // namespace Clib
} // namespace Pol
#endif
7 changes: 3 additions & 4 deletions pol-core/clib/cfgfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <time.h>
#include <vector>

#include "compilerspecifics.h"
#include "maputil.h"

namespace Pol
Expand Down Expand Up @@ -70,7 +69,7 @@ class ConfigFile : public ConfigSource
virtual void display_error( const std::string& msg, bool show_curline = true,
const ConfigElemBase* elem = nullptr,
bool error = true ) const override;
POL_NORETURN void display_and_rethrow_exception();
[[noreturn]] void display_and_rethrow_exception();
void register_allowed_type( const char* allowed_type );

private:
Expand All @@ -95,6 +94,6 @@ class StubConfigSource : public ConfigSource
virtual void display_error( const std::string& msg, bool show_curline, const ConfigElemBase* elem,
bool error ) const override;
};
}
}
} // namespace Clib
} // namespace Pol
#endif
53 changes: 0 additions & 53 deletions pol-core/clib/compilerspecifics.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,6 @@ Remove the include in all StdAfx.h files or live with the consequences :)
#define passert_assume( x )
#endif


// Defines noreturn attribute using VC++ specifics, C++11-way for modern compilers. :P
// Note: noreturn can be used for code-generation and is supposed to produce more optimized code
#ifndef POL_NORETURN
#if defined( _MSC_VER )
#define POL_NORETURN _declspec( noreturn )
#elif defined( __clang__ )
#define POL_NORETURN [[noreturn]]
#elif defined( __GNUC__ )
#define POL__GCC_VERSION ( __GNUC__ * 100 + __GNUC_MINOR__ )
#if POL__GCC_VERSION <= 407
#define POL_NORETURN __attribute__( ( noreturn ) )
#else
#define POL_NORETURN [[noreturn]]
#endif
#undef POL__GCC_VERSION
#else
#define POL_NORETURN [[noreturn]]
#endif
#endif

// Note: POL_ANALYZER_NORETURN is just a hint for code analyzers (mostly clang-analyzer) and is not
// used for code generation. I don't know of anything similar in the other analyzers and
// thought
Expand All @@ -52,36 +31,4 @@ Remove the include in all StdAfx.h files or live with the consequences :)
#endif
#endif

// the following code to handle NOEXCEPT was obtained
// from http://stackoverflow.com/questions/18387640/how-to-deal-with-noexcept-in-visual-studio
#if !defined( HAS_NOEXCEPT )
#if defined( __clang__ )
#if __has_feature( cxx_noexcept )
#define HAS_NOEXCEPT
#endif
#else
#if defined( __GXX_EXPERIMENTAL_CXX0X__ ) && __GNUC__ * 10 + __GNUC_MINOR__ >= 46 || \
defined( _MSC_FULL_VER ) && _MSC_FULL_VER >= 190023026
#define HAS_NOEXCEPT
#endif
#endif

#ifdef HAS_NOEXCEPT
#define POL_NOEXCEPT noexcept
#else
#define POL_NOEXCEPT
#endif
#endif

#if ( !defined( _MSC_VER ) || _MSC_VER >= 1900 )
#define THREADLOCAL thread_local
#else
#define THREADLOCAL __declspec( thread )
#endif

#if ( !defined( _MSC_VER ) || _MSC_VER >= 1900 )
#define CONSTEXPR constexpr
#else
#define CONSTEXPR
#endif
#endif
2 changes: 1 addition & 1 deletion pol-core/clib/fileutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bool IsDirectory( const char* dir )
sdir = sdir.erase( sdir.length() - 1, 1 );
struct stat st;
if ( stat( sdir.c_str(), &st ) )
return 0;
return false;
return ( st.st_mode & S_IFDIR ? true : false );
}

Expand Down
8 changes: 4 additions & 4 deletions pol-core/clib/passert.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ extern unsigned scripts_thread_scriptPC;

void force_backtrace( bool complete = false );

POL_NORETURN void passert_failed( const char* expr, const char* file, unsigned line );
POL_NORETURN void passert_failed( const char* expr, const std::string& reason, const char* file,
[[noreturn]] void passert_failed( const char* expr, const char* file, unsigned line );
[[noreturn]] void passert_failed( const char* expr, const std::string& reason, const char* file,
unsigned line );
}
} // namespace Clib
#if INC_PASSERT

/**
Expand Down Expand Up @@ -105,5 +105,5 @@ POL_NORETURN void passert_failed( const char* expr, const std::string& reason, c
#define passert_paranoid( exp ) ( (void)0 )

#endif
}
} // namespace Pol
#endif
5 changes: 2 additions & 3 deletions pol-core/clib/refptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#ifndef __REFPTR_H
#define __REFPTR_H

#include "compilerspecifics.h"
#include <atomic>

// **** base class for ref counted classes
Expand Down Expand Up @@ -67,7 +66,7 @@ class ref_ptr
public:
explicit ref_ptr( T* ptr = 0 );
ref_ptr( const ref_ptr& rptr );
ref_ptr( ref_ptr&& rptr ) POL_NOEXCEPT;
ref_ptr( ref_ptr&& rptr ) noexcept;
~ref_ptr();

// Operations
Expand Down Expand Up @@ -155,7 +154,7 @@ ref_ptr<T>::ref_ptr( const ref_ptr& rptr ) : _ptr( rptr.get() )
}

template <class T>
ref_ptr<T>::ref_ptr( ref_ptr&& rptr ) POL_NOEXCEPT : _ptr( rptr._ptr.exchange( nullptr ) )
ref_ptr<T>::ref_ptr( ref_ptr&& rptr ) noexcept : _ptr( rptr._ptr.exchange( nullptr ) )
{
#if REFPTR_DEBUG
--refptr_count;
Expand Down
7 changes: 3 additions & 4 deletions pol-core/clib/stlutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#define STLUTIL_H

#include "Header_Windows.h"
#include "compilerspecifics.h"
#include <cstring>
#include <sstream>

Expand Down Expand Up @@ -76,11 +75,11 @@ inline int stringicmp( const char* str1, const S2& str2 )
#define OSTRINGSTREAM_STR( x ) x.str()

template <class T, size_t N>
CONSTEXPR size_t arsize( T ( & )[N] )
constexpr size_t arsize( T ( & )[N] )
{
return N;
}
}
}
} // namespace Clib
} // namespace Pol

#endif
4 changes: 2 additions & 2 deletions pol-core/plib/mapfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Pol
{
namespace Core
{
bool cfg_show_roof_and_platform_warning = 1;
bool cfg_show_roof_and_platform_warning = true;
}
namespace Plib
{
Expand Down Expand Up @@ -213,7 +213,7 @@ u32 polflags_from_landtileflags( unsigned short tile, u32 lt_flags )
lt_flags |= Core::USTRUCT_TILE::FLAG_HALF_HEIGHT; // the entire map is this way

unsigned int flags = polflags_from_tileflags(
tile, lt_flags, 0, 0 ); // Land tiles shouldn't worry about noshoot or windows
tile, lt_flags, false, false ); // Land tiles shouldn't worry about noshoot or windows
return flags;
}

Expand Down
5 changes: 3 additions & 2 deletions pol-core/pol/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <stddef.h>

#include "../clib/compilerspecifics.h"
#include "../clib/rawtypes.h"
#include "fnsearch.h"
#include "globals/uvars.h"
Expand Down Expand Up @@ -180,5 +181,5 @@ Items::Item* find_walkon_item( ItemsVector& ivec, short z )
}
return nullptr;
}
}
}
} // namespace Core
} // namespace Pol
2 changes: 1 addition & 1 deletion pol-core/pol/item/itemdesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ ItemDesc::ItemDesc( u32 objtype, Clib::ConfigElem& elem, Type type, const Plib::
newbie( elem.remove_bool( "NEWBIE", false ) ),
insured( elem.remove_bool( "INSURED", false ) ),
invisible( elem.remove_bool( "INVISIBLE", false ) ),
decays_on_multis( elem.remove_bool( "DecaysOnMultis", 0 ) ),
decays_on_multis( elem.remove_bool( "DecaysOnMultis", false ) ),
blocks_casting_if_in_hand( elem.remove_bool( "BlocksCastingIfInHand", true ) ),
no_drop( elem.remove_bool( "NoDrop", false ) ),
base_str_req( elem.remove_ushort( "StrRequired", 0 ) * 10 ),
Expand Down
2 changes: 1 addition & 1 deletion pol-core/pol/login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ void send_start( Network::Client* client )

void login2( Network::Client* client, PKTIN_91* msg ) // Gameserver login and character listing
{
client->encrypt_server_stream = 1;
client->encrypt_server_stream = true;

if ( Network::is_banned_ip( client ) )
{
Expand Down
2 changes: 1 addition & 1 deletion pol-core/pol/module/uomod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4665,7 +4665,7 @@ bool UOExecutorModule::is_reserved_to_me( Item* item )

BObjectImp* UOExecutorModule::mf_Shutdown()
{
Clib::exit_signalled = 1;
Clib::exit_signalled = true;
#ifndef _WIN32
// the catch_signals_thread (actually main) sits with sigwait(),
// so it won't wake up except by being signalled.
Expand Down
10 changes: 5 additions & 5 deletions pol-core/pol/network/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ unsigned int Client::instance_counter_;
std::mutex Client::_SocketMutex;

Client::Client( ClientInterface& aInterface, Crypt::TCryptInfo& encryption )
: preDisconnect( 0 ),
disconnect( 0 ),
: preDisconnect( false ),
disconnect( false ),
acct( nullptr ),
chr( nullptr ),
Interface( aInterface ),
Expand All @@ -87,7 +87,7 @@ Client::Client( ClientInterface& aInterface, Crypt::TCryptInfo& encryption )
bytes_received( 0 ),
message_length( 0 ),
cryptengine( create_crypt_engine( encryption ) ),
encrypt_server_stream( 0 ),
encrypt_server_stream( false ),
msgtype_filter( Core::networkManager.login_filter.get() ),
_fpLog_lock(),
fpLog( "" ),
Expand Down Expand Up @@ -528,7 +528,7 @@ void Client::xmit( const void* data, unsigned short datalen )
if ( !disconnect )
POLLOG_ERROR.Format( "Client#{}: Disconnecting client due to send() error (1): {}\n" )
<< instance_ << sckerr;
disconnect = 1;
disconnect = true;
THREAD_CHECKPOINT( active_client, 209 );
return;
}
Expand Down Expand Up @@ -578,7 +578,7 @@ void Client::send_queued_data()
if ( !disconnect )
POLLOG.Format( "Client#{}: Disconnecting client due to send() error (2): {}\n" )
<< instance_ << sckerr;
disconnect = 1;
disconnect = true;
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions pol-core/pol/pol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void textcmd_startlog( Network::Client* client );
void textcmd_stoplog( Network::Client* client );
void start_client_char( Network::Client* client )
{
client->ready = 1;
client->ready = true;
client->chr->connected( true );

// even if this stuff just gets queued, we still want the client to start
Expand Down Expand Up @@ -433,7 +433,7 @@ void char_select( Network::Client* client, PKTIN_5D* msg )

chosen_char->client->gd->clear();
chosen_char->client->forceDisconnect();
chosen_char->client->ready = 0;
chosen_char->client->ready = false;
chosen_char->client->msgtype_filter = networkManager.disconnected_filter.get();

// disassociate the objects from each other.
Expand Down
2 changes: 1 addition & 1 deletion pol-core/pol/polfile1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Pol
{
namespace Core
{
bool cfg_show_illegal_graphic_warning = 1;
bool cfg_show_illegal_graphic_warning = true;

bool newstat_dont_add( std::vector<Plib::STATIC_ENTRY>& vec, USTRUCT_STATIC* pstat )
{
Expand Down
15 changes: 5 additions & 10 deletions pol-core/pol/realms/realmlos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,9 @@ bool Realm::has_los( const Core::ULWObject& att, const Core::ULWObject& tgt ) co
if ( att.realm != tgt.realm )
return false;
}
// due to the nature of los check the same x,y coordinates get checked, cache the last used
// coords to reduce the expensive map/multi read per coordinate

#if ( !defined( _MSC_VER ) || _MSC_VER >= 1900 )
static THREADLOCAL LosCache cache;
#else // older ms support only primitive types :(
LosCache cache;
#endif
// due to the nature of los check the same x,y coordinates get checked, cache the last used
// coords to reduce the expensive map/multi read per coordinate
static thread_local LosCache cache;
cache.last_x = 0xFFFF;
cache.last_y = 0xFFFF;
cache.shapes.clear();
Expand Down Expand Up @@ -348,8 +343,8 @@ bool Realm::has_los( const Core::ULWObject& att, const Core::ULWObject& tgt ) co
}
}
}
}
}
} // namespace Realms
} // namespace Pol


/****************************************************************************/
Expand Down
Loading

0 comments on commit 0d4cca7

Please sign in to comment.