Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c183ed

Browse files
committed
Merge branch 'python3' of https://github.com/renshawbay/pythonnet into python3
2 parents 796611a + 41ff7cb commit 2c183ed

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ pythonnet
33

44
Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET developers.
55

6-
[![Build Status](https://travis-ci.org/pythonnet/pythonnet.png?branch=develop)](https://travis-ci.org/pythonnet/pythonnet)
7-
8-
[![Build status](https://ci.appveyor.com/api/projects/status/65riiu1hvgaxsbwb)](https://ci.appveyor.com/project/davidanthoff/pythonnet)
6+
[![Build status](https://ci.appveyor.com/api/projects/status/u3p6pkiqpgu0qoku/branch/python3)](https://ci.appveyor.com/project/TonyRoberts/pythonnet/branch/python3)
97

108

119
**Features not yet integrated into the main branch**:

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def _find_msbuild_tool(tool="msbuild.exe", use_windows_sdk=False):
3131
value_name = "InstallationFolder"
3232
sdk_name = "Windows SDK"
3333
keys_to_check = [
34+
r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1A\WinSDK-Win32Tools",
3435
r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1\WinSDKWin32Tools",
36+
r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-Win32Tools",
3537
r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0\WinSDKWin32Tools",
3638
r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0A\WinSDKWin32Tools",
3739
]

src/runtime/classobject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal class ClassObject : ClassBase {
2626

2727
internal ClassObject(Type tp) : base(tp) {
2828
ctors = type.GetConstructors();
29-
binder = new ConstructorBinder();
29+
binder = new ConstructorBinder(type);
3030

3131
for (int i = 0; i < ctors.Length; i++) {
3232
binder.AddMethod(ctors[i]);

src/runtime/constructorbinder.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ namespace Python.Runtime {
2121
//========================================================================
2222

2323
internal class ConstructorBinder : MethodBinder {
24+
private Type _containingType = null;
2425

25-
internal ConstructorBinder () : base() {}
26+
internal ConstructorBinder(Type containingType) : base() {
27+
_containingType = containingType;
28+
}
2629

2730
//====================================================================
2831
// Constructors get invoked when an instance of a wrapped managed
@@ -53,9 +56,31 @@ internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw) {
5356
/// </remarks>
5457
internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw,
5558
MethodBase info) {
56-
Binding binding = this.Bind(inst, args, kw, info);
5759
Object result;
5860

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+
5984
if (binding == null) {
6085
// It is possible for __new__ to be invoked on construction
6186
// of a Python subclass of a managed class, so args may

src/tests/test_class.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,9 @@ def testStructConstruction(self):
136136
"""Test construction of structs."""
137137
from System.Drawing import Point
138138

139-
def test():
140-
p = Point()
141-
142-
self.assertRaises(TypeError, test)
139+
p = Point()
140+
self.assertTrue(p.X == 0)
141+
self.assertTrue(p.Y == 0)
143142

144143
p = Point(0, 0)
145144
self.assertTrue(p.X == 0)

0 commit comments

Comments
 (0)