Debian Codegraph @

pypy/module/_hpy_universal/src/bridge.h

raw symbols SCIP
1 #include "src/precommondefs.h"
2 #include "hpy.h"
3
4 /* One note about bridge functions which receive arguments of type HPy: in C,
5 * HPy is defined as:
6 * typedef struct { HPy_ssize_t _i; } HPy;
7 *
8 * however, as explained in llapi.py, to work around limitations of
9 * rffi/ll2ctypes, on the RPython side HPy is defined as:
10 * typedef HPy_ssize_t HPy;
11 *
12 * This poses a problem for bridge functions, because the types don't
13 * match. The workaround is to use a macro to convert from HPy to HPy_ssize_t
14 * by doing h._i. The naming convention is that in RPython we define a
15 * @BRIGE.func called _foo, and here we define a macro foo which calls
16 * _foo(h._i)
17 *
18 */
19
20 #ifdef RPYTHON_LL2CTYPES
21 /**************** BEFORE TRANSLATION ****************
22 *
23 * Define a set of macros to turn a call to foo() into bridge->foo()
24 *
25 */
26
27 #define hpy_err_Occurred_rpy() (hpy_get_bridge()->hpy_err_Occurred_rpy())
28 #define hpy_err_Clear() (hpy_get_bridge()->hpy_err_Clear())
29 #define hpy_err_SetString(a, b, c) (hpy_get_bridge()->_hpy_err_SetString(a, b, c))
30 #define hpy_err_SetObject(a, b, c) (hpy_get_bridge()->_hpy_err_SetObject(a, b, c))
31
32 typedef struct {
33 int (*hpy_err_Occurred_rpy)(void);
34 void (*hpy_err_Clear)(void);
35 void (*_hpy_err_SetString)(HPyContext *ctx, HPy type, const char* message);
36 void (*_hpy_err_SetObject)(HPyContext *ctx, HPy type, HPy value);
37 } _HPyBridge;
38
39
40 RPY_EXTERN _HPyBridge *hpy_get_bridge(void);
41
42 #else /* RPYTHON_LL2CTYPES */
43 /**************** AFTER TRANSLATION ****************
44 *
45 * Declare standard function prototypes
46 *
47 */
48
49 // see the comment above for why we need this macro
50 #define hpy_err_SetString(ctx, type, message) (_hpy_err_SetString(ctx, type._i, message))
51 #define hpy_err_SetObject(ctx, type, value) (_hpy_err_SetObject(ctx, type._i, value._i))
52
53 int hpy_err_Occurred_rpy(void);
54 void hpy_err_Clear(void);
55 void _hpy_err_SetString(HPyContext *ctx, HPy_ssize_t type, const char *message);
56 void _hpy_err_SetObject(HPyContext *ctx, HPy_ssize_t type, HPy_ssize_t value);
57
58
59 #endif /* RPYTHON_LL2CTYPES */