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

Skip to content

Commit 8283507

Browse files
committed
fix issues
1 parent 83b9237 commit 8283507

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

src/FunctionCodec.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ private static object ConvertVariadicObjectAction(PyObject pyObj, int numArgs)
9595
//TODO share code between ConvertUnaryFunc and ConvertVariadicObjectFunc
9696
private static object ConvertUnaryFunc(PyObject pyObj)
9797
{
98+
var pyAction = new PyObject(pyObj.Handle);
9899
Func<object> func = () =>
99100
{
100-
//Runtime.XIncref(pyObj.Handle);
101-
PyObject pyAction = new PyObject(pyObj.Handle);
102101
var pyArgs = new PyObject[0];
103102
using (Py.GIL())
104103
{
@@ -111,10 +110,9 @@ private static object ConvertUnaryFunc(PyObject pyObj)
111110

112111
private static object ConvertVariadicObjectFunc(PyObject pyObj, int numArgs)
113112
{
113+
var pyAction = new PyObject(pyObj.Handle);
114114
Func<object[], object> func = (object[] o) =>
115115
{
116-
//Runtime.XIncref(pyObj.Handle);
117-
PyObject pyAction = new PyObject(pyObj.Handle);
118116
var pyArgs = new PyObject[numArgs];
119117
int i = 0;
120118
foreach (object obj in o)

tests/FunctionCodecTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
42
using NUnit.Framework;
5-
using Python.Runtime.Codecs;
63

74
namespace Python.Runtime.Codecs
85
{

tests/TestCallbacks.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
using System;
2-
32
using NUnit.Framework;
4-
using Python.Runtime;
53

6-
namespace Python.EmbeddingTest
4+
namespace Python.Runtime.Codecs
75
{
8-
using Runtime = Python.Runtime.Runtime;
9-
106
public class TestCallbacks
117
{
128
[OneTimeSetUp]
@@ -60,7 +56,7 @@ def str_len(a):
6056

6157
var callables = new Callables();
6258

63-
Python.Runtime.Codecs.FunctionCodec.Register();
59+
FunctionCodec.Register();
6460

6561
//ret1. A function with no arguments that returns an integer
6662
//it must be convertible to Action or Func<object> and not to Func<object, object>
@@ -81,8 +77,8 @@ def str_len(a):
8177
{
8278
Action<object[]> result3 = null;
8379
Func<object[], object> result4 = null;
84-
Assert.DoesNotThrow(() => { result3 = ret1.As<Action<object[]>>(); });
85-
Assert.DoesNotThrow(() => { result4 = ret1.As<Func<object[], object>>(); });
80+
Assert.DoesNotThrow(() => { result3 = strLen.As<Action<object[]>>(); });
81+
Assert.DoesNotThrow(() => { result4 = strLen.As<Func<object[], object>>(); });
8682

8783
//try using both func and action to show you can get __len__ of a string but not an integer
8884
Assert.Throws<PythonException>(() => { callables.CallAction1((Action<object[]>)result3, 2); });

0 commit comments

Comments
 (0)