Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit022be19

Browse files
authored
Merge branch 'master' into amos-interop-changes
2 parents8e1fa20 +451fae6 commit022be19

16 files changed

+231
-166
lines changed

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
1414
-`clr.AddReference` may now throw errors besides`FileNotFoundException`, that provide more
1515
details about the cause of the failure
1616
-`clr.AddReference` no longer adds ".dll" implicitly
17+
-`PyIter(PyObject)` constructor replaced with static`PyIter.GetIter(PyObject)` method
1718

1819
###Fixed
1920

‎src/embed_tests/TestFinalizer.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ public void CollectBasicObject()
8787
Assert.GreaterOrEqual(objectCount,1);
8888
}
8989

90+
[Test]
91+
publicvoidCollectOnShutdown()
92+
{
93+
MakeAGarbage(outvarshortWeak,outvarlongWeak);
94+
FullGCCollect();
95+
vargarbage=Finalizer.Instance.GetCollectedObjects();
96+
Assert.IsNotEmpty(garbage);
97+
PythonEngine.Shutdown();
98+
garbage=Finalizer.Instance.GetCollectedObjects();
99+
Assert.IsEmpty(garbage);
100+
}
101+
90102
privatestaticvoidMakeAGarbage(outWeakReferenceshortWeak,outWeakReferencelongWeak)
91103
{
92104
PyLongobj=newPyLong(1024);

‎src/perf_tests/Python.PerformanceTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</ItemGroup>
2929

3030
<TargetName="GetRuntimeLibBuildOutput"BeforeTargets="Build">
31-
<MSBuildProjects="..\runtime\Python.Runtime.15.csproj"Properties="PYTHONNET_PY3_VERSION=PYTHON35;Configuration=$(Configuration);TargetFramework=net40;Python3Version=PYTHON35;OutputPath=bin\for_perf\">
31+
<MSBuildProjects="..\runtime\Python.Runtime.15.csproj"Properties="PYTHONNET_PY3_VERSION=PYTHON38;Configuration=$(Configuration);TargetFramework=net40;Python3Version=PYTHON38;OutputPath=bin\for_perf\">
3232
<OutputTaskParameter="TargetOutputs"ItemName="NewPythonRuntime" />
3333
</MSBuild>
3434
</Target>

‎src/runtime/pyansistring.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ public PyAnsiString(IntPtr ptr) : base(ptr)
1717
}
1818

1919

20+
privatestaticIntPtrFromObject(PyObjecto)
21+
{
22+
if(o==null||!IsStringType(o))
23+
{
24+
thrownewArgumentException("object is not a string");
25+
}
26+
Runtime.XIncref(o.obj);
27+
returno.obj;
28+
}
29+
2030
/// <summary>
2131
/// PyString Constructor
2232
/// </summary>
@@ -25,14 +35,14 @@ public PyAnsiString(IntPtr ptr) : base(ptr)
2535
/// An ArgumentException will be thrown if the given object is not
2636
/// a Python string object.
2737
/// </remarks>
28-
publicPyAnsiString(PyObjecto)
38+
publicPyAnsiString(PyObjecto):base(FromObject(o))
2939
{
30-
if(!IsStringType(o))
31-
{
32-
thrownewArgumentException("object is not a string");
33-
}
34-
Runtime.XIncref(o.obj);
35-
obj=o.obj;
40+
}
41+
privatestaticIntPtrFromString(strings)
42+
{
43+
IntPtrval=Runtime.PyString_FromString(s);
44+
PythonException.ThrowIfIsNull(val);
45+
returnval;
3646
}
3747

3848

@@ -42,10 +52,8 @@ public PyAnsiString(PyObject o)
4252
/// <remarks>
4353
/// Creates a Python string from a managed string.
4454
/// </remarks>
45-
publicPyAnsiString(strings)
55+
publicPyAnsiString(strings):base(FromString(s))
4656
{
47-
obj=Runtime.PyString_FromString(s);
48-
PythonException.ThrowIfIsNull(obj);
4957
}
5058

5159

