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

Skip to content

Commit ec98209

Browse files
committed
fixed bad IncRef after PyTuple_New
1 parent 82f6b99 commit ec98209

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/runtime/Codecs/TupleCodecs.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ public sealed class TupleCodec<TTuple> : IPyObjectEncoder, IPyObjectDecoder
1212
public static TupleCodec<TTuple> Instance { get; } = new TupleCodec<TTuple>();
1313

1414
public bool CanEncode(Type type)
15-
=> type.Namespace == typeof(TTuple).Namespace && type.Name.StartsWith(typeof(TTuple).Name + '`')
16-
|| type == typeof(object) || type == typeof(TTuple);
15+
{
16+
if (type == typeof(object) || type == typeof(TTuple)) return true;
17+
return type.Namespace == typeof(TTuple).Namespace
18+
// generic versions of tuples are named Tuple`TYPE_ARG_COUNT
19+
&& type.Name.StartsWith(typeof(TTuple).Name + '`');
20+
}
1721

1822
public PyObject TryEncode(object value)
1923
{
@@ -36,7 +40,7 @@ public PyObject TryEncode(object value)
3640
Runtime.PyTuple_SetItem(tuple, fieldIndex, pyItem);
3741
fieldIndex++;
3842
}
39-
return new PyTuple(Runtime.SelfIncRef(tuple));
43+
return new PyTuple(tuple);
4044
}
4145

4246
public bool CanDecode(PyObject objectType, Type targetType)

0 commit comments

Comments
 (0)