Skip to content

Commit 7fa537a

Browse files
committed
switched delegateobject.cs to the new style references
1 parent 590de7a commit 7fa537a

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

src/runtime/delegateobject.cs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal DelegateObject(Type tp) : base(tp)
2323
/// Given a PyObject pointer to an instance of a delegate type, return
2424
/// the true managed delegate the Python object represents (or null).
2525
/// </summary>
26-
private static Delegate GetTrueDelegate(IntPtr op)
26+
private static Delegate? GetTrueDelegate(BorrowedReference op)
2727
{
2828
var o = GetManagedObject(op) as CLRObject;
2929
if (o != null)
@@ -48,9 +48,9 @@ internal override bool CanSubclass()
4848
/// delegate instance belongs to an object generated to relay the call
4949
/// to the Python callable passed in.
5050
/// </summary>
51-
public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
51+
public static NewReference tp_new(BorrowedReference tp, BorrowedReference args, BorrowedReference kw)
5252
{
53-
var self = (DelegateObject)GetManagedObject(tp);
53+
var self = (DelegateObject)GetManagedObject(tp)!;
5454

5555
if (!self.type.Valid)
5656
{
@@ -63,26 +63,26 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
6363
return Exceptions.RaiseTypeError("class takes exactly one argument");
6464
}
6565

66-
IntPtr method = Runtime.PyTuple_GetItem(args, 0);
66+
BorrowedReference method = Runtime.PyTuple_GetItem(args, 0);
6767

6868
if (Runtime.PyCallable_Check(method) != 1)
6969
{
7070
return Exceptions.RaiseTypeError("argument must be callable");
7171
}
7272

73-
Delegate d = PythonEngine.DelegateManager.GetDelegate(type, method);
74-
return CLRObject.GetInstHandle(d, self.pyHandle);
73+
Delegate d = PythonEngine.DelegateManager.GetDelegate(type, new PyObject(method));
74+
return CLRObject.GetReference(d, self.pyHandle);
7575
}
7676

7777

7878
/// <summary>
7979
/// Implements __call__ for reflected delegate types.
8080
/// </summary>
81-
public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
81+
public static NewReference tp_call(BorrowedReference ob, BorrowedReference args, BorrowedReference kw)
8282
{
8383
// TODO: add fast type check!
84-
IntPtr pytype = Runtime.PyObject_TYPE(ob);
85-
var self = (DelegateObject)GetManagedObject(pytype);
84+
BorrowedReference pytype = Runtime.PyObject_TYPE(ob);
85+
var self = (DelegateObject)GetManagedObject(pytype)!;
8686
var o = GetManagedObject(ob) as CLRObject;
8787

8888
if (o == null)
@@ -103,16 +103,15 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
103103
/// <summary>
104104
/// Implements __cmp__ for reflected delegate types.
105105
/// </summary>
106-
public new static IntPtr tp_richcompare(IntPtr ob, IntPtr other, int op)
106+
public new static NewReference tp_richcompare(BorrowedReference ob, BorrowedReference other, int op)
107107
{
108108
if (op != Runtime.Py_EQ && op != Runtime.Py_NE)
109109
{
110-
Runtime.XIncref(Runtime.PyNotImplemented);
111-
return Runtime.PyNotImplemented;
110+
return new NewReference(Runtime.PyNotImplemented);
112111
}
113112

114-
IntPtr pytrue = Runtime.PyTrue;
115-
IntPtr pyfalse = Runtime.PyFalse;
113+
BorrowedReference pytrue = Runtime.PyTrue;
114+
BorrowedReference pyfalse = Runtime.PyFalse;
116115

117116
// swap true and false for NE
118117
if (op != Runtime.Py_EQ)
@@ -121,16 +120,10 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
121120
pyfalse = Runtime.PyTrue;
122121
}
123122

124-
Delegate d1 = GetTrueDelegate(ob);
125-
Delegate d2 = GetTrueDelegate(other);
126-
if (d1 == d2)
127-
{
128-
Runtime.XIncref(pytrue);
129-
return pytrue;
130-
}
123+
Delegate? d1 = GetTrueDelegate(ob);
124+
Delegate? d2 = GetTrueDelegate(other);
131125

132-
Runtime.XIncref(pyfalse);
133-
return pyfalse;
126+
return new NewReference(d1 == d2 ? pytrue : pyfalse);
134127
}
135128
}
136129
}

0 commit comments

Comments
 (0)