Skip to content

Commit 7dd3dd9

Browse files
committed
Merge branch 'master' into bugfix/GR-13202
# Conflicts: # graalpython/com.oracle.graal.python.test/src/tests/test_bytes.py
2 parents 0724644 + 5ba3d97 commit 7dd3dd9

File tree

8 files changed

+515
-7
lines changed

8 files changed

+515
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ language runtime. The main focus is on user-observable behavior of the engine.
1818
* Improve performance of `os.scandir` and functions that build on it (such as `glob`)
1919
* More correct implementation of standard streams, including buffering
2020
* Properly support the `-m` switch to run modules
21-
* Support creating ZIP files through the standard `zipfile` module
21+
* Support the standard `zipfile` module
22+
* Add the built-in `_cvs` module
23+
* Add support for `__slots__`
24+
* Allow arbitrary callable objects in methods, not only functions
25+
* Report that we have a TTY console if we are launched on a Terminal through our launcher
26+
* Add the `ginstall` custom module to install known packages such as NumPy and setuptools
2227

2328
## Version 1.0.0 RC10
2429

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@ To try it, you can use the bundled releases from
1414
some examples of what you can do with it, check out the
1515
[reference](https://www.graalvm.org/docs/reference-manual/languages/python/).
1616

17+
### Installing packages
18+
19+
At the moment not enough of the standard library is implemented to run the
20+
standard package installers for many packages. As a convenience, we provide a
21+
simple module to install packages that we know to be working (including
22+
potential patches required for those packages). Try the following to find out
23+
more:
24+
25+
```
26+
graalpython -m ginstall --help
27+
```
28+
29+
As a slightly more exciting example, try:
30+
31+
```
32+
graalpython -m ginstall install numpy
33+
```
34+
35+
If all goes well (you'll need to have `clang`, `llvm-link`, `llvm-extract`,
36+
`llvm-nm`, and `opt` in your `PATH` in addition to the normal NumPy build
37+
dependencies), you should be able to `import numpy` afterwards.
38+
1739
### Licensing
1840

1941
This Graal/Truffle-based implementation of Python is copyright (c) 2017, 2018
@@ -23,3 +45,4 @@ Universal Permissive License v 1.0 as shown at
2345
implementation is in part derived from and contains additional code from 3rd
2446
parties, the copyrights and licensing of which is detailed in the
2547
[LICENSE](LICENSE) and [3rd_party_licenses.txt](3rd_party_licenses.txt) files.
48+

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
@@ -610,3 +610,14 @@ class BytesSplitTest(BaseTestSplit, unittest.TestCase):
610610
class ByteArraySplitTest(BaseTestSplit, unittest.TestCase):
611611
type2test = bytearray
612612

613+
def test_add_mv_to_bytes():
614+
b = b'hello '
615+
mv = memoryview(b'world')
616+
b += mv
617+
assert b == b'hello world'
618+
619+
def test_add_mv_to_bytearray():
620+
ba = bytearray(b'hello ')
621+
mv = memoryview(b'world')
622+
ba += mv
623+
assert ba == b'hello world'

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
33
* Copyright (c) 2014, Regents of the University of California
44
*
55
* All rights reserved.
@@ -244,6 +244,20 @@ public Object add(PByteArray self, PIBytesLike other,
244244
return factory().createByteArray(res);
245245
}
246246

247+
@Specialization
248+
public Object add(PByteArray self, PMemoryView other,
249+
@Cached("create(TOBYTES)") LookupAndCallUnaryNode toBytesNode,
250+
@Cached("createBinaryProfile()") ConditionProfile isBytesProfile,
251+
@Cached("create()") SequenceStorageNodes.ConcatNode concatNode) {
252+
253+
Object bytesObj = toBytesNode.executeObject(other);
254+
if (isBytesProfile.profile(bytesObj instanceof PBytes)) {
255+
SequenceStorage res = concatNode.execute(self.getSequenceStorage(), ((PBytes) bytesObj).getSequenceStorage());
256+
return factory().createByteArray(res);
257+
}
258+
throw raise(SystemError, "could not get bytes of memoryview");
259+
}
260+
247261
@SuppressWarnings("unused")
248262
@Fallback
249263
public Object add(Object self, Object other) {

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
33
* Copyright (c) 2014, Regents of the University of California
44
*
55
* All rights reserved.
@@ -61,13 +61,16 @@
6161
import com.oracle.graal.python.builtins.objects.dict.PDict;
6262
import com.oracle.graal.python.builtins.objects.iterator.PSequenceIterator;
6363
import com.oracle.graal.python.builtins.objects.list.PList;
64+
import com.oracle.graal.python.builtins.objects.memoryview.PMemoryView;
6465
import com.oracle.graal.python.nodes.PNodeWithContext;
66+
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
6567
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
6668
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
6769
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
6870
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
6971
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
7072
import com.oracle.graal.python.runtime.exception.PythonErrorType;
73+
import static com.oracle.graal.python.runtime.exception.PythonErrorType.SystemError;
7174
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
7275
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
7376
import com.oracle.truffle.api.CompilerDirectives;
@@ -77,6 +80,7 @@
7780
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
7881
import com.oracle.truffle.api.dsl.NodeFactory;
7982
import com.oracle.truffle.api.dsl.Specialization;
83+
import com.oracle.truffle.api.profiles.ConditionProfile;
8084

8185
@CoreFunctions(extendClasses = PythonBuiltinClassType.PBytes)
8286
public class BytesBuiltins extends PythonBuiltins {
@@ -260,6 +264,20 @@ public Object add(PBytes left, PIBytesLike right,
260264
return factory().createBytes(res);
261265
}
262266

267+
@Specialization
268+
public Object add(PBytes self, PMemoryView other,
269+
@Cached("create(TOBYTES)") LookupAndCallUnaryNode toBytesNode,
270+
@Cached("createBinaryProfile()") ConditionProfile isBytesProfile,
271+
@Cached("create()") SequenceStorageNodes.ConcatNode concatNode) {
272+
273+
Object bytesObj = toBytesNode.executeObject(other);
274+
if (isBytesProfile.profile(bytesObj instanceof PBytes)) {
275+
SequenceStorage res = concatNode.execute(self.getSequenceStorage(), ((PBytes) bytesObj).getSequenceStorage());
276+
return factory().createByteArray(res);
277+
}
278+
throw raise(SystemError, "could not get bytes of memoryview");
279+
}
280+
263281
@SuppressWarnings("unused")
264282
@Fallback
265283
public Object add(Object self, Object other) {

graalpython/lib-graalpython/_sre.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -319,7 +319,7 @@ def findall(self, string, pos=0, endpos=-1):
319319
self.__check_input_type(string)
320320
if endpos > len(string):
321321
endpos = len(string)
322-
elif endpos < 0:
322+
elif endpos < 0 and len(string) > 0:
323323
endpos = endpos % len(string) + 1
324324
matchlist = []
325325
while pos < endpos:

0 commit comments

Comments
 (0)