[Libreoffice-bugs] [Bug 133887] New: Invoking a Basic routine with ByRef Variant parameter returns wrong value type

bugzilla-daemon at bugs.documentfoundation.org bugzilla-daemon at bugs.documentfoundation.org
Thu Jun 11 09:30:57 UTC 2020


https://bugs.documentfoundation.org/show_bug.cgi?id=133887

            Bug ID: 133887
           Summary: Invoking a Basic routine with ByRef Variant parameter
                    returns wrong value type
           Product: LibreOffice
           Version: Inherited From OOo
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Keywords: difficultyBeginner, easyHack, skillCpp
          Severity: normal
          Priority: medium
         Component: BASIC
          Assignee: libreoffice-bugs at lists.freedesktop.org
          Reporter: mikekaganski at hotmail.com
                CC: andreas.heinisch at yahoo.de

Created attachment 161869
  --> https://bugs.documentfoundation.org/attachment.cgi?id=161869&action=edit
A test document with macros

This is one of two related bug reports (the other is to follow); the attached
test document contains the tests for both. Please run TestByRefFromInvoke, and
only check first line of output for the purposes of this bug.

If there is a routine with a ByRef (default) parameter (i.e., inout parameter),
invoking it using XScript::invoke [1] requires passing *in* values through the
first array (sequence), and getting their modified *out* values in the last
passed array:

> Sub Foo(v) ' default ByRef As Variant
>     v = 6.75
> End Sub

> Sub TestInvoke
>     oScript = thisComponent.getScriptProvider().getScript("vnd.sun.star.script:Standard.Module1.Foo?language=Basic&location=document")
>     oScript.invoke(Array(0), aOutInd, aOutArr)
>     MsgBox aOutArr(0)
> End Sub

TestInvoke above passes "0" as initial value of the variable passed to the Foo,
and expects to get the modified value in the aOutArr(0) - i.e., it should
output "6.75".

However, the actual returned value is 7 - i.e., the result is converted to an
integral type. It is possible to get the correct result by modifying the value
passed to invoke call like this:

>     oScript.invoke(Array(0.1), aOutInd, aOutArr)

I.e., the type of returned value depends on the passed value. Passing an
integer value result in integer, Passing a string would result in "6.75"
returned as string...

The problem was introduced in
https://git.libreoffice.org/core/+/2115a3492c5b73f6a3666761a0290d5511d8091e for
i#66055, where passed variables made fixed to enable correct ByRef handling of
arguments with explicit integral types. However, this means that when we pass
an Integer to the code, its type is fixed at this point, and later the
assignment of a value of a different type converts the type to the original
fixed type.

The introduced code in practice made the variable fixed unconditionally, since
unoToSbxValue does not return an SbxVARIANT.

The OOo bug report referred to SbiRuntime::SetParameters; and the latter checks
not only the type of the passed value for being SbxVARIANT, but also the type
of the parameter of the method. So we should extend the mentioned OOo bug fix
to do the same in the BasicScriptImpl::invoke: get the type of variable; then
if we have pInfo, and it returns valid 
param info for this param, we should get the type of the param instead; and
only then, if the resulting type is not SbxVARIANT, we should set the "fixed"
flag.

[1]
https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1script_1_1provider_1_1XScript.html

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice-bugs/attachments/20200611/767fb5e8/attachment.htm>


More information about the Libreoffice-bugs mailing list