Skip to content

ccall: allow to use a header file #1613

@certik

Description

@certik

Right now, every @ccall always generates a C forward declaration (in the C backend). In addition, we would also like to have a mode, something like:

@ccall(header="some_header.h")
def f(x: i32) -> f64:
    pass

@ccall(header="some_header.h")
def g(x: i32) -> f64:
    pass

# later
e = f(5)
h = g(5)

Which would generate the following code:

#include "some_header.h"

...
e = f(5)
h = g(5)

and it would not forward declare f and it would only include some_header.h once. So in particular, if f is actually a C macro declared in the some_header.h file, it would also just work.

Alternative syntax:

from ltypes import headers

h = headers("some_header.h")
@ccall(h)
def dummy():
    pass

@ccall
def f(x: i32) -> f64:
    pass

# later
e = f(5)

We might need to figure out the best design, but we need this feature.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions