Bug Summary

File:registry/source/reflwrit.cxx
Location:line 621, column 13
Description:Called C++ object pointer is null

Annotated Source Code

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
21#include <new>
22#include <sal/types.h>
23#include <sal/macros.h>
24#include <osl/endian.h>
25#include <rtl/alloc.h>
26#include "rtl/string.hxx"
27#include "rtl/ustring.hxx"
28
29#include "registry/reflwrit.hxx"
30#include "registry/version.h"
31#include "registry/writer.h"
32
33#include "reflcnst.hxx"
34
35using ::rtl::OString;
36
37
38namespace {
39
40inline rtl::OString toByteString(rtl_uString const * str) {
41 return rtl::OString(
42 str->buffer, str->length, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)),
43 OUSTRING_TO_OSTRING_CVTFLAGS(((sal_uInt32)0x0006) | ((sal_uInt32)0x0060) | ((sal_uInt32)0x0100
) | ((sal_uInt32)0x0400) | ((sal_uInt32)0x4000))
);
44}
45
46}
47
48static sal_Unicode NULL_WSTRING[1] = { 0 };
49
50#define BLOP_OFFSET_MAGIC0 0
51#define BLOP_OFFSET_SIZE(0 + sizeof(sal_uInt32)) (BLOP_OFFSET_MAGIC0 + sizeof(sal_uInt32))
52#define BLOP_OFFSET_MINOR((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) (BLOP_OFFSET_SIZE(0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32))
53#define BLOP_OFFSET_MAJOR(((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof(sal_uInt16
))
(BLOP_OFFSET_MINOR((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof(sal_uInt16))
54#define BLOP_OFFSET_N_ENTRIES((((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof(sal_uInt16
)) + sizeof(sal_uInt16))
(BLOP_OFFSET_MAJOR(((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof(sal_uInt16
))
+ sizeof(sal_uInt16))
55#define BLOP_OFFSET_TYPE_SOURCE(((((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof(sal_uInt16
)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16))
(BLOP_OFFSET_N_ENTRIES((((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof(sal_uInt16
)) + sizeof(sal_uInt16))
+ sizeof(sal_uInt16))
56#define BLOP_OFFSET_TYPE_CLASS((((((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof(
sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof
(sal_uInt16))
(BLOP_OFFSET_TYPE_SOURCE(((((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof(sal_uInt16
)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16))
+ sizeof(sal_uInt16))
57#define BLOP_OFFSET_THIS(((((((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof
(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof
(sal_uInt16)) + sizeof(sal_uInt16))
(BLOP_OFFSET_TYPE_CLASS((((((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof(
sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof
(sal_uInt16))
+ sizeof(sal_uInt16))
58#define BLOP_OFFSET_UIK((((((((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof
(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof
(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16))
(BLOP_OFFSET_THIS(((((((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof
(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof
(sal_uInt16)) + sizeof(sal_uInt16))
+ sizeof(sal_uInt16))
59#define BLOP_OFFSET_DOKU(((((((((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof
(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof
(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof
(sal_uInt16))
(BLOP_OFFSET_UIK((((((((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof
(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof
(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16))
+ sizeof(sal_uInt16))
60#define BLOP_OFFSET_FILENAME((((((((((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof
(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof
(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof
(sal_uInt16)) + sizeof(sal_uInt16))
(BLOP_OFFSET_DOKU(((((((((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof
(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof
(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof
(sal_uInt16))
+ sizeof(sal_uInt16))
61#define BLOP_HEADER_N_ENTRIES6 6
62
63#define BLOP_OFFSET_N_SUPERTYPES0 0
64#define BLOP_OFFSET_SUPERTYPES(0 + sizeof(sal_uInt16)) (BLOP_OFFSET_N_SUPERTYPES0 + sizeof(sal_uInt16))
65
66#define BLOP_FIELD_ENTRY_ACCESS0 0
67#define BLOP_FIELD_ENTRY_NAME(0 + sizeof(sal_uInt16)) (BLOP_FIELD_ENTRY_ACCESS0 + sizeof(sal_uInt16))
68#define BLOP_FIELD_ENTRY_TYPE((0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) (BLOP_FIELD_ENTRY_NAME(0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16))
69#define BLOP_FIELD_ENTRY_VALUE(((0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16
))
(BLOP_FIELD_ENTRY_TYPE((0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16))
70#define BLOP_FIELD_ENTRY_DOKU((((0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16
)) + sizeof(sal_uInt16))
(BLOP_FIELD_ENTRY_VALUE(((0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16
))
+ sizeof(sal_uInt16))
71#define BLOP_FIELD_ENTRY_FILENAME(((((0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16
)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16))
(BLOP_FIELD_ENTRY_DOKU((((0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16
)) + sizeof(sal_uInt16))
+ sizeof(sal_uInt16))
72#define BLOP_FIELD_N_ENTRIES6 6
73
74#define BLOP_METHOD_SIZE0 0
75#define BLOP_METHOD_MODE(0 + sizeof(sal_uInt16)) (BLOP_METHOD_SIZE0 + sizeof(sal_uInt16))
76#define BLOP_METHOD_NAME((0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) (BLOP_METHOD_MODE(0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16))
77#define BLOP_METHOD_RETURN(((0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16
))
(BLOP_METHOD_NAME((0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16))
78#define BLOP_METHOD_DOKU((((0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16
)) + sizeof(sal_uInt16))
(BLOP_METHOD_RETURN(((0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16
))
+ sizeof(sal_uInt16))
79#define BLOP_METHOD_N_ENTRIES5 5
80
81#define BLOP_PARAM_TYPE0 0
82#define BLOP_PARAM_MODE(0 + sizeof(sal_uInt16)) (BLOP_PARAM_TYPE0 + sizeof(sal_uInt16))
83#define BLOP_PARAM_NAME((0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) (BLOP_PARAM_MODE(0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16))
84#define BLOP_PARAM_N_ENTRIES3 3
85
86#define BLOP_REFERENCE_TYPE0 0
87#define BLOP_REFERENCE_NAME(0 + sizeof(sal_uInt16)) (BLOP_REFERENCE_TYPE0 + sizeof(sal_uInt16))
88#define BLOP_REFERENCE_DOKU((0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) (BLOP_REFERENCE_NAME(0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16))
89#define BLOP_REFERENCE_ACCESS(((0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16
))
(BLOP_REFERENCE_DOKU((0 + sizeof(sal_uInt16)) + sizeof(sal_uInt16)) + sizeof(sal_uInt16))
90#define BLOP_REFERENCE_N_ENTRIES4 4
91
92sal_uInt32 UINT16StringLen(const sal_uInt8* wstring)
93{
94 if (!wstring) return 0;
95
96 const sal_uInt8* b = wstring;
97
98 while (b[0] || b[1]) b += sizeof(sal_uInt16);
99
100 return ((b - wstring) / sizeof(sal_uInt16));
101}
102
103sal_uInt32 writeString(sal_uInt8* buffer, const sal_Unicode* v)
104{
105 sal_uInt32 len = rtl_ustr_getLength(v) + 1;
106 sal_uInt32 i;
107 sal_uInt8* buff = buffer;
108
109 for (i = 0; i < len; i++)
110 {
111 buff += writeUINT16(buff, (sal_uInt16) v[i]);
112 }
113
114 return (buff - buffer);
115}
116
117sal_uInt32 readString(const sal_uInt8* buffer, sal_Unicode* v, sal_uInt32 maxSize)
118{
119 sal_uInt32 len = SAL_MIN(UINT16StringLen(buffer) + 1, maxSize / 2)(((UINT16StringLen(buffer) + 1) < (maxSize / 2)) ? (UINT16StringLen
(buffer) + 1) : (maxSize / 2))
;
120 sal_uInt32 i;
121 sal_uInt8* buff = (sal_uInt8*)buffer;
122
123 for (i = 0; i < (len - 1); i++)
124 {
125 sal_uInt16 aChar;
126
127 buff += readUINT16(buff, aChar);
128
129 v[i] = (sal_Unicode) aChar;
130 }
131
132 v[len - 1] = L'\0';
133
134 return (buff - ((sal_uInt8*)buffer));
135}
136
137sal_uInt32 writeFloat(sal_uInt8* buffer, float v)
138{
139 union
140 {
141 float v;
142 sal_uInt32 b;
143 } x;
144
145 x.v = v;
146
147#ifdef REGTYPE_IEEE_NATIVE1
148 writeUINT32(buffer, x.b);
149#else
150# error no IEEE
151#endif
152
153 return sizeof(sal_uInt32);
154}
155
156sal_uInt32 writeDouble(sal_uInt8* buffer, double v)
157{
158 union
159 {
160 double v;
161 struct
162 {
163 sal_uInt32 b1;
164 sal_uInt32 b2;
165 } b;
166 } x;
167
168 x.v = v;
169
170#ifdef REGTYPE_IEEE_NATIVE1
171# ifdef OSL_BIGENDIAN
172 writeUINT32(buffer, x.b.b1);
173 writeUINT32(buffer + sizeof(sal_uInt32), x.b.b2);
174# else
175 writeUINT32(buffer, x.b.b2);
176 writeUINT32(buffer + sizeof(sal_uInt32), x.b.b1);
177# endif
178#else
179# error no IEEE
180#endif
181
182 return (sizeof(sal_uInt32) + sizeof(sal_uInt32));
183}
184
185/**************************************************************************
186
187 buffer write functions
188
189**************************************************************************/
190
191
192/**************************************************************************
193
194 struct CPInfo
195
196**************************************************************************/
197
198struct CPInfo
199{
200 CPInfoTag m_tag;
201 union
202 {
203 const sal_Char* aUtf8;
204 RTUik* aUik;
205 RTConstValueUnion aConst;
206 } m_value;
207
208 sal_uInt16 m_index;
209 struct CPInfo* m_next;
210
211 CPInfo(CPInfoTag tag, struct CPInfo* prev);
212
213 sal_uInt32 getBlopSize();
214
215 sal_uInt32 toBlop(sal_uInt8* buffer);
216};
217
218CPInfo::CPInfo(CPInfoTag tag, struct CPInfo* prev)
219 : m_tag(tag)
220 , m_index(0)
221 , m_next(NULL__null)
222{
223 if (prev)
224 {
225 m_index = prev->m_index + 1;
226 prev->m_next = this;
227 }
228}
229
230sal_uInt32 CPInfo::getBlopSize()
231{
232 sal_uInt32 size = sizeof(sal_uInt32) /* size */ + sizeof(sal_uInt16) /* tag */;
233
234 switch (m_tag)
235 {
236 case CP_TAG_CONST_BOOL:
237 size += sizeof(sal_uInt8);
238 break;
239 case CP_TAG_CONST_BYTE:
240 size += sizeof(sal_uInt8);
241 break;
242 case CP_TAG_CONST_INT16:
243 size += sizeof(sal_Int16);
244 break;
245 case CP_TAG_CONST_UINT16:
246 size += sizeof(sal_uInt16);
247 break;
248 case CP_TAG_CONST_INT32:
249 size += sizeof(sal_Int32);
250 break;
251 case CP_TAG_CONST_UINT32:
252 size += sizeof(sal_uInt32);
253 break;
254 case CP_TAG_CONST_INT64:
255 size += sizeof(sal_Int64);
256 break;
257 case CP_TAG_CONST_UINT64:
258 size += sizeof(sal_uInt64);
259 break;
260 case CP_TAG_CONST_FLOAT:
261 size += sizeof(sal_uInt32);
262 break;
263 case CP_TAG_CONST_DOUBLE:
264 size += sizeof(sal_uInt32) + sizeof(sal_uInt32);
265 break;
266 case CP_TAG_CONST_STRING:
267 size += (rtl_ustr_getLength(m_value.aConst.aString) + 1) * sizeof(sal_uInt16);
268 break;
269 case CP_TAG_UTF8_NAME:
270 size += strlen(m_value.aUtf8) + 1;
271 break;
272 case CP_TAG_UIK:
273 size += sizeof(sal_uInt32) + sizeof(sal_uInt16) + sizeof(sal_uInt16) + sizeof(sal_uInt32) + sizeof(sal_uInt32);
274 break;
275 default:
276 break;
277 }
278
279 return size;
280}
281
282
283sal_uInt32 CPInfo::toBlop(sal_uInt8* buffer)
284{
285 sal_uInt8* buff = buffer;
286
287 buff += writeUINT32(buff, getBlopSize());
288 buff += writeUINT16(buff, (sal_uInt16) m_tag);
289
290 switch (m_tag)
291 {
292 case CP_TAG_CONST_BOOL:
293 buff += writeBYTE(buff, (sal_uInt8) m_value.aConst.aBool);
294 break;
295 case CP_TAG_CONST_BYTE:
296 buff += writeBYTE(
297 buff, static_cast< sal_uInt8 >(m_value.aConst.aByte));
298 break;
299 case CP_TAG_CONST_INT16:
300 buff += writeINT16(buff, m_value.aConst.aShort);
301 break;
302 case CP_TAG_CONST_UINT16:
303 buff += writeINT16(buff, m_value.aConst.aUShort);
304 break;
305 case CP_TAG_CONST_INT32:
306 buff += writeINT32(buff, m_value.aConst.aLong);
307 break;
308 case CP_TAG_CONST_UINT32:
309 buff += writeUINT32(buff, m_value.aConst.aULong);
310 break;
311 case CP_TAG_CONST_INT64:
312 buff += writeUINT64(buff, m_value.aConst.aHyper);
313 break;
314 case CP_TAG_CONST_UINT64:
315 buff += writeUINT64(buff, m_value.aConst.aUHyper);
316 break;
317 case CP_TAG_CONST_FLOAT:
318 buff += writeFloat(buff, m_value.aConst.aFloat);
319 break;
320 case CP_TAG_CONST_DOUBLE:
321 buff += writeDouble(buff, m_value.aConst.aDouble);
322 break;
323 case CP_TAG_CONST_STRING:
324 buff += writeString(buff, m_value.aConst.aString);
325 break;
326 case CP_TAG_UTF8_NAME:
327 buff += writeUtf8(buff, m_value.aUtf8);
328 break;
329 case CP_TAG_UIK:
330 buff += writeUINT32(buff, m_value.aUik->m_Data1);
331 buff += writeUINT16(buff, m_value.aUik->m_Data2);
332 buff += writeUINT16(buff, m_value.aUik->m_Data3);
333 buff += writeUINT32(buff, m_value.aUik->m_Data4);
334 buff += writeUINT32(buff, m_value.aUik->m_Data5);
335 break;
336 default:
337 break;
338 }
339
340 return (buff - buffer);
341}
342
343
344/**************************************************************************
345
346 class FieldEntry
347
348**************************************************************************/
349
350class FieldEntry
351{
352
353public:
354
355 OString m_name;
356 OString m_typeName;
357 OString m_doku;
358 OString m_fileName;
359 RTFieldAccess m_access;
360 RTValueType m_constValueType;
361 RTConstValueUnion m_constValue;
362
363 FieldEntry();
364 ~FieldEntry();
365
366 void setData(const OString& name,
367 const OString& typeName,
368 const OString& doku,
369 const OString& fileName,
370 RTFieldAccess access,
371 RTValueType constValueType,
372 RTConstValueUnion constValue);
373 // throws std::bad_alloc
374};
375
376FieldEntry::FieldEntry()
377 : m_access(RT_ACCESS_INVALID0x0000)
378 , m_constValueType(RT_TYPE_NONE)
379{
380}
381
382FieldEntry::~FieldEntry()
383{
384 if (
385 (m_constValueType == RT_TYPE_STRING) &&
386 m_constValue.aString &&
387 (m_constValue.aString != NULL_WSTRING)
388 )
389 {
390 delete[] (sal_Unicode*)m_constValue.aString;
391 }
392}
393
394void FieldEntry::setData(const OString& name,
395 const OString& typeName,
396 const OString& doku,
397 const OString& fileName,
398 RTFieldAccess access,
399 RTValueType constValueType,
400 RTConstValueUnion constValue)
401{
402 sal_Unicode * newValue = 0;
403 if (constValueType == RT_TYPE_STRING && constValue.aString != 0) {
404 sal_Int32 n = rtl_ustr_getLength(constValue.aString) + 1;
405 newValue = new sal_Unicode[n];
406 memcpy(newValue, constValue.aString, n * sizeof (sal_Unicode));
407 }
408
409 m_name = name;
410 m_typeName = typeName;
411 m_doku = doku;
412 m_fileName = fileName;
413
414 if (
415 (m_constValueType == RT_TYPE_STRING) &&
416 m_constValue.aString &&
417 (m_constValue.aString != NULL_WSTRING)
418 )
419 {
420 delete[] (sal_Unicode*)m_constValue.aString;
421 }
422
423 m_access = access;
424 m_constValueType = constValueType;
425
426 if (m_constValueType == RT_TYPE_STRING)
427 {
428 if (constValue.aString == NULL__null)
429 m_constValue.aString = NULL_WSTRING;
430 else
431 {
432 m_constValue.aString = newValue;
433 }
434 }
435 else
436 {
437 m_constValue = constValue;
438 }
439}
440
441/**************************************************************************
442
443 class ParamEntry
444
445**************************************************************************/
446
447class ParamEntry
448{
449public:
450
451 OString m_typeName;
452 OString m_name;
453 RTParamMode m_mode;
454
455 ParamEntry();
456 ~ParamEntry();
457
458 void setData(const OString& typeName,
459 const OString& name,
460 RTParamMode mode);
461};
462
463ParamEntry::ParamEntry()
464 : m_mode(RT_PARAM_INVALID)
465{
466}
467
468ParamEntry::~ParamEntry()
469{
470}
471
472void ParamEntry::setData(const OString& typeName,
473 const OString& name,
474 RTParamMode mode)
475{
476 m_name = name;
477 m_typeName = typeName;
478 m_mode = mode;
479}
480
481/**************************************************************************
482
483 class ReferenceEntry
484
485**************************************************************************/
486
487class ReferenceEntry
488{
489public:
490
491 OString m_name;
492 OString m_doku;
493 RTReferenceType m_type;
494 RTFieldAccess m_access;
495
496 ReferenceEntry();
497 ~ReferenceEntry();
498
499 void setData(const OString& name,
500 RTReferenceType refType,
501 const OString& doku,
502 RTFieldAccess access);
503};
504
505ReferenceEntry::ReferenceEntry()
506 : m_type(RT_REF_INVALID)
507 , m_access(RT_ACCESS_INVALID0x0000)
508{
509}
510
511ReferenceEntry::~ReferenceEntry()
512{
513}
514
515void ReferenceEntry::setData(const OString& name,
516 RTReferenceType refType,
517 const OString& doku,
518 RTFieldAccess access)
519{
520 m_name = name;
521 m_doku = doku;
522 m_type = refType;
523 m_access = access;
524}
525
526/**************************************************************************
527
528 class MethodEntry
529
530**************************************************************************/
531
532class MethodEntry
533{
534public:
535
536 OString m_name;
537 OString m_returnTypeName;
538 RTMethodMode m_mode;
539 sal_uInt16 m_paramCount;
540 ParamEntry* m_params;
541 sal_uInt16 m_excCount;
542 OString* m_excNames;
543 OString m_doku;
544
545 MethodEntry();
546 ~MethodEntry();
547
548 void setData(const OString& name,
549 const OString& returnTypeName,
550 RTMethodMode mode,
551 sal_uInt16 paramCount,
552 sal_uInt16 excCount,
553 const OString& doku);
554
555 void setExcName(sal_uInt16 excIndex, const OString& name);
556
557protected:
558
559 void reallocParams(sal_uInt16 size);
560 void reallocExcs(sal_uInt16 size);
561};
562
563MethodEntry::MethodEntry()
564 : m_mode(RT_MODE_INVALID)
565 , m_paramCount(0)
566 , m_params(NULL__null)
567 , m_excCount(0)
568 , m_excNames(NULL__null)
569{
570}
571
572MethodEntry::~MethodEntry()
573{
574 if (m_params)
575 delete[] m_params;
576
577 if (m_excNames)
578 delete[] m_excNames;
579}
580
581void MethodEntry::setData(const OString& name,
582 const OString& returnTypeName,
583 RTMethodMode mode,
584 sal_uInt16 paramCount,
585 sal_uInt16 excCount,
586 const OString& doku)
587{
588 m_name = name;
589 m_returnTypeName = returnTypeName;
590 m_doku = doku;
591
592 m_mode = mode;
593
594 reallocParams(paramCount);
2
Calling 'reallocParams'
595 reallocExcs(excCount);
596}
597
598void MethodEntry::setExcName(sal_uInt16 excIndex, const OString& name)
599{
600 if (excIndex < m_excCount)
601 {
602 m_excNames[excIndex] = name;
603 }
604}
605
606void MethodEntry::reallocParams(sal_uInt16 size)
607{
608 ParamEntry* newParams;
609
610 if (size)
3
Taking false branch
611 newParams = new ParamEntry[size];
612 else
613 newParams = NULL__null;
614
615 if (m_paramCount)
4
Taking true branch
616 {
617 sal_uInt16 i;
618
619 for (i = 0; i < SAL_MIN(size, m_paramCount)(((size) < (m_paramCount)) ? (size) : (m_paramCount)); i++)
5
Loop condition is true. Entering loop body
620 {
621 newParams[i].setData(m_params[i].m_typeName, m_params[i].m_name, m_params[i].m_mode);
6
Called C++ object pointer is null
622 }
623
624 delete[] m_params;
625 }
626
627 m_paramCount = size;
628 m_params = newParams;
629}
630
631void MethodEntry::reallocExcs(sal_uInt16 size)
632{
633 OString* newExcNames;
634
635 if (size)
636 newExcNames = new OString[size];
637 else
638 newExcNames = NULL__null;
639
640 sal_uInt16 i;
641
642 for (i = 0; i < SAL_MIN(size, m_excCount)(((size) < (m_excCount)) ? (size) : (m_excCount)); i++)
643 {
644 newExcNames[i] = m_excNames[i];
645 }
646
647 delete[] m_excNames;
648
649 m_excCount = size;
650 m_excNames = newExcNames;
651}
652
653
654/**************************************************************************
655
656 class TypeRegistryEntry
657
658**************************************************************************/
659
660class TypeWriter
661{
662
663public:
664
665 sal_uInt32 m_refCount;
666 typereg_Version m_version;
667 RTTypeClass m_typeClass;
668 OString m_typeName;
669 sal_uInt16 m_nSuperTypes;
670 OString* m_superTypeNames;
671 RTUik* m_pUik;
672 OString m_doku;
673 OString m_fileName;
674 sal_uInt16 m_fieldCount;
675 FieldEntry* m_fields;
676 sal_uInt16 m_methodCount;
677 MethodEntry* m_methods;
678 sal_uInt16 m_referenceCount;
679 ReferenceEntry* m_references;
680
681 sal_uInt8* m_blop;
682 sal_uInt32 m_blopSize;
683
684 TypeWriter(typereg_Version version,
685 rtl::OString const & documentation,
686 rtl::OString const & fileName,
687 RTTypeClass RTTypeClass,
688 bool published,
689 const OString& typeName,
690 sal_uInt16 superTypeCount,
691 sal_uInt16 FieldCount,
692 sal_uInt16 methodCount,
693 sal_uInt16 referenceCount);
694
695 ~TypeWriter();
696
697 void setSuperType(sal_uInt16 index, OString const & name);
698
699 void createBlop(); // throws std::bad_alloc
700};
701
702TypeWriter::TypeWriter(typereg_Version version,
703 rtl::OString const & documentation,
704 rtl::OString const & fileName,
705 RTTypeClass RTTypeClass,
706 bool published,
707 const OString& typeName,
708 sal_uInt16 superTypeCount,
709 sal_uInt16 fieldCount,
710 sal_uInt16 methodCount,
711 sal_uInt16 referenceCount)
712 : m_refCount(1)
713 , m_version(version)
714 , m_typeClass(
715 static_cast< enum RTTypeClass >(
716 RTTypeClass | (published ? RT_TYPE_PUBLISHED : 0)))
717 , m_typeName(typeName)
718 , m_nSuperTypes(superTypeCount)
719 , m_pUik(NULL__null)
720 , m_doku(documentation)
721 , m_fileName(fileName)
722 , m_fieldCount(fieldCount)
723 , m_methodCount(methodCount)
724 , m_referenceCount(referenceCount)
725 , m_blop(NULL__null)
726 , m_blopSize(0)
727{
728 if (m_nSuperTypes > 0)
729 {
730 m_superTypeNames = new OString[m_nSuperTypes];
731 } else
732 {
733 m_superTypeNames = NULL__null;
734 }
735
736 if (m_fieldCount)
737 m_fields = new FieldEntry[fieldCount];
738
739 if (m_methodCount)
740 m_methods = new MethodEntry[methodCount];
741
742 if (m_referenceCount)
743 m_references = new ReferenceEntry[referenceCount];
744}
745
746TypeWriter::~TypeWriter()
747{
748 if (m_superTypeNames)
749 delete[] m_superTypeNames;
750
751 if (m_blop)
752 delete[] m_blop;
753
754 if (m_fieldCount)
755 delete[] m_fields;
756
757 if (m_methodCount)
758 delete[] m_methods;
759
760 if (m_referenceCount)
761 delete[] m_references;
762
763 if (m_pUik)
764 delete m_pUik;
765}
766
767void TypeWriter::setSuperType(sal_uInt16 index, OString const & name)
768{
769 m_superTypeNames[index] = name;
770}
771
772void TypeWriter::createBlop()
773{
774 //TODO: Fix memory leaks that occur when std::bad_alloc is thrown
775
776 sal_uInt8* pBlopFields = NULL__null;
777 sal_uInt8* pBlopMethods = NULL__null;
778 sal_uInt8* pBlopReferences = NULL__null;
779 sal_uInt8* pBuffer = NULL__null;
780 sal_uInt32 blopFieldsSize = 0;
781 sal_uInt32 blopMethodsSize = 0;
782 sal_uInt32 blopReferenceSize = 0;
783
784 CPInfo root(CP_TAG_INVALID, NULL__null);
785 sal_uInt16 cpIndexThisName = 0;
786 sal_uInt16* cpIndexSuperNames = NULL__null;
787 sal_uInt16 cpIndexUik = 0;
788 sal_uInt16 cpIndexDoku = 0;
789 sal_uInt16 cpIndexFileName = 0;
790 CPInfo* pInfo = NULL__null;
791
792 sal_uInt16 entrySize = sizeof(sal_uInt16);
793 sal_uInt32 blopHeaderEntrySize = BLOP_OFFSET_N_ENTRIES((((0 + sizeof(sal_uInt32)) + sizeof(sal_uInt32)) + sizeof(sal_uInt16
)) + sizeof(sal_uInt16))
+ entrySize + (BLOP_HEADER_N_ENTRIES6 * entrySize);
794 sal_uInt32 blopFieldEntrySize = BLOP_FIELD_N_ENTRIES6 * entrySize;
795 sal_uInt32 blopMethodEntrySize = BLOP_METHOD_N_ENTRIES5 * entrySize;
796 sal_uInt32 blopParamEntrySize = BLOP_PARAM_N_ENTRIES3 * entrySize;
797 sal_uInt32 blopReferenceEntrySize = BLOP_REFERENCE_N_ENTRIES4 * entrySize;
798
799 sal_uInt32 blopSize = blopHeaderEntrySize;
800
801 // create CP entry for this name
802 pInfo = new CPInfo(CP_TAG_UTF8_NAME, &root);
803 pInfo->m_value.aUtf8 = m_typeName.getStr();
804 cpIndexThisName = pInfo->m_index;
805
806 // nSuperTypes
807 blopSize += entrySize;
808
809 // create CP entry for super names
810 if (m_nSuperTypes)
811 {
812 blopSize += m_nSuperTypes * entrySize;
813
814 cpIndexSuperNames = new sal_uInt16[m_nSuperTypes];
815
816 for (sal_uInt32 i=0; i < m_nSuperTypes; i++)
817 {
818 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
819 pInfo->m_value.aUtf8 = m_superTypeNames[i].getStr();
820 cpIndexSuperNames[i] = pInfo->m_index;
821 }
822 }
823
824 // create CP entry for uik
825 if (m_pUik != NULL__null)
826 {
827 pInfo = new CPInfo(CP_TAG_UIK, pInfo);
828 pInfo->m_value.aUik = m_pUik;
829 cpIndexUik = pInfo->m_index;
830 }
831
832 // create CP entry for doku
833 if (!m_doku.isEmpty())
834 {
835 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
836 pInfo->m_value.aUtf8 = m_doku.getStr();
837 cpIndexDoku = pInfo->m_index;
838 }
839
840 // create CP entry for idl source filename
841 if (!m_fileName.isEmpty())
842 {
843 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
844 pInfo->m_value.aUtf8 = m_fileName.getStr();
845 cpIndexFileName = pInfo->m_index;
846 }
847
848 // fields blop
849 blopSize += sizeof(sal_uInt16); // fieldCount + nFieldEntries
850
851 if (m_fieldCount)
852 {
853 sal_uInt16 cpIndexName = 0;
854 sal_uInt16 cpIndexTypeName = 0;
855 sal_uInt16 cpIndexValue = 0;
856 sal_uInt16 cpIndexDoku2 = 0;
857 sal_uInt16 cpIndexFileName2 = 0;
858
859 // nFieldEntries + n fields
860 blopFieldsSize = sizeof(sal_uInt16) + (m_fieldCount * blopFieldEntrySize);
861
862 blopSize += blopFieldsSize;
863
864 pBlopFields = new sal_uInt8[blopFieldsSize];
865 pBuffer = pBlopFields;
866
867 pBuffer += writeUINT16(pBuffer, BLOP_FIELD_N_ENTRIES6);
868
869 for (sal_uInt16 i = 0; i < m_fieldCount; i++)
870 {
871 cpIndexName = 0;
872 cpIndexTypeName = 0;
873 cpIndexValue = 0;
874 cpIndexDoku2 = 0;
875 cpIndexFileName2 = 0;
876
877 pBuffer += writeUINT16(pBuffer, m_fields[i].m_access);
878
879 if (!m_fields[i].m_name.isEmpty())
880 {
881 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
882 pInfo->m_value.aUtf8 = m_fields[i].m_name.getStr();
883 cpIndexName = pInfo->m_index;
884 }
885 pBuffer += writeUINT16(pBuffer, cpIndexName);
886
887 if (!m_fields[i].m_typeName.isEmpty())
888 {
889 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
890 pInfo->m_value.aUtf8 = m_fields[i].m_typeName.getStr();
891 cpIndexTypeName = pInfo->m_index;
892 }
893 pBuffer += writeUINT16(pBuffer, cpIndexTypeName);
894
895 if (m_fields[i].m_constValueType != RT_TYPE_NONE)
896 {
897 pInfo = new CPInfo((CPInfoTag)m_fields[i].m_constValueType, pInfo);
898 pInfo->m_value.aConst = m_fields[i].m_constValue;
899 cpIndexValue = pInfo->m_index;
900 }
901 pBuffer += writeUINT16(pBuffer, cpIndexValue);
902
903 if (!m_fields[i].m_doku.isEmpty())
904 {
905 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
906 pInfo->m_value.aUtf8 = m_fields[i].m_doku.getStr();
907 cpIndexDoku2 = pInfo->m_index;
908 }
909 pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
910
911 if (!m_fields[i].m_fileName.isEmpty())
912 {
913 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
914 pInfo->m_value.aUtf8 = m_fields[i].m_fileName.getStr();
915 cpIndexFileName2 = pInfo->m_index;
916 }
917 pBuffer += writeUINT16(pBuffer, cpIndexFileName2);
918 }
919 }
920
921 // methods blop
922 blopSize += sizeof(sal_uInt16); // methodCount
923
924 if (m_methodCount)
925 {
926 sal_uInt16* pMethodEntrySize = new sal_uInt16[m_methodCount];
927 sal_uInt16 cpIndexName = 0;
928 sal_uInt16 cpIndexReturn = 0;
929 sal_uInt16 cpIndexDoku2 = 0;
930
931 // nMethodEntries + nParamEntries
932 blopMethodsSize = (2 * sizeof(sal_uInt16));
933
934 for (sal_uInt16 i = 0; i < m_methodCount; i++)
935 {
936 pMethodEntrySize[i] = (sal_uInt16)
937 ( blopMethodEntrySize + // header
938 sizeof(sal_uInt16) + // parameterCount
939 (m_methods[i].m_paramCount * blopParamEntrySize) + // exceptions
940 sizeof(sal_uInt16) + // exceptionCount
941 (m_methods[i].m_excCount * sizeof(sal_uInt16)) ); // exceptions
942
943 blopMethodsSize += pMethodEntrySize[i];
944 }
945
946 pBlopMethods = new sal_uInt8[blopMethodsSize];
947
948 blopSize += blopMethodsSize;
949
950 pBuffer = pBlopMethods;
951
952 pBuffer += writeUINT16(pBuffer, BLOP_METHOD_N_ENTRIES5);
953 pBuffer += writeUINT16(pBuffer, BLOP_PARAM_N_ENTRIES3 );
954
955 for (sal_uInt16 i = 0; i < m_methodCount; i++)
956 {
957 cpIndexReturn = 0;
958 cpIndexDoku2 = 0;
959
960 pBuffer += writeUINT16(pBuffer, pMethodEntrySize[i]);
961 pBuffer += writeUINT16(
962 pBuffer,
963 sal::static_int_cast< sal_uInt16 >(m_methods[i].m_mode));
964
965 if (!m_methods[i].m_name.isEmpty())
966 {
967 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
968 pInfo->m_value.aUtf8 = m_methods[i].m_name.getStr();
969 cpIndexName = pInfo->m_index;
970 }
971 pBuffer += writeUINT16(pBuffer, cpIndexName);
972 cpIndexName = 0;
973
974 if (!m_methods[i].m_returnTypeName.isEmpty())
975 {
976 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
977 pInfo->m_value.aUtf8 = m_methods[i].m_returnTypeName.getStr();
978 cpIndexReturn = pInfo->m_index;
979 }
980 pBuffer += writeUINT16(pBuffer, cpIndexReturn);
981
982 if (!m_methods[i].m_doku.isEmpty())
983 {
984 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
985 pInfo->m_value.aUtf8 = m_methods[i].m_doku.getStr();
986 cpIndexDoku2 = pInfo->m_index;
987 }
988 pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
989
990 sal_uInt16 j;
991
992 pBuffer += writeUINT16(pBuffer, m_methods[i].m_paramCount);
993
994 for (j = 0; j < m_methods[i].m_paramCount; j++)
995 {
996 if (!m_methods[i].m_params[j].m_typeName.isEmpty())
997 {
998 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
999 pInfo->m_value.aUtf8 = m_methods[i].m_params[j].m_typeName.getStr();
1000 cpIndexName = pInfo->m_index;
1001 }
1002 pBuffer += writeUINT16(pBuffer, cpIndexName);
1003 cpIndexName = 0;
1004
1005 pBuffer += writeUINT16(
1006 pBuffer,
1007 sal::static_int_cast< sal_uInt16 >(
1008 m_methods[i].m_params[j].m_mode));
1009
1010 if (!m_methods[i].m_params[j].m_name.isEmpty())
1011 {
1012 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
1013 pInfo->m_value.aUtf8 = m_methods[i].m_params[j].m_name.getStr();
1014 cpIndexName = pInfo->m_index;
1015 }
1016 pBuffer += writeUINT16(pBuffer, cpIndexName);
1017 cpIndexName = 0;
1018 }
1019
1020 pBuffer += writeUINT16(pBuffer, m_methods[i].m_excCount);
1021
1022 for (j = 0; j < m_methods[i].m_excCount; j++)
1023 {
1024 if (!m_methods[i].m_excNames[j].isEmpty())
1025 {
1026 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
1027 pInfo->m_value.aUtf8 = m_methods[i].m_excNames[j].getStr();
1028 cpIndexName = pInfo->m_index;
1029 }
1030 pBuffer += writeUINT16(pBuffer, cpIndexName);
1031 cpIndexName = 0;
1032 }
1033 }
1034
1035 delete[] pMethodEntrySize;
1036 }
1037
1038 // reference blop
1039 blopSize += entrySize; // referenceCount
1040
1041 if (m_referenceCount)
1042 {
1043 sal_uInt16 cpIndexName = 0;
1044 sal_uInt16 cpIndexDoku2 = 0;
1045
1046 // nReferenceEntries + n references
1047 blopReferenceSize = entrySize + (m_referenceCount * blopReferenceEntrySize);
1048
1049 blopSize += blopReferenceSize;
1050
1051 pBlopReferences = new sal_uInt8[blopReferenceSize];
1052 pBuffer = pBlopReferences;
1053
1054 pBuffer += writeUINT16(pBuffer, BLOP_REFERENCE_N_ENTRIES4);
1055
1056 for (sal_uInt16 i = 0; i < m_referenceCount; i++)
1057 {
1058 pBuffer += writeUINT16(
1059 pBuffer,
1060 sal::static_int_cast< sal_uInt16 >(m_references[i].m_type));
1061
1062 cpIndexName = 0;
1063 cpIndexDoku2 = 0;
1064
1065 if (!m_references[i].m_name.isEmpty())
1066 {
1067 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
1068 pInfo->m_value.aUtf8 = m_references[i].m_name.getStr();
1069 cpIndexName = pInfo->m_index;
1070 }
1071 pBuffer += writeUINT16(pBuffer, cpIndexName);
1072
1073 if (!m_references[i].m_doku.isEmpty())
1074 {
1075 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
1076 pInfo->m_value.aUtf8 = m_references[i].m_doku.getStr();
1077 cpIndexDoku2 = pInfo->m_index;
1078 }
1079 pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
1080
1081 pBuffer += writeUINT16(pBuffer, m_references[i].m_access);
1082 }
1083 }
1084
1085
1086 // get CP infos blop-length
1087 pInfo = root.m_next;
1088 sal_uInt32 cpBlopSize = 0;
1089 sal_uInt16 cpCount = 0;
1090
1091 while (pInfo)
1092 {
1093 cpBlopSize += pInfo->getBlopSize();
1094 cpCount++;
1095 pInfo = pInfo->m_next;
1096 }
1097
1098 blopSize += cpBlopSize;
1099 blopSize += sizeof(sal_uInt16); // constantPoolCount
1100
1101 // write all in flat buffer
1102
1103 sal_uInt8 * blop = new sal_uInt8[blopSize];
1104
1105 pBuffer = blop;
1106
1107 // Assumes two's complement arithmetic with modulo-semantics:
1108 pBuffer += writeUINT32(pBuffer, magic + m_version);
1109 pBuffer += writeUINT32(pBuffer, blopSize);
1110 pBuffer += writeUINT16(pBuffer, minorVersion);
1111 pBuffer += writeUINT16(pBuffer, majorVersion);
1112 pBuffer += writeUINT16(pBuffer, BLOP_HEADER_N_ENTRIES6);
1113
1114 pBuffer += writeUINT16(pBuffer, (sal_uInt16)RT_UNO_IDL);
1115 pBuffer += writeUINT16(pBuffer, (sal_uInt16)m_typeClass);
1116 pBuffer += writeUINT16(pBuffer, cpIndexThisName);
1117 pBuffer += writeUINT16(pBuffer, cpIndexUik);
1118 pBuffer += writeUINT16(pBuffer, cpIndexDoku);
1119 pBuffer += writeUINT16(pBuffer, cpIndexFileName);
1120
1121 // write supertypes
1122 pBuffer += writeUINT16(pBuffer, m_nSuperTypes);
1123 if (m_nSuperTypes)
1124 {
1125 for (sal_uInt32 i=0; i < m_nSuperTypes; i++)
1126 {
1127 pBuffer += writeUINT16(pBuffer, cpIndexSuperNames[i]);
1128 }
1129 delete[] cpIndexSuperNames;
1130 }
1131
1132 pBuffer += writeUINT16(pBuffer, cpCount);
1133
1134 // write and delete CP infos
1135 pInfo = root.m_next;
1136
1137 while (pInfo)
1138 {
1139 CPInfo* pNextInfo = pInfo->m_next;
1140
1141 pBuffer += pInfo->toBlop(pBuffer);
1142 delete pInfo;
1143
1144 pInfo = pNextInfo;
1145 }
1146
1147 // write fields
1148 pBuffer += writeUINT16(pBuffer, m_fieldCount);
1149 if (blopFieldsSize)
1150 {
1151 memcpy(pBuffer, pBlopFields, blopFieldsSize);
1152 pBuffer += blopFieldsSize;
1153 }
1154
1155 // write methods
1156 pBuffer += writeUINT16(pBuffer, m_methodCount);
1157 if (blopMethodsSize)
1158 {
1159 memcpy(pBuffer, pBlopMethods, blopMethodsSize);
1160 pBuffer += blopMethodsSize;
1161 }
1162
1163 // write references
1164 pBuffer += writeUINT16(pBuffer, m_referenceCount);
1165 if (blopReferenceSize)
1166 {
1167 memcpy(pBuffer, pBlopReferences, blopReferenceSize);
1168 pBuffer += blopReferenceSize;
1169 }
1170
1171 delete[] pBlopFields;
1172 delete[] pBlopMethods;
1173 delete[] pBlopReferences;
1174
1175 delete[] m_blop;
1176 m_blop = blop;
1177 m_blopSize = blopSize;
1178}
1179
1180
1181/**************************************************************************
1182
1183 C-API
1184
1185**************************************************************************/
1186
1187extern "C" {
1188
1189static void TYPEREG_CALLTYPE acquire(TypeWriterImpl hEntry)
1190{
1191 TypeWriter* pEntry = (TypeWriter*) hEntry;
1192
1193 if (pEntry != NULL__null)
1194 pEntry->m_refCount++;
1195}
1196
1197static void TYPEREG_CALLTYPE release(TypeWriterImpl hEntry)
1198{
1199 TypeWriter* pEntry = (TypeWriter*) hEntry;
1200
1201 if (pEntry != NULL__null)
1202 {
1203 if (--pEntry->m_refCount == 0)
1204 delete pEntry;
1205 }
1206}
1207
1208static void TYPEREG_CALLTYPE setUik(TypeWriterImpl hEntry, const RTUik* uik)
1209{
1210 TypeWriter* pEntry = (TypeWriter*) hEntry;
1211
1212 if (pEntry != NULL__null)
1213 {
1214 if (pEntry->m_pUik)
1215 {
1216 pEntry->m_pUik->m_Data1 = uik->m_Data1;
1217 pEntry->m_pUik->m_Data2 = uik->m_Data2;
1218 pEntry->m_pUik->m_Data3 = uik->m_Data3;
1219 pEntry->m_pUik->m_Data4 = uik->m_Data4;
1220 pEntry->m_pUik->m_Data5 = uik->m_Data5;
1221 }
1222 else
1223 pEntry->m_pUik = new RTUik(*uik);
1224 }
1225}
1226
1227static void TYPEREG_CALLTYPE setDoku(TypeWriterImpl hEntry, rtl_uString* doku)
1228{
1229 static_cast< TypeWriter * >(hEntry)->m_doku = toByteString(doku);
1230}
1231
1232static void TYPEREG_CALLTYPE setFileName(TypeWriterImpl hEntry, rtl_uString* fileName)
1233{
1234 static_cast< TypeWriter * >(hEntry)->m_fileName = toByteString(fileName);
1235}
1236
1237REG_DLLPUBLIC__attribute__ ((visibility("default"))) sal_Bool TYPEREG_CALLTYPE typereg_writer_setFieldData(
1238 void * handle, sal_uInt16 index, rtl_uString const * documentation,
1239 rtl_uString const * fileName, RTFieldAccess flags, rtl_uString const * name,
1240 rtl_uString const * typeName, RTValueType valueType,
1241 RTConstValueUnion valueValue)
1242 SAL_THROW_EXTERN_C()throw ()
1243{
1244 try {
1245 static_cast< TypeWriter * >(handle)->m_fields[index].setData(
1246 toByteString(name), toByteString(typeName),
1247 toByteString(documentation), toByteString(fileName), flags,
1248 valueType, valueValue);
1249 } catch (std::bad_alloc &) {
1250 return false;
1251 }
1252 return true;
1253}
1254
1255static void TYPEREG_CALLTYPE setFieldData(TypeWriterImpl hEntry,
1256 sal_uInt16 index,
1257 rtl_uString* name,
1258 rtl_uString* typeName,
1259 rtl_uString* doku,
1260 rtl_uString* fileName,
1261 RTFieldAccess access,
1262 RTValueType valueType,
1263 RTConstValueUnion constValue)
1264{
1265 typereg_writer_setFieldData(
1266 hEntry, index, doku, fileName, access, name, typeName, valueType,
1267 constValue);
1268}
1269
1270REG_DLLPUBLIC__attribute__ ((visibility("default"))) sal_Bool TYPEREG_CALLTYPE typereg_writer_setMethodData(
1271 void * handle, sal_uInt16 index, rtl_uString const * documentation,
1272 RTMethodMode flags, rtl_uString const * name,
1273 rtl_uString const * returnTypeName, sal_uInt16 parameterCount,
1274 sal_uInt16 exceptionCount)
1275 SAL_THROW_EXTERN_C()throw ()
1276{
1277 try {
1278 static_cast< TypeWriter * >(handle)->m_methods[index].setData(
1
Calling 'setData'
1279 toByteString(name), toByteString(returnTypeName), flags,
1280 parameterCount, exceptionCount, toByteString(documentation));
1281 } catch (std::bad_alloc &) {
1282 return false;
1283 }
1284 return true;
1285}
1286
1287static void TYPEREG_CALLTYPE setMethodData(TypeWriterImpl hEntry,
1288 sal_uInt16 index,
1289 rtl_uString* name,
1290 rtl_uString* returnTypeName,
1291 RTMethodMode mode,
1292 sal_uInt16 paramCount,
1293 sal_uInt16 excCount,
1294 rtl_uString* doku)
1295{
1296 typereg_writer_setMethodData(
1297 hEntry, index, doku, mode, name, returnTypeName, paramCount, excCount);
1298}
1299
1300REG_DLLPUBLIC__attribute__ ((visibility("default"))) sal_Bool TYPEREG_CALLTYPE typereg_writer_setMethodParameterData(
1301 void * handle, sal_uInt16 methodIndex, sal_uInt16 parameterIndex,
1302 RTParamMode flags, rtl_uString const * name, rtl_uString const * typeName)
1303 SAL_THROW_EXTERN_C()throw ()
1304{
1305 try {
1306 static_cast< TypeWriter * >(handle)->
1307 m_methods[methodIndex].m_params[parameterIndex].setData(
1308 toByteString(typeName), toByteString(name), flags);
1309 } catch (std::bad_alloc &) {
1310 return false;
1311 }
1312 return true;
1313}
1314
1315static void TYPEREG_CALLTYPE setParamData(TypeWriterImpl hEntry,
1316 sal_uInt16 index,
1317 sal_uInt16 paramIndex,
1318 rtl_uString* type,
1319 rtl_uString* name,
1320 RTParamMode mode)
1321{
1322 typereg_writer_setMethodParameterData(
1323 hEntry, index, paramIndex, mode, name, type);
1324}
1325
1326REG_DLLPUBLIC__attribute__ ((visibility("default"))) sal_Bool TYPEREG_CALLTYPE typereg_writer_setMethodExceptionTypeName(
1327 void * handle, sal_uInt16 methodIndex, sal_uInt16 exceptionIndex,
1328 rtl_uString const * typeName)
1329 SAL_THROW_EXTERN_C()throw ()
1330{
1331 try {
1332 static_cast< TypeWriter * >(handle)->m_methods[methodIndex].setExcName(
1333 exceptionIndex, toByteString(typeName));
1334 } catch (std::bad_alloc &) {
1335 return false;
1336 }
1337 return true;
1338}
1339
1340static void TYPEREG_CALLTYPE setExcData(TypeWriterImpl hEntry,
1341 sal_uInt16 index,
1342 sal_uInt16 excIndex,
1343 rtl_uString* type)
1344{
1345 typereg_writer_setMethodExceptionTypeName(hEntry, index, excIndex, type);
1346}
1347
1348REG_DLLPUBLIC__attribute__ ((visibility("default"))) void const * TYPEREG_CALLTYPE typereg_writer_getBlob(void * handle, sal_uInt32 * size)
1349 SAL_THROW_EXTERN_C()throw ()
1350{
1351 TypeWriter * writer = static_cast< TypeWriter * >(handle);
1352 if (writer->m_blop == 0) {
1353 try {
1354 writer->createBlop();
1355 } catch (std::bad_alloc &) {
1356 return 0;
1357 }
1358 }
1359 *size = writer->m_blopSize;
1360 return writer->m_blop;
1361}
1362
1363static const sal_uInt8* TYPEREG_CALLTYPE getBlop(TypeWriterImpl hEntry)
1364{
1365 sal_uInt32 size;
1366 return static_cast< sal_uInt8 const * >(
1367 typereg_writer_getBlob(hEntry, &size));
1368}
1369
1370static sal_uInt32 TYPEREG_CALLTYPE getBlopSize(TypeWriterImpl hEntry)
1371{
1372 sal_uInt32 size;
1373 typereg_writer_getBlob(hEntry, &size);
1374 return size;
1375}
1376
1377REG_DLLPUBLIC__attribute__ ((visibility("default"))) sal_Bool TYPEREG_CALLTYPE typereg_writer_setReferenceData(
1378 void * handle, sal_uInt16 index, rtl_uString const * documentation,
1379 RTReferenceType sort, RTFieldAccess flags, rtl_uString const * typeName)
1380 SAL_THROW_EXTERN_C()throw ()
1381{
1382 try {
1383 static_cast< TypeWriter * >(handle)->m_references[index].setData(
1384 toByteString(typeName), sort, toByteString(documentation), flags);
1385 } catch (std::bad_alloc &) {
1386 return false;
1387 }
1388 return true;
1389}
1390
1391static void TYPEREG_CALLTYPE setReferenceData(TypeWriterImpl hEntry,
1392 sal_uInt16 index,
1393 rtl_uString* name,
1394 RTReferenceType refType,
1395 rtl_uString* doku,
1396 RTFieldAccess access)
1397{
1398 typereg_writer_setReferenceData(hEntry, index, doku, refType, access, name);
1399}
1400
1401REG_DLLPUBLIC__attribute__ ((visibility("default"))) void * TYPEREG_CALLTYPE typereg_writer_create(
1402 typereg_Version version, rtl_uString const * documentation,
1403 rtl_uString const * fileName, RTTypeClass typeClass, sal_Bool published,
1404 rtl_uString const * typeName, sal_uInt16 superTypeCount,
1405 sal_uInt16 fieldCount, sal_uInt16 methodCount, sal_uInt16 referenceCount)
1406 SAL_THROW_EXTERN_C()throw ()
1407{
1408 try {
1409 return new TypeWriter(
1410 version, toByteString(documentation), toByteString(fileName),
1411 typeClass, published, toByteString(typeName), superTypeCount,
1412 fieldCount, methodCount, referenceCount);
1413 } catch (std::bad_alloc &) {
1414 return 0;
1415 }
1416}
1417
1418REG_DLLPUBLIC__attribute__ ((visibility("default"))) void TYPEREG_CALLTYPE typereg_writer_destroy(void * handle) SAL_THROW_EXTERN_C()throw () {
1419 delete static_cast< TypeWriter * >(handle);
1420}
1421
1422REG_DLLPUBLIC__attribute__ ((visibility("default"))) sal_Bool TYPEREG_CALLTYPE typereg_writer_setSuperTypeName(
1423 void * handle, sal_uInt16 index, rtl_uString const * typeName)
1424 SAL_THROW_EXTERN_C()throw ()
1425{
1426 try {
1427 static_cast< TypeWriter * >(handle)->setSuperType(
1428 index, toByteString(typeName));
1429 } catch (std::bad_alloc &) {
1430 return false;
1431 }
1432 return true;
1433}
1434
1435static TypeWriterImpl TYPEREG_CALLTYPE createEntry(
1436 RTTypeClass typeClass, rtl_uString * typeName, rtl_uString * superTypeName,
1437 sal_uInt16 fieldCount, sal_uInt16 methodCount, sal_uInt16 referenceCount)
1438{
1439 rtl::OUString empty;
1440 sal_uInt16 superTypeCount = rtl_uString_getLength(superTypeName) == 0
1441 ? 0 : 1;
1442 TypeWriterImpl t = typereg_writer_create(
1443 TYPEREG_VERSION_0, empty.pData, empty.pData, typeClass, false, typeName,
1444 superTypeCount, fieldCount, methodCount, referenceCount);
1445 if (superTypeCount > 0) {
1446 typereg_writer_setSuperTypeName(t, 0, superTypeName);
1447 }
1448 return t;
1449}
1450
1451REG_DLLPUBLIC__attribute__ ((visibility("default"))) RegistryTypeWriter_Api* TYPEREG_CALLTYPE initRegistryTypeWriter_Api(void)
1452{
1453 static RegistryTypeWriter_Api aApi= {0,0,0,0,0,0,0,0,0,0,0,0,0};
1454 if (!aApi.acquire)
1455 {
1456 aApi.createEntry = &createEntry;
1457 aApi.acquire = &acquire;
1458 aApi.release = &release;
1459 aApi.setUik = &setUik;
1460 aApi.setDoku = &setDoku;
1461 aApi.setFileName = &setFileName;
1462 aApi.setFieldData = &setFieldData;
1463 aApi.setMethodData = &setMethodData;
1464 aApi.setParamData = &setParamData;
1465 aApi.setExcData = &setExcData;
1466 aApi.getBlop = &getBlop;
1467 aApi.getBlopSize = &getBlopSize;
1468 aApi.setReferenceData = &setReferenceData;
1469
1470 return (&aApi);
1471 }
1472 else
1473 {
1474 return (&aApi);
1475 }
1476}
1477
1478}
1479
1480/* vim:set shiftwidth=4 softtabstop=4 expandtab: */