Skip to content

Temporary fix method binder for out parameters #1672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@
- ([@DanBarzilian](https://github.com/DanBarzilian))
- ([@alxnull](https://github.com/alxnull))
- ([@gpetrou](https://github.com/gpetrou))
- Ehsan Iran-Nejad ([@eirannejad](https://github.com/eirannejad))
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Instead, `PyIterable` does that.
- Empty parameter names (as can be generated from F#) do not cause crashes
- Unicode strings with surrogates were truncated when converting from Python
- `Reload` mode now supports generic methods (previously Python would stop seeing them after reload)
- Temporarily fixed issue resolving method overload when method signature has `out` parameters ([#1672](i1672))

### Removed

Expand Down Expand Up @@ -881,3 +882,4 @@ This version improves performance on benchmarks significantly compared to 2.3.
[i1342]: https://github.com/pythonnet/pythonnet/issues/1342
[i238]: https://github.com/pythonnet/pythonnet/issues/238
[i1481]: https://github.com/pythonnet/pythonnet/issues/1481
[i1672]: https://github.com/pythonnet/pythonnet/pull/1672
8 changes: 8 additions & 0 deletions src/runtime/MethodBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,11 @@ static BorrowedReference HandleParamsArray(BorrowedReference args, int arrayStar
margs[paramIndex] = defaultArgList[paramIndex - pyArgCount];
}

if (parameter.ParameterType.IsByRef)
{
outs++;
}

continue;
}

Expand Down Expand Up @@ -817,6 +822,9 @@ static bool MatchesArgumentCount(int positionalArgumentCount, ParameterInfo[] pa
defaultArgList.Add(parameters[v].GetDefaultValue());
defaultsNeeded++;
}
else if (parameters[v].IsOut) {
defaultArgList.Add(null);
}
else if (!paramsArray)
{
match = false;
Expand Down
38 changes: 38 additions & 0 deletions tests/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,16 @@ def test_string_out_params():
assert result[1] == "output string"


def test_string_out_params_without_passing_string_value():
"""Test use of string out-parameters."""
# @eirannejad 2022-01-13
result = MethodTest.TestStringOutParams("hi")
assert isinstance(result, tuple)
assert len(result) == 2
assert result[0] is True
assert result[1] == "output string"


def test_string_ref_params():
"""Test use of string byref parameters."""
result = MethodTest.TestStringRefParams("hi", "there")
Expand Down Expand Up @@ -308,6 +318,16 @@ def test_value_out_params():
MethodTest.TestValueOutParams("hi", None)


def test_value_out_params_without_passing_string_value():
"""Test use of string out-parameters."""
# @eirannejad 2022-01-13
result = MethodTest.TestValueOutParams("hi")
assert isinstance(result, tuple)
assert len(result) == 2
assert result[0] is True
assert result[1] == 42


def test_value_ref_params():
"""Test use of value type byref parameters."""
result = MethodTest.TestValueRefParams("hi", 1)
Expand Down Expand Up @@ -336,6 +356,15 @@ def test_object_out_params():
assert isinstance(result[1], System.Exception)


def test_object_out_params_without_passing_string_value():
"""Test use of object out-parameters."""
result = MethodTest.TestObjectOutParams("hi")
assert isinstance(result, tuple)
assert len(result) == 2
assert result[0] is True
assert isinstance(result[1], System.Exception)


def test_object_ref_params():
"""Test use of object byref parameters."""
result = MethodTest.TestObjectRefParams("hi", MethodTest())
Expand Down Expand Up @@ -364,6 +393,15 @@ def test_struct_out_params():
MethodTest.TestValueRefParams("hi", None)


def test_struct_out_params_without_passing_string_value():
"""Test use of struct out-parameters."""
result = MethodTest.TestStructOutParams("hi")
assert isinstance(result, tuple)
assert len(result) == 2
assert result[0] is True
assert isinstance(result[1], System.Guid)


def test_struct_ref_params():
"""Test use of struct byref parameters."""
result = MethodTest.TestStructRefParams("hi", System.Guid.NewGuid())
Expand Down