50
50
import com .oracle .graal .python .nodes .PRaiseNode ;
51
51
import com .oracle .graal .python .nodes .builtins .ListNodes ;
52
52
import com .oracle .graal .python .nodes .call .special .LookupAndCallUnaryNode ;
53
+ import com .oracle .graal .python .runtime .sequence .storage .EmptySequenceStorage ;
54
+ import com .oracle .graal .python .runtime .sequence .storage .ObjectSequenceStorage ;
55
+ import com .oracle .graal .python .runtime .sequence .storage .SequenceStorage ;
53
56
import com .oracle .truffle .api .dsl .Cached ;
54
57
import com .oracle .truffle .api .dsl .GenerateCached ;
55
58
import com .oracle .truffle .api .dsl .GenerateInline ;
56
59
import com .oracle .truffle .api .dsl .Specialization ;
57
60
import com .oracle .truffle .api .frame .VirtualFrame ;
58
61
import com .oracle .truffle .api .nodes .Node ;
62
+ import com .oracle .truffle .api .object .HiddenKey ;
59
63
60
64
/**
61
65
* Partial equivalent of CPython's {@code PyObject_Dir}. Only supports listing attributes of an
@@ -77,7 +81,30 @@ static PList dir(VirtualFrame frame, Node inliningTarget, Object object,
77
81
throw raiseNode .get (inliningTarget ).raise (TypeError , ErrorMessages .OBJ_DOES_NOT_PROVIDE_DIR );
78
82
}
79
83
PList list = constructListNode .execute (frame , result );
84
+ filterHiddenKeys (list .getSequenceStorage ());
80
85
sortNode .execute (frame , list );
81
86
return list ;
82
87
}
88
+
89
+ static void filterHiddenKeys (SequenceStorage s ) {
90
+ if (s instanceof EmptySequenceStorage ) {
91
+ // noting to do.
92
+ } else if (s instanceof ObjectSequenceStorage storage ) {
93
+ // String do not have a special storage
94
+ Object [] oldarray = storage .getInternalArray ();
95
+ Object [] newarray = new Object [storage .length ()];
96
+ int j = 0 ;
97
+ for (int i = 0 ; i < storage .length (); i ++) {
98
+ Object o = oldarray [i ];
99
+ if (o instanceof HiddenKey ) {
100
+ continue ;
101
+ }
102
+ newarray [j ++] = o ;
103
+ }
104
+ storage .setInternalArrayObject (newarray );
105
+ storage .setNewLength (j );
106
+ } else {
107
+ assert false : "Unexpected storage type!" ;
108
+ }
109
+ }
83
110
}
0 commit comments