Skip to content
Snippets Groups Projects
Commit 9c90e08f authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Merge branch 'periodic-bc' into develop

parents e3cc7206 efbc768a
No related branches found
No related tags found
No related merge requests found
...@@ -142,21 +142,25 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer ...@@ -142,21 +142,25 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer
const Object* operator->() const const Object* operator->() const
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
return &this->pd->data; return &this->pd->data;
} }
Object* operator->() Object* operator->()
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
return &this->pd->data; return &this->pd->data;
} }
const Object& operator *() const const Object& operator *() const
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
return this->pd->data; return this->pd->data;
} }
Object& operator *() Object& operator *()
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
return this->pd->data; return this->pd->data;
} }
...@@ -176,6 +180,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer ...@@ -176,6 +180,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer
__cuda_callable__ __cuda_callable__
const Object& getData() const const Object& getData() const
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
return this->pd->data; return this->pd->data;
} }
...@@ -183,6 +188,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer ...@@ -183,6 +188,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer
__cuda_callable__ __cuda_callable__
Object& modifyData() Object& modifyData()
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
return this->pd->data; return this->pd->data;
} }
...@@ -203,7 +209,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer ...@@ -203,7 +209,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer
{ {
this->free(); this->free();
this->pd = (PointerData*) ptr.pd; this->pd = (PointerData*) ptr.pd;
if( this->pd != nullptr ) if( this->pd != nullptr )
this->pd->counter += 1; this->pd->counter += 1;
return *this; return *this;
} }
...@@ -399,22 +405,26 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer ...@@ -399,22 +405,26 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer
const Object* operator->() const const Object* operator->() const
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
return &this->pd->data; return &this->pd->data;
} }
Object* operator->() Object* operator->()
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
this->pd->maybe_modified = true; this->pd->maybe_modified = true;
return &this->pd->data; return &this->pd->data;
} }
const Object& operator *() const const Object& operator *() const
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
return this->pd->data; return this->pd->data;
} }
Object& operator *() Object& operator *()
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
this->pd->maybe_modified = true; this->pd->maybe_modified = true;
return this->pd->data; return this->pd->data;
} }
...@@ -466,7 +476,8 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer ...@@ -466,7 +476,8 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer
this->free(); this->free();
this->pd = (PointerData*) ptr.pd; this->pd = (PointerData*) ptr.pd;
this->cuda_pointer = ptr.cuda_pointer; this->cuda_pointer = ptr.cuda_pointer;
this->pd->counter += 1; if( this->pd != nullptr )
this->pd->counter += 1;
#ifdef TNL_DEBUG_SHARED_POINTERS #ifdef TNL_DEBUG_SHARED_POINTERS
std::cerr << "Copy-assigned shared pointer: counter = " << this->pd->counter << ", type: " << demangle(typeid(ObjectType).name()) << std::endl; std::cerr << "Copy-assigned shared pointer: counter = " << this->pd->counter << ", type: " << demangle(typeid(ObjectType).name()) << std::endl;
#endif #endif
...@@ -481,7 +492,8 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer ...@@ -481,7 +492,8 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer
this->free(); this->free();
this->pd = (PointerData*) ptr.pd; this->pd = (PointerData*) ptr.pd;
this->cuda_pointer = ptr.cuda_pointer; this->cuda_pointer = ptr.cuda_pointer;
this->pd->counter += 1; if( this->pd != nullptr )
this->pd->counter += 1;
#ifdef TNL_DEBUG_SHARED_POINTERS #ifdef TNL_DEBUG_SHARED_POINTERS
std::cerr << "Copy-assigned shared pointer: counter = " << this->pd->counter << ", type: " << demangle(typeid(ObjectType).name()) << std::endl; std::cerr << "Copy-assigned shared pointer: counter = " << this->pd->counter << ", type: " << demangle(typeid(ObjectType).name()) << std::endl;
#endif #endif
......
...@@ -118,21 +118,25 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer ...@@ -118,21 +118,25 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer
const Object* operator->() const const Object* operator->() const
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
return &this->pd->data; return &this->pd->data;
} }
Object* operator->() Object* operator->()
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
return &this->pd->data; return &this->pd->data;
} }
const Object& operator *() const const Object& operator *() const
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
return this->pd->data; return this->pd->data;
} }
Object& operator *() Object& operator *()
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
return this->pd->data; return this->pd->data;
} }
...@@ -152,6 +156,7 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer ...@@ -152,6 +156,7 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer
__cuda_callable__ __cuda_callable__
const Object& getData() const const Object& getData() const
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
return this->pd->data; return this->pd->data;
} }
...@@ -159,6 +164,7 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer ...@@ -159,6 +164,7 @@ class SharedPointer< Object, Devices::Host > : public SmartPointer
__cuda_callable__ __cuda_callable__
Object& modifyData() Object& modifyData()
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
return this->pd->data; return this->pd->data;
} }
......
...@@ -126,17 +126,20 @@ class SharedPointer< Object, Devices::MIC > : public SmartPointer ...@@ -126,17 +126,20 @@ class SharedPointer< Object, Devices::MIC > : public SmartPointer
const Object* operator->() const const Object* operator->() const
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
return &this->pd->data; return &this->pd->data;
} }
Object* operator->() Object* operator->()
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
this->pd->maybe_modified = true; this->pd->maybe_modified = true;
return &this->pd->data; return &this->pd->data;
} }
const Object& operator *() const const Object& operator *() const
{ {
TNL_ASSERT( this->pd != nullptr, "Attempt of dereferencing of null pointer" );
return this->pd->data; return this->pd->data;
} }
......
...@@ -107,6 +107,20 @@ TEST( SharedPointerCudaTest, getDataArrayTest ) ...@@ -107,6 +107,20 @@ TEST( SharedPointerCudaTest, getDataArrayTest )
#endif #endif
}; };
TEST( SharedPointerCudaTest, nullptrAssignement )
{
#ifdef HAVE_CUDA
using TestType = Pointers::SharedPointer< double, Devices::Cuda >;
TestType p1( 5 ), p2( nullptr );
// This should not crash
p1 = p2;
ASSERT_FALSE( p1 );
ASSERT_FALSE( p2 );
#endif
}
#endif #endif
......
...@@ -38,6 +38,19 @@ TEST( SharedPointerHostTest, ConstructorTest ) ...@@ -38,6 +38,19 @@ TEST( SharedPointerHostTest, ConstructorTest )
ASSERT_EQ( ptr1->x(), 1 ); ASSERT_EQ( ptr1->x(), 1 );
ASSERT_EQ( ptr1->y(), 2 ); ASSERT_EQ( ptr1->y(), 2 );
}; };
TEST( SharedPointerCudaTest, nullptrAssignement )
{
using TestType = Pointers::SharedPointer< double, Devices::Host >;
TestType p1( 5 ), p2( nullptr );
// This should not crash
p1 = p2;
ASSERT_FALSE( p1 );
ASSERT_FALSE( p2 );
}
#endif #endif
#include "../GtestMissingError.h" #include "../GtestMissingError.h"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment