Skip to content

Commit d222c34

Browse files
committed
Update HPy inlined files: 91734aa
1 parent a65d9e7 commit d222c34

Some content is hidden

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

50 files changed

+3972
-619
lines changed

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

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
#ifndef HPy_H
22
#define HPy_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#ifndef HPY_UNIVERSAL_ABI
8+
/* It would be nice if we could include hpy.h WITHOUT bringing in all the
9+
stuff from Python.h, to make sure that people don't use the CPython API by
10+
mistake. How to achieve it, though? */
11+
# define PY_SSIZE_T_CLEAN
12+
# include <Python.h>
13+
#endif
314

415
#include <stdlib.h>
516
#include <stdint.h>
@@ -26,6 +37,15 @@
2637
# define _HPy_NO_RETURN
2738
#endif
2839

40+
#if defined(_MSC_VER) && defined(__cplusplus) // MSVC C4576
41+
# define _hconv(h) {h}
42+
# define _hfconv(h) {h}
43+
# define _htsconv(h) {h}
44+
#else
45+
# define _hconv(h) ((HPy){h})
46+
# define _hfconv(h) ((HPyField){h})
47+
# define _htsconv(h) ((HPyThreadState){h})
48+
#endif
2949
/* ~~~~~~~~~~~~~~~~ HPyAPI declaration ~~~~~~~~~~~~~~~~ */
3050

3151
/* We have three different kind of API functions: */
@@ -88,20 +108,25 @@
88108
another HPy among other stuff
89109
*/
90110
typedef struct _HPy_s { intptr_t _i; } HPy;
111+
typedef struct { intptr_t _i; } HPyField;
91112
typedef struct { intptr_t _lst; } HPyListBuilder;
92113
typedef struct { intptr_t _tup; } HPyTupleBuilder;
93114
typedef struct { intptr_t _i; } HPyTracker;
115+
typedef struct { intptr_t _i; } HPyThreadState;
94116

95117

96118
/* A null handle is officially defined as a handle whose _i is 0. This is true
97119
in all ABI modes. */
98-
#define HPy_NULL ((HPy){0})
120+
#define HPy_NULL _hconv(0)
99121
#define HPy_IsNull(h) ((h)._i == 0)
100122

123+
#define HPyField_NULL _hfconv(0)
124+
#define HPyField_IsNull(f) ((f)._i == 0)
125+
101126
/* Convenience functions to cast between HPy and void*. We need to decide
102127
whether these are part of the official API or not, and maybe introduce a
103128
better naming convetion. For now, they are needed for ujson. */
104-
static inline HPy HPy_FromVoidP(void *p) { return (HPy){(intptr_t)p}; }
129+
static inline HPy HPy_FromVoidP(void *p) { return _hconv((intptr_t)p); }
105130
static inline void* HPy_AsVoidP(HPy h) { return (void*)h._i; }
106131

107132

@@ -112,14 +137,11 @@ typedef struct _HPyContext_s HPyContext;
112137
#ifdef HPY_UNIVERSAL_ABI
113138
typedef intptr_t HPy_ssize_t;
114139
typedef intptr_t HPy_hash_t;
140+
typedef uint32_t HPy_UCS4;
115141
#else
116-
/* It would be nice if we could include hpy.h WITHOUT bringing in all the
117-
stuff from Python.h, to make sure that people don't use the CPython API by
118-
mistake. How to achieve it, though? */
119-
# define PY_SSIZE_T_CLEAN
120-
# include <Python.h>
121142
typedef Py_ssize_t HPy_ssize_t;
122143
typedef Py_hash_t HPy_hash_t;
144+
typedef Py_UCS4 HPy_UCS4;
123145
#endif
124146

125147

@@ -132,6 +154,7 @@ typedef struct _HPyContext_s HPyContext;
132154
#include "hpy/hpytype.h"
133155
#include "hpy/hpymodule.h"
134156
#include "hpy/runtime/argparse.h"
157+
#include "hpy/runtime/buildvalue.h"
135158
#include "hpy/runtime/helpers.h"
136159

137160
#ifdef HPY_UNIVERSAL_ABI
@@ -146,4 +169,9 @@ typedef struct _HPyContext_s HPyContext;
146169
# include "hpy/cpython/autogen_api_impl.h"
147170
#endif
148171

