Skip to content

Commit 68da934

Browse files
committed
[GR-39997] [GR-40001] Auto-generate HPy backends.
PullRequest: graalpython/2806
2 parents 79289d4 + 9bb75e0 commit 68da934

File tree

68 files changed

+14423
-7121
lines changed

Some content is hidden

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

68 files changed

+14423
-7121
lines changed

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

Lines changed: 8 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ int Py_EXPORTED_SYMBOL graal_hpy_init(HPyContext *context, void *initObject) {
9696
return 0;
9797
}
9898

99+
void *graal_hpy_long2ptr(int64_t lval) {
100+
return (void *)lval;
101+
}
102+
99103
/* Call from Java if the HPy debug context is initialized. */
100104
void graal_hpy_set_debug_context(HPyContext *debug_ctx) {
101105
g_debug_ctx = debug_ctx;
@@ -339,11 +343,11 @@ int graal_hpy_get_errno() {
339343
return errno;
340344
}
341345

342-
void* graal_hpy_get_strerror(int i) {
346+
char *graal_hpy_get_strerror(int i) {
343347
if (i != 0) {
344-
return polyglot_from_string(strerror(i), SRC_CS);
348+
return strerror(i);
345349
}
346-
return polyglot_from_string("Error", SRC_CS);
350+
return "Error";
347351
}
348352

349353
uint64_t graal_hpy_strlen(const char *ptr) {
@@ -1523,7 +1527,7 @@ HPyAPI_STORAGE HPy _HPy_IMPL_NAME(SeqIter_New)(HPyContext *ctx, HPy seq) {
15231527
#include "hpynative.h"
15241528

15251529
/* Allocate a native HPy context structure and fill it. */
1526-
HPyContext *graal_hpy_context_to_native(HPyContext *managed_context, HPyContext *overrides) {
1530+
HPyContext *graal_hpy_context_to_native(HPyContext *managed_context) {
15271531
GraalHPyContext *full_native_context = (GraalHPyContext *) malloc(sizeof(GraalHPyContext));
15281532

15291533
HPyContext *native_context = graal_native_context_get_hpy_context(full_native_context);
@@ -1615,183 +1619,6 @@ HPyContext *graal_hpy_context_to_native(HPyContext *managed_context, HPyContext
16151619
COPY(h_SliceType);
16161620
#undef COPY
16171621

1618-
#define HPY_CTX_UPCALL(__fun) { void* v = overrides->__fun; if (v != NULL) native_context->__fun = v; else native_context->__fun = __fun; }
1619-
HPY_CTX_UPCALL(ctx_Module_Create);
1620-
HPY_CTX_UPCALL(ctx_Dup);
1621-
HPY_CTX_UPCALL(ctx_Close);
1622-
HPY_CTX_UPCALL(ctx_Long_FromLong)
1623-
HPY_CTX_UPCALL(ctx_Long_FromUnsignedLong)
1624-
HPY_CTX_UPCALL(ctx_Long_FromLongLong)
1625-
HPY_CTX_UPCALL(ctx_Long_FromUnsignedLongLong)
1626-
HPY_CTX_UPCALL(ctx_Long_FromSize_t)
1627-
HPY_CTX_UPCALL(ctx_Long_FromSsize_t)
1628-
HPY_CTX_UPCALL(ctx_Long_AsLong);
1629-
HPY_CTX_UPCALL(ctx_Long_AsUnsignedLong);
1630-
HPY_CTX_UPCALL(ctx_Long_AsUnsignedLongMask);
1631-
HPY_CTX_UPCALL(ctx_Long_AsLongLong);
1632-
HPY_CTX_UPCALL(ctx_Long_AsUnsignedLongLong);
1633-
HPY_CTX_UPCALL(ctx_Long_AsUnsignedLongLongMask);
1634-
HPY_CTX_UPCALL(ctx_Long_AsSize_t);
1635-
HPY_CTX_UPCALL(ctx_Long_AsSsize_t);
1636-
HPY_CTX_UPCALL(ctx_Float_FromDouble);
1637-
HPY_CTX_UPCALL(ctx_Float_AsDouble);
1638-
HPY_CTX_UPCALL(ctx_Bool_FromLong);
1639-
HPY_CTX_UPCALL(ctx_Length);
1640-
HPY_CTX_UPCALL(ctx_Number_Check);
1641-
HPY_CTX_UPCALL(ctx_Add);
1642-
HPY_CTX_UPCALL(ctx_Subtract);
1643-
HPY_CTX_UPCALL(ctx_Multiply);
1644-
HPY_CTX_UPCALL(ctx_MatrixMultiply);
1645-
HPY_CTX_UPCALL(ctx_FloorDivide);
1646-
HPY_CTX_UPCALL(ctx_TrueDivide);
1647-
HPY_CTX_UPCALL(ctx_Remainder);
1648-
HPY_CTX_UPCALL(ctx_Divmod);
1649-
HPY_CTX_UPCALL(ctx_Power);
1650-
HPY_CTX_UPCALL(ctx_Negative);
1651-
HPY_CTX_UPCALL(ctx_Positive);
1652-
HPY_CTX_UPCALL(ctx_Absolute);
1653-
HPY_CTX_UPCALL(ctx_Invert);
1654-
HPY_CTX_UPCALL(ctx_Lshift);
1655-
HPY_CTX_UPCALL(ctx_Rshift);
1656-
HPY_CTX_UPCALL(ctx_And);
1657-
HPY_CTX_UPCALL(ctx_Xor);
1658-
HPY_CTX_UPCALL(ctx_Or);
1659-
HPY_CTX_UPCALL(ctx_Index);
1660-
HPY_CTX_UPCALL(ctx_Long);
1661-
HPY_CTX_UPCALL(ctx_Float);
1662-
HPY_CTX_UPCALL(ctx_InPlaceAdd);
1663-
HPY_CTX_UPCALL(ctx_InPlaceSubtract);
1664-
HPY_CTX_UPCALL(ctx_InPlaceMultiply);
1665-
HPY_CTX_UPCALL(ctx_InPlaceMatrixMultiply);
1666-
HPY_CTX_UPCALL(ctx_InPlaceFloorDivide);
1667-
HPY_CTX_UPCALL(ctx_InPlaceTrueDivide);
1668-
HPY_CTX_UPCALL(ctx_InPlaceRemainder);
1669-
HPY_CTX_UPCALL(ctx_InPlacePower);
1670-
HPY_CTX_UPCALL(ctx_InPlaceLshift);
1671-
HPY_CTX_UPCALL(ctx_InPlaceRshift);
1672-
HPY_CTX_UPCALL(ctx_InPlaceAnd);
1673-
HPY_CTX_UPCALL(ctx_InPlaceXor);
1674-
HPY_CTX_UPCALL(ctx_InPlaceOr);
1675-
HPY_CTX_UPCALL(ctx_Callable_Check);
1676-
HPY_CTX_UPCALL(ctx_CallTupleDict);
1677-
HPY_CTX_UPCALL(ctx_Err_SetString);
1678-
HPY_CTX_UPCALL(ctx_Err_SetObject);
1679-
HPY_CTX_UPCALL(ctx_Err_Occurred);
1680-
HPY_CTX_UPCALL(ctx_Err_NoMemory);
1681-
HPY_CTX_UPCALL(ctx_Err_Clear);
1682-
HPY_CTX_UPCALL(ctx_Err_NewException);
1683-
HPY_CTX_UPCALL(ctx_Err_NewExceptionWithDoc);
1684-
HPY_CTX_UPCALL(ctx_IsTrue);
1685-
HPY_CTX_UPCALL(ctx_Type_FromSpec);
1686-
HPY_CTX_UPCALL(ctx_Type_GenericNew);
1687-
HPY_CTX_UPCALL(ctx_GetAttr);
1688-
HPY_CTX_UPCALL(ctx_GetAttr_s);
1689-
HPY_CTX_UPCALL(ctx_HasAttr);
1690-
HPY_CTX_UPCALL(ctx_HasAttr_s);
1691-
HPY_CTX_UPCALL(ctx_SetAttr);
1692-
HPY_CTX_UPCALL(ctx_SetAttr_s);
1693-
HPY_CTX_UPCALL(ctx_GetItem);
1694-
HPY_CTX_UPCALL(ctx_GetItem_i);
1695-
HPY_CTX_UPCALL(ctx_GetItem_s);
1696-
HPY_CTX_UPCALL(ctx_Contains);
1697-
HPY_CTX_UPCALL(ctx_SetItem);
1698-
HPY_CTX_UPCALL(ctx_SetItem_i);
1699-
HPY_CTX_UPCALL(ctx_SetItem_s);
1700-
HPY_CTX_UPCALL(ctx_Type);
1701-
HPY_CTX_UPCALL(ctx_TypeCheck);
1702-
HPY_CTX_UPCALL(ctx_TypeCheck_g);
1703-
HPY_CTX_UPCALL(ctx_Is);
1704-
HPY_CTX_UPCALL(ctx_Is_g);
1705-
HPY_CTX_UPCALL(ctx_AsStruct);
1706-
HPY_CTX_UPCALL(ctx_AsStructLegacy);
1707-
HPY_CTX_UPCALL(ctx_New);
1708-
HPY_CTX_UPCALL(ctx_Repr);
1709-
HPY_CTX_UPCALL(ctx_Str);
1710-
HPY_CTX_UPCALL(ctx_ASCII);
1711-
HPY_CTX_UPCALL(ctx_Bytes);
1712-
HPY_CTX_UPCALL(ctx_RichCompare);
1713-
HPY_CTX_UPCALL(ctx_RichCompareBool);
1714-
HPY_CTX_UPCALL(ctx_Hash);
1715-
HPY_CTX_UPCALL(ctx_Bytes_Check);
1716-
HPY_CTX_UPCALL(ctx_Bytes_Size);
1717-
HPY_CTX_UPCALL(ctx_Bytes_GET_SIZE);
1718-
HPY_CTX_UPCALL(ctx_Bytes_AsString);
1719-
HPY_CTX_UPCALL(ctx_Bytes_AS_STRING);
1720-
HPY_CTX_UPCALL(ctx_Bytes_FromString);
1721-
HPY_CTX_UPCALL(ctx_Bytes_FromStringAndSize);
1722-
HPY_CTX_UPCALL(ctx_Unicode_FromString);
1723-
HPY_CTX_UPCALL(ctx_Unicode_Check);
1724-
HPY_CTX_UPCALL(ctx_Unicode_AsUTF8String);
1725-
HPY_CTX_UPCALL(ctx_Unicode_AsUTF8AndSize);
1726-
HPY_CTX_UPCALL(ctx_Unicode_FromWideChar);
1727-
HPY_CTX_UPCALL(ctx_Unicode_DecodeFSDefault);
1728-
HPY_CTX_UPCALL(ctx_List_Check);
1729-
HPY_CTX_UPCALL(ctx_List_New);
1730-
HPY_CTX_UPCALL(ctx_List_Append);
1731-
HPY_CTX_UPCALL(ctx_Dict_Check);
1732-
HPY_CTX_UPCALL(ctx_Dict_New);
1733-
HPY_CTX_UPCALL(ctx_Tuple_Check);
1734-
HPY_CTX_UPCALL(ctx_Tuple_FromArray);
1735-
HPY_CTX_UPCALL(ctx_Import_ImportModule);
1736-
HPY_CTX_UPCALL(ctx_FromPyObject);
1737-
HPY_CTX_UPCALL(ctx_AsPyObject);
1738-
HPY_CTX_UPCALL(ctx_ListBuilder_New);
1739-
HPY_CTX_UPCALL(ctx_ListBuilder_Set);
1740-
HPY_CTX_UPCALL(ctx_ListBuilder_Build);
1741-
HPY_CTX_UPCALL(ctx_ListBuilder_Cancel);
1742-
HPY_CTX_UPCALL(ctx_TupleBuilder_New);
1743-
HPY_CTX_UPCALL(ctx_TupleBuilder_Set);
1744-
HPY_CTX_UPCALL(ctx_TupleBuilder_Build);
1745-
HPY_CTX_UPCALL(ctx_TupleBuilder_Cancel);
1746-
HPY_CTX_UPCALL(ctx_Tracker_New);
1747-
HPY_CTX_UPCALL(ctx_Tracker_Add);
1748-
HPY_CTX_UPCALL(ctx_Tracker_ForgetAll);
1749-
HPY_CTX_UPCALL(ctx_Tracker_Close);
1750-
HPY_CTX_UPCALL(ctx_Field_Store);
1751-
HPY_CTX_UPCALL(ctx_Field_Load);
1752-
HPY_CTX_UPCALL(ctx_LeavePythonExecution);
1753-
HPY_CTX_UPCALL(ctx_ReenterPythonExecution);
1754-
HPY_CTX_UPCALL(ctx_Global_Store);
1755-
HPY_CTX_UPCALL(ctx_Global_Load);
1756-
HPY_CTX_UPCALL(ctx_Dump);
1757-
HPY_CTX_UPCALL(ctx_Long_AsVoidPtr);
1758-
HPY_CTX_UPCALL(ctx_Long_AsDouble);
1759-
HPY_CTX_UPCALL(ctx_Err_SetFromErrnoWithFilename);
1760-
HPY_CTX_UPCALL(ctx_Err_SetFromErrnoWithFilenameObjects);
1761-
HPY_CTX_UPCALL(ctx_Err_ExceptionMatches);
1762-
HPY_CTX_UPCALL(ctx_Err_WarnEx);
1763-
HPY_CTX_UPCALL(ctx_Err_WriteUnraisable);
1764-
HPY_CTX_UPCALL(ctx_FatalError);
1765-
HPY_CTX_UPCALL(ctx_Unicode_AsASCIIString);
1766-
HPY_CTX_UPCALL(ctx_Unicode_AsLatin1String);
1767-
HPY_CTX_UPCALL(ctx_Unicode_DecodeFSDefaultAndSize);
1768-
HPY_CTX_UPCALL(ctx_Unicode_EncodeFSDefault);
1769-
HPY_CTX_UPCALL(ctx_Unicode_ReadChar);
1770-
HPY_CTX_UPCALL(ctx_Unicode_DecodeLatin1);
1771-
HPY_CTX_UPCALL(ctx_Unicode_DecodeASCII);
1772-
HPY_CTX_UPCALL(ctx_MaybeGetAttr_s);
1773-
HPY_CTX_UPCALL(ctx_SetType);
1774-
HPY_CTX_UPCALL(ctx_Type_IsSubtype);
1775-
HPY_CTX_UPCALL(ctx_Type_GetName);
1776-
HPY_CTX_UPCALL(ctx_Unicode_FromEncodedObject);
1777-
HPY_CTX_UPCALL(ctx_Unicode_InternFromString);
1778-
HPY_CTX_UPCALL(ctx_Unicode_Substring);
1779-
HPY_CTX_UPCALL(ctx_Dict_Keys);
1780-
HPY_CTX_UPCALL(ctx_Dict_GetItem);
1781-
HPY_CTX_UPCALL(ctx_ContextVar_New);
1782-
HPY_CTX_UPCALL(ctx_ContextVar_Get);
1783-
HPY_CTX_UPCALL(ctx_ContextVar_Set);
1784-
HPY_CTX_UPCALL(ctx_Capsule_New);
1785-
HPY_CTX_UPCALL(ctx_Capsule_Get);
1786-
HPY_CTX_UPCALL(ctx_Capsule_IsValid);
1787-
HPY_CTX_UPCALL(ctx_Capsule_Set);
1788-
HPY_CTX_UPCALL(ctx_Type_CheckSlot);
1789-
HPY_CTX_UPCALL(ctx_Sequence_Check);
1790-
HPY_CTX_UPCALL(ctx_Slice_Unpack);
1791-
HPY_CTX_UPCALL(ctx_SeqIter_New);
1792-
1793-
#undef HPY_CTX_UPCALL
1794-
17951622
return native_context;
17961623
}
17971624

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -47,6 +47,7 @@
4747
#include "hpy.h"
4848

4949
typedef struct {
50+
void *jni_backend;
5051
void *jni_context;
5152

5253
/* embed HPy context */

0 commit comments

Comments
 (0)