Skip to content

Commit 43ce485

Browse files
committed
[GR-38978] Update HPy import (release 0.0.4).
PullRequest: graalpython/2291
2 parents dfe43fe + 2a9b6d4 commit 43ce485

File tree

25 files changed

+151
-83
lines changed

25 files changed

+151
-83
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,13 +593,13 @@ HPyAPI_FUNC HPy HPyImport_ImportModule(HPyContext *ctx, const char *name)
593593
return _py2h(PyImport_ImportModule(name));
594594
}
595595

596-
HPyAPI_FUNC HPyThreadState HPy_LeavePythonExecution(HPyContext *ctx)
596+
HPyAPI_FUNC void HPy_ReenterPythonExecution(HPyContext *ctx, HPyThreadState state)
597597
{
598-
return _threads2h(PyEval_SaveThread());
598+
PyEval_RestoreThread(_h2threads(state));
599599
}
600600

601-
HPyAPI_FUNC void HPy_ReenterPythonExecution(HPyContext *ctx, HPyThreadState state)
601+
HPyAPI_FUNC HPyThreadState HPy_LeavePythonExecution(HPyContext *ctx)
602602
{
603-
PyEval_RestoreThread(_h2threads(state));
603+
return _threads2h(PyEval_SaveThread());
604604
}
605605

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,20 @@ typedef struct {
4949
} HPyModuleDef;
5050

5151

52+
#if defined(__cplusplus)
53+
# define HPyMODINIT_FUNC extern "C" Py_EXPORTED_SYMBOL HPy
54+
#else /* __cplusplus */
55+
# define HPyMODINIT_FUNC Py_EXPORTED_SYMBOL HPy
56+
#endif /* __cplusplus */
5257

5358
#ifdef HPY_UNIVERSAL_ABI
5459

5560
// module initialization in the universal case
5661
#define HPy_MODINIT(modname) \
5762
_HPy_HIDDEN HPyContext *_ctx_for_trampolines; \
5863
static HPy init_##modname##_impl(HPyContext *ctx); \
59-
Py_EXPORTED_SYMBOL \
60-
HPy HPyInit_##modname(HPyContext *ctx) \
64+
HPyMODINIT_FUNC \
65+
HPyInit_##modname(HPyContext *ctx) \
6166
{ \
6267
_ctx_for_trampolines = ctx; \
6368
return init_##modname##_impl(ctx); \

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
#ifndef HPY_INLINE_HELPERS_H
4242
#define HPY_INLINE_HELPERS_H
4343

44+
#if defined(_MSC_VER)
45+
# include <malloc.h> /* for alloca() */
46+
#endif
47+
4448
HPyAPI_FUNC HPy HPyErr_SetFromErrno(HPyContext *ctx, HPy h_type)
4549
{
4650
return HPyErr_SetFromErrnoWithFilenameObjects(ctx, h_type, HPy_NULL, HPy_NULL);
@@ -51,4 +55,24 @@ HPyAPI_FUNC HPy HPyErr_SetFromErrnoWithFilenameObject(HPyContext *ctx, HPy h_typ
5155
return HPyErr_SetFromErrnoWithFilenameObjects(ctx, h_type, filename, HPy_NULL);
5256
}
5357

58+
HPyAPI_FUNC HPy HPyTuple_Pack(HPyContext *ctx, HPy_ssize_t n, ...) {
59+
va_list vargs;
60+
HPy_ssize_t i;
61+
62+
if (n == 0) {
63+
return HPyTuple_FromArray(ctx, (HPy*)NULL, n);
64+
}
65+
HPy *array = (HPy *)alloca(n * sizeof(HPy));
66+
va_start(vargs, n);
67+
if (array == NULL) {
68+
va_end(vargs);
69+
return HPy_NULL;
70+
}
71+
for (i = 0; i < n; i++) {
72+
array[i] = va_arg(vargs, HPy);
73+
}
74+
va_end(vargs);
75+
return HPyTuple_FromArray(ctx, array, n);
76+
}
77+
5478
#endif //HPY_INLINE_HELPERS_H

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@
3939
((void**)data) \
4040
))
4141

