xpcom/build/FrozenFunctions.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/build/FrozenFunctions.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,133 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#include "nsXPCOM.h"
     1.9 +#include "nsXPCOMPrivate.h"
    1.10 +#include "nsXPCOMStrings.h"
    1.11 +#include "xptcall.h"
    1.12 +
    1.13 +#include <string.h>
    1.14 +
    1.15 +/**
    1.16 + * Private Method to register an exit routine.  This method
    1.17 + * used to allow you to setup a callback that will be called from 
    1.18 + * the NS_ShutdownXPCOM function after all services and 
    1.19 + * components have gone away. It was fatally flawed in that the component
    1.20 + * DLL could be released before the exit function was called; it is now a
    1.21 + * stub implementation that does nothing.
    1.22 + */
    1.23 +XPCOM_API(nsresult)
    1.24 +NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, uint32_t priority);
    1.25 +
    1.26 +XPCOM_API(nsresult)
    1.27 +NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine);
    1.28 +
    1.29 +static const XPCOMFunctions kFrozenFunctions = {
    1.30 +    XPCOM_GLUE_VERSION,
    1.31 +    sizeof(XPCOMFunctions),
    1.32 +    &NS_InitXPCOM2,
    1.33 +    &NS_ShutdownXPCOM,
    1.34 +    &NS_GetServiceManager,
    1.35 +    &NS_GetComponentManager,
    1.36 +    &NS_GetComponentRegistrar,
    1.37 +    &NS_GetMemoryManager,
    1.38 +    &NS_NewLocalFile,
    1.39 +    &NS_NewNativeLocalFile,
    1.40 +    &NS_RegisterXPCOMExitRoutine,
    1.41 +    &NS_UnregisterXPCOMExitRoutine,
    1.42 +
    1.43 +    // these functions were added post 1.4
    1.44 +    &NS_GetDebug,
    1.45 +    nullptr,
    1.46 +
    1.47 +    // these functions were added post 1.6
    1.48 +    &NS_StringContainerInit,
    1.49 +    &NS_StringContainerFinish,
    1.50 +    &NS_StringGetData,
    1.51 +    &NS_StringSetData,
    1.52 +    &NS_StringSetDataRange,
    1.53 +    &NS_StringCopy,
    1.54 +    &NS_CStringContainerInit,
    1.55 +    &NS_CStringContainerFinish,
    1.56 +    &NS_CStringGetData,
    1.57 +    &NS_CStringSetData,
    1.58 +    &NS_CStringSetDataRange,
    1.59 +    &NS_CStringCopy,
    1.60 +    &NS_CStringToUTF16,
    1.61 +    &NS_UTF16ToCString,
    1.62 +    &NS_StringCloneData,
    1.63 +    &NS_CStringCloneData,
    1.64 +
    1.65 +    // these functions were added post 1.7 (post Firefox 1.0)
    1.66 +    &NS_Alloc,
    1.67 +    &NS_Realloc,
    1.68 +    &NS_Free,
    1.69 +    &NS_StringContainerInit2,
    1.70 +    &NS_CStringContainerInit2,
    1.71 +    &NS_StringGetMutableData,
    1.72 +    &NS_CStringGetMutableData,
    1.73 +    nullptr,
    1.74 +
    1.75 +    // these functions were added post 1.8
    1.76 +    &NS_DebugBreak,
    1.77 +    &NS_LogInit,
    1.78 +    &NS_LogTerm,
    1.79 +    &NS_LogAddRef,
    1.80 +    &NS_LogRelease,
    1.81 +    &NS_LogCtor,
    1.82 +    &NS_LogDtor,
    1.83 +    &NS_LogCOMPtrAddRef,
    1.84 +    &NS_LogCOMPtrRelease,
    1.85 +    &NS_GetXPTCallStub,
    1.86 +    &NS_DestroyXPTCallStub,
    1.87 +    &NS_InvokeByIndex,
    1.88 +    nullptr,
    1.89 +    nullptr,
    1.90 +    &NS_StringSetIsVoid,
    1.91 +    &NS_StringGetIsVoid,
    1.92 +    &NS_CStringSetIsVoid,
    1.93 +    &NS_CStringGetIsVoid,
    1.94 +
    1.95 +    // these functions were added post 1.9, but then made obsolete
    1.96 +    nullptr,
    1.97 +    nullptr,
    1.98 +
    1.99 +    &NS_CycleCollectorSuspect3,
   1.100 +};
   1.101 +
   1.102 +EXPORT_XPCOM_API(nsresult)
   1.103 +NS_GetFrozenFunctions(XPCOMFunctions *functions, const char* /* libraryPath */)
   1.104 +{
   1.105 +    if (!functions)
   1.106 +        return NS_ERROR_OUT_OF_MEMORY;
   1.107 +
   1.108 +    if (functions->version != XPCOM_GLUE_VERSION)
   1.109 +        return NS_ERROR_FAILURE;
   1.110 +
   1.111 +    uint32_t size = functions->size;
   1.112 +    if (size > sizeof(XPCOMFunctions))
   1.113 +        size = sizeof(XPCOMFunctions);
   1.114 +
   1.115 +    size -= offsetof(XPCOMFunctions, init);
   1.116 +
   1.117 +    memcpy(&functions->init, &kFrozenFunctions.init, size);
   1.118 +
   1.119 +    return NS_OK;
   1.120 +}
   1.121 +
   1.122 +/*
   1.123 + * Stubs for nsXPCOMPrivate.h
   1.124 + */
   1.125 +
   1.126 +EXPORT_XPCOM_API(nsresult)
   1.127 +NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, uint32_t priority)
   1.128 +{
   1.129 +  return NS_OK;
   1.130 +}
   1.131 +
   1.132 +EXPORT_XPCOM_API(nsresult)
   1.133 +NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine)
   1.134 +{
   1.135 +  return NS_OK;
   1.136 +}

mercurial