Skip to content

Hook in custom callbacks to ccall #1614

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

Open
Tracked by #1600
certik opened this issue Mar 23, 2023 · 1 comment
Open
Tracked by #1600

Hook in custom callbacks to ccall #1614

certik opened this issue Mar 23, 2023 · 1 comment
Labels
easy to fix tests Testing related changes

Comments

@certik
Copy link
Contributor

certik commented Mar 23, 2023

In pure Python mode we need some way to register custom callbacks with ltypes, for example:

import ltypes
def callback(name):
    ...
ltypes.register_ccall_callback(callback)

@ccall
def f(..)
   ...

Now when f is called in pure Python mode, ltypes that implements the ccall decorator would instead call the user defined callback function that can provide custom callback, so that we do not need to call into C.

@certik certik mentioned this issue Mar 23, 2023
38 tasks
@certik
Copy link
Contributor Author

certik commented Apr 25, 2023

This was implemented in https://github.com/lcompilers/lpython/pull/1740/files#diff-851646ee31435bb9b3ae29b961902cf243cb91b3b145ef2e3df7e095b47150deR288, but we don't have a test. Here is how to use it:

import my_implementations
import lpython
from types import FunctionType
lpython.CTypes.emulations = {k: v for k, v in my_implementations.__dict__.items()
        if isinstance(v, FunctionType)}

Here the my_implementations module contains regular Python functions (instances of FunctionType) that provide a pure Python implementations of the ccalls. We assign to the emulations class variable.

@Smit-create Smit-create added easy to fix tests Testing related changes labels May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy to fix tests Testing related changes
Projects
None yet
Development

No branches or pull requests

2 participants