Bug 714967 - Support mozilla::services with external linkage. r=bsmedberg
authorJustin Wood <Callek@gmail.com>
Thu, 05 Jan 2012 02:04:48 -0500
changeset 85789 f65331c8b0e71969936fb6d2b3327b49f553d03d
parent 85766 bc30dee3a6f22a57e17d8382f9d416fbde1413ed
child 85790 3f4c56289ac7e6b4af02ada2fa3878be4baa4575
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs714967
milestone12.0a1
Bug 714967 - Support mozilla::services with external linkage. r=bsmedberg
xpcom/build/Services.cpp
xpcom/build/Services.h
--- a/xpcom/build/Services.cpp
+++ b/xpcom/build/Services.cpp
@@ -59,25 +59,30 @@ using namespace mozilla::services;
 
 /*
  * Define a global variable and a getter for every service in ServiceList.
  * eg. gIOService and GetIOService()
  */
 #define MOZ_SERVICE(NAME, TYPE, CONTRACT_ID)                            \
   static TYPE* g##NAME = nsnull;                                        \
                                                                         \
-  already_AddRefed<TYPE>                                         \
+  already_AddRefed<TYPE>                                                \
   mozilla::services::Get##NAME()                                        \
   {                                                                     \
     if (!g##NAME) {                                                     \
       nsCOMPtr<TYPE> os = do_GetService(CONTRACT_ID);                   \
       g##NAME = os.forget().get();                                      \
     }                                                                   \
     NS_IF_ADDREF(g##NAME);                                              \
     return g##NAME;                                                     \
+  }                                                                     \
+  NS_EXPORT_(already_AddRefed<TYPE>)                                    \
+  mozilla::services::_external_Get##NAME()                              \
+  {                                                                     \
+    return Get##NAME();                                                 \
   }
 
 #include "ServiceList.h"
 #undef MOZ_SERVICE
 
 /**
  * Clears service cache, sets gXPCOMShuttingDown
  */
--- a/xpcom/build/Services.h
+++ b/xpcom/build/Services.h
@@ -47,16 +47,31 @@
 
 #include "ServiceList.h"
 #undef MOZ_SERVICE
 #undef MOZ_USE_NAMESPACE
 
 namespace mozilla {
 namespace services {
 
-#define MOZ_SERVICE(NAME, TYPE, SERVICE_CID) already_AddRefed<TYPE> Get##NAME();
+#ifdef MOZILLA_INTERNAL_API
+#define MOZ_SERVICE(NAME, TYPE, SERVICE_CID)                        \
+    already_AddRefed<TYPE> Get##NAME();                             \
+    NS_EXPORT_(already_AddRefed<TYPE>) _external_Get##NAME();
+
 #include "ServiceList.h"
 #undef MOZ_SERVICE
+#else
+#define MOZ_SERVICE(NAME, TYPE, SERVICE_CID)                        \
+    NS_IMPORT_(already_AddRefed<TYPE>) _external_Get##NAME();       \
+    inline already_AddRefed<TYPE> Get##NAME()                       \
+    {                                                               \
+        return _external_Get##NAME();                               \
+    }
+
+#include "ServiceList.h"
+#undef MOZ_SERVICE
+#endif
 
 } // namespace services
 } // namespace mozilla
 
 #endif