← 输入框|github.com|刷新
Skip to content

Hook in custom callbacks to ccall #1614

Open

Description

@certik

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.

Activity

  1. certik commented on Apr 25, 2023

    @certik
    ContributorAuthor

    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.

  2. added
    tests
    on May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    easy to fixtests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions