xref: /trunk/main/bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_bridges.hxx"
30 
31 #include <exception>
32 #include <typeinfo>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 
37 #include "rtl/alloc.h"
38 #include "rtl/ustrbuf.hxx"
39 
40 #include <com/sun/star/uno/genfunc.hxx>
41 #include "com/sun/star/uno/RuntimeException.hpp"
42 #include <uno/data.h>
43 
44 #include <bridges/cpp_uno/shared/bridge.hxx>
45 #include <bridges/cpp_uno/shared/types.hxx>
46 #include "bridges/cpp_uno/shared/unointerfaceproxy.hxx"
47 #include "bridges/cpp_uno/shared/vtables.hxx"
48 
49 #include "abi.hxx"
50 #include "share.hxx"
51 
52 using namespace ::rtl;
53 using namespace ::com::sun::star::uno;
54 
55 //==================================================================================================
56 static void callVirtualMethod(void * pThis, sal_uInt32 nVtableIndex,
57                               void * pRegisterReturn, typelib_TypeDescriptionReference * pReturnTypeRef, bool bSimpleReturn,
58                               sal_uInt64 *pStack, sal_uInt32 nStack,
59                               sal_uInt64 *pGPR, sal_uInt32 nGPR,
60                               double *pFPR, sal_uInt32 nFPR) __attribute__((noinline));
61 
62 static void callVirtualMethod(void * pThis, sal_uInt32 nVtableIndex,
63                               void * pRegisterReturn, typelib_TypeDescriptionReference * pReturnTypeRef, bool bSimpleReturn,
64                               sal_uInt64 *pStack, sal_uInt32 nStack,
65                               sal_uInt64 *pGPR, sal_uInt32 nGPR,
66                               double *pFPR, sal_uInt32 nFPR)
67 {
68 #if OSL_DEBUG_LEVEL > 1
69     // Let's figure out what is really going on here
70     {
71         fprintf( stderr, "= callVirtualMethod() =\nGPR's (%d): ", nGPR );
72         for ( unsigned int i = 0; i < nGPR; ++i )
73             fprintf( stderr, "0x%lx, ", pGPR[i] );
74         fprintf( stderr, "\nFPR's (%d): ", nFPR );
75         for ( unsigned int i = 0; i < nFPR; ++i )
76             fprintf( stderr, "%f, ", pFPR[i] );
77         fprintf( stderr, "\nStack (%d): ", nStack );
78         for ( unsigned int i = 0; i < nStack; ++i )
79             fprintf( stderr, "0x%lx, ", pStack[i] );
80         fprintf( stderr, "\n" );
81     }
82 #endif
83 
84     // The call instruction within the asm section of callVirtualMethod may throw
85     // exceptions.  So that the compiler handles this correctly, it is important
86     // that (a) callVirtualMethod might call dummy_can_throw_anything (although this
87     // never happens at runtime), which in turn can throw exceptions, and (b)
88     // callVirtualMethod is not inlined at its call site (so that any exceptions are
89     // caught which are thrown from the instruction calling callVirtualMethod):
90     if ( !pThis )
91         CPPU_CURRENT_NAMESPACE::dummy_can_throw_anything( "xxx" ); // address something
92 
93     // Should not happen, but...
94     if ( nFPR > x86_64::MAX_SSE_REGS )
95         nFPR = x86_64::MAX_SSE_REGS;
96     if ( nGPR > x86_64::MAX_GPR_REGS )
97         nGPR = x86_64::MAX_GPR_REGS;
98 
99     // Get pointer to method
100     sal_uInt64 pMethod = *((sal_uInt64 *)pThis);
101     pMethod += 8 * nVtableIndex;
102     pMethod = *((sal_uInt64 *)pMethod);
103 
104     // Load parameters to stack, if necessary
105     if ( nStack )
106     {
107         // 16-bytes aligned
108         sal_uInt32 nStackBytes = ( ( nStack + 1 ) >> 1 ) * 16;
109         sal_uInt64 *pCallStack = (sal_uInt64 *) __builtin_alloca( nStackBytes );
110         memcpy( pCallStack, pStack, nStackBytes );
111     }
112 
113     // Return values
114     sal_uInt64 rax;
115     sal_uInt64 rdx;
116     double xmm0;
117     double xmm1;
118 
119     asm volatile (
120 
121         // Fill the xmm registers
122         "movq %2, %%rax\n\t"
123 
124         "movsd   (%%rax), %%xmm0\n\t"
125         "movsd  8(%%rax), %%xmm1\n\t"
126         "movsd 16(%%rax), %%xmm2\n\t"
127         "movsd 24(%%rax), %%xmm3\n\t"
128         "movsd 32(%%rax), %%xmm4\n\t"
129         "movsd 40(%%rax), %%xmm5\n\t"
130         "movsd 48(%%rax), %%xmm6\n\t"
131         "movsd 56(%%rax), %%xmm7\n\t"
132 
133         // Fill the general purpose registers
134         "movq %1, %%rax\n\t"
135 
136         "movq    (%%rax), %%rdi\n\t"
137         "movq   8(%%rax), %%rsi\n\t"
138         "movq  16(%%rax), %%rdx\n\t"
139         "movq  24(%%rax), %%rcx\n\t"
140         "movq  32(%%rax), %%r8\n\t"
141         "movq  40(%%rax), %%r9\n\t"
142 
143         // Perform the call
144         "movq %0, %%r11\n\t"
145         "movq %3, %%rax\n\t"
146         "call *%%r11\n\t"
147 
148         // Fill the return values
149         "movq   %%rax, %4\n\t"
150         "movq   %%rdx, %5\n\t"
151         "movsd %%xmm0, %6\n\t"
152         "movsd %%xmm1, %7\n\t"
153         :
154         : "m" ( pMethod ), "m" ( pGPR ), "m" ( pFPR ), "m" ( nFPR ),
155           "m" ( rax ), "m" ( rdx ), "m" ( xmm0 ), "m" ( xmm1 )
156         : "rax", "rdi", "rsi", "rdx", "rcx", "r8", "r9", "r11"
157     );
158 
159     switch (pReturnTypeRef->eTypeClass)
160     {
161     case typelib_TypeClass_HYPER:
162     case typelib_TypeClass_UNSIGNED_HYPER:
163         *reinterpret_cast<sal_uInt64 *>( pRegisterReturn ) = rax;
164         break;
165     case typelib_TypeClass_LONG:
166     case typelib_TypeClass_UNSIGNED_LONG:
167     case typelib_TypeClass_ENUM:
168         *reinterpret_cast<sal_uInt32 *>( pRegisterReturn ) = *reinterpret_cast<sal_uInt32*>( &rax );
169         break;
170     case typelib_TypeClass_CHAR:
171     case typelib_TypeClass_SHORT:
172     case typelib_TypeClass_UNSIGNED_SHORT:
173         *reinterpret_cast<sal_uInt16 *>( pRegisterReturn ) = *reinterpret_cast<sal_uInt16*>( &rax );
174         break;
175     case typelib_TypeClass_BOOLEAN:
176     case typelib_TypeClass_BYTE:
177         *reinterpret_cast<sal_uInt8 *>( pRegisterReturn ) = *reinterpret_cast<sal_uInt8*>( &rax );
178         break;
179     case typelib_TypeClass_FLOAT:
180     case typelib_TypeClass_DOUBLE:
181         *reinterpret_cast<double *>( pRegisterReturn ) = xmm0;
182         break;
183     default:
184         {
185             sal_Int32 const nRetSize = pReturnTypeRef->pType->nSize;
186             if (bSimpleReturn && nRetSize <= 16 && nRetSize > 0)
187             {
188                 sal_uInt64 longs[2];
189                 longs[0] = rax;
190                 longs[1] = rdx;
191 
192                 double doubles[2];
193                 doubles[0] = xmm0;
194                 doubles[1] = xmm1;
195                 x86_64::fill_struct( pReturnTypeRef, &longs[0], &doubles[0], pRegisterReturn);
196             }
197             break;
198         }
199     }
200 }
201 
202 //==================================================================================================
203 
204 // Macros for easier insertion of values to registers or stack
205 // pSV - pointer to the source
206 // nr - order of the value [will be increased if stored to register]
207 // pFPR, pGPR - pointer to the registers
208 // pDS - pointer to the stack [will be increased if stored here]
209 
210 // The value in %xmm register is already prepared to be retrieved as a float,
211 // thus we treat float and double the same
212 #define INSERT_FLOAT_DOUBLE( pSV, nr, pFPR, pDS ) \
213     if ( nr < x86_64::MAX_SSE_REGS ) \
214         pFPR[nr++] = *reinterpret_cast<double *>( pSV ); \
215     else \
216         *pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV ); // verbatim!
217 
218 #define INSERT_INT64( pSV, nr, pGPR, pDS ) \
219     if ( nr < x86_64::MAX_GPR_REGS ) \
220         pGPR[nr++] = *reinterpret_cast<sal_uInt64 *>( pSV ); \
221     else \
222         *pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV );
223 
224 #define INSERT_INT32( pSV, nr, pGPR, pDS ) \
225     if ( nr < x86_64::MAX_GPR_REGS ) \
226         pGPR[nr++] = *reinterpret_cast<sal_uInt32 *>( pSV ); \
227     else \
228         *pDS++ = *reinterpret_cast<sal_uInt32 *>( pSV );
229 
230 #define INSERT_INT16( pSV, nr, pGPR, pDS ) \
231     if ( nr < x86_64::MAX_GPR_REGS ) \
232         pGPR[nr++] = *reinterpret_cast<sal_uInt16 *>( pSV ); \
233     else \
234         *pDS++ = *reinterpret_cast<sal_uInt16 *>( pSV );
235 
236 #define INSERT_INT8( pSV, nr, pGPR, pDS ) \
237     if ( nr < x86_64::MAX_GPR_REGS ) \
238         pGPR[nr++] = *reinterpret_cast<sal_uInt8 *>( pSV ); \
239     else \
240         *pDS++ = *reinterpret_cast<sal_uInt8 *>( pSV );
241 
242 //==================================================================================================
243 
244 namespace {
245 
246 void appendCString(OUStringBuffer & buffer, char const * text) {
247     if (text != 0) {
248         buffer.append(
249             OStringToOUString(OString(text), RTL_TEXTENCODING_ISO_8859_1));
250             // use 8859-1 to avoid conversion failure
251     }
252 }
253 
254 }
255 
256 static void cpp_call(
257     bridges::cpp_uno::shared::UnoInterfaceProxy * pThis,
258     bridges::cpp_uno::shared::VtableSlot aVtableSlot,
259     typelib_TypeDescriptionReference * pReturnTypeRef,
260     sal_Int32 nParams, typelib_MethodParameter * pParams,
261     void * pUnoReturn, void * pUnoArgs[], uno_Any ** ppUnoExc )
262 {
263     // Maxium space for [complex ret ptr], values | ptr ...
264     // (but will be used less - some of the values will be in pGPR and pFPR)
265     sal_uInt64 *pStack = (sal_uInt64 *)__builtin_alloca( (nParams + 3) * sizeof(sal_uInt64) );
266     sal_uInt64 *pStackStart = pStack;
267 
268     sal_uInt64 pGPR[x86_64::MAX_GPR_REGS];
269     sal_uInt32 nGPR = 0;
270 
271     double pFPR[x86_64::MAX_SSE_REGS];
272     sal_uInt32 nFPR = 0;
273 
274     // Return
275     typelib_TypeDescription * pReturnTypeDescr = 0;
276     TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
277     OSL_ENSURE( pReturnTypeDescr, "### expected return type description!" );
278 
279     void * pCppReturn = 0; // if != 0 && != pUnoReturn, needs reconversion (see below)
280 
281     bool bSimpleReturn = true;
282     if ( pReturnTypeDescr )
283     {
284         if ( x86_64::return_in_hidden_param( pReturnTypeRef ) )
285             bSimpleReturn = false;
286 
287         if ( bSimpleReturn )
288             pCppReturn = pUnoReturn; // direct way for simple types
289         else
290         {
291             // complex return via ptr
292             pCppReturn = bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )?
293                          __builtin_alloca( pReturnTypeDescr->nSize ) : pUnoReturn;
294             INSERT_INT64( &pCppReturn, nGPR, pGPR, pStack );
295         }
296     }
297 
298     // Push "this" pointer
299     void * pAdjustedThisPtr = reinterpret_cast< void ** >( pThis->getCppI() ) + aVtableSlot.offset;
300     INSERT_INT64( &pAdjustedThisPtr, nGPR, pGPR, pStack );
301 
302     // Args
303     void ** pCppArgs = (void **)alloca( 3 * sizeof(void *) * nParams );
304     // Indizes of values this have to be converted (interface conversion cpp<=>uno)
305     sal_Int32 * pTempIndizes = (sal_Int32 *)(pCppArgs + nParams);
306     // Type descriptions for reconversions
307     typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pCppArgs + (2 * nParams));
308 
309     sal_Int32 nTempIndizes = 0;
310 
311     for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
312     {
313         const typelib_MethodParameter & rParam = pParams[nPos];
314         typelib_TypeDescription * pParamTypeDescr = 0;
315         TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
316 
317         if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
318         {
319             uno_copyAndConvertData( pCppArgs[nPos] = alloca( 8 ), pUnoArgs[nPos], pParamTypeDescr,
320                                     pThis->getBridge()->getUno2Cpp() );
321 
322             switch (pParamTypeDescr->eTypeClass)
323             {
324             case typelib_TypeClass_HYPER:
325             case typelib_TypeClass_UNSIGNED_HYPER:
326                 INSERT_INT64( pCppArgs[nPos], nGPR, pGPR, pStack );
327                 break;
328             case typelib_TypeClass_LONG:
329             case typelib_TypeClass_UNSIGNED_LONG:
330             case typelib_TypeClass_ENUM:
331                 INSERT_INT32( pCppArgs[nPos], nGPR, pGPR, pStack );
332                 break;
333             case typelib_TypeClass_SHORT:
334             case typelib_TypeClass_CHAR:
335             case typelib_TypeClass_UNSIGNED_SHORT:
336                 INSERT_INT16( pCppArgs[nPos], nGPR, pGPR, pStack );
337                 break;
338             case typelib_TypeClass_BOOLEAN:
339             case typelib_TypeClass_BYTE:
340                 INSERT_INT8( pCppArgs[nPos], nGPR, pGPR, pStack );
341                 break;
342             case typelib_TypeClass_FLOAT:
343             case typelib_TypeClass_DOUBLE:
344                 INSERT_FLOAT_DOUBLE( pCppArgs[nPos], nFPR, pFPR, pStack );
345                 break;
346             default:
347                 break;
348             }
349 
350             // no longer needed
351             TYPELIB_DANGER_RELEASE( pParamTypeDescr );
352         }
353         else // ptr to complex value | ref
354         {
355             if (! rParam.bIn) // is pure out
356             {
357                 // cpp out is constructed mem, uno out is not!
358                 uno_constructData(
359                     pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
360                     pParamTypeDescr );
361                 pTempIndizes[nTempIndizes] = nPos; // default constructed for cpp call
362                 // will be released at reconversion
363                 ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
364             }
365             // is in/inout
366             else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
367             {
368                 uno_copyAndConvertData(
369                     pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
370                     pUnoArgs[nPos], pParamTypeDescr, pThis->getBridge()->getUno2Cpp() );
371 
372                 pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
373                 // will be released at reconversion
374                 ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
375             }
376             else // direct way
377             {
378                 pCppArgs[nPos] = pUnoArgs[nPos];
379                 // no longer needed
380                 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
381             }
382             INSERT_INT64( &(pCppArgs[nPos]), nGPR, pGPR, pStack );
383         }
384     }
385 
386     try
387     {
388         try {
389             callVirtualMethod(
390                 pAdjustedThisPtr, aVtableSlot.index,
391                 pCppReturn, pReturnTypeRef, bSimpleReturn,
392                 pStackStart, ( pStack - pStackStart ),
393                 pGPR, nGPR,
394                 pFPR, nFPR );
395         } catch (Exception &) {
396             throw;
397         } catch (std::exception & e) {
398             OUStringBuffer buf;
399             buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("C++ code threw "));
400             appendCString(buf, typeid(e).name());
401             buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(": "));
402             appendCString(buf, e.what());
403             throw RuntimeException(
404                 buf.makeStringAndClear(), Reference< XInterface >());
405         } catch (...) {
406             throw RuntimeException(
407                 OUString(
408                     RTL_CONSTASCII_USTRINGPARAM(
409                         "C++ code threw unknown exception")),
410                 Reference< XInterface >());
411         }
412 
413         // NO exception occured...
414         *ppUnoExc = 0;
415 
416         // reconvert temporary params
417         for ( ; nTempIndizes--; )
418         {
419             sal_Int32 nIndex = pTempIndizes[nTempIndizes];
420             typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
421 
422             if (pParams[nIndex].bIn)
423             {
424                 if (pParams[nIndex].bOut) // inout
425                 {
426                     uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 ); // destroy uno value
427                     uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
428                                             pThis->getBridge()->getCpp2Uno() );
429                 }
430             }
431             else // pure out
432             {
433                 uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
434                                         pThis->getBridge()->getCpp2Uno() );
435             }
436             // destroy temp cpp param => cpp: every param was constructed
437             uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
438 
439             TYPELIB_DANGER_RELEASE( pParamTypeDescr );
440         }
441         // return value
442         if (pCppReturn && pUnoReturn != pCppReturn)
443         {
444             uno_copyAndConvertData( pUnoReturn, pCppReturn, pReturnTypeDescr,
445                                     pThis->getBridge()->getCpp2Uno() );
446             uno_destructData( pCppReturn, pReturnTypeDescr, cpp_release );
447         }
448     }
449     catch (...)
450     {
451         // fill uno exception
452         fillUnoException( CPPU_CURRENT_NAMESPACE::__cxa_get_globals()->caughtExceptions, *ppUnoExc, pThis->getBridge()->getCpp2Uno() );
453 
454         // temporary params
455         for ( ; nTempIndizes--; )
456         {
457             sal_Int32 nIndex = pTempIndizes[nTempIndizes];
458             // destroy temp cpp param => cpp: every param was constructed
459             uno_destructData( pCppArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], cpp_release );
460             TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
461         }
462         // return type
463         if (pReturnTypeDescr)
464             TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
465     }
466 }
467 
468 //==================================================================================================
469 
470 namespace bridges { namespace cpp_uno { namespace shared {
471 
472 void unoInterfaceProxyDispatch(
473     uno_Interface * pUnoI, const typelib_TypeDescription * pMemberDescr,
474     void * pReturn, void * pArgs[], uno_Any ** ppException )
475 {
476     // is my surrogate
477     bridges::cpp_uno::shared::UnoInterfaceProxy * pThis
478         = static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy * >(pUnoI);
479 #if OSL_DEBUG_LEVEL > 0
480     typelib_InterfaceTypeDescription * pTypeDescr = pThis->pTypeDescr;
481 #endif
482 
483     switch (pMemberDescr->eTypeClass)
484     {
485     case typelib_TypeClass_INTERFACE_ATTRIBUTE:
486     {
487 #if OSL_DEBUG_LEVEL > 0
488         // determine vtable call index
489         sal_Int32 nMemberPos = ((typelib_InterfaceMemberTypeDescription *)pMemberDescr)->nPosition;
490         OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### member pos out of range!" );
491 #endif
492         VtableSlot aVtableSlot(
493                 getVtableSlot(
494                     reinterpret_cast<
495                     typelib_InterfaceAttributeTypeDescription const * >(
496                         pMemberDescr)));
497 
498         if (pReturn)
499         {
500             // dependent dispatch
501             cpp_call(
502                 pThis, aVtableSlot,
503                 ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef,
504                 0, 0, // no params
505                 pReturn, pArgs, ppException );
506         }
507         else
508         {
509             // is SET
510             typelib_MethodParameter aParam;
511             aParam.pTypeRef =
512                 ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef;
513             aParam.bIn      = sal_True;
514             aParam.bOut     = sal_False;
515 
516             typelib_TypeDescriptionReference * pReturnTypeRef = 0;
517             OUString aVoidName( RTL_CONSTASCII_USTRINGPARAM("void") );
518             typelib_typedescriptionreference_new(
519                 &pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData );
520 
521             // dependent dispatch
522             aVtableSlot.index += 1; // get, then set method
523             cpp_call(
524                 pThis, aVtableSlot, // get, then set method
525                 pReturnTypeRef,
526                 1, &aParam,
527                 pReturn, pArgs, ppException );
528 
529             typelib_typedescriptionreference_release( pReturnTypeRef );
530         }
531 
532         break;
533     }
534     case typelib_TypeClass_INTERFACE_METHOD:
535     {
536 #if OSL_DEBUG_LEVEL > 0
537         // determine vtable call index
538         sal_Int32 nMemberPos = ((typelib_InterfaceMemberTypeDescription *)pMemberDescr)->nPosition;
539         OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### member pos out of range!" );
540 #endif
541         VtableSlot aVtableSlot(
542                 getVtableSlot(
543                     reinterpret_cast<
544                     typelib_InterfaceMethodTypeDescription const * >(
545                         pMemberDescr)));
546 
547         switch (aVtableSlot.index)
548         {
549             // standard calls
550         case 1: // acquire uno interface
551             (*pUnoI->acquire)( pUnoI );
552             *ppException = 0;
553             break;
554         case 2: // release uno interface
555             (*pUnoI->release)( pUnoI );
556             *ppException = 0;
557             break;
558         case 0: // queryInterface() opt
559         {
560             typelib_TypeDescription * pTD = 0;
561             TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( pArgs[0] )->getTypeLibType() );
562             if (pTD)
563             {
564                 uno_Interface * pInterface = 0;
565                 (*pThis->getBridge()->getUnoEnv()->getRegisteredInterface)(
566                     pThis->getBridge()->getUnoEnv(),
567                     (void **)&pInterface, pThis->oid.pData, (typelib_InterfaceTypeDescription *)pTD );
568 
569                 if (pInterface)
570                 {
571                     ::uno_any_construct(
572                         reinterpret_cast< uno_Any * >( pReturn ),
573                         &pInterface, pTD, 0 );
574                     (*pInterface->release)( pInterface );
575                     TYPELIB_DANGER_RELEASE( pTD );
576                     *ppException = 0;
577                     break;
578                 }
579                 TYPELIB_DANGER_RELEASE( pTD );
580             }
581         } // else perform queryInterface()
582         default:
583             // dependent dispatch
584             cpp_call(
585                 pThis, aVtableSlot,
586                 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pReturnTypeRef,
587                 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->nParams,
588                 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pParams,
589                 pReturn, pArgs, ppException );
590         }
591         break;
592     }
593     default:
594     {
595         ::com::sun::star::uno::RuntimeException aExc(
596             OUString( RTL_CONSTASCII_USTRINGPARAM("illegal member type description!") ),
597             ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
598 
599         Type const & rExcType = ::getCppuType( &aExc );
600         // binary identical null reference
601         ::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), 0 );
602     }
603     }
604 }
605 
606 } } }
607