Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add a test for creating a callback and passing it to qsort #1766

Open
@certik

Description

@certik

Here is a rough idea how it can work:

Comparator = Callable[[Any, Any], int]
@ccall
def qsort(arr: Sequence[Any],
          num_elems: int,
          elem_size: int,
          comp: Comparator) -> None:
    pass

The types have to be adjusted. And we want to use it like:

def sort_f16_idx_val_ascending(iv_ptr: CPtr, num_elements: i32) -> None:
    iv = ctypes.cast(iv_ptr, ctypes.POINTER(gd_lab_4_idx_val))
    qsort(iv, num_elements, sizeof(gd_lab_4_idx_val), f16_idx_val_cmp_ascending)

where the f16_idx_val_cmp_ascending function is the comparator. And we want this to call the qsort function in C.

I think we have most of these pieces in LPython/LFortran, we just need to write a test for this and ensure everything works and fix any bugs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions