@@ -23,7 +23,7 @@ internal DelegateObject(Type tp) : base(tp)
23
23
/// Given a PyObject pointer to an instance of a delegate type, return
24
24
/// the true managed delegate the Python object represents (or null).
25
25
/// </summary>
26
- private static Delegate GetTrueDelegate ( IntPtr op )
26
+ private static Delegate ? GetTrueDelegate ( BorrowedReference op )
27
27
{
28
28
var o = GetManagedObject ( op ) as CLRObject ;
29
29
if ( o != null )
@@ -48,9 +48,9 @@ internal override bool CanSubclass()
48
48
/// delegate instance belongs to an object generated to relay the call
49
49
/// to the Python callable passed in.
50
50
/// </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 )
52
52
{
53
- var self = ( DelegateObject ) GetManagedObject ( tp ) ;
53
+ var self = ( DelegateObject ) GetManagedObject ( tp ) ! ;
54
54
55
55
if ( ! self . type . Valid )
56
56
{
@@ -63,26 +63,26 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
63
63
return Exceptions . RaiseTypeError ( "class takes exactly one argument" ) ;
64
64
}
65
65
66
- IntPtr method = Runtime . PyTuple_GetItem ( args , 0 ) ;
66
+ BorrowedReference method = Runtime . PyTuple_GetItem ( args , 0 ) ;
67
67
68
68
if ( Runtime . PyCallable_Check ( method ) != 1 )
69
69
{
70
70
return Exceptions . RaiseTypeError ( "argument must be callable" ) ;
71
71
}
72
72
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 ) ;
75
75
}
76
76
77
77
78
78
/// <summary>
79
79
/// Implements __call__ for reflected delegate types.
80
80
/// </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 )
82
82
{
83
83
// 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 ) ! ;
86
86
var o = GetManagedObject ( ob ) as CLRObject ;
87
87
88
88
if ( o == null )
@@ -103,16 +103,15 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
103
103
/// <summary>
104
104
/// Implements __cmp__ for reflected delegate types.
105
105
/// </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 )
107
107
{
108
108
if ( op != Runtime . Py_EQ && op != Runtime . Py_NE )
109
109
{
110
- Runtime . XIncref ( Runtime . PyNotImplemented ) ;
111
- return Runtime . PyNotImplemented ;
110
+ return new NewReference ( Runtime . PyNotImplemented ) ;
112
111
}
113
112
114
- IntPtr pytrue = Runtime . PyTrue ;
115
- IntPtr pyfalse = Runtime . PyFalse ;
113
+ BorrowedReference pytrue = Runtime . PyTrue ;
114
+ BorrowedReference pyfalse = Runtime . PyFalse ;
116
115
117
116
// swap true and false for NE
118
117
if ( op != Runtime . Py_EQ )
@@ -121,16 +120,10 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
121
120
pyfalse = Runtime . PyTrue ;
122
121
}
123
122
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 ) ;
131
125
132
- Runtime . XIncref ( pyfalse ) ;
133
- return pyfalse ;
126
+ return new NewReference ( d1 == d2 ? pytrue : pyfalse ) ;
134
127
}
135
128
}
136
129
}
0 commit comments