<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def unpack_glist(glist_ptr, cffi_type, transfer_full=True):
 """Takes a glist ptr, copies the values casted to type_ in to a list and frees all items and the list. If an item is returned all yielded before are invalid. """


    current = glist_ptr
    while current:
        yield ffi.cast(cffi_type, current.data)
        if transfer_full:
            free(current.data)
        current = current.next
    if transfer_full:
        lib.g_list_free(glist_ptr)