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