Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize the codebase - remove leftover NULLs #2499

Merged
merged 7 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Checks: '-*,modernize-use-nullptr,modernize-use-override,bugprone,modernize-redundant-void-arg'
jougs marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion doc/htmldoc/static/js/11.1.0_highlight.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ className:"title",begin:u(t)+e.IDENT_RE,relevance:0
},c=u(t)+e.IDENT_RE+"\\s*\\(",d={
keyword:["asm","auto","break","case","const","continue","default","do","else","enum","extern","for","fortran","goto","if","inline","register","restrict","return","sizeof","static","struct","switch","typedef","union","volatile","while","_Alignas","_Alignof","_Atomic","_Generic","_Noreturn","_Static_assert","_Thread_local","alignas","alignof","noreturn","static_assert","thread_local","_Pragma"],
type:["float","double","signed","unsigned","int","short","long","char","void","_Bool","_Complex","_Imaginary","_Decimal32","_Decimal64","_Decimal128","complex","bool","imaginary"],
literal:"true false NULL",
literal:"true false nullptr",
jougs marked this conversation as resolved.
Show resolved Hide resolved
built_in:"std string wstring cin cout cerr clog stdin stdout stderr stringstream istringstream ostringstream auto_ptr deque list queue stack vector map set pair bitset multiset multimap unordered_set unordered_map unordered_multiset unordered_multimap priority_queue make_pair array shared_ptr abort terminate abs acos asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp fscanf future isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper labs ldexp log10 log malloc realloc memchr memcmp memcpy memset modf pow printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan vfprintf vprintf vsprintf endl initializer_list unique_ptr"
},g=[o,i,n,e.C_BLOCK_COMMENT_MODE,r,s],b={variants:[{begin:/=/,end:/;/},{
begin:/\(/,end:/\)/},{beginKeywords:"new throw return else",end:/;/}],
Expand Down
2 changes: 1 addition & 1 deletion doc/htmldoc/static/js/highlight.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ className:"title",begin:n.optional(a)+e.IDENT_RE,relevance:0
},d=n.optional(a)+e.IDENT_RE+"\\s*\\(",g={
keyword:["asm","auto","break","case","continue","default","do","else","enum","extern","for","fortran","goto","if","inline","register","restrict","return","sizeof","struct","switch","typedef","union","volatile","while","_Alignas","_Alignof","_Atomic","_Generic","_Noreturn","_Static_assert","_Thread_local","alignas","alignof","noreturn","static_assert","thread_local","_Pragma"],
type:["float","double","signed","unsigned","int","short","long","char","void","_Bool","_Complex","_Imaginary","_Decimal32","_Decimal64","_Decimal128","const","static","complex","bool","imaginary"],
literal:"true false NULL",
literal:"true false nullptr",
jougs marked this conversation as resolved.
Show resolved Hide resolved
built_in:"std string wstring cin cout cerr clog stdin stdout stderr stringstream istringstream ostringstream auto_ptr deque list queue stack vector map set pair bitset multiset multimap unordered_set unordered_map unordered_multiset unordered_multimap priority_queue make_pair array shared_ptr abort terminate abs acos asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp fscanf future isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper labs ldexp log10 log malloc realloc memchr memcmp memcpy memset modf pow printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan vfprintf vprintf vsprintf endl initializer_list unique_ptr"
},u=[l,r,t,e.C_BLOCK_COMMENT_MODE,o,s],b={variants:[{begin:/=/,end:/;/},{
begin:/\(/,end:/\)/},{beginKeywords:"new throw return else",end:/;/}],
Expand Down
2 changes: 1 addition & 1 deletion libnestutil/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
/* "Define if NAN is available" */
#cmakedefine HAVE_NAN 1

/* "Define if std::nan(NULL) is available" */
/* "Define if std::nan(nullptr) is available" */
heplesser marked this conversation as resolved.
Show resolved Hide resolved
#cmakedefine HAVE_STD_NAN 1

/* define for ostream */
Expand Down
50 changes: 24 additions & 26 deletions libnestutil/lockptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class lockPTR
PointerObject( PointerObject const& );

public:
explicit PointerObject( D* p = NULL )
explicit PointerObject( D* p = nullptr )
: pointee( p )
, deletable( true )
, locked( false )
Expand All @@ -114,7 +114,7 @@ class lockPTR
~PointerObject()
{
assert( not locked );
if ( ( pointee != NULL ) and deletable and not locked )
if ( pointee and deletable and not locked )
{
delete pointee;
}
Expand Down Expand Up @@ -164,34 +164,34 @@ class lockPTR
// object which must then be initialised, for example
// by assignement.

explicit lockPTR( D* p = NULL )
explicit lockPTR( D* p = nullptr )
{
obj = std::make_shared< PointerObject >( p );
assert( obj != NULL );
assert( obj );
}

explicit lockPTR( D& p_o )
{
obj = std::make_shared< PointerObject >( p_o );
assert( obj != NULL );
assert( obj );
}

lockPTR( const lockPTR< D >& spd )
: obj( spd.obj )
{
assert( obj != NULL );
assert( obj );
}

virtual ~lockPTR()
{
assert( obj != NULL );
assert( obj );
}

lockPTR< D >
operator=( const lockPTR< D >& spd )
{
assert( obj != NULL );
assert( spd.obj != NULL );
assert( obj );
assert( spd.obj );

obj = spd.obj;

Expand Down Expand Up @@ -234,41 +234,39 @@ class lockPTR
D*
operator->() const
{
assert( obj->get() != NULL );
assert( obj->get() );

return obj->get();
}

D*
operator->()
{
assert( obj->get() != NULL );
assert( obj->get() );

return obj->get();
}

D&
operator*()
{
assert( obj->get() != NULL );
assert( obj->get() );

return *( obj->get() );
}

const D&
operator*() const
{
assert( obj->get() != NULL );
assert( obj->get() );
return *( obj->get() );
}


bool
operator not() const //!< returns true if and only if obj->pointee == NULL
operator not() const //!< returns true if and only if not obj->pointee
{
// assert(obj != NULL);

return ( obj->get() == NULL );
return not obj->get();
}


Expand Down Expand Up @@ -296,51 +294,51 @@ class lockPTR


bool
valid() const //!< returns true if and only if obj->pointee != NULL
valid() const //!< returns true if and only if obj->pointee
{
assert( obj != NULL );
return ( obj->get() != NULL );
assert( obj );
return ( obj->get() );
}

bool
islocked() const
{
assert( obj != NULL );
assert( obj );
return ( obj->islocked() );
}

bool
deletable() const
{
assert( obj != NULL );
assert( obj );
return ( obj->isdeletable() );
}

void
lock() const
{
assert( obj != NULL );
assert( obj );
obj->lock();
}

void
unlock() const
{
assert( obj != NULL );
assert( obj );
obj->unlock();
}

void
unlock()
{
assert( obj != NULL );
assert( obj );
obj->unlock();
}

size_t
references() const
{
return ( obj == NULL ) ? 0 : obj.use_count();
return not obj ? 0 : obj.use_count();
}
};

Expand Down
8 changes: 4 additions & 4 deletions nest/neststartup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ neststartup( int* argc, char*** argv, SLIInterpreter& engine, std::string module
#ifdef _IS_PYNEST
// add the init-script to the list of module initializers
ArrayDatum* ad = dynamic_cast< ArrayDatum* >( engine.baselookup( engine.commandstring_name ).datum() );
assert( ad != NULL );
assert( ad );
ad->push_back( new StringDatum( "(" + modulepath + "/pynest-init.sli) run" ) );
#endif

Expand All @@ -160,11 +160,11 @@ nestshutdown( int exitcode )
Datum*
CYTHON_unpackConnectionGeneratorDatum( PyObject* obj )
{
Datum* ret = NULL;
ConnectionGenerator* cg = NULL;
Datum* ret = nullptr;
ConnectionGenerator* cg = nullptr;

cg = PNS::unpackConnectionGenerator( obj );
if ( cg != NULL )
if ( cg )
{
ret = static_cast< Datum* >( new ConnectionGeneratorDatum( cg ) );
}
Expand Down
2 changes: 1 addition & 1 deletion nest/neststartup.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Datum* CYTHON_unpackConnectionGeneratorDatum( PyObject* );
#else
#define CYTHON_isConnectionGenerator( x ) 0
#define CYTHON_unpackConnectionGeneratorDatum( x ) NULL
#define CYTHON_unpackConnectionGeneratorDatum( x ) nullptr
#endif

class SLIInterpreter;
Expand Down
2 changes: 1 addition & 1 deletion nestkernel/conn_builder_conngen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ ConnectionGeneratorBuilder::connect_()
if ( num_parameters == 0 )
{
// connect source to target
while ( cg_->next( source, target, NULL ) )
while ( cg_->next( source, target, nullptr ) )
{
// No need to check for locality of the target, as the mask
// created by cg_set_masks() only contains local nodes.
Expand Down
2 changes: 1 addition & 1 deletion nestkernel/connection_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ nest::ConnectionManager::trigger_update_weight( const long vt_id,
for ( std::vector< ConnectorBase* >::iterator it = connections_[ tid ].begin(); it != connections_[ tid ].end();
++it )
{
if ( *it != NULL )
if ( *it )
{
( *it )->trigger_update_weight(
vt_id, tid, dopa_spikes, t_trig, kernel().model_manager.get_connection_models( tid ) );
Expand Down
8 changes: 4 additions & 4 deletions nestkernel/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,10 @@ class Event
* members, however, in order to avoid the reference of reference
* problem, we store sender and receiver as pointers and use
* references in the interface.
* Thus, we can still ensure that the pointers are never NULL.
* Thus, we can still ensure that the pointers are never nullptr.
*/
Node* sender_; //!< Pointer to sender or NULL.
Node* receiver_; //!< Pointer to receiver or NULL.
Node* sender_; //!< Pointer to sender or nullptr.
Node* receiver_; //!< Pointer to receiver or nullptr.


/**
Expand Down Expand Up @@ -620,7 +620,7 @@ class DataLoggingRequest : public Event
Time recording_offset_;
/**
* Names of properties to record from.
* @note This pointer shall be NULL unless the event is sent by a connection
* @note This pointer shall be nullptr unless the event is sent by a connection
* routine.
*/
std::vector< Name > const* const record_from_;
Expand Down
16 changes: 8 additions & 8 deletions nestkernel/recording_backend_sionlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ nest::RecordingBackendSIONlib::open_files_()

// we need to delay the throwing of exceptions to the end of the parallel
// section
WrappedThreadException* we = NULL;
WrappedThreadException* we = nullptr;

// This code is executed in a parallel region (opened above)!
const thread t = kernel().vp_manager.get_thread_id();
Expand Down Expand Up @@ -228,8 +228,8 @@ nest::RecordingBackendSIONlib::open_files_()
&sion_chunksize,
&fs_block_size,
&rank,
NULL,
NULL );
nullptr,
nullptr );

file.buffer.reserve( P_.buffer_size_ );
file.buffer.clear();
Expand Down Expand Up @@ -316,7 +316,7 @@ nest::RecordingBackendSIONlib::close_files_()
if ( task == 0 )
{
int mc;
sion_int64* cs = NULL;
sion_int64* cs = nullptr;
int info_blk; // here int, other place sion_int64 due to sion api
sion_int64 info_pos;

Expand Down Expand Up @@ -536,14 +536,14 @@ nest::RecordingBackendSIONlib::build_filename_() const
* ---------------------------------------------------------------- */

nest::RecordingBackendSIONlib::SIONBuffer::SIONBuffer()
: buffer_( NULL )
: buffer_( nullptr )
, ptr_( 0 )
, max_size_( 0 )
{
}

nest::RecordingBackendSIONlib::SIONBuffer::SIONBuffer( size_t size )
: buffer_( NULL )
: buffer_( nullptr )
, ptr_( 0 )
, max_size_( 0 )
{
Expand All @@ -552,7 +552,7 @@ nest::RecordingBackendSIONlib::SIONBuffer::SIONBuffer( size_t size )

nest::RecordingBackendSIONlib::SIONBuffer::~SIONBuffer()
{
if ( buffer_ != NULL )
if ( buffer_ )
{
delete[] buffer_;
}
Expand All @@ -563,7 +563,7 @@ nest::RecordingBackendSIONlib::SIONBuffer::reserve( size_t size )
{
char* new_buffer = new char[ size ];

if ( buffer_ != NULL )
if ( buffer_ )
{
ptr_ = std::min( ptr_, size );
memcpy( new_buffer, buffer_, ptr_ );
Expand Down
2 changes: 1 addition & 1 deletion nestkernel/target_table_devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ TargetTableDevices::send_from_device( const thread tid,
it != target_from_devices_[ tid ][ ldid ].end();
++it )
{
if ( *it != NULL )
if ( *it )
{
( *it )->send_to_all( tid, cm, e );
}
Expand Down
2 changes: 1 addition & 1 deletion nestkernel/target_table_devices_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ nest::TargetTableDevices::send_to_device( const thread tid,
it != target_to_devices_[ tid ][ lid ].end();
++it )
{
if ( *it != NULL )
if ( *it )
{
( *it )->send_to_all( tid, cm, e );
}
Expand Down
2 changes: 1 addition & 1 deletion sli/aggregatedatum.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class AggregateDatum : public TypedDatum< slt >, public C
// to work.

const AggregateDatum< C, slt >* ddc = dynamic_cast< AggregateDatum< C, slt >* >( const_cast< Datum* >( dat ) );
if ( ddc == NULL )
if ( not ddc )
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion sli/genericdatum.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class GenericDatum : public TypedDatum< slt >

// std::cerr << "d = " << d << " ddc = " << ddc << " dat = " << dat <<
// std::endl;
if ( ddc == NULL )
if ( not ddc )
{
return false;
}
Expand Down
Loading