Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Tracked by #1600
certik opened this issue May 8, 2023 · 1 comment
Open
Tracked by #1600

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

certik opened this issue May 8, 2023 · 1 comment

Comments

@certik
Copy link
Contributor

certik commented May 8, 2023

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.

@certik certik mentioned this issue May 8, 2023
38 tasks
@certik
Copy link
Contributor Author

certik commented May 9, 2023

To test this, I would create our own C version of "qsort" with a callback, that way we can control the types exactly and make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant