Skip to content

Commit 5cecc35

Browse files
committed
Update HPy inlined files: f941e8f
1 parent d222c34 commit 5cecc35

File tree

17 files changed

+412
-97
lines changed

17 files changed

+412
-97
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ extern "C" {
4141
# define _hconv(h) {h}
4242
# define _hfconv(h) {h}
4343
# define _htsconv(h) {h}
44+
# define _hgconv(h) {h}
4445
#else
4546
# define _hconv(h) ((HPy){h})
4647
# define _hfconv(h) ((HPyField){h})
4748
# define _htsconv(h) ((HPyThreadState){h})
49+
# define _hgconv(h) ((HPyGlobal){h})
4850
#endif
4951
/* ~~~~~~~~~~~~~~~~ HPyAPI declaration ~~~~~~~~~~~~~~~~ */
5052

@@ -109,6 +111,7 @@ extern "C" {
109111
*/
110112
typedef struct _HPy_s { intptr_t _i; } HPy;
111113
typedef struct { intptr_t _i; } HPyField;
114+
typedef struct { intptr_t _i; } HPyGlobal;
112115
typedef struct { intptr_t _lst; } HPyListBuilder;
113116
typedef struct { intptr_t _tup; } HPyTupleBuilder;
114117
typedef struct { intptr_t _i; } HPyTracker;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ HPyAPI_FUNC HPy_ssize_t HPyLong_AsSsize_t(HPyContext *ctx, HPy h)
8080
return PyLong_AsSsize_t(_h2py(h));
8181
}
8282

83+
HPyAPI_FUNC void *HPyLong_AsVoidPtr(HPyContext *ctx, HPy h)
84+
{
85+
return PyLong_AsVoidPtr(_h2py(h));
86+
}
87+
88+
HPyAPI_FUNC double HPyLong_AsDouble(HPyContext *ctx, HPy h)
89+
{
90+
return PyLong_AsDouble(_h2py(h));
91+
}
92+
8393
HPyAPI_FUNC HPy HPyFloat_FromDouble(HPyContext *ctx, double v)
8494
{
8595
return _py2h(PyFloat_FromDouble(v));
@@ -334,6 +344,11 @@ HPyAPI_FUNC int HPyErr_WarnEx(HPyContext *ctx, HPy category, const char *message
334344
return PyErr_WarnEx(_h2py(category), message, stack_level);
335345
}
336346

347+
HPyAPI_FUNC void HPyErr_WriteUnraisable(HPyContext *ctx, HPy obj)
348+
{
349+
PyErr_WriteUnraisable(_h2py(obj));
350+
}
351+
337352
HPyAPI_FUNC int HPy_IsTrue(HPyContext *ctx, HPy h)
338353
{
339354
return PyObject_IsTrue(_h2py(h));

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ static inline PyObject * _hf2py(HPyField hf)
3333
return _h2py(h);
3434
}
3535

36+
static inline HPyGlobal _py2hg(PyObject *obj)
37+
{
38+
HPy h = _py2h(obj);
39+
return _hgconv(._i = h._i);
40+
}
41+
42+
static inline PyObject * _hg2py(HPyGlobal hf)
43+
{
44+
HPy h = { ._i = hf._i };
45+
return _h2py(h);
46+
}
47+
3648
// this should maybe autogenerated from public_api.h
3749
struct _HPyContext_s {
3850
const char *name;
@@ -226,9 +238,10 @@ HPyAPI_FUNC void HPyField_Store(HPyContext *ctx, HPy target_obj,
226238
HPyField *target_field, HPy h)
227239
{
228240
PyObject *obj = _h2py(h);
229-
Py_XDECREF(_hf2py(*target_field));
241+
PyObject *target_py_obj = _hf2py(*target_field);
230242
Py_XINCREF(obj);
231243
*target_field = _py2hf(obj);
244+
Py_XDECREF(target_py_obj);
232245
}
233246

234247
HPyAPI_FUNC HPy HPyField_Load(HPyContext *ctx, HPy source_obj, HPyField source_field)
@@ -238,6 +251,21 @@ HPyAPI_FUNC HPy HPyField_Load(HPyContext *ctx, HPy source_obj, HPyField source_f
238251
return _py2h(obj);
239252
}
240253

254+
HPyAPI_FUNC void HPyGlobal_Store(HPyContext *ctx, HPyGlobal *global, HPy h)
255+
{
256+
PyObject *obj = _h2py(h);
257+
Py_XDECREF(_hg2py(*global));
258+
Py_XINCREF(obj);
259+
*global = _py2hg(obj);
260+
}
261+
262+
HPyAPI_FUNC HPy HPyGlobal_Load(HPyContext *ctx, HPyGlobal global)
263+
{
264+
PyObject *obj = _hg2py(global);
265+
Py_INCREF(obj);
266+
return _py2h(obj);
267+
}
268+
241269
HPyAPI_FUNC HPy HPy_FromPyObject(HPyContext *ctx, PyObject *obj)
242270
{
243271
Py_XINCREF(obj);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ typedef struct {
1919
HPy_ssize_t size;
2020
cpy_PyMethodDef *legacy_methods;
2121
HPyDef **defines; /* points to an array of 'HPyDef *' */
22+
/* array with pointers to statically allocated HPyGlobal,
23+
* with NULL at the end as a sentinel. */
24+
HPyGlobal **globals;
2225
} HPyModuleDef;
2326

2427

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

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,30 @@ typedef struct {
1313
int basicsize;
1414
int itemsize;
1515
unsigned long flags;
16+
/*
17+
A type whose struct starts with PyObject_HEAD is a legacy type. A
18+
legacy type must set .legacy = true in its HPyType_Spec.
19+
A type is a non-legacy type, also called HPy pure type, if its struct
20+
does not include PyObject_HEAD. Using pure types should be preferred.
21+
Legacy types are available to allow gradual porting of existing CPython
22+
extensions.
23+
24+
A type with .legacy_slots not NULL is required to have .legacy = true and to
25+
include PyObject_HEAD at the start of its struct. It would be easy to
26+
relax this requirement on CPython (where the PyObject_HEAD fields are
27+
always present) but a large burden on other implementations (e.g. PyPy,
28+
GraalPython) where a struct starting with PyObject_HEAD might not exist.
29+
30+
Types that do not define a struct of their own, should set the value of
31+
.legacy to the same value as the type they inherit from. If they inherit
32+
from a built-in type, they may set .legacy to either true or false, depending
33+
on whether they still use .legacy_slots or not.
34+
35+
Pure HPy types that inherit a builtin type and define their own struct are
36+
not supported at the moment. One can use legacy types in the meanwhile.
37+
38+
Types created via the old Python C API are automatically legacy types.
39+
*/
1640
int legacy;
1741
void *legacy_slots; // PyType_Slot *
1842
HPyDef **defines; /* points to an array of 'HPyDef *' */
@@ -36,37 +60,6 @@ typedef struct {
3660
#define _Py_TPFLAGS_HAVE_VERSION_TAG (1UL << 18)
3761
#define HPy_TPFLAGS_DEFAULT (_Py_TPFLAGS_HEAPTYPE | _Py_TPFLAGS_HAVE_VERSION_TAG)
3862

39-
/* HPy_TPFLAGS_INTERNAL_PURE is set automatically on pure types created with
40-
HPyType_FromSpec. This flag should not be used directly. Set
41-
`.legacy = false` or `.legacy = true` instead.
42-
43-
A custom type is a pure type if its struct does not include PyObject_HEAD.
44-
A type whose struct does start with PyObject_HEAD is a legacy type. A
45-
legacy type must set .legacy = true in its HPyType_Spec.
46-
47-
A type with .legacy_slots not NULL is required to have .legacy = true and to
48-
include PyObject_HEAD at the start of its struct. It would be easy to
49-
relax this requirement on CPython (where the PyObject_HEAD fields are
50-
always present) but a large burden on other implementations (e.g. PyPy,
51-
GraalPython) where a struct starting with PyObject_HEAD might not exist.
52-
53-
Types that do not define a struct of their own, should set the value of
54-
.legacy to the same value as the type they inherit from. If they inherit
55-
from a built-in type, they may .legacy to either true or false, depending on
56-
whether they still use .legacy_slots or not.
57-
58-
Types created via the old Python C API are automatically legacy types.
59-
60-
Note on the choice of bit 8: Bit 8 looks likely to be the last free TPFLAG
61-
bit that C Python will allocate. Bits 0 to 8 were dropped in Python 3.0 and
62-
are being re-allocated slowly from 0 towards 8. As of 3.10, only bit 0 has
63-
been re-allocated.
64-
*/
65-
#define HPy_TPFLAGS_INTERNAL_PURE (1UL << 8)
66-
67-
#define HPy_TPFLAGS_INTERNAL_IS_HPY_TYPE (1UL << 7)
68-
69-
7063
/* Set if the type allows subclassing */
7164
#define HPy_TPFLAGS_BASETYPE (1UL << 10)
7265

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ struct _HPyContext_s {
108108
unsigned long long (*ctx_Long_AsUnsignedLongLongMask)(HPyContext *ctx, HPy h);
109109
size_t (*ctx_Long_AsSize_t)(HPyContext *ctx, HPy h);
110110
HPy_ssize_t (*ctx_Long_AsSsize_t)(HPyContext *ctx, HPy h);
111+
void *(*ctx_Long_AsVoidPtr)(HPyContext *ctx, HPy h);
112+
double (*ctx_Long_AsDouble)(HPyContext *ctx, HPy h);
111113
HPy (*ctx_Float_FromDouble)(HPyContext *ctx, double v);
112114
double (*ctx_Float_AsDouble)(HPyContext *ctx, HPy h);
113115
HPy (*ctx_Bool_FromLong)(HPyContext *ctx, long v);
@@ -161,6 +163,7 @@ struct _HPyContext_s {
161163
HPy (*ctx_Err_NewException)(HPyContext *ctx, const char *name, HPy base, HPy dict);
162164
HPy (*ctx_Err_NewExceptionWithDoc)(HPyContext *ctx, const char *name, const char *doc, HPy base, HPy dict);
163165
int (*ctx_Err_WarnEx)(HPyContext *ctx, HPy category, const char *message, HPy_ssize_t stack_level);
166+
void (*ctx_Err_WriteUnraisable)(HPyContext *ctx, HPy obj);
164167
int (*ctx_IsTrue)(HPyContext *ctx, HPy h);
165168
HPy (*ctx_Type_FromSpec)(HPyContext *ctx, HPyType_Spec *spec, HPyType_SpecParam *params);
166169
HPy (*ctx_Type_GenericNew)(HPyContext *ctx, HPy type, HPy *args, HPy_ssize_t nargs, HPy kw);
@@ -237,5 +240,7 @@ struct _HPyContext_s {
237240
HPy (*ctx_Field_Load)(HPyContext *ctx, HPy source_object, HPyField source_field);
238241
HPyThreadState (*ctx_LeavePythonExecution)(HPyContext *ctx);
239242
void (*ctx_ReenterPythonExecution)(HPyContext *ctx, HPyThreadState state);
243+
void (*ctx_Global_Store)(HPyContext *ctx, HPyGlobal *global, HPy h);
244+
HPy (*ctx_Global_Load)(HPyContext *ctx, HPyGlobal global);
240245
void (*ctx_Dump)(HPyContext *ctx, HPy h);
241246
};

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ HPyAPI_FUNC HPy_ssize_t HPyLong_AsSsize_t(HPyContext *ctx, HPy h) {
7878
return ctx->ctx_Long_AsSsize_t ( ctx, h );
7979
}
8080

81+
HPyAPI_FUNC void *HPyLong_AsVoidPtr(HPyContext *ctx, HPy h) {
82+
return ctx->ctx_Long_AsVoidPtr ( ctx, h );
83+
}
84+
85+
HPyAPI_FUNC double HPyLong_AsDouble(HPyContext *ctx, HPy h) {
86+
return ctx->ctx_Long_AsDouble ( ctx, h );
87+
}
88+
8189
HPyAPI_FUNC HPy HPyFloat_FromDouble(HPyContext *ctx, double v) {
8290
return ctx->ctx_Float_FromDouble ( ctx, v );
8391
}
@@ -286,6 +294,10 @@ HPyAPI_FUNC int HPyErr_WarnEx(HPyContext *ctx, HPy category, const char *message
286294
return ctx->ctx_Err_WarnEx ( ctx, category, message, stack_level );
287295
}
288296

297+
HPyAPI_FUNC void HPyErr_WriteUnraisable(HPyContext *ctx, HPy obj) {
298+
ctx->ctx_Err_WriteUnraisable ( ctx, obj );
299+
}
300+
289301
HPyAPI_FUNC int HPy_IsTrue(HPyContext *ctx, HPy h) {
290302
return ctx->ctx_IsTrue ( ctx, h );
291303
}
@@ -586,6 +598,14 @@ HPyAPI_FUNC void HPy_ReenterPythonExecution(HPyContext *ctx, HPyThreadState stat
586598
ctx->ctx_ReenterPythonExecution ( ctx, state );
587599
}
588600

601+
HPyAPI_FUNC void HPyGlobal_Store(HPyContext *ctx, HPyGlobal *global, HPy h) {
602+
ctx->ctx_Global_Store ( ctx, global, h );
603+
}
604+
605+
HPyAPI_FUNC HPy HPyGlobal_Load(HPyContext *ctx, HPyGlobal global) {
606+
return ctx->ctx_Global_Load ( ctx, global );
607+
}
608+
589609
HPyAPI_FUNC void _HPy_Dump(HPyContext *ctx, HPy h) {
590610
ctx->ctx_Dump ( ctx, h );
591611
}
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.0.4.dev195+g91734aa"
4-
#define HPY_GIT_REVISION "91734aa"
3+
#define HPY_VERSION "0.0.4.dev216+gf941e8f"
4+
#define HPY_GIT_REVISION "f941e8f"

0 commit comments

Comments
 (0)