Skip to content

Commit fb2a310

Browse files
committed
[GR-29198] [GR-26596] Update HPy Import.
PullRequest: graalpython/1599
2 parents 6d280f5 + bbb0cfd commit fb2a310

Some content is hidden

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

51 files changed

+3862
-1033
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ void* graal_hpy_from_string(const char *ptr) {
281281
return polyglot_from_string(ptr, SRC_CS);
282282
}
283283

284+
uint64_t graal_hpy_strlen(const char *ptr) {
285+
return strlen(ptr);
286+
}
287+
284288
/* getters for HPyType_Spec */
285289

286290
void* graal_hpy_type_spec_get_defines(HPyType_Spec *type_spec) {
@@ -412,11 +416,15 @@ double graal_hpy_read_d(void* object, HPy_ssize_t offset) {
412416
}
413417

414418
void* graal_hpy_read_string(void* object, HPy_ssize_t offset) {
415-
return polyglot_from_string(ReadMember(object, offset, char*), "utf-8");
419+
char *ptr = ReadMember(object, offset, char*);
420+
if (ptr != NULL) {
421+
return polyglot_from_string(ReadMember(object, offset, char*), "utf-8");
422+
}
423+
return NULL;
416424
}
417425

418426
void* graal_hpy_read_string_in_place(void* object, HPy_ssize_t offset) {
419-
char *addr = (char*) (((char*)object) + offset);
427+
char *addr = (char*) (((char*)object) + offset);
420428
return polyglot_from_string(addr, "utf-8");
421429
}
422430

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#define _HPyFunc_DECLARE_HPyFunc_INITPROC(SYM) static int SYM(HPyContext ctx, HPy self, HPy *args, HPy_ssize_t nargs, HPy kw)
6161
#define _HPyFunc_DECLARE_HPyFunc_GETTER(SYM) static HPy SYM(HPyContext ctx, HPy, void *)
6262
#define _HPyFunc_DECLARE_HPyFunc_SETTER(SYM) static int SYM(HPyContext ctx, HPy, HPy, void *)
63+
#define _HPyFunc_DECLARE_HPyFunc_OBJOBJPROC(SYM) static int SYM(HPyContext ctx, HPy, HPy)
6364
#define _HPyFunc_DECLARE_HPyFunc_DESTROYFUNC(SYM) static void SYM(void *)
6465

6566
typedef HPy (*HPyFunc_noargs)(HPyContext ctx, HPy self);
@@ -91,4 +92,5 @@ typedef int (*HPyFunc_descrsetfunc)(HPyContext ctx, HPy, HPy, HPy);
9192
typedef int (*HPyFunc_initproc)(HPyContext ctx, HPy self, HPy *args, HPy_ssize_t nargs, HPy kw);
9293
typedef HPy (*HPyFunc_getter)(HPyContext ctx, HPy, void *);
9394
typedef int (*HPyFunc_setter)(HPyContext ctx, HPy, HPy, void *);
95+
typedef int (*HPyFunc_objobjproc)(HPyContext ctx, HPy, HPy);
9496
typedef void (*HPyFunc_destroyfunc)(void *);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,14 @@ typedef enum {
6565
HPy_nb_subtract = 36,
6666
HPy_nb_true_divide = 37,
6767
HPy_nb_xor = 38,
68+
HPy_sq_ass_item = 39,
69+
HPy_sq_concat = 40,
70+
HPy_sq_contains = 41,
71+
HPy_sq_inplace_concat = 42,
72+
HPy_sq_inplace_repeat = 43,
6873
HPy_sq_item = 44,
6974
HPy_sq_length = 45,
75+
HPy_sq_repeat = 46,
7076
HPy_tp_init = 60,
7177
HPy_tp_new = 65,
7278
HPy_tp_repr = 66,
@@ -108,8 +114,14 @@ typedef enum {
108114
#define _HPySlot_SIG__HPy_nb_subtract HPyFunc_BINARYFUNC
109115
#define _HPySlot_SIG__HPy_nb_true_divide HPyFunc_BINARYFUNC
110116
#define _HPySlot_SIG__HPy_nb_xor HPyFunc_BINARYFUNC
117+
#define _HPySlot_SIG__HPy_sq_ass_item HPyFunc_SSIZEOBJARGPROC
118+
#define _HPySlot_SIG__HPy_sq_concat HPyFunc_BINARYFUNC
119+
#define _HPySlot_SIG__HPy_sq_contains HPyFunc_OBJOBJPROC
120+
#define _HPySlot_SIG__HPy_sq_inplace_concat HPyFunc_BINARYFUNC
121+
#define _HPySlot_SIG__HPy_sq_inplace_repeat HPyFunc_SSIZEARGFUNC
111122
#define _HPySlot_SIG__HPy_sq_item HPyFunc_SSIZEARGFUNC
112123
#define _HPySlot_SIG__HPy_sq_length HPyFunc_LENFUNC
124+
#define _HPySlot_SIG__HPy_sq_repeat HPyFunc_SSIZEARGFUNC
113125
#define _HPySlot_SIG__HPy_tp_init HPyFunc_INITPROC
114126
#define _HPySlot_SIG__HPy_tp_new HPyFunc_KEYWORDS
115127
#define _HPySlot_SIG__HPy_tp_repr HPyFunc_REPRFUNC

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

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,41 @@ HPyAPI_STORAGE long _HPy_IMPL_NAME(Long_AsLong)(HPyContext ctx, HPy h)
6666
return PyLong_AsLong(_h2py(h));
6767
}
6868

69+
HPyAPI_STORAGE unsigned long _HPy_IMPL_NAME(Long_AsUnsignedLong)(HPyContext ctx, HPy h)
70+
{
71+
return PyLong_AsUnsignedLong(_h2py(h));
72+
}
73+
74+
HPyAPI_STORAGE unsigned long _HPy_IMPL_NAME(Long_AsUnsignedLongMask)(HPyContext ctx, HPy h)
75+
{
76+
return PyLong_AsUnsignedLongMask(_h2py(h));
77+
}
78+
79+
HPyAPI_STORAGE long long _HPy_IMPL_NAME(Long_AsLongLong)(HPyContext ctx, HPy h)
80+
{
81+
return PyLong_AsLongLong(_h2py(h));
82+
}
83+
84+
HPyAPI_STORAGE unsigned long long _HPy_IMPL_NAME(Long_AsUnsignedLongLong)(HPyContext ctx, HPy h)
85+
{
86+
return PyLong_AsUnsignedLongLong(_h2py(h));
87+
}
88+
89+
HPyAPI_STORAGE unsigned long long _HPy_IMPL_NAME(Long_AsUnsignedLongLongMask)(HPyContext ctx, HPy h)
90+
{
91+
return PyLong_AsUnsignedLongLongMask(_h2py(h));
92+
}
93+
94+
HPyAPI_STORAGE size_t _HPy_IMPL_NAME(Long_AsSize_t)(HPyContext ctx, HPy h)
95+
{
96+
return PyLong_AsSize_t(_h2py(h));
97+
}
98+
99+
HPyAPI_STORAGE HPy_ssize_t _HPy_IMPL_NAME(Long_AsSsize_t)(HPyContext ctx, HPy h)
100+
{
101+
return PyLong_AsSsize_t(_h2py(h));
102+
}
103+
69104
HPyAPI_STORAGE HPy _HPy_IMPL_NAME(Float_FromDouble)(HPyContext ctx, double v)
70105
{
71106
return _py2h(PyFloat_FromDouble(v));
@@ -261,11 +296,21 @@ HPyAPI_STORAGE void _HPy_IMPL_NAME(Err_SetString)(HPyContext ctx, HPy h_type, co
261296
PyErr_SetString(_h2py(h_type), message);
262297
}
263298

299+
HPyAPI_STORAGE void _HPy_IMPL_NAME(Err_SetObject)(HPyContext ctx, HPy h_type, HPy h_value)
300+
{
301+
PyErr_SetObject(_h2py(h_type), _h2py(h_value));
302+
}
303+
264304
HPyAPI_STORAGE HPy _HPy_IMPL_NAME(Err_NoMemory)(HPyContext ctx)
265305
{
266306
return _py2h(PyErr_NoMemory());
267307
}
268308

309+
HPyAPI_STORAGE void _HPy_IMPL_NAME(Err_Clear)(HPyContext ctx)
310+
{
311+
PyErr_Clear();
312+
}
313+
269314
HPyAPI_STORAGE int _HPy_IMPL_NAME_NOPREFIX(IsTrue)(HPyContext ctx, HPy h)
270315
{
271316
return PyObject_IsTrue(_h2py(h));
@@ -371,6 +416,16 @@ HPyAPI_STORAGE char *_HPy_IMPL_NAME(Bytes_AS_STRING)(HPyContext ctx, HPy h)
371416
return PyBytes_AS_STRING(_h2py(h));
372417
}
373418

419+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME(Bytes_FromString)(HPyContext ctx, const char *v)
420+
{
421+
return _py2h(PyBytes_FromString(v));
422+
}
423+
424+
HPyAPI_STORAGE HPy _HPy_IMPL_NAME(Bytes_FromStringAndSize)(HPyContext ctx, const char *v, HPy_ssize_t len)
425+
{
426+
return _py2h(PyBytes_FromStringAndSize(v, len));
427+
}
428+
374429
HPyAPI_STORAGE HPy _HPy_IMPL_NAME(Unicode_FromString)(HPyContext ctx, const char *utf8)
375430
{
376431
return _py2h(PyUnicode_FromString(utf8));
@@ -416,13 +471,3 @@ HPyAPI_STORAGE HPy _HPy_IMPL_NAME(Dict_New)(HPyContext ctx)
416471
return _py2h(PyDict_New());
417472
}
418473

419-
HPyAPI_STORAGE int _HPy_IMPL_NAME(Dict_SetItem)(HPyContext ctx, HPy h_dict, HPy h_key, HPy h_val)
420-
{
421-
return PyDict_SetItem(_h2py(h_dict), _h2py(h_key), _h2py(h_val));
422-
}
423-
424-
HPyAPI_STORAGE HPy _HPy_IMPL_NAME(Dict_GetItem)(HPyContext ctx, HPy h_dict, HPy h_key)
425-
{
426-
return _py2h(PyDict_GetItem(_h2py(h_dict), _h2py(h_key)));
427-
}
428-

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ typedef enum {
5858
HPyFunc_INITPROC,
5959
HPyFunc_GETTER,
6060
HPyFunc_SETTER,
61+
HPyFunc_OBJOBJPROC,
6162

6263
} HPyFunc_Signature;
6364

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ typedef struct {
6969

7070
/* All types are dynamically allocated */
7171
#define _Py_TPFLAGS_HEAPTYPE (1UL << 9)
72+
#define _Py_TPFLAGS_HAVE_VERSION_TAG (1UL << 18)
7273

7374
/* Set if the type allows subclassing */
7475
#define HPy_TPFLAGS_BASETYPE (1UL << 10)
7576

76-
#define HPy_TPFLAGS_DEFAULT _Py_TPFLAGS_HEAPTYPE
77+
#define HPy_TPFLAGS_DEFAULT (_Py_TPFLAGS_HEAPTYPE | _Py_TPFLAGS_HAVE_VERSION_TAG)
7778

7879
#define HPy_CAST(ctx, return_type, h) ((return_type *) _HPy_Cast(ctx, h))
7980

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
#include "hpy.h"
2929

3030
HPyAPI_RUNTIME_FUNC(int)
31-
HPyArg_Parse(HPyContext ctx, HPy *args, HPy_ssize_t nargs, const char *fmt, ...);
31+
HPyArg_Parse(HPyContext ctx, HPyTracker *ht, HPy *args, HPy_ssize_t nargs, const char *fmt, ...);
3232

3333
HPyAPI_RUNTIME_FUNC(int)
34-
HPyArg_ParseKeywords(HPyContext ctx, HPy *args, HPy_ssize_t nargs, HPy kw,
34+
HPyArg_ParseKeywords(HPyContext ctx, HPyTracker *ht, HPy *args, HPy_ssize_t nargs, HPy kw,
3535
const char *fmt, const char *keywords[], ...);
3636

3737

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ _HPy_HIDDEN int
3434
ctx_Tracker_Add(HPyContext ctx, HPyTracker ht, HPy h);
3535

3636
_HPy_HIDDEN void
37-
ctx_Tracker_RemoveAll(HPyContext ctx, HPyTracker ht);
37+
ctx_Tracker_ForgetAll(HPyContext ctx, HPyTracker ht);
3838

3939
_HPy_HIDDEN void
40-
ctx_Tracker_Free(HPyContext ctx, HPyTracker ht);
40+
ctx_Tracker_Close(HPyContext ctx, HPyTracker ht);
4141

4242
#endif /* HPY_COMMON_RUNTIME_CTX_TRACKER_H */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
*/
2424

2525
// automatically generated by setup.py:get_scm_config()
26-
#define HPY_VERSION "0.1.dev618+g2f53dbf"
27-
#define HPY_GIT_REVISION "2f53dbf"
26+
#define HPY_VERSION "0.1.dev875+g7c832a2"
27+
#define HPY_GIT_REVISION "7c832a2"

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,8 @@
152152
{ \
153153
return (IMPL(_HPyGetContext(), _py2h(arg0), _py2h(arg1), arg2)); \
154154
}
155+
#define _HPyFunc_TRAMPOLINE_HPyFunc_OBJOBJPROC(SYM, IMPL) \
156+
static int SYM(cpy_PyObject *arg0, cpy_PyObject *arg1) \
157+
{ \
158+
return (IMPL(_HPyGetContext(), _py2h(arg0), _py2h(arg1))); \
159+
}

0 commit comments

Comments
 (0)