@@ -214,17 +214,21 @@ static uint64_t boxDouble(double value) {
214
214
215
215
static void * (* original_AsStruct )(HPyContext * ctx , HPy h );
216
216
static HPy (* original_Dup )(HPyContext * ctx , HPy h );
217
- static HPy (* original_FloatFromDouble )(HPyContext * ctx , double v );
218
- static double (* original_FloatAsDouble )(HPyContext * ctx , HPy h );
219
- static long (* original_LongAsLong )(HPyContext * ctx , HPy h );
220
- static double (* original_LongAsDouble )(HPyContext * ctx , HPy h );
221
- static HPy (* original_LongFromLong )(HPyContext * ctx , long l );
222
- static int (* original_ListCheck )(HPyContext * ctx , HPy h );
223
- static int (* original_NumberCheck )(HPyContext * ctx , HPy h );
217
+ static HPy (* original_Float_FromDouble )(HPyContext * ctx , double v );
218
+ static double (* original_Float_AsDouble )(HPyContext * ctx , HPy h );
219
+ static long (* original_Long_AsLong )(HPyContext * ctx , HPy h );
220
+ static unsigned long (* original_Long_AsUnsignedLong )(HPyContext * ctx , HPy h );
221
+ static double (* original_Long_AsDouble )(HPyContext * ctx , HPy h );
222
+ static HPy (* original_Long_FromLong )(HPyContext * ctx , long l );
223
+ static HPy (* original_Long_FromUnsignedLong )(HPyContext * ctx , unsigned long l );
224
+ static HPy (* original_Long_FromLongLong )(HPyContext * ctx , long long l );
225
+ static HPy (* original_Long_FromUnsignedLongLong )(HPyContext * ctx , unsigned long long l );
226
+ static int (* original_List_Check )(HPyContext * ctx , HPy h );
227
+ static int (* original_Number_Check )(HPyContext * ctx , HPy h );
224
228
static int (* original_TypeCheck )(HPyContext * ctx , HPy h , HPy type );
225
229
static void (* original_Close )(HPyContext * ctx , HPy h );
226
- static HPy (* original_UnicodeFromWideChar )(HPyContext * ctx , const wchar_t * arr , HPy_ssize_t size );
227
- static HPy (* original_TupleFromArray )(HPyContext * ctx , HPy * items , HPy_ssize_t nitems );
230
+ static HPy (* original_Unicode_FromWideChar )(HPyContext * ctx , const wchar_t * arr , HPy_ssize_t size );
231
+ static HPy (* original_Tuple_FromArray )(HPyContext * ctx , HPy * items , HPy_ssize_t nitems );
228
232
static int (* original_Is )(HPyContext * ctx , HPy a , HPy b );
229
233
230
234
static int augment_Is (HPyContext * ctx , HPy a , HPy b ) {
@@ -249,45 +253,81 @@ static void *augment_AsStruct(HPyContext *ctx, HPy h) {
249
253
}
250
254
}
251
255
252
- static HPy augment_FloatFromDouble (HPyContext * ctx , double v ) {
256
+ static HPy augment_Float_FromDouble (HPyContext * ctx , double v ) {
253
257
return toPtr (boxDouble (v ));
254
258
}
255
259
256
- static double augment_FloatAsDouble (HPyContext * ctx , HPy h ) {
260
+ static double augment_Float_AsDouble (HPyContext * ctx , HPy h ) {
257
261
uint64_t bits = toBits (h );
258
262
if (isBoxedDouble (bits )) {
259
263
return unboxDouble (bits );
260
264
} else if (isBoxedInt (bits )) {
261
265
return unboxInt (bits );
262
266
} else {
263
- return original_FloatAsDouble (ctx , h );
267
+ return original_Float_AsDouble (ctx , h );
264
268
}
265
269
}
266
270
267
- static long augment_LongAsLong (HPyContext * ctx , HPy h ) {
271
+ static long augment_Long_AsLong (HPyContext * ctx , HPy h ) {
268
272
uint64_t bits = toBits (h );
269
273
if (isBoxedInt (bits )) {
270
274
return unboxInt (bits );
271
275
} else {
272
- return original_LongAsLong (ctx , h );
276
+ return original_Long_AsLong (ctx , h );
273
277
}
274
278
}
275
279
276
- static double augment_LongAsDouble (HPyContext * ctx , HPy h ) {
280
+ static unsigned long augment_Long_AsUnsignedLong (HPyContext * ctx , HPy h ) {
277
281
uint64_t bits = toBits (h );
278
282
if (isBoxedInt (bits )) {
279
283
return unboxInt (bits );
280
284
} else {
281
- return original_LongAsDouble (ctx , h );
285
+ return original_Long_AsUnsignedLong (ctx , h );
282
286
}
283
287
}
284
288
285
- static HPy augment_LongFromLong (HPyContext * ctx , long l ) {
286
- int32_t i = (int32_t ) l ;
287
- if (l == i ) {
289
+ static double augment_Long_AsDouble (HPyContext * ctx , HPy h ) {
290
+ uint64_t bits = toBits (h );
291
+ if (isBoxedInt (bits )) {
292
+ return unboxInt (bits );
293
+ } else {
294
+ return original_Long_AsDouble (ctx , h );
295
+ }
296
+ }
297
+
298
+ static HPy augment_Long_FromLong (HPyContext * ctx , long l ) {
299
+ int32_t i = (int32_t ) l ;
300
+ if (l == i ) {
301
+ return toPtr (boxInt (i ));
302
+ } else {
303
+ return original_Long_FromLong (ctx , l );
304
+ }
305
+ }
306
+
307
+ static HPy augment_Long_FromUnsignedLong (HPyContext * ctx , unsigned long l ) {
308
+ int32_t i = (int32_t ) l ;
309
+ if (l == i ) {
310
+ return toPtr (boxInt (i ));
311
+ } else {
312
+ return original_Long_FromUnsignedLong (ctx , l );
313
+ }
314
+ }
315
+
316
+ static HPy augment_Long_FromLongLong (HPyContext * ctx , long long l ) {
317
+ int32_t i = (int32_t ) l ;
318
+ if (l == i ) {
319
+ return toPtr (boxInt (i ));
320
+ } else {
321
+ return original_Long_FromLongLong (ctx , l );
322
+ }
323
+ }
324
+
325
+ static HPy augment_Long_FromUnsignedLongLong (HPyContext * ctx , unsigned long long l ) {
326
+ int32_t i = (int32_t ) l ;
327
+ if (l == i ) {
288
328
return toPtr (boxInt (i ));
289
329
} else {
290
- return original_LongFromLong (ctx , l );
330
+ return original_Long_FromUnsignedLongLong (ctx , l );
291
331
}
292
332
}
293
333
@@ -325,12 +365,12 @@ static HPy augment_Dup(HPyContext *ctx, HPy h) {
325
365
}
326
366
}
327
367
328
- static int augment_NumberCheck (HPyContext * ctx , HPy obj ) {
368
+ static int augment_Number_Check (HPyContext * ctx , HPy obj ) {
329
369
uint64_t bits = toBits (obj );
330
370
if (isBoxedDouble (bits ) || isBoxedInt (bits )) {
331
371
return true;
332
372
} else {
333
- return original_NumberCheck (ctx , obj );
373
+ return original_Number_Check (ctx , obj );
334
374
}
335
375
}
336
376
@@ -354,18 +394,18 @@ static int augment_TypeCheck(HPyContext *ctx, HPy obj, HPy type) {
354
394
return original_TypeCheck (ctx , obj , type );
355
395
}
356
396
357
- static int augment_ListCheck (HPyContext * ctx , HPy obj ) {
397
+ static int augment_List_Check (HPyContext * ctx , HPy obj ) {
358
398
uint64_t bits = toBits (obj );
359
399
if (isBoxedHandle (bits )) {
360
- return original_ListCheck (ctx , obj );
400
+ return original_List_Check (ctx , obj );
361
401
} else {
362
402
return false;
363
403
}
364
404
}
365
405
366
406
#define MAX_UNICODE 0x10ffff
367
407
368
- static HPy augment_UnicodeFromWideChar (HPyContext * ctx , const wchar_t * u , HPy_ssize_t size ) {
408
+ static HPy augment_Unicode_FromWideChar (HPyContext * ctx , const wchar_t * u , HPy_ssize_t size ) {
369
409
if (u == NULL && size != 0 ) {
370
410
return HPy_NULL ;
371
411
}
@@ -408,7 +448,7 @@ static HPy augment_UnicodeFromWideChar(HPyContext *ctx, const wchar_t *u, HPy_ss
408
448
(* jniEnv )-> ReleasePrimitiveArrayCritical (jniEnv , jCharArray , content , 0 );
409
449
return DO_UPCALL_HPY (CONTEXT_INSTANCE (ctx ), UnicodeFromJCharArray , jCharArray );
410
450
} else {
411
- return original_UnicodeFromWideChar (ctx , u , size );
451
+ return original_Unicode_FromWideChar (ctx , u , size );
412
452
}
413
453
}
414
454
@@ -418,7 +458,7 @@ _HPy_HIDDEN HPy upcallTupleFromArray(HPyContext *ctx, HPy *items, HPy_ssize_t ni
418
458
return DO_UPCALL_HPY (CONTEXT_INSTANCE (ctx ), TupleFromArray , jLongArray , steal );
419
459
}
420
460
421
- static HPy augment_TupleFromArray (HPyContext * ctx , HPy * items , HPy_ssize_t nitems ) {
461
+ static HPy augment_Tuple_FromArray (HPyContext * ctx , HPy * items , HPy_ssize_t nitems ) {
422
462
return upcallTupleFromArray (ctx , items , nitems , JNI_FALSE );
423
463
}
424
464
@@ -430,49 +470,49 @@ void initDirectFastPaths(HPyContext *context) {
430
470
LOG ("%p" , context );
431
471
context -> name = "HPy Universal ABI (GraalVM backend, JNI)" ;
432
472
433
- original_FloatFromDouble = context -> ctx_Float_FromDouble ;
434
- context -> ctx_Float_FromDouble = augment_FloatFromDouble ;
473
+ #define AUGMENT (name ) \
474
+ original_ ## name = context->ctx_ ## name; \
475
+ context->ctx_ ## name = augment_ ## name;
476
+
477
+ AUGMENT (Float_FromDouble );
478
+
479
+ AUGMENT (Float_AsDouble );
480
+
481
+ AUGMENT (Long_AsLong );
435
482
436
- original_FloatAsDouble = context -> ctx_Float_AsDouble ;
437
- context -> ctx_Float_AsDouble = augment_FloatAsDouble ;
483
+ AUGMENT (Long_AsUnsignedLong );
438
484
439
- original_LongAsLong = context -> ctx_Long_AsLong ;
440
- context -> ctx_Long_AsLong = augment_LongAsLong ;
485
+ AUGMENT (Long_AsDouble );
441
486
442
- original_LongAsDouble = context -> ctx_Long_AsDouble ;
443
- context -> ctx_Long_AsDouble = augment_LongAsDouble ;
487
+ AUGMENT (Long_FromLong );
444
488
445
- original_LongFromLong = context -> ctx_Long_FromLong ;
446
- context -> ctx_Long_FromLong = augment_LongFromLong ;
489
+ AUGMENT (Long_FromUnsignedLong );
447
490
448
- original_Close = context -> ctx_Close ;
449
- context -> ctx_Close = augment_Close ;
491
+ AUGMENT (Long_FromLongLong );
450
492
451
- original_AsStruct = context -> ctx_AsStruct ;
452
- context -> ctx_AsStruct = augment_AsStruct ;
493
+ AUGMENT (Long_FromUnsignedLongLong );
494
+
495
+ AUGMENT (Close );
496
+
497
+ AUGMENT (AsStruct );
453
498
454
499
context -> ctx_AsStructLegacy = augment_AsStruct ;
455
500
456
- original_Dup = context -> ctx_Dup ;
457
- context -> ctx_Dup = augment_Dup ;
501
+ AUGMENT (Dup );
502
+
503
+ AUGMENT (Number_Check );
458
504
459
- original_NumberCheck = context -> ctx_Number_Check ;
460
- context -> ctx_Number_Check = augment_NumberCheck ;
505
+ AUGMENT (TypeCheck );
461
506
462
- original_TypeCheck = context -> ctx_TypeCheck ;
463
- context -> ctx_TypeCheck = augment_TypeCheck ;
507
+ AUGMENT (List_Check );
464
508
465
- original_ListCheck = context -> ctx_List_Check ;
466
- context -> ctx_List_Check = augment_ListCheck ;
509
+ AUGMENT (Unicode_FromWideChar );
467
510
468
- original_UnicodeFromWideChar = context -> ctx_Unicode_FromWideChar ;
469
- context -> ctx_Unicode_FromWideChar = augment_UnicodeFromWideChar ;
511
+ AUGMENT (Tuple_FromArray );
470
512
471
- original_TupleFromArray = context -> ctx_Tuple_FromArray ;
472
- context -> ctx_Tuple_FromArray = augment_TupleFromArray ;
513
+ AUGMENT (Is );
473
514
474
- original_Is = context -> ctx_Is ;
475
- context -> ctx_Is = augment_Is ;
515
+ #undef AUGMENT
476
516
}
477
517
478
518
void setHPyContextNativeSpace (HPyContext * context , void * * nativeSpace ) {
0 commit comments