1
1
/*
2
- * Copyright (c) 2019, 2021 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2019, 2022 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* The Universal Permissive License (UPL), Version 1.0
@@ -56,7 +56,10 @@ static HPyContext *g_debug_ctx;
56
56
typedef HPyDef * HPyDefPtr ;
57
57
58
58
POLYGLOT_DECLARE_TYPE (HPy )
59
+ POLYGLOT_DECLARE_TYPE (HPyField )
60
+ POLYGLOT_DECLARE_TYPE (HPyGlobal )
59
61
POLYGLOT_DECLARE_TYPE (HPyContext )
62
+ POLYGLOT_DECLARE_TYPE (HPyThreadState )
60
63
POLYGLOT_DECLARE_TYPE (HPyDef )
61
64
POLYGLOT_DECLARE_TYPE (HPyDef_Kind )
62
65
POLYGLOT_DECLARE_TYPE (HPyDefPtr )
@@ -82,6 +85,7 @@ int graal_hpy_init(HPyContext *context, void *initObject) {
82
85
// register the native type of HPy
83
86
polyglot_invoke (initObject , "setHPyContextNativeType" , polyglot_HPyContext_typeid ());
84
87
polyglot_invoke (initObject , "setHPyNativeType" , polyglot_HPy_typeid ());
88
+ polyglot_invoke (initObject , "setHPyFieldNativeType" , polyglot_HPyField_typeid ());
85
89
polyglot_invoke (initObject , "setHPyArrayNativeType" , polyglot_array_typeid (polyglot_HPy_typeid (), 0 ));
86
90
87
91
// register size of wchar_t
@@ -142,11 +146,11 @@ void* graal_hpy_from_HPyType_SpecParam_array(HPyType_SpecParam *ptr) {
142
146
}
143
147
144
148
void * graal_hpy_get_m_name (HPyModuleDef * moduleDef ) {
145
- return polyglot_from_string (moduleDef -> m_name , SRC_CS );
149
+ return polyglot_from_string (moduleDef -> name , SRC_CS );
146
150
}
147
151
148
152
void * graal_hpy_get_m_doc (HPyModuleDef * moduleDef ) {
149
- const char * m_doc = moduleDef -> m_doc ;
153
+ const char * m_doc = moduleDef -> doc ;
150
154
if (m_doc ) {
151
155
return polyglot_from_string (m_doc , SRC_CS );
152
156
}
@@ -167,6 +171,22 @@ HPyFunc_Signature graal_hpy_meth_get_signature(HPyMeth *methodDef) {
167
171
return methodDef -> signature ;
168
172
}
169
173
174
+ void * graal_hpy_get_field_i (HPyField * hf ) {
175
+ return hf -> _i ;
176
+ }
177
+
178
+ void graal_hpy_set_field_i (HPyField * hf , void * i ) {
179
+ hf -> _i = i ;
180
+ }
181
+
182
+ void * graal_hpy_get_global_i (HPyGlobal * hg ) {
183
+ return hg -> _i ;
184
+ }
185
+
186
+ void graal_hpy_set_global_i (HPyGlobal * hg , void * i ) {
187
+ hg -> _i = i ;
188
+ }
189
+
170
190
/* getters for HPySlot */
171
191
172
192
HPySlot_Slot graal_hpy_slot_get_slot (HPySlot * slot ) {
@@ -297,6 +317,17 @@ void* graal_hpy_from_string(const char *ptr) {
297
317
return polyglot_from_string (ptr , SRC_CS );
298
318
}
299
319
320
+ int graal_hpy_get_errno () {
321
+ return errno ;
322
+ }
323
+
324
+ void * graal_hpy_get_strerror (int i ) {
325
+ if (i != 0 ) {
326
+ return polyglot_from_string (strerror (i ), SRC_CS );
327
+ }
328
+ return polyglot_from_string ("Error" , SRC_CS );
329
+ }
330
+
300
331
uint64_t graal_hpy_strlen (const char * ptr ) {
301
332
return strlen (ptr );
302
333
}
@@ -624,12 +655,17 @@ HPy_buffer *graal_hpy_allocate_buffer() {
624
655
#define _h2py (_x ) NULL
625
656
626
657
typedef HPy * _HPyPtr ;
658
+ typedef HPyField * _HPyFieldPtr ;
627
659
typedef HPy _HPyConst ;
660
+ typedef HPyGlobal * _HPyGlobalPtr ;
628
661
629
662
#define HPy void*
630
663
#define HPyListBuilder void*
631
664
#define HPyTupleBuilder void*
632
665
#define HPyTracker void*
666
+ #define HPyField void*
667
+ #define HPyThreadState void*
668
+ #define HPyGlobal void*
633
669
634
670
#define SELECT_CTX (__ctx__ ) ((__ctx__) == g_universal_ctx ? g_universal_ctx : g_debug_ctx)
635
671
@@ -728,6 +764,14 @@ HPyAPI_STORAGE HPy_ssize_t _HPy_IMPL_NAME(Long_AsSsize_t)(HPyContext *ctx, HPy h
728
764
return (HPy_ssize_t ) UPCALL_I64 (ctx_Long_AsSsize_t , ctx , h );
729
765
}
730
766
767
+ HPyAPI_STORAGE void * _HPy_IMPL_NAME (Long_AsVoidPtr )(HPyContext * ctx , HPy h ) {
768
+ return (void * ) UPCALL_I64 (ctx_Long_AsVoidPtr , ctx , h );
769
+ }
770
+
771
+ HPyAPI_STORAGE double _HPy_IMPL_NAME (Long_AsDouble )(HPyContext * ctx , HPy h ) {
772
+ return UPCALL_DOUBLE (ctx_Long_AsDouble , ctx , h );
773
+ }
774
+
731
775
HPyAPI_STORAGE HPy _HPy_IMPL_NAME (Float_FromDouble )(HPyContext * ctx , double v )
732
776
{
733
777
return UPCALL_HPY (ctx_Float_FromDouble , ctx , v );
@@ -943,11 +987,23 @@ HPyAPI_STORAGE void _HPy_IMPL_NAME(Err_SetObject)(HPyContext *ctx, HPy h_type, H
943
987
UPCALL_VOID (ctx_Err_SetObject , ctx , h_type , h_value );
944
988
}
945
989
990
+ HPyAPI_STORAGE HPy _HPy_IMPL_NAME (Err_SetFromErrnoWithFilename )(HPyContext * ctx , HPy h_type , const char * filename_fsencoded ) {
991
+ return UPCALL_HPY (ctx_Err_SetFromErrnoWithFilename , ctx , h_type , filename_fsencoded );
992
+ }
993
+
994
+ HPyAPI_STORAGE HPy _HPy_IMPL_NAME (Err_SetFromErrnoWithFilenameObjects )(HPyContext * ctx , HPy h_type , HPy filename1 , HPy filename2 ) {
995
+ return UPCALL_HPY (ctx_Err_SetFromErrnoWithFilenameObjects , ctx , h_type , filename1 , filename2 );
996
+ }
997
+
946
998
HPyAPI_STORAGE int _HPy_IMPL_NAME (Err_Occurred )(HPyContext * ctx )
947
999
{
948
1000
return (int ) polyglot_as_i32 (UPCALL_HPY0 (ctx_Err_Occurred , ctx ));
949
1001
}
950
1002
1003
+ HPyAPI_STORAGE int _HPy_IMPL_NAME (Err_ExceptionMatches )(HPyContext * ctx , HPy exc ) {
1004
+ return (int ) UPCALL_I32 (ctx_Err_ExceptionMatches , ctx , exc );
1005
+ }
1006
+
951
1007
HPyAPI_STORAGE HPy _HPy_IMPL_NAME (Err_NoMemory )(HPyContext * ctx )
952
1008
{
953
1009
return UPCALL_HPY0 (ctx_Err_NoMemory , ctx );
@@ -966,6 +1022,18 @@ HPyAPI_STORAGE HPy _HPy_IMPL_NAME(Err_NewExceptionWithDoc)(HPyContext *ctx, cons
966
1022
return UPCALL_HPY (ctx_Err_NewExceptionWithDoc , ctx , name , doc , base , dict );
967
1023
}
968
1024
1025
+ HPyAPI_STORAGE int _HPy_IMPL_NAME (Err_WarnEx )(HPyContext * ctx , HPy category , const char * message , HPy_ssize_t stack_level ) {
1026
+ return (int ) UPCALL_I32 (ctx_Err_WarnEx , ctx , category , message , stack_level );
1027
+ }
1028
+
1029
+ HPyAPI_STORAGE void _HPy_IMPL_NAME (Err_WriteUnraisable )(HPyContext * ctx , HPy obj ) {
1030
+ UPCALL_VOID (ctx_Err_WriteUnraisable , ctx , obj );
1031
+ }
1032
+
1033
+ HPyAPI_STORAGE void _HPy_IMPL_NAME (FatalError )(HPyContext * ctx , const char * msg ) {
1034
+ UPCALL_VOID (ctx_FatalError , ctx , msg );
1035
+ }
1036
+
969
1037
HPyAPI_STORAGE int _HPy_IMPL_NAME_NOPREFIX (IsTrue )(HPyContext * ctx , HPy h )
970
1038
{
971
1039
return UPCALL_HPY (ctx_IsTrue , ctx , h );
@@ -1026,6 +1094,10 @@ HPyAPI_STORAGE HPy _HPy_IMPL_NAME_NOPREFIX(GetItem_s)(HPyContext *ctx, HPy obj,
1026
1094
return UPCALL_HPY (ctx_GetItem_s , ctx , obj , key );
1027
1095
}
1028
1096
1097
+ HPyAPI_STORAGE int _HPy_IMPL_NAME_NOPREFIX (Contains )(HPyContext * ctx , HPy container , HPy key ) {
1098
+ return (int ) UPCALL_I32 (ctx_Contains , ctx , container , key );
1099
+ }
1100
+
1029
1101
HPyAPI_STORAGE int _HPy_IMPL_NAME_NOPREFIX (SetItem )(HPyContext * ctx , HPy obj , HPy key , HPy value )
1030
1102
{
1031
1103
return UPCALL_HPY (ctx_SetItem , ctx , obj , key , value );
@@ -1151,6 +1223,14 @@ HPyAPI_STORAGE int _HPy_IMPL_NAME(Unicode_Check)(HPyContext *ctx, HPy h)
1151
1223
return (int ) UPCALL_I32 (ctx_Unicode_Check , ctx , h );
1152
1224
}
1153
1225
1226
+ HPyAPI_STORAGE HPy _HPy_IMPL_NAME (Unicode_AsASCIIString )(HPyContext * ctx , HPy h ) {
1227
+ return UPCALL_HPY (ctx_Unicode_AsASCIIString , ctx , h );
1228
+ }
1229
+
1230
+ HPyAPI_STORAGE HPy _HPy_IMPL_NAME (Unicode_AsLatin1String )(HPyContext * ctx , HPy h ) {
1231
+ return UPCALL_HPY (ctx_Unicode_AsLatin1String , ctx , h );
1232
+ }
1233
+
1154
1234
HPyAPI_STORAGE HPy _HPy_IMPL_NAME (Unicode_AsUTF8String )(HPyContext * ctx , HPy h )
1155
1235
{
1156
1236
return UPCALL_HPY (ctx_Unicode_AsUTF8String , ctx , h );
@@ -1170,6 +1250,26 @@ HPyAPI_STORAGE HPy _HPy_IMPL_NAME(Unicode_DecodeFSDefault)(HPyContext *ctx, cons
1170
1250
return UPCALL_HPY (ctx_Unicode_DecodeFSDefault , ctx , v );
1171
1251
}
1172
1252
1253
+ HPyAPI_STORAGE HPy _HPy_IMPL_NAME (Unicode_DecodeFSDefaultAndSize )(HPyContext * ctx , const char * v , HPy_ssize_t size ) {
1254
+ return UPCALL_HPY (ctx_Unicode_DecodeFSDefaultAndSize , ctx , v , size );
1255
+ }
1256
+
1257
+ HPyAPI_STORAGE HPy _HPy_IMPL_NAME (Unicode_EncodeFSDefault )(HPyContext * ctx , HPy h ) {
1258
+ return UPCALL_HPY (ctx_Unicode_EncodeFSDefault , ctx , h );
1259
+ }
1260
+
1261
+ HPyAPI_STORAGE uint32_t _HPy_IMPL_NAME (Unicode_ReadChar )(HPyContext * ctx , HPy h , HPy_ssize_t index ) {
1262
+ return (uint32_t ) UPCALL_I32 (ctx_Unicode_ReadChar , ctx , h , index );
1263
+ }
1264
+
1265
+ HPyAPI_STORAGE HPy _HPy_IMPL_NAME (Unicode_DecodeLatin1 )(HPyContext * ctx , const char * s , HPy_ssize_t size , const char * errors ) {
1266
+ return UPCALL_HPY (ctx_Unicode_DecodeLatin1 , ctx , s , size , errors );
1267
+ }
1268
+
1269
+ HPyAPI_STORAGE HPy _HPy_IMPL_NAME (Unicode_DecodeASCII )(HPyContext * ctx , const char * s , HPy_ssize_t size , const char * errors ) {
1270
+ return UPCALL_HPY (ctx_Unicode_DecodeASCII , ctx , s , size , errors );
1271
+ }
1272
+
1173
1273
HPyAPI_STORAGE int _HPy_IMPL_NAME (List_Check )(HPyContext * ctx , HPy h )
1174
1274
{
1175
1275
return (int ) UPCALL_I32 (ctx_List_Check , ctx , h );
@@ -1271,6 +1371,30 @@ HPyAPI_STORAGE void _HPy_IMPL_NAME(Tracker_Close)(HPyContext *ctx, HPyTracker ht
1271
1371
UPCALL_VOID (ctx_Tracker_Close , ctx , ht );
1272
1372
}
1273
1373
1374
+ HPyAPI_STORAGE void _HPy_IMPL_NAME (Field_Store )(HPyContext * ctx , HPy target_object , _HPyFieldPtr target_field , HPy h ) {
1375
+ UPCALL_VOID (ctx_Field_Store , ctx , target_object , target_field , h );
1376
+ }
1377
+
1378
+ HPyAPI_STORAGE HPy _HPy_IMPL_NAME (Field_Load )(HPyContext * ctx , HPy source_object , HPyField source_field ) {
1379
+ return UPCALL_HPY (ctx_Field_Load , ctx , source_object , source_field );
1380
+ }
1381
+
1382
+ HPyAPI_STORAGE HPyThreadState _HPy_IMPL_NAME (LeavePythonExecution )(HPyContext * ctx ) {
1383
+ return UPCALL_HPY0 (ctx_LeavePythonExecution , ctx );
1384
+ }
1385
+
1386
+ HPyAPI_STORAGE void _HPy_IMPL_NAME (ReenterPythonExecution )(HPyContext * ctx , HPyThreadState state ) {
1387
+ UPCALL_VOID (ctx_ReenterPythonExecution , ctx , state );
1388
+ }
1389
+
1390
+ HPyAPI_STORAGE void _HPy_IMPL_NAME (Global_Store )(HPyContext * ctx , _HPyGlobalPtr global , HPy h ) {
1391
+ UPCALL_VOID (ctx_Global_Store , ctx , global , h );
1392
+ }
1393
+
1394
+ HPyAPI_STORAGE HPy _HPy_IMPL_NAME (Global_Load )(HPyContext * ctx , HPyGlobal global ) {
1395
+ return UPCALL_HPY (ctx_Global_Load , ctx , global );
1396
+ }
1397
+
1274
1398
HPyAPI_STORAGE void _HPy_IMPL_NAME (Dump )(HPyContext * ctx , HPy h ) {
1275
1399
UPCALL_VOID (ctx_Dump , ctx , h );
1276
1400
}
@@ -1279,6 +1403,9 @@ HPyAPI_STORAGE void _HPy_IMPL_NAME(Dump)(HPyContext *ctx, HPy h) {
1279
1403
#undef HPyListBuilder
1280
1404
#undef HPyTupleBuilder
1281
1405
#undef HPyTracker
1406
+ #undef HPyField
1407
+ #undef HPyThreadState
1408
+ #undef HPyGlobal
1282
1409
1283
1410
#undef _HPy_IMPL_NAME_NOPREFIX
1284
1411
#undef _HPy_IMPL_NAME
@@ -1292,14 +1419,14 @@ HPyContext *graal_hpy_context_to_native(HPyContext *managed_context, HPyContext
1292
1419
HPyContext * native_context = graal_native_context_get_hpy_context (full_native_context );
1293
1420
1294
1421
#define COPY (__member ) native_context->__member = managed_context->__member
1295
- COPY (name );
1296
- COPY (ctx_version );
1297
- COPY (h_None );
1298
- COPY (h_True );
1299
- COPY (h_False );
1300
- COPY (h_NotImplemented );
1301
- COPY (h_Ellipsis );
1302
- COPY (h_BaseException );
1422
+ COPY (name );
1423
+ COPY (ctx_version );
1424
+ COPY (h_None );
1425
+ COPY (h_True );
1426
+ COPY (h_False );
1427
+ COPY (h_NotImplemented );
1428
+ COPY (h_Ellipsis );
1429
+ COPY (h_BaseException );
1303
1430
COPY (h_Exception );
1304
1431
COPY (h_StopAsyncIteration );
1305
1432
COPY (h_StopIteration );
@@ -1365,7 +1492,9 @@ HPyContext *graal_hpy_context_to_native(HPyContext *managed_context, HPyContext
1365
1492
COPY (h_ResourceWarning );
1366
1493
COPY (h_BaseObjectType );
1367
1494
COPY (h_TypeType );
1495
+ COPY (h_BoolType );
1368
1496
COPY (h_LongType );
1497
+ COPY (h_FloatType );
1369
1498
COPY (h_UnicodeType );
1370
1499
COPY (h_TupleType );
1371
1500
COPY (h_ListType );
@@ -1449,6 +1578,7 @@ HPyContext *graal_hpy_context_to_native(HPyContext *managed_context, HPyContext
1449
1578
HPY_CTX_UPCALL (ctx_GetItem );
1450
1579
HPY_CTX_UPCALL (ctx_GetItem_i );
1451
1580
HPY_CTX_UPCALL (ctx_GetItem_s );
1581
+ HPY_CTX_UPCALL (ctx_Contains );
1452
1582
HPY_CTX_UPCALL (ctx_SetItem );
1453
1583
HPY_CTX_UPCALL (ctx_SetItem_i );
1454
1584
HPY_CTX_UPCALL (ctx_SetItem_s );
@@ -1500,7 +1630,29 @@ HPyContext *graal_hpy_context_to_native(HPyContext *managed_context, HPyContext
1500
1630
HPY_CTX_UPCALL (ctx_Tracker_Add );
1501
1631
HPY_CTX_UPCALL (ctx_Tracker_ForgetAll );
1502
1632
HPY_CTX_UPCALL (ctx_Tracker_Close );
1633
+ HPY_CTX_UPCALL (ctx_Field_Store );
1634
+ HPY_CTX_UPCALL (ctx_Field_Load );
1635
+ HPY_CTX_UPCALL (ctx_LeavePythonExecution );
1636
+ HPY_CTX_UPCALL (ctx_ReenterPythonExecution );
1637
+ HPY_CTX_UPCALL (ctx_Global_Store );
1638
+ HPY_CTX_UPCALL (ctx_Global_Load );
1503
1639
HPY_CTX_UPCALL (ctx_Dump );
1640
+ HPY_CTX_UPCALL (ctx_Long_AsVoidPtr );
1641
+ HPY_CTX_UPCALL (ctx_Long_AsDouble );
1642
+ HPY_CTX_UPCALL (ctx_Err_SetFromErrnoWithFilename );
1643
+ HPY_CTX_UPCALL (ctx_Err_SetFromErrnoWithFilenameObjects );
1644
+ HPY_CTX_UPCALL (ctx_Err_ExceptionMatches );
1645
+ HPY_CTX_UPCALL (ctx_Err_WarnEx );
1646
+ HPY_CTX_UPCALL (ctx_Err_WriteUnraisable );
1647
+ HPY_CTX_UPCALL (ctx_FatalError );
1648
+ HPY_CTX_UPCALL (ctx_Unicode_AsASCIIString );
1649
+ HPY_CTX_UPCALL (ctx_Unicode_AsLatin1String );
1650
+ HPY_CTX_UPCALL (ctx_Unicode_DecodeFSDefaultAndSize );
1651
+ HPY_CTX_UPCALL (ctx_Unicode_EncodeFSDefault );
1652
+ HPY_CTX_UPCALL (ctx_Unicode_ReadChar );
1653
+ HPY_CTX_UPCALL (ctx_Unicode_DecodeLatin1 );
1654
+ HPY_CTX_UPCALL (ctx_Unicode_DecodeASCII );
1655
+
1504
1656
#undef HPY_CTX_UPCALL
1505
1657
1506
1658
return native_context ;
0 commit comments