42-
43-
/* ~~~ HPyTuple_Pack ~~~
44-
45-
this is just syntactic sugar around HPyTuple_FromArray, to help porting the
46-
exising code which uses PyTuple_Pack
47-
*/
48-
49-
#define HPyTuple_Pack(ctx, n, ...) (HPyTuple_FromArray(ctx, (HPy[]){ __VA_ARGS__ }, n))
50-
5142
/* Rich comparison opcodes */
5243
typedef enum {
5344
HPy_LT = 0,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ struct _HPyContext_s {
278278
void (*ctx_Tracker_Close)(HPyContext *ctx, HPyTracker ht);
279279
void (*ctx_Field_Store)(HPyContext *ctx, HPy target_object, _HPyFieldPtr target_field, HPy h);
280280
HPy (*ctx_Field_Load)(HPyContext *ctx, HPy source_object, HPyField source_field);
281-
HPyThreadState (*ctx_LeavePythonExecution)(HPyContext *ctx);
282281
void (*ctx_ReenterPythonExecution)(HPyContext *ctx, HPyThreadState state);
282+
HPyThreadState (*ctx_LeavePythonExecution)(HPyContext *ctx);
283283
void (*ctx_Global_Store)(HPyContext *ctx, _HPyGlobalPtr global, HPy h);
284284
HPy (*ctx_Global_Load)(HPyContext *ctx, HPyGlobal global);
285285
void (*ctx_Dump)(HPyContext *ctx, HPy h);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -648,14 +648,14 @@ HPyAPI_FUNC HPy HPyField_Load(HPyContext *ctx, HPy source_object, HPyField sourc
648648
return WRAP(ctx->ctx_Field_Load ( ctx, UNWRAP(source_object), UNWRAP_FIELD(source_field) ));
649649
}
650650

651-
HPyAPI_FUNC HPyThreadState HPy_LeavePythonExecution(HPyContext *ctx) {
652-
return WRAP_THREADSTATE(ctx->ctx_LeavePythonExecution ( ctx ));
653-
}
654-
655651
HPyAPI_FUNC void HPy_ReenterPythonExecution(HPyContext *ctx, HPyThreadState state) {
656652
ctx->ctx_ReenterPythonExecution ( ctx, UNWRAP_THREADSTATE(state) );
657653
}
658654

655+
HPyAPI_FUNC HPyThreadState HPy_LeavePythonExecution(HPyContext *ctx) {
656+
return WRAP_THREADSTATE(ctx->ctx_LeavePythonExecution ( ctx ));
657+
}
658+
659659
HPyAPI_FUNC void HPyGlobal_Store(HPyContext *ctx, HPyGlobal *global, HPy h) {
660660
ctx->ctx_Global_Store ( ctx, global, UNWRAP(h) );
661661
}

graalpython/com.oracle.graal.python.cext/include/hpy/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.0.4.dev216+gf941e8f"
27-
#define HPY_GIT_REVISION "f941e8f"
26+
#define HPY_VERSION "0.0.4"
27+
#define HPY_GIT_REVISION "41989b8"

graalpython/com.oracle.graal.python.jni/src/ctx_tracker.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ ctx_Tracker_New(HPyContext *ctx, HPy_ssize_t capacity)
109109
}
110110
capacity++; // always reserve space for an extra handle, see the docs
111111

112-
hp = malloc(sizeof(_HPyTracker_s));
112+
hp = (_HPyTracker_s*)malloc(sizeof(_HPyTracker_s));
113113
if (hp == NULL) {
114114
HPyErr_NoMemory(ctx);
115115
return _hp2ht(0);
116116
}
117-
hp->handles = calloc(capacity, sizeof(HPy));
117+
hp->handles = (HPy*)calloc(capacity, sizeof(HPy));
118118
if (hp->handles == NULL) {
119119
free(hp);
120120
HPyErr_NoMemory(ctx);
@@ -142,7 +142,7 @@ tracker_resize(HPyContext *ctx, _HPyTracker_s *hp, HPy_ssize_t capacity)
142142
HPyErr_SetString(ctx, ctx->h_ValueError, "HPyTracker resize would lose handles");
143143
return -1;
144144
}
145-
new_handles = realloc(hp->handles, capacity * sizeof(HPy));
145+
new_handles = (HPy*)realloc(hp->handles, capacity * sizeof(HPy));
146146
if (new_handles == NULL) {
147147
HPyErr_NoMemory(ctx);
148148
return -1;

graalpython/lib-graalpython/modules/hpy.egg-info/PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: hpy
3-
Version: 0.0.4.dev216+gf941e8f
3+
Version: 0.0.4
44
Summary: UNKNOWN
55
Home-page: UNKNOWN
66
License: UNKNOWN

graalpython/lib-graalpython/modules/hpy/debug/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MIT License
22
#
3-
# Copyright (c) 2021, Oracle and/or its affiliates.
3+
# Copyright (c) 2021, 2022, Oracle and/or its affiliates.
44
# Copyright (c) 2019 pyhandle
55
#
66
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -22,3 +22,13 @@
2222
# SOFTWARE.
2323

2424
from .leakdetector import HPyDebugError, HPyLeakError, LeakDetector
25+
26+
27+
def set_handle_stack_trace_limit(limit):
28+
from hpy.universal import _debug
29+
_debug.set_handle_stack_trace_limit(limit)
30+
31+
32+
def disable_handle_stack_traces():
33+
from hpy.universal import _debug
34+
_debug.set_handle_stack_trace_limit(None)

0 commit comments

Comments
 (0)