Skip to content

Commit d794620

Browse files
committed
Update HPy inlined files: ef4faf0
1 parent 7803ae8 commit d794620

34 files changed

+1935
-433
lines changed

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

Lines changed: 206 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,176 @@ HPyAPI_STORAGE HPy _HPy_IMPL_NAME(Float_FromDouble)(HPyContext ctx, double v)
3333
return _py2h(PyFloat_FromDouble(v));
3434
}
3535

36-
HPyAPI_STORAGE HPy _HPy_IMPL_NAME(Number_Add)(HPyContext ctx, HPy h1, HPy h2)
36+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Add)(HPyContext ctx, HPy h1, HPy h2)
3737
{
3838
return _py2h(PyNumber_Add(_h2py(h1), _h2py(h2)));
3939
}
4040

41+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Subtract)(HPyContext ctx, HPy h1, HPy h2)
42+
{
43+
return _py2h(PyNumber_Subtract(_h2py(h1), _h2py(h2)));
44+
}
45+
46+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Multiply)(HPyContext ctx, HPy h1, HPy h2)
47+
{
48+
return _py2h(PyNumber_Multiply(_h2py(h1), _h2py(h2)));
49+
}
50+
51+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(MatrixMultiply)(HPyContext ctx, HPy h1, HPy h2)
52+
{
53+
return _py2h(PyNumber_MatrixMultiply(_h2py(h1), _h2py(h2)));
54+
}
55+
56+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(FloorDivide)(HPyContext ctx, HPy h1, HPy h2)
57+
{
58+
return _py2h(PyNumber_FloorDivide(_h2py(h1), _h2py(h2)));
59+
}
60+
61+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(TrueDivide)(HPyContext ctx, HPy h1, HPy h2)
62+
{
63+
return _py2h(PyNumber_TrueDivide(_h2py(h1), _h2py(h2)));
64+
}
65+
66+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Remainder)(HPyContext ctx, HPy h1, HPy h2)
67+
{
68+
return _py2h(PyNumber_Remainder(_h2py(h1), _h2py(h2)));
69+
}
70+
71+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Divmod)(HPyContext ctx, HPy h1, HPy h2)
72+
{
73+
return _py2h(PyNumber_Divmod(_h2py(h1), _h2py(h2)));
74+
}
75+
76+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Power)(HPyContext ctx, HPy h1, HPy h2, HPy h3)
77+
{
78+
return _py2h(PyNumber_Power(_h2py(h1), _h2py(h2), _h2py(h3)));
79+
}
80+
81+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Negative)(HPyContext ctx, HPy h1)
82+
{
83+
return _py2h(PyNumber_Negative(_h2py(h1)));
84+
}
85+
86+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Positive)(HPyContext ctx, HPy h1)
87+
{
88+
return _py2h(PyNumber_Positive(_h2py(h1)));
89+
}
90+
91+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Absolute)(HPyContext ctx, HPy h1)
92+
{
93+
return _py2h(PyNumber_Absolute(_h2py(h1)));
94+
}
95+
96+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Invert)(HPyContext ctx, HPy h1)
97+
{
98+
return _py2h(PyNumber_Invert(_h2py(h1)));
99+
}
100+
101+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Lshift)(HPyContext ctx, HPy h1, HPy h2)
102+
{
103+
return _py2h(PyNumber_Lshift(_h2py(h1), _h2py(h2)));
104+
}
105+
106+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Rshift)(HPyContext ctx, HPy h1, HPy h2)
107+
{
108+
return _py2h(PyNumber_Rshift(_h2py(h1), _h2py(h2)));
109+
}
110+
111+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(And)(HPyContext ctx, HPy h1, HPy h2)
112+
{
113+
return _py2h(PyNumber_And(_h2py(h1), _h2py(h2)));
114+
}
115+
116+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Xor)(HPyContext ctx, HPy h1, HPy h2)
117+
{
118+
return _py2h(PyNumber_Xor(_h2py(h1), _h2py(h2)));
119+
}
120+
121+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Or)(HPyContext ctx, HPy h1, HPy h2)
122+
{
123+
return _py2h(PyNumber_Or(_h2py(h1), _h2py(h2)));
124+
}
125+
126+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Index)(HPyContext ctx, HPy h1)
127+
{
128+
return _py2h(PyNumber_Index(_h2py(h1)));
129+
}
130+
131+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Long)(HPyContext ctx, HPy h1)
132+
{
133+
return _py2h(PyNumber_Long(_h2py(h1)));
134+
}
135+
136+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(Float)(HPyContext ctx, HPy h1)
137+
{
138+
return _py2h(PyNumber_Float(_h2py(h1)));
139+
}
140+
141+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(InPlaceAdd)(HPyContext ctx, HPy h1, HPy h2)
142+
{
143+
return _py2h(PyNumber_InPlaceAdd(_h2py(h1), _h2py(h2)));
144+
}
145+
146+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(InPlaceSubtract)(HPyContext ctx, HPy h1, HPy h2)
147+
{
148+
return _py2h(PyNumber_InPlaceSubtract(_h2py(h1), _h2py(h2)));
149+
}
150+
151+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(InPlaceMultiply)(HPyContext ctx, HPy h1, HPy h2)
152+
{
153+
return _py2h(PyNumber_InPlaceMultiply(_h2py(h1), _h2py(h2)));
154+
}
155+
156+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(InPlaceMatrixMultiply)(HPyContext ctx, HPy h1, HPy h2)
157+
{
158+
return _py2h(PyNumber_InPlaceMatrixMultiply(_h2py(h1), _h2py(h2)));
159+
}
160+
161+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(InPlaceFloorDivide)(HPyContext ctx, HPy h1, HPy h2)
162+
{
163+
return _py2h(PyNumber_InPlaceFloorDivide(_h2py(h1), _h2py(h2)));
164+
}
165+
166+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(InPlaceTrueDivide)(HPyContext ctx, HPy h1, HPy h2)
167+
{
168+
return _py2h(PyNumber_InPlaceTrueDivide(_h2py(h1), _h2py(h2)));
169+
}
170+
171+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(InPlaceRemainder)(HPyContext ctx, HPy h1, HPy h2)
172+
{
173+
return _py2h(PyNumber_InPlaceRemainder(_h2py(h1), _h2py(h2)));
174+
}
175+
176+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(InPlacePower)(HPyContext ctx, HPy h1, HPy h2, HPy h3)
177+
{
178+
return _py2h(PyNumber_InPlacePower(_h2py(h1), _h2py(h2), _h2py(h3)));
179+
}
180+
181+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(InPlaceLshift)(HPyContext ctx, HPy h1, HPy h2)
182+
{
183+
return _py2h(PyNumber_InPlaceLshift(_h2py(h1), _h2py(h2)));
184+
}
185+
186+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(InPlaceRshift)(HPyContext ctx, HPy h1, HPy h2)
187+
{
188+
return _py2h(PyNumber_InPlaceRshift(_h2py(h1), _h2py(h2)));
189+
}
190+
191+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(InPlaceAnd)(HPyContext ctx, HPy h1, HPy h2)
192+
{
193+
return _py2h(PyNumber_InPlaceAnd(_h2py(h1), _h2py(h2)));
194+
}
195+
196+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(InPlaceXor)(HPyContext ctx, HPy h1, HPy h2)
197+
{
198+
return _py2h(PyNumber_InPlaceXor(_h2py(h1), _h2py(h2)));
199+
}
200+
201+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(InPlaceOr)(HPyContext ctx, HPy h1, HPy h2)
202+
{
203+
return _py2h(PyNumber_InPlaceOr(_h2py(h1), _h2py(h2)));
204+
}
205+
41206
HPyAPI_STORAGE void _HPy_IMPL_NAME(Err_SetString)(HPyContext ctx, HPy h_type, const char *message)
42207
{
43208
return PyErr_SetString(_h2py(h_type), message);
@@ -48,6 +213,46 @@ HPyAPI_STORAGE int _HPy_IMPL_NAME(Object_IsTrue)(HPyContext ctx, HPy h)
48213
return PyObject_IsTrue(_h2py(h));
49214
}
50215

