From 735ea444f2c15771736260fc78704f6b9132ceac Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 29 Apr 2024 14:20:05 +0200 Subject: 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 --- static/source/embindmaker/embindmaker.cxx | 79 ++++++++++------------ static/source/unoembindhelpers/PrimaryBindings.cxx | 18 ----- 2 files changed, 35 insertions(+), 62 deletions(-) (limited to 'static') 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 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 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 const& manager, OUString co } } +void recordInOutParameterType(rtl::Reference const& manager, OUString const& type, + std::set& 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 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 void registerInOutParam(char const* name) -{ - class_>(name).constructor().constructor().property( - "val", &unoembindhelpers::UnoInOutParam::get, &unoembindhelpers::UnoInOutParam::set); -} - Reference getCurrentModelFromViewSh() { SfxViewShell* pSh = nullptr; @@ -386,18 +380,6 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings) }; }); - registerInOutParam("uno_InOutParam_boolean"); - registerInOutParam("uno_InOutParam_byte"); - registerInOutParam("uno_InOutParam_short"); - registerInOutParam("uno_InOutParam_unsigned_short"); - registerInOutParam("uno_InOutParam_long"); - registerInOutParam("uno_InOutParam_unsigned_long"); - registerInOutParam("uno_InOutParam_hyper"); - registerInOutParam("uno_InOutParam_unsigned_hyper"); - registerInOutParam("uno_InOutParam_float"); - registerInOutParam("uno_InOutParam_double"); - registerInOutParam("uno_InOutParam_char"); - function("getCurrentModelFromViewSh", &getCurrentModelFromViewSh); function("getUnoComponentContext", &comphelper::getProcessComponentContext); function("throwUnoException", +[](css::uno::Type const& type, emscripten::val const& value) { -- cgit