From e4cf6c324cd7491444576ee57d60475d0c4f239c Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 30 Jan 2024 22:30:13 +0100 Subject: [PATCH] Embind in-out/out params of primitive type apparently need a wrapper > let translit = css.i18n.Transliteration.create(Module.getUnoComponentContext()); > let match1; > let match2; > let eq = translit.equals(new Module.OUString("test1"), 0, 5, match1, new Module.OUString("test2"), 0, 5, match2); > console.log('match ' + eq + ', ' + match1 + ', ' + match2); caused an uncaught UnboundTypeError with message "Cannot call uno_Type_com$sun$star$i18n$XTransliteration.equals due to unbound types: Pl", so use > let translit = css.i18n.Transliteration.create(Module.getUnoComponentContext()); > let match1 = new Module.UnoInOutParamLong; > let match2 = new Module.UnoInOutParamLong; > let eq = translit.equals(new Module.OUString("test1"), 0, 5, match1, new Module.OUString("test2"), 0, 5, match2); > console.log('match ' + eq + ', ' + match1.val + ', ' + match2.val); > delete match1; > delete match2; instead Change-Id: Ic5a0a9e37e884817158069702510eab0d29adefa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162784 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- .../unoembindhelpers/PrimaryBindings.hxx | 16 ++++++ static/source/embindmaker/embindmaker.cxx | 47 +++++++++++++++- .../unoembindhelpers/PrimaryBindings.cxx | 56 +++++++++++++++++++ 3 files changed, 118 insertions(+), 1 deletion(-) diff --git a/include/static/unoembindhelpers/PrimaryBindings.hxx b/include/static/unoembindhelpers/PrimaryBindings.hxx index 0c744502848e..5b677345b86b 100644 --- a/include/static/unoembindhelpers/PrimaryBindings.hxx +++ b/include/static/unoembindhelpers/PrimaryBindings.hxx @@ -32,6 +32,22 @@ enum class uno_Reference { FromAny }; + +template struct UnoInOutParam +{ + UnoInOutParam() {} + + UnoInOutParam(T the_value) + : value(the_value) + { + } + + T get() const { return value; } + + void set(T the_value) { value = the_value; } + + T value; +}; } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/static/source/embindmaker/embindmaker.cxx b/static/source/embindmaker/embindmaker.cxx index 6a9083f28516..cb0ad6c04445 100644 --- a/static/source/embindmaker/embindmaker.cxx +++ b/static/source/embindmaker/embindmaker.cxx @@ -444,9 +444,49 @@ 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) + { + 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)) @@ -460,11 +500,16 @@ void dumpParameters(std::ostream& out, rtl::Reference const& manage } out << " "; } - else if (param.direction != unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN) + else if (param.direction != unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN + && !wrap) { out << "*"; } out << param.name; + if (!declarations && wrap) + { + out << "->value"; + } } } diff --git a/static/source/unoembindhelpers/PrimaryBindings.cxx b/static/source/unoembindhelpers/PrimaryBindings.cxx index 4277af563936..0a87d32e2710 100644 --- a/static/source/unoembindhelpers/PrimaryBindings.cxx +++ b/static/source/unoembindhelpers/PrimaryBindings.cxx @@ -111,6 +111,62 @@ EMSCRIPTEN_BINDINGS(PrimaryBindings) }, allow_raw_pointers()); + class_>("UnoInOutParamBoolean") + .constructor() + .constructor() + .property("val", &unoembindhelpers::UnoInOutParam::get, + &unoembindhelpers::UnoInOutParam::set); + class_>("UnoInOutParamByte") + .constructor() + .constructor() + .property("val", &unoembindhelpers::UnoInOutParam::get, + &unoembindhelpers::UnoInOutParam::set); + class_>("UnoInOutParamShort") + .constructor() + .constructor() + .property("val", &unoembindhelpers::UnoInOutParam::get, + &unoembindhelpers::UnoInOutParam::set); + class_>("UnoInOutParamUnsignedShort") + .constructor() + .constructor() + .property("val", &unoembindhelpers::UnoInOutParam::get, + &unoembindhelpers::UnoInOutParam::set); + class_>("UnoInOutParamLong") + .constructor() + .constructor() + .property("val", &unoembindhelpers::UnoInOutParam::get, + &unoembindhelpers::UnoInOutParam::set); + class_>("UnoInOutParamUnsignedLong") + .constructor() + .constructor() + .property("val", &unoembindhelpers::UnoInOutParam::get, + &unoembindhelpers::UnoInOutParam::set); + class_>("UnoInOutParamHyper") + .constructor() + .constructor() + .property("val", &unoembindhelpers::UnoInOutParam::get, + &unoembindhelpers::UnoInOutParam::set); + class_>("UnoInOutParamUnsignedHyper") + .constructor() + .constructor() + .property("val", &unoembindhelpers::UnoInOutParam::get, + &unoembindhelpers::UnoInOutParam::set); + class_>("UnoInOutParamFloat") + .constructor() + .constructor() + .property("val", &unoembindhelpers::UnoInOutParam::get, + &unoembindhelpers::UnoInOutParam::set); + class_>("UnoInOutParamDouble") + .constructor() + .constructor() + .property("val", &unoembindhelpers::UnoInOutParam::get, + &unoembindhelpers::UnoInOutParam::set); + class_>("UnoInOutParamChar") + .constructor() + .constructor() + .property("val", &unoembindhelpers::UnoInOutParam::get, + &unoembindhelpers::UnoInOutParam::set); + function("getCurrentModelFromViewSh", &getCurrentModelFromViewSh); function("getUnoComponentContext", &comphelper::getProcessComponentContext); }