8000 Update HPy inlined files: 1d5d4c5 · oracle/graalpython@8560322 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8560322

Browse files
committed
Update HPy inlined files: 1d5d4c5
1 parent f832e4f commit 8560322

28 files changed

+663
-79
lines changed

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
@@ -40,6 +40,8 @@
4040
#define _HPyFunc_DECLARE_HPyFunc_GETTER(SYM) static HPy SYM(HPyContext ctx, HPy, void *)
4141
#define _HPyFunc_DECLARE_HPyFunc_SETTER(SYM) static int SYM(HPyContext ctx, HPy, HPy, void *)
4242
#define _HPyFunc_DECLARE_HPyFunc_OBJOBJPROC(SYM) static int SYM(HPyContext ctx, HPy, HPy)
43+
#define _HPyFunc_DECLARE_HPyFunc_GETBUFFERPROC(SYM) static int SYM(HPyContext, HPy, HPy_buffer *, int)
44+
#define _HPyFunc_DECLARE_HPyFunc_RELEASEBUFFERPROC(SYM) static void SYM(HPyContext, HPy, HPy_buffer *)
4345
#define _HPyFunc_DECLARE_HPyFunc_DESTROYFUNC(SYM) static void SYM(void *)
4446

4547
typedef HPy (*HPyFunc_noargs)(HPyContext ctx, HPy self);
@@ -72,4 +74,6 @@ typedef int (*HPyFunc_initproc)(HPyContext ctx, HPy self, HPy *args, HPy_ssize_t
7274
typedef HPy (*HPyFunc_getter)(HPyContext ctx, HPy, void *);
7375
typedef int (*HPyFunc_setter)(HPyContext ctx, HPy, HPy, void *);
7476
typedef int (*HPyFunc_objobjproc)(HPyContext ctx, HPy, HPy);
77+
typedef int (*HPyFunc_getbufferproc)(HPyContext, HPy, HPy_buffer *, int);
78+
typedef void (*HPyFunc_releasebufferproc)(HPyContext, HPy, HPy_buffer *);
7579
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
@@ -11,6 +11,8 @@
1111
*/
1212

1313
typedef enum {
14+
HPy_bf_getbuffer = 1,
15+
HPy_bf_releasebuffer = 2,
1416
HPy_nb_absolute = 6,
1517
HPy_nb_add = 7,
1618
HPy_nb_and = 8,
@@ -61,6 +63,8 @@ typedef enum {
6163
HPy_tp_destroy = 1000,
6264
} HPySlot_Slot;
6365

66+
#define _HPySlot_SIG__HPy_bf_getbuffer HPyFunc_GETBUFFERPROC
67+
#define _HPySlot_SIG__HPy_bf_releasebuffer HPyFunc_RELEASEBUFFERPROC
6468
#define _HPySlot_SIG__HPy_nb_absolute HPyFunc_UNARYFUNC
6569
#define _HPySlot_SIG__HPy_nb_add HPyFunc_BINARYFUNC
6670
#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
@@ -90,6 +90,11 @@ HPyAPI_STORAGE double _HPy_IMPL_NAME(Float_AsDouble)(HPyContext ctx, HPy h)
9090
return PyFloat_AsDouble(_h2py(h));
9191
}
9292

93+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME(Bool_FromLong)(HPyContext ctx, long v)
94+
{
95+
return _py2h(PyBool_FromLong(v));
96+
}
97+
9398
HPyAPI_STORAGE HPy_ssize_t _HPy_IMPL_NAME_NOPREFIX(Length)(HPyContext ctx, HPy h)
9499
{
95100
return PyObject_Length(_h2py(h));
@@ -340,6 +345,11 @@ HPyAPI_STORAGE int _HPy_IMPL_NAME_NOPREFIX(SetItem)(HPyContext ctx, HPy obj, HPy
340345
return PyObject_SetItem(_h2py(obj), _h2py(key), _h2py(value));
341346
}
342347

348+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Type)(HPyContext ctx, HPy obj)
349+
{
350+
return _py2h(PyObject_Type(_h2py(obj)));
351+
}
352+
343353
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Repr)(HPyContext ctx, HPy obj)
344354
{
345355
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
@@ -9,6 +9,7 @@
99
typedef struct _object cpy_PyObject;
1010
typedef cpy_PyObject *(*cpy_PyCFunction)(cpy_PyObject *, cpy_PyObject *);
1111
typedef struct PyMethodDef cpy_PyMethodDef;
12+
typedef struct bufferinfo cpy_Py_buffer;
1213

1314

1415
#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
@@ -9,6 +9,8 @@ typedef enum {
99

1010
HPyFunc_DESTROYFUNC,
1111

12+
HPyFunc_GETBUFFERPROC,
13+
HPyFunc_RELEASEBUFFERPROC,
1214
HPyFunc_UNARYFUNC,
1315
HPyFunc_BINARYFUNC,
1416
HPyFunc_TERNARYFUNC,
@@ -70,6 +72,19 @@ typedef enum {
7072
enum { SYM##_sig = SIG }; \
7173
_HPyFunc_TRAMPOLINE_##SIG(SYM, IMPL)
7274

75+
typedef struct {
76+
void *buf;
77+
HPy obj; /* owned reference */
78+
HPy_ssize_t len;
79+
HPy_ssize_t itemsize;
80+
int readonly;
81+
int ndim;
82+
char *format;
83+
HPy_ssize_t *shape;
84+
HPy_ssize_t *strides;
85+
HPy_ssize_t *suboffsets;
86+
void *internal;
87+
} HPy_buffer;
7388

7489
#include "autogen_hpyfunc_declare.h"
7590

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ typedef struct {
2929
unsigned int flags;
3030
void *legacy_slots; // PyType_Slot *
3131
HPyDef **defines; /* points to an array of 'HPyDef *' */
32+
const char* doc; /* UTF-8 doc string or NULL */
3233
} HPyType_Spec;
3334

3435
typedef enum {

graalpython/com.oracle.graal.python.cext/include/common/runtime/ctx_object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
#include "hpy.h"
66

77
_HPy_HIDDEN void ctx_Dump(HPyContext ctx, HPy h);
8+
_HPy_HIDDEN int ctx_TypeCheck(HPyContext ctx, HPy h_obj, HPy h_type);
89

910
#endif /* HPY_COMMON_RUNTIME_CTX_OBJECT_H */
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22
// automatically generated by setup.py:get_scm_config()
3-
#define HPY_VERSION "0.1.dev965+g6d3b941"
4-
#define HPY_GIT_REVISION "6d3b941"
3+
#define HPY_VERSION "0.0.2.dev144+ng1d5d4c5"
4+
#define HPY_GIT_REVISION "1d5d4c5"

graalpython/com.oracle.graal.python.cext/include/cpython/hpy.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ typedef Py_hash_t HPy_hash_t;
4545

4646
// this should maybe autogenerated from public_api.h
4747
typedef struct _HPyContext_s {
48+
const char *name;
4849
/* Constants */
4950
HPy h_None;
5051
HPy h_True;
5152
HPy h_False;
53+
HPy h_NotImplemented;
54+
HPy h_Ellipsis;
5255
/* Exceptions */
5356
HPy h_BaseException;
5457
HPy h_Exception;
@@ -140,13 +143,14 @@ static inline void* HPy_AsVoidP(HPy h) { return (void*)h._o; }
140143
HPyAPI_FUNC(HPyContext)
141144
_HPyGetContext(void) {
142145
HPyContext ctx = &_global_ctx;
143-
if (HPy_IsNull(ctx->h_None)) {
144-
// XXX: we need to find a better way to check whether the ctx is
145-
// initialized or not
146+
if (!ctx->name) {
147+
ctx->name = "HPy CPython ABI",
146148
/* Constants */
147149
ctx->h_None = _py2h(Py_None);
148150
ctx->h_True = _py2h(Py_True);
149151
ctx->h_False = _py2h(Py_False);
152+
ctx->h_NotImplemented = _py2h(Py_NotImplemented);
153+
ctx->h_Ellipsis = _py2h(Py_Ellipsis);
150154
/* Exceptions */
151155
ctx->h_BaseException = _py2h(PyExc_BaseException);
152156
ctx->h_Exception = _py2h(PyExc_Exception);
@@ -329,6 +333,12 @@ _HPy_Dump(HPyContext ctx, HPy h)
329333
return ctx_Dump(ctx, h);
330334
}
331335

336+
HPyAPI_FUNC(int)
337+
HPy_TypeCheck(HPyContext ctx, HPy h_obj, HPy h_type)
338+
{
339+
return ctx_TypeCheck(ctx, h_obj, h_type);
340+
}
341+
332342
HPyAPI_FUNC(HPyListBuilder)
333343
HPyListBuilder_New(HPyContext ctx, HPy_ssize_t initial_size)
334344
{

graalpython/com.oracle.graal.python.cext/include/cpython/hpyfunc_trampolines.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,18 @@
6969
return _h2py(IMPL(_HPyGetContext(), _py2h(self), _py2h(obj), op)); \
7070
}
7171

72+
/* With the cpython ABI, Py_buffer and HPy_buffer are ABI-compatible.
73+
* Even though casting between them is technically undefined behavior, it
74+
* should always work. That way, we avoid a costly allocation and copy. */
75+
#define _HPyFunc_TRAMPOLINE_HPyFunc_GETBUFFERPROC(SYM, IMPL) \
76+
static int SYM(PyObject *arg0, Py_buffer *arg1, int arg2) \
77+
{ \
78+
return (IMPL(_HPyGetContext(), _py2h(arg0), (HPy_buffer*)arg1, arg2)); \
79+
}
80+
#define _HPyFunc_TRAMPOLINE_HPyFunc_RELEASEBUFFERPROC(SYM, IMPL) \
81+
static void SYM(PyObject *arg0, Py_buffer *arg1) \
82+
{ \
83+
return (IMPL(_HPyGetContext(), _py2h(arg0), (HPy_buffer*)arg1)); \
84+
}
85+
7286
#endif // HPY_CPYTHON_HPYFUNC_TRAMPOLINES_H

graalpython/com.oracle.graal.python.cext/include/universal/autogen_ctx.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
*/
1212

1313
struct _HPyContext_s {
14+
const char *name; // used just to make debugging and testing easier
15+
void *_private; // used by implementations to store custom data
1416
int ctx_version;
1517
HPy h_None;
1618
HPy h_True;
1719
HPy h_False;
20+
HPy h_NotImplemented;
21+
HPy h_Ellipsis;
1822
HPy h_BaseException;
1923
HPy h_Exception;
2024
HPy h_StopAsyncIteration;
@@ -104,6 +108,7 @@ struct _HPyContext_s {
104108
HPy_ssize_t (*ctx_Long_AsSsize_t)(HPyContext ctx, HPy h);
105109
HPy (*ctx_Float_FromDouble)(HPyContext ctx, double v);
106110
double (*ctx_Float_AsDouble)(HPyContext ctx, HPy h);
111+
HPy (*ctx_Bool_FromLong)(HPyContext ctx, long v);
107112
HPy_ssize_t (*ctx_Length)(HPyContext ctx, HPy h);
108113
int (*ctx_Number_Check)(HPyContext ctx, HPy h);
109114
HPy (*ctx_Add)(HPyContext ctx, HPy h1, HPy h2);
@@ -163,6 +168,8 @@ struct _HPyContext_s {
163168
int (*ctx_SetItem)(HPyContext ctx, HPy obj, HPy key, HPy value);
164169
int (*ctx_SetItem_i)(HPyContext ctx, HPy obj, HPy_ssize_t idx, HPy value);
165170
int (*ctx_SetItem_s)(HPyContext ctx, HPy obj, const char *key, HPy value);
171+
HPy (*ctx_Type)(HPyContext ctx, HPy obj);
172+
int (*ctx_TypeCheck)(HPyContext ctx, HPy obj, HPy type);
166173
void *(*ctx_Cast)(HPyContext ctx, HPy h);
167174
HPy (*ctx_New)(HPyContext ctx, HPy h_type, void **data);
168175
HPy (*ctx_Repr)(HPyContext ctx, HPy obj);

graalpython/com.oracle.graal.python.cext/include/universal/autogen_trampolines.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ static inline double HPyFloat_AsDouble(HPyContext ctx, HPy h) {
8686
return ctx->ctx_Float_AsDouble ( ctx, h );
8787
}
8888

89+
static inline HPy HPyBool_FromLong(HPyContext ctx, long v) {
90+
return ctx->ctx_Bool_FromLong ( ctx, v );
91+
}
92+
8993
static inline HPy_ssize_t HPy_Length(HPyContext ctx, HPy h) {
9094
return ctx->ctx_Length ( ctx, h );
9195
}
@@ -318,6 +322,14 @@ static inline int HPy_SetItem_s(HPyContext ctx, HPy obj, const char *key, HPy va
318322
return ctx->ctx_SetItem_s ( ctx, obj, key, value );
319323
}
320324

325+
static inline HPy HPy_Type(HPyContext ctx, HPy obj) {
326+
return ctx->ctx_Type ( ctx, obj );
327+
}
328+
329+
static inline int HPy_TypeCheck(HPyContext ctx, HPy obj, HPy type) {
330+
return ctx->ctx_TypeCheck ( ctx, obj, type );
331+
}
332+
321333
static inline void *_HPy_Cast(HPyContext ctx, HPy h) {
322334
return ctx->ctx_Cast ( ctx, h );
323335
}

graalpython/com.oracle.graal.python.cext/include/universal/hpyfunc_trampolines.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,34 @@ typedef struct {
118118
return a.result; \
119119
}
120120

121+
typedef struct {
122+
cpy_PyObject *self;
123+
cpy_Py_buffer *view;
124+
int flags;
125+
int result;
126+
} _HPyFunc_args_GETBUFFERPROC;
127+
128+
#define _HPyFunc_TRAMPOLINE_HPyFunc_GETBUFFERPROC(SYM, IMPL) \
129+
static int SYM(cpy_PyObject *self, cpy_Py_buffer *view, int flags) \
130+
{ \
131+
_HPyFunc_args_GETBUFFERPROC a = {self, view, flags}; \
132+
_HPy_CallRealFunctionFromTrampoline( \
133+
_ctx_for_trampolines, HPyFunc_GETBUFFERPROC, IMPL, &a); \
134+
return a.result; \
135+
}
136+
137+
typedef struct {
138+
cpy_PyObject *self;
139+
cpy_Py_buffer *view;
140+
} _HPyFunc_args_RELEASEBUFFERPROC;
141+
142+
#define _HPyFunc_TRAMPOLINE_HPyFunc_RELEASEBUFFERPROC(SYM, IMPL) \
143+
static void SYM(cpy_PyObject *self, cpy_Py_buffer *view) \
144+
{ \
145+
_HPyFunc_args_RELEASEBUFFERPROC a = {self, view}; \
146+
_HPy_CallRealFunctionFromTrampoline( \
147+
_ctx_for_trampolines, HPyFunc_RELEASEBUFFERPROC, IMPL, &a); \
148+
return; \
149+
}
150+
121151
#endif // HPY_UNIVERSAL_HPYFUNC_TRAMPOLINES_H

graalpython/lib-graalpython/modules/hpy/devel/src/runtime/ctx_object.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,27 @@ ctx_Dump(HPyContext ctx, HPy h)
1414
// about the handle itself in the future.
1515
_PyObject_Dump(_h2py(h));
1616
}
17+
18+
/* NOTE: contrarily to CPython, the HPy have to check that h_type is a
19+
type. On CPython it's not necessarily because it passes a PyTypeObject*,
20+
but here we can only receive an HPy.
21+
22+
However, we can't/don't want to raise an exception if you pass a non-type,
23+
because the CPython version (PyObject_TypeCheck) always succeed and it
24+
would be too easy to forget to check the return value. We just raise a
25+
fatal error instead.
26+
27+
Hopefully the slowdown is not too much. If it proves to be too much, we
28+
could say that the function is allowed to crash if you pass a non-type, and
29+
do the check only in debug mode.
30+
*/
31+
_HPy_HIDDEN int
32+
ctx_TypeCheck(HPyContext ctx, HPy h_obj, HPy h_type)
33+
{
34+
PyObject *type= _h2py(h_type);
35+
assert(type != NULL);
36+
if (!PyType_Check(type)) {
37+
Py_FatalError("HPy_TypeCheck arg 2 must be a type");
38+
}
39+
return PyObject_TypeCheck(_h2py(h_obj), (PyTypeObject*)type);
40+
}

0 commi 31A0 t comments

Comments
 (0)
0