Skip to content

Initial C-api implementation #5604

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
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell.dict/python-more.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ nlocals
NOARGS
nonbytes
Nonprintable
obmalloc
origname
ospath
pendingcr
Expand Down
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"baseclass",
"boxvec",
"Bytecode",
"ccomplex",
"cfgs",
"codegen",
"coro",
Expand Down
72 changes: 41 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ sqlite = ["rustpython-stdlib/sqlite"]
ssl = ["rustpython-stdlib/ssl"]
ssl-vendor = ["ssl", "rustpython-stdlib/ssl-vendor"]
tkinter = ["rustpython-stdlib/tkinter"]
capi = ["rustpython-capi"]

[dependencies]
rustpython-capi = { workspace = true, optional = true }
rustpython-compiler = { workspace = true }
rustpython-pylib = { workspace = true, optional = true }
rustpython-stdlib = { workspace = true, optional = true, features = ["compiler"] }
Expand Down Expand Up @@ -114,7 +116,7 @@ template = "installer-config/installer.wxs"
[workspace]
resolver = "2"
members = [
"compiler", "compiler/core", "compiler/codegen", "compiler/literal", "compiler/source",
"capi", "compiler", "compiler/core", "compiler/codegen", "compiler/literal", "compiler/source",
".", "common", "derive", "jit", "vm", "vm/sre_engine", "pylib", "stdlib", "derive-impl", "wtf8",
"wasm/lib",
]
Expand All @@ -129,6 +131,7 @@ license = "MIT"

[workspace.dependencies]
rustpython-compiler-source = { path = "compiler/source" }
rustpython-capi = { path = "capi", version = "0.4.0" }
rustpython-compiler-core = { path = "compiler/core", version = "0.4.0" }
rustpython-compiler = { path = "compiler", version = "0.4.0" }
rustpython-codegen = { path = "compiler/codegen", version = "0.4.0" }
Expand Down
34 changes: 34 additions & 0 deletions capi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "rustpython-capi"
description = "CAPI for RustPython"
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true

[lib]
crate-type = ["cdylib"]

[features]

[dependencies]
malachite-bigint = { workspace = true }
num-complex = { workspace = true }

rustpython-common = { workspace = true }
rustpython-vm = { workspace = true }

[lints.rust]
unsafe_code = "allow"
unsafe_op_in_unsafe_fn = "deny"
elided_lifetimes_in_paths = "warn"

[lints.clippy]
perf = "warn"
style = "warn"
complexity = "warn"
suspicious = "warn"
correctness = "warn"
missing_safety_doc = "allow"
15 changes: 15 additions & 0 deletions capi/src/bool.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// https://docs.python.org/3/c-api/bool.html

use std::ffi;

use rustpython_vm::{PyObject, PyObjectRef};

// TODO: Everything else

#[unsafe(export_name = "PyBool_FromLong")]
pub unsafe extern "C" fn bool_from_long(value: ffi::c_long) -> *mut PyObject {
let vm = crate::get_vm();
Into::<PyObjectRef>::into(vm.ctx.new_bool(value != 0))
.into_raw()
.as_ptr()
}
Loading
Loading