216+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(GetAttr)(HPyContext ctx, HPy obj, HPy name)
217+
{
218+
return _py2h(PyObject_GetAttr(_h2py(obj), _h2py(name)));
219+
}
220+
221+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(GetAttr_s)(HPyContext ctx, HPy obj, const char *name)
222+
{
223+
return _py2h(PyObject_GetAttrString(_h2py(obj), name));
224+
}
225+
226+
HPyAPI_STORAGE int _HPy_IMPL_NAME_NOPREFIX(HasAttr)(HPyContext ctx, HPy obj, HPy name)
227+
{
228+
return PyObject_HasAttr(_h2py(obj), _h2py(name));
229+
}
230+
231+
HPyAPI_STORAGE int _HPy_IMPL_NAME_NOPREFIX(HasAttr_s)(HPyContext ctx, HPy obj, const char *name)
232+
{
233+
return PyObject_HasAttrString(_h2py(obj), name);
234+
}
235+
236+
HPyAPI_STORAGE int _HPy_IMPL_NAME_NOPREFIX(SetAttr)(HPyContext ctx, HPy obj, HPy name, HPy value)
237+
{
238+
return PyObject_SetAttr(_h2py(obj), _h2py(name), _h2py(value));
239+
}
240+
241+
HPyAPI_STORAGE int _HPy_IMPL_NAME_NOPREFIX(SetAttr_s)(HPyContext ctx, HPy obj, const char *name, HPy value)
242+
{
243+
return PyObject_SetAttrString(_h2py(obj), name, _h2py(value));
244+
}
245+
246+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(GetItem)(HPyContext ctx, HPy obj, HPy key)
247+
{
248+
return _py2h(PyObject_GetItem(_h2py(obj), _h2py(key)));
249+
}
250+
251+
HPyAPI_STORAGE int _HPy_IMPL_NAME_NOPREFIX(SetItem)(HPyContext ctx, HPy obj, HPy key, HPy value)
252+
{
253+
return PyObject_SetItem(_h2py(obj), _h2py(key), _h2py(value));
254+
}
255+
51256
HPyAPI_STORAGE int _HPy_IMPL_NAME(Bytes_Check)(HPyContext ctx, HPy h)
52257
{
53258
return PyBytes_Check(_h2py(h));
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef HPY_UNIVERSAL_CPY_TYPES_H
2+
#define HPY_UNIVERSAL_CPY_TYPES_H
3+
4+
/* generally speaking, we can't #include Python.h, but there are a bunch of
5+
* types defined there that we need to use. Here, we redefine all the types
6+
* we need, with a cpy_ prefix.
7+
*/
8+
9+
typedef struct _object cpy_PyObject;
10+
typedef cpy_PyObject *(*cpy_PyCFunction)(cpy_PyObject *, cpy_PyObject *);
11+
typedef struct PyMethodDef cpy_PyMethodDef;
12+
13+
14+
#endif /* HPY_UNIVERSAL_CPY_TYPES_H */
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#ifndef HPY_UNIVERSAL_HPYDEF_H
2+
#define HPY_UNIVERSAL_HPYDEF_H
3+
4+
#include "common/hpyfunc.h"
5+
#include "common/typeslots.h"
6+
7+
typedef struct {
8+
HPySlot_Slot slot; // The slot to fill
9+
void *impl; // Function pointer to the implementation
10+
void *cpy_trampoline; // Used by CPython to call impl
11+
} HPySlot;
12+
13+
typedef struct {
14+
const char *name; // The name of the built-in function/method
15+
const char *doc; // The __doc__ attribute, or NULL
16+
void *impl; // Function pointer to the implementation
17+
void *cpy_trampoline; // Used by CPython to call impl
18+
HPyFunc_Signature signature; // Indicates impl's expected the signature
19+
} HPyMeth;
20+
21+
/*
22+
typedef struct {
23+
...
24+
} HPyMember;
25+
26+
typedef struct {
27+
...
28+
} HPyGetSet;
29+
*/
30+
31+
typedef enum {
32+
HPyDef_Kind_Slot = 1,
33+
HPyDef_Kind_Meth = 2
34+
// HPyDef_Kind_Member = 3,
35+
// HPyDef_Kind_GetSet = 4,
36+
} HPyDef_Kind;
37+
38+
typedef struct {
39+
HPyDef_Kind kind;
40+
union {
41+
HPySlot slot;
42+
HPyMeth meth;
43+
// HPyMember member;
44+
// HPyGetSet getset;
45+
};
46+
} HPyDef;
47+
48+
// macros to automatically define HPyDefs of various kinds
49+
50+
#define HPyDef_SLOT(SYM, SLOT, IMPL, SIG) \
51+
HPyFunc_DECLARE(IMPL, SIG); \
52+
HPyFunc_TRAMPOLINE(SYM##_trampoline, IMPL, SIG); \
53+
HPyDef SYM = { \
54+
.kind = HPyDef_Kind_Slot, \
55+
.slot = { \
56+
.slot = SLOT, \
57+
.impl = IMPL, \
58+
.cpy_trampoline = SYM##_trampoline \
59+
} \
60+
};
61+
62+
63+
#define HPyDef_METH(SYM, NAME, IMPL, SIG) \
64+
HPyFunc_DECLARE(IMPL, SIG); \
65+
HPyFunc_TRAMPOLINE(SYM##_trampoline, IMPL, SIG); \
66+
HPyDef SYM = { \
67+
.kind = HPyDef_Kind_Meth, \
68+
.meth = { \
69+
.name = NAME, \
70+
.impl = IMPL, \
71+
.cpy_trampoline = SYM##_trampoline, \
72+
.signature = SIG \
73+
} \
74+
};
75+
76+
#endif /* HPY_UNIVERSAL_HPYDEF_H */
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#ifndef HPY_UNIVERSAL_HPYFUNC_H
2+
#define HPY_UNIVERSAL_HPYFUNC_H
3+
4+
typedef enum {
5+
HPyFunc_VARARGS = 1, // METH_VARARGS
6+
HPyFunc_KEYWORDS = 2, // METH_VARARGS | METH_KEYWORDS
7+
HPyFunc_NOARGS = 3, // METH_NOARGS
8+
HPyFunc_O = 4 // METH_O
9+
} HPyFunc_Signature;
10+
11+
// typedefs corresponding to the various HPyFunc_Signature members
12+
typedef HPy (*HPyFunc_noargs)(HPyContext ctx, HPy self);
13+
typedef HPy (*HPyFunc_o)(HPyContext ctx, HPy self, HPy arg);
14+
typedef HPy (*HPyFunc_varargs)(HPyContext ctx, HPy self, HPy *args, HPy_ssize_t nargs);
15+
typedef HPy (*HPyFunc_keywords)(HPyContext ctx, HPy self,
16+
HPy *args, HPy_ssize_t nargs, HPy kw);
17+
18+
19+
/* Emit a forward declaration for a function SYM having a signature SIG, where
20+
SIG is one of HPyFunc_Signature members.
21+
22+
Strictly speaking, the anonymous enum is not needed, since it just defines
23+
a constant like Foo_sig which is never used anyway. However, since we try
24+
to use "SIG" in the enum definition, we get a very nice error message in
25+
case we use a SIG value which does not exists. If we didn't use this
26+
trick, we would get a VERY obscure error message, since gcc would see a
27+
function call to something like _HPyFunc_DECLARE_HPyFunc_XXX.
28+
*/
29+
#define HPyFunc_DECLARE(SYM, SIG) \
30+
enum { SYM##_sig = SIG }; \
31+
_HPyFunc_DECLARE_##SIG(SYM)
32+
33+
34+
/* Emit a CPython-compatible trampoline which calls IMPL, where IMPL has the
35+
signature SIG. See above for why we need the anonymous enum. The actual
36+
implementation of trampolines are in hpyfunc_trampolines.h, which is
37+
different for the CPython and Universal cases */
38+
#define HPyFunc_TRAMPOLINE(SYM, IMPL, SIG) \
39+
enum { SYM##_sig = SIG }; \
40+
_HPyFunc_TRAMPOLINE_##SIG(SYM, IMPL)
41+
42+
43+
// these should be autogenerated
44+
45+
#define _HPyFunc_DECLARE_HPyFunc_NOARGS(SYM) \
46+
static HPy SYM(HPyContext ctx, HPy self)
47+
48+
#define _HPyFunc_DECLARE_HPyFunc_O(SYM) \
49+
static HPy SYM(HPyContext ctx, HPy self, HPy arg)
50+
51+
#define _HPyFunc_DECLARE_HPyFunc_VARARGS(SYM) \
52+
static HPy SYM(HPyContext ctx, HPy self, HPy *args, HPy_ssize_t nargs);
53+
54+
#define _HPyFunc_DECLARE_HPyFunc_KEYWORDS(SYM) \
55+
static HPy SYM(HPyContext ctx, HPy self, HPy *args, HPy_ssize_t nargs, HPy kw);
56+
57+
58+
#ifdef HPY_UNIVERSAL_ABI
59+
# include "universal/hpyfunc_trampolines.h"
60+
#else
61+
# include "cpython/hpyfunc_trampolines.h"
62+
#endif // HPY_UNIVERSAL_ABI
63+
64+
#endif /* HPY_UNIVERSAL_HPYFUNC_H */

0 commit comments

Comments
 (0)