| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 93c8e38 commit fef6f35
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | using System; | |
| 2 | + using System.Collections.Concurrent; | ||
| 2 | 3 | using System.Collections.Generic; | |
| 3 | 4 | using System.Dynamic; | |
| 4 | 5 | using System.Linq; | |
@@ -41,8 +42,14 @@ internal class TypeManager | |||
| 41 | 42 | ||
| 42 | 43 | static readonly DynamicObjectMemberAccessor dynamicMemberAccessor = new(); | |
| 43 | 44 | ||
| 45 | + // tp_getattro_dlr_proxy / tp_setattro_dlr_proxy hit HasClrMember on every | ||
| 46 | + // attribute access; cache the reflection result per (Type, name). | ||
| 47 | + static readonly ConcurrentDictionary<(Type, string), bool> _hasClrMemberCache = new(); | ||
| 48 | + | ||
| 44 | 49 | static bool HasClrMember(object instance, string memberName) => | |
| 45 | - instance.GetType().GetMember(memberName, BindingFlags.Public | BindingFlags.Instance).Length > 0; | ||
| 50 | + _hasClrMemberCache.GetOrAdd( | ||
| 51 | + (instance.GetType(), memberName), | ||
| 52 | + k => k.Item1.GetMember(k.Item2, BindingFlags.Public | BindingFlags.Instance).Length > 0); | ||
| 46 | 53 | ||
| 47 | 54 | static bool IsPythonSpecialAttributeName(string memberName) => | |
| 48 | 55 | memberName.Length > 4 && memberName.StartsWith("__") && memberName.EndsWith("__"); | |
@@ -198,7 +205,9 @@ public static int tp_setattro_dlr_proxy(BorrowedReference ob, BorrowedReference | |||
| 198 | 205 | } | |
| 199 | 206 | catch (Exception e) | |
| 200 | 207 | { | |
| 201 | - Exceptions.SetError(e); | ||
| 208 | + // Same reasoning as the getter: avoid Converter.ToPython(e) to keep this | ||
| 209 | + // slot re-entry-safe on live dynamic objects. | ||
| 210 | + Exceptions.SetError(Exceptions.RuntimeError, e.Message); | ||
| 202 | 211 | return -1; | |
| 203 | 212 | } | |
| 204 | 213 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments