Skip to content
Merged
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
6 changes: 2 additions & 4 deletions common/src/rc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(not(feature = "threading"))]
use std::rc::{Rc, Weak};
use std::rc::Rc;
#[cfg(feature = "threading")]
use std::sync::{Arc, Weak};
use std::sync::Arc;

// type aliases instead of newtypes because you can't do `fn method(self: PyRc<Self>)` with a
// newtype; requires the arbitrary_self_types unstable feature
Expand All @@ -10,5 +10,3 @@ use std::sync::{Arc, Weak};
pub type PyRc<T> = Arc<T>;
#[cfg(not(feature = "threading"))]
pub type PyRc<T> = Rc<T>;

pub type PyWeak<T> = Weak<T>;
8 changes: 4 additions & 4 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ mod doc;
mod from_args;
mod pyclass;
mod pymodule;
mod pypayload;
mod pystructseq;
mod pyvalue;

use error::{extract_spans, Diagnostic};
use proc_macro2::TokenStream;
Expand Down Expand Up @@ -120,8 +120,8 @@ pub fn py_freeze(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
result_to_tokens(compile_bytecode::impl_py_freeze(input.into()))
}

#[proc_macro_derive(PyValue)]
pub fn pyvalue(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
#[proc_macro_derive(PyPayload)]
pub fn pypayload(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse_macro_input!(input as DeriveInput);
result_to_tokens(pyvalue::impl_pyvalue(input))
result_to_tokens(pypayload::impl_pypayload(input))
}
2 changes: 1 addition & 1 deletion derive/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ pub(crate) fn impl_define_exception(exc_def: PyExceptionDef) -> Result<TokenStre
pub struct #class_name {}

// We need this to make extend mechanism work:
impl ::rustpython_vm::PyValue for #class_name {
impl ::rustpython_vm::PyPayload for #class_name {
fn class(vm: &::rustpython_vm::VirtualMachine) -> &::rustpython_vm::builtins::PyTypeRef {
&vm.ctx.exceptions.#ctx_name
}
Expand Down
4 changes: 2 additions & 2 deletions derive/src/pyvalue.rs → derive/src/pypayload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use proc_macro2::TokenStream;
use quote::quote;
use syn::{DeriveInput, Result};

pub(crate) fn impl_pyvalue(input: DeriveInput) -> Result<TokenStream> {
pub(crate) fn impl_pypayload(input: DeriveInput) -> Result<TokenStream> {
let ty = &input.ident;

let ret = quote! {
impl ::rustpython_vm::PyValue for #ty {
impl ::rustpython_vm::PyPayload for #ty {
fn class(_vm: &::rustpython_vm::VirtualMachine) -> &rustpython_vm::builtins::PyTypeRef {
<Self as ::rustpython_vm::pyclass::StaticType>::static_type()
}
Expand Down
15 changes: 7 additions & 8 deletions stdlib/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ mod array {
AsBuffer, AsMapping, Comparable, Constructor, IterNext, IterNextIterable, Iterable,
PyComparisonOp,
},
AsObject, PyObject, PyObjectRef, PyObjectView, PyRef, PyResult, PyValue,
VirtualMachine,
AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
},
};
use itertools::Itertools;
Expand Down Expand Up @@ -583,7 +582,7 @@ mod array {

#[pyattr]
#[pyclass(name = "array")]
#[derive(Debug, PyValue)]
#[derive(Debug, PyPayload)]
pub struct PyArray {
array: PyRwLock<ArrayContentType>,
exports: AtomicUsize,
Expand Down Expand Up @@ -1152,7 +1151,7 @@ mod array {

impl Comparable for PyArray {
fn cmp(
zelf: &PyObjectView<Self>,
zelf: &Py<Self>,
other: &PyObject,
op: PyComparisonOp,
vm: &VirtualMachine,
Expand Down Expand Up @@ -1203,7 +1202,7 @@ mod array {
}

impl AsBuffer for PyArray {
fn as_buffer(zelf: &PyObjectView<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
fn as_buffer(zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
let array = zelf.read();
let buf = PyBuffer::new(
zelf.to_owned().into(),
Expand Down Expand Up @@ -1254,7 +1253,7 @@ mod array {
}

impl AsMapping for PyArray {
fn as_mapping(_zelf: &PyObjectView<Self>, _vm: &VirtualMachine) -> PyMappingMethods {
fn as_mapping(_zelf: &Py<Self>, _vm: &VirtualMachine) -> PyMappingMethods {
Self::MAPPING_METHODS
}
}
Expand All @@ -1280,7 +1279,7 @@ mod array {

#[pyattr]
#[pyclass(name = "array_iterator")]
#[derive(Debug, PyValue)]
#[derive(Debug, PyPayload)]
pub struct PyArrayIter {
position: AtomicUsize,
array: PyArrayRef,
Expand All @@ -1291,7 +1290,7 @@ mod array {

impl IterNextIterable for PyArrayIter {}
impl IterNext for PyArrayIter {
fn next(zelf: &PyObjectView<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
let pos = zelf.position.fetch_add(1, atomic::Ordering::SeqCst);
let r = if let Some(item) = zelf.array.read().get(pos, vm) {
PyIterReturn::Return(item?)
Expand Down
8 changes: 4 additions & 4 deletions stdlib/src/contextvars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ pub(crate) use _contextvars::make_module;
mod _contextvars {
use rustpython_vm::builtins::{PyFunction, PyStrRef, PyTypeRef};
use rustpython_vm::function::{ArgCallable, FuncArgs, OptionalArg};
use rustpython_vm::{PyObjectRef, PyRef, PyResult, PyValue, VirtualMachine};
use rustpython_vm::{PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine};

#[pyattr]
#[pyclass(name)]
#[derive(Debug, PyValue)]
#[derive(Debug, PyPayload)]
struct Context {}

#[pyimpl]
Expand Down Expand Up @@ -75,7 +75,7 @@ mod _contextvars {

#[pyattr]
#[pyclass(name)]
#[derive(Debug, PyValue)]
#[derive(Debug, PyPayload)]
struct ContextVar {
#[allow(dead_code)] // TODO: RUSTPYTHON
name: String,
Expand Down Expand Up @@ -147,7 +147,7 @@ mod _contextvars {

#[pyattr]
#[pyclass(name = "Token")]
#[derive(Debug, PyValue)]
#[derive(Debug, PyPayload)]
struct ContextToken {}

#[derive(FromArgs)]
Expand Down
8 changes: 4 additions & 4 deletions stdlib/src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod _csv {
match_class,
protocol::{PyIter, PyIterReturn},
types::{IterNext, IterNextIterable},
AsObject, PyObjectRef, PyObjectView, PyResult, PyValue, TryFromObject, VirtualMachine,
AsObject, Py, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine,
};
use itertools::{self, Itertools};
use std::fmt;
Expand Down Expand Up @@ -153,7 +153,7 @@ mod _csv {
}

#[pyclass(noattr, module = "_csv", name = "reader")]
#[derive(PyValue)]
#[derive(PyPayload)]
pub(super) struct Reader {
iter: PyIter,
state: PyMutex<ReadState>,
Expand All @@ -169,7 +169,7 @@ mod _csv {
impl Reader {}
impl IterNextIterable for Reader {}
impl IterNext for Reader {
fn next(zelf: &PyObjectView<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
let string = match zelf.iter.next(vm)? {
PyIterReturn::Return(obj) => obj,
PyIterReturn::StopIteration(v) => return Ok(PyIterReturn::StopIteration(v)),
Expand Down Expand Up @@ -243,7 +243,7 @@ mod _csv {
}

#[pyclass(noattr, module = "_csv", name = "writer")]
#[derive(PyValue)]
#[derive(PyPayload)]
pub(super) struct Writer {
write: PyObjectRef,
state: PyMutex<WriteState>,
Expand Down
4 changes: 2 additions & 2 deletions stdlib/src/hashlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod hashlib {
use crate::vm::{
builtins::{PyBytes, PyBytesRef, PyStrRef, PyTypeRef},
function::{FuncArgs, OptionalArg},
PyResult, PyValue, VirtualMachine,
PyPayload, PyResult, VirtualMachine,
};
use blake2::{Blake2b512, Blake2s256};
use digest::DynDigest;
Expand Down Expand Up @@ -46,7 +46,7 @@ mod hashlib {

#[pyattr]
#[pyclass(module = "hashlib", name = "hasher")]
#[derive(PyValue)]
#[derive(PyPayload)]
struct PyHasher {
name: String,
buffer: PyRwLock<HashWrapper>,
Expand Down
10 changes: 3 additions & 7 deletions stdlib/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ mod _json {
function::OptionalArg,
protocol::PyIterReturn,
types::{Callable, Constructor},
AsObject, PyObjectRef, PyObjectView, PyResult, PyValue, VirtualMachine,
AsObject, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
};
use num_bigint::BigInt;
use std::str::FromStr;

#[pyattr(name = "make_scanner")]
#[pyclass(name = "Scanner")]
#[derive(Debug, PyValue)]
#[derive(Debug, PyPayload)]
struct JsonScanner {
strict: bool,
object_hook: Option<PyObjectRef>,
Expand Down Expand Up @@ -196,11 +196,7 @@ mod _json {

impl Callable for JsonScanner {
type Args = (PyStrRef, isize);
fn call(
zelf: &PyObjectView<Self>,
(pystr, idx): Self::Args,
vm: &VirtualMachine,
) -> PyResult {
fn call(zelf: &Py<Self>, (pystr, idx): Self::Args, vm: &VirtualMachine) -> PyResult {
if idx < 0 {
return Err(vm.new_value_error("idx cannot be negative".to_owned()));
}
Expand Down
4 changes: 2 additions & 2 deletions stdlib/src/pyexpat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod _pyexpat {
builtins::{PyStr, PyStrRef, PyTypeRef},
function::ArgBytesLike,
function::{IntoFuncArgs, OptionalArg},
PyContext, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, VirtualMachine,
PyContext, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine,
};
use rustpython_common::lock::PyRwLock;
use std::io::Cursor;
Expand All @@ -44,7 +44,7 @@ mod _pyexpat {

#[pyattr]
#[pyclass(name = "xmlparser", module = false)]
#[derive(Debug, PyValue)]
#[derive(Debug, PyPayload)]
pub struct PyExpatLikeXmlParser {
start_element: MutableObject,
end_element: MutableObject,
Expand Down
8 changes: 4 additions & 4 deletions stdlib/src/pystruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) mod _struct {
match_class,
protocol::PyIterReturn,
types::{Constructor, IterNext, IterNextIterable},
AsObject, PyObjectRef, PyObjectView, PyResult, PyValue, TryFromObject, VirtualMachine,
AsObject, Py, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;

Expand Down Expand Up @@ -161,7 +161,7 @@ pub(crate) mod _struct {

#[pyattr]
#[pyclass(name = "unpack_iterator")]
#[derive(Debug, PyValue)]
#[derive(Debug, PyPayload)]
struct UnpackIterator {
format_spec: FormatSpec,
buffer: ArgBytesLike,
Expand Down Expand Up @@ -206,7 +206,7 @@ pub(crate) mod _struct {
}
impl IterNextIterable for UnpackIterator {}
impl IterNext for UnpackIterator {
fn next(zelf: &PyObjectView<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
let size = zelf.format_spec.size;
let offset = zelf.offset.fetch_add(size);
zelf.buffer.with_ref(|buf| {
Expand Down Expand Up @@ -238,7 +238,7 @@ pub(crate) mod _struct {

#[pyattr]
#[pyclass(name = "Struct")]
#[derive(Debug, PyValue)]
#[derive(Debug, PyPayload)]
struct PyStruct {
spec: FormatSpec,
format: PyStrRef,
Expand Down
4 changes: 2 additions & 2 deletions stdlib/src/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod _random {
builtins::{PyInt, PyTypeRef},
function::OptionalOption,
types::Constructor,
PyObjectRef, PyResult, PyValue, VirtualMachine,
PyObjectRef, PyPayload, PyResult, VirtualMachine,
};
use num_bigint::{BigInt, Sign};
use num_traits::{Signed, Zero};
Expand Down Expand Up @@ -56,7 +56,7 @@ mod _random {

#[pyattr]
#[pyclass(name = "Random")]
#[derive(Debug, PyValue)]
#[derive(Debug, PyPayload)]
struct PyRandom {
rng: PyMutex<PyRng>,
}
Expand Down
6 changes: 3 additions & 3 deletions stdlib/src/re.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod re {
builtins::{PyInt, PyIntRef, PyStr, PyStrRef},
convert::{ToPyObject, TryFromObject},
function::{OptionalArg, PosArgs},
match_class, PyObjectRef, PyResult, PyValue, VirtualMachine,
match_class, PyObjectRef, PyResult, PyPayload, VirtualMachine,
};
use num_traits::Signed;
use regex::bytes::{Captures, Regex, RegexBuilder};
Expand All @@ -21,7 +21,7 @@ mod re {

#[pyattr]
#[pyclass(module = "re", name = "Pattern")]
#[derive(Debug, PyValue)]
#[derive(Debug, PyPayload)]
struct PyPattern {
regex: Regex,
pattern: String,
Expand Down Expand Up @@ -77,7 +77,7 @@ mod re {
/// Inner data for a match object.
#[pyattr]
#[pyclass(module = "re", name = "Match")]
#[derive(PyValue)]
#[derive(PyPayload)]
struct PyMatch {
haystack: PyStrRef,
captures: Vec<Option<Range<usize>>>,
Expand Down
4 changes: 2 additions & 2 deletions stdlib/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ mod decl {
use super::*;
use crate::vm::{
builtins::PyFloat, common::lock::PyMutex, convert::ToPyObject, function::OptionalArg,
stdlib::io::Fildes, AsObject, PyValue,
stdlib::io::Fildes, AsObject, PyPayload,
};
use libc::pollfd;
use num_traits::ToPrimitive;
use std::time;

#[pyclass(module = "select", name = "poll")]
#[derive(Default, Debug, PyValue)]
#[derive(Default, Debug, PyPayload)]
pub struct PyPoll {
// keep sorted
fds: PyMutex<Vec<pollfd>>,
Expand Down
4 changes: 2 additions & 2 deletions stdlib/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod _socket {
convert::{ToPyException, ToPyObject, TryFromBorrowedObject, TryFromObject},
function::{ArgBytesLike, ArgMemoryBuffer, FuncArgs, OptionalArg, OptionalOption},
utils::{Either, ToCString},
AsObject, PyObjectRef, PyResult, PyValue, VirtualMachine,
AsObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
use num_traits::ToPrimitive;
Expand Down Expand Up @@ -231,7 +231,7 @@ mod _socket {
#[pyattr(name = "socket")]
#[pyattr(name = "SocketType")]
#[pyclass(name = "socket")]
#[derive(Debug, PyValue)]
#[derive(Debug, PyPayload)]
pub struct PySocket {
kind: AtomicCell<i32>,
family: AtomicCell<i32>,
Expand Down
Loading