(typ, obj, c, size, listptr, errorptr)
Construct a new native list from a Python array of objects.
    copied from _python_list_to_native but list_getitem is converted to array
    getitem.
Construct a new native list from a Python array of objects.
    copied from _python_list_to_native but list_getitem is converted to array
    getitem.
Construct a new native list from a Python array of objects . copied from _python_list_to_native but list_getitem is converted to array getitem .
def _python_array_obj_to_native_list(typ, obj, c, size, listptr, errorptr):
    """
    Construct a new native list from a Python array of objects.
    copied from _python_list_to_native but list_getitem is converted to array
    getitem.
    """
    def check_element_type(nth, itemobj, expected_typobj):
        typobj = nth.typeof(itemobj)
        # Check if *typobj* is NULL
        with c.builder.if_then(
                cgutils.is_null(c.builder, typobj),
                likely=False,
        ):
            c.builder.store(cgutils.true_bit, errorptr)
            loop.do_break()
        # Mandate that objects all have the same exact type
        type_mismatch = c.builder.icmp_signed('!=', typobj, expected_typobj)

        with c.builder.if_then(type_mismatch, likely=False):
            c.builder.store(cgutils.true_bit, errorptr)
            c.pyapi.err_format(
                "PyExc_TypeError",
                "can't unbox heterogeneous list: %S != %S",
                expected_typobj, typobj,
            )
            c.pyapi.decref(typobj)
            loop.do_break()
        c.pyapi.decref(typobj)

    # Allocate a new native list
    ok, list = listobj.ListInstance.allocate_ex(c.context, c.builder, typ, size)
    # Array getitem call
    arr_get_fnty = LLType.function(LLType.pointer(c.pyapi.pyobj), [c.pyapi.pyobj, c.pyapi.py_ssize_t])
    arr_get_fn = c.pyapi._get_function(arr_get_fnty, name="array_getptr1")

    with c.builder.if_else(ok, likely=True) as (if_ok, if_not_ok):
        with if_ok:
            list.size = size
            zero = lir.Constant(size.type, 0)
            with c.builder.if_then(c.builder.icmp_signed('>', size, zero),
                                   likely=True):
                # Traverse Python list and unbox objects into native list
                with _NumbaTypeHelper(c) as nth:
                    # Note: *expected_typobj* can't be NULL
                    # TODO: enable type checking when emty list item in
                    # list(list(str)) case can be handled
                    # expected_typobj = nth.typeof(c.builder.load(
                    #                 c.builder.call(arr_get_fn, [obj, zero])))
                    with cgutils.for_range(c.builder, size) as loop:
                        itemobj = c.builder.call(arr_get_fn, [obj, loop.index])
                        # extra load since we have ptr to object
                        itemobj = c.builder.load(itemobj)
                        # c.pyapi.print_object(itemobj)
                        # check_element_type(nth, itemobj, expected_typobj)
                        # XXX we don't call native cleanup for each
                        # list element, since that would require keeping
                        # of which unboxings have been successful.
                        native = c.unbox(typ.dtype, itemobj)
                        with c.builder.if_then(native.is_error, likely=False):
                            c.builder.store(cgutils.true_bit, errorptr)
                            loop.do_break()
                        # The object (e.g. string) is stored so incref=True
                        list.setitem(loop.index, native.value, incref=True)
                    # c.pyapi.decref(expected_typobj)
            if typ.reflected:
                list.parent = obj
            # Stuff meminfo pointer into the Python object for
            # later reuse.
            with c.builder.if_then(c.builder.not_(c.builder.load(errorptr)),
                                   likely=False):
                c.pyapi.object_set_private_data(obj, list.meminfo)
            list.set_dirty(False)
            c.builder.store(list.value, listptr)

        with if_not_ok:
            c.builder.store(cgutils.true_bit, errorptr)

    # If an error occurred, drop the whole native list
    with c.builder.if_then(c.builder.load(errorptr)):
        c.context.nrt.decref(c.builder, typ, list.value)
def _python_array_obj_to_native_list ( typ , obj , c , size , listptr , errorptr ) : def check_element_type ( nth , itemobj , expected_typobj ) : typobj = nth . typeof ( itemobj ) # Check if *typobj* is NULL with c . builder . if_then ( cgutils . is_null ( c . builder , typobj ) , likely = False , ) : c . builder . store ( cgutils . true_bit , errorptr ) loop . do_break ( ) # Mandate that objects all have the same exact type type_mismatch = c . builder . icmp_signed ( '!=' , typobj , expected_typobj ) with c . builder . if_then ( type_mismatch , likely = False ) : c . builder . store ( cgutils . true_bit , errorptr ) c . pyapi . err_format ( "PyExc_TypeError" , "can't unbox heterogeneous list: %S != %S" , expected_typobj , typobj , ) c . pyapi . decref ( typobj ) loop . do_break ( ) c . pyapi . decref ( typobj ) # Allocate a new native list ok , list = listobj . ListInstance . allocate_ex ( c . context , c . builder , typ , size ) # Array getitem call arr_get_fnty = LLType . function ( LLType . pointer ( c . pyapi . pyobj ) , [ c . pyapi . pyobj , c . pyapi . py_ssize_t ] ) arr_get_fn = c . pyapi . _get_function ( arr_get_fnty , name = "array_getptr1" ) with c . builder . if_else ( ok , likely = True ) as ( if_ok , if_not_ok ) : with if_ok : list . size = size zero = lir . Constant ( size . type , 0 ) with c . builder . if_then ( c . builder . icmp_signed ( '>' , size , zero ) , likely = True ) : # Traverse Python list and unbox objects into native list with _NumbaTypeHelper ( c ) as nth : # Note: *expected_typobj* can't be NULL # TODO: enable type checking when emty list item in # list(list(str)) case can be handled # expected_typobj = nth.typeof(c.builder.load( #                 c.builder.call(arr_get_fn, [obj, zero]))) with cgutils . for_range ( c . builder , size ) as loop : itemobj = c . builder . call ( arr_get_fn , [ obj , loop . index ] ) # extra load since we have ptr to object itemobj = c . builder . load ( itemobj ) # c.pyapi.print_object(itemobj) # check_element_type(nth, itemobj, expected_typobj) # XXX we don't call native cleanup for each # list element, since that would require keeping # of which unboxings have been successful. native = c . unbox ( typ . dtype , itemobj ) with c . builder . if_then ( native . is_error , likely = False ) : c . builder . store ( cgutils . true_bit , errorptr ) loop . do_break ( ) # The object (e.g. string) is stored so incref=True list . setitem ( loop . index , native . value , incref = True ) # c.pyapi.decref(expected_typobj) if typ . reflected : list . parent = obj # Stuff meminfo pointer into the Python object for # later reuse. with c . builder . if_then ( c . builder . not_ ( c . builder . load ( errorptr ) ) , likely = False ) : c . pyapi . object_set_private_data ( obj , list . meminfo ) list . set_dirty ( False ) c . builder . store ( list . value , listptr ) with if_not_ok : c . builder . store ( cgutils . true_bit , errorptr ) # If an error occurred, drop the whole native list with c . builder . if_then ( c . builder . load ( errorptr ) ) : c . context . nrt . decref ( c . builder , typ , list . value )