Skip to content

Commit bb58e77

Browse files
committed
[GR-40218] Improve important HPy API functions.
PullRequest: graalpython/2402
2 parents 5c74801 + 7336e02 commit bb58e77

File tree

27 files changed

+2126
-1571
lines changed

27 files changed

+2126
-1571
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <truffle.h>
4545

4646
#include <wchar.h>
47+
#include <string.h>
4748

4849
#define SRC_CS "utf-8"
4950
#define UNWRAP(_h) ((_h)._i)
@@ -107,6 +108,10 @@ void graal_hpy_free(void *ptr) {
107108
free(ptr);
108109
}
109110

111+
char* graal_hpy_strdup(const char *ptr) {
112+
return strdup(ptr);
113+
}
114+
110115
void* graal_hpy_from_HPy_array(void *arr, uint64_t len) {
111116
return polyglot_from_HPy_array(arr, len);
112117
}
@@ -1124,11 +1129,21 @@ HPyAPI_STORAGE int _HPy_IMPL_NAME_NOPREFIX(TypeCheck)(HPyContext *ctx, HPy obj,
11241129
return (int) UPCALL_I32(ctx_TypeCheck, ctx, obj, type);
11251130
}
11261131

1132+
HPyAPI_STORAGE int _HPy_IMPL_NAME_NOPREFIX(TypeCheck_g)(HPyContext *ctx, HPy obj, HPyGlobal type)
1133+
{
1134+
return (int) UPCALL_I32(ctx_TypeCheck_g, ctx, obj, type);
1135+
}
1136+
11271137
HPyAPI_STORAGE int _HPy_IMPL_NAME_NOPREFIX(Is)(HPyContext *ctx, HPy obj, HPy other)
11281138
{
11291139
return (int) UPCALL_I32(ctx_Is, ctx, obj, other);
11301140
}
11311141

1142+
HPyAPI_STORAGE int _HPy_IMPL_NAME_NOPREFIX(Is_g)(HPyContext *ctx, HPy obj, HPyGlobal other)
1143+
{
1144+
return (int) UPCALL_I32(ctx_Is_g, ctx, obj, other);
1145+
}
1146+
11321147
HPyAPI_STORAGE void *_HPy_IMPL_NAME_NOPREFIX(AsStruct)(HPyContext *ctx, HPy obj)
11331148
{
11341149
return UPCALL_HPY(ctx_AsStruct, ctx, obj);
@@ -1671,7 +1686,9 @@ HPyContext *graal_hpy_context_to_native(HPyContext *managed_context, HPyContext
16711686
HPY_CTX_UPCALL(ctx_SetItem_s);
16721687
HPY_CTX_UPCALL(ctx_Type);
16731688
HPY_CTX_UPCALL(ctx_TypeCheck);
1689+
HPY_CTX_UPCALL(ctx_TypeCheck_g);
16741690
HPY_CTX_UPCALL(ctx_Is);
1691+
HPY_CTX_UPCALL(ctx_Is_g);
16751692
HPY_CTX_UPCALL(ctx_AsStruct);
16761693
HPY_CTX_UPCALL(ctx_AsStructLegacy);
16771694
HPY_CTX_UPCALL(ctx_New);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ HPyAPI_FUNC int HPy_TypeCheck(HPyContext *ctx, HPy h_obj, HPy h_type)
371371
return ctx_TypeCheck(ctx, h_obj, h_type);
372372
}
373373

374+
HPyAPI_FUNC int HPy_TypeCheck_g(HPyContext *ctx, HPy h_obj, HPyGlobal g_type)
375+
{
376+
return ctx_TypeCheck_g(ctx, h_obj, g_type);
377+
}
378+
374379
HPyAPI_FUNC int HPyType_IsSubtype(HPyContext *ctx, HPy h_sub, HPy h_type)
375380
{
376381
return ctx_Type_IsSubtype(ctx, h_sub, h_type);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ _HPy_HIDDEN HPy ctx_Module_Create(HPyContext *ctx, HPyModuleDef *hpydef);
5757
// ctx_object.c
5858
_HPy_HIDDEN void ctx_Dump(HPyContext *ctx, HPy h);
5959
_HPy_HIDDEN int ctx_TypeCheck(HPyContext *ctx, HPy h_obj, HPy h_type);
60+
_HPy_HIDDEN int ctx_TypeCheck_g(HPyContext *ctx, HPy h_obj, HPyGlobal g_type);
6061
_HPy_HIDDEN int ctx_Type_IsSubtype(HPyContext *ctx, HPy h_sub, HPy h_type);
6162
_HPy_HIDDEN int ctx_Is(HPyContext *ctx, HPy h_obj, HPy h_other);
63+
_HPy_HIDDEN int ctx_Is_g(HPyContext *ctx, HPy h_obj, HPyGlobal g_other);
6264
_HPy_HIDDEN HPy ctx_GetItem_i(HPyContext *ctx, HPy obj, HPy_ssize_t idx);
6365
_HPy_HIDDEN HPy ctx_GetItem_s(HPyContext *ctx, HPy obj, const char *key);
6466
_HPy_HIDDEN int ctx_SetItem_i(HPyContext *ctx, HPy obj, HPy_ssize_t idx, HPy value);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ struct _HPyContext_s {
309309
const char *(*ctx_Type_GetName)(HPyContext *ctx, HPy type);
310310
HPy (*ctx_SeqIter_New)(HPyContext *ctx, HPy seq);
311311
int (*ctx_Type_CheckSlot)(HPyContext *ctx, HPy type, HPyDef *value);
312+
int (*ctx_TypeCheck_g)(HPyContext *ctx, HPy obj, HPyGlobal type);
313+
int (*ctx_Is_g)(HPyContext *ctx, HPy obj, HPyGlobal other);
312314
};
313315

314316
#ifdef GRAALVM_PYTHON_LLVM

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ HPyAPI_FUNC int HPy_TypeCheck(HPyContext *ctx, HPy obj, HPy type) {
436436
return ctx->ctx_TypeCheck ( ctx, UNWRAP(obj), UNWRAP(type) );
437437
}
438438

439+
HPyAPI_FUNC int HPy_TypeCheck_g(HPyContext *ctx, HPy obj, HPyGlobal type) {
440+
return ctx->ctx_TypeCheck_g ( ctx, UNWRAP(obj), UNWRAP_GLOBAL(type) );
441+
}
442+
439443
HPyAPI_FUNC int HPy_SetType(HPyContext *ctx, HPy obj, HPy type) {
440444
return ctx->ctx_SetType ( ctx, UNWRAP(obj), UNWRAP(type) );
441445
}
@@ -452,6 +456,10 @@ HPyAPI_FUNC int HPy_Is(HPyContext *ctx, HPy obj, HPy other) {
452456
return ctx->ctx_Is ( ctx, UNWRAP(obj), UNWRAP(other) );
453457
}
454458

459+
HPyAPI_FUNC int HPy_Is_g(HPyContext *ctx, HPy obj, HPyGlobal other) {
460+
return ctx->ctx_Is_g ( ctx, UNWRAP(obj), UNWRAP_GLOBAL(other) );
461+
}
462+
455463
HPyAPI_FUNC void *HPy_AsStruct(HPyContext *ctx, HPy h) {
456464
return ctx->ctx_AsStruct ( ctx, UNWRAP(h) );
457465
}

graalpython/com.oracle.graal.python.jni/src/debug/autogen_debug_ctx_init.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,12 @@ int debug_ctx_SetItem_i(HPyContext *dctx, DHPy obj, HPy_ssize_t idx, DHPy value)
127127
int debug_ctx_SetItem_s(HPyContext *dctx, DHPy obj, const char *key, DHPy value);
128128
DHPy debug_ctx_Type(HPyContext *dctx, DHPy obj);
129129
int debug_ctx_TypeCheck(HPyContext *dctx, DHPy obj, DHPy type);
130+
int debug_ctx_TypeCheck_g(HPyContext *dctx, DHPy obj, HPyGlobal type);
130131
int debug_ctx_SetType(HPyContext *dctx, DHPy obj, DHPy type);
131132
int debug_ctx_Type_IsSubtype(HPyContext *dctx, DHPy sub, DHPy type);
132133
const char *debug_ctx_Type_GetName(HPyContext *dctx, DHPy type);
133134
int debug_ctx_Is(HPyContext *dctx, DHPy obj, DHPy other);
135+
int debug_ctx_Is_g(HPyContext *dctx, DHPy obj, HPyGlobal other);
134136
void *debug_ctx_AsStruct(HPyContext *dctx, DHPy h);
135137
void *debug_ctx_AsStructLegacy(HPyContext *dctx, DHPy h);
136138
DHPy debug_ctx_New(HPyContext *dctx, DHPy h_type, void **data);
@@ -384,10 +386,12 @@ static inline void debug_ctx_init_fields(HPyContext *dctx, HPyContext *uctx)
384386
dctx->ctx_SetItem_s = &debug_ctx_SetItem_s;
385387
dctx->ctx_Type = &debug_ctx_Type;
386388
dctx->ctx_TypeCheck = &debug_ctx_TypeCheck;
389+
dctx->ctx_TypeCheck_g = &debug_ctx_TypeCheck_g;
387390
dctx->ctx_SetType = &debug_ctx_SetType;
388391
dctx->ctx_Type_IsSubtype = &debug_ctx_Type_IsSubtype;
389392
dctx->ctx_Type_GetName = &debug_ctx_Type_GetName;
390393
dctx->ctx_Is = &debug_ctx_Is;
394+
dctx->ctx_Is_g = &debug_ctx_Is_g;
391395
dctx->ctx_AsStruct = &debug_ctx_AsStruct;
392396
dctx->ctx_AsStructLegacy = &debug_ctx_AsStructLegacy;
393397
dctx->ctx_New = &debug_ctx_New;

graalpython/com.oracle.graal.python.jni/src/debug/autogen_debug_wrappers.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,11 @@ int debug_ctx_TypeCheck(HPyContext *dctx, DHPy obj, DHPy type)
486486
return HPy_TypeCheck(get_info(dctx)->uctx, DHPy_unwrap(dctx, obj), DHPy_unwrap(dctx, type));
487487
}
488488

489+
int debug_ctx_TypeCheck_g(HPyContext *dctx, DHPy obj, HPyGlobal type)
490+
{
491+
return HPy_TypeCheck_g(get_info(dctx)->uctx, DHPy_unwrap(dctx, obj), type);
492+
}
493+
489494
int debug_ctx_SetType(HPyContext *dctx, DHPy obj, DHPy type)
490495
{
491496
return HPy_SetType(get_info(dctx)->uctx, DHPy_unwrap(dctx, obj), DHPy_unwrap(dctx, type));
@@ -506,6 +511,11 @@ int debug_ctx_Is(HPyContext *dctx, DHPy obj, DHPy other)
506511
return HPy_Is(get_info(dctx)->uctx, DHPy_unwrap(dctx, obj), DHPy_unwrap(dctx, other));
507512
}
508513

514+
int debug_ctx_Is_g(HPyContext *dctx, DHPy obj, HPyGlobal other)
515+
{
516+
return HPy_Is_g(get_info(dctx)->uctx, DHPy_unwrap(dctx, obj), other);
517+
}
518+
509519
void *debug_ctx_AsStruct(HPyContext *dctx, DHPy h)
510520
{
511521
return HPy_AsStruct(get_info(dctx)->uctx, DHPy_unwrap(dctx, h));

0 commit comments

Comments
 (0)