Commit e8316fd3 authored by Davis King's avatar Davis King

Changed shared_ptr slightly to avoid warnings from gcc.

parent 000b7e70
...@@ -116,6 +116,16 @@ namespace dlib ...@@ -116,6 +116,16 @@ namespace dlib
} }
}; };
struct default_deleter : public shared_ptr_deleter
{
void del(const void* p) { delete ((T*)p); }
void* get_deleter_void(const std::type_info&) const
{
return 0;
}
};
public: public:
typedef T element_type; typedef T element_type;
...@@ -136,6 +146,7 @@ namespace dlib ...@@ -136,6 +146,7 @@ namespace dlib
try try
{ {
shared_node = new shared_ptr_node; shared_node = new shared_ptr_node;
shared_node->del = new default_deleter;
} }
catch (...) catch (...)
{ {
...@@ -177,15 +188,8 @@ namespace dlib ...@@ -177,15 +188,8 @@ namespace dlib
if (shared_node->ref_count == 1) if (shared_node->ref_count == 1)
{ {
// delete the data in the appropriate way // delete the data in the appropriate way
if (shared_node->del)
{
shared_node->del->del(data); shared_node->del->del(data);
delete shared_node->del; delete shared_node->del;
}
else
{
delete data;
}
// notify any weak_ptrs that the data has now expired // notify any weak_ptrs that the data has now expired
if (shared_node->weak_node) if (shared_node->weak_node)
...@@ -301,6 +305,7 @@ namespace dlib ...@@ -301,6 +305,7 @@ namespace dlib
<< "\n\tthis: " << this << "\n\tthis: " << this
); );
shared_node = new shared_ptr_node; shared_node = new shared_ptr_node;
shared_node->del = new default_deleter;
data = r.release(); data = r.release();
} }
...@@ -334,6 +339,7 @@ namespace dlib ...@@ -334,6 +339,7 @@ namespace dlib
reset(); reset();
shared_node = new shared_ptr_node; shared_node = new shared_ptr_node;
shared_node->del = new default_deleter;
data = r.release(); data = r.release();
return *this; return *this;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment