Skip to content

Commit 877d9e4

Browse files
committed
[GR-34916] Intrinsify python_cext - removed GetNativeNullNode.
PullRequest: graalpython/2103
2 parents ac16453 + 90875d7 commit 877d9e4

34 files changed

+449
-700
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java

Lines changed: 84 additions & 126 deletions
Large diffs are not rendered by default.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java

Lines changed: 62 additions & 90 deletions
Large diffs are not rendered by default.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBytesBuiltins.java

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import com.oracle.graal.python.builtins.objects.cext.capi.CApiGuards;
6363
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes;
6464
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.AsPythonObjectNode;
65-
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.GetNativeNullNode;
6665
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.PRaiseNativeNode;
6766
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.TransformExceptionToNativeNode;
6867
import com.oracle.graal.python.builtins.objects.cext.capi.PythonNativeWrapper;
@@ -164,33 +163,30 @@ public abstract static class PyBytesConcatNode extends PythonBinaryBuiltinNode {
164163
@Specialization
165164
public Object concat(VirtualFrame frame, PBytes original, Object newPart,
166165
@Cached BytesBuiltins.AddNode addNode,
167-
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
168-
@Cached GetNativeNullNode getNativeNullNode) {
166+
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
169167
try {
170168
return addNode.execute(frame, original, newPart);
171169
} catch (PException e) {
172170
transformExceptionToNativeNode.execute(e);
173-
return getNativeNullNode.execute();
171+
return getContext().getNativeNull();
174172
}
175173
}
176174

177175
@Specialization(guards = {"!isPBytes(original)", "isBytesSubtype(frame, original, getClassNode, isSubtypeNode)"})
178176
public Object concatNative(VirtualFrame frame, @SuppressWarnings("unused") Object original, @SuppressWarnings("unused") Object newPart,
179177
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
180178
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
181-
@Cached GetNativeNullNode getNativeNullNode,
182179
@Cached PRaiseNativeNode raiseNativeNode) {
183-
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), PythonBuiltinClassType.NotImplementedError, NATIVE_S_SUBTYPES_NOT_IMPLEMENTED, "bytes");
180+
return raiseNativeNode.raise(frame, getContext().getNativeNull(), PythonBuiltinClassType.NotImplementedError, NATIVE_S_SUBTYPES_NOT_IMPLEMENTED, "bytes");
184181
}
185182

186183
@Specialization(guards = {"!isPBytes(original)", "!isBytesSubtype(frame, original, getClassNode, isSubtypeNode)"})
187184
public Object concat(VirtualFrame frame, Object original, @SuppressWarnings("unused") Object newPart,
188185
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
189186
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
190187
@Cached StrNode strNode,
191-
@Cached GetNativeNullNode getNativeNullNode,
192188
@Cached PRaiseNativeNode raiseNativeNode) {
193-
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(frame, original), original);
189+
return raiseNativeNode.raise(frame, getContext().getNativeNull(), SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(frame, original), original);
194190
}
195191

196192
protected boolean isBytesSubtype(VirtualFrame frame, Object obj, GetClassNode getClassNode, IsSubtypeNode isSubtypeNode) {
@@ -204,33 +200,30 @@ public abstract static class PyBytesJoinNode extends PythonBinaryBuiltinNode {
204200
@Specialization
205201
public Object join(VirtualFrame frame, PBytes original, Object newPart,
206202
@Cached BytesBuiltins.JoinNode joinNode,
207-
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
208-
@Cached GetNativeNullNode getNativeNullNode) {
203+
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
209204
try {
210205
return joinNode.execute(frame, original, newPart);
211206
} catch (PException e) {
212207
transformExceptionToNativeNode.execute(e);
213-
return getNativeNullNode.execute();
208+
return getContext().getNativeNull();
214209
}
215210
}
216211

217212
@Specialization(guards = {"!isPBytes(original)", "isBytesSubtype(frame, original, getClassNode, isSubtypeNode)"})
218213
public Object joinNative(VirtualFrame frame, @SuppressWarnings("unused") Object original, @SuppressWarnings("unused") Object newPart,
219214
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
220215
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
221-
@Cached PRaiseNativeNode raiseNativeNode,
222-
@Cached GetNativeNullNode getNativeNullNode) {
223-
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), PythonBuiltinClassType.NotImplementedError, NATIVE_S_SUBTYPES_NOT_IMPLEMENTED, "bytes");
216+
@Cached PRaiseNativeNode raiseNativeNode) {
217+
return raiseNativeNode.raise(frame, getContext().getNativeNull(), PythonBuiltinClassType.NotImplementedError, NATIVE_S_SUBTYPES_NOT_IMPLEMENTED, "bytes");
224218
}
225219

226220
@Specialization(guards = {"!isPBytes(original)", "!isBytesSubtype(frame, original, getClassNode, isSubtypeNode)"})
227221
public Object join(VirtualFrame frame, @SuppressWarnings("unused") Object original, @SuppressWarnings("unused") Object newPart,
228222
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
229223
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
230224
@Cached StrNode strNode,
231-
@Cached PRaiseNativeNode raiseNativeNode,
232-
@Cached GetNativeNullNode getNativeNullNode) {
233-
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(frame, original), original);
225+
@Cached PRaiseNativeNode raiseNativeNode) {
226+
return raiseNativeNode.raise(frame, getContext().getNativeNull(), SystemError, BAD_ARG_TO_INTERNAL_FUNC_WAS_S_P, strNode.executeWith(frame, original), original);
234227
}
235228

236229
protected boolean isBytesSubtype(VirtualFrame frame, Object obj, GetClassNode getClassNode, IsSubtypeNode isSubtypeNode) {
@@ -245,14 +238,13 @@ public abstract static class PyBytesFromFormatNode extends PythonBinaryBuiltinNo
245238
public Object fromFormat(VirtualFrame frame, String fmt, Object args,
246239
@Cached ModNode modeNode,
247240
@Cached EncodeNode encodeNode,
248-
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
249-
@Cached GetNativeNullNode getNativeNullNode) {
241+
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
250242
try {
251243
Object formated = modeNode.execute(frame, fmt, args);
252244
return encodeNode.execute(frame, formated, PNone.NONE, PNone.NONE);
253245
} catch (PException e) {
254246
transformExceptionToNativeNode.execute(e);
255-
return getNativeNullNode.execute();
247+
return getContext().getNativeNull();
256248
}
257249
}
258250
}
@@ -273,13 +265,12 @@ public Object fromObject(VirtualFrame frame, Object obj,
273265
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
274266
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
275267
@SuppressWarnings("unused") @Cached PyObjectLookupAttr lookupAttrNode,
276-
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
277-
@Cached GetNativeNullNode getNativeNullNode) {
268+
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
278269
try {
279270
return bytesNode.execute(frame, PythonBuiltinClassType.PBytes, obj, PNone.NO_VALUE, PNone.NO_VALUE);
280271
} catch (PException e) {
281272
transformExceptionToNativeNode.execute(e);
282-
return getNativeNullNode.execute();
273+
return getContext().getNativeNull();
283274
}
284275
}
285276

@@ -288,9 +279,8 @@ public Object fromObject(VirtualFrame frame, Object obj,
288279
@SuppressWarnings("unused") @Cached GetClassNode getClassNode,
289280
@SuppressWarnings("unused") @Cached IsSubtypeNode isSubtypeNode,
290281
@SuppressWarnings("unused") @Cached PyObjectLookupAttr lookupAttrNode,
291-
@Cached PRaiseNativeNode raiseNativeNode,
292-
@Cached GetNativeNullNode getNativeNullNode) {
293-
return raiseNativeNode.raise(frame, getNativeNullNode.execute(), TypeError, CANNOT_CONVERT_P_OBJ_TO_S, obj, "bytes");
282+
@Cached PRaiseNativeNode raiseNativeNode) {
283+
return raiseNativeNode.raise(frame, getContext().getNativeNull(), TypeError, CANNOT_CONVERT_P_OBJ_TO_S, obj, "bytes");
294284
}
295285

296286
protected boolean isBytesSubtype(VirtualFrame frame, Object obj, GetClassNode getClassNode, IsSubtypeNode isSubtypeNode) {
@@ -306,7 +296,7 @@ protected boolean isAcceptedSubtype(VirtualFrame frame, Object obj, GetClassNode
306296
}
307297
}
308298

309-
@Builtin(name = "PyBytes_FromStringAndSize", minNumOfPositionalArgs = 3, declaresExplicitSelf = true)
299+
@Builtin(name = "PyBytes_FromStringAndSize", minNumOfPositionalArgs = 2)
310300
@GenerateNodeFactory
311301
@ImportStatic(CApiGuards.class)
312302
abstract static class PyBytes_FromStringAndSize extends NativeBuiltin {
@@ -317,7 +307,7 @@ abstract static class PyBytes_FromStringAndSize extends NativeBuiltin {
317307
// PythonNativeObject)
318308

319309
@Specialization
320-
Object doGeneric(VirtualFrame frame, @SuppressWarnings("unused") Object module, PythonNativeWrapper object, long size,
310+
Object doGeneric(VirtualFrame frame, PythonNativeWrapper object, long size,
321311
@Cached AsPythonObjectNode asPythonObjectNode,
322312
@Exclusive @Cached BytesNodes.ToBytesNode getByteArrayNode,
323313
@Shared("toSulongNode") @Cached CExtNodes.ToSulongNode toSulongNode) {
@@ -333,16 +323,15 @@ Object doGeneric(VirtualFrame frame, @SuppressWarnings("unused") Object module,
333323
}
334324

335325
@Specialization(guards = "!isNativeWrapper(nativePointer)")
336-
Object doNativePointer(VirtualFrame frame, Object module, Object nativePointer, long size,
337-
@Exclusive @Cached GetNativeNullNode getNativeNullNode,
326+
Object doNativePointer(VirtualFrame frame, Object nativePointer, long size,
338327
@Exclusive @Cached GetByteArrayNode getByteArrayNode,
339328
@Shared("toSulongNode") @Cached CExtNodes.ToSulongNode toSulongNode) {
340329
try {
341330
return toSulongNode.execute(factory().createBytes(getByteArrayNode.execute(nativePointer, size)));
342331
} catch (InteropException e) {
343-
return raiseNative(frame, getNativeNullNode.execute(module), PythonErrorType.TypeError, "%m", e);
332+
return raiseNative(frame, getContext().getNativeNull(), PythonErrorType.TypeError, "%m", e);
344333
} catch (OverflowException e) {
345-
return raiseNative(frame, getNativeNullNode.execute(module), PythonErrorType.SystemError, "negative size passed");
334+
return raiseNative(frame, getContext().getNativeNull(), PythonErrorType.SystemError, "negative size passed");
346335
}
347336
}
348337
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCEvalBuiltins.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import com.oracle.graal.python.builtins.PythonBuiltins;
4848
import com.oracle.graal.python.builtins.modules.ThreadModuleBuiltins.AllocateLockNode;
4949
import com.oracle.graal.python.builtins.objects.PNone;
50-
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.GetNativeNullNode;
5150
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.TransformExceptionToNativeNode;
5251
import com.oracle.graal.python.builtins.objects.module.PythonModule;
5352
import com.oracle.graal.python.builtins.objects.thread.LockBuiltins.AcquireLockNode;
@@ -85,13 +84,12 @@ public abstract static class PyThreadAllocateLockNode extends PythonBuiltinNode
8584
@Specialization
8685
public Object allocate(VirtualFrame frame,
8786
@Cached AllocateLockNode allocateNode,
88-
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
89-
@Cached GetNativeNullNode getNativeNullNode) {
87+
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
9088
try {
9189
return allocateNode.execute(frame, PNone.NO_VALUE, PNone.NO_VALUE);
9290
} catch (PException e) {
9391
transformExceptionToNativeNode.execute(e);
94-
return getNativeNullNode.execute();
92+
return getContext().getNativeNull();
9593
}
9694
}
9795
}
@@ -118,13 +116,12 @@ public abstract static class PyThreadReleaseLockNode extends PythonUnaryBuiltinN
118116
@Specialization
119117
public Object release(VirtualFrame frame, PLock lock,
120118
@Cached ReleaseLockNode releaseNode,
121-
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
122-
@Cached GetNativeNullNode getNativeNullNode) {
119+
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
123120
try {
124121
return releaseNode.execute(frame, lock);
125122
} catch (PException e) {
126123
transformExceptionToNativeNode.execute(e);
127-
return getNativeNullNode.execute();
124+
return getContext().getNativeNull();
128125
}
129126
}
130127
}
@@ -134,14 +131,13 @@ public Object release(VirtualFrame frame, PLock lock,
134131
public abstract static class PyEvalGetBuiltinsNode extends PythonBuiltinNode {
135132
@Specialization
136133
public Object release(@Cached GetDictIfExistsNode getDictNode,
137-
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
138-
@Cached GetNativeNullNode getNativeNullNode) {
134+
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
139135
try {
140136
PythonModule cext = getCore().getBuiltins();
141137
return getDictNode.execute(cext);
142138
} catch (PException e) {
143139
transformExceptionToNativeNode.execute(e);
144-
return getNativeNullNode.execute();
140+
return getContext().getNativeNull();
145141
}
146142
}
147143
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextCodeBuiltins.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import com.oracle.graal.python.builtins.Python3Core;
4848
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4949
import com.oracle.graal.python.builtins.PythonBuiltins;
50-
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.GetNativeNullNode;
5150
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.TransformExceptionToNativeNode;
5251
import com.oracle.graal.python.nodes.call.CallNode;
5352
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -80,8 +79,7 @@ public abstract static class PyCodeNewNode extends PythonBuiltinNode {
8079
@Specialization
8180
public Object codeNew(VirtualFrame frame, Object[] arguments,
8281
@Cached CallNode callNode,
83-
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
84-
@Cached GetNativeNullNode getNativeNullNode) {
82+
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
8583
try {
8684
Object[] args = new Object[arguments.length + 1];
8785
// Add posonlyargcount (2nd arg)
@@ -91,7 +89,7 @@ public Object codeNew(VirtualFrame frame, Object[] arguments,
9189
return callNode.execute(frame, PythonBuiltinClassType.PCode, args);
9290
} catch (PException e) {
9391
transformExceptionToNativeNode.execute(e);
94-
return getNativeNullNode.execute();
92+
return getContext().getNativeNull();
9593
}
9694
}
9795
}
@@ -102,13 +100,12 @@ public abstract static class PyCodeNewWithPosOnlyArgsNode extends PythonBuiltinN
102100
@Specialization
103101
public Object codeNew(VirtualFrame frame, Object[] arguments,
104102
@Cached CallNode callNode,
105-
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
106-
@Cached GetNativeNullNode getNativeNullNode) {
103+
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
107104
try {
108105
return callNode.execute(frame, PythonBuiltinClassType.PCode, arguments);
109106
} catch (PException e) {
110107
transformExceptionToNativeNode.execute(e);
111-
return getNativeNullNode.execute();
108+
return getContext().getNativeNull();
112109
}
113110
}
114111
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextComplexBuiltins.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import com.oracle.graal.python.builtins.PythonBuiltins;
5050
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.ComplexNode;
5151
import com.oracle.graal.python.builtins.objects.PNone;
52-
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.GetNativeNullNode;
5352
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.TransformExceptionToNativeNode;
5453
import com.oracle.graal.python.builtins.objects.complex.PComplex;
5554
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
@@ -94,14 +93,13 @@ PTuple asComplex(PComplex c) {
9493
@Specialization(guards = "!isPComplex(obj)")
9594
Object asComplex(VirtualFrame frame, Object obj,
9695
@Cached ComplexNode complexNode,
97-
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
98-
@Cached GetNativeNullNode getNativeNullNode) {
96+
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
9997
try {
10098
PComplex c = (PComplex) complexNode.execute(frame, PythonBuiltinClassType.PComplex, obj, PNone.NO_VALUE);
10199
return factory().createTuple(new Object[]{c.getReal(), c.getImag()});
102100
} catch (PException e) {
103101
transformExceptionToNativeNode.execute(e);
104-
return getNativeNullNode.execute();
102+
return getContext().getNativeNull();
105103
}
106104
}
107105
}

0 commit comments

Comments
 (0)