Skip to content

Semantics of p_c_pointer and PointerToCPtr #592

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 #1575
certik opened this issue Jun 13, 2022 · 4 comments
Open
Tracked by #1575

Semantics of p_c_pointer and PointerToCPtr #592

certik opened this issue Jun 13, 2022 · 4 comments

Comments

@certik
Copy link
Contributor

certik commented Jun 13, 2022

Currently p_c_pointer(pointer(xi32), p) gets translated to:

         (= 
            (Var 6 p) 
            (PointerToCPtr 
               (GetPointer 
                  (Var 6 xi32) 
                  (Pointer 
                     (Integer 4 [])) ()) 
               (CPtr) ()) ()) 

and p_c_pointer(xi64, p) gets translated to:

         (= 
            (Var 6 p) 
            (PointerToCPtr 
               (Var 6 xi64) 
               (CPtr) ()) ()) 

What should be the recommended usage? It seems to me the second case is incorrect, as PointerToCPtr should only accepts pointers as the first argument?

The other issue is: we need to also have a CPython implementation of whatever syntax/semantics we choose. If it cannot be done for the above syntax, then we need to change it.

@czgdp1807
Copy link
Collaborator

We can use ctypes to run the code with CPython?

@certik
Copy link
Contributor Author

certik commented Jun 14, 2022

Yes, we already do in ltypes.py.

@czgdp1807
Copy link
Collaborator

I see. So just importing stuff from ctypes into ltypes will allow CPython to at least run the code. However, I am wondering can CPython really call into C code. Like AFAIK, LPython generates an object file and that's linked to the object file of .c file (where we implement the C functions called in Python code). Now since CPython never generates an object file then how will the C functions linked to their definition.

@certik
Copy link
Contributor Author

certik commented Jun 14, 2022

Yes, so callbacks cannot be done from CPython, I also just realized that, so we will simply not implement @ccallable in CPython. But calling into C is possible, and it works already. So all other features we'll get working.

@certik certik mentioned this issue Mar 21, 2023
6 tasks
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

2 participants