Skip to content

Commit 85b0c0d

Browse files
committed
Fixing problem with creating recursive node.
1 parent 4a30e81 commit 85b0c0d

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_bytes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,17 @@ def test_empty_separator(self):
593593
self.assertRaises(ValueError, self.type2test(b'a b').split, b'')
594594
self.assertRaises(ValueError, self.type2test(b'a b').rsplit, b'')
595595

596+
def test_indexable_object(self):
597+
598+
class MyIndexable(object):
599+
def __init__(self, value):
600+
self.value = value
601+
def __index__(self):
602+
return self.value
603+
604+
self.assertEqual(self.type2test(b'ahoj jak\tse\nmas').split(maxsplit=MyIndexable(1)), [b'ahoj', b'jak\tse\nmas'])
605+
self.assertEqual(self.type2test(b'ahoj jak\tse\nmas').rsplit(maxsplit=MyIndexable(1)), [b'ahoj jak\tse', b'mas'])
606+
596607
class BytesSplitTest(BaseTestSplit, unittest.TestCase):
597608
type2test = bytes
598609

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/AbstractBytesBuiltins.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.oracle.graal.python.builtins.objects.ints.PInt;
5050
import com.oracle.graal.python.builtins.objects.list.ListBuiltins.ListAppendNode;
5151
import com.oracle.graal.python.builtins.objects.list.PList;
52+
import com.oracle.graal.python.nodes.argument.ReadArgumentNode;
5253
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5354
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
5455
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
@@ -318,6 +319,10 @@ protected List<byte[]> splitDelimiter(byte[] bytes, byte[] sep, int maxsplit) {
318319
throw new RuntimeException();
319320
}
320321

322+
protected AbstractSplitNode createRecursiveNode() {
323+
throw new RuntimeException();
324+
}
325+
321326
@CompilationFinal private ConditionProfile isEmptySepProfile;
322327
@CompilationFinal private ConditionProfile overflowProfile;
323328

@@ -348,10 +353,6 @@ protected List<byte[]> splitDelimiter(byte[] bytes, byte[] sep, int maxsplit) {
348353
}
349354
}
350355

351-
public static AbstractSplitNode create() {
352-
return AbstractBytesBuiltinsFactory.AbstractSplitNodeGen.create();
353-
}
354-
355356
private ConditionProfile getIsEmptyProfile() {
356357
if (isEmptySepProfile == null) {
357358
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -403,7 +404,7 @@ private CastToIntegerFromIndexNode getCastIntNode() {
403404
private AbstractSplitNode getRecursiveNode() {
404405
if (recursiveNode == null) {
405406
CompilerDirectives.transferToInterpreterAndInvalidate();
406-
recursiveNode = insert(AbstractSplitNode.create());
407+
recursiveNode = insert(createRecursiveNode());
407408
}
408409
return recursiveNode;
409410
}
@@ -661,6 +662,11 @@ protected List<byte[]> splitDelimiter(byte[] bytes, byte[] sep, int maxsplit) {
661662
}
662663
return result;
663664
}
665+
666+
@Override
667+
protected AbstractSplitNode createRecursiveNode() {
668+
return AbstractBytesBuiltinsFactory.SplitNodeFactory.create(new ReadArgumentNode[]{});
669+
}
664670
}
665671

666672
@Builtin(name = "rsplit", minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 3, keywordArguments = {"sep", "maxsplit"})
@@ -763,5 +769,10 @@ protected List<byte[]> splitDelimiter(byte[] bytes, byte[] sep, int maxsplit) {
763769
}
764770
return result;
765771
}
772+
773+
@Override
774+
protected AbstractSplitNode createRecursiveNode() {
775+
return AbstractBytesBuiltinsFactory.RSplitNodeFactory.create(new ReadArgumentNode[]{});
776+
}
766777
}
767778
}

0 commit comments

Comments
 (0)