Skip to content

Semantics of p_c_pointer and PointerToCPtr #592

Open

Description

@certik

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.

Activity

  1. czgdp1807 commented on Jun 14, 2022

    @czgdp1807
    Collaborator

    We can use ctypes to run the code with CPython?

  2. certik commented on Jun 14, 2022

    @certik
    ContributorAuthor

    Yes, we already do in ltypes.py.

  3. czgdp1807 commented on Jun 14, 2022

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

  4. certik commented on Jun 14, 2022

    @certik
    ContributorAuthor

    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.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions