1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
$NetBSD: patch-ad,v 1.1.1.1 2002/02/13 18:09:23 mrauch Exp $
--- ../bridges/source/cpp_uno/gcc2_netbsd_intel/except.cxx.orig Sun Jan 6 11:41:58 2002
+++ ../bridges/source/cpp_uno/gcc2_netbsd_intel/except.cxx
@@ -0,0 +1,305 @@
+#include <dlfcn.h>
+#include <new.h>
+#include <typeinfo>
+#if STLPORT_VERSION<321
+#include <map.h>
+#else
+#include <map>
+#endif
+#ifndef _RTL_ALLOC_H_
+#include <rtl/alloc.h>
+#endif
+#ifndef _OSL_DIAGNOSE_H_
+#include <osl/diagnose.h>
+#endif
+
+#ifndef _BRIDGES_CPP_UNO_BRIDGE_HXX_
+#include <bridges/cpp_uno/bridge.hxx>
+#endif
+#ifndef _TYPELIB_TYPEDESCRIPTION_HXX_
+#include <typelib/typedescription.hxx>
+#endif
+#ifndef _COM_SUN_STAR_UNO_ANY_HXX_
+#include <com/sun/star/uno/Any.hxx>
+#endif
+
+#include <rtl/strbuf.hxx>
+
+#include "gcc2_netbsd_intel.hxx"
+
+#ifdef DEBUG
+#include <stdio.h>
+#endif
+
+using namespace std;
+using namespace osl;
+using namespace rtl;
+using namespace com::sun::star::uno;
+
+namespace CPPU_CURRENT_NAMESPACE
+{
+
+//==================================================================================================
+static OString toUNOname( const OString & rRTTIname )
+{
+ OString aRet;
+
+ sal_Char* pStr = rRTTIname.getStr();
+ sal_Char* pOrg = pStr;
+
+ // check for namespace
+ if( *pStr == '_' )
+ pStr++;
+ if( *pStr == 'Q' )
+ {
+ pStr++;
+ if( *pStr++ == '_' )
+ {
+ while( *pStr++ != '_' )
+ ;
+ }
+ }
+
+ while( *pStr )
+ {
+ int nCharsToCopy = 0;
+ while( *pStr >= '0' && *pStr <= '9' )
+ nCharsToCopy = 10*nCharsToCopy + (int)(*pStr++ - '0');
+ if( aRet.getLength() )
+ aRet += ".";
+ aRet += rRTTIname.copy( pStr - pOrg, nCharsToCopy );
+ pStr += nCharsToCopy;
+ }
+
+ return aRet;
+}
+//==================================================================================================
+static OString toRTTIname( const OString & rUNOname )
+{
+ if( ! rUNOname.getLength() )
+ return OString();
+
+ OStringBuffer aRet( 64 );
+
+ sal_Int32 nIndex = 0;
+ sal_Int32 nToken = 0;
+ do
+ {
+ OString aToken( rUNOname.getToken( 0, '.', nIndex ) );
+ aRet.append( OString::valueOf( (sal_Int32)aToken.getLength() ) );
+ aRet.append( aToken );
+ ++nToken;
+ }
+ while (nIndex >= 0);
+
+ OString ret( aRet.makeStringAndClear() );
+
+ if( nToken >= 2 )
+ {
+ OStringBuffer buf( 64 );
+ buf.append( 'Q' );
+ if( nToken > 9 )
+ aRet.append( '_' );
+ buf.append( OString::valueOf( (sal_Int32)nToken ) );
+ if( nToken > 9 )
+ aRet.append( '_' );
+ buf.append( ret );
+ ret = buf.makeStringAndClear();
+ }
+
+ return ret;
+}
+
+
+//##################################################################################################
+//#### RTTI simulation #############################################################################
+//##################################################################################################
+
+class RTTIHolder
+{
+ static std::map< OString, void* > aAllRTTI;
+public:
+ static void* getRTTI( const OString& rTypename );
+ static void* getRTTI_UnoName( const OString& rUnoTypename )
+ { return getRTTI( toRTTIname( rUnoTypename ) ); }
+
+ static void* insertRTTI( const OString& rTypename );
+ static void* insertRTTI_UnoName( const OString& rTypename )
+ { return insertRTTI( toRTTIname( rTypename ) ); }
+
+ // rSuperTypename MUST exist !!!
+ static void* insertRTTI( const OString& rTypename, const OString& rSuperTypename );
+ static void* insertRTTI_UnoNames( const OString& rTypename, const OString& rSuperTypename )
+ { return insertRTTI( toRTTIname( rTypename ), toRTTIname( rSuperTypename ) ); }
+
+ // for complex RTTI
+ static void* insertRTTI( const OString& rTypename, void* pRTTI );
+ static void* insertRTTI_UnoName( const OString&rTypename, void* pRTTI )
+ { return insertRTTI( toRTTIname( rTypename ), pRTTI ); }
+};
+
+std::map< OString, void* > RTTIHolder::aAllRTTI;
+
+void* RTTIHolder::getRTTI( const OString& rTypename )
+{
+ std::map< OString, void* >::iterator element;
+
+ element = aAllRTTI.find( rTypename );
+ return element != aAllRTTI.end() ? (*element).second : NULL;
+}
+
+void* RTTIHolder::insertRTTI( const OString& rTypename )
+{
+#ifdef DEBUG
+ fprintf( stderr, "generating base RTTI: %s\n", rTypename.getStr() );
+#endif
+ void* pRTTI = new __user_type_info( strdup( rTypename.getStr() ) );
+ aAllRTTI[ rTypename ] = pRTTI;
+ return pRTTI;
+}
+
+void* RTTIHolder::insertRTTI( const OString& rTypename, const OString& rSuperTypename )
+{
+#ifdef DEBUG
+ fprintf( stderr, "generating subclass RTTI: %s %s\n", rTypename.getStr(), rSuperTypename.getStr() );
+#endif
+ OSL_ENSURE( ! getRTTI( rTypename ), "insert RTTI called on already existing type" );
+ void* pRTTI = new __si_type_info( strdup( rTypename.getStr() ), *(__user_type_info*)getRTTI( rSuperTypename ) );
+ aAllRTTI[ rTypename ] = pRTTI;
+ return pRTTI;
+}
+
+void* RTTIHolder::insertRTTI( const OString& rTypename, void* pRTTI )
+{
+ aAllRTTI[ rTypename ] = pRTTI;
+ return pRTTI;
+}
+
+//--------------------------------------------------------------------------------------------------
+
+static void* generateRTTI( typelib_CompoundTypeDescription * pCompTypeDescr )
+{
+ OString aCompTypeName( OUStringToOString( pCompTypeDescr->aBase.pTypeName, RTL_TEXTENCODING_ASCII_US ) );
+ void* pRTTI = RTTIHolder::getRTTI_UnoName( aCompTypeName );
+ if( pRTTI )
+ return pRTTI;
+
+ if( ! pCompTypeDescr->pBaseTypeDescription )
+ // this is a base type
+ return RTTIHolder::insertRTTI_UnoName( aCompTypeName );
+ if( ! pCompTypeDescr->pBaseTypeDescription->pBaseTypeDescription )
+ {
+ OString aBasename(
+ OUStringToOString( pCompTypeDescr->pBaseTypeDescription->aBase.pTypeName, RTL_TEXTENCODING_ASCII_US )
+ );
+ if( ! RTTIHolder::getRTTI_UnoName( aBasename ) )
+ RTTIHolder::insertRTTI_UnoName( aBasename );
+
+ // this type has only one supertype
+ return RTTIHolder::insertRTTI_UnoNames( aCompTypeName, aBasename );
+ }
+
+ // create __si_type_info
+ void* pSuperRTTI = generateRTTI( pCompTypeDescr->pBaseTypeDescription );
+ OString aCompTypeRTTIname( toRTTIname( aCompTypeName ) );
+#ifdef DEBUG
+ fprintf( stderr, "generating RTTI: %s\n", aCompTypeRTTIname.getStr() );
+#endif
+ pRTTI = new __si_type_info( strdup( aCompTypeRTTIname.getStr() ),
+ *(__user_type_info*)pSuperRTTI );
+#if 0
+ __class_type_info::base_info* pBaseInfo = new __class_type_info::base_info;
+ pBaseInfo->base = (__user_type_info*)pSuperRTTI;
+ pBaseInfo->offset = 0;
+ pBaseInfo->is_virtual = 0;
+ pBaseInfo->access1 = __class_type_info::PUBLIC;
+
+ OString aCompTypeRTTIname( toRTTIname( aCompTypeName ) );
+ pRTTI = new __class_type_info(
+ strdup( aCompTypeRTTIname.getStr() ),
+ pBaseInfo,
+ 1
+ );
+#endif
+ return RTTIHolder::insertRTTI_UnoName( aCompTypeName, pRTTI );
+}
+
+//--------------------------------------------------------------------------------------------------
+
+static Mutex s_aMutex;
+static std::map< void*, typelib_TypeDescription* > aExceptionMap;
+
+static void deleteException( void* pExc, int nDummy )
+{
+ MutexGuard aGuard( s_aMutex );
+ std::map< void*, typelib_TypeDescription* >::iterator element =
+ aExceptionMap.find( pExc );
+ OSL_ASSERT( element != aExceptionMap.end() );
+ if( element != aExceptionMap.end() )
+ {
+ typelib_TypeDescription* pType = (*element).second;
+ aExceptionMap.erase( pExc );
+ uno_destructData( pExc, pType, cpp_release );
+ typelib_typedescription_release( pType );
+ }
+}
+
+//__________________________________________________________________________________________________
+
+//##################################################################################################
+//#### exported ####################################################################################
+//##################################################################################################
+
+
+void gcc291_netbsd_intel_raiseException( uno_Any * pUnoExc, uno_Mapping * pUno2Cpp )
+{
+ // construct cpp exception object
+ typelib_TypeDescription * pTypeDescr = 0;
+ typelib_typedescriptionreference_getDescription( &pTypeDescr, pUnoExc->pType );
+
+ void * pCppExc = __eh_alloc( pTypeDescr->nSize ); // will be released in generated dtor
+ uno_copyAndConvertData( pCppExc, pUnoExc->pData, pTypeDescr, pUno2Cpp );
+
+ // destruct uno exception
+ uno_any_destruct( pUnoExc, 0 );
+
+ // a must be
+ OSL_ENSURE( sizeof(sal_Int32) == sizeof(void *), "### pointer size differs from sal_Int32!" );
+
+ typelib_CompoundTypeDescription * pCompTypeDescr = (typelib_CompoundTypeDescription *)pTypeDescr;
+ void* pRTTI = generateRTTI( pCompTypeDescr );
+
+ {
+ MutexGuard aGuard( s_aMutex );
+ aExceptionMap[ pCppExc ] = pTypeDescr;
+ }
+
+ __cp_push_exception( pCppExc, pRTTI, deleteException );
+ __throw();
+}
+
+void gcc291_netbsd_intel_fillUnoException( cp_eh_info* pInfo, uno_Any* pExc, uno_Mapping * pCpp2Uno )
+{
+ OUString aName( OStringToOUString(
+ toUNOname( ((__user_type_info*)(pInfo->type))->name() ), RTL_TEXTENCODING_ASCII_US ) );
+
+ typelib_TypeDescription * pExcTypeDescr = 0;
+ typelib_typedescription_getByName(
+ &pExcTypeDescr,
+ aName.pData );
+ OSL_ENSURE( pExcTypeDescr, "could not get type description for exception" );
+ if (pExcTypeDescr)
+ {
+ // construct cpp exception any
+ Any aAny( pInfo->value, pExcTypeDescr ); // const_cast
+ typelib_typedescription_release( pExcTypeDescr );
+ // construct uno exception any
+ typelib_TypeDescription* pAnyDescr = 0;
+ getCppuType( (const Any *)0 ).getDescription( &pAnyDescr );
+ uno_copyAndConvertData( pExc, &aAny, pAnyDescr, pCpp2Uno );
+ typelib_typedescription_release( pAnyDescr );
+ }
+}
+
+}
+
|