Skip to content

Commit ae49ea0

Browse files
committed
Merge remote-tracking branch 'origin/master' into tim/sklearn-linreg
2 parents 32ca115 + aaf95f1 commit ae49ea0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2766
-669
lines changed

graalpython/com.oracle.graal.python.cext/src/object.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ static PyObject* wrap_ssizeobjargproc(ssizeobjargproc f, PyObject* a, PyObject*
197197
return PyLong_FromLong(f(explicit_cast(a), PyLong_AsSsize_t(size), explicit_cast(b)));
198198
}
199199

200+
static PyObject* wrap_initproc(initproc f, PyObject* a, PyObject* b, PyObject* c) {
201+
return PyLong_FromLong(f(explicit_cast(a), explicit_cast(b), explicit_cast(c)));
202+
}
203+
200204
/* very special case: operator '**' has an optional third arg */
201205
static PyObject* wrap_pow(ternaryfunc f, ...) {
202206
int nargs = polyglot_get_arg_count();
@@ -382,7 +386,7 @@ int PyType_Ready(PyTypeObject* cls) {
382386
ADD_SLOT("__next__", cls->tp_iternext, -1);
383387
ADD_SLOT("__get__", cls->tp_descr_get, -3);
384388
ADD_SLOT("__set__", cls->tp_descr_set, -3);
385-
ADD_SLOT("__init__", cls->tp_init, METH_KEYWORDS | METH_VARARGS);
389+
ADD_SLOT_CONV("__init__", wrap_initproc, cls->tp_init, METH_KEYWORDS | METH_VARARGS);
386390
ADD_SLOT_CONV("__alloc__", wrap_allocfunc, cls->tp_alloc, -2);
387391
ADD_SLOT("__new__", cls->tp_new, METH_KEYWORDS | METH_VARARGS);
388392
ADD_SLOT("__free__", cls->tp_free, -1);
@@ -613,7 +617,11 @@ int PyObject_Print(PyObject* object, FILE* fd, int flags) {
613617
}
614618

615619
PyObject* PyObject_GetAttrString(PyObject* obj, const char* attr) {
616-
return PyObject_GetAttr(obj, PyUnicode_FromString(attr));
620+
void* result = polyglot_invoke(PY_TRUFFLE_CEXT, "PyObject_GetAttr", to_java(obj), polyglot_from_string(attr, "utf-8"));
621+
if (result == ERROR_MARKER) {
622+
return NULL;
623+
}
624+
return to_sulong(result);
617625
}
618626

619627
int PyObject_SetAttrString(PyObject* obj, const char* attr, PyObject* value) {

graalpython/com.oracle.graal.python.cext/src/unicodeobject.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ PyObject* PyTruffle_Unicode_FromFormat(const char* fmt, int s, void* v0, void* v
7474
case 7: v7 = value; break; \
7575
case 8: v8 = value; break; \
7676
case 9: v9 = value; break; \
77+
case 10: v10 = value; break; \
78+
case 11: v11 = value; break; \
79+
case 12: v12 = value; break; \
80+
case 13: v13 = value; break; \
81+
case 14: v14 = value; break; \
82+
case 15: v15 = value; break; \
83+
case 16: v16 = value; break; \
84+
case 17: v17 = value; break; \
85+
case 18: v18 = value; break; \
86+
case 19: v19 = value; break; \
7787
}
7888

7989
char* fmtcpy = strdup(fmt);

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_unicode.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
# SOFTWARE.
3737

3838
import sys
39-
import warnings
40-
from . import CPyExtTestCase, CPyExtFunction, CPyExtFunctionVoid, unhandled_error_compare, GRAALPYTHON
39+
40+
from . import CPyExtTestCase, CPyExtFunction, unhandled_error_compare, GRAALPYTHON
41+
4142
__dir__ = __file__.rpartition("/")[0]
4243

4344

@@ -326,7 +327,6 @@ def compile_module(self, name):
326327
cmpfunc=unhandled_error_compare
327328
)
328329

329-
# TODO enable once supported
330330
test_PyUnicode_GET_SIZE = CPyExtFunction(
331331
lambda args: len(args[0]),
332332
lambda: (
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright (c) 2018, Oracle and/or its affiliates.
2+
#
3+
# The Universal Permissive License (UPL), Version 1.0
4+
#
5+
# Subject to the condition set forth below, permission is hereby granted to any
6+
# person obtaining a copy of this software, associated documentation and/or data
7+
# (collectively the "Software"), free of charge and under any and all copyright
8+
# rights in the Software, and any and all patent rights owned or freely
9+
# licensable by each licensor hereunder covering either (i) the unmodified
10+
# Software as contributed to or provided by such licensor, or (ii) the Larger
11+
# Works (as defined below), to deal in both
12+
#
13+
# (a) the Software, and
14+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
# one is included with the Software (each a "Larger Work" to which the
16+
# Software is contributed by such licensors),
17+
#
18+
# without restriction, including without limitation the rights to copy, create
19+
# derivative works of, display, perform, and distribute the Software and make,
20+
# use, sell, offer for sale, import, export, have made, and have sold the
21+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
# either these or other terms.
23+
#
24+
# This license is subject to the following condition:
25+
#
26+
# The above copyright notice and either this complete permission notice or at a
27+
# minimum a reference to the UPL must be included in all copies or substantial
28+
# portions of the Software.
29+
#
30+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
# SOFTWARE.
37+
38+
39+
def assert_raises(err, fn, *args, **kwargs):
40+
raised = False
41+
try:
42+
fn(*args, **kwargs)
43+
except err:
44+
raised = True
45+
assert raised
46+
47+
48+
def test_import():
49+
imported = True
50+
try:
51+
import array
52+
except ImportError:
53+
imported = False
54+
assert imported
55+
56+
57+
def test_create():
58+
from array import array
59+
a = array('b', b'x'*10)
60+
assert str(a) == "array('b', [120, 120, 120, 120, 120, 120, 120, 120, 120, 120])"

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

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,90 @@ def test_rfind():
347347
assert b"hello".rfind(b"x") == -1, "4"
348348
assert b"hello".rfind(b"ll") == 2, "3"
349349

350+
351+
def test_extend():
352+
orig = b'hello'
353+
a = bytearray(orig)
354+
a.extend(a)
355+
356+
assert a == orig + orig
357+
assert a[5:] == orig
358+
359+
a = bytearray(b'')
360+
# Test iterators that don't have a __length_hint__
361+
a.extend(map(int, orig * 25))
362+
a.extend(int(x) for x in orig * 25)
363+
assert a == orig * 50
364+
assert a[-5:] == orig
365+
366+
a = bytearray(b'')
367+
a.extend(iter(map(int, orig * 50)))
368+
assert a == orig * 50
369+
assert a[-5:] == orig
370+
371+
a = bytearray(b'')
372+
a.extend(list(map(int, orig * 50)))
373+
assert a == orig * 50
374+
assert a[-5:] == orig
375+
376+
a = bytearray(b'')
377+
assert_raises(ValueError, a.extend, [0, 1, 2, 256])
378+
assert_raises(ValueError, a.extend, [0, 1, 2, -1])
379+
assert len(a) == 0
380+
381+
382+
def test_startswith():
383+
b = b'hello'
384+
assert not b.startswith(b"anything")
385+
assert b.startswith(b"hello")
386+
assert b.startswith(b"hel")
387+
assert b.startswith(b"h")
388+
assert not b.startswith(b"hellow")
389+
assert not b.startswith(b"ha")
390+
391+
b = bytearray(b'hello')
392+
assert not b.startswith(b"anything")
393+
assert b.startswith(b"hello")
394+
assert b.startswith(b"hel")
395+
assert b.startswith(b"h")
396+
assert not b.startswith(b"hellow")
397+
assert not b.startswith(b"ha")
398+
399+
400+
def test_endswith():
401+
b = b'hello'
402+
assert not b.endswith(b"anything")
403+
assert b.endswith(b"hello")
404+
assert b.endswith(b"llo")
405+
assert b.endswith(b"o")
406+
assert not b.endswith(b"whello")
407+
assert not b.endswith(b"no")
408+
409+
b = bytearray(b'hello')
410+
assert not b.endswith(b"anything")
411+
assert b.endswith(b"hello")
412+
assert b.endswith(b"llo")
413+
assert b.endswith(b"o")
414+
assert not b.endswith(b"whello")
415+
assert not b.endswith(b"no")
416+
417+
418+
def test_find():
419+
b = b'mississippi'
420+
i = 105
421+
w = 119
422+
423+
assert b.find(b'ss') == 2
424+
assert b.find(b'w') == -1
425+
assert b.find(b'mississippian') == -1
426+
427+
assert b.find(i) == 1
428+
assert b.find(w) == -1
429+
430+
assert b.find(b'ss', 3) == 5
431+
assert b.find(b'ss', 1, 7) == 2
432+
assert b.find(b'ss', 1, 3) == -1
433+
434+
assert b.find(i, 6) == 7
435+
assert b.find(i, 1, 3) == 1
436+
assert b.find(w, 1, 3) == -1

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Copyright (C) 1996-2017 Python Software Foundation
33
#
44
# Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
5+
6+
57
def assert_raises(err, fn, *args, **kwargs):
68
raised = False
79
try:
@@ -12,7 +14,12 @@ def assert_raises(err, fn, *args, **kwargs):
1214

1315

1416
def test_import():
15-
import codecs
17+
imported = True
18+
try:
19+
import codecs
20+
except ImportError:
21+
imported = False
22+
assert imported
1623

1724

1825
def test_decode():
@@ -21,9 +28,9 @@ def test_decode():
2128
# TODO: this does not work yet due to the fact that we do not handle all strings literal types yet
2229
# assert codecs.decode(b'\xe4\xf6\xfc', 'latin-1') == '\xe4\xf6\xfc'
2330
# assert_raises(TypeError, codecs.decode)
24-
# assert codecs.decode(b'abc') == 'abc'
31+
assert codecs.decode(b'abc') == 'abc'
2532
# assert_raises(UnicodeDecodeError, codecs.decode, b'\xff', 'ascii')
26-
#
33+
2734
# test keywords
2835
# assert codecs.decode(obj=b'\xe4\xf6\xfc', encoding='latin-1') == '\xe4\xf6\xfc'
2936
# assert codecs.decode(b'[\xff]', 'ascii', errors='ignore') == '[]'
@@ -36,7 +43,7 @@ def test_encode():
3643
# TODO: this does not work yet due to the fact that we do not handle all strings literal types yet
3744
# assert codecs.encode('\xe4\xf6\xfc', 'latin-1') == b'\xe4\xf6\xfc'
3845
# assert_raises(TypeError, codecs.encode)
39-
# assert_raises(LookupError, codecs.encode, "foo", "__spam__")
46+
assert_raises(LookupError, codecs.encode, "foo", "__spam__")
4047
# assert codecs.encode('abc') == b'abc'
4148
# assert_raises(UnicodeEncodeError, codecs.encode, '\xffff', 'ascii')
4249

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ def assert_raises(err, fn, *args, **kwargs):
4545

4646

4747
def test_import():
48-
import collections
49-
from collections import namedtuple, Counter, OrderedDict, _count_elements
50-
from collections import UserDict, UserString, UserList
51-
from collections import ChainMap
52-
# from collections import deque
48+
imported = True
49+
try:
50+
import collections
51+
from collections import namedtuple, Counter, OrderedDict, _count_elements
52+
from collections import UserDict, UserString, UserList
53+
from collections import ChainMap
54+
# from collections import deque
55+
except ImportError:
56+
imported = False
57+
assert imported

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,3 +575,74 @@ def fromhex(cls, value1, value2):
575575
f = F.fromhex('1', '1')
576576
self.assertEqual(17.0, f)
577577
self.assertEqual(F, type(f))
578+
579+
class MyFloat(float):
580+
pass
581+
582+
class RealImagConjugateTests(unittest.TestCase):
583+
584+
def test_real_imag(self):
585+
def builtinTest(number):
586+
a = float(number)
587+
b = a.real
588+
c = a.imag
589+
assert a == b
590+
assert a is b
591+
assert c == 0
592+
assert type(a) == float
593+
assert type(b) == float
594+
assert type(c) == float
595+
596+
builtinTest(-9.1)
597+
builtinTest(0.0)
598+
builtinTest(9.2)
599+
builtinTest(6227020800.90)
600+
builtinTest(9999992432902008176640000999999.1)
601+
602+
def test_real_imag_subclass(self):
603+
def subclassTest(number):
604+
a = MyFloat(number)
605+
b = a.real
606+
c = a.imag
607+
assert a == b
608+
assert a is not b
609+
assert c == 0.0
610+
assert type(a) == MyFloat
611+
assert type(b) == float
612+
assert type(c) == float
613+
614+
subclassTest(-9.0)
615+
subclassTest(0.0)
616+
subclassTest(9.1)
617+
subclassTest(6227020800.2)
618+
subclassTest(9999992432902008176640000999999.33)
619+
620+
def test_conjugate(self):
621+
def builtinTest(number):
622+
a = float(number)
623+
b = a.conjugate()
624+
assert a == b
625+
assert a is b
626+
assert type(a) == float
627+
assert type(b) == float
628+
629+
builtinTest(-9.1)
630+
builtinTest(0.0)
631+
builtinTest(9.2)
632+
builtinTest(6227020800.90)
633+
builtinTest(9999992432902008176640000999999.1)
634+
635+
def test_conjugate_subclass(self):
636+
def subclassTest(number):
637+
a = MyFloat(number)
638+
b = a.conjugate()
639+
assert a == b
640+
assert a is not b
641+
assert type(a) == MyFloat
642+
assert type(b) == float
643+
644+
subclassTest(-9.0)
645+
subclassTest(0.0)
646+
subclassTest(9.1)
647+
subclassTest(6227020800.2)
648+
subclassTest(9999992432902008176640000999999.33)

0 commit comments

Comments
 (0)