Skip to content

Commit 6675034

Browse files
committed
[GR-16858] Support Numpy 1.16.4
PullRequest: graalpython/575
2 parents 2cfd11e + ef931cd commit 6675034

File tree

12 files changed

+856
-251
lines changed

12 files changed

+856
-251
lines changed

graalpython/com.oracle.graal.python.cext/src/capi.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,6 @@ extern PyObject* wrapped_null;
327327

328328
/* internal functions to avoid unnecessary managed <-> native conversions */
329329

330-
/* DICT */
331-
void* PyTruffle_Tuple_GetItem(void* jtuple, Py_ssize_t position);
332-
333330
/* STR */
334331
PyObject* PyTruffle_Unicode_FromFormat(const char*, va_list, void**, int);
335332

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ int PyTruffle_Tuple_SetItem(PyObject* tuple, Py_ssize_t position, PyObject* item
130130
return 0;
131131
}
132132

133+
PyObject* PyTruffle_Tuple_GetItem(PyObject* tuple, Py_ssize_t position) {
134+
return native_to_java(PyTuple_GET_ITEM(tuple, position));
135+
}
136+
133137
PyObject* PyTruffle_Tuple_Alloc(PyTypeObject* cls, Py_ssize_t nitems) {
134138
/*
135139
* TODO(fa): For 'PyVarObjects' (i.e. 'nitems > 0') we increase the size by 'sizeof(void *)'

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
import com.oracle.truffle.api.Truffle;
181181
import com.oracle.truffle.api.debug.Debugger;
182182
import com.oracle.truffle.api.dsl.Cached;
183+
import com.oracle.truffle.api.dsl.Cached.Shared;
183184
import com.oracle.truffle.api.dsl.Fallback;
184185
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
185186
import com.oracle.truffle.api.dsl.ImportStatic;
@@ -1331,20 +1332,22 @@ Object minmaxSequenceWithKey(VirtualFrame frame, PythonObject arg1, @SuppressWar
13311332
@Specialization(guards = "args.length != 0")
13321333
Object minmaxBinary(VirtualFrame frame, Object arg1, Object[] args, @SuppressWarnings("unused") PNone keywordArg,
13331334
@Cached("createComparison()") BinaryComparisonNode compare,
1334-
@Cached("createBinaryProfile()") ConditionProfile moreThanTwo) {
1335-
return minmaxBinaryWithKey(frame, arg1, args, null, compare, null, moreThanTwo);
1335+
@Cached("createBinaryProfile()") ConditionProfile moreThanTwo,
1336+
@Shared("castToBooleanNode") @Cached("createIfTrueNode()") CastToBooleanNode castToBooleanNode) {
1337+
return minmaxBinaryWithKey(frame, arg1, args, null, compare, null, moreThanTwo, castToBooleanNode);
13361338
}
13371339

13381340
@Specialization(guards = "args.length != 0")
13391341
Object minmaxBinaryWithKey(VirtualFrame frame, Object arg1, Object[] args, PythonObject keywordArg,
13401342
@Cached("createComparison()") BinaryComparisonNode compare,
1341-
@Cached("create()") CallNode keyCall,
1342-
@Cached("createBinaryProfile()") ConditionProfile moreThanTwo) {
1343+
@Cached CallNode keyCall,
1344+
@Cached("createBinaryProfile()") ConditionProfile moreThanTwo,
1345+
@Shared("castToBooleanNode") @Cached("createIfTrueNode()") CastToBooleanNode castToBooleanNode) {
13431346
Object currentValue = arg1;
13441347
Object currentKey = applyKeyFunction(frame, keywordArg, keyCall, currentValue);
13451348
Object nextValue = args[0];
13461349
Object nextKey = applyKeyFunction(frame, keywordArg, keyCall, nextValue);
1347-
if (compare.executeBool(frame, nextKey, currentKey)) {
1350+
if (castToBooleanNode.executeBoolean(frame, compare.executeWith(frame, nextKey, currentKey))) {
13481351
currentKey = nextKey;
13491352
currentValue = nextValue;
13501353
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/NativeCAPISymbols.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public abstract class NativeCAPISymbols {
8383
public static final String FUN_GET_THREAD_STATE_TYPE_ID = "get_thread_state_typeid";
8484
public static final String FUN_ADD_NATIVE_SLOTS = "PyTruffle_Type_AddSlots";
8585
public static final String FUN_PY_TRUFFLE_TUPLE_SET_ITEM = "PyTruffle_Tuple_SetItem";
86+
public static final String FUN_PY_TRUFFLE_TUPLE_GET_ITEM = "PyTruffle_Tuple_GetItem";
8687
public static final String FUN_PY_TRUFFLE_OBJECT_SIZE = "PyTruffle_Object_Size";
8788

8889
@CompilationFinal(dimensions = 1) private static final String[] values;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/PyNumberMethodsWrapper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
@ImportStatic(SpecialMethodNames.class)
8989
public class PyNumberMethodsWrapper extends PythonNativeWrapper {
9090

91-
// TODO extend list according to 'isValidMember'
9291
private static final String[] NUMBER_METHODS = new String[]{
9392
NB_ADD,
9493
NB_SUBTRACT,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/PySequenceArrayWrapper.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import com.oracle.graal.python.runtime.sequence.storage.NativeSequenceStorage;
7070
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
7171
import com.oracle.truffle.api.Assumption;
72+
import com.oracle.truffle.api.CompilerAsserts;
7273
import com.oracle.truffle.api.CompilerDirectives;
7374
import com.oracle.truffle.api.dsl.Cached;
7475
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -107,6 +108,29 @@ public int getElementAccessSize() {
107108
return elementAccessSize;
108109
}
109110

111+
@Override
112+
public int hashCode() {
113+
CompilerAsserts.neverPartOfCompilation();
114+
final int prime = 31;
115+
int result = 1;
116+
result = prime * result + getDelegate().hashCode();
117+
return result;
118+
}
119+
120+
@Override
121+
public boolean equals(Object obj) {
122+
if (this == obj) {
123+
return true;
124+
}
125+
if (obj == null) {
126+
return false;
127+
}
128+
if (getClass() != obj.getClass()) {
129+
return false;
130+
}
131+
return getDelegate() == ((PySequenceArrayWrapper) obj).getDelegate();
132+
}
133+
110134
@ExportMessage
111135
final long getArraySize(
112136
@Shared("callLenNode") @Cached LookupAndCallUnaryDynamicNode callLenNode,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public Object get(SuperObject self, Object obj, @SuppressWarnings("unused") Obje
403403
@Builtin(name = SpecialMethodNames.__GETATTRIBUTE__, minNumOfPositionalArgs = 2)
404404
@GenerateNodeFactory
405405
public abstract static class GetattributeNode extends PythonBinaryBuiltinNode {
406-
@Child private ReadAttributeFromObjectNode readFromDict = ReadAttributeFromObjectNode.create();
406+
@Child private ReadAttributeFromObjectNode readFromDict = ReadAttributeFromObjectNode.createForceType();
407407
@Child private LookupInheritedAttributeNode readGet = LookupInheritedAttributeNode.create(SpecialMethodNames.__GET__);
408408
@Child private GetObjectTypeNode getObjectType = GetObjectTypeNodeGen.create();
409409
@Child private GetTypeNode getType;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/PTuple.java

Lines changed: 1 addition & 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) 2013, Regents of the University of California
44
*
55
* All rights reserved.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,17 +370,25 @@ public abstract static class GetItemNode extends PythonBinaryBuiltinNode {
370370
public abstract Object execute(PTuple tuple, Object index);
371371

372372
@Specialization(guards = "!isPSlice(key)")
373-
public Object doPTuple(PTuple tuple, Object key,
373+
Object doPTuple(PTuple tuple, Object key,
374374
@Cached("createGetItemNode()") SequenceStorageNodes.GetItemNode getItemNode) {
375375
return getItemNode.execute(tuple.getSequenceStorage(), key);
376376
}
377377

378378
@Specialization
379-
public Object doPTuple(PTuple tuple, PSlice key,
379+
Object doPTuple(PTuple tuple, PSlice key,
380380
@Cached("createGetItemNode()") SequenceStorageNodes.GetItemNode getItemNode) {
381381
return getItemNode.execute(tuple.getSequenceStorage(), key);
382382
}
383383

384+
@Specialization
385+
Object doNative(PythonNativeObject tuple, long key,
386+
@Cached PCallCapiFunction callSetItem,
387+
@Cached CExtNodes.ToSulongNode toSulongNode,
388+
@Cached CExtNodes.AsPythonObjectNode asPythonObjectNode) {
389+
return asPythonObjectNode.execute(callSetItem.call(NativeCAPISymbols.FUN_PY_TRUFFLE_TUPLE_GET_ITEM, toSulongNode.execute(tuple), key));
390+
}
391+
384392
protected static SequenceStorageNodes.GetItemNode createGetItemNode() {
385393
return SequenceStorageNodes.GetItemNode.create(NormalizeIndexNode.forTuple(), TYPE_ERROR_MESSAGE, (s, f) -> f.createTuple(s));
386394
}

graalpython/lib-graalpython/_collections.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# coding=utf-8
2-
# Copyright (c) 2018, Oracle and/or its affiliates.
2+
# Copyright (c) 2018, 2019, Oracle and/or its affiliates.
33
# Copyright (c) 2017, The PyPy Project
44
#
55
# The MIT License
@@ -627,3 +627,6 @@ def __missing__(self, key):
627627
raise KeyError((key,))
628628
self[key] = value = self.default_factory()
629629
return value
630+
631+
def __repr__(self):
632+
return "%s(%r, %s)" % (type(self).__name__, self.default_factory, dict.__repr__(self))

0 commit comments

Comments
 (0)