@@ -46,33 +46,43 @@ def box_slice(typ, val, c):
4646 """
4747 start = c .builder .extract_value (val , 0 )
4848 stop = c .builder .extract_value (val , 1 )
49+ step = c .builder .extract_value (val , 2 ) if typ .has_step else None
4950
51+ # Numba uses sys.maxsize and -sys.maxsize-1 to represent None
52+ # We want to use None in the Python representation
5053 none_val = ir .Constant (ir .IntType (64 ), sys .maxsize )
54+ neg_none_val = ir .Constant (ir .IntType (64 ), - sys .maxsize - 1 )
55+ none_obj = c .pyapi .get_null_object ()
5156
52- start_is_none = c .builder .icmp_signed ("==" , start , none_val )
5357 start = c .builder .select (
54- start_is_none ,
55- c . pyapi . get_null_object () ,
58+ c . builder . icmp_signed ( "==" , start , none_val ) ,
59+ none_obj ,
5660 c .box (types .int64 , start ),
5761 )
5862
59- stop_is_none = c .builder .icmp_signed ("==" , stop , none_val )
63+ # None stop is represented as neg_none_val when step is negative
64+ if step is not None :
65+ stop_none_val = c .builder .select (
66+ c .builder .icmp_signed (">" , step , ir .Constant (ir .IntType (64 ), 0 )),
67+ none_val ,
68+ neg_none_val ,
69+ )
70+ else :
71+ stop_none_val = none_val
6072 stop = c .builder .select (
61- stop_is_none ,
62- c . pyapi . get_null_object () ,
73+ c . builder . icmp_signed ( "==" , stop , stop_none_val ) ,
74+ none_obj ,
6375 c .box (types .int64 , stop ),
6476 )
6577
66- if typ .has_step :
67- step = c .builder .extract_value (val , 2 )
68- step_is_none = c .builder .icmp_signed ("==" , step , none_val )
78+ if step is not None :
6979 step = c .builder .select (
70- step_is_none ,
71- c . pyapi . get_null_object () ,
80+ c . builder . icmp_signed ( "==" , step , none_val ) ,
81+ none_obj ,
7282 c .box (types .int64 , step ),
7383 )
7484 else :
75- step = c . pyapi . get_null_object ()
85+ step = none_obj
7686
7787 slice_val = slice_new (c .pyapi , start , stop , step )
7888
0 commit comments