Skip to content

Commit 88f5c2c

Browse files
committed
struct access to PyDateTime_CAPI
1 parent 63c3028 commit 88f5c2c

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
#include "pythread.h"
120120
#include "funcobject.h"
121121
#include "iterobject.h"
122+
#include "datetime.h"
122123

123124
#define PY_TRUFFLE_CEXT ((void*)polyglot_import("python_cext"))
124125
#define PY_BUILTIN ((void*)polyglot_import("python_builtins"))
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "capi.h"
2+
3+
POLYGLOT_DECLARE_TYPE(PyDateTime_CAPI);
4+
5+
/** to be used from Java code only; returns the type ID for a PyDateTime_CAPI */
6+
extern PyObject* set_PyDateTime_CAPI_typeid(PyTypeObject* type) {
7+
polyglot_invoke(PY_TRUFFLE_CEXT, "PyTruffle_Set_SulongType", type, polyglot_PyDateTime_CAPI_typeid());
8+
return Py_True;
9+
}
10+

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,17 @@ Object doMemoryview(PMemoryView object, String key,
481481
throw new IllegalStateException("delegate of memoryview object is not native");
482482
}
483483

484+
protected static boolean isPyDateTimeCAPI(PythonObject object) {
485+
return object.getPythonClass().getName().equals("PyDateTime_CAPI");
486+
}
487+
488+
@Specialization(guards = "isPyDateTimeCAPI(object)")
489+
Object doDatetimeCAPI(PythonObject object, String key,
490+
@Cached("create()") GetClassNode getClass,
491+
@Cached("create()") LookupAttributeInMRONode.Dynamic getAttrNode) {
492+
return getToSulongNode().execute(getAttrNode.execute(getClass.execute(object), key));
493+
}
494+
484495
@Fallback
485496
Object doGeneric(Object object, String key) {
486497
// This is the preliminary generic case: There are native members we know that they

graalpython/lib-graalpython/python_cext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,7 @@ def DateTime_FromDateAndTimeAndFold(y, mon, d, h, m, s, usec, tz, fold, typ):
11961196
def Time_FromTimeAndFold(h, m, s, us, tz, fold, typ):
11971197
return typ(hour=h, minute=m, second=s, microsecond=us, tzinfo=tz, fold=fold)
11981198

1199+
import_c_func("set_PyDateTime_CAPI_typeid")(PyDateTime_CAPI)
11991200
datetime.datetime_CAPI = PyCapsule("datetime.datetime_CAPI", PyDateTime_CAPI(), None)
12001201

12011202

0 commit comments

Comments
 (0)