Skip to content

Commit b4fc282

Browse files
committed
[GR-16853] Remove PYPY_VERSION.
PullRequest: graalpython/1860
2 parents e0ed0e9 + bfad8b2 commit b4fc282

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1800
-461
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,31 @@
4141
#ifndef Py_PYTHON_H
4242
#define Py_PYTHON_H
4343

44+
#include "pyconfig.h"
45+
4446
#define HAVE_UTIME_H
4547
#define HAVE_UNISTD_H
4648
#define HAVE_SIGNAL_H
4749
#define HAVE_FCNTL_H
4850
#define HAVE_SYS_WAIT_H
4951

5052
#define GRAALVM_PYTHON 1
51-
#define PYPY_VERSION 0
52-
#define PYPY_VERSION_NUM 0x07030000
53+
54+
/* If Cython is involved, avoid accesses to internal structures. While we are
55+
* supporting this in many cases, it still involves overhead. */
56+
#define CYTHON_USE_TYPE_SLOTS 0
57+
#define CYTHON_USE_PYTYPE_LOOKUP 0
58+
#define CYTHON_FAST_PYCCALL 0
59+
#define CYTHON_USE_DICT_VERSIONS 0
60+
#define CYTHON_AVOID_BORROWED_REFS 1
61+
#define CYTHON_USE_TP_FINALIZE 0
62+
#define CYTHON_USE_PYLIST_INTERNALS 0
63+
#define CYTHON_USE_UNICODE_INTERNALS 0
64+
#define CYTHON_USE_PYLONG_INTERNALS 0
65+
#define CYTHON_USE_ASYNC_SLOTS 0
66+
#define CYTHON_USE_UNICODE_WRITER 0
67+
#define CYTHON_USE_EXC_INFO_STACK 0
68+
#define CYTHON_FAST_THREAD_STATE 0
5369

5470
#include <stdio.h>
5571
#include <string.h>
@@ -129,4 +145,6 @@
129145

130146
#include "abstract.h"
131147

148+
#include "eval.h"
149+
132150
#endif
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* Copyright (c) 2021, Oracle and/or its affiliates.
2+
* Copyright (C) 1996-2020 Python Software Foundation
3+
*
4+
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
5+
*/
6+
7+
/* Interface to execute compiled code */
8+
9+
#ifndef Py_EVAL_H
10+
#define Py_EVAL_H
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
PyAPI_FUNC(PyObject *) PyEval_EvalCode(PyObject *, PyObject *, PyObject *);
16+
17+
PyAPI_FUNC(PyObject *) PyEval_EvalCodeEx(PyObject *co,
18+
PyObject *globals,
19+
PyObject *locals,
20+
PyObject *const *args, int argc,
21+
PyObject *const *kwds, int kwdc,
22+
PyObject *const *defs, int defc,
23+
PyObject *kwdefs, PyObject *closure);
24+
25+
#ifndef Py_LIMITED_API
26+
PyAPI_FUNC(PyObject *) _PyEval_EvalCodeWithName(
27+
PyObject *co,
28+
PyObject *globals, PyObject *locals,
29+
PyObject *const *args, Py_ssize_t argcount,
30+
PyObject *const *kwnames, PyObject *const *kwargs,
31+
Py_ssize_t kwcount, int kwstep,
32+
PyObject *const *defs, Py_ssize_t defcount,
33+
PyObject *kwdefs, PyObject *closure,
34+
PyObject *name, PyObject *qualname);
35+
36+
PyAPI_FUNC(PyObject *) _PyEval_CallTracing(PyObject *func, PyObject *args);
37+
#endif
38+
39+
#ifdef __cplusplus
40+
}
41+
#endif
42+
#endif /* !Py_EVAL_H */

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
#ifndef Py_PYCONFIG_H
4242
#define Py_PYCONFIG_H
4343

44+
/* Enable GNU extensions on systems that have them. */
45+
#ifndef _GNU_SOURCE
46+
#define _GNU_SOURCE 1
47+
#endif
48+
4449
// required for __UINT32_MAX__ etc.
4550
#include <limits.h>
4651

graalpython/com.oracle.graal.python.cext/posix/fork_exec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*
44
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
55
*/
6-
#ifdef __gnu_linux__
7-
#define _GNU_SOURCE
6+
#if defined(__gnu_linux__) && !defined(_GNU_SOURCE)
7+
#define _GNU_SOURCE 1
88
#endif
99

1010
#include <unistd.h>

graalpython/com.oracle.graal.python.cext/posix/posix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444

4545
// This file uses GNU extensions. Functions that require non-GNU versions (e.g. strerror_r)
4646
// need to go to posix_no_gnu.c
47-
#ifdef __gnu_linux__
48-
#define _GNU_SOURCE
47+
#if defined(__gnu_linux__) && !defined(_GNU_SOURCE)
48+
#define _GNU_SOURCE 1
4949
#endif
5050

5151
#include <arpa/inet.h>

graalpython/com.oracle.graal.python.cext/setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,9 @@ def build_nativelibsupport(capi_home, subdir, libname, deps=[], **kwargs):
473473
def build_libposix(capi_home):
474474
src_dir = os.path.join(__dir__, "posix")
475475
files = [os.path.abspath(os.path.join(src_dir, f)) for f in os.listdir(src_dir) if f.endswith(".c")]
476+
no_gnu_source = get_config_var("USE_GNU_SOURCE")
477+
if no_gnu_source:
478+
get_config_vars()["CFLAGS"] = get_config_var("CFLAGS_DEFAULT")
476479
module = Extension(libposix_name,
477480
sources=files,
478481
libraries=['crypt'] if not darwin_native else [],
@@ -486,6 +489,8 @@ def build_libposix(capi_home):
486489
description="Graal Python's Native support for the POSIX library",
487490
ext_modules=[module],
488491
)
492+
if no_gnu_source:
493+
get_config_vars()["CFLAGS"] = get_config_var("CFLAGS_DEFAULT") + " " + get_config_var("USE_GNU_SOURCE")
489494

490495

491496
def build_builtin_exts(capi_home):

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

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ declare_type(PyFloat_Type, float, PyFloatObject);
179179
declare_type(PySlice_Type, slice, PySliceObject);
180180
declare_type(PyByteArray_Type, bytearray, PyByteArrayObject);
181181
declare_type(PyCFunction_Type, builtin_function_or_method, PyCFunctionObject);
182-
declare_type(PyWrapperDescr_Type, method_descriptor, PyWrapperDescrObject); // LS: previously wrapper_descriptor
182+
declare_type(PyWrapperDescr_Type, wrapper_descriptor, PyWrapperDescrObject);
183183
// tfel: Both method_descriptor maps to both PyWrapperDescr_Type and
184184
// PyMethodDescr_Type. This reflects our interpreter, but we need to make sure
185185
// that the dynamic type for method_descriptor is always going to be
@@ -210,10 +210,79 @@ initialize_type(PyEllipsis_Type, ellipsis, _object);
210210
initialize_type(_PyWeakref_ProxyType, ProxyType, PyWeakReference);
211211
initialize_type(_PyWeakref_CallableProxyType, CallableProxyType, PyWeakReference);
212212

213-
POLYGLOT_DECLARE_TYPE(PyThreadState);
214213
POLYGLOT_DECLARE_TYPE(newfunc);
215214
POLYGLOT_DECLARE_TYPE(Py_buffer);
216215

216+
/* primitive and pointer type declarations */
217+
218+
#define REGISTER_BASIC_TYPE(typename) \
219+
POLYGLOT_DECLARE_TYPE(typename); \
220+
NO_INLINE polyglot_typeid get_ ## typename ## _typeid(void) { \
221+
return polyglot_ ## typename ## _typeid(); \
222+
}
223+
224+
/* just a renaming to avoid name clash with Java types */
225+
typedef void* void_ptr_t;
226+
typedef char char_t;
227+
typedef float float_t;
228+
typedef double double_t;
229+
typedef int int_t;
230+
typedef unsigned int uint_t;
231+
typedef long long_t;
232+
typedef unsigned long ulong_t;
233+
typedef long long longlong_t;
234+
typedef unsigned long long ulonglong_t;
235+
236+
REGISTER_BASIC_TYPE(void_ptr_t);
237+
REGISTER_BASIC_TYPE(int_t);
238+
REGISTER_BASIC_TYPE(uint_t);
239+
REGISTER_BASIC_TYPE(long_t);
240+
REGISTER_BASIC_TYPE(ulong_t);
241+
REGISTER_BASIC_TYPE(longlong_t);
242+
REGISTER_BASIC_TYPE(ulonglong_t);
243+
REGISTER_BASIC_TYPE(int64_t);
244+
REGISTER_BASIC_TYPE(int32_t);
245+
REGISTER_BASIC_TYPE(int16_t);
246+
REGISTER_BASIC_TYPE(int8_t);
247+
REGISTER_BASIC_TYPE(uint64_t);
248+
REGISTER_BASIC_TYPE(uint32_t);
249+
REGISTER_BASIC_TYPE(uint16_t);
250+
REGISTER_BASIC_TYPE(uint8_t);
251+
REGISTER_BASIC_TYPE(Py_complex);
252+
REGISTER_BASIC_TYPE(char_t);
253+
REGISTER_BASIC_TYPE(PyObject);
254+
REGISTER_BASIC_TYPE(PyTypeObject);
255+
REGISTER_BASIC_TYPE(float_t);
256+
REGISTER_BASIC_TYPE(double_t);
257+
REGISTER_BASIC_TYPE(Py_ssize_t);
258+
REGISTER_BASIC_TYPE(size_t);
259+
REGISTER_BASIC_TYPE(PyThreadState);
260+
261+
/* For pointers, make them look like an array of size 1 such that it is
262+
possible to dereference the pointer by accessing element 0. */
263+
#define REGISTER_POINTER_TYPE(basetype, ptrtype) \
264+
typedef basetype* ptrtype; \
265+
POLYGLOT_DECLARE_TYPE(ptrtype); \
266+
NO_INLINE polyglot_typeid get_ ## ptrtype ## _typeid(void) { \
267+
return polyglot_array_typeid(polyglot_ ## basetype ## _typeid(), 1); \
268+
}
269+
270+
REGISTER_POINTER_TYPE(int64_t, int64_ptr_t);
271+
REGISTER_POINTER_TYPE(int32_t, int32_ptr_t);
272+
REGISTER_POINTER_TYPE(int16_t, int16_ptr_t);
273+
REGISTER_POINTER_TYPE(int8_t, int8_ptr_t);
274+
REGISTER_POINTER_TYPE(char_t, char_ptr_t);
275+
REGISTER_POINTER_TYPE(uint64_t, uint64_ptr_t);
276+
REGISTER_POINTER_TYPE(uint32_t, uint32_ptr_t);
277+
REGISTER_POINTER_TYPE(uint16_t, uint16_ptr_t);
278+
REGISTER_POINTER_TYPE(uint8_t, uint8_ptr_t);
279+
REGISTER_POINTER_TYPE(Py_complex, Py_complex_ptr_t);
280+
REGISTER_POINTER_TYPE(PyObject, PyObject_ptr_t);
281+
REGISTER_POINTER_TYPE(PyObject_ptr_t, PyObject_ptr_ptr_t);
282+
REGISTER_POINTER_TYPE(float_t, float_ptr_t);
283+
REGISTER_POINTER_TYPE(double_t, double_ptr_t);
284+
REGISTER_POINTER_TYPE(Py_ssize_t, Py_ssize_ptr_t);
285+
217286

218287
static void initialize_globals() {
219288
// register native NULL
@@ -413,7 +482,6 @@ polyglot_typeid get_byte_array_typeid(uint64_t len) {
413482
return polyglot_array_typeid(polyglot_i8_typeid(), len);
414483
}
415484

416-
POLYGLOT_DECLARE_TYPE(uint32_t);
417485
/** to be used from Java code only; returns the type ID for a uint32_t array */
418486
polyglot_typeid get_uint32_t_array_typeid(uint64_t len) {
419487
return polyglot_array_typeid(polyglot_uint32_t_typeid(), len);

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

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ typedef struct {
8282
} PyBufferDecorator;
8383

8484
/* Taken from CPython "Objects/descrobject.c".
85-
* This struct is actually private to 'descrobject.c' but we need to register
85+
* This struct is actually private to 'descrobject.c' but we need to register
8686
* it to the managed property type. */
8787
typedef struct {
8888
PyObject_HEAD
@@ -312,20 +312,34 @@ void initialize_hashes();
312312
#define JWRAPPER_SETATTR 11
313313
#define JWRAPPER_RICHCMP 12
314314
#define JWRAPPER_SETITEM 13
315-
#define JWRAPPER_REVERSE 14
316-
#define JWRAPPER_POW 15
317-
#define JWRAPPER_REVERSE_POW 16
318-
#define JWRAPPER_LT 17
319-
#define JWRAPPER_LE 18
320-
#define JWRAPPER_EQ 19
321-
#define JWRAPPER_NE 20
322-
#define JWRAPPER_GT 21
323-
#define JWRAPPER_GE 22
324-
#define JWRAPPER_ITERNEXT 23
325-
#define JWRAPPER_INQUIRY 24
326-
#define JWRAPPER_DELITEM 25
327-
#define JWRAPPER_GETITEM 26
328-
#define JWRAPPER_INITPROC 29
315+
#define JWRAPPER_UNARYFUNC 14
316+
#define JWRAPPER_BINARYFUNC 15
317+
#define JWRAPPER_BINARYFUNC_L 16
318+
#define JWRAPPER_BINARYFUNC_R 17
319+
#define JWRAPPER_TERNARYFUNC 18
320+
#define JWRAPPER_TERNARYFUNC_R 19
321+
#define JWRAPPER_LT 20
322+
#define JWRAPPER_LE 21
323+
#define JWRAPPER_EQ 22
324+
#define JWRAPPER_NE 23
325+
#define JWRAPPER_GT 24
326+
#define JWRAPPER_GE 25
327+
#define JWRAPPER_ITERNEXT 26
328+
#define JWRAPPER_INQUIRY 27
329+
#define JWRAPPER_DELITEM 28
330+
#define JWRAPPER_GETITEM 29
331+
#define JWRAPPER_GETTER 30
332+
#define JWRAPPER_SETTER 31
333+
#define JWRAPPER_INITPROC 32
334+
#define JWRAPPER_HASHFUNC 33
335+
#define JWRAPPER_CALL 34
336+
#define JWRAPPER_SETATTRO 35
337+
#define JWRAPPER_DESCR_GET 36
338+
#define JWRAPPER_DESCR_SET 37
339+
#define JWRAPPER_LENFUNC 38
340+
#define JWRAPPER_OBJOBJPROC 39
341+
#define JWRAPPER_OBJOBJARGPROC 40
342+
#define JWRAPPER_NEW 41
329343

330344
#define TDEBUG __builtin_debugtrap()
331345
#define get_method_flags_wrapper(flags) \

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

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,60 @@ void PyThread_release_lock(PyThread_type_lock aLock) {
9595
}
9696

9797

98-
void PyThread_free_lock(PyThread_type_lock lock)
98+
void PyThread_free_lock(PyThread_type_lock lock) {
99+
}
100+
101+
PyObject *
102+
PyEval_EvalCode(PyObject *co, PyObject *globals, PyObject *locals)
103+
{
104+
return PyEval_EvalCodeEx(co,
105+
globals, locals,
106+
(PyObject **)NULL, 0,
107+
(PyObject **)NULL, 0,
108+
(PyObject **)NULL, 0,
109+
NULL, NULL);
110+
}
111+
112+
PyObject *
113+
PyEval_EvalCodeEx(PyObject *_co, PyObject *globals, PyObject *locals,
114+
PyObject *const *args, int argcount,
115+
PyObject *const *kws, int kwcount,
116+
PyObject *const *defs, int defcount,
117+
PyObject *kwdefs, PyObject *closure)
118+
{
119+
return _PyEval_EvalCodeWithName(_co, globals, locals,
120+
args, argcount,
121+
kws, kws != NULL ? kws + 1 : NULL,
122+
kwcount, 2,
123+
defs, defcount,
124+
kwdefs, closure,
125+
NULL, NULL);
126+
}
127+
128+
typedef PyObject *(*eval_code_ex_fun_t)(PyObject *_co, PyObject *globals, PyObject *locals,
129+
PyObject *const *args,
130+
PyObject *const *kwnames,
131+
PyObject *const *kwargs,
132+
PyObject *const *defs,
133+
PyObject *kwdefs, PyObject *closure);
134+
UPCALL_TYPED_ID(PyEval_EvalCodeEx, eval_code_ex_fun_t);
135+
PyObject *
136+
_PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
137+
PyObject *const *args, Py_ssize_t argcount,
138+
PyObject *const *kwnames, PyObject *const *kwargs,
139+
Py_ssize_t kwcount, int kwstep,
140+
PyObject *const *defs, Py_ssize_t defcount,
141+
PyObject *kwdefs, PyObject *closure,
142+
PyObject *name, PyObject *qualname)
99143
{
144+
if (globals == NULL) {
145+
PyErr_SetString(PyExc_SystemError, "PyEval_EvalCodeEx: NULL globals");
146+
return NULL;
147+
}
148+
/* TODO(fa): do not ignore 'name' and 'qualname' */
149+
return _jls_PyEval_EvalCodeEx(native_to_java(_co), native_to_java(globals), native_to_java(locals != NULL ? locals : Py_None),
150+
polyglot_from_PyObjectPtr_array(args, argcount),
151+
polyglot_from_PyObjectPtr_array(kwnames, kwcount), polyglot_from_PyObjectPtr_array(kwargs, kwcount),
152+
polyglot_from_PyObjectPtr_array(defs, defcount),
153+
native_to_java(kwdefs), native_to_java(closure));
100154
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ typedef struct {
4848

4949
PyTypeObject PyGetSetDescr_Type = PY_TRUFFLE_TYPE("getset_descriptor", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, sizeof(PyGetSetDescrObject));
5050
/* NOTE: we use the same Python type (namely 'PBuiltinFunction') for 'wrapper_descriptor' as for 'method_descriptor'; so the flags must be the same! */
51-
PyTypeObject PyWrapperDescr_Type = PY_TRUFFLE_TYPE("wrapper_descriptor", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_METHOD_DESCRIPTOR| _Py_TPFLAGS_HAVE_VECTORCALL, sizeof(PyWrapperDescrObject));
51+
PyTypeObject PyWrapperDescr_Type = PY_TRUFFLE_TYPE("wrapper_descriptor", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_METHOD_DESCRIPTOR, sizeof(PyWrapperDescrObject));
5252
PyTypeObject PyMemberDescr_Type = PY_TRUFFLE_TYPE("member_descriptor", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, sizeof(PyMemberDescrObject));
5353
PyTypeObject PyMethodDescr_Type = PY_TRUFFLE_TYPE_WITH_VECTORCALL("method_descriptor", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_METHOD_DESCRIPTOR| _Py_TPFLAGS_HAVE_VECTORCALL, sizeof(PyMethodDescrObject), offsetof(PyMethodDescrObject, vectorcall));
5454
PyTypeObject PyDictProxy_Type = PY_TRUFFLE_TYPE("mappingproxy", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, sizeof(mappingproxyobject));
@@ -67,11 +67,11 @@ int PyMethodDescr_Check(PyObject* method) {
6767
return UPCALL_CEXT_I(_jls_PyMethodDescr_Check, native_to_java(method));
6868
}
6969

70-
typedef PyObject* (*PyDescr_NewClassMethod_fun_t)(void* name,
70+
typedef PyObject* (*PyDescr_NewClassMethod_fun_t)(void* name,
7171
const char* doc,
72-
int flags,
73-
int wrapper,
74-
void* methObj,
72+
int flags,
73+
int wrapper,
74+
void* methObj,
7575
void* primary);
7676
UPCALL_TYPED_ID(PyDescr_NewClassMethod, PyDescr_NewClassMethod_fun_t);
7777
PyObject* PyDescr_NewClassMethod(PyTypeObject *type, PyMethodDef *method) {
@@ -84,7 +84,7 @@ PyObject* PyDescr_NewClassMethod(PyTypeObject *type, PyMethodDef *method) {
8484
type);
8585
}
8686

87-
typedef PyObject* (*PyDescr_NewGetSet_fun_t)(void* name,
87+
typedef PyObject* (*PyDescr_NewGetSet_fun_t)(void* name,
8888
PyTypeObject *type,
8989
void *get,
9090
void *set,

0 commit comments

Comments
 (0)