@@ -705,13 +705,25 @@ def emit_cast(
705705 self .emit_lines (f" { dest } = { src } ;" , "else {" )
706706 self .emit_cast_error_handler (error , src , dest , typ , raise_exception )
707707 self .emit_line ("}" )
708- elif is_object_rprimitive (typ ) or is_native_rprimitive ( typ ) :
708+ elif is_object_rprimitive (typ ):
709709 if declare_dest :
710710 self .emit_line (f"PyObject *{ dest } ;" )
711711 self .emit_arg_check (src , dest , typ , "" , optional )
712712 self .emit_line (f"{ dest } = { src } ;" )
713713 if optional :
714714 self .emit_line ("}" )
715+ elif is_native_rprimitive (typ ):
716+ # Native primitive types have type check functions of form "CPy<Name>_Check(...)".
717+ if declare_dest :
718+ self .emit_line (f"PyObject *{ dest } ;" )
719+ short_name = typ .name .rsplit ("." , 1 )[- 1 ]
720+ check = f"(CPy{ short_name } _Check({ src } ))"
721+ if likely :
722+ check = f"(likely{ check } )"
723+ self .emit_arg_check (src , dest , typ , check , optional )
724+ self .emit_lines (f" { dest } = { src } ;" , "else {" )
725+ self .emit_cast_error_handler (error , src , dest , typ , raise_exception )
726+ self .emit_line ("}" )
715727 elif isinstance (typ , RUnion ):
716728 self .emit_union_cast (
717729 src , dest , typ , declare_dest , error , optional , src_type , raise_exception
0 commit comments