Skip to content

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

0 commit comments

Comments
 (0)