Skip to content

Commit 2095b46

Browse files
committed
switched classobject.cs to the new style references
1 parent 58cb0e6 commit 2095b46

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/runtime/classobject.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,13 @@ public static NewReference tp_new(BorrowedReference tp, BorrowedReference args,
8080
}
8181

8282
BorrowedReference op = Runtime.PyTuple_GetItem(args, 0);
83-
object result;
8483

85-
if (!Converter.ToManaged(op, type, out result, true))
84+
if (!Converter.ToManaged(op, type, out var result, true))
8685
{
8786
return default;
8887
}
8988

90-
return CLRObject.GetReference(result, tp);
89+
return CLRObject.GetReference(result!, tp);
9190
}
9291

9392
if (type.IsAbstract)
@@ -101,13 +100,13 @@ public static NewReference tp_new(BorrowedReference tp, BorrowedReference args,
101100
return NewEnum(type, args, tp);
102101
}
103102

104-
object obj = self.binder.InvokeRaw(null, args, kw);
103+
object? obj = self.binder.InvokeRaw(null, args, kw);
105104
if (obj == null)
106105
{
107-
return IntPtr.Zero;
106+
return default;
108107
}
109108

110-
return CLRObject.GetReference(obj, tp).DangerousMoveToPointerOrNull();
109+
return CLRObject.GetReference(obj, tp);
111110
}
112111

113112
private static NewReference NewEnum(Type type, BorrowedReference args, BorrowedReference tp)
@@ -132,7 +131,7 @@ private static NewReference NewEnum(Type type, BorrowedReference args, BorrowedR
132131
}
133132

134133
var op = Runtime.PyTuple_GetItem(args, 0);
135-
if (!Converter.ToManaged(op, type.GetEnumUnderlyingType(), out object result, true))
134+
if (!Converter.ToManaged(op, type.GetEnumUnderlyingType(), out object? result, true))
136135
{
137136
return default;
138137
}
@@ -169,21 +168,20 @@ public override NewReference type_subscript(BorrowedReference idx)
169168
return Exceptions.RaiseTypeError("type expected");
170169
}
171170
var c = GetManagedObject(idx) as ClassBase;
172-
Type t = c != null ? c.type.Value : Converter.GetTypeByAlias(idx);
171+
Type? t = c != null ? c.type.Value : Converter.GetTypeByAlias(idx);
173172
if (t == null)
174173
{
175174
return Exceptions.RaiseTypeError("type expected");
176175
}
177176
Type a = t.MakeArrayType();
178177
ClassBase o = ClassManager.GetClass(a);
179-
Runtime.XIncref(o.pyHandle);
180-
return o.pyHandle;
178+
return new NewReference(o.ObjectReference);
181179
}
182180

183181
// If there are generics in our namespace with the same base name
184182
// as the current type, then [<type>] means the caller wants to
185183
// bind the generic type matching the given type parameters.
186-
Type[] types = Runtime.PythonArgsToTypeArray(idx);
184+
Type[]? types = Runtime.PythonArgsToTypeArray(idx);
187185
if (types == null)
188186
{
189187
return Exceptions.RaiseTypeError("type(s) expected");
@@ -192,10 +190,8 @@ public override NewReference type_subscript(BorrowedReference idx)
192190
Type gtype = AssemblyManager.LookupTypes($"{type.Value.FullName}`{types.Length}").FirstOrDefault();
193191
if (gtype != null)
194192
{
195-
var g = ClassManager.GetClass(gtype) as GenericType;
193+
var g = (GenericType)ClassManager.GetClass(gtype);
196194
return g.type_subscript(idx);
197-
//Runtime.XIncref(g.pyHandle);
198-
//return g.pyHandle;
199195
}
200196
return Exceptions.RaiseTypeError("unsubscriptable object");
201197
}

0 commit comments

Comments
 (0)