File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed
com.oracle.graal.python.test/src/tests/cpyext
com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -326,13 +326,13 @@ def test_float_subclass(self):
326
326
TestFloatSubclass = CPyExtType ("TestFloatSubclass" ,
327
327
"""
328
328
static PyTypeObject* testFloatSubclassPtr = NULL;
329
-
329
+
330
330
static PyObject* new_fp(double val) {
331
331
PyFloatObject* fp = PyObject_New(PyFloatObject, testFloatSubclassPtr);
332
332
fp->ob_fval = val;
333
333
return (PyObject*)fp;
334
334
}
335
-
335
+
336
336
static PyObject* fp_tpnew(PyTypeObject* type, PyObject* args, PyObject* kwargs) {
337
337
double dval = 0.0;
338
338
Py_XINCREF(args);
@@ -341,7 +341,7 @@ def test_float_subclass(self):
341
341
}}
342
342
return new_fp(dval);
343
343
}
344
-
344
+
345
345
static PyObject* fp_add(PyObject* l, PyObject* r) {
346
346
if (PyFloat_Check(l)) {
347
347
if (PyFloat_Check(r)) {
@@ -360,15 +360,16 @@ def test_float_subclass(self):
360
360
}
361
361
""" ,
362
362
cmembers = "PyFloatObject base;" ,
363
- tp_base = "&PyFloat_Type" ,
363
+ tp_base = "&PyFloat_Type" ,
364
364
nb_add = "fp_add" ,
365
365
tp_new = "fp_tpnew" ,
366
366
post_ready_code = "testFloatSubclassPtr = &TestFloatSubclassType; Py_INCREF(testFloatSubclassPtr);"
367
367
)
368
368
tester = TestFloatSubclass (41.0 )
369
369
res = tester + 1
370
370
assert res == 42.0 , "expected 42.0 but was %s" % res
371
-
371
+ assert hash (tester ) != 0
372
+
372
373
def test_custom_basicsize (self ):
373
374
TestCustomBasicsize = CPyExtType ("TestCustomBasicsize" ,
374
375
'''
Original file line number Diff line number Diff line change 109
109
import com .oracle .graal .python .runtime .formatting .InternalFormat .Spec ;
110
110
import com .oracle .truffle .api .CompilerDirectives ;
111
111
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
112
+ import com .oracle .truffle .api .dsl .Bind ;
112
113
import com .oracle .truffle .api .dsl .Cached ;
113
114
import com .oracle .truffle .api .dsl .Cached .Shared ;
114
115
import com .oracle .truffle .api .dsl .Fallback ;
@@ -654,9 +655,16 @@ protected static boolean accepts(Object obj) {
654
655
@ TypeSystemReference (PythonArithmeticTypes .class )
655
656
abstract static class HashNode extends PythonUnaryBuiltinNode {
656
657
@ Specialization
657
- static long hashDouble (double self ) {
658
+ static long doDouble (double self ) {
658
659
return PyObjectHashNode .hash (self );
659
660
}
661
+
662
+ @ Specialization (guards = "dval != null" )
663
+ static long doNativeFloat (@ SuppressWarnings ("unused" ) VirtualFrame frame , @ SuppressWarnings ("unused" ) PythonNativeObject object ,
664
+ @ SuppressWarnings ("unused" ) @ Cached FromNativeSubclassNode getFloat ,
665
+ @ Bind ("getFloat.execute(frame, object)" ) Double dval ) {
666
+ return PyObjectHashNode .hash (dval );
667
+ }
660
668
}
661
669
662
670
@ Builtin (name = "fromhex" , minNumOfPositionalArgs = 2 , isClassmethod = true )
You can’t perform that action at this time.
0 commit comments