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

Commite5d299e

Browse files
authored
Merge pull request#531 from dmitriyse/py_ssize_t-fix
Interop methods with Py_ssize_t works differently in NetCoreApp 2.0
2 parents08344b7 +1e41038 commite5d299e

15 files changed

+252
-76
lines changed

‎CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
2929
- Fixed Visual Studio 2017 compat ([#434][i434]) for setup.py
3030
- Fixed crashes when integrating pythonnet in Unity3d ([#714][i714]),
3131
related to unloading the Application Domain
32+
- Fixed interop methods with Py_ssize_t. NetCoreApp 2.0 is more sensitive than net40 and requires this fix. ([#531][p531])
3233
- Fixed crash on exit of the Python interpreter if a python class
3334
derived from a .NET class has a`__namespace__` or`__assembly__`
3435
attribute ([#481][i481])
@@ -689,3 +690,4 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
689690
[p163]:https://github.com/pythonnet/pythonnet/pull/163
690691
[p625]:https://github.com/pythonnet/pythonnet/pull/625
691692
[i131]:https://github.com/pythonnet/pythonnet/issues/131
693+
[p531]:https://github.com/pythonnet/pythonnet/pull/531

‎src/embed_tests/TestPySequence.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ public void TestRepeat()
6969
PyObjectactual=t1.Repeat(3);
7070
Assert.AreEqual("FooFooFoo",actual.ToString());
7171

72-
// On 32 bit system this argument should be int, but on the 64 bit system this should be long value.
73-
// This works on the Framework 4.0 accidentally, it should produce out of memory!
74-
// actual = t1.Repeat(-3);
75-
// Assert.AreEqual("", actual.ToString());
72+
actual=t1.Repeat(-3);
73+
Assert.AreEqual("",actual.ToString());
7674
}
7775

7876
[Test]

‎src/runtime/arrayobject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public static IntPtr mp_subscript(IntPtr ob, IntPtr idx)
9393
returnIntPtr.Zero;
9494
}
9595

96-
intcount=Runtime.PyTuple_Size(idx);
96+
varcount=Runtime.PyTuple_Size(idx);
9797

9898
varargs=newint[count];
9999

@@ -186,7 +186,7 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v)
186186
return-1;
187187
}
188188

189-
intcount=Runtime.PyTuple_Size(idx);
189+
varcount=Runtime.PyTuple_Size(idx);
190190
varargs=newint[count];
191191

192192
for(vari=0;i<count;i++)

‎src/runtime/assemblymanager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private static Assembly ResolveHandler(object ob, ResolveEventArgs args)
140140
internalstaticvoidUpdatePath()
141141
{
142142
IntPtrlist=Runtime.PySys_GetObject("path");
143-
intcount=Runtime.PyList_Size(list);
143+
varcount=Runtime.PyList_Size(list);
144144
if(count!=pypath.Count)
145145
{
146146
pypath.Clear();

‎src/runtime/classobject.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v)
230230
}
231231

232232
// Get the args passed in.
233-
inti=Runtime.PyTuple_Size(args);
233+
vari=Runtime.PyTuple_Size(args);
234234
IntPtrdefaultArgs=cls.indexer.GetDefaultArgs(args);
235-
intnumOfDefaultArgs=Runtime.PyTuple_Size(defaultArgs);
236-
inttemp=i+numOfDefaultArgs;
235+
varnumOfDefaultArgs=Runtime.PyTuple_Size(defaultArgs);
236+
vartemp=i+numOfDefaultArgs;
237237
IntPtrreal=Runtime.PyTuple_New(temp+1);
238238
for(varn=0;n<i;n++)
239239
{

‎src/runtime/converter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ private static void SetConversionError(IntPtr value, Type target)
842842
privatestaticboolToArray(IntPtrvalue,TypeobType,outobjectresult,boolsetError)
843843
{
844844
TypeelementType=obType.GetElementType();
845-
intsize=Runtime.PySequence_Size(value);
845+
varsize=Runtime.PySequence_Size(value);
846846
result=null;
847847

848848
if(size<0)

‎src/runtime/exceptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public static void SetError(Exception e)
276276
/// </remarks>
277277
publicstaticboolErrorOccurred()
278278
{
279-
returnRuntime.PyErr_Occurred()!=0;
279+
returnRuntime.PyErr_Occurred()!=IntPtr.Zero;
280280
}
281281

282282
/// <summary>

‎src/runtime/importhook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
155155
// hook is saved as this.py_import. This version handles CLR
156156
// import and defers to the normal builtin for everything else.
157157

158-
intnum_args=Runtime.PyTuple_Size(args);
158+
varnum_args=Runtime.PyTuple_Size(args);
159159
if(num_args<1)
160160
{
161161
returnExceptions.RaiseTypeError("__import__() takes at least 1 argument (0 given)");

‎src/runtime/indexer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ internal void SetItem(IntPtr inst, IntPtr args)
5656

5757
internalboolNeedsDefaultArgs(IntPtrargs)
5858
{
59-
intpynargs=Runtime.PyTuple_Size(args);
59+
varpynargs=Runtime.PyTuple_Size(args);
6060
MethodBase[]methods=SetterBinder.GetMethods();
6161
if(methods.Length==0)
6262
{
@@ -72,7 +72,7 @@ internal bool NeedsDefaultArgs(IntPtr args)
7272
returnfalse;
7373
}
7474

75-
for(intv=pynargs;v<clrnargs;v++)
75+
for(varv=pynargs;v<clrnargs;v++)
7676
{
7777
if(pi[v].DefaultValue==DBNull.Value)
7878
{
@@ -95,7 +95,7 @@ internal IntPtr GetDefaultArgs(IntPtr args)
9595
{
9696
returnRuntime.PyTuple_New(0);
9797
}
98-
intpynargs=Runtime.PyTuple_Size(args);
98+
varpynargs=Runtime.PyTuple_Size(args);
9999

100100
// Get the default arg tuple
101101
MethodBase[]methods=SetterBinder.GetMethods();

‎src/runtime/interfaceobject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static InterfaceObject()
3636
publicstaticIntPtrtp_new(IntPtrtp,IntPtrargs,IntPtrkw)
3737
{
3838
varself=(InterfaceObject)GetManagedObject(tp);
39-
intnargs=Runtime.PyTuple_Size(args);
39+
varnargs=Runtime.PyTuple_Size(args);
4040
Typetype=self.type;
4141
objectobj;
4242

‎src/runtime/metatype.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static IntPtr Initialize()
2929
/// </summary>
3030
publicstaticIntPtrtp_new(IntPtrtp,IntPtrargs,IntPtrkw)
3131
{
32-
intlen=Runtime.PyTuple_Size(args);
32+
varlen=Runtime.PyTuple_Size(args);
3333
if(len<3)
3434
{
3535
returnExceptions.RaiseTypeError("invalid argument list");

‎src/runtime/methodbinder.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
279279
{
280280
// loop to find match, return invoker w/ or /wo error
281281
MethodBase[]_methods=null;
282-
intpynargs=Runtime.PyTuple_Size(args);
282+
varpynargs=(int)Runtime.PyTuple_Size(args);
283283
objectarg;
284284
varisGeneric=false;
285285
ArrayListdefaultArgList=null;
@@ -301,9 +301,9 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
301301
isGeneric=true;
302302
}
303303
ParameterInfo[]pi=mi.GetParameters();
304-
intclrnargs=pi.Length;
304+
varclrnargs=pi.Length;
305305
varmatch=false;
306-
intarrayStart=-1;
306+
vararrayStart=-1;
307307
varouts=0;
308308

309309
if(pynargs==clrnargs)
@@ -314,7 +314,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
314314
{
315315
match=true;
316316
defaultArgList=newArrayList();
317-
for(intv=pynargs;v<clrnargs;v++)
317+
for(varv=pynargs;v<clrnargs;v++)
318318
{
319319
if(pi[v].DefaultValue==DBNull.Value)
320320
{
@@ -338,7 +338,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
338338
{
339339
varmargs=newobject[clrnargs];
340340

341-
for(varn=0;n<clrnargs;n++)
341+
for(intn=0;n<clrnargs;n++)
342342
{
343343
IntPtrop;
344344
if(n<pynargs)

‎src/runtime/methodbinding.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
104104
{
105105
if(self.info.IsGenericMethod)
106106
{
107-
intlen=Runtime.PyTuple_Size(args);//FIXME: Never used
107+
varlen=Runtime.PyTuple_Size(args);//FIXME: Never used
108108
Type[]sigTp=Runtime.PythonArgsToTypeArray(args,true);
109109
if(sigTp!=null)
110110
{
@@ -129,7 +129,7 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
129129

130130
if(target==IntPtr.Zero&&!self.m.IsStatic())
131131
{
132-
intlen=Runtime.PyTuple_Size(args);
132+
varlen=Runtime.PyTuple_Size(args);
133133
if(len<1)
134134
{
135135
Exceptions.SetError(Exceptions.TypeError,"not enough arguments");

‎src/runtime/pyobject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,9 @@ public virtual void DelItem(int index)
519519
/// Returns the length for objects that support the Python sequence
520520
/// protocol, or 0 if the object does not support the protocol.
521521
/// </remarks>
522-
publicvirtualintLength()
522+
publicvirtuallongLength()
523523
{
524-
ints=Runtime.PyObject_Size(obj);
524+
vars=Runtime.PyObject_Size(obj);
525525
if(s<0)
526526
{
527527
Runtime.PyErr_Clear();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp