Skip to content

Commit f14680d

Browse files
committed
[GR-9785] Fix NumPy/multiarray compilation errors.
PullRequest: graalpython-open/42
2 parents 7b6d6c7 + 804fd2c commit f14680d

File tree

9 files changed

+473
-51
lines changed

9 files changed

+473
-51
lines changed

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

Lines changed: 63 additions & 48 deletions
Large diffs are not rendered by default.
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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+
/* Definitions for bytecode */
8+
9+
#ifndef Py_LIMITED_API
10+
#ifndef Py_CODE_H
11+
#define Py_CODE_H
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
typedef uint16_t _Py_CODEUNIT;
17+
18+
#ifdef WORDS_BIGENDIAN
19+
# define _Py_OPCODE(word) ((word) >> 8)
20+
# define _Py_OPARG(word) ((word) & 255)
21+
#else
22+
# define _Py_OPCODE(word) ((word) & 255)
23+
# define _Py_OPARG(word) ((word) >> 8)
24+
#endif
25+
26+
/* Bytecode object */
27+
typedef struct {
28+
PyObject_HEAD
29+
int co_argcount; /* #arguments, except *args */
30+
int co_kwonlyargcount; /* #keyword only arguments */
31+
int co_nlocals; /* #local variables */
32+
int co_stacksize; /* #entries needed for evaluation stack */
33+
int co_flags; /* CO_..., see below */
34+
int co_firstlineno; /* first source line number */
35+
PyObject *co_code; /* instruction opcodes */
36+
PyObject *co_consts; /* list (constants used) */
37+
PyObject *co_names; /* list of strings (names used) */
38+
PyObject *co_varnames; /* tuple of strings (local variable names) */
39+
PyObject *co_freevars; /* tuple of strings (free variable names) */
40+
PyObject *co_cellvars; /* tuple of strings (cell variable names) */
41+
/* The rest aren't used in either hash or comparisons, except for co_name,
42+
used in both. This is done to preserve the name and line number
43+
for tracebacks and debuggers; otherwise, constant de-duplication
44+
would collapse identical functions/lambdas defined on different lines.
45+
*/
46+
unsigned char *co_cell2arg; /* Maps cell vars which are arguments. */
47+
PyObject *co_filename; /* unicode (where it was loaded from) */
48+
PyObject *co_name; /* unicode (name, for reference) */
49+
PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) See
50+
Objects/lnotab_notes.txt for details. */
51+
void *co_zombieframe; /* for optimization only (see frameobject.c) */
52+
PyObject *co_weakreflist; /* to support weakrefs to code objects */
53+
/* Scratch space for extra data relating to the code object.
54+
Type is a void* to keep the format private in codeobject.c to force
55+
people to go through the proper APIs. */
56+
void *co_extra;
57+
} PyCodeObject;
58+
59+
/* Masks for co_flags above */
60+
#define CO_OPTIMIZED 0x0001
61+
#define CO_NEWLOCALS 0x0002
62+
#define CO_VARARGS 0x0004
63+
#define CO_VARKEYWORDS 0x0008
64+
#define CO_NESTED 0x0010
65+
#define CO_GENERATOR 0x0020
66+
/* The CO_NOFREE flag is set if there are no free or cell variables.
67+
This information is redundant, but it allows a single flag test
68+
to determine whether there is any extra work to be done when the
69+
call frame it setup.
70+
*/
71+
#define CO_NOFREE 0x0040
72+
73+
/* The CO_COROUTINE flag is set for coroutine functions (defined with
74+
``async def`` keywords) */
75+
#define CO_COROUTINE 0x0080
76+
#define CO_ITERABLE_COROUTINE 0x0100
77+
#define CO_ASYNC_GENERATOR 0x0200
78+
79+
/* These are no longer used. */
80+
#if 0
81+
#define CO_GENERATOR_ALLOWED 0x1000
82+
#endif
83+
#define CO_FUTURE_DIVISION 0x2000
84+
#define CO_FUTURE_ABSOLUTE_IMPORT 0x4000 /* do absolute imports by default */
85+
#define CO_FUTURE_WITH_STATEMENT 0x8000
86+
#define CO_FUTURE_PRINT_FUNCTION 0x10000
87+
#define CO_FUTURE_UNICODE_LITERALS 0x20000
88+
89+
#define CO_FUTURE_BARRY_AS_BDFL 0x40000
90+
#define CO_FUTURE_GENERATOR_STOP 0x80000
91+
92+
/* This value is found in the co_cell2arg array when the associated cell
93+
variable does not correspond to an argument. The maximum number of
94+
arguments is 255 (indexed up to 254), so 255 work as a special flag.*/
95+
#define CO_CELL_NOT_AN_ARG 255
96+
97+
/* This should be defined if a future statement modifies the syntax.
98+
For example, when a keyword is added.
99+
*/
100+
#define PY_PARSER_REQUIRES_FUTURE_KEYWORD
101+
102+
#define CO_MAXBLOCKS 20 /* Max static block nesting within a function */
103+
104+
PyAPI_DATA(PyTypeObject) PyCode_Type;
105+
106+
#define PyCode_Check(op) (Py_TYPE(op) == &PyCode_Type)
107+
#define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars))
108+
109+
/* Public interface */
110+
PyAPI_FUNC(PyCodeObject *) PyCode_New(
111+
int, int, int, int, int, PyObject *, PyObject *,
112+
PyObject *, PyObject *, PyObject *, PyObject *,
113+
PyObject *, PyObject *, int, PyObject *);
114+
/* same as struct above */
115+
116+
/* Creates a new empty code object with the specified source location. */
117+
PyAPI_FUNC(PyCodeObject *)
118+
PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno);
119+
120+
/* Return the line number associated with the specified bytecode index
121+
in this code object. If you just need the line number of a frame,
122+
use PyFrame_GetLineNumber() instead. */
123+
PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);
124+
125+
/* for internal use only */
126+
typedef struct _addr_pair {
127+
int ap_lower;
128+
int ap_upper;
129+
} PyAddrPair;
130+
131+
#ifndef Py_LIMITED_API
132+
/* Update *bounds to describe the first and one-past-the-last instructions in the
133+
same line as lasti. Return the number of that line.
134+
*/
135+
PyAPI_FUNC(int) _PyCode_CheckLineNumber(PyCodeObject* co,
136+
int lasti, PyAddrPair *bounds);
137+
138+
/* Create a comparable key used to compare constants taking in account the
139+
* object type. It is used to make sure types are not coerced (e.g., float and
140+
* complex) _and_ to distinguish 0.0 from -0.0 e.g. on IEEE platforms
141+
*
142+
* Return (type(obj), obj, ...): a tuple with variable size (at least 2 items)
143+
* depending on the type and the value. The type is the first item to not
144+
* compare bytes and str which can raise a BytesWarning exception. */
145+
PyAPI_FUNC(PyObject*) _PyCode_ConstantKey(PyObject *obj);
146+
#endif
147+
148+
PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts,
149+
PyObject *names, PyObject *lnotab);
150+
151+
152+
#ifndef Py_LIMITED_API
153+
PyAPI_FUNC(int) _PyCode_GetExtra(PyObject *code, Py_ssize_t index,
154+
void **extra);
155+
PyAPI_FUNC(int) _PyCode_SetExtra(PyObject *code, Py_ssize_t index,
156+
void *extra);
157+
#endif
158+
159+
#ifdef __cplusplus
160+
}
161+
#endif
162+
#endif /* !Py_CODE_H */
163+
#endif /* Py_LIMITED_API */
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
#ifndef Py_LIMITED_API
7+
#ifndef Py_PYDEBUG_H
8+
#define Py_PYDEBUG_H
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
/* These global variable are defined in pylifecycle.c */
14+
/* XXX (ncoghlan): move these declarations to pylifecycle.h? */
15+
PyAPI_DATA(int) Py_DebugFlag;
16+
PyAPI_DATA(int) Py_VerboseFlag;
17+
PyAPI_DATA(int) Py_QuietFlag;
18+
PyAPI_DATA(int) Py_InteractiveFlag;
19+
PyAPI_DATA(int) Py_InspectFlag;
20+
PyAPI_DATA(int) Py_OptimizeFlag;
21+
PyAPI_DATA(int) Py_NoSiteFlag;
22+
PyAPI_DATA(int) Py_BytesWarningFlag;
23+
PyAPI_DATA(int) Py_UseClassExceptionsFlag;
24+
PyAPI_DATA(int) Py_FrozenFlag;
25+
PyAPI_DATA(int) Py_IgnoreEnvironmentFlag;
26+
PyAPI_DATA(int) Py_DontWriteBytecodeFlag;
27+
PyAPI_DATA(int) Py_NoUserSiteDirectory;
28+
PyAPI_DATA(int) Py_UnbufferedStdioFlag;
29+
PyAPI_DATA(int) Py_HashRandomizationFlag;
30+
PyAPI_DATA(int) Py_IsolatedFlag;
31+
32+
#ifdef MS_WINDOWS
33+
PyAPI_DATA(int) Py_LegacyWindowsStdioFlag;
34+
#endif
35+
36+
/* this is a wrapper around getenv() that pays attention to
37+
Py_IgnoreEnvironmentFlag. It should be used for getting variables like
38+
PYTHONPATH and PYTHONHOME from the environment */
39+
#define Py_GETENV(s) (Py_IgnoreEnvironmentFlag ? NULL : getenv(s))
40+
41+
#ifdef __cplusplus
42+
}
43+
#endif
44+
#endif /* !Py_PYDEBUG_H */
45+
#endif /* Py_LIMITED_API */
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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+
/* Interfaces to configure, query, create & destroy the Python runtime */
8+
9+
#ifndef Py_PYLIFECYCLE_H
10+
#define Py_PYLIFECYCLE_H
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
PyAPI_FUNC(void) Py_SetProgramName(wchar_t *);
16+
PyAPI_FUNC(wchar_t *) Py_GetProgramName(void);
17+
18+
PyAPI_FUNC(void) Py_SetPythonHome(wchar_t *);
19+
PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
20+
21+
#ifndef Py_LIMITED_API
22+
/* Only used by applications that embed the interpreter and need to
23+
* override the standard encoding determination mechanism
24+
*/
25+
PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding,
26+
const char *errors);
27+
#endif
28+
29+
PyAPI_FUNC(void) Py_Initialize(void);
30+
PyAPI_FUNC(void) Py_InitializeEx(int);
31+
#ifndef Py_LIMITED_API
32+
PyAPI_FUNC(void) _Py_InitializeEx_Private(int, int);
33+
#endif
34+
PyAPI_FUNC(void) Py_Finalize(void);
35+
PyAPI_FUNC(int) Py_FinalizeEx(void);
36+
PyAPI_FUNC(int) Py_IsInitialized(void);
37+
PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void);
38+
PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *);
39+
40+
41+
/* Py_PyAtExit is for the atexit module, Py_AtExit is for low-level
42+
* exit functions.
43+
*/
44+
#ifndef Py_LIMITED_API
45+
PyAPI_FUNC(void) _Py_PyAtExit(void (*func)(void));
46+
#endif
47+
PyAPI_FUNC(int) Py_AtExit(void (*func)(void));
48+
49+
PyAPI_FUNC(void) Py_Exit(int);
50+
51+
/* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL. */
52+
#ifndef Py_LIMITED_API
53+
PyAPI_FUNC(void) _Py_RestoreSignals(void);
54+
55+
PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
56+
#endif
57+
58+
/* Bootstrap __main__ (defined in Modules/main.c) */
59+
PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv);
60+
61+
/* In getpath.c */
62+
PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void);
63+
PyAPI_FUNC(wchar_t *) Py_GetPrefix(void);
64+
PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void);
65+
PyAPI_FUNC(wchar_t *) Py_GetPath(void);
66+
PyAPI_FUNC(void) Py_SetPath(const wchar_t *);
67+
#ifdef MS_WINDOWS
68+
int _Py_CheckPython3();
69+
#endif
70+
71+
/* In their own files */
72+
PyAPI_FUNC(const char *) Py_GetVersion(void);
73+
PyAPI_FUNC(const char *) Py_GetPlatform(void);
74+
PyAPI_FUNC(const char *) Py_GetCopyright(void);
75+
PyAPI_FUNC(const char *) Py_GetCompiler(void);
76+
PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
77+
#ifndef Py_LIMITED_API
78+
PyAPI_FUNC(const char *) _Py_gitidentifier(void);
79+
PyAPI_FUNC(const char *) _Py_gitversion(void);
80+
#endif
81+
82+
/* Internal -- various one-time initializations */
83+
#ifndef Py_LIMITED_API
84+
PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);
85+
PyAPI_FUNC(PyObject *) _PySys_Init(void);
86+
PyAPI_FUNC(void) _PyImport_Init(void);
87+
PyAPI_FUNC(void) _PyExc_Init(PyObject * bltinmod);
88+
PyAPI_FUNC(void) _PyImportHooks_Init(void);
89+
PyAPI_FUNC(int) _PyFrame_Init(void);
90+
PyAPI_FUNC(int) _PyFloat_Init(void);
91+
PyAPI_FUNC(int) PyByteArray_Init(void);
92+
PyAPI_FUNC(void) _PyRandom_Init(void);
93+
#endif
94+
95+
/* Various internal finalizers */
96+
#ifndef Py_LIMITED_API
97+
PyAPI_FUNC(void) _PyExc_Fini(void);
98+
PyAPI_FUNC(void) _PyImport_Fini(void);
99+
PyAPI_FUNC(void) PyMethod_Fini(void);
100+
PyAPI_FUNC(void) PyFrame_Fini(void);
101+
PyAPI_FUNC(void) PyCFunction_Fini(void);
102+
PyAPI_FUNC(void) PyDict_Fini(void);
103+
PyAPI_FUNC(void) PyTuple_Fini(void);
104+
PyAPI_FUNC(void) PyList_Fini(void);
105+
PyAPI_FUNC(void) PySet_Fini(void);
106+
PyAPI_FUNC(void) PyBytes_Fini(void);
107+
PyAPI_FUNC(void) PyByteArray_Fini(void);
108+
PyAPI_FUNC(void) PyFloat_Fini(void);
109+
PyAPI_FUNC(void) PyOS_FiniInterrupts(void);
110+
PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void);
111+
PyAPI_FUNC(void) _PyGC_Fini(void);
112+
PyAPI_FUNC(void) PySlice_Fini(void);
113+
PyAPI_FUNC(void) _PyType_Fini(void);
114+
PyAPI_FUNC(void) _PyRandom_Fini(void);
115+
PyAPI_FUNC(void) PyAsyncGen_Fini(void);
116+
117+
PyAPI_DATA(PyThreadState *) _Py_Finalizing;
118+
#endif
119+
120+
/* Signals */
121+
typedef void (*PyOS_sighandler_t)(int);
122+
PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int);
123+
PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t);
124+
125+
#ifndef Py_LIMITED_API
126+
/* Random */
127+
PyAPI_FUNC(int) _PyOS_URandom(void *buffer, Py_ssize_t size);
128+
PyAPI_FUNC(int) _PyOS_URandomNonblock(void *buffer, Py_ssize_t size);
129+
#endif /* !Py_LIMITED_API */
130+
131+
#ifdef __cplusplus
132+
}
133+
#endif
134+
#endif /* !Py_PYLIFECYCLE_H */
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2018, Oracle and/or its affiliates.
3+
*
4+
* The Universal Permissive License (UPL), Version 1.0
5+
*
6+
* Subject to the condition set forth below, permission is hereby granted to any
7+
* person obtaining a copy of this software, associated documentation and/or data
8+
* (collectively the "Software"), free of charge and under any and all copyright
9+
* rights in the Software, and any and all patent rights owned or freely
10+
* licensable by each licensor hereunder covering either (i) the unmodified
11+
* Software as contributed to or provided by such licensor, or (ii) the Larger
12+
* Works (as defined below), to deal in both
13+
*
14+
* (a) the Software, and
15+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16+
* one is included with the Software (each a "Larger Work" to which the
17+
* Software is contributed by such licensors),
18+
*
19+
* without restriction, including without limitation the rights to copy, create
20+
* derivative works of, display, perform, and distribute the Software and make,
21+
* use, sell, offer for sale, import, export, have made, and have sold the
22+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
23+
* either these or other terms.
24+
*
25+
* This license is subject to the following condition:
26+
*
27+
* The above copyright notice and either this complete permission notice or at a
28+
* minimum a reference to the UPL must be included in all copies or substantial
29+
* portions of the Software.
30+
*
31+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37+
* SOFTWARE.
38+
*/
39+
#include "capi.h"
40+
41+
int Py_OptimizeFlag = 0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ int PyErr_ExceptionMatches(PyObject *exc) {
149149
}
150150

151151
PyObject* PyTruffle_Err_Format(PyObject* exception, const char* fmt, int s, void* v0, void* v1, void* v2, void* v3, void* v4, void* v5, void* v6, void* v7, void* v8, void* v9) {
152-
PyObject *formatted_msg = PyTruffle_Unicode_FromFormat(fmt, s, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9);
152+
PyObject *formatted_msg = PyTruffle_Unicode_FromFormat(fmt, s, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
153153
truffle_invoke(PY_TRUFFLE_CEXT, "PyErr_CreateAndSetException", to_java(exception), to_java(formatted_msg));
154154
return NULL;
155155
}

0 commit comments

Comments
 (0)