@@ -488,6 +488,26 @@ static mp_obj_t extra_coverage(void) {
488488 // mpz_set_from_float with 0 as argument
489489 mpz_set_from_float (& mpz , 0 );
490490 mp_printf (& mp_plat_print , "%f\n" , mpz_as_float (& mpz ));
491+
492+ // convert a large integer value (stored in a mpz) to mp_uint_t and to ll;
493+ mp_obj_t obj_bigint = mp_obj_new_int_from_uint ((mp_uint_t )0xdeadbeef );
494+ mp_printf (& mp_plat_print , "%x\n" , mp_obj_get_uint (obj_bigint ));
495+ obj_bigint = mp_obj_new_int_from_ll (0xc0ffee777c0ffeell );
496+ long long value_ll = mp_obj_get_ll (obj_bigint );
497+ mp_printf (& mp_plat_print , "%x%08x\n" , (uint32_t )(value_ll >> 32 ), (uint32_t )value_ll );
498+
499+ // convert a large integer value (stored via a struct object) to uint and to ll
500+ // `deadbeef` global is an uctypes.struct defined by extra_coverage.py
501+ obj_bigint = mp_load_global (MP_QSTR_deadbeef );
502+ mp_printf (& mp_plat_print , "%x\n" , mp_obj_get_uint (obj_bigint ));
503+ value_ll = mp_obj_get_ll (obj_bigint );
504+ mp_printf (& mp_plat_print , "%x%08x\n" , (uint32_t )(value_ll >> 32 ), (uint32_t )value_ll );
505+
506+ // convert a smaller integer value to mp_uint_t and to ll
507+ obj_bigint = mp_obj_new_int_from_uint (0xc0ffee );
508+ mp_printf (& mp_plat_print , "%x\n" , mp_obj_get_uint (obj_bigint ));
509+ value_ll = mp_obj_get_ll (obj_bigint );
510+ mp_printf (& mp_plat_print , "%x%08x\n" , (uint32_t )(value_ll >> 32 ), (uint32_t )value_ll );
491511 }
492512
493513 // runtime utils
@@ -530,6 +550,22 @@ static mp_obj_t extra_coverage(void) {
530550 mp_obj_print_exception (& mp_plat_print , MP_OBJ_FROM_PTR (nlr .ret_val ));
531551 }
532552
553+ // mp_obj_get_uint from a non-int object (should raise exception)
554+ if (nlr_push (& nlr ) == 0 ) {
555+ mp_obj_get_uint (mp_const_none );
556+ nlr_pop ();
557+ } else {
558+ mp_obj_print_exception (& mp_plat_print , MP_OBJ_FROM_PTR (nlr .ret_val ));
559+ }
560+
561+ // mp_obj_int_get_ll from a non-int object (should raise exception)
562+ if (nlr_push (& nlr ) == 0 ) {
563+ mp_obj_get_ll (mp_const_none );
564+ nlr_pop ();
565+ } else {
566+ mp_obj_print_exception (& mp_plat_print , MP_OBJ_FROM_PTR (nlr .ret_val ));
567+ }
568+
533569 // call mp_obj_new_exception_args (it's a part of the public C API and not used in the core)
534570 mp_obj_print_exception (& mp_plat_print , mp_obj_new_exception_args (& mp_type_ValueError , 0 , NULL ));
535571 }
0 commit comments