| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6956638 commit 7db46e5
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,7 +26,7 @@ internal class ClassObject : ClassBase { | |||
| 26 | 26 | ||
| 27 | 27 | internal ClassObject(Type tp) : base(tp) { | |
| 28 | 28 | ctors = type.GetConstructors(); | |
| 29 | - binder = new ConstructorBinder(); | ||
| 29 | + binder = new ConstructorBinder(type); | ||
| 30 | 30 | ||
| 31 | 31 | for (int i = 0; i < ctors.Length; i++) { | |
| 32 | 32 | binder.AddMethod(ctors[i]); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,8 +21,11 @@ namespace Python.Runtime { | |||
| 21 | 21 | //======================================================================== | |
| 22 | 22 | ||
| 23 | 23 | internal class ConstructorBinder : MethodBinder { | |
| 24 | + private Type _containingType = null; | ||
| 24 | 25 | ||
| 25 | - internal ConstructorBinder () : base() {} | ||
| 26 | + internal ConstructorBinder(Type containingType) : base() { | ||
| 27 | + _containingType = containingType; | ||
| 28 | + } | ||
| 26 | 29 | ||
| 27 | 30 | //==================================================================== | |
| 28 | 31 | // Constructors get invoked when an instance of a wrapped managed | |
@@ -53,9 +56,31 @@ internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw) { | |||
| 53 | 56 | /// </remarks> | |
| 54 | 57 | internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw, | |
| 55 | 58 | MethodBase info) { | |
| 56 | - Binding binding = this.Bind(inst, args, kw, info); | ||
| 57 | 59 | Object result; | |
| 58 | 60 | ||
| 61 | + if (_containingType.IsValueType && !_containingType.IsPrimitive && | ||
| 62 | + !_containingType.IsEnum && _containingType != typeof (decimal) && | ||
| 63 | + Runtime.PyTuple_Size(args) == 0) { | ||
| 64 | + // If you are trying to construct an instance of a struct by | ||
| 65 | + // calling its default constructor, that ConstructorInfo | ||
| 66 | + // instance will not appear in reflection and the object must | ||
| 67 | + // instead be constructed via a call to | ||
| 68 | + // Activator.CreateInstance(). | ||
| 69 | + try { | ||
| 70 | + result = Activator.CreateInstance(_containingType); | ||
| 71 | + } | ||
| 72 | + catch (Exception e) { | ||
| 73 | + if (e.InnerException != null) { | ||
| 74 | + e = e.InnerException; | ||
| 75 | + } | ||
| 76 | + Exceptions.SetError(e); | ||
| 77 | + return null; | ||
| 78 | + } | ||
| 79 | + return result; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + Binding binding = this.Bind(inst, args, kw, info); | ||
| 83 | + | ||
| 59 | 84 | if (binding == null) { | |
| 60 | 85 | // It is possible for __new__ to be invoked on construction | |
| 61 | 86 | // of a Python subclass of a managed class, so args may | |
| Back | FazBrowse Home | New Git URL |
0 commit comments