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
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.
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 ***** */
39 #include "nsXPCOMPrivate.h"
40 #include "nsXPCOMStrings.h"
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.
54 NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine
, PRUint32 priority
);
57 NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine
);
59 static const XPCOMFunctions kFrozenFunctions
= {
61 sizeof(XPCOMFunctions
),
64 &NS_GetServiceManager_P
,
65 &NS_GetComponentManager_P
,
66 &NS_GetComponentRegistrar_P
,
67 &NS_GetMemoryManager_P
,
69 &NS_NewNativeLocalFile_P
,
70 &NS_RegisterXPCOMExitRoutine
,
71 &NS_UnregisterXPCOMExitRoutine
,
73 // these functions were added post 1.4
77 // these functions were added post 1.6
78 &NS_StringContainerInit_P
,
79 &NS_StringContainerFinish_P
,
82 &NS_StringSetDataRange_P
,
84 &NS_CStringContainerInit_P
,
85 &NS_CStringContainerFinish_P
,
88 &NS_CStringSetDataRange_P
,
92 &NS_StringCloneData_P
,
93 &NS_CStringCloneData_P
,
95 // these functions were added post 1.7 (post Firefox 1.0)
99 &NS_StringContainerInit2_P
,
100 &NS_CStringContainerInit2_P
,
101 &NS_StringGetMutableData_P
,
102 &NS_CStringGetMutableData_P
,
105 // these functions were added post 1.8
113 &NS_LogCOMPtrAddRef_P
,
114 &NS_LogCOMPtrRelease_P
,
115 &NS_GetXPTCallStub_P
,
116 &NS_DestroyXPTCallStub_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
,
125 // these functions were added post 1.9
126 &NS_CycleCollectorSuspect2_P
,
127 &NS_CycleCollectorForget2_P
130 EXPORT_XPCOM_API(nsresult
)
131 NS_GetFrozenFunctions(XPCOMFunctions
*functions
, const char* /* libraryPath */)
134 return NS_ERROR_OUT_OF_MEMORY
;
136 if (functions
->version
!= XPCOM_GLUE_VERSION
)
137 return NS_ERROR_FAILURE
;
139 PRUint32 size
= functions
->size
;
140 if (size
> sizeof(XPCOMFunctions
))
141 size
= sizeof(XPCOMFunctions
);
143 size
-= offsetof(XPCOMFunctions
, init
);
145 memcpy(&functions
->init
, &kFrozenFunctions
.init
, size
);
151 * Stubs for nsXPCOM.h
155 EXPORT_XPCOM_API(nsresult
)
156 NS_InitXPCOM2(nsIServiceManager
**result
,
157 nsIFile
*binDirectory
,
158 nsIDirectoryServiceProvider
*dirProvider
)
160 return NS_InitXPCOM2_P(result
, binDirectory
, dirProvider
);
163 #undef NS_ShutdownXPCOM
164 EXPORT_XPCOM_API(nsresult
)
165 NS_ShutdownXPCOM(nsIServiceManager
*svcMgr
)
167 return NS_ShutdownXPCOM_P(svcMgr
);
170 #undef NS_GetServiceManager
171 EXPORT_XPCOM_API(nsresult
)
172 NS_GetServiceManager(nsIServiceManager
* *result
)
174 return NS_GetServiceManager_P(result
);
177 #undef NS_GetComponentManager
178 EXPORT_XPCOM_API(nsresult
)
179 NS_GetComponentManager(nsIComponentManager
* *result
)
181 return NS_GetComponentManager_P(result
);
184 #undef NS_GetComponentRegistrar
185 EXPORT_XPCOM_API(nsresult
)
186 NS_GetComponentRegistrar(nsIComponentRegistrar
** result
)
188 return NS_GetComponentRegistrar_P(result
);
191 #undef NS_GetMemoryManager
192 EXPORT_XPCOM_API(nsresult
)
193 NS_GetMemoryManager(nsIMemory
* *result
)
195 return NS_GetMemoryManager_P(result
);
198 #undef NS_NewLocalFile
199 EXPORT_XPCOM_API(nsresult
)
200 NS_NewLocalFile(const nsAString
&path
,
202 nsILocalFile
**result
)
204 return NS_NewLocalFile_P(path
, followLinks
, result
);
207 #undef NS_NewNativeLocalFile
208 EXPORT_XPCOM_API(nsresult
)
209 NS_NewNativeLocalFile(const nsACString
&path
,
211 nsILocalFile
**result
)
213 return NS_NewNativeLocalFile_P(path
, followLinks
, result
);
217 EXPORT_XPCOM_API(nsresult
)
218 NS_GetDebug(nsIDebug
**result
)
220 return NS_GetDebug_P(result
);
223 #undef NS_GetTraceRefcnt
224 EXPORT_XPCOM_API(nsresult
)
225 NS_GetTraceRefcnt(nsITraceRefcnt
**result
)
227 return NS_GetTraceRefcnt_P(result
);
231 EXPORT_XPCOM_API(void*)
232 NS_Alloc(PRSize size
)
234 return NS_Alloc_P(size
);
238 EXPORT_XPCOM_API(void*)
239 NS_Realloc(void* ptr
, PRSize size
)
241 return NS_Realloc_P(ptr
, size
);
245 EXPORT_XPCOM_API(void)
252 EXPORT_XPCOM_API(void)
253 NS_DebugBreak(PRUint32 aSeverity
, const char *aStr
, const char *aExpr
,
254 const char *aFile
, PRInt32 aLine
)
256 NS_DebugBreak_P(aSeverity
, aStr
, aExpr
, aFile
, aLine
);
260 EXPORT_XPCOM_API(void)
267 EXPORT_XPCOM_API(void)
274 EXPORT_XPCOM_API(void)
275 NS_LogAddRef(void* aPtr
, nsrefcnt aNewRefCnt
,
276 const char *aTypeName
, PRUint32 aInstanceSize
)
278 NS_LogAddRef_P(aPtr
, aNewRefCnt
, aTypeName
, aInstanceSize
);
282 EXPORT_XPCOM_API(void)
283 NS_LogRelease(void* aPtr
, nsrefcnt aNewRefCnt
, const char *aTypeName
)
285 NS_LogRelease_P(aPtr
, aNewRefCnt
, aTypeName
);
289 EXPORT_XPCOM_API(void)
290 NS_LogCtor(void *aPtr
, const char *aTypeName
, PRUint32 aInstanceSize
)
292 NS_LogCtor_P(aPtr
, aTypeName
, aInstanceSize
);
296 EXPORT_XPCOM_API(void)
297 NS_LogDtor(void *aPtr
, const char *aTypeName
, PRUint32 aInstanceSize
)
299 NS_LogDtor_P(aPtr
, aTypeName
, aInstanceSize
);
302 #undef NS_LogCOMPtrAddRef
303 EXPORT_XPCOM_API(void)
304 NS_LogCOMPtrAddRef(void *aCOMPtr
, nsISupports
* aObject
)
306 NS_LogCOMPtrAddRef_P(aCOMPtr
, aObject
);
309 #undef NS_LogCOMPtrRelease
310 EXPORT_XPCOM_API(void)
311 NS_LogCOMPtrRelease(void *aCOMPtr
, nsISupports
* aObject
)
313 NS_LogCOMPtrRelease_P(aCOMPtr
, aObject
);
316 #undef NS_GetXPTCallStub
317 EXPORT_XPCOM_API(nsresult
)
318 NS_GetXPTCallStub(REFNSIID aIID
, nsIXPTCProxy
* aOuter
,
319 nsISomeInterface
* *aStub
)
321 return NS_GetXPTCallStub_P(aIID
, aOuter
, aStub
);
324 #undef NS_DestroyXPTCallStub
325 EXPORT_XPCOM_API(void)
326 NS_DestroyXPTCallStub(nsISomeInterface
* aStub
)
328 NS_DestroyXPTCallStub_P(aStub
);
331 #undef NS_InvokeByIndex
332 EXPORT_XPCOM_API(nsresult
)
333 NS_InvokeByIndex(nsISupports
* that
, PRUint32 methodIndex
,
334 PRUint32 paramCount
, nsXPTCVariant
* params
)
336 return NS_InvokeByIndex_P(that
, methodIndex
, paramCount
, params
);
340 * Stubs for nsXPCOMPrivate.h
343 EXPORT_XPCOM_API(nsresult
)
344 NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine
, PRUint32 priority
)
349 EXPORT_XPCOM_API(nsresult
)
350 NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine
)
356 * Stubs for nsStringAPI.h
359 #undef NS_StringContainerInit
360 EXPORT_XPCOM_API(nsresult
)
361 NS_StringContainerInit(nsStringContainer
&aStr
)
363 return NS_StringContainerInit_P(aStr
);
366 #undef NS_StringContainerInit2
367 EXPORT_XPCOM_API(nsresult
)
368 NS_StringContainerInit2(nsStringContainer
&aStr
,
369 const PRUnichar
*aData
,
370 PRUint32 aDataLength
,
373 return NS_StringContainerInit2_P(aStr
, aData
, aDataLength
, aFlags
);
376 #undef NS_StringContainerFinish
377 EXPORT_XPCOM_API(void)
378 NS_StringContainerFinish(nsStringContainer
&aStr
)
380 NS_StringContainerFinish_P(aStr
);
383 #undef NS_StringGetData
384 EXPORT_XPCOM_API(PRUint32
)
385 NS_StringGetData(const nsAString
&aStr
, const PRUnichar
**aBuf
, PRBool
*aTerm
)
387 return NS_StringGetData_P(aStr
, aBuf
, aTerm
);
390 #undef NS_StringGetMutableData
391 EXPORT_XPCOM_API(PRUint32
)
392 NS_StringGetMutableData(nsAString
&aStr
, PRUint32 aLen
, PRUnichar
**aBuf
)
394 return NS_StringGetMutableData_P(aStr
, aLen
, aBuf
);
397 #undef NS_StringCloneData
398 EXPORT_XPCOM_API(PRUnichar
*)
399 NS_StringCloneData(const nsAString
&aStr
)
401 return NS_StringCloneData_P(aStr
);
404 #undef NS_StringSetData
405 EXPORT_XPCOM_API(nsresult
)
406 NS_StringSetData(nsAString
&aStr
, const PRUnichar
*aBuf
, PRUint32 aCount
)
408 return NS_StringSetData_P(aStr
, aBuf
, aCount
);
411 #undef NS_StringSetDataRange
412 EXPORT_XPCOM_API(nsresult
)
413 NS_StringSetDataRange(nsAString
&aStr
, PRUint32 aCutStart
, PRUint32 aCutLength
,
414 const PRUnichar
*aBuf
, PRUint32 aCount
)
416 return NS_StringSetDataRange_P(aStr
, aCutStart
, aCutLength
, aBuf
, aCount
);
420 EXPORT_XPCOM_API(nsresult
)
421 NS_StringCopy(nsAString
&aDest
, const nsAString
&aSrc
)
423 return NS_StringCopy_P(aDest
, aSrc
);
426 #undef NS_StringSetIsVoid
427 EXPORT_XPCOM_API(void)
428 NS_StringSetIsVoid(nsAString
&aStr
, const PRBool aIsVoid
)
430 NS_StringSetIsVoid_P(aStr
, aIsVoid
);
433 #undef NS_StringGetIsVoid
434 EXPORT_XPCOM_API(PRBool
)
435 NS_StringGetIsVoid(const nsAString
&aStr
)
437 return NS_StringGetIsVoid_P(aStr
);
440 #undef NS_CStringContainerInit
441 EXPORT_XPCOM_API(nsresult
)
442 NS_CStringContainerInit(nsCStringContainer
&aStr
)
444 return NS_CStringContainerInit_P(aStr
);
447 #undef NS_CStringContainerInit2
448 EXPORT_XPCOM_API(nsresult
)
449 NS_CStringContainerInit2(nsCStringContainer
&aStr
,
451 PRUint32 aDataLength
,
454 return NS_CStringContainerInit2_P(aStr
, aData
, aDataLength
, aFlags
);
457 #undef NS_CStringContainerFinish
458 EXPORT_XPCOM_API(void)
459 NS_CStringContainerFinish(nsCStringContainer
&aStr
)
461 NS_CStringContainerFinish_P(aStr
);
464 #undef NS_CStringGetData
465 EXPORT_XPCOM_API(PRUint32
)
466 NS_CStringGetData(const nsACString
&aStr
, const char **aBuf
, PRBool
*aTerm
)
468 return NS_CStringGetData_P(aStr
, aBuf
, aTerm
);
471 #undef NS_CStringGetMutableData
472 EXPORT_XPCOM_API(PRUint32
)
473 NS_CStringGetMutableData(nsACString
&aStr
, PRUint32 aLen
, char **aBuf
)
475 return NS_CStringGetMutableData_P(aStr
, aLen
, aBuf
);
478 #undef NS_CStringCloneData
479 EXPORT_XPCOM_API(char *)
480 NS_CStringCloneData(const nsACString
&aStr
)
482 return NS_CStringCloneData_P(aStr
);
485 #undef NS_CStringSetData
486 EXPORT_XPCOM_API(nsresult
)
487 NS_CStringSetData(nsACString
&aStr
, const char *aBuf
, PRUint32 aCount
)
489 return NS_CStringSetData_P(aStr
, aBuf
, aCount
);
492 #undef NS_CStringSetDataRange
493 EXPORT_XPCOM_API(nsresult
)
494 NS_CStringSetDataRange(nsACString
&aStr
, PRUint32 aCutStart
, PRUint32 aCutLength
,
495 const char *aBuf
, PRUint32 aCount
)
497 return NS_CStringSetDataRange_P(aStr
, aCutStart
, aCutLength
, aBuf
, aCount
);
500 #undef NS_CStringCopy
501 EXPORT_XPCOM_API(nsresult
)
502 NS_CStringCopy(nsACString
&aDest
, const nsACString
&aSrc
)
504 return NS_CStringCopy_P(aDest
, aSrc
);
507 #undef NS_CStringSetIsVoid
508 EXPORT_XPCOM_API(void)
509 NS_CStringSetIsVoid(nsACString
&aStr
, const PRBool aIsVoid
)
511 NS_CStringSetIsVoid_P(aStr
, aIsVoid
);
514 #undef NS_CStringGetIsVoid
515 EXPORT_XPCOM_API(PRBool
)
516 NS_CStringGetIsVoid(const nsACString
&aStr
)
518 return NS_CStringGetIsVoid_P(aStr
);
521 #undef NS_CStringToUTF16
522 EXPORT_XPCOM_API(nsresult
)
523 NS_CStringToUTF16(const nsACString
&aSrc
, nsCStringEncoding aSrcEncoding
, nsAString
&aDest
)
525 return NS_CStringToUTF16_P(aSrc
, aSrcEncoding
, aDest
);
528 #undef NS_UTF16ToCString
529 EXPORT_XPCOM_API(nsresult
)
530 NS_UTF16ToCString(const nsAString
&aSrc
, nsCStringEncoding aDestEncoding
, nsACString
&aDest
)
532 return NS_UTF16ToCString_P(aSrc
, aDestEncoding
, aDest
);
535 #undef NS_CycleCollectorSuspect
536 EXPORT_XPCOM_API(PRBool
)
537 NS_CycleCollectorSuspect(nsISupports
* obj
)
539 return NS_CycleCollectorSuspect_P(obj
);
542 #undef NS_CycleCollectorForget
543 EXPORT_XPCOM_API(PRBool
)
544 NS_CycleCollectorForget(nsISupports
* obj
)
546 return NS_CycleCollectorForget_P(obj
);
549 #undef NS_CycleCollectorSuspect2
550 EXPORT_XPCOM_API(nsPurpleBufferEntry
*)
551 NS_CycleCollectorSuspect2(nsISupports
* obj
)
553 return NS_CycleCollectorSuspect2_P(obj
);
556 #undef NS_CycleCollectorForget2
557 EXPORT_XPCOM_API(PRBool
)
558 NS_CycleCollectorForget2(nsPurpleBufferEntry
* e
)
560 return NS_CycleCollectorForget2_P(e
);