Back to index

lightning-sunbird  0.9+nobinonly
xptcstubs_emx.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /* Implement shared vtbl methods */
00039 
00040 // This is a 98% copy of other implementations; see comment at top of
00041 // xptcinvoke_emx.cpp for why this file exists.
00042 //
00043 
00044 #include "xptcprivate.h"
00045 
00046 #if !defined(__EMX__)
00047 #error "This code is for OS/2 EMX only"
00048 #endif
00049 
00050 static nsresult
00051 PrepareAndDispatch( nsXPTCStubBase *self, PRUint32 methodIndex,
00052                     PRUint32 *args)
00053 {
00054 #define PARAM_BUFFER_COUNT     16
00055 
00056     nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
00057     nsXPTCMiniVariant* dispatchParams = NULL;
00058     nsIInterfaceInfo* iface_info = NULL;
00059     const nsXPTMethodInfo* info;
00060     PRUint8 paramCount;
00061     PRUint8 i;
00062     nsresult result = NS_ERROR_FAILURE;
00063 
00064     // If anything fails before stackBytesToPop can be set then
00065     // the failure is completely catastrophic!
00066 
00067     NS_ASSERTION(self,"no self");
00068 
00069     self->GetInterfaceInfo(&iface_info);
00070     NS_ASSERTION(iface_info,"no interface info");
00071 
00072     iface_info->GetMethodInfo(PRUint16(methodIndex), &info);
00073     NS_ASSERTION(info,"no interface info");
00074 
00075     paramCount = info->GetParamCount();
00076 
00077     // setup variant array pointer
00078     if(paramCount > PARAM_BUFFER_COUNT)
00079         dispatchParams = new nsXPTCMiniVariant[paramCount];
00080     else
00081         dispatchParams = paramBuffer;
00082     NS_ASSERTION(dispatchParams,"no place for params");
00083 
00084     PRUint32* ap = args;
00085     for(i = 0; i < paramCount; i++, ap++)
00086     {
00087         const nsXPTParamInfo& param = info->GetParam(i);
00088         const nsXPTType& type = param.GetType();
00089         nsXPTCMiniVariant* dp = &dispatchParams[i];
00090 
00091         if(param.IsOut() || !type.IsArithmetic())
00092         {
00093             dp->val.p = (void*) *ap;
00094             continue;
00095         }
00096         // else
00097         switch(type)
00098         {
00099         case nsXPTType::T_I8     : dp->val.i8  = *((PRInt8*)  ap);       break;
00100         case nsXPTType::T_I16    : dp->val.i16 = *((PRInt16*) ap);       break;
00101         case nsXPTType::T_I32    : dp->val.i32 = *((PRInt32*) ap);       break;
00102         case nsXPTType::T_I64    : dp->val.i64 = *((PRInt64*) ap); ap++; break;
00103         case nsXPTType::T_U8     : dp->val.u8  = *((PRUint8*) ap);       break;
00104         case nsXPTType::T_U16    : dp->val.u16 = *((PRUint16*)ap);       break;
00105         case nsXPTType::T_U32    : dp->val.u32 = *((PRUint32*)ap);       break;
00106         case nsXPTType::T_U64    : dp->val.u64 = *((PRUint64*)ap); ap++; break;
00107         case nsXPTType::T_FLOAT  : dp->val.f   = *((float*)   ap);       break;
00108         case nsXPTType::T_DOUBLE : dp->val.d   = *((double*)  ap); ap++; break;
00109         case nsXPTType::T_BOOL   : dp->val.b   = *((PRBool*)  ap);       break;
00110         case nsXPTType::T_CHAR   : dp->val.c   = *((char*)    ap);       break;
00111         case nsXPTType::T_WCHAR  : dp->val.wc  = *((wchar_t*) ap);       break;
00112         default:
00113             NS_ASSERTION(0, "bad type");
00114             break;
00115         }
00116     }
00117 
00118     result = self->CallMethod((PRUint16)methodIndex, info, dispatchParams);
00119 
00120     NS_RELEASE(iface_info);
00121 
00122     if(dispatchParams != paramBuffer)
00123         delete [] dispatchParams;
00124 
00125     return result;
00126 }
00127 
00128 #define STUB_ENTRY(n) \
00129 nsresult nsXPTCStubBase::Stub##n() \
00130 { \
00131   register void* method = PrepareAndDispatch; \
00132   register nsresult result; \
00133   __asm__ __volatile__( \
00134     "leal   0x0c(%%ebp), %%ecx\n\t"    /* args */ \
00135     "pushl  %%ecx\n\t" \
00136     "pushl  $"#n"\n\t"                 /* method index */ \
00137     "movl   0x08(%%ebp), %%ecx\n\t"    /* this */ \
00138     "pushl  %%ecx\n\t" \
00139     "call   *%%edx"                    /* PrepareAndDispatch */ \
00140     : "=a" (result)     /* %0 */ \
00141     : "d" (method)      /* %1 */ \
00142     : "ax", "dx", "cx", "memory" ); \
00143     return result; \
00144 }
00145 
00146 #define SENTINEL_ENTRY(n) \
00147 nsresult nsXPTCStubBase::Sentinel##n() \
00148 { \
00149     NS_ASSERTION(0,"nsXPCWrappedJS::Sentinel called"); \
00150     return NS_ERROR_NOT_IMPLEMENTED; \
00151 }
00152 
00153 #include "xptcstubsdef.inc"