- Notifications
You must be signed in to change notification settings - Fork768
#2240 Recursion error when doing reversed python operations on C# types#2327
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
5d551fb Tests for operators on type CS type with codec
gertdreyere7a3aba Bugfix: RecursionError when reverse/righthand operations invoked. e.g…
gertdreyerc256746 Update Authors and Changelog
gertdreyer5277ed9 Normalized names. Added HashCode and Equals to testing objects
gertdreyered2505c Cleanup Codec/Argument Reversing Passing.
gertdreyerFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Bugfix: RecursionError when reverse/righthand operations invoked. e.g…
…. __rsub__, __rmul__
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commite7a3aba0733ab3b76ac7c87815df7b06ad057ab8
There are no files selected for viewing
2 changes: 1 addition & 1 deletionsrc/runtime/ClassManager.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
40 changes: 24 additions & 16 deletionssrc/runtime/MethodBinder.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -28,17 +28,22 @@ internal class MethodBinder | ||
| [NonSerialized] | ||
| public bool init = false; | ||
| public const bool DefaultAllowThreads = true; | ||
| public bool allow_threads = DefaultAllowThreads; | ||
| public bool args_reversed = false; | ||
| internal MethodBinder(bool reverse_args = false) | ||
gertdreyer marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| { | ||
| list = new List<MaybeMethodBase>(); | ||
| args_reversed = reverse_args; | ||
| } | ||
| internal MethodBinder(MethodInfo mi, bool reverse_args = false) | ||
| { | ||
| list = new List<MaybeMethodBase> { new MaybeMethodBase(mi) }; | ||
| args_reversed = reverse_args; | ||
| } | ||
| public int Count | ||
| @@ -271,10 +276,11 @@ internal static int ArgPrecedence(Type t) | ||
| /// <param name="inst">The Python target of the method invocation.</param> | ||
| /// <param name="args">The Python arguments.</param> | ||
| /// <param name="kw">The Python keyword arguments.</param> | ||
| /// <param name="reverse_args">Reverse arguments of methods. Used for methods such as __radd__, __rsub__, __rmod__ etc</param> | ||
| /// <returns>A Binding if successful. Otherwise null.</returns> | ||
| internal Binding? Bind(BorrowedReference inst, BorrowedReference args, BorrowedReference kw, bool reverse_args = false) | ||
| { | ||
| return Bind(inst, args, kw, null, null, reverse_args); | ||
| } | ||
| /// <summary> | ||
| @@ -287,10 +293,11 @@ internal static int ArgPrecedence(Type t) | ||
| /// <param name="args">The Python arguments.</param> | ||
| /// <param name="kw">The Python keyword arguments.</param> | ||
| /// <param name="info">If not null, only bind to that method.</param> | ||
| /// <param name="reverse_args">Reverse arguments of methods. Used for methods such as __radd__, __rsub__, __rmod__ etc</param> | ||
| /// <returns>A Binding if successful. Otherwise null.</returns> | ||
| internal Binding? Bind(BorrowedReference inst, BorrowedReference args, BorrowedReference kw, MethodBase? info, bool reverse_args = false) | ||
| { | ||
| return Bind(inst, args, kw, info, null, reverse_args); | ||
| } | ||
| private readonly struct MatchedMethod | ||
| @@ -334,8 +341,9 @@ public MismatchedMethod(Exception exception, MethodBase mb) | ||
| /// <param name="kw">The Python keyword arguments.</param> | ||
| /// <param name="info">If not null, only bind to that method.</param> | ||
| /// <param name="methodinfo">If not null, additionally attempt to bind to the generic methods in this array by inferring generic type parameters.</param> | ||
| /// <param name="reverse_args">Reverse arguments of methods. Used for methods such as __radd__, __rsub__, __rmod__ etc</param> | ||
| /// <returns>A Binding if successful. Otherwise null.</returns> | ||
| internal Binding? Bind(BorrowedReference inst, BorrowedReference args, BorrowedReference kw, MethodBase? info, MethodBase[]? methodinfo, bool reverse_args = false) | ||
| { | ||
| // loop to find match, return invoker w/ or w/o error | ||
| var kwargDict = new Dictionary<string, PyObject>(); | ||
| @@ -363,10 +371,10 @@ public MismatchedMethod(Exception exception, MethodBase mb) | ||
| _methods = GetMethods(); | ||
| } | ||
| return Bind(inst, args, kwargDict, _methods, matchGenerics: true, reverse_args); | ||
| } | ||
| privatestatic Binding? Bind(BorrowedReference inst, BorrowedReference args, Dictionary<string, PyObject> kwargDict, MethodBase[] methods, bool matchGenerics, bool reversed = false) | ||
gertdreyer marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| { | ||
| var pynargs = (int)Runtime.PyTuple_Size(args); | ||
| var isGeneric = false; | ||
| @@ -386,7 +394,7 @@ public MismatchedMethod(Exception exception, MethodBase mb) | ||
| // Binary operator methods will have 2 CLR args but only one Python arg | ||
| // (unary operators will have 1 less each), since Python operator methods are bound. | ||
| isOperator = isOperator && pynargs == pi.Length - 1; | ||
| bool isReverse = isOperator &&reversed; // Only cast if isOperator. | ||
| if (isReverse && OperatorMethod.IsComparisonOp((MethodInfo)mi)) | ||
| continue; // Comparison operators in Python have no reverse mode. | ||
| if (!MatchesArgumentCount(pynargs, pi, kwargDict, out bool paramsArray, out ArrayList? defaultArgList, out int kwargsMatched, out int defaultsNeeded) && !isOperator) | ||
| @@ -809,14 +817,14 @@ static bool MatchesArgumentCount(int positionalArgumentCount, ParameterInfo[] pa | ||
| return match; | ||
| } | ||
| internal virtual NewReference Invoke(BorrowedReference inst, BorrowedReference args, BorrowedReference kw, bool reverse_args = false) | ||
| { | ||
| return Invoke(inst, args, kw, null, null, reverse_args); | ||
| } | ||
| internal virtual NewReference Invoke(BorrowedReference inst, BorrowedReference args, BorrowedReference kw, MethodBase? info, bool reverse_args = false) | ||
| { | ||
| return Invoke(inst, args, kw, info, null, reverse_args = false); | ||
| } | ||
| protected static void AppendArgumentTypes(StringBuilder to, BorrowedReference args) | ||
| @@ -852,7 +860,7 @@ protected static void AppendArgumentTypes(StringBuilder to, BorrowedReference ar | ||
| to.Append(')'); | ||
| } | ||
| internal virtual NewReference Invoke(BorrowedReference inst, BorrowedReference args, BorrowedReference kw, MethodBase? info, MethodBase[]? methodinfo, bool reverse_args = false) | ||
| { | ||
| // No valid methods, nothing to bind. | ||
| if (GetMethods().Length == 0) | ||
| @@ -865,7 +873,7 @@ internal virtual NewReference Invoke(BorrowedReference inst, BorrowedReference a | ||
| return Exceptions.RaiseTypeError(msg.ToString()); | ||
| } | ||
| Binding? binding = Bind(inst, args, kw, info, methodinfo, reverse_args); | ||
| object result; | ||
| IntPtr ts = IntPtr.Zero; | ||
3 changes: 2 additions & 1 deletionsrc/runtime/Types/MethodBinding.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletionssrc/runtime/Types/MethodObject.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
18 changes: 6 additions & 12 deletionssrc/runtime/Types/OperatorMethod.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.