Skip to content

Commit 0407d30

Browse files
authored
Merge pull request #1812 from certik/unsigned5
lpython.py: handle unsigned integers everywhere
2 parents 68024a0 + 159e646 commit 0407d30

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

src/runtime/lpython/lpython.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ def convert_type_to_ctype(arg):
232232
return ctypes.c_int16
233233
elif arg == i8:
234234
return ctypes.c_int8
235+
elif arg == u64:
236+
return ctypes.c_uint64
237+
elif arg == u32:
238+
return ctypes.c_uint32
239+
elif arg == u16:
240+
return ctypes.c_uint16
241+
elif arg == u8:
242+
return ctypes.c_uint8
235243
elif arg == CPtr:
236244
return ctypes.c_void_p
237245
elif arg == str:
@@ -264,11 +272,16 @@ def convert_numpy_dtype_to_ctype(arg):
264272
return ctypes.c_int32
265273
elif arg == np.int16:
266274
return ctypes.c_int16
267-
elif arg == np.uint16:
268-
# TODO: once LPython supports unsigned, change this to unsigned:
269-
return ctypes.c_int16
270275
elif arg == np.int8:
271276
return ctypes.c_int8
277+
elif arg == np.uint64:
278+
return ctypes.c_uint64
279+
elif arg == np.uint32:
280+
return ctypes.c_uint32
281+
elif arg == np.uint16:
282+
return ctypes.c_uint16
283+
elif arg == np.uint8:
284+
return ctypes.c_uint8
272285
elif arg == np.void:
273286
return ctypes.c_void_p
274287
elif arg is None:
@@ -431,12 +444,30 @@ def pointer(x, type_=None):
431444
if isinstance(x, ndarray):
432445
return x.ctypes.data_as(ctypes.POINTER(convert_numpy_dtype_to_ctype(x.dtype)))
433446
else:
434-
if type_ == i32:
447+
if type_ == i8:
448+
return ctypes.cast(ctypes.pointer(ctypes.c_int8(x)),
449+
ctypes.c_void_p)
450+
elif type_ == i16:
451+
return ctypes.cast(ctypes.pointer(ctypes.c_int16(x)),
452+
ctypes.c_void_p)
453+
elif type_ == i32:
435454
return ctypes.cast(ctypes.pointer(ctypes.c_int32(x)),
436455
ctypes.c_void_p)
437456
elif type_ == i64:
438457
return ctypes.cast(ctypes.pointer(ctypes.c_int64(x)),
439458
ctypes.c_void_p)
459+
elif type_ == u8:
460+
return ctypes.cast(ctypes.pointer(ctypes.c_uint8(x)),
461+
ctypes.c_void_p)
462+
elif type_ == u16:
463+
return ctypes.cast(ctypes.pointer(ctypes.c_uint16(x)),
464+
ctypes.c_void_p)
465+
elif type_ == u32:
466+
return ctypes.cast(ctypes.pointer(ctypes.c_uint32(x)),
467+
ctypes.c_void_p)
468+
elif type_ == u64:
469+
return ctypes.cast(ctypes.pointer(ctypes.c_uint64(x)),
470+
ctypes.c_void_p)
440471
elif type_ == f32:
441472
return ctypes.cast(ctypes.pointer(ctypes.c_float(x)),
442473
ctypes.c_void_p)

0 commit comments

Comments
 (0)