‎src/runtime/pydict.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ public PyDict(IntPtr ptr) : base(ptr)
2929
/// <remarks>
3030
/// Creates a new Python dictionary object.
3131
/// </remarks>
32-
publicPyDict()
32+
publicPyDict():base(Runtime.PyDict_New())
3333
{
34-
obj=Runtime.PyDict_New();
3534
if(obj==IntPtr.Zero)
3635
{
3736
thrownewPythonException();
@@ -47,14 +46,13 @@ public PyDict()
4746
/// ArgumentException will be thrown if the given object is not a
4847
/// Python dictionary object.
4948
/// </remarks>
50-
publicPyDict(PyObjecto)
49+
publicPyDict(PyObjecto):base(o.obj)
5150
{
51+
Runtime.XIncref(o.obj);
5252
if(!IsDictType(o))
5353
{
5454
thrownewArgumentException("object is not a dict");
5555
}
56-
Runtime.XIncref(o.obj);
57-
obj=o.obj;
5856
}
5957

6058

‎src/runtime/pyfloat.cs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ namespace Python.Runtime
44
{
55
/// <summary>
66
/// Represents a Python float object. See the documentation at
7-
/// PY2: https://docs.python.org/2/c-api/float.html
87
/// PY3: https://docs.python.org/3/c-api/float.html
98
/// for details.
109
/// </summary>
@@ -31,14 +30,8 @@ public PyFloat(IntPtr ptr) : base(ptr)
3130
/// ArgumentException will be thrown if the given object is not a
3231
/// Python float object.
3332
/// </remarks>
34-
publicPyFloat(PyObjecto)
33+
publicPyFloat(PyObjecto):base(FromObject(o))
3534
{
36-
if(!IsFloatType(o))
37-
{
38-
thrownewArgumentException("object is not a float");
39-
}
40-
Runtime.XIncref(o.obj);
41-
obj=o.obj;
4235
}
4336

4437

@@ -48,26 +41,45 @@ public PyFloat(PyObject o)
4841
/// <remarks>
4942
/// Creates a new Python float from a double value.
5043
/// </remarks>
51-
publicPyFloat(doublevalue)
44+
publicPyFloat(doublevalue):base(FromDouble(value))
45+
{
46+
}
47+
48+
privatestaticIntPtrFromObject(PyObjecto)
49+
{
50+
if(o==null||!IsFloatType(o))
51+
{
52+
thrownewArgumentException("object is not a float");
53+
}
54+
Runtime.XIncref(o.obj);
55+
returno.obj;
56+
}
57+
58+
privatestaticIntPtrFromDouble(doublevalue)
5259
{
53-
obj=Runtime.PyFloat_FromDouble(value);
54-
PythonException.ThrowIfIsNull(obj);
60+
IntPtrval=Runtime.PyFloat_FromDouble(value);
61+
PythonException.ThrowIfIsNull(val);
62+
returnval;
5563
}
5664

65+
privatestaticIntPtrFromString(stringvalue)
66+
{
67+
using(vars=newPyString(value))
68+
{
69+
IntPtrval=Runtime.PyFloat_FromString(s.obj,IntPtr.Zero);
70+
PythonException.ThrowIfIsNull(val);
71+
returnval;
72+
}
73+
}
5774

5875
/// <summary>
5976
/// PyFloat Constructor
6077
/// </summary>
6178
/// <remarks>
6279
/// Creates a new Python float from a string value.
6380
/// </remarks>
64-
publicPyFloat(stringvalue)
81+
publicPyFloat(stringvalue):base(FromString(value))
6582
{
66-
using(vars=newPyString(value))
67-
{
68-
obj=Runtime.PyFloat_FromString(s.obj,IntPtr.Zero);
69-
PythonException.ThrowIfIsNull(obj);
70-
}
7183
}
7284

7385

‎src/runtime/pyint.cs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,35 @@ public PyInt(IntPtr ptr) : base(ptr)
3131
/// ArgumentException will be thrown if the given object is not a
3232
/// Python int object.
3333
/// </remarks>
34-
publicPyInt(PyObjecto)
34+
publicPyInt(PyObjecto):base(FromObject(o))
3535
{
36-
if(!IsIntType(o))
36+
}
37+
38+
privatestaticIntPtrFromObject(PyObjecto)
39+
{
40+
if(o==null||!IsIntType(o))
3741
{
3842
thrownewArgumentException("object is not an int");
3943
}
4044
Runtime.XIncref(o.obj);
41-
obj=o.obj;
45+
returno.obj;
4246
}
4347

48+
privatestaticIntPtrFromInt(intvalue)
49+
{
50+
IntPtrval=Runtime.PyInt_FromInt32(value);
51+
PythonException.ThrowIfIsNull(val);
52+
returnval;
53+
}
4454

4555
/// <summary>
4656
/// PyInt Constructor
4757
/// </summary>
4858
/// <remarks>
4959
/// Creates a new Python int from an int32 value.
5060
/// </remarks>
51-
publicPyInt(intvalue)
61+
publicPyInt(intvalue):base(FromInt(value))
5262
{
53-
obj=Runtime.PyInt_FromInt32(value);
54-
PythonException.ThrowIfIsNull(obj);
5563
}
5664

5765

@@ -62,10 +70,8 @@ public PyInt(int value)
6270
/// Creates a new Python int from a uint32 value.
6371
/// </remarks>
6472
[CLSCompliant(false)]
65-
publicPyInt(uintvalue)
73+
publicPyInt(uintvalue):base(FromLong(value))
6674
{
67-
obj=Runtime.PyInt_FromInt64(value);
68-
PythonException.ThrowIfIsNull(obj);
6975
}
7076

7177

@@ -75,10 +81,15 @@ public PyInt(uint value)
7581
/// <remarks>
7682
/// Creates a new Python int from an int64 value.
7783
/// </remarks>
78-
publicPyInt(longvalue)
84+
publicPyInt(longvalue):base(FromLong(value))
7985
{
80-
obj=Runtime.PyInt_FromInt64(value);
81-
PythonException.ThrowIfIsNull(obj);
86+
}
87+
88+
privatestaticIntPtrFromLong(longvalue)
89+
{
90+
IntPtrval=Runtime.PyInt_FromInt64(value);
91+
PythonException.ThrowIfIsNull(val);
92+
returnval;
8293
}
8394

8495

@@ -89,10 +100,8 @@ public PyInt(long value)
89100
/// Creates a new Python int from a uint64 value.
90101
/// </remarks>
91102
[CLSCompliant(false)]
92-
publicPyInt(ulongvalue)
103+
publicPyInt(ulongvalue):base(FromLong((long)value))
93104
{
94-
obj=Runtime.PyInt_FromInt64((long)value);
95-
PythonException.ThrowIfIsNull(obj);
96105
}
97106

98107

@@ -142,16 +151,21 @@ public PyInt(sbyte value) : this((int)value)
142151
}
143152

144153

154+
privatestaticIntPtrFromString(stringvalue)
155+
{
156+
IntPtrval=Runtime.PyInt_FromString(value,IntPtr.Zero,0);
157+
PythonException.ThrowIfIsNull(val);
158+
returnval;
159+
}
160+
145161
/// <summary>
146162
/// PyInt Constructor
147163
/// </summary>
148164
/// <remarks>
149165
/// Creates a new Python int from a string value.
150166
/// </remarks>
151-
publicPyInt(stringvalue)
167+
publicPyInt(stringvalue):base(FromString(value))
152168
{
153-
obj=Runtime.PyInt_FromString(value,IntPtr.Zero,0);
154-
PythonException.ThrowIfIsNull(obj);
155169
}
156170

157171

‎src/runtime/pyiter.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,22 @@ public PyIter(IntPtr ptr) : base(ptr)
2626
}
2727

2828
/// <summary>
29-
/// PyIterConstructor
29+
/// PyIterfactory function.
3030
/// </summary>
3131
/// <remarks>
32-
///Creates aPython iterator fromaniterable. Like doing "iter(iterable)" in python.
32+
///Create anew PyIter froma giveniterable. Like doing "iter(iterable)" in python.
3333
/// </remarks>
34-
publicPyIter(PyObjectiterable)
34+
/// <param name="iterable"></param>
35+
/// <returns></returns>
36+
publicstaticPyIterGetIter(PyObjectiterable)
3537
{
36-
obj=Runtime.PyObject_GetIter(iterable.obj);
37-
if(obj==IntPtr.Zero)
38+
if(iterable==null)
3839
{
39-
thrownewPythonException();
40+
thrownewArgumentNullException();
4041
}
42+
IntPtrval=Runtime.PyObject_GetIter(iterable.obj);
43+
PythonException.ThrowIfIsNull(val);
44+
returnnewPyIter(val);
4145
}
4246

4347
protectedoverridevoidDispose(booldisposing)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp