]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - wtf/gobject/GOwnPtr.h
JavaScriptCore-903.tar.gz
[apple/javascriptcore.git] / wtf / gobject / GOwnPtr.h
index 1fc594c9fa42c246af104bf84012876b6bf7db7e..8c7e8372f73ff790841b59a8f914d0d9a655f8b2 100644 (file)
 #ifndef GOwnPtr_h
 #define GOwnPtr_h
 
+#if ENABLE(GLIB_SUPPORT)
+
 #include <algorithm>
 #include <wtf/Assertions.h>
 #include <wtf/Noncopyable.h>
 
-// Forward delcarations at this point avoid the need to include GLib includes
-// in WTF headers.
-typedef struct _GError GError;
-typedef struct _GList GList;
-typedef struct _GCond GCond;
-typedef struct _GMutex GMutex;
-typedef struct _GPatternSpec GPatternSpec;
-typedef struct _GDir GDir;
-typedef struct _GHashTable GHashTable;
-typedef struct _GFile GFile;
 extern "C" void g_free(void*);
 
 namespace WTF {
@@ -47,10 +39,9 @@ template<> void freeOwnedGPtr<GCond>(GCond*);
 template<> void freeOwnedGPtr<GMutex>(GMutex*);
 template<> void freeOwnedGPtr<GPatternSpec>(GPatternSpec*);
 template<> void freeOwnedGPtr<GDir>(GDir*);
-template<> void freeOwnedGPtr<GHashTable>(GHashTable*);
-template<> void freeOwnedGPtr<GFile>(GFile*);
 
-template <typename T> class GOwnPtr : public Noncopyable {
+template <typename T> class GOwnPtr {
+    WTF_MAKE_NONCOPYABLE(GOwnPtr);
 public:
     explicit GOwnPtr(T* ptr = 0) : m_ptr(ptr) { }
     ~GOwnPtr() { freeOwnedGPtr(m_ptr); }
@@ -78,8 +69,9 @@ public:
 
     void clear()
     {
-        freeOwnedGPtr(m_ptr);
+        T* ptr = m_ptr;
         m_ptr = 0;
+        freeOwnedGPtr(ptr);
     }
 
     T& operator*() const
@@ -145,4 +137,7 @@ template <typename T> inline void freeOwnedGPtr(T* ptr)
 
 using WTF::GOwnPtr;
 
+#endif // ENABLE(GLIB_SUPPORT)
+
 #endif // GOwnPtr_h
+