Skip to content

Adds support for str type to ccall #674

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

Merged
merged 3 commits into from
Jun 22, 2022
Merged

Conversation

dylon
Copy link

@dylon dylon commented Jun 22, 2022

No description provided.

@dylon
Copy link
Author

dylon commented Jun 22, 2022

File: main.py

from ltypes import ccall

@ccall
def prn(msg: str) -> None:
    pass

prn("Hello World!")

File: main.c

#include <stdio.h>

void prn(char * msg) {
  printf("%s\n", msg);
}

Compile library:

clang -shared -o libprn.so main.c

Execute:

PYTHONPATH=~/Workspace/lpython/src/runtime/ltypes LPYTHON_PY_MOD_NAME=prn LPYTHON_PY_MOD_PATH=. python main.py

Output:

Hello World!

@czgdp1807
Copy link
Collaborator

Looks good. Can we add a test as well?

@czgdp1807
Copy link
Collaborator

Let's copy chagnes in test_c_interop_02 from https://github.com/lcompilers/lpython/pull/671/files and apply here.

@czgdp1807
Copy link
Collaborator

czgdp1807 commented Jun 22, 2022

@dylon Will you mind if I do this? LLVM backend works fine. C backend needs some minor changes to get it working. Please let me know if you are okay with me pushing changes to your branch. Thanks.

@czgdp1807 czgdp1807 added the cpython Changes related to CPython label Jun 22, 2022
@certik
Copy link
Contributor

certik commented Jun 22, 2022

I am working on tests right now, almost done.

@certik certik requested a review from czgdp1807 June 22, 2022 09:28
@certik
Copy link
Contributor

certik commented Jun 22, 2022

This is ready.

@certik certik enabled auto-merge June 22, 2022 09:33
@certik certik merged commit 4591db8 into lcompilers:main Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cpython Changes related to CPython
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants