43
43
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__DOC__ ;
44
44
45
45
import com .oracle .graal .python .builtins .Builtin ;
46
- import com .oracle .graal .python .builtins .objects .PNone ;
47
46
import com .oracle .graal .python .builtins .objects .PythonAbstractObject ;
48
47
import com .oracle .graal .python .builtins .objects .cext .capi .CArrayWrappers .CStringWrapper ;
49
- import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodes .AsCharPointerNode ;
50
48
import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodes .FromCharPointerNode ;
51
49
import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodes .GetNativeNullNode ;
52
50
import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodes .ToSulongNode ;
82
80
import com .oracle .truffle .api .nodes .Node ;
83
81
import com .oracle .truffle .llvm .spi .NativeTypeLibrary ;
84
82
85
- /**
86
- * Wraps a PythonObject to provide a native view with a shape like {@code PyMethodDescr}.
87
- */
88
83
/**
89
84
* Wrapper object that emulate the ABI for {@code PyMethodDef}.
90
85
*
99
94
*/
100
95
@ ExportLibrary (InteropLibrary .class )
101
96
@ ExportLibrary (NativeTypeLibrary .class )
102
- public class PyMethodDescrWrapper extends PythonNativeWrapper {
97
+ public class PyMethodDefWrapper extends PythonNativeWrapper {
103
98
public static final String ML_NAME = "ml_name" ;
104
99
public static final String ML_METH = "ml_meth" ;
105
100
public static final String ML_FLAGS = "ml_flags" ;
106
101
public static final String ML_DOC = "ml_doc" ;
107
102
108
- public PyMethodDescrWrapper (PythonObject delegate ) {
103
+ public PyMethodDefWrapper (PythonObject delegate ) {
109
104
super (delegate );
110
105
}
111
106
@@ -140,7 +135,7 @@ protected Object readMember(String member,
140
135
}
141
136
142
137
@ GenerateUncached
143
- @ ImportStatic (PyMethodDescrWrapper .class )
138
+ @ ImportStatic (PyMethodDefWrapper .class )
144
139
abstract static class ReadFieldNode extends Node {
145
140
146
141
public abstract Object execute (Object delegate , String key );
@@ -153,14 +148,17 @@ protected static boolean eq(String expected, String actual) {
153
148
static Object getName (PythonObject object , @ SuppressWarnings ("unused" ) String key ,
154
149
@ Cached PythonAbstractObject .PInteropGetAttributeNode getAttrNode ,
155
150
@ Shared ("toSulongNode" ) @ Cached ToSulongNode toSulongNode ,
156
- @ Shared ("asCharPointerNode " ) @ Cached AsCharPointerNode asCharPointerNode ,
151
+ @ Shared ("castToJavaStringNode " ) @ Cached CastToJavaStringNode castToJavaStringNode ,
157
152
@ Shared ("getNativeNullNode" ) @ Cached GetNativeNullNode getNativeNullNode ) {
158
153
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
+ }
163
160
}
161
+ return toSulongNode .execute (getNativeNullNode .execute ());
164
162
}
165
163
166
164
@ Specialization (guards = {"eq(ML_DOC, key)" })
@@ -170,7 +168,7 @@ static Object getDoc(PythonObject object, @SuppressWarnings("unused") String key
170
168
@ Shared ("castToJavaStringNode" ) @ Cached CastToJavaStringNode castToJavaStringNode ,
171
169
@ Shared ("getNativeNullNode" ) @ Cached GetNativeNullNode getNativeNullNode ) {
172
170
Object doc = getAttrNode .execute (object , __DOC__ );
173
- if (doc != PNone . NO_VALUE ) {
171
+ if (! PGuards . isPNone ( doc ) ) {
174
172
try {
175
173
return new CStringWrapper (castToJavaStringNode .execute (doc ));
176
174
} catch (CannotCastException e ) {
@@ -187,7 +185,7 @@ static Object getMeth(PythonObject object, @SuppressWarnings("unused") String ke
187
185
}
188
186
189
187
@ 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 ) {
191
189
PBuiltinFunction fun = null ;
192
190
if (object instanceof PBuiltinFunction ) {
193
191
fun = (PBuiltinFunction ) object ;
@@ -264,7 +262,7 @@ protected void removeMember(@SuppressWarnings("unused") String member) throws Un
264
262
}
265
263
266
264
@ GenerateUncached
267
- @ ImportStatic ({SpecialMethodNames .class , PGuards .class , PyMethodDescrWrapper .class })
265
+ @ ImportStatic ({SpecialMethodNames .class , PGuards .class , PyMethodDefWrapper .class })
268
266
abstract static class WriteFieldNode extends Node {
269
267
270
268
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) {
273
271
return expected .equals (actual );
274
272
}
275
273
276
- @ Specialization (guards = {"!isBuiltinMethod(object)" , "!isBuiltinFunction(object)" , "eq(DOC , key)" })
274
+ @ Specialization (guards = {"!isBuiltinMethod(object)" , "!isBuiltinFunction(object)" , "eq(ML_DOC , key)" })
277
275
static void doPythonObject (PythonObject object , @ SuppressWarnings ("unused" ) String key , Object value ,
278
276
@ Cached ("key" ) @ SuppressWarnings ("unused" ) String cachedKey ,
279
277
@ Cached PythonAbstractObject .PInteropSetAttributeNode setAttrNode ,
280
278
@ Shared ("fromCharPointerNode" ) @ Cached FromCharPointerNode fromCharPointerNode ) throws UnsupportedMessageException , UnknownIdentifierException {
281
279
setAttrNode .execute (object , __DOC__ , fromCharPointerNode .execute (value ));
282
280
}
283
281
284
- @ Specialization (guards = {"isBuiltinMethod(object) || isBuiltinFunction(object)" , "eq(DOC , key)" })
282
+ @ Specialization (guards = {"isBuiltinMethod(object) || isBuiltinFunction(object)" , "eq(ML_DOC , key)" })
285
283
static void doBuiltinFunctionOrMethod (PythonBuiltinObject object , @ SuppressWarnings ("unused" ) String key , Object value ,
286
284
@ Cached ("key" ) @ SuppressWarnings ("unused" ) String cachedKey ,
287
285
@ Exclusive @ Cached WriteAttributeToDynamicObjectNode writeAttrToDynamicObjectNode ,
0 commit comments