Skip to content

Commit 08dfee5

Browse files
committed
[GR-9785] Fix remaining NumPy/multiarray compilation errors.
PullRequest: graalpython-open/43
2 parents 3ca1c8a + 94464e1 commit 08dfee5

File tree

17 files changed

+742
-16
lines changed

17 files changed

+742
-16
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
#define HAVE_FCNTL_H
4646
#define HAVE_SYS_WAIT_H
4747

48+
#define PYPY_VERSION 0
49+
4850
#include <truffle.h>
4951
#include <polyglot.h>
5052
#include <stdio.h>
@@ -102,6 +104,8 @@
102104
#include "pylifecycle.h"
103105
#include "pydebug.h"
104106
#include "code.h"
107+
#include "pyfpe.h"
108+
#include "memoryobject.h"
105109

106110
#undef Py_NoValue
107111
#define Py_NoValue truffle_invoke(PY_TRUFFLE_CEXT, "Py_NoValue")
Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
/* Copyright (c) 2018, Oracle and/or its affiliates.
2+
* Copyright (C) 1996-2017 Python Software Foundation
3+
*
4+
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
5+
*/
6+
/* datetime.h
7+
*/
8+
#ifndef Py_LIMITED_API
9+
#ifndef DATETIME_H
10+
#define DATETIME_H
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
/* Fields are packed into successive bytes, each viewed as unsigned and
16+
* big-endian, unless otherwise noted:
17+
*
18+
* byte offset
19+
* 0 year 2 bytes, 1-9999
20+
* 2 month 1 byte, 1-12
21+
* 3 day 1 byte, 1-31
22+
* 4 hour 1 byte, 0-23
23+
* 5 minute 1 byte, 0-59
24+
* 6 second 1 byte, 0-59
25+
* 7 usecond 3 bytes, 0-999999
26+
* 10
27+
*/
28+
29+
/* # of bytes for year, month, and day. */
30+
#define _PyDateTime_DATE_DATASIZE 4
31+
32+
/* # of bytes for hour, minute, second, and usecond. */
33+
#define _PyDateTime_TIME_DATASIZE 6
34+
35+
/* # of bytes for year, month, day, hour, minute, second, and usecond. */
36+
#define _PyDateTime_DATETIME_DATASIZE 10
37+
38+
39+
typedef struct
40+
{
41+
PyObject_HEAD
42+
Py_hash_t hashcode; /* -1 when unknown */
43+
int days; /* -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS */
44+
int seconds; /* 0 <= seconds < 24*3600 is invariant */
45+
int microseconds; /* 0 <= microseconds < 1000000 is invariant */
46+
} PyDateTime_Delta;
47+
48+
typedef struct
49+
{
50+
PyObject_HEAD /* a pure abstract base class */
51+
} PyDateTime_TZInfo;
52+
53+
54+
/* The datetime and time types have hashcodes, and an optional tzinfo member,
55+
* present if and only if hastzinfo is true.
56+
*/
57+
#define _PyTZINFO_HEAD \
58+
PyObject_HEAD \
59+
Py_hash_t hashcode; \
60+
char hastzinfo; /* boolean flag */
61+
62+
/* No _PyDateTime_BaseTZInfo is allocated; it's just to have something
63+
* convenient to cast to, when getting at the hastzinfo member of objects
64+
* starting with _PyTZINFO_HEAD.
65+
*/
66+
typedef struct
67+
{
68+
_PyTZINFO_HEAD
69+
} _PyDateTime_BaseTZInfo;
70+
71+
/* All time objects are of PyDateTime_TimeType, but that can be allocated
72+
* in two ways, with or without a tzinfo member. Without is the same as
73+
* tzinfo == None, but consumes less memory. _PyDateTime_BaseTime is an
74+
* internal struct used to allocate the right amount of space for the
75+
* "without" case.
76+
*/
77+
#define _PyDateTime_TIMEHEAD \
78+
_PyTZINFO_HEAD \
79+
unsigned char data[_PyDateTime_TIME_DATASIZE];
80+
81+
typedef struct
82+
{
83+
_PyDateTime_TIMEHEAD
84+
} _PyDateTime_BaseTime; /* hastzinfo false */
85+
86+
typedef struct
87+
{
88+
_PyDateTime_TIMEHEAD
89+
unsigned char fold;
90+
PyObject *tzinfo;
91+
} PyDateTime_Time; /* hastzinfo true */
92+
93+
94+
/* All datetime objects are of PyDateTime_DateTimeType, but that can be
95+
* allocated in two ways too, just like for time objects above. In addition,
96+
* the plain date type is a base class for datetime, so it must also have
97+
* a hastzinfo member (although it's unused there).
98+
*/
99+
typedef struct
100+
{
101+
_PyTZINFO_HEAD
102+
unsigned char data[_PyDateTime_DATE_DATASIZE];
103+
} PyDateTime_Date;
104+
105+
#define _PyDateTime_DATETIMEHEAD \
106+
_PyTZINFO_HEAD \
107+
unsigned char data[_PyDateTime_DATETIME_DATASIZE];
108+
109+
typedef struct
110+
{
111+
_PyDateTime_DATETIMEHEAD
112+
} _PyDateTime_BaseDateTime; /* hastzinfo false */
113+
114+
typedef struct
115+
{
116+
_PyDateTime_DATETIMEHEAD
117+
unsigned char fold;
118+
PyObject *tzinfo;
119+
} PyDateTime_DateTime; /* hastzinfo true */
120+
121+
122+
/* Apply for date and datetime instances. */
123+
#define PyDateTime_GET_YEAR(o) ((((PyDateTime_Date*)o)->data[0] << 8) | \
124+
((PyDateTime_Date*)o)->data[1])
125+
#define PyDateTime_GET_MONTH(o) (((PyDateTime_Date*)o)->data[2])
126+
#define PyDateTime_GET_DAY(o) (((PyDateTime_Date*)o)->data[3])
127+
128+
#define PyDateTime_DATE_GET_HOUR(o) (((PyDateTime_DateTime*)o)->data[4])
129+
#define PyDateTime_DATE_GET_MINUTE(o) (((PyDateTime_DateTime*)o)->data[5])
130+
#define PyDateTime_DATE_GET_SECOND(o) (((PyDateTime_DateTime*)o)->data[6])
131+
#define PyDateTime_DATE_GET_MICROSECOND(o) \
132+
((((PyDateTime_DateTime*)o)->data[7] << 16) | \
133+
(((PyDateTime_DateTime*)o)->data[8] << 8) | \
134+
((PyDateTime_DateTime*)o)->data[9])
135+
#define PyDateTime_DATE_GET_FOLD(o) (((PyDateTime_DateTime*)o)->fold)
136+
137+
/* Apply for time instances. */
138+
#define PyDateTime_TIME_GET_HOUR(o) (((PyDateTime_Time*)o)->data[0])
139+
#define PyDateTime_TIME_GET_MINUTE(o) (((PyDateTime_Time*)o)->data[1])
140+
#define PyDateTime_TIME_GET_SECOND(o) (((PyDateTime_Time*)o)->data[2])
141+
#define PyDateTime_TIME_GET_MICROSECOND(o) \
142+
((((PyDateTime_Time*)o)->data[3] << 16) | \
143+
(((PyDateTime_Time*)o)->data[4] << 8) | \
144+
((PyDateTime_Time*)o)->data[5])
145+
#define PyDateTime_TIME_GET_FOLD(o) (((PyDateTime_Time*)o)->fold)
146+
147+
/* Apply for time delta instances */
148+
#define PyDateTime_DELTA_GET_DAYS(o) (((PyDateTime_Delta*)o)->days)
149+
#define PyDateTime_DELTA_GET_SECONDS(o) (((PyDateTime_Delta*)o)->seconds)
150+
#define PyDateTime_DELTA_GET_MICROSECONDS(o) \
151+
(((PyDateTime_Delta*)o)->microseconds)
152+
153+
154+
/* Define structure for C API. */
155+
typedef struct {
156+
/* type objects */
157+
PyTypeObject *DateType;
158+
PyTypeObject *DateTimeType;
159+
PyTypeObject *TimeType;
160+
PyTypeObject *DeltaType;
161+
PyTypeObject *TZInfoType;
162+
163+
/* constructors */
164+
PyObject *(*Date_FromDate)(int, int, int, PyTypeObject*);
165+
PyObject *(*DateTime_FromDateAndTime)(int, int, int, int, int, int, int,
166+
PyObject*, PyTypeObject*);
167+
PyObject *(*Time_FromTime)(int, int, int, int, PyObject*, PyTypeObject*);
168+
PyObject *(*Delta_FromDelta)(int, int, int, int, PyTypeObject*);
169+
170+
/* constructors for the DB API */
171+
PyObject *(*DateTime_FromTimestamp)(PyObject*, PyObject*, PyObject*);
172+
PyObject *(*Date_FromTimestamp)(PyObject*, PyObject*);
173+
174+
/* PEP 495 constructors */
175+
PyObject *(*DateTime_FromDateAndTimeAndFold)(int, int, int, int, int, int, int,
176+
PyObject*, int, PyTypeObject*);
177+
PyObject *(*Time_FromTimeAndFold)(int, int, int, int, PyObject*, int, PyTypeObject*);
178+
179+
} PyDateTime_CAPI;
180+
181+
#define PyDateTime_CAPSULE_NAME "datetime.datetime_CAPI"
182+
183+
184+
#ifdef Py_BUILD_CORE
185+
186+
/* Macros for type checking when building the Python core. */
187+
#define PyDate_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateType)
188+
#define PyDate_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateType)
189+
190+
#define PyDateTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateTimeType)
191+
#define PyDateTime_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DateTimeType)
192+
193+
#define PyTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeType)
194+
#define PyTime_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TimeType)
195+
196+
#define PyDelta_Check(op) PyObject_TypeCheck(op, &PyDateTime_DeltaType)
197+
#define PyDelta_CheckExact(op) (Py_TYPE(op) == &PyDateTime_DeltaType)
198+
199+
#define PyTZInfo_Check(op) PyObject_TypeCheck(op, &PyDateTime_TZInfoType)
200+
#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == &PyDateTime_TZInfoType)
201+
202+
#else
203+
204+
/* Define global variable for the C API and a macro for setting it. */
205+
static PyDateTime_CAPI *PyDateTimeAPI = NULL;
206+
207+
#define PyDateTime_IMPORT \
208+
PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0)
209+
210+
/* Macros for type checking when not building the Python core. */
211+
#define PyDate_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateType)
212+
#define PyDate_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DateType)
213+
214+
#define PyDateTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateTimeType)
215+
#define PyDateTime_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DateTimeType)
216+
217+
#define PyTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TimeType)
218+
#define PyTime_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->TimeType)
219+
220+
#define PyDelta_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DeltaType)
221+
#define PyDelta_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->DeltaType)
222+
223+
#define PyTZInfo_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TZInfoType)
224+
#define PyTZInfo_CheckExact(op) (Py_TYPE(op) == PyDateTimeAPI->TZInfoType)
225+
226+
/* Macros for accessing constructors in a simplified fashion. */
227+
#define PyDate_FromDate(year, month, day) \
228+
PyDateTimeAPI->Date_FromDate(year, month, day, PyDateTimeAPI->DateType)
229+
230+
#define PyDateTime_FromDateAndTime(year, month, day, hour, min, sec, usec) \
231+
PyDateTimeAPI->DateTime_FromDateAndTime(year, month, day, hour, \
232+
min, sec, usec, Py_None, PyDateTimeAPI->DateTimeType)
233+
234+
#define PyDateTime_FromDateAndTimeAndFold(year, month, day, hour, min, sec, usec, fold) \
235+
PyDateTimeAPI->DateTime_FromDateAndTimeAndFold(year, month, day, hour, \
236+
min, sec, usec, Py_None, fold, PyDateTimeAPI->DateTimeType)
237+
238+
#define PyTime_FromTime(hour, minute, second, usecond) \
239+
PyDateTimeAPI->Time_FromTime(hour, minute, second, usecond, \
240+
Py_None, PyDateTimeAPI->TimeType)
241+
242+
#define PyTime_FromTimeAndFold(hour, minute, second, usecond, fold) \
243+
PyDateTimeAPI->Time_FromTimeAndFold(hour, minute, second, usecond, \
244+
Py_None, fold, PyDateTimeAPI->TimeType)
245+
246+
#define PyDelta_FromDSU(days, seconds, useconds) \
247+
PyDateTimeAPI->Delta_FromDelta(days, seconds, useconds, 1, \
248+
PyDateTimeAPI->DeltaType)
249+
250+
/* Macros supporting the DB API. */
251+
#define PyDateTime_FromTimestamp(args) \
252+
PyDateTimeAPI->DateTime_FromTimestamp( \
253+
(PyObject*) (PyDateTimeAPI->DateTimeType), args, NULL)
254+
255+
#define PyDate_FromTimestamp(args) \
256+
PyDateTimeAPI->Date_FromTimestamp( \
257+
(PyObject*) (PyDateTimeAPI->DateType), args)
258+
259+
#endif /* Py_BUILD_CORE */
260+
261+
#ifdef __cplusplus
262+
}
263+
#endif
264+
#endif
265+
#endif /* !Py_LIMITED_API */
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* Copyright (c) 2018, Oracle and/or its affiliates.
2+
* Copyright (C) 1996-2017 Python Software Foundation
3+
*
4+
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
5+
*/
6+
7+
/* Memory view object. In Python this is available as "memoryview". */
8+
9+
#ifndef Py_MEMORYOBJECT_H
10+
#define Py_MEMORYOBJECT_H
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
#ifndef Py_LIMITED_API
16+
PyAPI_DATA(PyTypeObject) _PyManagedBuffer_Type;
17+
#endif
18+
PyAPI_DATA(PyTypeObject) PyMemoryView_Type;
19+
20+
#define PyMemoryView_Check(op) (Py_TYPE(op) == &PyMemoryView_Type)
21+
22+
#ifndef Py_LIMITED_API
23+
/* Get a pointer to the memoryview's private copy of the exporter's buffer. */
24+
#define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view)
25+
/* Get a pointer to the exporting object (this may be NULL!). */
26+
#define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj)
27+
#endif
28+
29+
PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);
30+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
31+
PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(char *mem, Py_ssize_t size,
32+
int flags);
33+
#endif
34+
#ifndef Py_LIMITED_API
35+
PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info);
36+
#endif
37+
PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base,
38+
int buffertype,
39+
char order);
40+
41+
42+
/* The structs are declared here so that macros can work, but they shouldn't
43+
be considered public. Don't access their fields directly, use the macros
44+
and functions instead! */
45+
#ifndef Py_LIMITED_API
46+
#define _Py_MANAGED_BUFFER_RELEASED 0x001 /* access to exporter blocked */
47+
#define _Py_MhANAGED_BUFFER_FREE_FORMAT 0x002 /* free format */
48+
typedef struct {
49+
PyObject_HEAD
50+
int flags; /* state flags */
51+
Py_ssize_t exports; /* number of direct memoryview exports */
52+
Py_buffer master; /* snapshot buffer obtained from the original exporter */
53+
} _PyManagedBufferObject;
54+
55+
56+
/* memoryview state flags */
57+
#define _Py_MEMORYVIEW_RELEASED 0x001 /* access to master buffer blocked */
58+
#define _Py_MEMORYVIEW_C 0x002 /* C-contiguous layout */
59+
#define _Py_MEMORYVIEW_FORTRAN 0x004 /* Fortran contiguous layout */
60+
#define _Py_MEMORYVIEW_SCALAR 0x008 /* scalar: ndim = 0 */
61+
#define _Py_MEMORYVIEW_PIL 0x010 /* PIL-style layout */
62+
63+
typedef struct {
64+
PyObject_VAR_HEAD
65+
_PyManagedBufferObject *mbuf; /* managed buffer */
66+
Py_hash_t hash; /* hash value for read-only views */
67+
int flags; /* state flags */
68+
Py_ssize_t exports; /* number of buffer re-exports */
69+
Py_buffer view; /* private copy of the exporter's view */
70+
PyObject *weakreflist;
71+
Py_ssize_t ob_array[1]; /* shape, strides, suboffsets */
72+
} PyMemoryViewObject;
73+
#endif
74+
75+
#ifdef __cplusplus
76+
}
77+
#endif
78+
#endif /* !Py_MEMORYOBJECT_H */
79+

0 commit comments

Comments
 (0)