172+
#include "hpy/inline_helpers.h"
173+
174+
#ifdef __cplusplus
175+
}
176+
#endif
149177
#endif /* HPy_H */

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#define _HPyFunc_DECLARE_HPyFunc_OBJOBJPROC(SYM) static int SYM(HPyContext *ctx, HPy, HPy)
4343
#define _HPyFunc_DECLARE_HPyFunc_GETBUFFERPROC(SYM) static int SYM(HPyContext *ctx, HPy, HPy_buffer *, int)
4444
#define _HPyFunc_DECLARE_HPyFunc_RELEASEBUFFERPROC(SYM) static void SYM(HPyContext *ctx, HPy, HPy_buffer *)
45+
#define _HPyFunc_DECLARE_HPyFunc_TRAVERSEPROC(SYM) static int SYM(void *object, HPyFunc_visitproc visit, void *arg)
46+
#define _HPyFunc_DECLARE_HPyFunc_DESTRUCTOR(SYM) static void SYM(HPyContext *ctx, HPy)
4547
#define _HPyFunc_DECLARE_HPyFunc_DESTROYFUNC(SYM) static void SYM(void *)
4648

4749
typedef HPy (*HPyFunc_noargs)(HPyContext *ctx, HPy self);
@@ -76,4 +78,6 @@ typedef int (*HPyFunc_setter)(HPyContext *ctx, HPy, HPy, void *);
7678
typedef int (*HPyFunc_objobjproc)(HPyContext *ctx, HPy, HPy);
7779
typedef int (*HPyFunc_getbufferproc)(HPyContext *ctx, HPy, HPy_buffer *, int);
7880
typedef void (*HPyFunc_releasebufferproc)(HPyContext *ctx, HPy, HPy_buffer *);
81+
typedef int (*HPyFunc_traverseproc)(void *object, HPyFunc_visitproc visit, void *arg);
82+
typedef void (*HPyFunc_destructor)(HPyContext *ctx, HPy);
7983
typedef void (*HPyFunc_destroyfunc)(void *);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
typedef enum {
1414
HPy_bf_getbuffer = 1,
1515
HPy_bf_releasebuffer = 2,
16+
HPy_mp_ass_subscript = 3,
17+
HPy_mp_length = 4,
18+
HPy_mp_subscript = 5,
1619
HPy_nb_absolute = 6,
1720
HPy_nb_add = 7,
1821
HPy_nb_and = 8,
@@ -58,13 +61,18 @@ typedef enum {
5861
HPy_tp_new = 65,
5962
HPy_tp_repr = 66,
6063
HPy_tp_richcompare = 67,
64+
HPy_tp_traverse = 71,
6165
HPy_nb_matrix_multiply = 75,
6266
HPy_nb_inplace_matrix_multiply = 76,
67+
HPy_tp_finalize = 80,
6368
HPy_tp_destroy = 1000,
6469
} HPySlot_Slot;
6570

6671
#define _HPySlot_SIG__HPy_bf_getbuffer HPyFunc_GETBUFFERPROC
6772
#define _HPySlot_SIG__HPy_bf_releasebuffer HPyFunc_RELEASEBUFFERPROC
73+
#define _HPySlot_SIG__HPy_mp_ass_subscript HPyFunc_OBJOBJARGPROC
74+
#define _HPySlot_SIG__HPy_mp_length HPyFunc_LENFUNC
75+
#define _HPySlot_SIG__HPy_mp_subscript HPyFunc_BINARYFUNC
6876
#define _HPySlot_SIG__HPy_nb_absolute HPyFunc_UNARYFUNC
6977
#define _HPySlot_SIG__HPy_nb_add HPyFunc_BINARYFUNC
7078
#define _HPySlot_SIG__HPy_nb_and HPyFunc_BINARYFUNC
@@ -110,6 +118,8 @@ typedef enum {
110118
#define _HPySlot_SIG__HPy_tp_new HPyFunc_KEYWORDS
111119
#define _HPySlot_SIG__HPy_tp_repr HPyFunc_REPRFUNC
112120
#define _HPySlot_SIG__HPy_tp_richcompare HPyFunc_RICHCMPFUNC
121+
#define _HPySlot_SIG__HPy_tp_traverse HPyFunc_TRAVERSEPROC
113122
#define _HPySlot_SIG__HPy_nb_matrix_multiply HPyFunc_BINARYFUNC
114123
#define _HPySlot_SIG__HPy_nb_inplace_matrix_multiply HPyFunc_BINARYFUNC
124+
#define _HPySlot_SIG__HPy_tp_finalize HPyFunc_DESTRUCTOR
115125
#define _HPySlot_SIG__HPy_tp_destroy HPyFunc_DESTROYFUNC

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ typedef struct _object cpy_PyObject;
1010
typedef cpy_PyObject *(*cpy_PyCFunction)(cpy_PyObject *, cpy_PyObject *);
1111
typedef struct PyMethodDef cpy_PyMethodDef;
1212
typedef struct bufferinfo cpy_Py_buffer;
13+
typedef int (*cpy_visitproc)(cpy_PyObject *, void *);
14+
typedef cpy_PyObject *(*cpy_PyCFunction)(cpy_PyObject *, cpy_PyObject *);
15+
typedef cpy_PyObject *(*cpy_getter)(cpy_PyObject *, void *);
16+
typedef int (*cpy_setter)(cpy_PyObject *, cpy_PyObject *, void *);
1317

1418

1519
#endif /* HPY_UNIVERSAL_CPY_TYPES_H */

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

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,19 +280,38 @@ HPyAPI_FUNC int HPyCallable_Check(HPyContext *ctx, HPy h)
280280
return PyCallable_Check(_h2py(h));
281281
}
282282

283-
HPyAPI_FUNC void HPyErr_SetString(HPyContext *ctx, HPy h_type, const char *message)
283+
HPyAPI_FUNC HPy HPyErr_SetString(HPyContext *ctx, HPy h_type, const char *message)
284284
{
285285
PyErr_SetString(_h2py(h_type), message);
286+
return HPy_NULL;
286287
}
287288

288-
HPyAPI_FUNC void HPyErr_SetObject(HPyContext *ctx, HPy h_type, HPy h_value)
289+
HPyAPI_FUNC HPy HPyErr_SetObject(HPyContext *ctx, HPy h_type, HPy h_value)
289290
{
290291
PyErr_SetObject(_h2py(h_type), _h2py(h_value));
292+
return HPy_NULL;
293+
}
294+
295+
HPyAPI_FUNC HPy HPyErr_SetFromErrnoWithFilename(HPyContext *ctx, HPy h_type, const char *filename_fsencoded)
296+
{
297+
return _py2h(PyErr_SetFromErrnoWithFilename(_h2py(h_type), filename_fsencoded));
298+
}
299+
300+
HPyAPI_FUNC HPy HPyErr_SetFromErrnoWithFilenameObjects(HPyContext *ctx, HPy h_type, HPy filename1, HPy filename2)
301+
{
302+
PyErr_SetFromErrnoWithFilenameObjects(_h2py(h_type), _h2py(filename1), _h2py(filename2));
303+
return HPy_NULL;
304+
}
305+
306+
HPyAPI_FUNC int HPyErr_ExceptionMatches(HPyContext *ctx, HPy exc)
307+
{
308+
return PyErr_ExceptionMatches(_h2py(exc));
291309
}
292310

293311
HPyAPI_FUNC HPy HPyErr_NoMemory(HPyContext *ctx)
294312
{
295-
return _py2h(PyErr_NoMemory());
313+
PyErr_NoMemory();
314+
return HPy_NULL;
296315
}
297316

298317
HPyAPI_FUNC void HPyErr_Clear(HPyContext *ctx)
@@ -310,6 +329,11 @@ HPyAPI_FUNC HPy HPyErr_NewExceptionWithDoc(HPyContext *ctx, const char *name, co
310329
return _py2h(PyErr_NewExceptionWithDoc(name, doc, _h2py(base), _h2py(dict)));
311330
}
312331

332+
HPyAPI_FUNC int HPyErr_WarnEx(HPyContext *ctx, HPy category, const char *message, HPy_ssize_t stack_level)
333+
{
334+
return PyErr_WarnEx(_h2py(category), message, stack_level);
335+
}
336+
313337
HPyAPI_FUNC int HPy_IsTrue(HPyContext *ctx, HPy h)
314338
{
315339
return PyObject_IsTrue(_h2py(h));
@@ -350,6 +374,11 @@ HPyAPI_FUNC HPy HPy_GetItem(HPyContext *ctx, HPy obj, HPy key)
350374
return _py2h(PyObject_GetItem(_h2py(obj), _h2py(key)));
351375
}
352376

377+
HPyAPI_FUNC int HPy_Contains(HPyContext *ctx, HPy container, HPy key)
378+
{
379+
return PySequence_Contains(_h2py(container), _h2py(key));
380+
}
381+
353382
HPyAPI_FUNC int HPy_SetItem(HPyContext *ctx, HPy obj, HPy key, HPy value)
354383
{
355384
return PyObject_SetItem(_h2py(obj), _h2py(key), _h2py(value));
@@ -435,6 +464,16 @@ HPyAPI_FUNC int HPyUnicode_Check(HPyContext *ctx, HPy h)
435464
return PyUnicode_Check(_h2py(h));
436465
}
437466

467+
HPyAPI_FUNC HPy HPyUnicode_AsASCIIString(HPyContext *ctx, HPy h)
468+
{
469+
return _py2h(PyUnicode_AsASCIIString(_h2py(h)));
470+
}
471+
472+
HPyAPI_FUNC HPy HPyUnicode_AsLatin1String(HPyContext *ctx, HPy h)
473+
{
474+
return _py2h(PyUnicode_AsLatin1String(_h2py(h)));
475+
}
476+
438477
HPyAPI_FUNC HPy HPyUnicode_AsUTF8String(HPyContext *ctx, HPy h)
439478
{
440479
return _py2h(PyUnicode_AsUTF8String(_h2py(h)));
@@ -455,6 +494,31 @@ HPyAPI_FUNC HPy HPyUnicode_DecodeFSDefault(HPyContext *ctx, const char *v)
455494
return _py2h(PyUnicode_DecodeFSDefault(v));
456495
}
457496

497+
HPyAPI_FUNC HPy HPyUnicode_DecodeFSDefaultAndSize(HPyContext *ctx, const char *v, HPy_ssize_t size)
498+
{
499+
return _py2h(PyUnicode_DecodeFSDefaultAndSize(v, size));
500+
}
501+
502+
HPyAPI_FUNC HPy HPyUnicode_EncodeFSDefault(HPyContext *ctx, HPy h)
503+
{
504+
return _py2h(PyUnicode_EncodeFSDefault(_h2py(h)));
505+
}
506+
507+
HPyAPI_FUNC HPy_UCS4 HPyUnicode_ReadChar(HPyContext *ctx, HPy h, HPy_ssize_t index)
508+
{
509+
return PyUnicode_ReadChar(_h2py(h), index);
510+
}
511+
512+
HPyAPI_FUNC HPy HPyUnicode_DecodeASCII(HPyContext *ctx, const char *s, HPy_ssize_t size, const char *errors)
513+
{
514+
return _py2h(PyUnicode_DecodeASCII(s, size, errors));
515+
}
516+
517+
HPyAPI_FUNC HPy HPyUnicode_DecodeLatin1(HPyContext *ctx, const char *s, HPy_ssize_t size, const char *errors)
518+
{
519+
return _py2h(PyUnicode_DecodeLatin1(s, size, errors));
520+
}
521+
458522
HPyAPI_FUNC int HPyList_Check(HPyContext *ctx, HPy h)
459523
{
460524
return PyList_Check(_h2py(h));
@@ -490,3 +554,13 @@ HPyAPI_FUNC HPy HPyImport_ImportModule(HPyContext *ctx, const char *name)
490554
return _py2h(PyImport_ImportModule(name));
491555
}
492556

557+
HPyAPI_FUNC HPyThreadState HPy_LeavePythonExecution(HPyContext *ctx)
558+
{
559+
return _threads2h(PyEval_SaveThread());
560+
}
561+
562+
HPyAPI_FUNC void HPy_ReenterPythonExecution(HPyContext *ctx, HPyThreadState state)
563+
{
564+
PyEval_RestoreThread(_h2threads(state));
565+
}
566+

0 commit comments

Comments
 (0)