summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorStephan Bergmann <stephan.bergmann@allotropia.de>2024-04-29 14:20:05 +0200
committerStephan Bergmann <stephan.bergmann@allotropia.de>2024-04-30 07:53:11 +0200
commit735ea444f2c15771736260fc78704f6b9132ceac (patch)
treef06900aed489e47b4144512dcddf06ebbc8f7417 /static
parent621cfc0e4120ab2b381b54268fe39bd19257df9b (diff)
Embind: Fix out-param handling
...by using UnoInOutParam in all cases. Some types whose Embind mappings don't employ any smart pointers (like any and sequence) would have worked directly with pointers, but others (like string and type) would have caused Embind errors at runtime. So consistently use UnoInOutParam in all cases (and generate bindings for all the used cases in embindmaker). Change-Id: If26551bf4e99d10748aec1597d6e99f994dfd86e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166854 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Diffstat (limited to 'static')
-rw-r--r--static/source/embindmaker/embindmaker.cxx79
-rw-r--r--static/source/unoembindhelpers/PrimaryBindings.cxx18
2 files changed, 35 insertions, 62 deletions
diff --git a/static/source/embindmaker/embindmaker.cxx b/static/source/embindmaker/embindmaker.cxx
index 6c0017ccb8c2..0b7634cf8409 100644
--- a/static/source/embindmaker/embindmaker.cxx
+++ b/static/source/embindmaker/embindmaker.cxx
@@ -558,49 +558,13 @@ void dumpParameters(std::ostream& out, rtl::Reference<TypeManager> const& manage
{
out << ", ";
}
- bool wrap = false;
- if (param.direction != unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
- {
- switch (manager->getSort(resolveOuterTypedefs(manager, param.type)))
- {
- case codemaker::UnoType::Sort::Boolean:
- case codemaker::UnoType::Sort::Byte:
- case codemaker::UnoType::Sort::Short:
- case codemaker::UnoType::Sort::UnsignedShort:
- case codemaker::UnoType::Sort::Long:
- case codemaker::UnoType::Sort::UnsignedLong:
- case codemaker::UnoType::Sort::Hyper:
- case codemaker::UnoType::Sort::UnsignedHyper:
- case codemaker::UnoType::Sort::Float:
- case codemaker::UnoType::Sort::Double:
- case codemaker::UnoType::Sort::Char:
- case codemaker::UnoType::Sort::Enum:
- wrap = true;
- break;
- case codemaker::UnoType::Sort::String:
- case codemaker::UnoType::Sort::Type:
- case codemaker::UnoType::Sort::Any:
- case codemaker::UnoType::Sort::Sequence:
- case codemaker::UnoType::Sort::PlainStruct:
- case codemaker::UnoType::Sort::InstantiatedPolymorphicStruct:
- case codemaker::UnoType::Sort::Interface:
- break;
- default:
- throw CannotDumpException("unexpected entity \"" + param.type
- + "\" as parameter type");
- }
- }
if (declarations)
{
- if (wrap)
+ if (param.direction != unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
{
out << "::unoembindhelpers::UnoInOutParam<";
}
dumpType(out, manager, param.type);
- if (wrap)
- {
- out << ">";
- }
if (param.direction == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
{
if (passByReference(manager, param.type))
@@ -610,17 +574,13 @@ void dumpParameters(std::ostream& out, rtl::Reference<TypeManager> const& manage
}
else
{
- out << " *";
+ out << "> *";
}
out << " ";
}
- else if (param.direction != unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN
- && !wrap)
- {
- out << "*";
- }
out << param.name;
- if (!declarations && wrap)
+ if (!declarations
+ && param.direction != unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
{
out << "->value";
}
@@ -872,6 +832,13 @@ void recordSequenceTypes(rtl::Reference<TypeManager> const& manager, OUString co
}
}
+void recordInOutParameterType(rtl::Reference<TypeManager> const& manager, OUString const& type,
+ std::set<OUString>& inOutParameters)
+{
+ auto const res = resolveAllTypedefs(manager, type);
+ inOutParameters.insert(res);
+}
+
void writeJsMap(std::ostream& out, Module const& module, std::string const& prefix)
{
auto comma = false;
@@ -1041,6 +1008,7 @@ SAL_IMPLEMENT_MAIN()
recordSequenceTypes(mgr, mem.type, sequences);
}
}
+ std::set<OUString> inOutParams;
for (auto const& ifc : interfaces)
{
auto const ent = mgr->getManager()->findEntity(ifc);
@@ -1113,6 +1081,11 @@ SAL_IMPLEMENT_MAIN()
for (auto const& param : meth.parameters)
{
recordSequenceTypes(mgr, param.type, sequences);
+ if (param.direction
+ != unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
+ {
+ recordInOutParameterType(mgr, param.type, inOutParams);
+ }
}
recordSequenceTypes(mgr, meth.returnType, sequences);
}
@@ -1160,6 +1133,24 @@ SAL_IMPLEMENT_MAIN()
}
cppOut << "_" << jsName(nuc) << "\");\n";
}
+ for (auto const& par : inOutParams)
+ {
+ cppOut << " ::unoembindhelpers::registerInOutParameter<";
+ dumpType(cppOut, mgr, par);
+ cppOut << ">(\"uno_InOutParam_";
+ sal_Int32 k;
+ auto const nuc = b2u(codemaker::UnoType::decompose(u2b(par), &k));
+ if (k >= 1)
+ {
+ cppOut << "sequence";
+ if (k > 1)
+ {
+ cppOut << k;
+ }
+ cppOut << "_";
+ }
+ cppOut << jsName(nuc.replace(' ', '_')) << "\");\n";
+ }
cppOut << "}\n";
cppOut.close();
if (!cppOut)
diff --git a/static/source/unoembindhelpers/PrimaryBindings.cxx b/static/source/unoembindhelpers/PrimaryBindings.cxx
index 6ae2e68323dc..4972699178c8 100644
--- a/static/source/unoembindhelpers/PrimaryBindings.cxx
+++ b/static/source/unoembindhelpers/PrimaryBindings.cxx
@@ -158,12 +158,6 @@ void copyStruct(typelib_CompoundTypeDescription* desc, void const* source, void*
}
}
-template <typename T> void registerInOutParam(char const* name)
-{
- class_<unoembindhelpers::UnoInOutParam<T>>(name).constructor().constructor<T>().property(
- "val", &unoembindhelpers::UnoInOutParam<T>::get, &unoembindhelpers::UnoInOutParam<T>::set);
-}
-
Reference<css::frame::XModel> getCurrentModelFromViewSh()
{
SfxViewShell* pSh = nullptr;
@@ -386,18 +380,6 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings)
};
});
- registerInOutParam<sal_Bool>("uno_InOutParam_boolean");
- registerInOutParam<sal_Int8>("uno_InOutParam_byte");
- registerInOutParam<sal_Int16>("uno_InOutParam_short");
- registerInOutParam<sal_uInt16>("uno_InOutParam_unsigned_short");
- registerInOutParam<sal_Int32>("uno_InOutParam_long");
- registerInOutParam<sal_uInt32>("uno_InOutParam_unsigned_long");
- registerInOutParam<sal_Int64>("uno_InOutParam_hyper");
- registerInOutParam<sal_uInt64>("uno_InOutParam_unsigned_hyper");
- registerInOutParam<float>("uno_InOutParam_float");
- registerInOutParam<double>("uno_InOutParam_double");
- registerInOutParam<sal_Unicode>("uno_InOutParam_char");
-
function("getCurrentModelFromViewSh", &getCurrentModelFromViewSh);
function("getUnoComponentContext", &comphelper::getProcessComponentContext);
function("throwUnoException", +[](css::uno::Type const& type, emscripten::val const& value) {