|
106 | 106 | import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes;
|
107 | 107 | import com.oracle.graal.python.builtins.objects.common.PHashingCollection;
|
108 | 108 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
|
| 109 | +import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.CastToByteNode; |
109 | 110 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.NormalizeIndexNode;
|
110 | 111 | import com.oracle.graal.python.builtins.objects.complex.PComplex;
|
111 | 112 | import com.oracle.graal.python.builtins.objects.dict.PDict;
|
|
162 | 163 | import com.oracle.graal.python.runtime.exception.PException;
|
163 | 164 | import com.oracle.graal.python.runtime.exception.PythonErrorType;
|
164 | 165 | import com.oracle.graal.python.runtime.object.PythonObjectFactory;
|
| 166 | +import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage; |
165 | 167 | import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
|
166 | 168 | import com.oracle.truffle.api.CallTarget;
|
167 | 169 | import com.oracle.truffle.api.CompilerDirectives;
|
@@ -2431,4 +2433,32 @@ int add(Object self, @SuppressWarnings("unused") Object o) {
|
2431 | 2433 |
|
2432 | 2434 | }
|
2433 | 2435 |
|
| 2436 | + @Builtin(name = "_PyBytes_Resize", fixedNumOfPositionalArgs = 2) |
| 2437 | + @GenerateNodeFactory |
| 2438 | + public abstract static class PyBytes_Resize extends PythonBinaryBuiltinNode { |
| 2439 | + |
| 2440 | + @Specialization |
| 2441 | + int resize(PBytes self, long newSizeL, |
| 2442 | + @Cached("create()") SequenceStorageNodes.LenNode lenNode, |
| 2443 | + @Cached("create()") SequenceStorageNodes.GetItemNode getItemNode, |
| 2444 | + @Cached("create()") CastToIndexNode castToIndexNode, |
| 2445 | + @Cached("create()") CastToByteNode castToByteNode) { |
| 2446 | + |
| 2447 | + SequenceStorage storage = self.getSequenceStorage(); |
| 2448 | + int newSize = castToIndexNode.execute(newSizeL); |
| 2449 | + int len = lenNode.execute(storage); |
| 2450 | + byte[] smaller = new byte[newSize]; |
| 2451 | + for (int i = 0; i < newSize && i < len; i++) { |
| 2452 | + smaller[i] = castToByteNode.execute(getItemNode.execute(storage, i)); |
| 2453 | + } |
| 2454 | + self.setSequenceStorage(new ByteSequenceStorage(smaller)); |
| 2455 | + return 0; |
| 2456 | + } |
| 2457 | + |
| 2458 | + @Fallback |
| 2459 | + int add(Object self, @SuppressWarnings("unused") Object o) { |
| 2460 | + return NativeBuiltin.raiseNative(this, -1, SystemError, "expected a set object, not %p", self); |
| 2461 | + } |
| 2462 | + |
| 2463 | + } |
2434 | 2464 | }
|
0 commit comments