Skip to content

Commit 7e841e2

Browse files
committed
Update HPy inlined files: 41989b8
1 parent 5cecc35 commit 7e841e2

File tree

24 files changed

+147
-79
lines changed

24 files changed

+147
-79
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
@@ -569,13 +569,13 @@ HPyAPI_FUNC HPy HPyImport_ImportModule(HPyContext *ctx, const char *name)
569569
return _py2h(PyImport_ImportModule(name));
570570
}
571571

572-
HPyAPI_FUNC HPyThreadState HPy_LeavePythonExecution(HPyContext *ctx)
572+
HPyAPI_FUNC void HPy_ReenterPythonExecution(HPyContext *ctx, HPyThreadState state)
573573
{
574-
return _threads2h(PyEval_SaveThread());
574+
PyEval_RestoreThread(_h2threads(state));
575575
}
576576

577-
HPyAPI_FUNC void HPy_ReenterPythonExecution(HPyContext *ctx, HPyThreadState state)
577+
HPyAPI_FUNC HPyThreadState HPy_LeavePythonExecution(HPyContext *ctx)
578578
{
579-
PyEval_RestoreThread(_h2threads(state));
579+
return _threads2h(PyEval_SaveThread());
580580
}
581581

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

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

2727

28+
#if defined(__cplusplus)
29+
# define HPyMODINIT_FUNC extern "C" Py_EXPORTED_SYMBOL HPy
30+
#else /* __cplusplus */
31+
# define HPyMODINIT_FUNC Py_EXPORTED_SYMBOL HPy
32+
#endif /* __cplusplus */
2833

2934
#ifdef HPY_UNIVERSAL_ABI
3035

3136
// module initialization in the universal case
3237
#define HPy_MODINIT(modname) \
3338
_HPy_HIDDEN HPyContext *_ctx_for_trampolines; \
3439
static HPy init_##modname##_impl(HPyContext *ctx); \
35-
Py_EXPORTED_SYMBOL \
36-
HPy HPyInit_##modname(HPyContext *ctx) \
40+
HPyMODINIT_FUNC \
41+
HPyInit_##modname(HPyContext *ctx) \
3742
{ \
3843
_ctx_for_trampolines = ctx; \
3944
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
@@ -1,6 +1,10 @@
11
#ifndef HPY_INLINE_HELPERS_H
22
#define HPY_INLINE_HELPERS_H
33

4+
#if defined(_MSC_VER)
5+
# include <malloc.h> /* for alloca() */
6+
#endif
7+
48
HPyAPI_FUNC HPy HPyErr_SetFromErrno(HPyContext *ctx, HPy h_type)
59
{
610
return HPyErr_SetFromErrnoWithFilenameObjects(ctx, h_type, HPy_NULL, HPy_NULL);
@@ -11,4 +15,24 @@ HPyAPI_FUNC HPy HPyErr_SetFromErrnoWithFilenameObject(HPyContext *ctx, HPy h_typ
1115
return HPyErr_SetFromErrnoWithFilenameObjects(ctx, h_type, filename, HPy_NULL);
1216
}
1317

18+
HPyAPI_FUNC HPy HPyTuple_Pack(HPyContext *ctx, HPy_ssize_t n, ...) {
19+
va_list vargs;
20+
HPy_ssize_t i;
21+
22+
if (n == 0) {
23+
return HPyTuple_FromArray(ctx, (HPy*)NULL, n);
24+
}
25+
HPy *array = (HPy *)alloca(n * sizeof(HPy));
26+
va_start(vargs, n);
27+
if (array == NULL) {
28+
va_end(vargs);
29+
return HPy_NULL;
30+
}
31+
for (i = 0; i < n; i++) {
32+
array[i] = va_arg(vargs, HPy);
33+
}
34+
va_end(vargs);
35+
return HPyTuple_FromArray(ctx, array, n);
36+
}
37+
1438
#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
@@ -15,15 +15,6 @@
1515
((void**)data) \
1616
))
1717

18-
19-
/* ~~~ HPyTuple_Pack ~~~
20-
21-
this is just syntactic sugar around HPyTuple_FromArray, to help porting the
22-
exising code which uses PyTuple_Pack
23-
*/
24-
25-
#define HPyTuple_Pack(ctx, n, ...) (HPyTuple_FromArray(ctx, (HPy[]){ __VA_ARGS__ }, n))
26-
2718
/* Rich comparison opcodes */
2819
typedef enum {
2920
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
@@ -238,8 +238,8 @@ struct _HPyContext_s {
238238
void (*ctx_Tracker_Close)(HPyContext *ctx, HPyTracker ht);
239239
void (*ctx_Field_Store)(HPyContext *ctx, HPy target_object, HPyField *target_field, HPy h);
240240
HPy (*ctx_Field_Load)(HPyContext *ctx, HPy source_object, HPyField source_field);
241-
HPyThreadState (*ctx_LeavePythonExecution)(HPyContext *ctx);
242241
void (*ctx_ReenterPythonExecution)(HPyContext *ctx, HPyThreadState state);
242+
HPyThreadState (*ctx_LeavePythonExecution)(HPyContext *ctx);
243243
void (*ctx_Global_Store)(HPyContext *ctx, HPyGlobal *global, HPy h);
244244
HPy (*ctx_Global_Load)(HPyContext *ctx, HPyGlobal global);
245245
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
@@ -590,14 +590,14 @@ HPyAPI_FUNC HPy HPyField_Load(HPyContext *ctx, HPy source_object, HPyField sourc
590590
return ctx->ctx_Field_Load ( ctx, source_object, source_field );
591591
}
592592

593-
HPyAPI_FUNC HPyThreadState HPy_LeavePythonExecution(HPyContext *ctx) {
594-
return ctx->ctx_LeavePythonExecution ( ctx );
595-
}
596-
597593
HPyAPI_FUNC void HPy_ReenterPythonExecution(HPyContext *ctx, HPyThreadState state) {
598594
ctx->ctx_ReenterPythonExecution ( ctx, state );
599595
}
600596

597+
HPyAPI_FUNC HPyThreadState HPy_LeavePythonExecution(HPyContext *ctx) {
598+
return ctx->ctx_LeavePythonExecution ( ctx );
599+
}
600+
601601
HPyAPI_FUNC void HPyGlobal_Store(HPyContext *ctx, HPyGlobal *global, HPy h) {
602602
ctx->ctx_Global_Store ( ctx, global, h );
603603
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22
// automatically generated by setup.py:get_scm_config()
3-
#define HPY_VERSION "0.0.4.dev216+gf941e8f"
4-
#define HPY_GIT_REVISION "f941e8f"
3+
#define HPY_VERSION "0.0.4"
4+
#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
@@ -85,12 +85,12 @@ ctx_Tracker_New(HPyContext *ctx, HPy_ssize_t capacity)
8585
}
8686
capacity++; // always reserve space for an extra handle, see the docs
8787

88-
hp = malloc(sizeof(_HPyTracker_s));
88+
hp = (_HPyTracker_s*)malloc(sizeof(_HPyTracker_s));
8989
if (hp == NULL) {
9090
HPyErr_NoMemory(ctx);
9191
return _hp2ht(0);
9292
}
93-
hp->handles = calloc(capacity, sizeof(HPy));
93+
hp->handles = (HPy*)calloc(capacity, sizeof(HPy));
9494
if (hp->handles == NULL) {
9595
free(hp);
9696
HPyErr_NoMemory(ctx);
@@ -118,7 +118,7 @@ tracker_resize(HPyContext *ctx, _HPyTracker_s *hp, HPy_ssize_t capacity)
118118
HPyErr_SetString(ctx, ctx->h_ValueError, "HPyTracker resize would lose handles");
119119
return -1;
120120
}
121-
new_handles = realloc(hp->handles, capacity * sizeof(HPy));
121+
new_handles = (HPy*)realloc(hp->handles, capacity * sizeof(HPy));
122122
if (new_handles == NULL) {
123123
HPyErr_NoMemory(ctx);
124124
return -1;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
11
from .leakdetector import HPyDebugError, HPyLeakError, LeakDetector
2+
3+
4+
def set_handle_stack_trace_limit(limit):
5+
from hpy.universal import _debug
6+
_debug.set_handle_stack_trace_limit(limit)
7+
8+
9+
def disable_handle_stack_traces():
10+
from hpy.universal import _debug
11+
_debug.set_handle_stack_trace_limit(None)

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,26 @@ def handle_hpy_ext_modules(dist, attr, hpy_ext_modules):
123123
124124
def __bootstrap__():
125125
126-
import sys, pkg_resources
126+
from sys import modules
127+
from os import environ
128+
from pkg_resources import resource_filename
127129
from hpy.universal import load
128-
ext_filepath = pkg_resources.resource_filename(__name__, {ext_file!r})
129-
m = load({module_name!r}, ext_filepath)
130+
env_debug = environ.get('HPY_DEBUG')
131+
is_debug = env_debug is not None and (env_debug == "1" or __name__ in env_debug.split(","))
132+
ext_filepath = resource_filename(__name__, {ext_file!r})
133+
if 'HPY_LOG' in environ:
134+
if is_debug:
135+
print("Loading {module_name!r} in HPy universal mode with a debug context")
136+
else:
137+
print("Loading {module_name!r} in HPy universal mode")
138+
m = load({module_name!r}, ext_filepath, debug=is_debug)
130139
m.__file__ = ext_filepath
131140
m.__loader__ = __loader__
132141
m.__name__ = __name__
133142
m.__package__ = __package__
134143
m.__spec__ = __spec__
135144
m.__spec__.origin = ext_filepath
136-
sys.modules[__name__] = m
145+
modules[__name__] = m
137146
138147
__bootstrap__()
139148
"""

0 commit comments

Comments
 (0)