Skip to content

Adds support for str type to ccall - #674

Merged
certik merged 3 commits into
lcompilers:mainfrom
dylon:dylon/str-args
Jun 22, 2022
Merged

Adds support for str type to ccall#674
certik merged 3 commits into
lcompilers:mainfrom
dylon:dylon/str-args

Conversation

@dylon

Copy link
Copy Markdown

No description provided.

@dylon

dylon commented Jun 22, 2022

Copy link
Copy Markdown
Author

File: main.py

fromltypesimportccall@ccalldefprn(msg: str) ->None:
passprn("Hello World!")

File: main.c

#include<stdio.h>voidprn(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
Copy Markdown
Collaborator

Looks good. Can we add a test as well?

@czgdp1807

Copy link
Copy Markdown
Collaborator

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

@czgdp1807

czgdp1807 commented Jun 22, 2022

Copy link
Copy Markdown
Collaborator

@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.

@czgdp1807czgdp1807 added the cpython Changes related to CPython label Jun 22, 2022
@certik

Copy link
Copy Markdown
Contributor

I am working on tests right now, almost done.

@certik
certik requested a review from czgdp1807June 22, 2022 09:28
@certik

Copy link
Copy Markdown
Contributor

This is ready.

@certik
certik enabled auto-merge June 22, 2022 09:33
@certik
certik merged commit 4591db8 into lcompilers:mainJun 22, 2022
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cpythonChanges related to CPython

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@dylon@czgdp1807@certik@GSIT3ch