Skip to content

Commit d2928a7

Browse files
committed
[GR-34916] Intrinsify python_cext - datetime capi.
PullRequest: graalpython/2135
2 parents acd6c60 + 81c5380 commit d2928a7

File tree

15 files changed

+844
-224
lines changed

15 files changed

+844
-224
lines changed

graalpython/com.oracle.graal.python.cext/include/Python.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -136,7 +136,6 @@
136136
#include "pythread.h"
137137
#include "funcobject.h"
138138
#include "iterobject.h"
139-
#include "datetime.h"
140139
#include "typeslots.h"
141140
#include "weakrefobject.h"
142141
#include "sysmodule.h"

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -49,6 +49,7 @@
4949
#include "Python.h"
5050
#include <truffle.h>
5151
#include <graalvm/llvm/handles.h>
52+
#include "datetime.h"
5253

5354
#define SRC_CS "utf-8"
5455

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -70,9 +70,7 @@ POLYGLOT_DECLARE_TYPE(PyDateTime_Delta);
7070
POLYGLOT_DECLARE_TYPE(PyDateTime_TZInfo);
7171

7272
/** to be used from Java code only; returns the type ID for a PyDateTime_CAPI */
73-
extern PyObject* set_PyDateTime_typeids(PyTypeObject* dtcapiType, PyTypeObject* dateType, PyTypeObject* dateTimeType, PyTypeObject* timeType, PyTypeObject* deltaType, PyTypeObject* tzinfoType) {
74-
polyglot_invoke(PY_TRUFFLE_CEXT, "PyTruffle_Set_SulongType", dtcapiType, polyglot_PyDateTime_CAPI_typeid());
75-
73+
extern polyglot_typeid set_PyDateTime_typeids(PyTypeObject* dateType, PyTypeObject* dateTimeType, PyTypeObject* timeType, PyTypeObject* deltaType, PyTypeObject* tzinfoType) {
7674
/* safe native get/set descriptors */
7775
PyGetSetDef* getsets_date= PyDateTime_DateType.tp_getset;
7876
PyGetSetDef* getsets_time = PyDateTime_TimeType.tp_getset;
@@ -91,7 +89,7 @@ extern PyObject* set_PyDateTime_typeids(PyTypeObject* dtcapiType, PyTypeObject*
9189
register_native_slots(&PyDateTime_TimeType, getsets_time, NULL);
9290
register_native_slots(&PyDateTime_DeltaType, NULL, members_delta);
9391

94-
return Py_True;
92+
return polyglot_PyDateTime_CAPI_typeid();
9593
}
9694

9795
BASICSIZE_GETTER(PyDateTime_Date);

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

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,50 @@ def test_sequence_size(self):
421421
tester = TestSequenceSize()
422422
assert tester.callSize(tester) == 10
423423

424+
def test_sequence_size_err(self):
425+
TestSequenceSizeErr = CPyExtType("TestSequenceSizeErr",
426+
"""
427+
Py_ssize_t test_sq_length(PyObject* a) {
428+
PyErr_Format(PyExc_TypeError, "test type error");
429+
return -1;
430+
}
431+
PyObject* callSize(PyObject* a) {
432+
return PyLong_FromSsize_t(PySequence_Size(a));
433+
}
434+
""",
435+
tp_methods='{"callSize", (PyCFunction)callSize, METH_O, ""}',
436+
sq_length="&test_sq_length",
437+
)
438+
tester = TestSequenceSizeErr()
439+
try:
440+
tester.callSize(tester)
441+
except SystemError:
442+
assert True
443+
else:
444+
assert False
445+
446+
def test_sequence_size_err2(self):
447+
TestSequenceSizeErr2 = CPyExtType("TestSequenceSizeErr2",
448+
"""
449+
Py_ssize_t test_sq_length(PyObject* a) {
450+
PyErr_Format(PyExc_TypeError, "test type error");
451+
return -2;
452+
}
453+
PyObject* callSize(PyObject* a) {
454+
return PyLong_FromSsize_t(PySequence_Size(a));
455+
}
456+
""",
457+
tp_methods='{"callSize", (PyCFunction)callSize, METH_O, ""}',
458+
sq_length="&test_sq_length",
459+
)
460+
tester = TestSequenceSizeErr2()
461+
try:
462+
tester.callSize(tester)
463+
except SystemError:
464+
assert True
465+
else:
466+
assert False
467+
424468
def test_mapping_check(self):
425469
TestMappingCheck = CPyExtType("TestMappingCheck",
426470
"""
@@ -454,6 +498,28 @@ def test_mapping_size(self):
454498
tester = TestMappingSize()
455499
assert tester.callSize(tester) == 11
456500

501+
def test_mapping_size_err(self):
502+
TestMappingSizeErr = CPyExtType("TestMappingSizeErr",
503+
"""
504+
Py_ssize_t test_mp_length(PyObject* a) {
505+
PyErr_Format(PyExc_TypeError, "test type error");
506+
return -1;
507+
}
508+
PyObject* callSize(PyObject* a) {
509+
return PyLong_FromSsize_t(PyMapping_Size(a));
510+
}
511+
""",
512+
tp_methods='{"callSize", (PyCFunction)callSize, METH_O, ""}',
513+
mp_length="&test_mp_length",
514+
)
515+
tester = TestMappingSizeErr()
516+
try:
517+
tester.callSize(tester)
518+
except SystemError:
519+
assert True
520+
else:
521+
assert False
522+
457523
def test_object_size_sq(self):
458524
TestObjectSizeSQ = CPyExtType("TestObjectSizeSQ",
459525
"""
@@ -486,6 +552,28 @@ def test_object_size_mp(self):
486552
tester = TestObjectSizeMP()
487553
assert tester.callSize(tester) == 13
488554

555+
def test_object_size_err(self):
556+
TestObjectSizeErr = CPyExtType("TestObjectSizeErr",
557+
"""
558+
Py_ssize_t test_sq_length(PyObject* a) {
559+
PyErr_Format(PyExc_TypeError, "test type error");
560+
return -1;
561+
}
562+
PyObject* callSize(PyObject* a) {
563+
return PyLong_FromSsize_t(PyObject_Size(a));
564+
}
565+
""",
566+
tp_methods='{"callSize", (PyCFunction)callSize, METH_O, ""}',
567+
mp_length="&test_sq_length",
568+
)
569+
tester = TestObjectSizeErr()
570+
try:
571+
tester.callSize(tester)
572+
except SystemError:
573+
assert True
574+
else:
575+
assert False
576+
489577
class TestAbstract(CPyExtTestCase):
490578

491579
def compile_module(self, name):

0 commit comments

Comments
 (0)