Bug 455527 - In some cases Embedding startup crashes if gAppData == null. r=benjamin.
[mozilla-central.git] / xpcom / stub / nsXPComStub.cpp
blobea297f12d772f7657019ea2c53d6835483a114b6
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is Mozilla.
16 * The Initial Developer of the Original Code is IBM Corporation.
17 * Portions created by IBM Corporation are Copyright (C) 2004
18 * IBM Corporation. All Rights Reserved.
20 * Contributor(s):
21 * Darin Fisher <darin@meer.net>
22 * Benjamin Smedberg <benjamin@smedbergs.us>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nsXPCOM.h"
39 #include "nsXPCOMPrivate.h"
40 #include "nsXPCOMStrings.h"
41 #include "xptcall.h"
43 #include <string.h>
45 /**
46 * Private Method to register an exit routine. This method
47 * used to allow you to setup a callback that will be called from
48 * the NS_ShutdownXPCOM function after all services and
49 * components have gone away. It was fatally flawed in that the component
50 * DLL could be released before the exit function was called; it is now a
51 * stub implementation that does nothing.
53 XPCOM_API(nsresult)
54 NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, PRUint32 priority);
56 XPCOM_API(nsresult)
57 NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine);
59 static const XPCOMFunctions kFrozenFunctions = {
60 XPCOM_GLUE_VERSION,
61 sizeof(XPCOMFunctions),
62 &NS_InitXPCOM2_P,
63 &NS_ShutdownXPCOM_P,
64 &NS_GetServiceManager_P,
65 &NS_GetComponentManager_P,
66 &NS_GetComponentRegistrar_P,
67 &NS_GetMemoryManager_P,
68 &NS_NewLocalFile_P,
69 &NS_NewNativeLocalFile_P,
70 &NS_RegisterXPCOMExitRoutine,
71 &NS_UnregisterXPCOMExitRoutine,
73 // these functions were added post 1.4
74 &NS_GetDebug_P,
75 &NS_GetTraceRefcnt_P,
77 // these functions were added post 1.6
78 &NS_StringContainerInit_P,
79 &NS_StringContainerFinish_P,
80 &NS_StringGetData_P,
81 &NS_StringSetData_P,
82 &NS_StringSetDataRange_P,
83 &NS_StringCopy_P,
84 &NS_CStringContainerInit_P,
85 &NS_CStringContainerFinish_P,
86 &NS_CStringGetData_P,
87 &NS_CStringSetData_P,
88 &NS_CStringSetDataRange_P,
89 &NS_CStringCopy_P,
90 &NS_CStringToUTF16_P,
91 &NS_UTF16ToCString_P,
92 &NS_StringCloneData_P,
93 &NS_CStringCloneData_P,
95 // these functions were added post 1.7 (post Firefox 1.0)
96 &NS_Alloc_P,
97 &NS_Realloc_P,
98 &NS_Free_P,
99 &NS_StringContainerInit2_P,
100 &NS_CStringContainerInit2_P,
101 &NS_StringGetMutableData_P,
102 &NS_CStringGetMutableData_P,
103 &NS_InitXPCOM3_P,
105 // these functions were added post 1.8
106 &NS_DebugBreak_P,
107 &NS_LogInit_P,
108 &NS_LogTerm_P,
109 &NS_LogAddRef_P,
110 &NS_LogRelease_P,
111 &NS_LogCtor_P,
112 &NS_LogDtor_P,
113 &NS_LogCOMPtrAddRef_P,
114 &NS_LogCOMPtrRelease_P,
115 &NS_GetXPTCallStub_P,
116 &NS_DestroyXPTCallStub_P,
117 &NS_InvokeByIndex_P,
118 &NS_CycleCollectorSuspect_P,
119 &NS_CycleCollectorForget_P,
120 &NS_StringSetIsVoid_P,
121 &NS_StringGetIsVoid_P,
122 &NS_CStringSetIsVoid_P,
123 &NS_CStringGetIsVoid_P
126 EXPORT_XPCOM_API(nsresult)
127 NS_GetFrozenFunctions(XPCOMFunctions *functions, const char* /* libraryPath */)
129 if (!functions)
130 return NS_ERROR_OUT_OF_MEMORY;
132 if (functions->version != XPCOM_GLUE_VERSION)
133 return NS_ERROR_FAILURE;
135 PRUint32 size = functions->size;
136 if (size > sizeof(XPCOMFunctions))
137 size = sizeof(XPCOMFunctions);
139 size -= offsetof(XPCOMFunctions, init);
141 memcpy(&functions->init, &kFrozenFunctions.init, size);
143 return NS_OK;
147 * Stubs for nsXPCOM.h
150 #undef NS_InitXPCOM2
151 EXPORT_XPCOM_API(nsresult)
152 NS_InitXPCOM2(nsIServiceManager **result,
153 nsIFile *binDirectory,
154 nsIDirectoryServiceProvider *dirProvider)
156 return NS_InitXPCOM2_P(result, binDirectory, dirProvider);
159 #undef NS_InitXPCOM3
160 EXPORT_XPCOM_API(nsresult)
161 NS_InitXPCOM3(nsIServiceManager **result,
162 nsIFile *binDirectory,
163 nsIDirectoryServiceProvider *dirProvider,
164 nsStaticModuleInfo const *staticComponents,
165 PRUint32 componentCount)
167 return NS_InitXPCOM3_P(result, binDirectory, dirProvider,
168 staticComponents, componentCount);
171 #undef NS_ShutdownXPCOM
172 EXPORT_XPCOM_API(nsresult)
173 NS_ShutdownXPCOM(nsIServiceManager *svcMgr)
175 return NS_ShutdownXPCOM_P(svcMgr);
178 #undef NS_GetServiceManager
179 EXPORT_XPCOM_API(nsresult)
180 NS_GetServiceManager(nsIServiceManager* *result)
182 return NS_GetServiceManager_P(result);
185 #undef NS_GetComponentManager
186 EXPORT_XPCOM_API(nsresult)
187 NS_GetComponentManager(nsIComponentManager* *result)
189 return NS_GetComponentManager_P(result);
192 #undef NS_GetComponentRegistrar
193 EXPORT_XPCOM_API(nsresult)
194 NS_GetComponentRegistrar(nsIComponentRegistrar* *result)
196 return NS_GetComponentRegistrar_P(result);
199 #undef NS_GetMemoryManager
200 EXPORT_XPCOM_API(nsresult)
201 NS_GetMemoryManager(nsIMemory* *result)
203 return NS_GetMemoryManager_P(result);
206 #undef NS_NewLocalFile
207 EXPORT_XPCOM_API(nsresult)
208 NS_NewLocalFile(const nsAString &path,
209 PRBool followLinks,
210 nsILocalFile **result)
212 return NS_NewLocalFile_P(path, followLinks, result);
215 #undef NS_NewNativeLocalFile
216 EXPORT_XPCOM_API(nsresult)
217 NS_NewNativeLocalFile(const nsACString &path,
218 PRBool followLinks,
219 nsILocalFile **result)
221 return NS_NewNativeLocalFile_P(path, followLinks, result);
224 #undef NS_GetDebug
225 EXPORT_XPCOM_API(nsresult)
226 NS_GetDebug(nsIDebug **result)
228 return NS_GetDebug_P(result);
231 #undef NS_GetTraceRefcnt
232 EXPORT_XPCOM_API(nsresult)
233 NS_GetTraceRefcnt(nsITraceRefcnt **result)
235 return NS_GetTraceRefcnt_P(result);
238 #undef NS_Alloc
239 EXPORT_XPCOM_API(void*)
240 NS_Alloc(PRSize size)
242 return NS_Alloc_P(size);
245 #undef NS_Realloc
246 EXPORT_XPCOM_API(void*)
247 NS_Realloc(void* ptr, PRSize size)
249 return NS_Realloc_P(ptr, size);
252 #undef NS_Free
253 EXPORT_XPCOM_API(void)
254 NS_Free(void* ptr)
256 NS_Free_P(ptr);
259 #undef NS_DebugBreak
260 EXPORT_XPCOM_API(void)
261 NS_DebugBreak(PRUint32 aSeverity, const char *aStr, const char *aExpr,
262 const char *aFile, PRInt32 aLine)
264 NS_DebugBreak_P(aSeverity, aStr, aExpr, aFile, aLine);
267 #undef NS_LogInit
268 EXPORT_XPCOM_API(void)
269 NS_LogInit()
271 NS_LogInit_P();
274 #undef NS_LogTerm
275 EXPORT_XPCOM_API(void)
276 NS_LogTerm()
278 NS_LogTerm_P();
281 #undef NS_LogAddRef
282 EXPORT_XPCOM_API(void)
283 NS_LogAddRef(void* aPtr, nsrefcnt aNewRefCnt,
284 const char *aTypeName, PRUint32 aInstanceSize)
286 NS_LogAddRef_P(aPtr, aNewRefCnt, aTypeName, aInstanceSize);
289 #undef NS_LogRelease
290 EXPORT_XPCOM_API(void)
291 NS_LogRelease(void* aPtr, nsrefcnt aNewRefCnt, const char *aTypeName)
293 NS_LogRelease_P(aPtr, aNewRefCnt, aTypeName);
296 #undef NS_LogCtor
297 EXPORT_XPCOM_API(void)
298 NS_LogCtor(void *aPtr, const char *aTypeName, PRUint32 aInstanceSize)
300 NS_LogCtor_P(aPtr, aTypeName, aInstanceSize);
303 #undef NS_LogDtor
304 EXPORT_XPCOM_API(void)
305 NS_LogDtor(void *aPtr, const char *aTypeName, PRUint32 aInstanceSize)
307 NS_LogDtor_P(aPtr, aTypeName, aInstanceSize);
310 #undef NS_LogCOMPtrAddRef
311 EXPORT_XPCOM_API(void)
312 NS_LogCOMPtrAddRef(void *aCOMPtr, nsISupports* aObject)
314 NS_LogCOMPtrAddRef_P(aCOMPtr, aObject);
317 #undef NS_LogCOMPtrRelease
318 EXPORT_XPCOM_API(void)
319 NS_LogCOMPtrRelease(void *aCOMPtr, nsISupports* aObject)
321 NS_LogCOMPtrRelease_P(aCOMPtr, aObject);
324 #undef NS_GetXPTCallStub
325 EXPORT_XPCOM_API(nsresult)
326 NS_GetXPTCallStub(REFNSIID aIID, nsIXPTCProxy* aOuter,
327 nsISomeInterface* *aStub)
329 return NS_GetXPTCallStub_P(aIID, aOuter, aStub);
332 #undef NS_DestroyXPTCallStub
333 EXPORT_XPCOM_API(void)
334 NS_DestroyXPTCallStub(nsISomeInterface* aStub)
336 NS_DestroyXPTCallStub_P(aStub);
339 #undef NS_InvokeByIndex
340 EXPORT_XPCOM_API(nsresult)
341 NS_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
342 PRUint32 paramCount, nsXPTCVariant* params)
344 return NS_InvokeByIndex_P(that, methodIndex, paramCount, params);
348 * Stubs for nsXPCOMPrivate.h
351 EXPORT_XPCOM_API(nsresult)
352 NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, PRUint32 priority)
354 return NS_OK;
357 EXPORT_XPCOM_API(nsresult)
358 NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine)
360 return NS_OK;
364 * Stubs for nsStringAPI.h
367 #undef NS_StringContainerInit
368 EXPORT_XPCOM_API(nsresult)
369 NS_StringContainerInit(nsStringContainer &aStr)
371 return NS_StringContainerInit_P(aStr);
374 #undef NS_StringContainerInit2
375 EXPORT_XPCOM_API(nsresult)
376 NS_StringContainerInit2(nsStringContainer &aStr,
377 const PRUnichar *aData,
378 PRUint32 aDataLength,
379 PRUint32 aFlags)
381 return NS_StringContainerInit2_P(aStr, aData, aDataLength, aFlags);
384 #undef NS_StringContainerFinish
385 EXPORT_XPCOM_API(void)
386 NS_StringContainerFinish(nsStringContainer &aStr)
388 NS_StringContainerFinish_P(aStr);
391 #undef NS_StringGetData
392 EXPORT_XPCOM_API(PRUint32)
393 NS_StringGetData(const nsAString &aStr, const PRUnichar **aBuf, PRBool *aTerm)
395 return NS_StringGetData_P(aStr, aBuf, aTerm);
398 #undef NS_StringGetMutableData
399 EXPORT_XPCOM_API(PRUint32)
400 NS_StringGetMutableData(nsAString &aStr, PRUint32 aLen, PRUnichar **aBuf)
402 return NS_StringGetMutableData_P(aStr, aLen, aBuf);
405 #undef NS_StringCloneData
406 EXPORT_XPCOM_API(PRUnichar *)
407 NS_StringCloneData(const nsAString &aStr)
409 return NS_StringCloneData_P(aStr);
412 #undef NS_StringSetData
413 EXPORT_XPCOM_API(nsresult)
414 NS_StringSetData(nsAString &aStr, const PRUnichar *aBuf, PRUint32 aCount)
416 return NS_StringSetData_P(aStr, aBuf, aCount);
419 #undef NS_StringSetDataRange
420 EXPORT_XPCOM_API(nsresult)
421 NS_StringSetDataRange(nsAString &aStr, PRUint32 aCutStart, PRUint32 aCutLength,
422 const PRUnichar *aBuf, PRUint32 aCount)
424 return NS_StringSetDataRange_P(aStr, aCutStart, aCutLength, aBuf, aCount);
427 #undef NS_StringCopy
428 EXPORT_XPCOM_API(nsresult)
429 NS_StringCopy(nsAString &aDest, const nsAString &aSrc)
431 return NS_StringCopy_P(aDest, aSrc);
434 #undef NS_StringSetIsVoid
435 EXPORT_XPCOM_API(void)
436 NS_StringSetIsVoid(nsAString &aStr, const PRBool aIsVoid)
438 NS_StringSetIsVoid_P(aStr, aIsVoid);
441 #undef NS_StringGetIsVoid
442 EXPORT_XPCOM_API(PRBool)
443 NS_StringGetIsVoid(const nsAString &aStr)
445 return NS_StringGetIsVoid_P(aStr);
448 #undef NS_CStringContainerInit
449 EXPORT_XPCOM_API(nsresult)
450 NS_CStringContainerInit(nsCStringContainer &aStr)
452 return NS_CStringContainerInit_P(aStr);
455 #undef NS_CStringContainerInit2
456 EXPORT_XPCOM_API(nsresult)
457 NS_CStringContainerInit2(nsCStringContainer &aStr,
458 const char *aData,
459 PRUint32 aDataLength,
460 PRUint32 aFlags)
462 return NS_CStringContainerInit2_P(aStr, aData, aDataLength, aFlags);
465 #undef NS_CStringContainerFinish
466 EXPORT_XPCOM_API(void)
467 NS_CStringContainerFinish(nsCStringContainer &aStr)
469 NS_CStringContainerFinish_P(aStr);
472 #undef NS_CStringGetData
473 EXPORT_XPCOM_API(PRUint32)
474 NS_CStringGetData(const nsACString &aStr, const char **aBuf, PRBool *aTerm)
476 return NS_CStringGetData_P(aStr, aBuf, aTerm);
479 #undef NS_CStringGetMutableData
480 EXPORT_XPCOM_API(PRUint32)
481 NS_CStringGetMutableData(nsACString &aStr, PRUint32 aLen, char **aBuf)
483 return NS_CStringGetMutableData_P(aStr, aLen, aBuf);
486 #undef NS_CStringCloneData
487 EXPORT_XPCOM_API(char *)
488 NS_CStringCloneData(const nsACString &aStr)
490 return NS_CStringCloneData_P(aStr);
493 #undef NS_CStringSetData
494 EXPORT_XPCOM_API(nsresult)
495 NS_CStringSetData(nsACString &aStr, const char *aBuf, PRUint32 aCount)
497 return NS_CStringSetData_P(aStr, aBuf, aCount);
500 #undef NS_CStringSetDataRange
501 EXPORT_XPCOM_API(nsresult)
502 NS_CStringSetDataRange(nsACString &aStr, PRUint32 aCutStart, PRUint32 aCutLength,
503 const char *aBuf, PRUint32 aCount)
505 return NS_CStringSetDataRange_P(aStr, aCutStart, aCutLength, aBuf, aCount);
508 #undef NS_CStringCopy
509 EXPORT_XPCOM_API(nsresult)
510 NS_CStringCopy(nsACString &aDest, const nsACString &aSrc)
512 return NS_CStringCopy_P(aDest, aSrc);
515 #undef NS_CStringSetIsVoid
516 EXPORT_XPCOM_API(void)
517 NS_CStringSetIsVoid(nsACString &aStr, const PRBool aIsVoid)
519 NS_CStringSetIsVoid_P(aStr, aIsVoid);
522 #undef NS_CStringGetIsVoid
523 EXPORT_XPCOM_API(PRBool)
524 NS_CStringGetIsVoid(const nsACString &aStr)
526 return NS_CStringGetIsVoid_P(aStr);
529 #undef NS_CStringToUTF16
530 EXPORT_XPCOM_API(nsresult)
531 NS_CStringToUTF16(const nsACString &aSrc, nsCStringEncoding aSrcEncoding, nsAString &aDest)
533 return NS_CStringToUTF16_P(aSrc, aSrcEncoding, aDest);
536 #undef NS_UTF16ToCString
537 EXPORT_XPCOM_API(nsresult)
538 NS_UTF16ToCString(const nsAString &aSrc, nsCStringEncoding aDestEncoding, nsACString &aDest)
540 return NS_UTF16ToCString_P(aSrc, aDestEncoding, aDest);
543 #undef NS_CycleCollectorSuspect
544 EXPORT_XPCOM_API(PRBool)
545 NS_CycleCollectorSuspect(nsISupports* obj)
547 return NS_CycleCollectorSuspect_P(obj);
550 #undef NS_CycleCollectorForget
551 EXPORT_XPCOM_API(PRBool)
552 NS_CycleCollectorForget(nsISupports* obj)
554 return NS_CycleCollectorForget_P(obj);