File: | bridges/source/jni_uno/jni_java2uno.cxx |
Location: | line 203, column 27 |
Description: | Call to 'alloca' has an allocation size of 0 bytes |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |||||
2 | /************************************************************************* | |||||
3 | * | |||||
4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |||||
5 | * | |||||
6 | * Copyright 2000, 2010 Oracle and/or its affiliates. | |||||
7 | * | |||||
8 | * OpenOffice.org - a multi-platform office productivity suite | |||||
9 | * | |||||
10 | * This file is part of OpenOffice.org. | |||||
11 | * | |||||
12 | * OpenOffice.org is free software: you can redistribute it and/or modify | |||||
13 | * it under the terms of the GNU Lesser General Public License version 3 | |||||
14 | * only, as published by the Free Software Foundation. | |||||
15 | * | |||||
16 | * OpenOffice.org is distributed in the hope that it will be useful, | |||||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
19 | * GNU Lesser General Public License version 3 for more details | |||||
20 | * (a copy is included in the LICENSE file that accompanied this code). | |||||
21 | * | |||||
22 | * You should have received a copy of the GNU Lesser General Public License | |||||
23 | * version 3 along with OpenOffice.org. If not, see | |||||
24 | * <http://www.openoffice.org/license.html> | |||||
25 | * for a copy of the LGPLv3 License. | |||||
26 | * | |||||
27 | ************************************************************************/ | |||||
28 | ||||||
29 | ||||||
30 | #include <sal/alloca.h> | |||||
31 | ||||||
32 | #include "jni_bridge.h" | |||||
33 | ||||||
34 | #include <rtl/ustrbuf.hxx> | |||||
35 | ||||||
36 | #include <algorithm> | |||||
37 | ||||||
38 | ||||||
39 | using namespace ::rtl; | |||||
40 | ||||||
41 | namespace jni_uno | |||||
42 | { | |||||
43 | ||||||
44 | //______________________________________________________________________________ | |||||
45 | jobject Bridge::map_to_java( | |||||
46 | JNI_context const & jni, | |||||
47 | uno_Interface * pUnoI, JNI_interface_type_info const * info ) const | |||||
48 | { | |||||
49 | // get oid | |||||
50 | rtl_uString * pOid = 0; | |||||
51 | (*m_uno_env->getObjectIdentifier)( m_uno_env, &pOid, pUnoI ); | |||||
52 | OSL_ASSERT( 0 != pOid )do { if (true && (!(0 != pOid))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_java2uno.cxx" ":" "52" ": "), "OSL_ASSERT: %s", "0 != pOid"); } } while (false ); | |||||
53 | OUString oid( pOid, SAL_NO_ACQUIRE ); | |||||
54 | ||||||
55 | // opt getRegisteredInterface() | |||||
56 | JLocalAutoRef jo_oid( jni, ustring_to_jstring( jni, oid.pData ) ); | |||||
57 | jvalue args[ 2 ]; | |||||
58 | args[ 0 ].l = jo_oid.get(); | |||||
59 | args[ 1 ].l = info->m_type; | |||||
60 | jobject jo_iface = jni->CallObjectMethodA( | |||||
61 | m_jni_info->m_object_java_env, | |||||
62 | m_jni_info->m_method_IEnvironment_getRegisteredInterface, args ); | |||||
63 | jni.ensure_no_exception(); | |||||
64 | ||||||
65 | if (0 == jo_iface) // no registered iface | |||||
66 | { | |||||
67 | // register uno interface | |||||
68 | (*m_uno_env->registerInterface)( | |||||
69 | m_uno_env, reinterpret_cast< void ** >( &pUnoI ), | |||||
70 | oid.pData, (typelib_InterfaceTypeDescription *)info->m_td.get() ); | |||||
71 | ||||||
72 | // create java and register java proxy | |||||
73 | jvalue args2[ 7 ]; | |||||
74 | acquire(); | |||||
75 | args2[ 0 ].j = reinterpret_cast< sal_Int64 >( this ); | |||||
76 | (*pUnoI->acquire)( pUnoI ); | |||||
77 | args2[ 1 ].l = m_jni_info->m_object_java_env; | |||||
78 | args2[ 2 ].j = reinterpret_cast< sal_Int64 >( pUnoI ); | |||||
79 | typelib_typedescription_acquire( info->m_td.get() ); | |||||
80 | args2[ 3 ].j = reinterpret_cast< sal_Int64 >( info->m_td.get() ); | |||||
81 | args2[ 4 ].l = info->m_type; | |||||
82 | args2[ 5 ].l = jo_oid.get(); | |||||
83 | args2[ 6 ].l = info->m_proxy_ctor; | |||||
84 | jo_iface = jni->CallStaticObjectMethodA( | |||||
85 | m_jni_info->m_class_JNI_proxy, | |||||
86 | m_jni_info->m_method_JNI_proxy_create, args2 ); | |||||
87 | jni.ensure_no_exception(); | |||||
88 | } | |||||
89 | ||||||
90 | OSL_ASSERT( 0 != jo_iface )do { if (true && (!(0 != jo_iface))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_java2uno.cxx" ":" "90" ": "), "OSL_ASSERT: %s", "0 != jo_iface"); } } while (false); | |||||
91 | return jo_iface; | |||||
92 | } | |||||
93 | ||||||
94 | ||||||
95 | //______________________________________________________________________________ | |||||
96 | void Bridge::handle_uno_exc( JNI_context const & jni, uno_Any * uno_exc ) const | |||||
97 | { | |||||
98 | if (typelib_TypeClass_EXCEPTION == uno_exc->pType->eTypeClass) | |||||
99 | { | |||||
100 | #if OSL_DEBUG_LEVEL1 > 0 | |||||
101 | // append java stack trace to Message member | |||||
102 | reinterpret_cast< ::com::sun::star::uno::Exception * >( | |||||
103 | uno_exc->pData )->Message += jni.get_stack_trace(); | |||||
104 | #endif | |||||
105 | ||||||
106 | #if OSL_DEBUG_LEVEL1 > 1 | |||||
107 | { | |||||
108 | OUStringBuffer buf( 128 ); | |||||
109 | buf.appendAscii( | |||||
110 | RTL_CONSTASCII_STRINGPARAM("exception occurred java->uno: [")(&("exception occurred java->uno: [")[0]), ((sal_Int32 )(sizeof ("exception occurred java->uno: [") / sizeof (("exception occurred java->uno: [" )[0]))-1) ); | |||||
111 | buf.append( OUString::unacquired( &uno_exc->pType->pTypeName ) ); | |||||
112 | buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] ")(&("] ")[0]), ((sal_Int32)(sizeof ("] ") / sizeof (("] ") [0]))-1) ); | |||||
113 | buf.append( | |||||
114 | reinterpret_cast< ::com::sun::star::uno::Exception const * >( | |||||
115 | uno_exc->pData )->Message ); | |||||
116 | OString cstr_msg( | |||||
117 | OUStringToOString( | |||||
118 | buf.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11)) ) ); | |||||
119 | OSL_TRACE( "%s", cstr_msg.getStr() )do { if (true && (1 > 0)) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_java2uno.cxx" ":" "119" ": "), "%s", cstr_msg.getStr()); } } while (false); | |||||
120 | } | |||||
121 | #endif | |||||
122 | // signal exception | |||||
123 | jvalue java_exc; | |||||
124 | try | |||||
125 | { | |||||
126 | map_to_java( | |||||
127 | jni, &java_exc, uno_exc->pData, uno_exc->pType, 0, | |||||
128 | true /* in */, false /* no out */ ); | |||||
129 | } | |||||
130 | catch (...) | |||||
131 | { | |||||
132 | uno_any_destruct( uno_exc, 0 ); | |||||
133 | throw; | |||||
134 | } | |||||
135 | uno_any_destruct( uno_exc, 0 ); | |||||
136 | ||||||
137 | JLocalAutoRef jo_exc( jni, java_exc.l ); | |||||
138 | jint res = jni->Throw( (jthrowable) jo_exc.get() ); | |||||
139 | if (0 != res) | |||||
140 | { | |||||
141 | // call toString() | |||||
142 | JLocalAutoRef jo_descr( | |||||
143 | jni, jni->CallObjectMethodA( | |||||
144 | jo_exc.get(), m_jni_info->m_method_Object_toString, 0 ) ); | |||||
145 | jni.ensure_no_exception(); | |||||
146 | OUStringBuffer buf( 128 ); | |||||
147 | buf.appendAscii( RTL_CONSTASCII_STRINGPARAM((&("throwing java exception failed: ")[0]), ((sal_Int32)( sizeof ("throwing java exception failed: ") / sizeof (("throwing java exception failed: " )[0]))-1) | |||||
148 | "throwing java exception failed: ")(&("throwing java exception failed: ")[0]), ((sal_Int32)( sizeof ("throwing java exception failed: ") / sizeof (("throwing java exception failed: " )[0]))-1) ); | |||||
149 | buf.append( jstring_to_oustring( jni, (jstring) jo_descr.get() ) ); | |||||
150 | buf.append( jni.get_stack_trace() ); | |||||
151 | throw BridgeRuntimeError( buf.makeStringAndClear() ); | |||||
152 | } | |||||
153 | } | |||||
154 | else | |||||
155 | { | |||||
156 | OUString message( | |||||
157 | OUSTR("thrown exception is no uno exception: ")::rtl::OUString( (&("thrown exception is no uno exception: " )[0]), ((sal_Int32)((sizeof ("thrown exception is no uno exception: " ) / sizeof (("thrown exception is no uno exception: ")[0]))-1 )), (((rtl_TextEncoding) 11)) ) + | |||||
158 | OUString::unacquired( &uno_exc->pType->pTypeName ) + | |||||
159 | jni.get_stack_trace() ); | |||||
160 | uno_any_destruct( uno_exc, 0 ); | |||||
161 | throw BridgeRuntimeError( message ); | |||||
162 | } | |||||
163 | } | |||||
164 | ||||||
165 | union largest | |||||
166 | { | |||||
167 | sal_Int64 n; | |||||
168 | double d; | |||||
169 | void * p; | |||||
170 | uno_Any a; | |||||
171 | }; | |||||
172 | ||||||
173 | //______________________________________________________________________________ | |||||
174 | jobject Bridge::call_uno( | |||||
175 | JNI_context const & jni, | |||||
176 | uno_Interface * pUnoI, typelib_TypeDescription * member_td, | |||||
177 | typelib_TypeDescriptionReference * return_type, | |||||
178 | sal_Int32 nParams, typelib_MethodParameter const * pParams, | |||||
179 | jobjectArray jo_args /* may be 0 */ ) const | |||||
180 | { | |||||
181 | // return mem | |||||
182 | sal_Int32 return_size; | |||||
183 | switch (return_type->eTypeClass) { | |||||
184 | case typelib_TypeClass_VOID: | |||||
185 | return_size = 0; | |||||
186 | break; | |||||
187 | ||||||
188 | case typelib_TypeClass_STRUCT: | |||||
189 | case typelib_TypeClass_EXCEPTION: | |||||
190 | return_size = std::max( | |||||
191 | TypeDescr(return_type).get()->nSize, | |||||
192 | static_cast< sal_Int32 >(sizeof (largest))); | |||||
193 | break; | |||||
194 | ||||||
195 | default: | |||||
196 | return_size = sizeof (largest); | |||||
197 | break; | |||||
198 | } | |||||
199 | ||||||
200 | #ifdef BROKEN_ALLOCA | |||||
201 | char * mem = (char *) malloc( | |||||
202 | #else | |||||
203 | char * mem = (char *) alloca(__builtin_alloca (endif (nParams * sizeof (void *)) + return_size + (nParams * sizeof (largest))) | |||||
| ||||||
204 | #endif__builtin_alloca (endif (nParams * sizeof (void *)) + return_size + (nParams * sizeof (largest))) | |||||
205 | (nParams * sizeof (void *)) +__builtin_alloca (endif (nParams * sizeof (void *)) + return_size + (nParams * sizeof (largest))) | |||||
206 | return_size + (nParams * sizeof (largest)) )__builtin_alloca (endif (nParams * sizeof (void *)) + return_size + (nParams * sizeof (largest))); | |||||
207 | void ** uno_args = (void **) mem; | |||||
208 | void * uno_ret = return_size == 0 ? 0 : (mem + (nParams * sizeof (void *))); | |||||
209 | largest * uno_args_mem = (largest *) | |||||
210 | (mem + (nParams * sizeof (void *)) + return_size); | |||||
211 | ||||||
212 | OSL_ASSERT( (0 == nParams) || (nParams == jni->GetArrayLength( jo_args )) )do { if (true && (!((0 == nParams) || (nParams == jni ->GetArrayLength( jo_args ))))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_java2uno.cxx" ":" "212" ": "), "OSL_ASSERT: %s", "(0 == nParams) || (nParams == jni->GetArrayLength( jo_args ))" ); } } while (false); | |||||
213 | for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos ) | |||||
214 | { | |||||
215 | typelib_MethodParameter const & param = pParams[ nPos ]; | |||||
216 | typelib_TypeDescriptionReference * type = param.pTypeRef; | |||||
217 | ||||||
218 | uno_args[ nPos ] = &uno_args_mem[ nPos ]; | |||||
219 | if (typelib_TypeClass_STRUCT == type->eTypeClass || | |||||
220 | typelib_TypeClass_EXCEPTION == type->eTypeClass) | |||||
221 | { | |||||
222 | TypeDescr td( type ); | |||||
223 | if (sal::static_int_cast< sal_uInt32 >(td.get()->nSize) | |||||
224 | > sizeof (largest)) | |||||
225 | #ifdef BROKEN_ALLOCA | |||||
226 | uno_args[ nPos ] = malloc( td.get()->nSize ); | |||||
227 | #else | |||||
228 | uno_args[ nPos ] = alloca( td.get()->nSize )__builtin_alloca (td.get()->nSize); | |||||
229 | #endif | |||||
230 | } | |||||
231 | ||||||
232 | if (param.bIn) | |||||
233 | { | |||||
234 | try | |||||
235 | { | |||||
236 | JLocalAutoRef jo_arg( | |||||
237 | jni, jni->GetObjectArrayElement( jo_args, nPos ) ); | |||||
238 | jni.ensure_no_exception(); | |||||
239 | jvalue java_arg; | |||||
240 | java_arg.l = jo_arg.get(); | |||||
241 | map_to_uno( | |||||
242 | jni, uno_args[ nPos ], java_arg, type, 0, | |||||
243 | false /* no assign */, sal_False((sal_Bool)0) != param.bOut, | |||||
244 | true /* special wrapped integral types */ ); | |||||
245 | } | |||||
246 | catch (...) | |||||
247 | { | |||||
248 | // cleanup uno in args | |||||
249 | for ( sal_Int32 n = 0; n < nPos; ++n ) | |||||
250 | { | |||||
251 | typelib_MethodParameter const & p = pParams[ n ]; | |||||
252 | if (p.bIn) | |||||
253 | { | |||||
254 | uno_type_destructData( | |||||
255 | uno_args[ n ], p.pTypeRef, 0 ); | |||||
256 | } | |||||
257 | #ifdef BROKEN_ALLOCA | |||||
258 | if (uno_args[ nPos ] && uno_args[ nPos ] != &uno_args_mem[ nPos ]) | |||||
259 | free( uno_args[ nPos ] ); | |||||
260 | #endif | |||||
261 | } | |||||
262 | #ifdef BROKEN_ALLOCA | |||||
263 | free( mem ); | |||||
264 | #endif | |||||
265 | throw; | |||||
266 | } | |||||
267 | } | |||||
268 | } | |||||
269 | ||||||
270 | uno_Any uno_exc_holder; | |||||
271 | uno_Any * uno_exc = &uno_exc_holder; | |||||
272 | // call binary uno | |||||
273 | (*pUnoI->pDispatcher)( pUnoI, member_td, uno_ret, uno_args, &uno_exc ); | |||||
274 | ||||||
275 | if (0 == uno_exc) | |||||
276 | { | |||||
277 | // convert out args; destruct uno args | |||||
278 | for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos ) | |||||
279 | { | |||||
280 | typelib_MethodParameter const & param = pParams[ nPos ]; | |||||
281 | typelib_TypeDescriptionReference * type = param.pTypeRef; | |||||
282 | if (param.bOut) | |||||
283 | { | |||||
284 | try | |||||
285 | { | |||||
286 | // get out holder array[ 1 ] | |||||
287 | JLocalAutoRef jo_out_holder( | |||||
288 | jni, jni->GetObjectArrayElement( jo_args, nPos ) ); | |||||
289 | jni.ensure_no_exception(); | |||||
290 | jvalue java_arg; | |||||
291 | java_arg.l = jo_out_holder.get(); | |||||
292 | map_to_java( | |||||
293 | jni, &java_arg, uno_args[ nPos ], type, 0, | |||||
294 | true /* in */, true /* out holder */ ); | |||||
295 | } | |||||
296 | catch (...) | |||||
297 | { | |||||
298 | // cleanup further uno args | |||||
299 | for ( sal_Int32 n = nPos; n < nParams; ++n ) | |||||
300 | { | |||||
301 | uno_type_destructData( | |||||
302 | uno_args[ n ], pParams[ n ].pTypeRef, 0 ); | |||||
303 | #ifdef BROKEN_ALLOCA | |||||
304 | if (uno_args[ nPos ] && uno_args[ nPos ] != &uno_args_mem[ nPos ]) | |||||
305 | free( uno_args[ nPos ] ); | |||||
306 | #endif | |||||
307 | } | |||||
308 | // cleanup uno return value | |||||
309 | uno_type_destructData( uno_ret, return_type, 0 ); | |||||
310 | #ifdef BROKEN_ALLOCA | |||||
311 | free( mem ); | |||||
312 | #endif | |||||
313 | throw; | |||||
314 | } | |||||
315 | } | |||||
316 | if (typelib_TypeClass_DOUBLE < type->eTypeClass && | |||||
317 | typelib_TypeClass_ENUM != type->eTypeClass) // opt | |||||
318 | { | |||||
319 | uno_type_destructData( uno_args[ nPos ], type, 0 ); | |||||
320 | #ifdef BROKEN_ALLOCA | |||||
321 | if (uno_args[ nPos ] && uno_args[ nPos ] != &uno_args_mem[ nPos ]) | |||||
322 | free( uno_args[ nPos ] ); | |||||
323 | #endif | |||||
324 | } | |||||
325 | } | |||||
326 | ||||||
327 | if (typelib_TypeClass_VOID != return_type->eTypeClass) | |||||
328 | { | |||||
329 | // convert uno return value | |||||
330 | jvalue java_ret; | |||||
331 | try | |||||
332 | { | |||||
333 | map_to_java( | |||||
334 | jni, &java_ret, uno_ret, return_type, 0, | |||||
335 | true /* in */, false /* no out */, | |||||
336 | true /* special_wrapped_integral_types */ ); | |||||
337 | } | |||||
338 | catch (...) | |||||
339 | { | |||||
340 | uno_type_destructData( uno_ret, return_type, 0 ); | |||||
341 | #ifdef BROKEN_ALLOCA | |||||
342 | free( mem ); | |||||
343 | #endif | |||||
344 | throw; | |||||
345 | } | |||||
346 | if (typelib_TypeClass_DOUBLE < return_type->eTypeClass && | |||||
347 | typelib_TypeClass_ENUM != return_type->eTypeClass) // opt | |||||
348 | { | |||||
349 | uno_type_destructData( uno_ret, return_type, 0 ); | |||||
350 | } | |||||
351 | #ifdef BROKEN_ALLOCA | |||||
352 | free( mem ); | |||||
353 | #endif | |||||
354 | return java_ret.l; | |||||
355 | } | |||||
356 | #ifdef BROKEN_ALLOCA | |||||
357 | free( mem ); | |||||
358 | #endif | |||||
359 | return 0; // void return | |||||
360 | } | |||||
361 | else // exception occurred | |||||
362 | { | |||||
363 | // destruct uno in args | |||||
364 | for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos ) | |||||
365 | { | |||||
366 | typelib_MethodParameter const & param = pParams[ nPos ]; | |||||
367 | if (param.bIn) | |||||
368 | uno_type_destructData( uno_args[ nPos ], param.pTypeRef, 0 ); | |||||
369 | #ifdef BROKEN_ALLOCA | |||||
370 | if (uno_args[ nPos ] && uno_args[ nPos ] != &uno_args_mem[ nPos ]) | |||||
371 | free( uno_args[ nPos ] ); | |||||
372 | #endif | |||||
373 | } | |||||
374 | ||||||
375 | handle_uno_exc( jni, uno_exc ); | |||||
376 | #ifdef BROKEN_ALLOCA | |||||
377 | free( mem ); | |||||
378 | #endif | |||||
379 | return 0; | |||||
380 | } | |||||
381 | } | |||||
382 | ||||||
383 | } | |||||
384 | ||||||
385 | using namespace ::jni_uno; | |||||
386 | ||||||
387 | extern "C" | |||||
388 | { | |||||
389 | ||||||
390 | //------------------------------------------------------------------------------ | |||||
391 | JNIEXPORT jobject | |||||
392 | JNICALL Java_com_sun_star_bridges_jni_1uno_JNI_1proxy_dispatch_1call( | |||||
393 | JNIEnv * jni_env, jobject jo_proxy, jlong bridge_handle, jstring jo_method, | |||||
394 | jobjectArray jo_args /* may be 0 */ ) | |||||
395 | SAL_THROW_EXTERN_C()throw () | |||||
396 | { | |||||
397 | Bridge const * bridge = reinterpret_cast< Bridge const * >( bridge_handle ); | |||||
398 | JNI_info const * jni_info = bridge->m_jni_info; | |||||
399 | JNI_context jni( | |||||
400 | jni_info, jni_env, | |||||
401 | static_cast< jobject >( | |||||
402 | reinterpret_cast< ::jvmaccess::UnoVirtualMachine * >( | |||||
403 | bridge->m_java_env->pContext )->getClassLoader() ) ); | |||||
404 | ||||||
405 | OUString method_name; | |||||
406 | ||||||
407 | try | |||||
408 | { | |||||
409 | method_name = jstring_to_oustring( jni, jo_method ); | |||||
410 | #if OSL_DEBUG_LEVEL1 > 1 | |||||
411 | { | |||||
412 | OUStringBuffer trace_buf( 64 ); | |||||
413 | trace_buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("java->uno call: ")(&("java->uno call: ")[0]), ((sal_Int32)(sizeof ("java->uno call: " ) / sizeof (("java->uno call: ")[0]))-1) ); | |||||
414 | trace_buf.append( method_name ); | |||||
415 | trace_buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" on oid ")(&(" on oid ")[0]), ((sal_Int32)(sizeof (" on oid ") / sizeof ((" on oid ")[0]))-1) ); | |||||
416 | JLocalAutoRef jo_oid( | |||||
417 | jni, jni->GetObjectField( | |||||
418 | jo_proxy, jni_info->m_field_JNI_proxy_m_oid ) ); | |||||
419 | trace_buf.append( jstring_to_oustring( jni, (jstring) jo_oid.get() ) ); | |||||
420 | OString cstr_msg( | |||||
421 | OUStringToOString( | |||||
422 | trace_buf.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11)) ) ); | |||||
423 | OSL_TRACE( "%s", cstr_msg.getStr() )do { if (true && (1 > 0)) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_java2uno.cxx" ":" "423" ": "), "%s", cstr_msg.getStr()); } } while (false); | |||||
424 | } | |||||
425 | #endif | |||||
426 | ||||||
427 | // special IQueryInterface.queryInterface() | |||||
428 | if ( method_name == "queryInterface" ) | |||||
| ||||||
429 | { | |||||
430 | // oid | |||||
431 | JLocalAutoRef jo_oid( | |||||
432 | jni, jni->GetObjectField( | |||||
433 | jo_proxy, jni_info->m_field_JNI_proxy_m_oid ) ); | |||||
434 | // type | |||||
435 | JLocalAutoRef jo_type( | |||||
436 | jni, jni->GetObjectArrayElement( jo_args, 0 ) ); | |||||
437 | jni.ensure_no_exception(); | |||||
438 | ||||||
439 | JLocalAutoRef jo_type_name( | |||||
440 | jni, jni->GetObjectField( | |||||
441 | jo_type.get(), jni_info->m_field_Type__typeName ) ); | |||||
442 | if (! jo_type_name.is()) | |||||
443 | { | |||||
444 | throw BridgeRuntimeError( | |||||
445 | OUSTR("incomplete type object: no type name!")::rtl::OUString( (&("incomplete type object: no type name!" )[0]), ((sal_Int32)((sizeof ("incomplete type object: no type name!" ) / sizeof (("incomplete type object: no type name!")[0]))-1) ), (((rtl_TextEncoding) 11)) ) + | |||||
446 | jni.get_stack_trace() ); | |||||
447 | } | |||||
448 | OUString type_name( | |||||
449 | jstring_to_oustring( jni, (jstring) jo_type_name.get() ) ); | |||||
450 | JNI_type_info const * info = | |||||
451 | jni_info->get_type_info( jni, type_name ); | |||||
452 | if (typelib_TypeClass_INTERFACE != info->m_td.get()->eTypeClass) | |||||
453 | { | |||||
454 | throw BridgeRuntimeError( | |||||
455 | OUSTR("queryInterface() call demands an INTERFACE type!")::rtl::OUString( (&("queryInterface() call demands an INTERFACE type!" )[0]), ((sal_Int32)((sizeof ("queryInterface() call demands an INTERFACE type!" ) / sizeof (("queryInterface() call demands an INTERFACE type!" )[0]))-1)), (((rtl_TextEncoding) 11)) ) ); | |||||
456 | } | |||||
457 | JNI_interface_type_info const * iface_info = | |||||
458 | static_cast< JNI_interface_type_info const * >( info ); | |||||
459 | ||||||
460 | // getRegisteredInterface() already tested in JNI_proxy: | |||||
461 | // perform queryInterface call on binary uno interface | |||||
462 | uno_Interface * pUnoI = reinterpret_cast< uno_Interface * >( | |||||
463 | jni->GetLongField( | |||||
464 | jo_proxy, jni_info->m_field_JNI_proxy_m_receiver_handle ) ); | |||||
465 | ||||||
466 | uno_Any uno_ret; | |||||
467 | void * uno_args[] = { &iface_info->m_td.get()->pWeakRef }; | |||||
468 | uno_Any uno_exc_holder; | |||||
469 | uno_Any * uno_exc = &uno_exc_holder; | |||||
470 | // call binary uno | |||||
471 | (*pUnoI->pDispatcher)( | |||||
472 | pUnoI, jni_info->m_XInterface_queryInterface_td.get(), | |||||
473 | &uno_ret, uno_args, &uno_exc ); | |||||
474 | if (0 == uno_exc) | |||||
475 | { | |||||
476 | jobject jo_ret = 0; | |||||
477 | if (typelib_TypeClass_INTERFACE == uno_ret.pType->eTypeClass) | |||||
478 | { | |||||
479 | uno_Interface * pUnoRet = | |||||
480 | (uno_Interface *) uno_ret.pReserved; | |||||
481 | if (0 != pUnoRet) | |||||
482 | { | |||||
483 | try | |||||
484 | { | |||||
485 | jo_ret = | |||||
486 | bridge->map_to_java( jni, pUnoRet, iface_info ); | |||||
487 | } | |||||
488 | catch (...) | |||||
489 | { | |||||
490 | uno_any_destruct( &uno_ret, 0 ); | |||||
491 | throw; | |||||
492 | } | |||||
493 | } | |||||
494 | } | |||||
495 | uno_any_destruct( &uno_ret, 0 ); | |||||
496 | return jo_ret; | |||||
497 | } | |||||
498 | else | |||||
499 | { | |||||
500 | bridge->handle_uno_exc( jni, uno_exc ); | |||||
501 | return 0; | |||||
502 | } | |||||
503 | } | |||||
504 | ||||||
505 | typelib_InterfaceTypeDescription * td = | |||||
506 | reinterpret_cast< typelib_InterfaceTypeDescription * >( | |||||
507 | jni->GetLongField( | |||||
508 | jo_proxy, jni_info->m_field_JNI_proxy_m_td_handle ) ); | |||||
509 | uno_Interface * pUnoI = | |||||
510 | reinterpret_cast< uno_Interface * >( | |||||
511 | jni->GetLongField( | |||||
512 | jo_proxy, jni_info->m_field_JNI_proxy_m_receiver_handle ) ); | |||||
513 | ||||||
514 | typelib_TypeDescriptionReference ** ppAllMembers = td->ppAllMembers; | |||||
515 | for ( sal_Int32 nPos = td->nAllMembers; nPos--; ) | |||||
516 | { | |||||
517 | // try to avoid getting typedescription as long as possible, | |||||
518 | // because of a Mutex.acquire() in | |||||
519 | // typelib_typedescriptionreference_getDescription() | |||||
520 | typelib_TypeDescriptionReference * member_type = | |||||
521 | ppAllMembers[ nPos ]; | |||||
522 | ||||||
523 | // check method_name against fully qualified type_name | |||||
524 | // of member_type; type_name is of the form | |||||
525 | // <name> "::" <method_name> *(":@" <idx> "," <idx> ":" <name>) | |||||
526 | OUString const & type_name = | |||||
527 | OUString::unacquired( &member_type->pTypeName ); | |||||
528 | sal_Int32 offset = type_name.indexOf( ':' ) + 2; | |||||
529 | OSL_ASSERT(do { if (true && (!(offset >= 2 && offset < type_name.getLength() && type_name[offset - 1] == ':' ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_java2uno.cxx" ":" "531" ": "), "OSL_ASSERT: %s", "offset >= 2 && offset < type_name.getLength() && type_name[offset - 1] == ':'" ); } } while (false) | |||||
530 | offset >= 2 && offset < type_name.getLength()do { if (true && (!(offset >= 2 && offset < type_name.getLength() && type_name[offset - 1] == ':' ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_java2uno.cxx" ":" "531" ": "), "OSL_ASSERT: %s", "offset >= 2 && offset < type_name.getLength() && type_name[offset - 1] == ':'" ); } } while (false) | |||||
531 | && type_name[offset - 1] == ':' )do { if (true && (!(offset >= 2 && offset < type_name.getLength() && type_name[offset - 1] == ':' ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_java2uno.cxx" ":" "531" ": "), "OSL_ASSERT: %s", "offset >= 2 && offset < type_name.getLength() && type_name[offset - 1] == ':'" ); } } while (false); | |||||
532 | sal_Int32 remainder = type_name.getLength() - offset; | |||||
533 | if (typelib_TypeClass_INTERFACE_METHOD == member_type->eTypeClass) | |||||
534 | { | |||||
535 | if ((method_name.getLength() == remainder | |||||
536 | || (method_name.getLength() < remainder | |||||
537 | && type_name[offset + method_name.getLength()] == ':')) | |||||
538 | && type_name.match(method_name, offset)) | |||||
539 | { | |||||
540 | TypeDescr member_td( member_type ); | |||||
541 | typelib_InterfaceMethodTypeDescription * method_td = | |||||
542 | reinterpret_cast< | |||||
543 | typelib_InterfaceMethodTypeDescription * >( | |||||
544 | member_td.get() ); | |||||
545 | return bridge->call_uno( | |||||
546 | jni, pUnoI, member_td.get(), | |||||
547 | method_td->pReturnTypeRef, | |||||
548 | method_td->nParams, method_td->pParams, | |||||
549 | jo_args ); | |||||
550 | } | |||||
551 | } | |||||
552 | else // attribute | |||||
553 | { | |||||
554 | OSL_ASSERT(do { if (true && (!(typelib_TypeClass_INTERFACE_ATTRIBUTE == member_type->eTypeClass))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_java2uno.cxx" ":" "556" ": "), "OSL_ASSERT: %s", "typelib_TypeClass_INTERFACE_ATTRIBUTE == member_type->eTypeClass" ); } } while (false) | |||||
555 | typelib_TypeClass_INTERFACE_ATTRIBUTE ==do { if (true && (!(typelib_TypeClass_INTERFACE_ATTRIBUTE == member_type->eTypeClass))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_java2uno.cxx" ":" "556" ": "), "OSL_ASSERT: %s", "typelib_TypeClass_INTERFACE_ATTRIBUTE == member_type->eTypeClass" ); } } while (false) | |||||
556 | member_type->eTypeClass )do { if (true && (!(typelib_TypeClass_INTERFACE_ATTRIBUTE == member_type->eTypeClass))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_java2uno.cxx" ":" "556" ": "), "OSL_ASSERT: %s", "typelib_TypeClass_INTERFACE_ATTRIBUTE == member_type->eTypeClass" ); } } while (false); | |||||
557 | ||||||
558 | if (method_name.getLength() >= 3 | |||||
559 | && (method_name.getLength() - 3 == remainder | |||||
560 | || (method_name.getLength() - 3 < remainder | |||||
561 | && type_name[ | |||||
562 | offset + (method_name.getLength() - 3)] == ':')) | |||||
563 | && method_name[1] == 'e' && method_name[2] == 't' | |||||
564 | && rtl_ustr_compare_WithLength( | |||||
565 | type_name.getStr() + offset, | |||||
566 | method_name.getLength() - 3, | |||||
567 | method_name.getStr() + 3, | |||||
568 | method_name.getLength() - 3) == 0) | |||||
569 | { | |||||
570 | if ('g' == method_name[ 0 ]) | |||||
571 | { | |||||
572 | TypeDescr member_td( member_type ); | |||||
573 | typelib_InterfaceAttributeTypeDescription * attr_td = | |||||
574 | reinterpret_cast< | |||||
575 | typelib_InterfaceAttributeTypeDescription * >( | |||||
576 | member_td.get() ); | |||||
577 | return bridge->call_uno( | |||||
578 | jni, pUnoI, member_td.get(), | |||||
579 | attr_td->pAttributeTypeRef, | |||||
580 | 0, 0, | |||||
581 | jo_args ); | |||||
582 | } | |||||
583 | else if ('s' == method_name[ 0 ]) | |||||
584 | { | |||||
585 | TypeDescr member_td( member_type ); | |||||
586 | typelib_InterfaceAttributeTypeDescription * attr_td = | |||||
587 | reinterpret_cast< | |||||
588 | typelib_InterfaceAttributeTypeDescription * >( | |||||
589 | member_td.get() ); | |||||
590 | if (! attr_td->bReadOnly) | |||||
591 | { | |||||
592 | typelib_MethodParameter param; | |||||
593 | param.pTypeRef = attr_td->pAttributeTypeRef; | |||||
594 | param.bIn = sal_True((sal_Bool)1); | |||||
595 | param.bOut = sal_False((sal_Bool)0); | |||||
596 | return bridge->call_uno( | |||||
597 | jni, pUnoI, member_td.get(), | |||||
598 | jni_info->m_void_type.getTypeLibType(), | |||||
599 | 1, ¶m, | |||||
600 | jo_args ); | |||||
601 | } | |||||
602 | } | |||||
603 | } | |||||
604 | } | |||||
605 | } | |||||
606 | // the thing that should not be... no method info found! | |||||
607 | OUStringBuffer buf( 64 ); | |||||
608 | buf.appendAscii( RTL_CONSTASCII_STRINGPARAM((&("calling undeclared function on interface ")[0]), ((sal_Int32 )(sizeof ("calling undeclared function on interface ") / sizeof (("calling undeclared function on interface ")[0]))-1) | |||||
609 | "calling undeclared function on interface ")(&("calling undeclared function on interface ")[0]), ((sal_Int32 )(sizeof ("calling undeclared function on interface ") / sizeof (("calling undeclared function on interface ")[0]))-1) ); | |||||
610 | buf.append( OUString::unacquired( | |||||
611 | &((typelib_TypeDescription *)td)->pTypeName ) ); | |||||
612 | buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(": ")(&(": ")[0]), ((sal_Int32)(sizeof (": ") / sizeof ((": ") [0]))-1) ); | |||||
613 | buf.append( method_name ); | |||||
614 | buf.append( jni.get_stack_trace() ); | |||||
615 | throw BridgeRuntimeError( buf.makeStringAndClear() ); | |||||
616 | } | |||||
617 | catch (const BridgeRuntimeError & err) | |||||
618 | { | |||||
619 | OUStringBuffer buf( 128 ); | |||||
620 | buf.appendAscii( | |||||
621 | RTL_CONSTASCII_STRINGPARAM("[jni_uno bridge error] "(&("[jni_uno bridge error] " "Java calling UNO method ")[ 0]), ((sal_Int32)(sizeof ("[jni_uno bridge error] " "Java calling UNO method " ) / sizeof (("[jni_uno bridge error] " "Java calling UNO method " )[0]))-1) | |||||
622 | "Java calling UNO method ")(&("[jni_uno bridge error] " "Java calling UNO method ")[ 0]), ((sal_Int32)(sizeof ("[jni_uno bridge error] " "Java calling UNO method " ) / sizeof (("[jni_uno bridge error] " "Java calling UNO method " )[0]))-1) ); | |||||
623 | buf.append( method_name ); | |||||
624 | buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(": ")(&(": ")[0]), ((sal_Int32)(sizeof (": ") / sizeof ((": ") [0]))-1) ); | |||||
625 | buf.append( err.m_message ); | |||||
626 | // notify RuntimeException | |||||
627 | OString cstr_msg( | |||||
628 | OUStringToOString( | |||||
629 | buf.makeStringAndClear(), RTL_TEXTENCODING_JAVA_UTF8(((rtl_TextEncoding) 90)) ) ); | |||||
630 | OSL_FAIL( cstr_msg.getStr() )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_java2uno.cxx" ":" "630" ": "), "%s", cstr_msg.getStr()); } } while (false); | |||||
631 | if (jni->ThrowNew(jni_info->m_class_RuntimeException, cstr_msg.getStr()) | |||||
632 | != 0) | |||||
633 | { | |||||
634 | OSL_ASSERT( false )do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_java2uno.cxx" ":" "634" ": "), "OSL_ASSERT: %s", "false"); } } while (false ); | |||||
635 | } | |||||
636 | return 0; | |||||
637 | } | |||||
638 | catch (const ::jvmaccess::VirtualMachine::AttachGuard::CreationException &) | |||||
639 | { | |||||
640 | OString cstr_msg( | |||||
641 | OString( RTL_CONSTASCII_STRINGPARAM((&("[jni_uno bridge error] " "attaching current thread to java failed!" )[0]), ((sal_Int32)(sizeof ("[jni_uno bridge error] " "attaching current thread to java failed!" ) / sizeof (("[jni_uno bridge error] " "attaching current thread to java failed!" )[0]))-1) | |||||
642 | "[jni_uno bridge error] "(&("[jni_uno bridge error] " "attaching current thread to java failed!" )[0]), ((sal_Int32)(sizeof ("[jni_uno bridge error] " "attaching current thread to java failed!" ) / sizeof (("[jni_uno bridge error] " "attaching current thread to java failed!" )[0]))-1) | |||||
643 | "attaching current thread to java failed!")(&("[jni_uno bridge error] " "attaching current thread to java failed!" )[0]), ((sal_Int32)(sizeof ("[jni_uno bridge error] " "attaching current thread to java failed!" ) / sizeof (("[jni_uno bridge error] " "attaching current thread to java failed!" )[0]))-1) ) + | |||||
644 | OUStringToOString( | |||||
645 | jni.get_stack_trace(), RTL_TEXTENCODING_JAVA_UTF8(((rtl_TextEncoding) 90)) ) ); | |||||
646 | OSL_FAIL( cstr_msg.getStr() )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_java2uno.cxx" ":" "646" ": "), "%s", cstr_msg.getStr()); } } while (false); | |||||
647 | if (jni->ThrowNew(jni_info->m_class_RuntimeException, cstr_msg.getStr()) | |||||
648 | != 0) | |||||
649 | { | |||||
650 | OSL_ASSERT( false )do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_java2uno.cxx" ":" "650" ": "), "OSL_ASSERT: %s", "false"); } } while (false ); | |||||
651 | } | |||||
652 | return 0; | |||||
653 | } | |||||
654 | } | |||||
655 | ||||||
656 | //------------------------------------------------------------------------------ | |||||
657 | JNIEXPORT void | |||||
658 | JNICALL Java_com_sun_star_bridges_jni_1uno_JNI_1proxy_finalize__J( | |||||
659 | JNIEnv * jni_env, jobject jo_proxy, jlong bridge_handle ) | |||||
660 | SAL_THROW_EXTERN_C()throw () | |||||
661 | { | |||||
662 | Bridge const * bridge = reinterpret_cast< Bridge const * >( bridge_handle ); | |||||
663 | JNI_info const * jni_info = bridge->m_jni_info; | |||||
664 | JNI_context jni( | |||||
665 | jni_info, jni_env, | |||||
666 | static_cast< jobject >( | |||||
667 | reinterpret_cast< ::jvmaccess::UnoVirtualMachine * >( | |||||
668 | bridge->m_java_env->pContext )->getClassLoader() ) ); | |||||
669 | ||||||
670 | uno_Interface * pUnoI = reinterpret_cast< uno_Interface * >( | |||||
671 | jni->GetLongField( | |||||
672 | jo_proxy, jni_info->m_field_JNI_proxy_m_receiver_handle ) ); | |||||
673 | typelib_TypeDescription * td = | |||||
674 | reinterpret_cast< typelib_TypeDescription * >( | |||||
675 | jni->GetLongField( | |||||
676 | jo_proxy, jni_info->m_field_JNI_proxy_m_td_handle ) ); | |||||
677 | ||||||
678 | #if OSL_DEBUG_LEVEL1 > 1 | |||||
679 | { | |||||
680 | JLocalAutoRef jo_oid( | |||||
681 | jni, jni->GetObjectField( | |||||
682 | jo_proxy, jni_info->m_field_JNI_proxy_m_oid ) ); | |||||
683 | OUString oid( jstring_to_oustring( jni, (jstring) jo_oid.get() ) ); | |||||
684 | OString cstr_msg( | |||||
685 | OUStringToOString( | |||||
686 | OUSTR("freeing java uno proxy: ")::rtl::OUString( (&("freeing java uno proxy: ")[0]), ((sal_Int32 )((sizeof ("freeing java uno proxy: ") / sizeof (("freeing java uno proxy: " )[0]))-1)), (((rtl_TextEncoding) 11)) ) + oid, | |||||
687 | RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11)) ) ); | |||||
688 | OSL_TRACE( "%s", cstr_msg.getStr() )do { if (true && (1 > 0)) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/bridges/source/jni_uno/jni_java2uno.cxx" ":" "688" ": "), "%s", cstr_msg.getStr()); } } while (false); | |||||
689 | } | |||||
690 | #endif | |||||
691 | // revoke from uno env; has already been revoked from java env | |||||
692 | (*bridge->m_uno_env->revokeInterface)( bridge->m_uno_env, pUnoI ); | |||||
693 | // release receiver | |||||
694 | (*pUnoI->release)( pUnoI ); | |||||
695 | // release typedescription handle | |||||
696 | typelib_typedescription_release( td ); | |||||
697 | // release bridge handle | |||||
698 | bridge->release(); | |||||
699 | } | |||||
700 | ||||||
701 | } | |||||
702 | ||||||
703 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |