Skip to content

Commit fbdb937

Browse files
committed
Obtain latest master
2 parents db10932 + 1b33592 commit fbdb937

File tree

412 files changed

+13194
-6392
lines changed

Some content is hidden

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

412 files changed

+13194
-6392
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "ea08890c99fa458eedbe654f6d413cfbd995f8a8" }
1+
{ "overlay": "a821a41d4b56097241ba670508db188ead7e8b58" }

docs/contributor/IMPLEMENTATION_DETAILS.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,28 @@ we are always running single threaded or always own the GIL already when we get
248248
to a specific message we never emit a boundary call to lock and unlock the
249249
GIL. This implies that we may deopt in some places if, after compiling some
250250
code, we later start a second thread.
251+
252+
## Threading
253+
254+
As explained above, we use a GIL to prevent parallel execution of Python code. A
255+
timer is running the interrupts threads periodically to relinquish the GIL and
256+
give other threads a chance to run. This preemption is prohibited in most C
257+
extension code, however, since the assumption in C extensions written for
258+
CPython is that the GIL will not be relinquished while executing the C code and
259+
many C extensions are not written to reentrant.
260+
261+
So, commonly at any given time there is only one Graal Python thread executing
262+
and all the other threads are waiting to acquire the GIL. If the Python
263+
interpreter shuts down, there are two sets of threads we need to deal with:
264+
"well-behaved" threads created using the `threading` module are interrupted and
265+
joined using the `threading` module's `shutdown` function. Daemon threads or
266+
threads created using the internal Python `_thread` module cannot be joined in
267+
this way. For those threads, we invalidate their `PythonThreadState` (a
268+
thread-local data structure) and use the Java `Thread#interrupt` method to
269+
interrupt their waiting on the GIL. This exception is handled by checking if the
270+
thread state has been invalidated and if so, just exit the thread gracefully.
271+
272+
For embedders, it may be important to be able to interrupt Python threads by
273+
other means. We use the TruffleSafepoint mechanism to mark our threads waiting
274+
to acquire the GIL as blocked for the purpose of safepoints. The Truffle
275+
safepoint action mechanism can thus be used to kill threads waiting on the GIL.

docs/user/Packages.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ Other extensions might currently work, but they are not actively tested.
4141
Note that to try extensions on GraalVM's Python runtime, you have to download, build, and install them manually for now.
4242

4343
### Using `pip`
44-
The `pip` package installer is available and working in a `venv`, but there is no support for SSL yet.
45-
This means you can install packages from PyPI if you use an HTTP mirror, and you can install local packages.
44+
45+
The `pip` package installer is available and working when using a `venv`.

graalpython/com.oracle.graal.python.benchmarks/java/com/oracle/graal/python/benchmarks/parser/ParserBenchRunner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import com.oracle.graal.python.parser.PythonParserImpl;
4747
import com.oracle.graal.python.parser.PythonSSTNodeFactory;
4848
import com.oracle.graal.python.runtime.PythonContext;
49-
import com.oracle.graal.python.runtime.PythonCore;
49+
import com.oracle.graal.python.builtins.Python3Core;
5050
import com.oracle.graal.python.runtime.PythonParser;
5151
import com.oracle.truffle.api.TruffleFile;
5252
import com.oracle.truffle.api.source.Source;
@@ -98,7 +98,7 @@ public class ParserBenchRunner {
9898

9999
protected final PythonContext pyContext;
100100
protected final PythonParserImpl parser;
101-
protected final PythonCore core;
101+
protected final Python3Core core;
102102
private List<Source> sources;
103103

104104
public ParserBenchRunner() {

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
#define UNWRAP(_h) ((_h)._i)
4949
#define WRAP(_ptr) ((HPy){(_ptr)})
5050

51-
5251
typedef HPyDef* HPyDefPtr;
5352

5453
POLYGLOT_DECLARE_TYPE(HPy);
@@ -91,6 +90,10 @@ void* graal_hpy_calloc(size_t count, size_t eltsize) {
9190
return calloc(count, eltsize);
9291
}
9392

93+
void graal_hpy_free(void *ptr) {
94+
free(ptr);
95+
}
96+
9497
void* graal_hpy_from_HPy_array(void *arr, uint64_t len) {
9598
return polyglot_from_HPy_array(arr, len);
9699
}
@@ -571,3 +574,9 @@ int graal_hpy_bulk_free(void* ptrArray[], int64_t len) {
571574
}
572575
return 0;
573576
}
577+
578+
POLYGLOT_DECLARE_TYPE(HPy_buffer);
579+
HPy_buffer *graal_hpy_allocate_buffer() {
580+
return polyglot_from_HPy_buffer((HPy_buffer *) malloc(sizeof(HPy_buffer)));
581+
}
582+

graalpython/com.oracle.graal.python.cext/include/common/autogen_hpyfunc_declare.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
#define _HPyFunc_DECLARE_HPyFunc_GETTER(SYM) static HPy SYM(HPyContext ctx, HPy, void *)
6464
#define _HPyFunc_DECLARE_HPyFunc_SETTER(SYM) static int SYM(HPyContext ctx, HPy, HPy, void *)
6565
#define _HPyFunc_DECLARE_HPyFunc_OBJOBJPROC(SYM) static int SYM(HPyContext ctx, HPy, HPy)
66+
#define _HPyFunc_DECLARE_HPyFunc_GETBUFFERPROC(SYM) static int SYM(HPyContext, HPy, HPy_buffer *, int)
67+
#define _HPyFunc_DECLARE_HPyFunc_RELEASEBUFFERPROC(SYM) static void SYM(HPyContext, HPy, HPy_buffer *)
6668
#define _HPyFunc_DECLARE_HPyFunc_DESTROYFUNC(SYM) static void SYM(void *)
6769

6870
typedef HPy (*HPyFunc_noargs)(HPyContext ctx, HPy self);
@@ -95,4 +97,6 @@ typedef int (*HPyFunc_initproc)(HPyContext ctx, HPy self, HPy *args, HPy_ssize_t
9597
typedef HPy (*HPyFunc_getter)(HPyContext ctx, HPy, void *);
9698
typedef int (*HPyFunc_setter)(HPyContext ctx, HPy, HPy, void *);
9799
typedef int (*HPyFunc_objobjproc)(HPyContext ctx, HPy, HPy);
100+
typedef int (*HPyFunc_getbufferproc)(HPyContext, HPy, HPy_buffer *, int);
101+
typedef void (*HPyFunc_releasebufferproc)(HPyContext, HPy, HPy_buffer *);
98102
typedef void (*HPyFunc_destroyfunc)(void *);

graalpython/com.oracle.graal.python.cext/include/common/autogen_hpyslot.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
*/
3535

3636
typedef enum {
37+
HPy_bf_getbuffer = 1,
38+
HPy_bf_releasebuffer = 2,
3739
HPy_nb_absolute = 6,
3840
HPy_nb_add = 7,
3941
HPy_nb_and = 8,
@@ -84,6 +86,8 @@ typedef enum {
8486
HPy_tp_destroy = 1000,
8587
} HPySlot_Slot;
8688

89+
#define _HPySlot_SIG__HPy_bf_getbuffer HPyFunc_GETBUFFERPROC
90+
#define _HPySlot_SIG__HPy_bf_releasebuffer HPyFunc_RELEASEBUFFERPROC
8791
#define _HPySlot_SIG__HPy_nb_absolute HPyFunc_UNARYFUNC
8892
#define _HPySlot_SIG__HPy_nb_add HPyFunc_BINARYFUNC
8993
#define _HPySlot_SIG__HPy_nb_and HPyFunc_BINARYFUNC

graalpython/com.oracle.graal.python.cext/include/common/autogen_impl.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ HPyAPI_STORAGE double _HPy_IMPL_NAME(Float_AsDouble)(HPyContext ctx, HPy h)
113113
return PyFloat_AsDouble(_h2py(h));
114114
}
115115

116+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME(Bool_FromLong)(HPyContext ctx, long v)
117+
{
118+
return _py2h(PyBool_FromLong(v));
119+
}
120+
116121
HPyAPI_STORAGE HPy_ssize_t _HPy_IMPL_NAME_NOPREFIX(Length)(HPyContext ctx, HPy h)
117122
{
118123
return PyObject_Length(_h2py(h));
@@ -363,6 +368,11 @@ HPyAPI_STORAGE int _HPy_IMPL_NAME_NOPREFIX(SetItem)(HPyContext ctx, HPy obj, HPy
363368
return PyObject_SetItem(_h2py(obj), _h2py(key), _h2py(value));
364369
}
365370

371+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Type)(HPyContext ctx, HPy obj)
372+
{
373+
return _py2h(PyObject_Type(_h2py(obj)));
374+
}
375+
366376
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Repr)(HPyContext ctx, HPy obj)
367377
{
368378
return _py2h(PyObject_Repr(_h2py(obj)));

graalpython/com.oracle.graal.python.cext/include/common/cpy_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ typedef struct PyMethodDef cpy_PyMethodDef;
3838
typedef PyType_Slot cpy_PyTypeSlot;
3939
typedef PyGetSetDef cpy_PyGetSetDef;
4040
typedef PyMemberDef cpy_PyMemberDef;
41+
typedef struct bufferinfo cpy_Py_buffer;
4142

4243

4344
#endif /* HPY_UNIVERSAL_CPY_TYPES_H */

graalpython/com.oracle.graal.python.cext/include/common/hpyfunc.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ typedef enum {
3333

3434
HPyFunc_DESTROYFUNC,
3535

36+
HPyFunc_GETBUFFERPROC,
37+
HPyFunc_RELEASEBUFFERPROC,
3638
HPyFunc_UNARYFUNC,
3739
HPyFunc_BINARYFUNC,
3840
HPyFunc_TERNARYFUNC,
@@ -94,6 +96,19 @@ typedef enum {
9496
enum { SYM##_sig = SIG }; \
9597
_HPyFunc_TRAMPOLINE_##SIG(SYM, IMPL)
9698

99+
typedef struct {
100+
void *buf;
101+
HPy obj; /* owned reference */
102+
HPy_ssize_t len;
103+
HPy_ssize_t itemsize;
104+
int readonly;
105+
int ndim;
106+
char *format;
107+
HPy_ssize_t *shape;
108+
HPy_ssize_t *strides;
109+
HPy_ssize_t *suboffsets;
110+
void *internal;
111+
} HPy_buffer;
97112

98113
#include "autogen_hpyfunc_declare.h"
99114

0 commit comments

Comments
 (0)