Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/bridges/source/cpp_uno/shared/component.cxx
Line
Count
Source
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
#include <bridge.hxx>
21
22
#include <com/sun/star/uno/Reference.hxx>
23
#include <com/sun/star/uno/RuntimeException.hpp>
24
#include <com/sun/star/uno/XInterface.hpp>
25
#include <rtl/process.h>
26
#include <rtl/ustrbuf.hxx>
27
#include <rtl/ustring.h>
28
#include <rtl/ustring.hxx>
29
#include <sal/log.hxx>
30
#include <sal/types.h>
31
#include <uno/environment.h>
32
#include <uno/lbnames.h>
33
#include <uno/mapping.h>
34
#include <cppu/EnvDcp.hxx>
35
36
37
namespace {
38
39
const OUString & cppu_cppenv_getStaticOIdPart()
40
120k
{
41
120k
    static OUString s_aStaticOidPart = []() {
42
13
        OUStringBuffer aRet(64);
43
13
        aRet.append("];");
44
        // good guid
45
13
        sal_uInt8 ar[16];
46
13
        ::rtl_getGlobalProcessId(ar);
47
13
        for (unsigned char i : ar)
48
208
        {
49
208
            aRet.append(static_cast<sal_Int32>(i), 16);
50
208
        }
51
13
        return aRet.makeStringAndClear();
52
13
    }();
53
120k
    return s_aStaticOidPart;
54
120k
}
55
56
}
57
58
extern "C" {
59
60
static void s_stub_computeObjectIdentifier(va_list * pParam)
61
120k
{
62
120k
    uno_ExtEnvironment  * pEnv       = va_arg(*pParam, uno_ExtEnvironment *);
63
120k
    rtl_uString        ** ppOId      = va_arg(*pParam, rtl_uString **);
64
120k
    void                * pInterface = va_arg(*pParam, void *);
65
66
67
120k
    assert(pEnv && ppOId && pInterface);
68
120k
    if (!(pEnv && ppOId && pInterface))
69
0
        return;
70
71
120k
    if (*ppOId)
72
0
    {
73
0
        rtl_uString_release( *ppOId );
74
0
        *ppOId = nullptr;
75
0
    }
76
77
120k
    try
78
120k
    {
79
120k
        ::com::sun::star::uno::Reference<
80
120k
              ::com::sun::star::uno::XInterface > xHome(
81
120k
                  static_cast< css::uno::XInterface * >(
82
120k
                      pInterface ),
83
120k
                  ::com::sun::star::uno::UNO_QUERY );
84
120k
        assert(xHome.is() && "### query to XInterface failed!");
85
120k
        if (xHome.is())
86
120k
        {
87
            // interface
88
120k
            OUString aRet =
89
120k
                OUString::number( reinterpret_cast< sal_IntPtr >(xHome.get()), 16 ) +
90
120k
                ";" +
91
                // ;environment[context]
92
120k
                OUString::unacquired(&pEnv->aBase.pTypeName) +
93
120k
                "[" +
94
120k
                OUString::number( reinterpret_cast< sal_IntPtr >(pEnv->aBase.pContext), 16 ) +
95
                // ];good guid
96
120k
                cppu_cppenv_getStaticOIdPart();
97
120k
            *ppOId = aRet.pData;
98
120k
            ::rtl_uString_acquire( *ppOId );
99
120k
        }
100
120k
    }
101
120k
    catch (const css::uno::RuntimeException & e)
102
120k
    {
103
0
        SAL_WARN("bridges",
104
0
            "### RuntimeException occurred during queryInterface(): "
105
0
            << e.Message);
106
0
    }
107
120k
}
108
109
static void computeObjectIdentifier(
110
    uno_ExtEnvironment * pExtEnv, rtl_uString ** ppOId, void * pInterface )
111
120k
{
112
120k
    uno_Environment_invoke(&pExtEnv->aBase, s_stub_computeObjectIdentifier, pExtEnv, ppOId, pInterface);
113
120k
}
114
115
static void s_stub_acquireInterface(va_list * pParam)
116
150k
{
117
150k
    /*uno_ExtEnvironment * pExtEnv = */va_arg(*pParam, uno_ExtEnvironment *);
118
150k
    void               * pCppI   = va_arg(*pParam, void *);
119
120
150k
    static_cast< css::uno::XInterface * >( pCppI )->acquire();
121
150k
}
122
123
static void acquireInterface( uno_ExtEnvironment * pExtEnv, void * pCppI )
124
150k
{
125
150k
    uno_Environment_invoke(&pExtEnv->aBase, s_stub_acquireInterface, pExtEnv, pCppI);
126
150k
}
127
128
static void s_stub_releaseInterface(va_list * pParam)
129
120k
{
130
120k
    /*uno_ExtEnvironment * pExtEnv = */va_arg(*pParam, uno_ExtEnvironment *);
131
120k
    void               * pCppI   = va_arg(*pParam, void *);
132
133
120k
    static_cast< css::uno::XInterface * >( pCppI )->release();
134
120k
}
135
136
static void releaseInterface( uno_ExtEnvironment * pExtEnv, void * pCppI )
137
120k
{
138
120k
    uno_Environment_invoke(&pExtEnv->aBase, s_stub_releaseInterface, pExtEnv, pCppI);
139
120k
}
140
141
static void environmentDisposing(
142
    SAL_UNUSED_PARAMETER uno_Environment * )
143
68.5k
{
144
68.5k
}
145
146
#ifdef DISABLE_DYNLOADING
147
#define uno_initEnvironment CPPU_ENV_uno_initEnvironment
148
#endif
149
150
SAL_DLLPUBLIC_EXPORT void uno_initEnvironment(uno_Environment * pCppEnv) noexcept
151
68.5k
{
152
68.5k
    assert(pCppEnv->pExtEnv);
153
68.5k
    assert(
154
68.5k
        ::rtl_ustr_ascii_compare_WithLength(
155
68.5k
             pCppEnv->pTypeName->buffer, rtl_str_getLength(CPPU_CURRENT_LANGUAGE_BINDING_NAME), CPPU_CURRENT_LANGUAGE_BINDING_NAME )
156
68.5k
        == 0
157
68.5k
        && "### wrong environment type!");
158
68.5k
    reinterpret_cast<uno_ExtEnvironment *>(pCppEnv)->computeObjectIdentifier
159
68.5k
        = computeObjectIdentifier;
160
68.5k
    reinterpret_cast<uno_ExtEnvironment *>(pCppEnv)->acquireInterface = acquireInterface;
161
68.5k
    reinterpret_cast<uno_ExtEnvironment *>(pCppEnv)->releaseInterface = releaseInterface;
162
68.5k
    pCppEnv->environmentDisposing = environmentDisposing;
163
68.5k
}
164
165
#ifdef DISABLE_DYNLOADING
166
#define uno_ext_getMapping CPPU_ENV_uno_ext_getMapping
167
#endif
168
169
SAL_DLLPUBLIC_EXPORT void uno_ext_getMapping(
170
    uno_Mapping ** ppMapping, uno_Environment * pFrom, uno_Environment * pTo) noexcept
171
136k
{
172
136k
    assert(ppMapping && pFrom && pTo);
173
136k
    if (!(ppMapping && pFrom && pTo && pFrom->pExtEnv && pTo->pExtEnv))
174
0
        return;
175
176
136k
    uno_Mapping * pMapping = nullptr;
177
178
136k
    OUString from_envTypeName(cppu::EnvDcp::getTypeName(pFrom->pTypeName));
179
136k
    OUString to_envTypeName(cppu::EnvDcp::getTypeName(pTo->pTypeName));
180
181
136k
    if (rtl_ustr_ascii_compare(
182
136k
            from_envTypeName.pData->buffer,
183
136k
            CPPU_CURRENT_LANGUAGE_BINDING_NAME ) == 0 &&
184
68.0k
        rtl_ustr_ascii_compare(
185
68.0k
            to_envTypeName.pData->buffer, UNO_LB_UNO ) == 0)
186
68.0k
    {
187
        // ref count initially 1
188
68.0k
        pMapping = bridges::cpp_uno::shared::Bridge::createMapping(
189
68.0k
            pFrom->pExtEnv, pTo->pExtEnv, true );
190
68.0k
        ::uno_registerMapping(
191
68.0k
            &pMapping, bridges::cpp_uno::shared::freeMapping,
192
68.0k
            &pFrom->pExtEnv->aBase,
193
68.0k
            &pTo->pExtEnv->aBase, nullptr );
194
68.0k
    }
195
68.0k
    else if (rtl_ustr_ascii_compare(
196
68.0k
                 to_envTypeName.pData->buffer,
197
68.0k
                 CPPU_CURRENT_LANGUAGE_BINDING_NAME ) == 0 &&
198
68.0k
             rtl_ustr_ascii_compare(
199
68.0k
                 from_envTypeName.pData->buffer, UNO_LB_UNO ) == 0)
200
68.0k
    {
201
        // ref count initially 1
202
68.0k
        pMapping = bridges::cpp_uno::shared::Bridge::createMapping(
203
68.0k
            pTo->pExtEnv, pFrom->pExtEnv, false );
204
68.0k
        ::uno_registerMapping(
205
68.0k
            &pMapping, bridges::cpp_uno::shared::freeMapping,
206
68.0k
            &pFrom->pExtEnv->aBase,
207
68.0k
            &pTo->pExtEnv->aBase, nullptr );
208
68.0k
    }
209
210
136k
    if (*ppMapping)
211
0
    {
212
0
        (*(*ppMapping)->release)( *ppMapping );
213
0
    }
214
136k
    if (pMapping)
215
136k
        *ppMapping = pMapping;
216
136k
}
217
218
}
219
220
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */