Skip to content

Commit 3b917e8

Browse files
committed
Rename PyMethodDescrWrapper to PyMethodDefWrapper
1 parent 0a58d6a commit 3b917e8

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/DynamicObjectNativeWrapper.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -889,27 +889,27 @@ static Object doDGetSet(PythonObject object, @SuppressWarnings("unused") PythonN
889889

890890
@Specialization(guards = "eq(D_METHOD, key)")
891891
static Object doDBase(PythonObject object, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key) {
892-
return new PyMethodDescrWrapper(object);
892+
return new PyMethodDefWrapper(object);
893893
}
894894

895895
@Specialization(guards = "eq(M_ML, key)")
896896
static Object doDBase(PBuiltinFunction object, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key) {
897-
return new PyMethodDescrWrapper(object);
897+
return new PyMethodDefWrapper(object);
898898
}
899899

900900
@Specialization(guards = "eq(M_ML, key)")
901901
static Object doDBase(PFunction object, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key) {
902-
return new PyMethodDescrWrapper(object);
902+
return new PyMethodDefWrapper(object);
903903
}
904904

905905
@Specialization(guards = "eq(M_ML, key)")
906906
static Object doDBase(PBuiltinMethod object, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key) {
907-
return new PyMethodDescrWrapper(object);
907+
return new PyMethodDefWrapper(object);
908908
}
909909

910910
@Specialization(guards = "eq(M_ML, key)")
911911
static Object doDBase(PMethod object, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key) {
912-
return new PyMethodDescrWrapper(object);
912+
return new PyMethodDefWrapper(object);
913913
}
914914

915915
@Specialization(guards = "eq(D_QUALNAME, key)")
Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@
4343
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__DOC__;
4444

4545
import com.oracle.graal.python.builtins.Builtin;
46-
import com.oracle.graal.python.builtins.objects.PNone;
4746
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
4847
import com.oracle.graal.python.builtins.objects.cext.capi.CArrayWrappers.CStringWrapper;
49-
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.AsCharPointerNode;
5048
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.FromCharPointerNode;
5149
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.GetNativeNullNode;
5250
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.ToSulongNode;
@@ -82,9 +80,6 @@
8280
import com.oracle.truffle.api.nodes.Node;
8381
import com.oracle.truffle.llvm.spi.NativeTypeLibrary;
8482

85-
/**
86-
* Wraps a PythonObject to provide a native view with a shape like {@code PyMethodDescr}.
87-
*/
8883
/**
8984
* Wrapper object that emulate the ABI for {@code PyMethodDef}.
9085
*
@@ -99,13 +94,13 @@
9994
*/
10095
@ExportLibrary(InteropLibrary.class)
10196
@ExportLibrary(NativeTypeLibrary.class)
102-
public class PyMethodDescrWrapper extends PythonNativeWrapper {
97+
public class PyMethodDefWrapper extends PythonNativeWrapper {
10398
public static final String ML_NAME = "ml_name";
10499
public static final String ML_METH = "ml_meth";
105100
public static final String ML_FLAGS = "ml_flags";
106101
public static final String ML_DOC = "ml_doc";
107102

108-
public PyMethodDescrWrapper(PythonObject delegate) {
103+
public PyMethodDefWrapper(PythonObject delegate) {
109104
super(delegate);
110105
}
111106

@@ -140,7 +135,7 @@ protected Object readMember(String member,
140135
}
141136

142137
@GenerateUncached
143-
@ImportStatic(PyMethodDescrWrapper.class)
138+
@ImportStatic(PyMethodDefWrapper.class)
144139
abstract static class ReadFieldNode extends Node {
145140

146141
public abstract Object execute(Object delegate, String key);
@@ -153,14 +148,17 @@ protected static boolean eq(String expected, String actual) {
153148
static Object getName(PythonObject object, @SuppressWarnings("unused") String key,
154149
@Cached PythonAbstractObject.PInteropGetAttributeNode getAttrNode,
155150
@Shared("toSulongNode") @Cached ToSulongNode toSulongNode,
156-
@Shared("asCharPointerNode") @Cached AsCharPointerNode asCharPointerNode,
151+
@Shared("castToJavaStringNode") @Cached CastToJavaStringNode castToJavaStringNode,
157152
@Shared("getNativeNullNode") @Cached GetNativeNullNode getNativeNullNode) {
158153
Object name = getAttrNode.execute(object, SpecialAttributeNames.__NAME__);
159-
if (PGuards.isPNone(name)) {
160-
return toSulongNode.execute(getNativeNullNode.execute());
161-
} else {
162-
return asCharPointerNode.execute(name);
154+
if (!PGuards.isPNone(name)) {
155+
try {
156+
return new CStringWrapper(castToJavaStringNode.execute(name));
157+
} catch (CannotCastException e) {
158+
// fall through
159+
}
163160
}
161+
return toSulongNode.execute(getNativeNullNode.execute());
164162
}
165163

166164
@Specialization(guards = {"eq(ML_DOC, key)"})
@@ -170,7 +168,7 @@ static Object getDoc(PythonObject object, @SuppressWarnings("unused") String key
170168
@Shared("castToJavaStringNode") @Cached CastToJavaStringNode castToJavaStringNode,
171169
@Shared("getNativeNullNode") @Cached GetNativeNullNode getNativeNullNode) {
172170
Object doc = getAttrNode.execute(object, __DOC__);
173-
if (doc != PNone.NO_VALUE) {
171+
if (!PGuards.isPNone(doc)) {
174172
try {
175173
return new CStringWrapper(castToJavaStringNode.execute(doc));
176174
} catch (CannotCastException e) {
@@ -187,7 +185,7 @@ static Object getMeth(PythonObject object, @SuppressWarnings("unused") String ke
187185
}
188186

189187
@Specialization(guards = {"eq(ML_FLAGS, key)"})
190-
static Object getMeth(PythonObject object, @SuppressWarnings("unused") String key) {
188+
static Object getFlags(PythonObject object, @SuppressWarnings("unused") String key) {
191189
PBuiltinFunction fun = null;
192190
if (object instanceof PBuiltinFunction) {
193191
fun = (PBuiltinFunction) object;
@@ -264,7 +262,7 @@ protected void removeMember(@SuppressWarnings("unused") String member) throws Un
264262
}
265263

266264
@GenerateUncached
267-
@ImportStatic({SpecialMethodNames.class, PGuards.class, PyMethodDescrWrapper.class})
265+
@ImportStatic({SpecialMethodNames.class, PGuards.class, PyMethodDefWrapper.class})
268266
abstract static class WriteFieldNode extends Node {
269267

270268
public abstract void execute(Object delegate, String key, Object value) throws UnsupportedMessageException, UnknownIdentifierException;
@@ -273,15 +271,15 @@ protected static boolean eq(String expected, String actual) {
273271
return expected.equals(actual);
274272
}
275273

276-
@Specialization(guards = {"!isBuiltinMethod(object)", "!isBuiltinFunction(object)", "eq(DOC, key)"})
274+
@Specialization(guards = {"!isBuiltinMethod(object)", "!isBuiltinFunction(object)", "eq(ML_DOC, key)"})
277275
static void doPythonObject(PythonObject object, @SuppressWarnings("unused") String key, Object value,
278276
@Cached("key") @SuppressWarnings("unused") String cachedKey,
279277
@Cached PythonAbstractObject.PInteropSetAttributeNode setAttrNode,
280278
@Shared("fromCharPointerNode") @Cached FromCharPointerNode fromCharPointerNode) throws UnsupportedMessageException, UnknownIdentifierException {
281279
setAttrNode.execute(object, __DOC__, fromCharPointerNode.execute(value));
282280
}
283281

284-
@Specialization(guards = {"isBuiltinMethod(object) || isBuiltinFunction(object)", "eq(DOC, key)"})
282+
@Specialization(guards = {"isBuiltinMethod(object) || isBuiltinFunction(object)", "eq(ML_DOC, key)"})
285283
static void doBuiltinFunctionOrMethod(PythonBuiltinObject object, @SuppressWarnings("unused") String key, Object value,
286284
@Cached("key") @SuppressWarnings("unused") String cachedKey,
287285
@Exclusive @Cached WriteAttributeToDynamicObjectNode writeAttrToDynamicObjectNode,

0 commit comments

Comments
 (0)