@@ -220,6 +220,42 @@ static void ctx_Field_Store_jni(HPyContext *ctx, HPy owner, HPyField *field, HPy
220
220
field -> _i = DO_UPCALL_SIZE_T (CONTEXT_INSTANCE (ctx ), FieldStore , HPY_UP (owner ), field -> _i , HPY_UP (value ));
221
221
}
222
222
223
+ static const char * getBoxedPrimitiveName (uint64_t bits ) {
224
+ assert (!isBoxedHandle (bits ));
225
+ if (isBoxedInt (bits )) {
226
+ return "int" ;
227
+ }
228
+ assert (isBoxedDouble (bits ));
229
+ return "float" ;
230
+ }
231
+
232
+ int ctx_SetItem_s_jni (HPyContext * ctx , HPy target , const char * name , HPy value ) {
233
+ uint64_t bits = toBits (target );
234
+ if (!isBoxedHandle (bits )) {
235
+ const size_t buffer_size = 128 ;
236
+ char message [buffer_size ];
237
+ snprintf (message , buffer_size ,
238
+ "'%s' object does not support item assignment" , getBoxedPrimitiveName (bits ));
239
+ HPyErr_SetString (ctx , ctx -> h_TypeError , message );
240
+ return -1 ;
241
+ }
242
+ jstring jname = (* jniEnv )-> NewStringUTF (jniEnv , name );
243
+ return DO_UPCALL_INT (CONTEXT_INSTANCE (ctx ), SetItems , target , jname , value );
244
+ }
245
+
246
+ HPy ctx_GetItem_s_jni (HPyContext * ctx , HPy target , const char * name ) {
247
+ uint64_t bits = toBits (target );
248
+ if (!isBoxedHandle (bits )) {
249
+ const size_t buffer_size = 128 ;
250
+ char message [buffer_size ];
251
+ snprintf (message , buffer_size ,
252
+ "'%s' object is not subscriptable" , getBoxedPrimitiveName (bits ));
253
+ return HPyErr_SetString (ctx , ctx -> h_TypeError , message );
254
+ }
255
+ jstring jname = (* jniEnv )-> NewStringUTF (jniEnv , name );
256
+ return DO_UPCALL_HPY (CONTEXT_INSTANCE (ctx ), GetItems , target , jname );
257
+ }
258
+
223
259
//*************************
224
260
// BOXING
225
261
@@ -556,42 +592,6 @@ void augment_Field_Store(HPyContext *ctx, HPy target_object, HPyField *target_fi
556
592
}
557
593
}
558
594
559
- static const char * getBoxedPrimitiveName (uint64_t bits ) {
560
- assert (!isBoxedHandle (bits ));
561
- if (isBoxedInt (bits )) {
562
- return "int" ;
563
- }
564
- assert (isBoxedDouble (bits ));
565
- return "float" ;
566
- }
567
-
568
- int augment_SetItem_s (HPyContext * ctx , HPy target , const char * name , HPy value ) {
569
- uint64_t bits = toBits (target );
570
- if (!isBoxedHandle (bits )) {
571
- const size_t buffer_size = 128 ;
572
- char message [buffer_size ];
573
- snprintf (message , buffer_size ,
574
- "'%s' object does not support item assignment" , getBoxedPrimitiveName (bits ));
575
- HPyErr_SetString (ctx , ctx -> h_TypeError , message );
576
- return -1 ;
577
- }
578
- jstring jname = (* jniEnv )-> NewStringUTF (jniEnv , name );
579
- return DO_UPCALL_INT (CONTEXT_INSTANCE (ctx ), SetItems , target , jname , value );
580
- }
581
-
582
- HPy augment_GetItem_s (HPyContext * ctx , HPy target , const char * name ) {
583
- uint64_t bits = toBits (target );
584
- if (!isBoxedHandle (bits )) {
585
- const size_t buffer_size = 128 ;
586
- char message [buffer_size ];
587
- snprintf (message , buffer_size ,
588
- "'%s' object is not subscriptable" , getBoxedPrimitiveName (bits ));
589
- return HPyErr_SetString (ctx , ctx -> h_TypeError , message );
590
- }
591
- jstring jname = (* jniEnv )-> NewStringUTF (jniEnv , name );
592
- return DO_UPCALL_HPY (CONTEXT_INSTANCE (ctx ), GetItems , target , jname );
593
- }
594
-
595
595
HPy augment_Type (HPyContext * ctx , HPy h ) {
596
596
uint64_t bits = toBits (h );
597
597
if (isBoxedInt (bits )) {
@@ -662,9 +662,6 @@ void initDirectFastPaths(HPyContext *context) {
662
662
AUGMENT (Type );
663
663
664
664
#undef AUGMENT
665
-
666
- context -> ctx_SetItem_s = augment_SetItem_s ;
667
- context -> ctx_GetItem_s = augment_GetItem_s ;
668
665
}
669
666
670
667
void setHPyContextNativeSpace (HPyContext * context , void * * nativeSpace ) {
@@ -725,6 +722,9 @@ JNIEXPORT jint JNICALL Java_com_oracle_graal_python_builtins_objects_cext_hpy_Gr
725
722
context -> ctx_Field_Load = ctx_Field_Load_jni ;
726
723
context -> ctx_Field_Store = ctx_Field_Store_jni ;
727
724
725
+ context -> ctx_SetItem_s = ctx_SetItem_s_jni ;
726
+ context -> ctx_GetItem_s = ctx_GetItem_s_jni ;
727
+
728
728
graal_hpy_context_get_native_context (context )-> jni_context = (void * ) (* env )-> NewGlobalRef (env , ctx );
729
729
assert (clazz != NULL );
730
730
0 commit comments