forked from Rust-related/RustPython
2024 edition formatting
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
use criterion::measurement::WallTime;
|
||||
use criterion::{
|
||||
black_box, criterion_group, criterion_main, Bencher, BenchmarkGroup, BenchmarkId, Criterion,
|
||||
Throughput,
|
||||
Bencher, BenchmarkGroup, BenchmarkId, Criterion, Throughput, black_box, criterion_group,
|
||||
criterion_main,
|
||||
};
|
||||
use rustpython_compiler::Mode;
|
||||
use rustpython_parser::ast;
|
||||
use rustpython_parser::Parse;
|
||||
use rustpython_parser::ast;
|
||||
use rustpython_vm::{Interpreter, PyResult, Settings};
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use criterion::{
|
||||
criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, BenchmarkId,
|
||||
Criterion, Throughput,
|
||||
BatchSize, BenchmarkGroup, BenchmarkId, Criterion, Throughput, criterion_group, criterion_main,
|
||||
measurement::WallTime,
|
||||
};
|
||||
use pyo3::types::PyAnyMethods;
|
||||
use rustpython_compiler::Mode;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
pub use libc::stat as StatStruct;
|
||||
|
||||
#[cfg(windows)]
|
||||
pub use windows::{fstat, StatStruct};
|
||||
pub use windows::{StatStruct, fstat};
|
||||
|
||||
#[cfg(not(windows))]
|
||||
pub fn fstat(fd: libc::c_int) -> std::io::Result<StatStruct> {
|
||||
@@ -28,19 +28,19 @@ pub mod windows {
|
||||
use std::ffi::{CString, OsStr, OsString};
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
use std::sync::OnceLock;
|
||||
use windows_sys::core::PCWSTR;
|
||||
use windows_sys::Win32::Foundation::{
|
||||
FreeLibrary, SetLastError, BOOL, ERROR_INVALID_HANDLE, ERROR_NOT_SUPPORTED, FILETIME,
|
||||
HANDLE, INVALID_HANDLE_VALUE,
|
||||
BOOL, ERROR_INVALID_HANDLE, ERROR_NOT_SUPPORTED, FILETIME, FreeLibrary, HANDLE,
|
||||
INVALID_HANDLE_VALUE, SetLastError,
|
||||
};
|
||||
use windows_sys::Win32::Storage::FileSystem::{
|
||||
FileBasicInfo, FileIdInfo, GetFileInformationByHandle, GetFileInformationByHandleEx,
|
||||
GetFileType, BY_HANDLE_FILE_INFORMATION, FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_READONLY,
|
||||
BY_HANDLE_FILE_INFORMATION, FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_READONLY,
|
||||
FILE_ATTRIBUTE_REPARSE_POINT, FILE_BASIC_INFO, FILE_ID_INFO, FILE_TYPE_CHAR,
|
||||
FILE_TYPE_DISK, FILE_TYPE_PIPE, FILE_TYPE_UNKNOWN,
|
||||
FILE_TYPE_DISK, FILE_TYPE_PIPE, FILE_TYPE_UNKNOWN, FileBasicInfo, FileIdInfo,
|
||||
GetFileInformationByHandle, GetFileInformationByHandleEx, GetFileType,
|
||||
};
|
||||
use windows_sys::Win32::System::LibraryLoader::{GetProcAddress, LoadLibraryW};
|
||||
use windows_sys::Win32::System::SystemServices::IO_REPARSE_TAG_SYMLINK;
|
||||
use windows_sys::core::PCWSTR;
|
||||
|
||||
pub const S_IFIFO: libc::c_int = 0o010000;
|
||||
pub const S_IFLNK: libc::c_int = 0o120000;
|
||||
|
||||
@@ -64,11 +64,7 @@ pub fn gt_int(value: f64, other_int: &BigInt) -> bool {
|
||||
}
|
||||
|
||||
pub fn div(v1: f64, v2: f64) -> Option<f64> {
|
||||
if v2 != 0.0 {
|
||||
Some(v1 / v2)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if v2 != 0.0 { Some(v1 / v2) } else { None }
|
||||
}
|
||||
|
||||
pub fn mod_(v1: f64, v2: f64) -> Option<f64> {
|
||||
@@ -125,11 +121,7 @@ pub fn nextafter(x: f64, y: f64) -> f64 {
|
||||
let b = x.to_bits();
|
||||
let bits = if (y > x) == (x > 0.0) { b + 1 } else { b - 1 };
|
||||
let ret = f64::from_bits(bits);
|
||||
if ret == 0.0 {
|
||||
ret.copysign(x)
|
||||
} else {
|
||||
ret
|
||||
}
|
||||
if ret == 0.0 { ret.copysign(x) } else { ret }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,11 +150,7 @@ pub fn hash_bigint(value: &BigInt) -> PyHash {
|
||||
|
||||
#[inline(always)]
|
||||
pub fn fix_sentinel(x: PyHash) -> PyHash {
|
||||
if x == SENTINEL {
|
||||
-2
|
||||
} else {
|
||||
x
|
||||
}
|
||||
if x == SENTINEL { -2 } else { x }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -241,11 +241,7 @@ pub mod levenshtein {
|
||||
if b.is_ascii_uppercase() {
|
||||
b += b'a' - b'A';
|
||||
}
|
||||
if a == b {
|
||||
CASE_COST
|
||||
} else {
|
||||
MOVE_COST
|
||||
}
|
||||
if a == b { CASE_COST } else { MOVE_COST }
|
||||
}
|
||||
|
||||
pub fn levenshtein_distance(a: &str, b: &str, max_cost: usize) -> usize {
|
||||
|
||||
@@ -8,21 +8,21 @@
|
||||
#![deny(clippy::cast_possible_truncation)]
|
||||
|
||||
use crate::{
|
||||
IndexSet,
|
||||
error::{CodegenError, CodegenErrorType},
|
||||
ir,
|
||||
symboltable::{self, SymbolFlags, SymbolScope, SymbolTable},
|
||||
IndexSet,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use num_complex::Complex64;
|
||||
use num_traits::ToPrimitive;
|
||||
use rustpython_ast::located::{self as located_ast, Located};
|
||||
use rustpython_compiler_core::{
|
||||
Mode,
|
||||
bytecode::{
|
||||
self, Arg as OpArgMarker, CodeObject, ComparisonOperator, ConstantData, Instruction, OpArg,
|
||||
OpArgType,
|
||||
},
|
||||
Mode,
|
||||
};
|
||||
use rustpython_parser_core::source_code::{LineNumber, SourceLocation};
|
||||
use std::borrow::Cow;
|
||||
@@ -975,7 +975,7 @@ impl Compiler {
|
||||
}
|
||||
}
|
||||
located_ast::Expr::BinOp(_) | located_ast::Expr::UnaryOp(_) => {
|
||||
return Err(self.error(CodegenErrorType::Delete("expression")))
|
||||
return Err(self.error(CodegenErrorType::Delete("expression")));
|
||||
}
|
||||
_ => return Err(self.error(CodegenErrorType::Delete(expression.python_name()))),
|
||||
}
|
||||
@@ -1213,7 +1213,7 @@ impl Compiler {
|
||||
|
||||
if !finalbody.is_empty() {
|
||||
emit!(self, Instruction::PopBlock); // pop excepthandler block
|
||||
// We enter the finally block, without exception.
|
||||
// We enter the finally block, without exception.
|
||||
emit!(self, Instruction::EnterFinally);
|
||||
}
|
||||
|
||||
@@ -3124,7 +3124,9 @@ impl Compiler {
|
||||
| "with_statement" | "print_function" | "unicode_literals" | "generator_stop" => {}
|
||||
"annotations" => self.future_annotations = true,
|
||||
other => {
|
||||
return Err(self.error(CodegenErrorType::InvalidFutureFeature(other.to_owned())))
|
||||
return Err(
|
||||
self.error(CodegenErrorType::InvalidFutureFeature(other.to_owned()))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3477,8 +3479,8 @@ impl ToU32 for usize {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use rustpython_parser::ast::Suite;
|
||||
use rustpython_parser::Parse;
|
||||
use rustpython_parser::ast::Suite;
|
||||
use rustpython_parser_core::source_code::LinearLocator;
|
||||
|
||||
fn compile_exec(source: &str) -> CodeObject {
|
||||
|
||||
@@ -199,11 +199,7 @@ impl CodeInfo {
|
||||
})
|
||||
.collect::<Box<[_]>>();
|
||||
|
||||
if found_cellarg {
|
||||
Some(cell2arg)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if found_cellarg { Some(cell2arg) } else { None }
|
||||
}
|
||||
|
||||
fn dce(&mut self) {
|
||||
|
||||
@@ -8,8 +8,8 @@ Inspirational file: https://github.com/python/cpython/blob/main/Python/symtable.
|
||||
*/
|
||||
|
||||
use crate::{
|
||||
error::{CodegenError, CodegenErrorType},
|
||||
IndexMap,
|
||||
error::{CodegenError, CodegenErrorType},
|
||||
};
|
||||
use bitflags::bitflags;
|
||||
use rustpython_ast::{self as ast, located::Located};
|
||||
@@ -505,7 +505,10 @@ impl SymbolTableAnalyzer {
|
||||
// check if assignee is an iterator in top scope
|
||||
if parent_symbol.flags.contains(SymbolFlags::ITER) {
|
||||
return Err(SymbolTableError {
|
||||
error: format!("assignment expression cannot rebind comprehension iteration variable {}", symbol.name),
|
||||
error: format!(
|
||||
"assignment expression cannot rebind comprehension iteration variable {}",
|
||||
symbol.name
|
||||
),
|
||||
location: None,
|
||||
});
|
||||
}
|
||||
@@ -1408,7 +1411,7 @@ impl SymbolTableBuilder {
|
||||
return Err(SymbolTableError {
|
||||
error: format!("cannot define nonlocal '{name}' at top level."),
|
||||
location,
|
||||
})
|
||||
});
|
||||
}
|
||||
_ => {
|
||||
// Ok!
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use rustpython_codegen::{compile, symboltable};
|
||||
use rustpython_parser::ast::{self as ast, fold::Fold, ConstantOptimizer};
|
||||
use rustpython_parser::ast::{self as ast, ConstantOptimizer, fold::Fold};
|
||||
|
||||
pub use rustpython_codegen::compile::CompileOpts;
|
||||
pub use rustpython_compiler_core::{bytecode::CodeObject, Mode};
|
||||
pub use rustpython_parser::{source_code::LinearLocator, Parse};
|
||||
pub use rustpython_compiler_core::{Mode, bytecode::CodeObject};
|
||||
pub use rustpython_parser::{Parse, source_code::LinearLocator};
|
||||
|
||||
// these modules are out of repository. re-exporting them here for convenience.
|
||||
pub use rustpython_codegen as codegen;
|
||||
|
||||
@@ -17,17 +17,16 @@ use crate::Diagnostic;
|
||||
use once_cell::sync::Lazy;
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
use quote::quote;
|
||||
use rustpython_compiler_core::{bytecode::CodeObject, frozen, Mode};
|
||||
use rustpython_compiler_core::{Mode, bytecode::CodeObject, frozen};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use syn::{
|
||||
self,
|
||||
self, LitByteStr, LitStr, Macro,
|
||||
parse::{ParseStream, Parser, Result as ParseResult},
|
||||
spanned::Spanned,
|
||||
LitByteStr, LitStr, Macro,
|
||||
};
|
||||
|
||||
static CARGO_MANIFEST_DIR: Lazy<PathBuf> = Lazy::new(|| {
|
||||
@@ -118,11 +117,13 @@ impl CompilationSource {
|
||||
})?;
|
||||
self.compile_string(&source, mode, module_name, compiler, || rel_path.display())
|
||||
}
|
||||
CompilationSourceKind::SourceCode(code) => {
|
||||
self.compile_string(&textwrap::dedent(code), mode, module_name, compiler, || {
|
||||
"string literal"
|
||||
})
|
||||
}
|
||||
CompilationSourceKind::SourceCode(code) => self.compile_string(
|
||||
&textwrap::dedent(code),
|
||||
mode,
|
||||
module_name,
|
||||
compiler,
|
||||
|| "string literal",
|
||||
),
|
||||
CompilationSourceKind::Dir(_) => {
|
||||
unreachable!("Can't use compile_single with directory source")
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{quote, ToTokens};
|
||||
use quote::{ToTokens, quote};
|
||||
use syn::ext::IdentExt;
|
||||
use syn::meta::ParseNestedMeta;
|
||||
use syn::{parse_quote, Attribute, Data, DeriveInput, Expr, Field, Ident, Result, Token};
|
||||
use syn::{Attribute, Data, DeriveInput, Expr, Field, Ident, Result, Token, parse_quote};
|
||||
|
||||
/// The kind of the python parameter, this corresponds to the value of Parameter.kind
|
||||
/// (https://docs.python.org/3/library/inspect.html#inspect.Parameter.kind)
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
use super::Diagnostic;
|
||||
use crate::util::{
|
||||
format_doc, pyclass_ident_and_attrs, pyexception_ident_and_attrs, text_signature,
|
||||
ClassItemMeta, ContentItem, ContentItemInner, ErrorVec, ExceptionItemMeta, ItemMeta,
|
||||
ItemMetaInner, ItemNursery, SimpleItemMeta, ALL_ALLOWED_NAMES,
|
||||
ALL_ALLOWED_NAMES, ClassItemMeta, ContentItem, ContentItemInner, ErrorVec, ExceptionItemMeta,
|
||||
ItemMeta, ItemMetaInner, ItemNursery, SimpleItemMeta, format_doc, pyclass_ident_and_attrs,
|
||||
pyexception_ident_and_attrs, text_signature,
|
||||
};
|
||||
use proc_macro2::{Delimiter, Group, Span, TokenStream, TokenTree};
|
||||
use quote::{quote, quote_spanned, ToTokens};
|
||||
use quote::{ToTokens, quote, quote_spanned};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::str::FromStr;
|
||||
use syn::{parse_quote, spanned::Spanned, Attribute, Ident, Item, Result};
|
||||
use syn::{Attribute, Ident, Item, Result, parse_quote, spanned::Spanned};
|
||||
use syn_ext::ext::*;
|
||||
use syn_ext::types::*;
|
||||
|
||||
@@ -126,7 +126,7 @@ pub(crate) fn impl_pyclass_impl(attr: PunctuatedNestedMeta, item: Item) -> Resul
|
||||
return Err(syn::Error::new_spanned(
|
||||
segment,
|
||||
"Py{Ref}<T> is expected but Py{Ref}<?> is found",
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,7 +134,7 @@ pub(crate) fn impl_pyclass_impl(attr: PunctuatedNestedMeta, item: Item) -> Resul
|
||||
return Err(syn::Error::new_spanned(
|
||||
segment,
|
||||
"Py{Ref}<T> is expected but Py{Ref}? is found",
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -152,7 +152,7 @@ pub(crate) fn impl_pyclass_impl(attr: PunctuatedNestedMeta, item: Item) -> Resul
|
||||
return Err(syn::Error::new_spanned(
|
||||
imp.self_ty,
|
||||
"PyImpl can only be implemented for Py{Ref}<T> or T",
|
||||
))
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1237,11 +1237,7 @@ impl MethodItemMeta {
|
||||
name
|
||||
} else {
|
||||
let name = inner.item_name();
|
||||
if magic {
|
||||
format!("__{name}__")
|
||||
} else {
|
||||
name
|
||||
}
|
||||
if magic { format!("__{name}__") } else { name }
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1308,11 +1304,7 @@ impl GetSetItemMeta {
|
||||
GetSetItemKind::Set => extract_prefix_name("set_", "setter")?,
|
||||
GetSetItemKind::Delete => extract_prefix_name("del_", "deleter")?,
|
||||
};
|
||||
if magic {
|
||||
format!("__{name}__")
|
||||
} else {
|
||||
name
|
||||
}
|
||||
if magic { format!("__{name}__") } else { name }
|
||||
};
|
||||
Ok((py_name, kind))
|
||||
}
|
||||
@@ -1488,7 +1480,10 @@ fn extract_impl_attrs(attr: PunctuatedNestedMeta, item: &Ident) -> Result<Extrac
|
||||
)
|
||||
} else {
|
||||
if path.is_ident("DefaultConstructor") {
|
||||
bail_span!(meta, "Try `#[pyclass(with(Constructor, ...))]` instead of `#[pyclass(with(DefaultConstructor, ...))]`. DefaultConstructor implicitly implements Constructor.")
|
||||
bail_span!(
|
||||
meta,
|
||||
"Try `#[pyclass(with(Constructor, ...))]` instead of `#[pyclass(with(DefaultConstructor, ...))]`. DefaultConstructor implicitly implements Constructor."
|
||||
)
|
||||
}
|
||||
if path.is_ident("Constructor") || path.is_ident("Unconstructible") {
|
||||
has_constructor = true;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use crate::error::Diagnostic;
|
||||
use crate::util::{
|
||||
format_doc, iter_use_idents, pyclass_ident_and_attrs, text_signature, AttrItemMeta,
|
||||
AttributeExt, ClassItemMeta, ContentItem, ContentItemInner, ErrorVec, ItemMeta, ItemNursery,
|
||||
ModuleItemMeta, SimpleItemMeta, ALL_ALLOWED_NAMES,
|
||||
ALL_ALLOWED_NAMES, AttrItemMeta, AttributeExt, ClassItemMeta, ContentItem, ContentItemInner,
|
||||
ErrorVec, ItemMeta, ItemNursery, ModuleItemMeta, SimpleItemMeta, format_doc, iter_use_idents,
|
||||
pyclass_ident_and_attrs, text_signature,
|
||||
};
|
||||
use proc_macro2::{Delimiter, Group, TokenStream, TokenTree};
|
||||
use quote::{quote, quote_spanned, ToTokens};
|
||||
use quote::{ToTokens, quote, quote_spanned};
|
||||
use std::{collections::HashSet, str::FromStr};
|
||||
use syn::{parse_quote, spanned::Spanned, Attribute, Ident, Item, Result};
|
||||
use syn::{Attribute, Ident, Item, Result, parse_quote, spanned::Spanned};
|
||||
use syn_ext::ext::*;
|
||||
use syn_ext::types::PunctuatedNestedMeta;
|
||||
|
||||
@@ -688,7 +688,7 @@ impl ModuleItem for AttributeItem {
|
||||
other => {
|
||||
return Err(
|
||||
self.new_syn_error(other.span(), "can only be on a function, const and use")
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use itertools::Itertools;
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
use quote::{quote, ToTokens};
|
||||
use quote::{ToTokens, quote};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use syn::{spanned::Spanned, Attribute, Ident, Result, Signature, UseTree};
|
||||
use syn::{Attribute, Ident, Result, Signature, UseTree, spanned::Spanned};
|
||||
use syn_ext::{
|
||||
ext::{AttributeExt as SynAttributeExt, *},
|
||||
types::*,
|
||||
@@ -75,7 +75,7 @@ impl ItemNursery {
|
||||
|
||||
impl ToTokens for ValidatedItemNursery {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
let mut sorted = self.0 .0.clone();
|
||||
let mut sorted = self.0.0.clone();
|
||||
sorted.sort_by(|a, b| a.sort_order.cmp(&b.sort_order));
|
||||
tokens.extend(sorted.iter().map(|item| {
|
||||
let cfgs = &item.cfgs;
|
||||
@@ -447,7 +447,7 @@ impl ItemMeta for ExceptionItemMeta {
|
||||
Self(ClassItemMeta(inner))
|
||||
}
|
||||
fn inner(&self) -> &ItemMetaInner {
|
||||
&self.0 .0
|
||||
&self.0.0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -470,12 +470,12 @@ impl ExceptionItemMeta {
|
||||
let type_name = inner.item_name();
|
||||
let Some(py_name) = type_name.as_str().strip_prefix("Py") else {
|
||||
bail_span!(
|
||||
inner.item_ident,
|
||||
"#[pyexception] expects its underlying type to be named `Py` prefixed"
|
||||
)
|
||||
inner.item_ident,
|
||||
"#[pyexception] expects its underlying type to be named `Py` prefixed"
|
||||
)
|
||||
};
|
||||
py_name.to_string()
|
||||
})
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ impl derive_impl::Compiler for Compiler {
|
||||
mode: rustpython_compiler::Mode,
|
||||
module_name: String,
|
||||
) -> Result<rustpython_compiler::CodeObject, Box<dyn std::error::Error>> {
|
||||
use rustpython_compiler::{compile, CompileOpts};
|
||||
use rustpython_compiler::{CompileOpts, compile};
|
||||
Ok(compile(source, mode, module_name, CompileOpts::default())?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use rustpython::vm::{
|
||||
pyclass, pymodule, PyObject, PyPayload, PyResult, TryFromBorrowedObject, VirtualMachine,
|
||||
PyObject, PyPayload, PyResult, TryFromBorrowedObject, VirtualMachine, pyclass, pymodule,
|
||||
};
|
||||
|
||||
pub fn main() {
|
||||
@@ -31,7 +31,7 @@ pub fn main() {
|
||||
#[pymodule]
|
||||
mod rust_py_module {
|
||||
use super::*;
|
||||
use rustpython::vm::{builtins::PyList, convert::ToPyObject, PyObjectRef};
|
||||
use rustpython::vm::{PyObjectRef, builtins::PyList, convert::ToPyObject};
|
||||
|
||||
#[pyfunction]
|
||||
fn rust_function(
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use rustpython_vm as vm;
|
||||
use std::process::ExitCode;
|
||||
use vm::{
|
||||
Interpreter, PyResult,
|
||||
builtins::PyIntRef,
|
||||
protocol::{PyIter, PyIterReturn},
|
||||
Interpreter, PyResult,
|
||||
};
|
||||
|
||||
fn py_main(interp: &Interpreter) -> vm::PyResult<()> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use rustpython_vm as vm;
|
||||
use std::process::ExitCode;
|
||||
use vm::{builtins::PyStrRef, Interpreter};
|
||||
use vm::{Interpreter, builtins::PyStrRef};
|
||||
|
||||
fn py_main(interp: &Interpreter) -> vm::PyResult<PyStrRef> {
|
||||
interp.enter(|vm| {
|
||||
|
||||
@@ -12,7 +12,7 @@ extern crate env_logger;
|
||||
extern crate log;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use rustpython_parser::{ast, Parse};
|
||||
use rustpython_parser::{Parse, ast};
|
||||
use std::{
|
||||
path::Path,
|
||||
time::{Duration, Instant},
|
||||
|
||||
@@ -1 +1 @@
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use rustpython_vm::{builtins::PyModule, Interpreter, PyRef, Settings, VirtualMachine};
|
||||
use rustpython_vm::{Interpreter, PyRef, Settings, VirtualMachine, builtins::PyModule};
|
||||
|
||||
pub type InitHook = Box<dyn FnOnce(&mut VirtualMachine)>;
|
||||
|
||||
|
||||
@@ -50,14 +50,14 @@ mod interpreter;
|
||||
mod settings;
|
||||
mod shell;
|
||||
|
||||
use rustpython_vm::{scope::Scope, PyResult, VirtualMachine};
|
||||
use rustpython_vm::{PyResult, VirtualMachine, scope::Scope};
|
||||
use std::env;
|
||||
use std::io::IsTerminal;
|
||||
use std::process::ExitCode;
|
||||
|
||||
pub use interpreter::InterpreterConfig;
|
||||
pub use rustpython_vm as vm;
|
||||
pub use settings::{opts_with_clap, InstallPipMode, RunMode};
|
||||
pub use settings::{InstallPipMode, RunMode, opts_with_clap};
|
||||
pub use shell::run_shell;
|
||||
|
||||
/// The main cli of the `rustpython` interpreter. This function will return `std::process::ExitCode`
|
||||
|
||||
@@ -238,7 +238,9 @@ fn settings_from(matches: &ArgMatches) -> (Settings, RunMode) {
|
||||
settings.int_max_str_digits = match env::var("PYTHONINTMAXSTRDIGITS").unwrap().parse() {
|
||||
Ok(digits @ (0 | 640..)) => digits,
|
||||
_ => {
|
||||
error!("Fatal Python error: config_init_int_max_str_digits: PYTHONINTMAXSTRDIGITS: invalid limit; must be >= 640 or 0 for unlimited.\nPython runtime state: preinitialized");
|
||||
error!(
|
||||
"Fatal Python error: config_init_int_max_str_digits: PYTHONINTMAXSTRDIGITS: invalid limit; must be >= 640 or 0 for unlimited.\nPython runtime state: preinitialized"
|
||||
);
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
mod helper;
|
||||
|
||||
use rustpython_parser::{lexer::LexicalErrorType, ParseErrorType, Tok};
|
||||
use rustpython_parser::{ParseErrorType, Tok, lexer::LexicalErrorType};
|
||||
use rustpython_vm::{
|
||||
AsObject, PyResult, VirtualMachine,
|
||||
builtins::PyBaseExceptionRef,
|
||||
compiler::{self, CompileError, CompileErrorType},
|
||||
readline::{Readline, ReadlineResult},
|
||||
scope::Scope,
|
||||
AsObject, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
enum ShellExecResult {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#![cfg_attr(target_arch = "wasm32", allow(dead_code))]
|
||||
use rustpython_vm::{
|
||||
AsObject, PyResult, TryFromObject, VirtualMachine,
|
||||
builtins::{PyDictRef, PyStrRef},
|
||||
function::ArgIterable,
|
||||
identifier, AsObject, PyResult, TryFromObject, VirtualMachine,
|
||||
identifier,
|
||||
};
|
||||
|
||||
pub struct ShellHelper<'vm> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// spell-checker:ignore typecode tofile tolist fromfile
|
||||
|
||||
use rustpython_vm::{builtins::PyModule, PyRef, VirtualMachine};
|
||||
use rustpython_vm::{PyRef, VirtualMachine, builtins::PyModule};
|
||||
|
||||
pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
|
||||
let module = array::make_module(vm);
|
||||
@@ -41,6 +41,7 @@ mod array {
|
||||
str::wchar_t,
|
||||
},
|
||||
vm::{
|
||||
AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
atomic_func,
|
||||
builtins::{
|
||||
PositionIterInternal, PyByteArray, PyBytes, PyBytesRef, PyDictRef, PyFloat, PyInt,
|
||||
@@ -64,7 +65,6 @@ mod array {
|
||||
AsBuffer, AsMapping, AsSequence, Comparable, Constructor, IterNext, Iterable,
|
||||
PyComparisonOp, Representable, SelfIter,
|
||||
},
|
||||
AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
},
|
||||
};
|
||||
use itertools::Itertools;
|
||||
@@ -1528,7 +1528,7 @@ mod array {
|
||||
2 => Some(Self::Utf16 { big_endian }),
|
||||
4 => Some(Self::Utf32 { big_endian }),
|
||||
_ => None,
|
||||
}
|
||||
};
|
||||
}
|
||||
'f' => {
|
||||
// Copied from CPython
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
pub(super) use decl::crc32;
|
||||
pub(crate) use decl::make_module;
|
||||
use rustpython_vm::{builtins::PyBaseExceptionRef, convert::ToPyException, VirtualMachine};
|
||||
use rustpython_vm::{VirtualMachine, builtins::PyBaseExceptionRef, convert::ToPyException};
|
||||
|
||||
const PAD: u8 = 61u8;
|
||||
const MAXLINESIZE: usize = 76; // Excluding the CRLF
|
||||
@@ -11,10 +11,10 @@ const MAXLINESIZE: usize = 76; // Excluding the CRLF
|
||||
mod decl {
|
||||
use super::{MAXLINESIZE, PAD};
|
||||
use crate::vm::{
|
||||
PyResult, VirtualMachine,
|
||||
builtins::{PyIntRef, PyTypeRef},
|
||||
convert::ToPyException,
|
||||
function::{ArgAsciiBuffer, ArgBytesLike, OptionalArg},
|
||||
PyResult, VirtualMachine,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
|
||||
@@ -751,7 +751,10 @@ impl ToPyException for Base64DecodeError {
|
||||
InvalidByte(_, _) => "Only base64 data is allowed".to_owned(),
|
||||
InvalidLastSymbol(_, PAD) => "Excess data after padding".to_owned(),
|
||||
InvalidLastSymbol(length, _) => {
|
||||
format!("Invalid base64-encoded string: number of data characters {} cannot be 1 more than a multiple of 4", length)
|
||||
format!(
|
||||
"Invalid base64-encoded string: number of data characters {} cannot be 1 more than a multiple of 4",
|
||||
length
|
||||
)
|
||||
}
|
||||
InvalidLength => "Incorrect padding".to_owned(),
|
||||
};
|
||||
|
||||
@@ -3,9 +3,9 @@ pub(crate) use _bisect::make_module;
|
||||
#[pymodule]
|
||||
mod _bisect {
|
||||
use crate::vm::{
|
||||
PyObjectRef, PyResult, VirtualMachine,
|
||||
function::{ArgIndex, OptionalArg},
|
||||
types::PyComparisonOp,
|
||||
PyObjectRef, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
#[derive(FromArgs)]
|
||||
|
||||
@@ -4,7 +4,7 @@ pub(crate) use _blake2::make_module;
|
||||
|
||||
#[pymodule]
|
||||
mod _blake2 {
|
||||
use crate::hashlib::_hashlib::{local_blake2b, local_blake2s, BlakeHashArgs};
|
||||
use crate::hashlib::_hashlib::{BlakeHashArgs, local_blake2b, local_blake2s};
|
||||
use crate::vm::{PyPayload, PyResult, VirtualMachine};
|
||||
|
||||
#[pyfunction]
|
||||
|
||||
@@ -6,13 +6,13 @@ pub(crate) use _bz2::make_module;
|
||||
mod _bz2 {
|
||||
use crate::common::lock::PyMutex;
|
||||
use crate::vm::{
|
||||
VirtualMachine,
|
||||
builtins::{PyBytesRef, PyTypeRef},
|
||||
function::{ArgBytesLike, OptionalArg},
|
||||
object::{PyPayload, PyResult},
|
||||
types::Constructor,
|
||||
VirtualMachine,
|
||||
};
|
||||
use bzip2::{write::BzEncoder, Decompress, Status};
|
||||
use bzip2::{Decompress, Status, write::BzEncoder};
|
||||
use std::{fmt, io::Write};
|
||||
|
||||
// const BUFSIZ: i32 = 8192;
|
||||
@@ -196,7 +196,7 @@ mod _bz2 {
|
||||
_ => {
|
||||
return Err(
|
||||
vm.new_value_error("compresslevel must be between 1 and 9".to_owned())
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ pub(crate) use cmath::make_module;
|
||||
#[pymodule]
|
||||
mod cmath {
|
||||
use crate::vm::{
|
||||
function::{ArgIntoComplex, ArgIntoFloat, OptionalArg},
|
||||
PyResult, VirtualMachine,
|
||||
function::{ArgIntoComplex, ArgIntoFloat, OptionalArg},
|
||||
};
|
||||
use num_complex::Complex64;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::vm::{builtins::PyModule, class::StaticType, PyRef, VirtualMachine};
|
||||
use crate::vm::{PyRef, VirtualMachine, builtins::PyModule, class::StaticType};
|
||||
use _contextvars::PyContext;
|
||||
use std::cell::RefCell;
|
||||
|
||||
@@ -23,14 +23,13 @@ thread_local! {
|
||||
#[pymodule]
|
||||
mod _contextvars {
|
||||
use crate::vm::{
|
||||
atomic_func,
|
||||
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, atomic_func,
|
||||
builtins::{PyStrRef, PyTypeRef},
|
||||
class::StaticType,
|
||||
common::hash::PyHash,
|
||||
function::{ArgCallable, FuncArgs, OptionalArg},
|
||||
protocol::{PyMappingMethods, PySequenceMethods},
|
||||
types::{AsMapping, AsSequence, Constructor, Hashable, Representable},
|
||||
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
@@ -4,11 +4,11 @@ pub(crate) use _csv::make_module;
|
||||
mod _csv {
|
||||
use crate::common::lock::PyMutex;
|
||||
use crate::vm::{
|
||||
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine,
|
||||
builtins::{PyBaseExceptionRef, PyInt, PyNone, PyStr, PyType, PyTypeError, PyTypeRef},
|
||||
function::{ArgIterable, ArgumentError, FromArgs, FuncArgs, OptionalArg},
|
||||
protocol::{PyIter, PyIterReturn},
|
||||
types::{Constructor, IterNext, Iterable, SelfIter},
|
||||
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine,
|
||||
};
|
||||
use csv_core::Terminator;
|
||||
use itertools::{self, Itertools};
|
||||
@@ -396,7 +396,7 @@ mod _csv {
|
||||
Some(write_meth) => write_meth,
|
||||
None if file.is_callable() => file,
|
||||
None => {
|
||||
return Err(vm.new_type_error("argument 1 must have a \"write\" method".to_owned()))
|
||||
return Err(vm.new_type_error("argument 1 must have a \"write\" method".to_owned()));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -995,7 +995,7 @@ mod _csv {
|
||||
csv_core::ReadRecordResult::OutputEndsFull => resize_buf(output_ends),
|
||||
csv_core::ReadRecordResult::Record => break,
|
||||
csv_core::ReadRecordResult::End => {
|
||||
return Ok(PyIterReturn::StopIteration(None))
|
||||
return Ok(PyIterReturn::StopIteration(None));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ pub(crate) use decl::make_module;
|
||||
#[pymodule(name = "dis")]
|
||||
mod decl {
|
||||
use crate::vm::{
|
||||
PyObjectRef, PyRef, PyResult, TryFromObject, VirtualMachine,
|
||||
builtins::{PyCode, PyDictRef, PyStrRef},
|
||||
bytecode::CodeFlags,
|
||||
PyObjectRef, PyRef, PyResult, TryFromObject, VirtualMachine,
|
||||
};
|
||||
|
||||
#[pyfunction]
|
||||
|
||||
@@ -2,7 +2,7 @@ pub(crate) use decl::make_module;
|
||||
|
||||
#[pymodule(name = "faulthandler")]
|
||||
mod decl {
|
||||
use crate::vm::{frame::Frame, function::OptionalArg, stdlib::sys::PyStderr, VirtualMachine};
|
||||
use crate::vm::{VirtualMachine, frame::Frame, function::OptionalArg, stdlib::sys::PyStderr};
|
||||
|
||||
fn dump_frame(frame: &Frame, vm: &VirtualMachine) {
|
||||
let stderr = PyStderr(vm);
|
||||
|
||||
@@ -3,10 +3,10 @@ pub(crate) use fcntl::make_module;
|
||||
#[pymodule]
|
||||
mod fcntl {
|
||||
use crate::vm::{
|
||||
PyResult, VirtualMachine,
|
||||
builtins::PyIntRef,
|
||||
function::{ArgMemoryBuffer, ArgStrOrBytesLike, Either, OptionalArg},
|
||||
stdlib::{io, os},
|
||||
PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
// TODO: supply these from <asm-generic/fnctl.h> (please file an issue/PR upstream):
|
||||
@@ -20,7 +20,7 @@ mod fcntl {
|
||||
// I_LINK, I_UNLINK, I_PLINK, I_PUNLINK
|
||||
|
||||
#[pyattr]
|
||||
use libc::{FD_CLOEXEC, F_GETFD, F_GETFL, F_SETFD, F_SETFL};
|
||||
use libc::{F_GETFD, F_GETFL, F_SETFD, F_SETFL, FD_CLOEXEC};
|
||||
|
||||
#[cfg(not(target_os = "wasi"))]
|
||||
#[pyattr]
|
||||
@@ -45,7 +45,7 @@ mod fcntl {
|
||||
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
|
||||
#[pyattr]
|
||||
use libc::{
|
||||
F_ADD_SEALS, F_GETLEASE, F_GETPIPE_SZ, F_GET_SEALS, F_NOTIFY, F_SEAL_GROW, F_SEAL_SEAL,
|
||||
F_ADD_SEALS, F_GET_SEALS, F_GETLEASE, F_GETPIPE_SZ, F_NOTIFY, F_SEAL_GROW, F_SEAL_SEAL,
|
||||
F_SEAL_SHRINK, F_SEAL_WRITE, F_SETLEASE, F_SETPIPE_SZ,
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ pub(crate) use gc::make_module;
|
||||
|
||||
#[pymodule]
|
||||
mod gc {
|
||||
use crate::vm::{function::FuncArgs, PyResult, VirtualMachine};
|
||||
use crate::vm::{PyResult, VirtualMachine, function::FuncArgs};
|
||||
|
||||
#[pyfunction]
|
||||
fn collect(_args: FuncArgs, _vm: &VirtualMachine) -> i32 {
|
||||
|
||||
@@ -3,11 +3,11 @@ pub(crate) use grp::make_module;
|
||||
#[pymodule]
|
||||
mod grp {
|
||||
use crate::vm::{
|
||||
PyObjectRef, PyResult, VirtualMachine,
|
||||
builtins::{PyIntRef, PyListRef, PyStrRef},
|
||||
convert::{IntoPyException, ToPyObject},
|
||||
exceptions,
|
||||
types::PyStructSequence,
|
||||
PyObjectRef, PyResult, VirtualMachine,
|
||||
};
|
||||
use nix::unistd;
|
||||
use std::ptr::NonNull;
|
||||
|
||||
@@ -6,16 +6,16 @@ pub(crate) use _hashlib::make_module;
|
||||
pub mod _hashlib {
|
||||
use crate::common::lock::PyRwLock;
|
||||
use crate::vm::{
|
||||
PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
builtins::{PyBytes, PyStrRef, PyTypeRef},
|
||||
convert::ToPyObject,
|
||||
function::{ArgBytesLike, ArgStrOrBytesLike, FuncArgs, OptionalArg},
|
||||
protocol::PyBuffer,
|
||||
PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
use blake2::{Blake2b512, Blake2s256};
|
||||
use digest::{core_api::BlockSizeUser, DynDigest};
|
||||
use digest::{DynDigest, core_api::BlockSizeUser};
|
||||
use digest::{ExtendableOutput, Update};
|
||||
use dyn_clone::{clone_trait_object, DynClone};
|
||||
use dyn_clone::{DynClone, clone_trait_object};
|
||||
use md5::Md5;
|
||||
use sha1::Sha1;
|
||||
use sha2::{Sha224, Sha256, Sha384, Sha512};
|
||||
|
||||
@@ -5,12 +5,12 @@ mod machinery;
|
||||
mod _json {
|
||||
use super::machinery;
|
||||
use crate::vm::{
|
||||
AsObject, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
builtins::{PyBaseExceptionRef, PyStrRef, PyType, PyTypeRef},
|
||||
convert::{ToPyObject, ToPyResult},
|
||||
function::{IntoFuncArgs, OptionalArg},
|
||||
protocol::PyIterReturn,
|
||||
types::{Callable, Constructor},
|
||||
AsObject, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
use malachite_bigint::BigInt;
|
||||
use std::str::FromStr;
|
||||
@@ -80,14 +80,14 @@ mod _json {
|
||||
None => {
|
||||
return Ok(PyIterReturn::StopIteration(Some(
|
||||
vm.ctx.new_int(idx).into(),
|
||||
)))
|
||||
)));
|
||||
}
|
||||
};
|
||||
let next_idx = idx + c.len_utf8();
|
||||
match c {
|
||||
'"' => {
|
||||
return scanstring(pystr, next_idx, OptionalArg::Present(self.strict), vm)
|
||||
.map(|x| PyIterReturn::Return(x.to_pyobject(vm)))
|
||||
.map(|x| PyIterReturn::Return(x.to_pyobject(vm)));
|
||||
}
|
||||
'{' => {
|
||||
// TODO: parse the object in rust
|
||||
|
||||
@@ -40,10 +40,10 @@ use libc::localeconv;
|
||||
#[pymodule]
|
||||
mod _locale {
|
||||
use rustpython_vm::{
|
||||
PyObjectRef, PyResult, VirtualMachine,
|
||||
builtins::{PyDictRef, PyIntRef, PyListRef, PyStrRef, PyTypeRef},
|
||||
convert::ToPyException,
|
||||
function::OptionalArg,
|
||||
PyObjectRef, PyResult, VirtualMachine,
|
||||
};
|
||||
use std::{
|
||||
ffi::{CStr, CString},
|
||||
@@ -56,12 +56,12 @@ mod _locale {
|
||||
))]
|
||||
#[pyattr]
|
||||
use libc::{
|
||||
ABDAY_1, ABDAY_2, ABDAY_3, ABDAY_4, ABDAY_5, ABDAY_6, ABDAY_7, ABMON_1, ABMON_10, ABMON_11,
|
||||
ABMON_12, ABMON_2, ABMON_3, ABMON_4, ABMON_5, ABMON_6, ABMON_7, ABMON_8, ABMON_9,
|
||||
ALT_DIGITS, AM_STR, CODESET, CRNCYSTR, DAY_1, DAY_2, DAY_3, DAY_4, DAY_5, DAY_6, DAY_7,
|
||||
D_FMT, D_T_FMT, ERA, ERA_D_FMT, ERA_D_T_FMT, ERA_T_FMT, LC_MESSAGES, MON_1, MON_10, MON_11,
|
||||
MON_12, MON_2, MON_3, MON_4, MON_5, MON_6, MON_7, MON_8, MON_9, NOEXPR, PM_STR, RADIXCHAR,
|
||||
THOUSEP, T_FMT, T_FMT_AMPM, YESEXPR,
|
||||
ABDAY_1, ABDAY_2, ABDAY_3, ABDAY_4, ABDAY_5, ABDAY_6, ABDAY_7, ABMON_1, ABMON_2, ABMON_3,
|
||||
ABMON_4, ABMON_5, ABMON_6, ABMON_7, ABMON_8, ABMON_9, ABMON_10, ABMON_11, ABMON_12,
|
||||
ALT_DIGITS, AM_STR, CODESET, CRNCYSTR, D_FMT, D_T_FMT, DAY_1, DAY_2, DAY_3, DAY_4, DAY_5,
|
||||
DAY_6, DAY_7, ERA, ERA_D_FMT, ERA_D_T_FMT, ERA_T_FMT, LC_MESSAGES, MON_1, MON_2, MON_3,
|
||||
MON_4, MON_5, MON_6, MON_7, MON_8, MON_9, MON_10, MON_11, MON_12, NOEXPR, PM_STR,
|
||||
RADIXCHAR, T_FMT, T_FMT_AMPM, THOUSEP, YESEXPR,
|
||||
};
|
||||
|
||||
#[pyattr]
|
||||
@@ -148,9 +148,7 @@ mod _locale {
|
||||
}
|
||||
|
||||
macro_rules! set_int_field {
|
||||
($lc:expr, $field:ident) => {{
|
||||
result.set_item(stringify!($field), vm.new_pyobj((*$lc).$field), vm)?
|
||||
}};
|
||||
($lc:expr, $field:ident) => {{ result.set_item(stringify!($field), vm.new_pyobj((*$lc).$field), vm)? }};
|
||||
}
|
||||
|
||||
macro_rules! set_group_field {
|
||||
|
||||
@@ -3,9 +3,10 @@ pub(crate) use math::make_module;
|
||||
#[pymodule]
|
||||
mod math {
|
||||
use crate::vm::{
|
||||
builtins::{try_bigint_to_f64, try_f64_to_bigint, PyFloat, PyInt, PyIntRef, PyStrInterned},
|
||||
PyObject, PyObjectRef, PyRef, PyResult, VirtualMachine,
|
||||
builtins::{PyFloat, PyInt, PyIntRef, PyStrInterned, try_bigint_to_f64, try_f64_to_bigint},
|
||||
function::{ArgIndex, ArgIntoFloat, ArgIterable, Either, OptionalArg, PosArgs},
|
||||
identifier, PyObject, PyObjectRef, PyRef, PyResult, VirtualMachine,
|
||||
identifier,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use malachite_bigint::BigInt;
|
||||
@@ -475,21 +476,13 @@ mod math {
|
||||
#[pyfunction]
|
||||
fn erf(x: ArgIntoFloat) -> f64 {
|
||||
let x = *x;
|
||||
if x.is_nan() {
|
||||
x
|
||||
} else {
|
||||
puruspe::erf(x)
|
||||
}
|
||||
if x.is_nan() { x } else { puruspe::erf(x) }
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn erfc(x: ArgIntoFloat) -> f64 {
|
||||
let x = *x;
|
||||
if x.is_nan() {
|
||||
x
|
||||
} else {
|
||||
puruspe::erfc(x)
|
||||
}
|
||||
if x.is_nan() { x } else { puruspe::erfc(x) }
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
|
||||
@@ -2,7 +2,7 @@ pub(crate) use _md5::make_module;
|
||||
|
||||
#[pymodule]
|
||||
mod _md5 {
|
||||
use crate::hashlib::_hashlib::{local_md5, HashArgs};
|
||||
use crate::hashlib::_hashlib::{HashArgs, local_md5};
|
||||
use crate::vm::{PyPayload, PyResult, VirtualMachine};
|
||||
|
||||
#[pyfunction]
|
||||
|
||||
@@ -8,7 +8,8 @@ mod mmap {
|
||||
lock::{MapImmutable, PyMutex, PyMutexGuard},
|
||||
};
|
||||
use crate::vm::{
|
||||
atomic_func,
|
||||
AsObject, FromArgs, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
|
||||
TryFromBorrowedObject, VirtualMachine, atomic_func,
|
||||
builtins::{PyBytes, PyBytesRef, PyInt, PyIntRef, PyTypeRef},
|
||||
byte::{bytes_from_object, value_from_object},
|
||||
convert::ToPyException,
|
||||
@@ -18,8 +19,6 @@ mod mmap {
|
||||
},
|
||||
sliceable::{SaturatedSlice, SequenceIndex, SequenceIndexOp},
|
||||
types::{AsBuffer, AsMapping, AsSequence, Constructor, Representable},
|
||||
AsObject, FromArgs, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
|
||||
TryFromBorrowedObject, VirtualMachine,
|
||||
};
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
use memmap2::{Advice, Mmap, MmapMut, MmapOptions};
|
||||
|
||||
@@ -3,7 +3,7 @@ pub(crate) use _multiprocessing::make_module;
|
||||
#[cfg(windows)]
|
||||
#[pymodule]
|
||||
mod _multiprocessing {
|
||||
use crate::vm::{function::ArgBytesLike, stdlib::os, PyResult, VirtualMachine};
|
||||
use crate::vm::{PyResult, VirtualMachine, function::ArgBytesLike, stdlib::os};
|
||||
use windows_sys::Win32::Networking::WinSock::{self, SOCKET};
|
||||
|
||||
#[pyfunction]
|
||||
|
||||
@@ -6,13 +6,13 @@ mod _overlapped {
|
||||
// straight-forward port of Modules/overlapped.c
|
||||
|
||||
use crate::vm::{
|
||||
Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
builtins::{PyBaseExceptionRef, PyBytesRef, PyTypeRef},
|
||||
common::lock::PyMutex,
|
||||
convert::{ToPyException, ToPyObject},
|
||||
protocol::PyBuffer,
|
||||
stdlib::os::errno_err,
|
||||
types::Constructor,
|
||||
Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
use windows_sys::Win32::{
|
||||
Foundation::{self, GetLastError, HANDLE},
|
||||
|
||||
@@ -28,7 +28,7 @@ mod _posixsubprocess {
|
||||
use rustpython_vm::{AsObject, TryFromBorrowedObject};
|
||||
|
||||
use super::*;
|
||||
use crate::vm::{convert::IntoPyException, PyResult, VirtualMachine};
|
||||
use crate::vm::{PyResult, VirtualMachine, convert::IntoPyException};
|
||||
|
||||
#[pyfunction]
|
||||
fn fork_exec(args: ForkExecArgs, vm: &VirtualMachine) -> PyResult<libc::pid_t> {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
use crate::vm::{builtins::PyModule, extend_module, PyRef, VirtualMachine};
|
||||
use crate::vm::{PyRef, VirtualMachine, builtins::PyModule, extend_module};
|
||||
|
||||
pub fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
|
||||
let module = _pyexpat::make_module(vm);
|
||||
@@ -32,10 +32,10 @@ macro_rules! create_property {
|
||||
#[pymodule(name = "pyexpat")]
|
||||
mod _pyexpat {
|
||||
use crate::vm::{
|
||||
Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine,
|
||||
builtins::{PyStr, PyStrRef, PyType},
|
||||
function::ArgBytesLike,
|
||||
function::{IntoFuncArgs, OptionalArg},
|
||||
Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine,
|
||||
};
|
||||
use rustpython_common::lock::PyRwLock;
|
||||
use std::io::Cursor;
|
||||
|
||||
@@ -10,13 +10,13 @@ pub(crate) use _struct::make_module;
|
||||
#[pymodule]
|
||||
pub(crate) mod _struct {
|
||||
use crate::vm::{
|
||||
buffer::{new_struct_error, struct_error_type, FormatSpec},
|
||||
AsObject, Py, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine,
|
||||
buffer::{FormatSpec, new_struct_error, struct_error_type},
|
||||
builtins::{PyBytes, PyStr, PyStrRef, PyTupleRef, PyTypeRef},
|
||||
function::{ArgBytesLike, ArgMemoryBuffer, PosArgs},
|
||||
match_class,
|
||||
protocol::PyIterReturn,
|
||||
types::{Constructor, IterNext, Iterable, SelfIter},
|
||||
AsObject, Py, PyObjectRef, PyPayload, PyResult, TryFromObject, VirtualMachine,
|
||||
};
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ pub(crate) use _random::make_module;
|
||||
mod _random {
|
||||
use crate::common::lock::PyMutex;
|
||||
use crate::vm::{
|
||||
PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
builtins::{PyInt, PyTupleRef},
|
||||
convert::ToPyException,
|
||||
function::OptionalOption,
|
||||
types::{Constructor, Initializer},
|
||||
PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use malachite_bigint::{BigInt, BigUint, Sign};
|
||||
@@ -75,11 +75,7 @@ mod _random {
|
||||
let mut rng = self.rng.lock();
|
||||
let mut gen_u32 = |k| {
|
||||
let r = rng.next_u32();
|
||||
if k < 32 {
|
||||
r >> (32 - k)
|
||||
} else {
|
||||
r
|
||||
}
|
||||
if k < 32 { r >> (32 - k) } else { r }
|
||||
};
|
||||
|
||||
let words = (k - 1) / 32 + 1;
|
||||
|
||||
@@ -3,10 +3,10 @@ pub(crate) use resource::make_module;
|
||||
#[pymodule]
|
||||
mod resource {
|
||||
use crate::vm::{
|
||||
PyObject, PyObjectRef, PyResult, TryFromBorrowedObject, VirtualMachine,
|
||||
convert::{ToPyException, ToPyObject},
|
||||
stdlib::os,
|
||||
types::PyStructSequence,
|
||||
PyObject, PyObjectRef, PyResult, TryFromBorrowedObject, VirtualMachine,
|
||||
};
|
||||
use std::{io, mem};
|
||||
|
||||
@@ -24,8 +24,8 @@ mod resource {
|
||||
// TODO: RLIMIT_OFILE,
|
||||
#[pyattr]
|
||||
use libc::{
|
||||
RLIMIT_AS, RLIMIT_CORE, RLIMIT_CPU, RLIMIT_DATA, RLIMIT_FSIZE, RLIMIT_MEMLOCK,
|
||||
RLIMIT_NOFILE, RLIMIT_NPROC, RLIMIT_RSS, RLIMIT_STACK, RLIM_INFINITY,
|
||||
RLIM_INFINITY, RLIMIT_AS, RLIMIT_CORE, RLIMIT_CPU, RLIMIT_DATA, RLIMIT_FSIZE,
|
||||
RLIMIT_MEMLOCK, RLIMIT_NOFILE, RLIMIT_NPROC, RLIMIT_RSS, RLIMIT_STACK,
|
||||
};
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
|
||||
|
||||
@@ -5,9 +5,9 @@ mod _scproxy {
|
||||
// straight-forward port of Modules/_scproxy.c
|
||||
|
||||
use crate::vm::{
|
||||
PyResult, VirtualMachine,
|
||||
builtins::{PyDictRef, PyStr},
|
||||
convert::ToPyObject,
|
||||
PyResult, VirtualMachine,
|
||||
};
|
||||
use system_configuration::core_foundation::{
|
||||
array::CFArray,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::vm::{
|
||||
builtins::PyListRef, builtins::PyModule, PyObject, PyObjectRef, PyRef, PyResult, TryFromObject,
|
||||
VirtualMachine,
|
||||
PyObject, PyObjectRef, PyRef, PyResult, TryFromObject, VirtualMachine, builtins::PyListRef,
|
||||
builtins::PyModule,
|
||||
};
|
||||
use std::{io, mem};
|
||||
|
||||
@@ -19,7 +19,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
|
||||
|
||||
#[cfg(unix)]
|
||||
mod platform {
|
||||
pub use libc::{fd_set, select, timeval, FD_ISSET, FD_SET, FD_SETSIZE, FD_ZERO};
|
||||
pub use libc::{FD_ISSET, FD_SET, FD_SETSIZE, FD_ZERO, fd_set, select, timeval};
|
||||
pub use std::os::unix::io::RawFd;
|
||||
|
||||
pub fn check_err(x: i32) -> bool {
|
||||
@@ -30,8 +30,8 @@ mod platform {
|
||||
#[allow(non_snake_case)]
|
||||
#[cfg(windows)]
|
||||
mod platform {
|
||||
pub use WinSock::{FD_SET as fd_set, FD_SETSIZE, SOCKET as RawFd, TIMEVAL as timeval, select};
|
||||
use windows_sys::Win32::Networking::WinSock;
|
||||
pub use WinSock::{select, FD_SET as fd_set, FD_SETSIZE, SOCKET as RawFd, TIMEVAL as timeval};
|
||||
|
||||
// based off winsock2.h: https://gist.github.com/piscisaureus/906386#file-winsock2-h-L128-L141
|
||||
|
||||
@@ -69,7 +69,7 @@ mod platform {
|
||||
|
||||
#[cfg(target_os = "wasi")]
|
||||
mod platform {
|
||||
pub use libc::{timeval, FD_SETSIZE};
|
||||
pub use libc::{FD_SETSIZE, timeval};
|
||||
pub use std::os::wasi::io::RawFd;
|
||||
|
||||
pub fn check_err(x: i32) -> bool {
|
||||
@@ -124,8 +124,8 @@ mod platform {
|
||||
}
|
||||
}
|
||||
|
||||
pub use platform::timeval;
|
||||
use platform::RawFd;
|
||||
pub use platform::timeval;
|
||||
|
||||
#[derive(Traverse)]
|
||||
struct Selectable {
|
||||
@@ -218,11 +218,11 @@ fn sec_to_timeval(sec: f64) -> timeval {
|
||||
mod decl {
|
||||
use super::*;
|
||||
use crate::vm::{
|
||||
PyObjectRef, PyResult, VirtualMachine,
|
||||
builtins::PyTypeRef,
|
||||
convert::ToPyException,
|
||||
function::{Either, OptionalOption},
|
||||
stdlib::time,
|
||||
PyObjectRef, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
#[pyattr]
|
||||
@@ -327,12 +327,12 @@ mod decl {
|
||||
pub(super) mod poll {
|
||||
use super::*;
|
||||
use crate::vm::{
|
||||
AsObject, PyPayload,
|
||||
builtins::PyFloat,
|
||||
common::lock::PyMutex,
|
||||
convert::{IntoPyException, ToPyObject},
|
||||
function::OptionalArg,
|
||||
stdlib::io::Fildes,
|
||||
AsObject, PyPayload,
|
||||
};
|
||||
use libc::pollfd;
|
||||
use num_traits::{Signed, ToPrimitive};
|
||||
@@ -494,8 +494,9 @@ mod decl {
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "redox"))]
|
||||
#[pyattr]
|
||||
use libc::{
|
||||
EPOLLERR, EPOLLEXCLUSIVE, EPOLLHUP, EPOLLIN, EPOLLMSG, EPOLLONESHOT, EPOLLOUT, EPOLLPRI,
|
||||
EPOLLRDBAND, EPOLLRDHUP, EPOLLRDNORM, EPOLLWAKEUP, EPOLLWRBAND, EPOLLWRNORM, EPOLL_CLOEXEC,
|
||||
EPOLL_CLOEXEC, EPOLLERR, EPOLLEXCLUSIVE, EPOLLHUP, EPOLLIN, EPOLLMSG, EPOLLONESHOT,
|
||||
EPOLLOUT, EPOLLPRI, EPOLLRDBAND, EPOLLRDHUP, EPOLLRDNORM, EPOLLWAKEUP, EPOLLWRBAND,
|
||||
EPOLLWRNORM,
|
||||
};
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "redox"))]
|
||||
#[pyattr]
|
||||
@@ -505,13 +506,13 @@ mod decl {
|
||||
pub(super) mod epoll {
|
||||
use super::*;
|
||||
use crate::vm::{
|
||||
PyPayload,
|
||||
builtins::PyTypeRef,
|
||||
common::lock::{PyRwLock, PyRwLockReadGuard},
|
||||
convert::{IntoPyException, ToPyObject},
|
||||
function::OptionalArg,
|
||||
stdlib::io::Fildes,
|
||||
types::Constructor,
|
||||
PyPayload,
|
||||
};
|
||||
use rustix::event::epoll::{self, EventData, EventFlags};
|
||||
use std::ops::Deref;
|
||||
@@ -645,7 +646,7 @@ mod decl {
|
||||
..-1 => {
|
||||
return Err(vm.new_value_error(format!(
|
||||
"maxevents must be greater than 0, got {maxevents}"
|
||||
)))
|
||||
)));
|
||||
}
|
||||
-1 => libc::FD_SETSIZE - 1,
|
||||
_ => maxevents as usize,
|
||||
|
||||
@@ -2,7 +2,7 @@ pub(crate) use _sha1::make_module;
|
||||
|
||||
#[pymodule]
|
||||
mod _sha1 {
|
||||
use crate::hashlib::_hashlib::{local_sha1, HashArgs};
|
||||
use crate::hashlib::_hashlib::{HashArgs, local_sha1};
|
||||
use crate::vm::{PyPayload, PyResult, VirtualMachine};
|
||||
|
||||
#[pyfunction]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::vm::{builtins::PyModule, PyRef, VirtualMachine};
|
||||
use crate::vm::{PyRef, VirtualMachine, builtins::PyModule};
|
||||
|
||||
pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
|
||||
let _ = vm.import("_hashlib", 0);
|
||||
@@ -7,7 +7,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
|
||||
|
||||
#[pymodule]
|
||||
mod _sha256 {
|
||||
use crate::hashlib::_hashlib::{local_sha224, local_sha256, HashArgs};
|
||||
use crate::hashlib::_hashlib::{HashArgs, local_sha224, local_sha256};
|
||||
use crate::vm::{PyPayload, PyResult, VirtualMachine};
|
||||
|
||||
#[pyfunction]
|
||||
|
||||
@@ -3,8 +3,8 @@ pub(crate) use _sha3::make_module;
|
||||
#[pymodule]
|
||||
mod _sha3 {
|
||||
use crate::hashlib::_hashlib::{
|
||||
local_sha3_224, local_sha3_256, local_sha3_384, local_sha3_512, local_shake_128,
|
||||
local_shake_256, HashArgs,
|
||||
HashArgs, local_sha3_224, local_sha3_256, local_sha3_384, local_sha3_512, local_shake_128,
|
||||
local_shake_256,
|
||||
};
|
||||
use crate::vm::{PyPayload, PyResult, VirtualMachine};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::vm::{builtins::PyModule, PyRef, VirtualMachine};
|
||||
use crate::vm::{PyRef, VirtualMachine, builtins::PyModule};
|
||||
|
||||
pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
|
||||
let _ = vm.import("_hashlib", 0);
|
||||
@@ -7,7 +7,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
|
||||
|
||||
#[pymodule]
|
||||
mod _sha512 {
|
||||
use crate::hashlib::_hashlib::{local_sha384, local_sha512, HashArgs};
|
||||
use crate::hashlib::_hashlib::{HashArgs, local_sha384, local_sha512};
|
||||
use crate::vm::{PyPayload, PyResult, VirtualMachine};
|
||||
|
||||
#[pyfunction]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::vm::{builtins::PyModule, PyRef, VirtualMachine};
|
||||
use crate::vm::{PyRef, VirtualMachine, builtins::PyModule};
|
||||
#[cfg(feature = "ssl")]
|
||||
pub(super) use _socket::{sock_select, timeout_error_msg, PySocket, SelectKind};
|
||||
pub(super) use _socket::{PySocket, SelectKind, sock_select, timeout_error_msg};
|
||||
|
||||
pub fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
|
||||
#[cfg(windows)]
|
||||
@@ -12,13 +12,13 @@ pub fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
|
||||
mod _socket {
|
||||
use crate::common::lock::{PyMappedRwLockReadGuard, PyRwLock, PyRwLockReadGuard};
|
||||
use crate::vm::{
|
||||
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
builtins::{PyBaseExceptionRef, PyListRef, PyStrRef, PyTupleRef, PyTypeRef},
|
||||
common::os::ErrorExt,
|
||||
convert::{IntoPyException, ToPyObject, TryFromBorrowedObject, TryFromObject},
|
||||
function::{ArgBytesLike, ArgMemoryBuffer, Either, FsPath, OptionalArg, OptionalOption},
|
||||
types::{Constructor, DefaultConstructor, Initializer, Representable},
|
||||
utils::ToCString,
|
||||
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
use num_traits::ToPrimitive;
|
||||
@@ -40,32 +40,33 @@ mod _socket {
|
||||
INADDR_ANY, INADDR_BROADCAST, INADDR_LOOPBACK, INADDR_NONE,
|
||||
};
|
||||
pub use winapi::um::winsock2::{
|
||||
getprotobyname, getservbyname, getservbyport, getsockopt, setsockopt,
|
||||
SO_EXCLUSIVEADDRUSE,
|
||||
SO_EXCLUSIVEADDRUSE, getprotobyname, getservbyname, getservbyport, getsockopt,
|
||||
setsockopt,
|
||||
};
|
||||
pub use winapi::um::ws2tcpip::{
|
||||
EAI_AGAIN, EAI_BADFLAGS, EAI_FAIL, EAI_FAMILY, EAI_MEMORY, EAI_NODATA, EAI_NONAME,
|
||||
EAI_SERVICE, EAI_SOCKTYPE,
|
||||
};
|
||||
pub use windows_sys::Win32::Networking::WinSock::{
|
||||
AF_DECnet, AF_APPLETALK, AF_IPX, AF_LINK, AI_ADDRCONFIG, AI_ALL, AI_CANONNAME,
|
||||
AI_NUMERICSERV, AI_V4MAPPED, IPPORT_RESERVED, IPPROTO_AH, IPPROTO_DSTOPTS, IPPROTO_EGP,
|
||||
IPPROTO_ESP, IPPROTO_FRAGMENT, IPPROTO_GGP, IPPROTO_HOPOPTS, IPPROTO_ICMP,
|
||||
IPPROTO_ICMPV6, IPPROTO_IDP, IPPROTO_IGMP, IPPROTO_IP, IPPROTO_IP as IPPROTO_IPIP,
|
||||
IPPROTO_IPV4, IPPROTO_IPV6, IPPROTO_ND, IPPROTO_NONE, IPPROTO_PIM, IPPROTO_PUP,
|
||||
IPPROTO_RAW, IPPROTO_ROUTING, IPPROTO_TCP, IPPROTO_UDP, IPV6_CHECKSUM, IPV6_DONTFRAG,
|
||||
IPV6_HOPLIMIT, IPV6_HOPOPTS, IPV6_JOIN_GROUP, IPV6_LEAVE_GROUP, IPV6_MULTICAST_HOPS,
|
||||
AF_APPLETALK, AF_DECnet, AF_IPX, AF_LINK, AI_ADDRCONFIG, AI_ALL, AI_CANONNAME,
|
||||
AI_NUMERICSERV, AI_V4MAPPED, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_HDRINCL,
|
||||
IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_OPTIONS, IP_RECVDSTADDR,
|
||||
IP_TOS, IP_TTL, IPPORT_RESERVED, IPPROTO_AH, IPPROTO_DSTOPTS, IPPROTO_EGP, IPPROTO_ESP,
|
||||
IPPROTO_FRAGMENT, IPPROTO_GGP, IPPROTO_HOPOPTS, IPPROTO_ICMP, IPPROTO_ICMPV6,
|
||||
IPPROTO_IDP, IPPROTO_IGMP, IPPROTO_IP, IPPROTO_IP as IPPROTO_IPIP, IPPROTO_IPV4,
|
||||
IPPROTO_IPV6, IPPROTO_ND, IPPROTO_NONE, IPPROTO_PIM, IPPROTO_PUP, IPPROTO_RAW,
|
||||
IPPROTO_ROUTING, IPPROTO_TCP, IPPROTO_UDP, IPV6_CHECKSUM, IPV6_DONTFRAG, IPV6_HOPLIMIT,
|
||||
IPV6_HOPOPTS, IPV6_JOIN_GROUP, IPV6_LEAVE_GROUP, IPV6_MULTICAST_HOPS,
|
||||
IPV6_MULTICAST_IF, IPV6_MULTICAST_LOOP, IPV6_PKTINFO, IPV6_RECVRTHDR, IPV6_RECVTCLASS,
|
||||
IPV6_RTHDR, IPV6_TCLASS, IPV6_UNICAST_HOPS, IPV6_V6ONLY, IP_ADD_MEMBERSHIP,
|
||||
IP_DROP_MEMBERSHIP, IP_HDRINCL, IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL,
|
||||
IP_OPTIONS, IP_RECVDSTADDR, IP_TOS, IP_TTL, MSG_BCAST, MSG_CTRUNC, MSG_DONTROUTE,
|
||||
MSG_MCAST, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL, NI_DGRAM, NI_MAXHOST, NI_MAXSERV,
|
||||
NI_NAMEREQD, NI_NOFQDN, NI_NUMERICHOST, NI_NUMERICSERV, RCVALL_IPLEVEL, RCVALL_OFF,
|
||||
RCVALL_ON, RCVALL_SOCKETLEVELONLY, SD_BOTH as SHUT_RDWR, SD_RECEIVE as SHUT_RD,
|
||||
SD_SEND as SHUT_WR, SIO_KEEPALIVE_VALS, SIO_LOOPBACK_FAST_PATH, SIO_RCVALL, SOCK_DGRAM,
|
||||
SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET, SOCK_STREAM, SOL_SOCKET, SOMAXCONN, SO_BROADCAST,
|
||||
SO_ERROR, SO_LINGER, SO_OOBINLINE, SO_REUSEADDR, SO_TYPE, SO_USELOOPBACK, TCP_NODELAY,
|
||||
WSAEBADF, WSAECONNRESET, WSAENOTSOCK, WSAEWOULDBLOCK,
|
||||
IPV6_RTHDR, IPV6_TCLASS, IPV6_UNICAST_HOPS, IPV6_V6ONLY, MSG_BCAST, MSG_CTRUNC,
|
||||
MSG_DONTROUTE, MSG_MCAST, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL, NI_DGRAM,
|
||||
NI_MAXHOST, NI_MAXSERV, NI_NAMEREQD, NI_NOFQDN, NI_NUMERICHOST, NI_NUMERICSERV,
|
||||
RCVALL_IPLEVEL, RCVALL_OFF, RCVALL_ON, RCVALL_SOCKETLEVELONLY, SD_BOTH as SHUT_RDWR,
|
||||
SD_RECEIVE as SHUT_RD, SD_SEND as SHUT_WR, SIO_KEEPALIVE_VALS, SIO_LOOPBACK_FAST_PATH,
|
||||
SIO_RCVALL, SO_BROADCAST, SO_ERROR, SO_LINGER, SO_OOBINLINE, SO_REUSEADDR, SO_TYPE,
|
||||
SO_USELOOPBACK, SOCK_DGRAM, SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET, SOCK_STREAM,
|
||||
SOL_SOCKET, SOMAXCONN, TCP_NODELAY, WSAEBADF, WSAECONNRESET, WSAENOTSOCK,
|
||||
WSAEWOULDBLOCK,
|
||||
};
|
||||
pub const IF_NAMESIZE: usize =
|
||||
windows_sys::Win32::NetworkManagement::Ndis::IF_MAX_STRING_SIZE as _;
|
||||
@@ -86,14 +87,14 @@ mod _socket {
|
||||
IPPROTO_ICMPV6, IPPROTO_IP, IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_TCP as SOL_TCP, IPPROTO_UDP,
|
||||
MSG_CTRUNC, MSG_DONTROUTE, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL, NI_DGRAM, NI_MAXHOST,
|
||||
NI_NAMEREQD, NI_NOFQDN, NI_NUMERICHOST, NI_NUMERICSERV, SHUT_RD, SHUT_RDWR, SHUT_WR,
|
||||
SOCK_DGRAM, SOCK_STREAM, SOL_SOCKET, SO_BROADCAST, SO_ERROR, SO_LINGER, SO_OOBINLINE,
|
||||
SO_REUSEADDR, SO_TYPE, TCP_NODELAY,
|
||||
SO_BROADCAST, SO_ERROR, SO_LINGER, SO_OOBINLINE, SO_REUSEADDR, SO_TYPE, SOCK_DGRAM,
|
||||
SOCK_STREAM, SOL_SOCKET, TCP_NODELAY,
|
||||
};
|
||||
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
#[pyattr]
|
||||
use c::{
|
||||
AF_DECnet, AF_APPLETALK, AF_IPX, IPPROTO_AH, IPPROTO_DSTOPTS, IPPROTO_EGP, IPPROTO_ESP,
|
||||
AF_APPLETALK, AF_DECnet, AF_IPX, IPPROTO_AH, IPPROTO_DSTOPTS, IPPROTO_EGP, IPPROTO_ESP,
|
||||
IPPROTO_FRAGMENT, IPPROTO_HOPOPTS, IPPROTO_IDP, IPPROTO_IGMP, IPPROTO_IPIP, IPPROTO_NONE,
|
||||
IPPROTO_PIM, IPPROTO_PUP, IPPROTO_RAW, IPPROTO_ROUTING,
|
||||
};
|
||||
@@ -126,8 +127,9 @@ mod _socket {
|
||||
J1939_IDLE_ADDR, J1939_MAX_UNICAST_ADDR, J1939_NLA_BYTES_ACKED, J1939_NLA_PAD,
|
||||
J1939_NO_ADDR, J1939_NO_NAME, J1939_NO_PGN, J1939_PGN_ADDRESS_CLAIMED,
|
||||
J1939_PGN_ADDRESS_COMMANDED, J1939_PGN_MAX, J1939_PGN_PDU1_MAX, J1939_PGN_REQUEST,
|
||||
SCM_J1939_DEST_ADDR, SCM_J1939_DEST_NAME, SCM_J1939_ERRQUEUE, SCM_J1939_PRIO, SOL_CAN_BASE,
|
||||
SOL_CAN_RAW, SO_J1939_ERRQUEUE, SO_J1939_FILTER, SO_J1939_PROMISC, SO_J1939_SEND_PRIO,
|
||||
SCM_J1939_DEST_ADDR, SCM_J1939_DEST_NAME, SCM_J1939_ERRQUEUE, SCM_J1939_PRIO,
|
||||
SO_J1939_ERRQUEUE, SO_J1939_FILTER, SO_J1939_PROMISC, SO_J1939_SEND_PRIO, SOL_CAN_BASE,
|
||||
SOL_CAN_RAW,
|
||||
};
|
||||
|
||||
#[cfg(all(target_os = "linux", target_env = "gnu"))]
|
||||
@@ -168,11 +170,11 @@ mod _socket {
|
||||
#[pyattr]
|
||||
use c::{
|
||||
ALG_OP_DECRYPT, ALG_OP_ENCRYPT, ALG_SET_AEAD_ASSOCLEN, ALG_SET_AEAD_AUTHSIZE, ALG_SET_IV,
|
||||
ALG_SET_KEY, ALG_SET_OP, IPV6_DSTOPTS, IPV6_NEXTHOP, IPV6_PATHMTU, IPV6_RECVDSTOPTS,
|
||||
IPV6_RECVHOPLIMIT, IPV6_RECVHOPOPTS, IPV6_RECVPATHMTU, IPV6_RTHDRDSTOPTS,
|
||||
IP_DEFAULT_MULTICAST_LOOP, IP_RECVOPTS, IP_RETOPTS, NETLINK_CRYPTO, NETLINK_DNRTMSG,
|
||||
NETLINK_FIREWALL, NETLINK_IP6_FW, NETLINK_NFLOG, NETLINK_ROUTE, NETLINK_USERSOCK,
|
||||
NETLINK_XFRM, SOL_ALG, SO_PASSSEC, SO_PEERSEC,
|
||||
ALG_SET_KEY, ALG_SET_OP, IP_DEFAULT_MULTICAST_LOOP, IP_RECVOPTS, IP_RETOPTS, IPV6_DSTOPTS,
|
||||
IPV6_NEXTHOP, IPV6_PATHMTU, IPV6_RECVDSTOPTS, IPV6_RECVHOPLIMIT, IPV6_RECVHOPOPTS,
|
||||
IPV6_RECVPATHMTU, IPV6_RTHDRDSTOPTS, NETLINK_CRYPTO, NETLINK_DNRTMSG, NETLINK_FIREWALL,
|
||||
NETLINK_IP6_FW, NETLINK_NFLOG, NETLINK_ROUTE, NETLINK_USERSOCK, NETLINK_XFRM, SO_PASSSEC,
|
||||
SO_PEERSEC, SOL_ALG,
|
||||
};
|
||||
|
||||
#[cfg(any(target_os = "android", target_vendor = "apple"))]
|
||||
@@ -190,9 +192,9 @@ mod _socket {
|
||||
#[cfg(any(unix, target_os = "android", windows))]
|
||||
#[pyattr]
|
||||
use c::{
|
||||
INADDR_BROADCAST, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF, IPV6_MULTICAST_LOOP,
|
||||
IPV6_UNICAST_HOPS, IPV6_V6ONLY, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_IF,
|
||||
IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_TTL,
|
||||
INADDR_BROADCAST, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_IF,
|
||||
IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_TTL, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF,
|
||||
IPV6_MULTICAST_LOOP, IPV6_UNICAST_HOPS, IPV6_V6ONLY,
|
||||
};
|
||||
|
||||
#[cfg(any(unix, target_os = "android", windows))]
|
||||
@@ -213,8 +215,8 @@ mod _socket {
|
||||
AF_ALG, AF_ASH, AF_ATMPVC, AF_ATMSVC, AF_AX25, AF_BRIDGE, AF_CAN, AF_ECONET, AF_IRDA,
|
||||
AF_LLC, AF_NETBEUI, AF_NETLINK, AF_NETROM, AF_PACKET, AF_PPPOX, AF_RDS, AF_SECURITY,
|
||||
AF_TIPC, AF_VSOCK, AF_WANPIPE, AF_X25, IP_TRANSPARENT, MSG_CONFIRM, MSG_ERRQUEUE,
|
||||
MSG_FASTOPEN, MSG_MORE, PF_CAN, PF_PACKET, PF_RDS, SCM_CREDENTIALS, SOL_IP, SOL_TIPC,
|
||||
SOL_UDP, SO_BINDTODEVICE, SO_MARK, TCP_CORK, TCP_DEFER_ACCEPT, TCP_LINGER2, TCP_QUICKACK,
|
||||
MSG_FASTOPEN, MSG_MORE, PF_CAN, PF_PACKET, PF_RDS, SCM_CREDENTIALS, SO_BINDTODEVICE,
|
||||
SO_MARK, SOL_IP, SOL_TIPC, SOL_UDP, TCP_CORK, TCP_DEFER_ACCEPT, TCP_LINGER2, TCP_QUICKACK,
|
||||
TCP_SYNCNT, TCP_WINDOW_CLAMP,
|
||||
};
|
||||
|
||||
@@ -271,7 +273,7 @@ mod _socket {
|
||||
|
||||
#[cfg(any(target_os = "android", target_os = "linux", windows))]
|
||||
#[pyattr]
|
||||
use c::{IPV6_HOPOPTS, IPV6_RECVRTHDR, IPV6_RTHDR, IP_OPTIONS};
|
||||
use c::{IP_OPTIONS, IPV6_HOPOPTS, IPV6_RECVRTHDR, IPV6_RTHDR};
|
||||
|
||||
#[cfg(any(
|
||||
target_os = "dragonfly",
|
||||
@@ -525,7 +527,7 @@ mod _socket {
|
||||
))]
|
||||
#[pyattr]
|
||||
use c::{
|
||||
AF_LINK, IPPROTO_GGP, IPV6_JOIN_GROUP, IPV6_LEAVE_GROUP, IP_RECVDSTADDR, SO_USELOOPBACK,
|
||||
AF_LINK, IP_RECVDSTADDR, IPPROTO_GGP, IPV6_JOIN_GROUP, IPV6_LEAVE_GROUP, SO_USELOOPBACK,
|
||||
};
|
||||
|
||||
#[cfg(any(
|
||||
@@ -633,7 +635,7 @@ mod _socket {
|
||||
#[pyattr]
|
||||
use c::{
|
||||
EAI_AGAIN, EAI_BADFLAGS, EAI_FAIL, EAI_FAMILY, EAI_MEMORY, EAI_NONAME, EAI_SERVICE,
|
||||
EAI_SOCKTYPE, IPV6_RECVTCLASS, IPV6_TCLASS, IP_HDRINCL, IP_TOS, SOMAXCONN,
|
||||
EAI_SOCKTYPE, IP_HDRINCL, IP_TOS, IPV6_RECVTCLASS, IPV6_TCLASS, SOMAXCONN,
|
||||
};
|
||||
|
||||
#[cfg(not(any(
|
||||
@@ -1473,11 +1475,7 @@ mod _socket {
|
||||
#[pymethod]
|
||||
fn gettimeout(&self) -> Option<f64> {
|
||||
let timeout = self.timeout.load();
|
||||
if timeout >= 0.0 {
|
||||
Some(timeout)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if timeout >= 0.0 { Some(timeout) } else { None }
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
@@ -1601,7 +1599,7 @@ mod _socket {
|
||||
_ => {
|
||||
return Err(vm
|
||||
.new_value_error("`how` must be SHUT_RD, SHUT_WR, or SHUT_RDWR".to_owned())
|
||||
.into())
|
||||
.into());
|
||||
}
|
||||
};
|
||||
Ok(self.sock()?.shutdown(how)?)
|
||||
@@ -2054,7 +2052,7 @@ mod _socket {
|
||||
_ => {
|
||||
return Err(vm
|
||||
.new_type_error("illegal sockaddr argument".to_owned())
|
||||
.into())
|
||||
.into());
|
||||
}
|
||||
}
|
||||
let (addr, flowinfo, scopeid) = Address::from_tuple_ipv6(&address, vm)?;
|
||||
@@ -2259,7 +2257,7 @@ mod _socket {
|
||||
_ => {
|
||||
return Err(vm
|
||||
.new_os_error("address family mismatched".to_owned())
|
||||
.into())
|
||||
.into());
|
||||
}
|
||||
}
|
||||
return Ok(SocketAddr::V4(net::SocketAddrV4::new(
|
||||
@@ -2433,11 +2431,7 @@ mod _socket {
|
||||
#[pyfunction]
|
||||
fn getdefaulttimeout() -> Option<f64> {
|
||||
let timeout = DEFAULT_TIMEOUT.load();
|
||||
if timeout >= 0.0 {
|
||||
Some(timeout)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if timeout >= 0.0 { Some(timeout) } else { None }
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// spell-checker:ignore cantlock commithook foreignkey notnull primarykey gettemppath autoindex convpath
|
||||
// spell-checker:ignore dbmoved vnode nbytes
|
||||
|
||||
use rustpython_vm::{builtins::PyModule, AsObject, PyRef, VirtualMachine};
|
||||
use rustpython_vm::{AsObject, PyRef, VirtualMachine, builtins::PyModule};
|
||||
|
||||
// pub(crate) use _sqlite::make_module;
|
||||
pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
|
||||
@@ -21,29 +21,29 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
|
||||
#[pymodule]
|
||||
mod _sqlite {
|
||||
use libsqlite3_sys::{
|
||||
sqlite3, sqlite3_aggregate_context, sqlite3_backup_finish, sqlite3_backup_init,
|
||||
sqlite3_backup_pagecount, sqlite3_backup_remaining, sqlite3_backup_step, sqlite3_bind_blob,
|
||||
sqlite3_bind_double, sqlite3_bind_int64, sqlite3_bind_null, sqlite3_bind_parameter_count,
|
||||
sqlite3_bind_parameter_name, sqlite3_bind_text, sqlite3_blob, sqlite3_blob_bytes,
|
||||
sqlite3_blob_close, sqlite3_blob_open, sqlite3_blob_read, sqlite3_blob_write,
|
||||
sqlite3_busy_timeout, sqlite3_changes, sqlite3_close_v2, sqlite3_column_blob,
|
||||
sqlite3_column_bytes, sqlite3_column_count, sqlite3_column_decltype, sqlite3_column_double,
|
||||
sqlite3_column_int64, sqlite3_column_name, sqlite3_column_text, sqlite3_column_type,
|
||||
sqlite3_complete, sqlite3_context, sqlite3_context_db_handle, sqlite3_create_collation_v2,
|
||||
sqlite3_create_function_v2, sqlite3_create_window_function, sqlite3_data_count,
|
||||
sqlite3_db_handle, sqlite3_errcode, sqlite3_errmsg, sqlite3_exec, sqlite3_expanded_sql,
|
||||
sqlite3_extended_errcode, sqlite3_finalize, sqlite3_get_autocommit, sqlite3_interrupt,
|
||||
sqlite3_last_insert_rowid, sqlite3_libversion, sqlite3_limit, sqlite3_open_v2,
|
||||
sqlite3_prepare_v2, sqlite3_progress_handler, sqlite3_reset, sqlite3_result_blob,
|
||||
sqlite3_result_double, sqlite3_result_error, sqlite3_result_error_nomem,
|
||||
sqlite3_result_error_toobig, sqlite3_result_int64, sqlite3_result_null,
|
||||
sqlite3_result_text, sqlite3_set_authorizer, sqlite3_sleep, sqlite3_step, sqlite3_stmt,
|
||||
sqlite3_stmt_busy, sqlite3_stmt_readonly, sqlite3_threadsafe, sqlite3_total_changes,
|
||||
sqlite3_trace_v2, sqlite3_user_data, sqlite3_value, sqlite3_value_blob,
|
||||
sqlite3_value_bytes, sqlite3_value_double, sqlite3_value_int64, sqlite3_value_text,
|
||||
sqlite3_value_type, SQLITE_BLOB, SQLITE_DETERMINISTIC, SQLITE_FLOAT, SQLITE_INTEGER,
|
||||
SQLITE_NULL, SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE, SQLITE_OPEN_URI, SQLITE_TEXT,
|
||||
SQLITE_TRACE_STMT, SQLITE_TRANSIENT, SQLITE_UTF8,
|
||||
SQLITE_BLOB, SQLITE_DETERMINISTIC, SQLITE_FLOAT, SQLITE_INTEGER, SQLITE_NULL,
|
||||
SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE, SQLITE_OPEN_URI, SQLITE_TEXT, SQLITE_TRACE_STMT,
|
||||
SQLITE_TRANSIENT, SQLITE_UTF8, sqlite3, sqlite3_aggregate_context, sqlite3_backup_finish,
|
||||
sqlite3_backup_init, sqlite3_backup_pagecount, sqlite3_backup_remaining,
|
||||
sqlite3_backup_step, sqlite3_bind_blob, sqlite3_bind_double, sqlite3_bind_int64,
|
||||
sqlite3_bind_null, sqlite3_bind_parameter_count, sqlite3_bind_parameter_name,
|
||||
sqlite3_bind_text, sqlite3_blob, sqlite3_blob_bytes, sqlite3_blob_close, sqlite3_blob_open,
|
||||
sqlite3_blob_read, sqlite3_blob_write, sqlite3_busy_timeout, sqlite3_changes,
|
||||
sqlite3_close_v2, sqlite3_column_blob, sqlite3_column_bytes, sqlite3_column_count,
|
||||
sqlite3_column_decltype, sqlite3_column_double, sqlite3_column_int64, sqlite3_column_name,
|
||||
sqlite3_column_text, sqlite3_column_type, sqlite3_complete, sqlite3_context,
|
||||
sqlite3_context_db_handle, sqlite3_create_collation_v2, sqlite3_create_function_v2,
|
||||
sqlite3_create_window_function, sqlite3_data_count, sqlite3_db_handle, sqlite3_errcode,
|
||||
sqlite3_errmsg, sqlite3_exec, sqlite3_expanded_sql, sqlite3_extended_errcode,
|
||||
sqlite3_finalize, sqlite3_get_autocommit, sqlite3_interrupt, sqlite3_last_insert_rowid,
|
||||
sqlite3_libversion, sqlite3_limit, sqlite3_open_v2, sqlite3_prepare_v2,
|
||||
sqlite3_progress_handler, sqlite3_reset, sqlite3_result_blob, sqlite3_result_double,
|
||||
sqlite3_result_error, sqlite3_result_error_nomem, sqlite3_result_error_toobig,
|
||||
sqlite3_result_int64, sqlite3_result_null, sqlite3_result_text, sqlite3_set_authorizer,
|
||||
sqlite3_sleep, sqlite3_step, sqlite3_stmt, sqlite3_stmt_busy, sqlite3_stmt_readonly,
|
||||
sqlite3_threadsafe, sqlite3_total_changes, sqlite3_trace_v2, sqlite3_user_data,
|
||||
sqlite3_value, sqlite3_value_blob, sqlite3_value_bytes, sqlite3_value_double,
|
||||
sqlite3_value_int64, sqlite3_value_text, sqlite3_value_type,
|
||||
};
|
||||
use malachite_bigint::Sign;
|
||||
use rustpython_common::{
|
||||
@@ -53,13 +53,16 @@ mod _sqlite {
|
||||
static_cell,
|
||||
};
|
||||
use rustpython_vm::{
|
||||
atomic_func,
|
||||
__exports::paste,
|
||||
AsObject, Py, PyAtomicRef, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
|
||||
TryFromBorrowedObject, VirtualMachine, atomic_func,
|
||||
builtins::{
|
||||
PyBaseException, PyBaseExceptionRef, PyByteArray, PyBytes, PyDict, PyDictRef, PyFloat,
|
||||
PyInt, PyIntRef, PySlice, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef,
|
||||
},
|
||||
convert::IntoObject,
|
||||
function::{ArgCallable, ArgIterable, FsPath, FuncArgs, OptionalArg, PyComparisonValue},
|
||||
object::{Traverse, TraverseFn},
|
||||
protocol::{PyBuffer, PyIterReturn, PyMappingMethods, PySequence, PySequenceMethods},
|
||||
sliceable::{SaturatedSliceIter, SliceableSequenceOp},
|
||||
types::{
|
||||
@@ -67,16 +70,12 @@ mod _sqlite {
|
||||
PyComparisonOp, SelfIter,
|
||||
},
|
||||
utils::ToCString,
|
||||
AsObject, Py, PyAtomicRef, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
|
||||
TryFromBorrowedObject, VirtualMachine,
|
||||
__exports::paste,
|
||||
object::{Traverse, TraverseFn},
|
||||
};
|
||||
use std::{
|
||||
ffi::{c_int, c_longlong, c_uint, c_void, CStr},
|
||||
ffi::{CStr, c_int, c_longlong, c_uint, c_void},
|
||||
fmt::Debug,
|
||||
ops::Deref,
|
||||
ptr::{null, null_mut, NonNull},
|
||||
ptr::{NonNull, null, null_mut},
|
||||
thread::ThreadId,
|
||||
};
|
||||
|
||||
@@ -445,7 +444,7 @@ mod _sqlite {
|
||||
vm,
|
||||
exc,
|
||||
"user-defined aggregate's '__init__' method raised error\0",
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2082,7 +2081,7 @@ mod _sqlite {
|
||||
_ => {
|
||||
return Err(vm.new_value_error(
|
||||
"'origin' should be os.SEEK_SET, os.SEEK_CUR, or os.SEEK_END".to_owned(),
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::vm::{builtins::PyModule, PyRef, VirtualMachine};
|
||||
use crate::vm::{PyRef, VirtualMachine, builtins::PyModule};
|
||||
use openssl_probe::ProbeResult;
|
||||
|
||||
pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
|
||||
@@ -36,6 +36,7 @@ mod _ssl {
|
||||
},
|
||||
socket::{self, PySocket},
|
||||
vm::{
|
||||
PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
builtins::{PyBaseExceptionRef, PyStrRef, PyType, PyTypeRef, PyWeak},
|
||||
convert::{ToPyException, ToPyObject},
|
||||
exceptions,
|
||||
@@ -45,7 +46,6 @@ mod _ssl {
|
||||
},
|
||||
types::Constructor,
|
||||
utils::ToCString,
|
||||
PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
},
|
||||
};
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
@@ -55,7 +55,7 @@ mod _ssl {
|
||||
error::ErrorStack,
|
||||
nid::Nid,
|
||||
ssl::{self, SslContextBuilder, SslOptions, SslVerifyMode},
|
||||
x509::{self, X509Ref, X509},
|
||||
x509::{self, X509, X509Ref},
|
||||
};
|
||||
use openssl_sys as sys;
|
||||
use rustpython_vm::ospath::OsPath;
|
||||
@@ -70,9 +70,6 @@ mod _ssl {
|
||||
// Constants
|
||||
#[pyattr]
|
||||
use sys::{
|
||||
SSL_OP_NO_SSLv2 as OP_NO_SSLv2,
|
||||
SSL_OP_NO_SSLv3 as OP_NO_SSLv3,
|
||||
SSL_OP_NO_TLSv1 as OP_NO_TLSv1,
|
||||
// TODO: so many more of these
|
||||
SSL_AD_DECODE_ERROR as ALERT_DESCRIPTION_DECODE_ERROR,
|
||||
SSL_AD_ILLEGAL_PARAMETER as ALERT_DESCRIPTION_ILLEGAL_PARAMETER,
|
||||
@@ -92,7 +89,10 @@ mod _ssl {
|
||||
// X509_V_FLAG_X509_STRICT as VERIFY_X509_STRICT,
|
||||
SSL_ERROR_ZERO_RETURN,
|
||||
SSL_OP_CIPHER_SERVER_PREFERENCE as OP_CIPHER_SERVER_PREFERENCE,
|
||||
SSL_OP_NO_SSLv2 as OP_NO_SSLv2,
|
||||
SSL_OP_NO_SSLv3 as OP_NO_SSLv3,
|
||||
SSL_OP_NO_TICKET as OP_NO_TICKET,
|
||||
SSL_OP_NO_TLSv1 as OP_NO_TLSv1,
|
||||
SSL_OP_SINGLE_DH_USE as OP_SINGLE_DH_USE,
|
||||
};
|
||||
|
||||
@@ -601,7 +601,7 @@ mod _ssl {
|
||||
return Err(vm.new_value_error(
|
||||
"Cannot set verify_mode to CERT_NONE when check_hostname is enabled."
|
||||
.to_owned(),
|
||||
))
|
||||
));
|
||||
}
|
||||
CertRequirements::None => SslVerifyMode::NONE,
|
||||
CertRequirements::Optional => SslVerifyMode::PEER,
|
||||
@@ -1006,11 +1006,7 @@ mod _ssl {
|
||||
#[pymethod]
|
||||
fn version(&self) -> Option<&'static str> {
|
||||
let v = self.stream.read().ssl().version_str();
|
||||
if v == "unknown" {
|
||||
None
|
||||
} else {
|
||||
Some(v)
|
||||
}
|
||||
if v == "unknown" { None } else { Some(v) }
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
@@ -1058,7 +1054,7 @@ mod _ssl {
|
||||
return Err(socket::timeout_error_msg(
|
||||
vm,
|
||||
"The handshake operation timed out".to_owned(),
|
||||
))
|
||||
));
|
||||
}
|
||||
SelectRet::Closed => return Err(socket_closed_error(vm)),
|
||||
SelectRet::Nonblocking => {}
|
||||
@@ -1084,7 +1080,7 @@ mod _ssl {
|
||||
return Err(socket::timeout_error_msg(
|
||||
vm,
|
||||
"The write operation timed out".to_owned(),
|
||||
))
|
||||
));
|
||||
}
|
||||
SelectRet::Closed => return Err(socket_closed_error(vm)),
|
||||
_ => {}
|
||||
@@ -1100,7 +1096,7 @@ mod _ssl {
|
||||
return Err(socket::timeout_error_msg(
|
||||
vm,
|
||||
"The write operation timed out".to_owned(),
|
||||
))
|
||||
));
|
||||
}
|
||||
SelectRet::Closed => return Err(socket_closed_error(vm)),
|
||||
SelectRet::Nonblocking => {}
|
||||
@@ -1152,7 +1148,7 @@ mod _ssl {
|
||||
return Err(socket::timeout_error_msg(
|
||||
vm,
|
||||
"The read operation timed out".to_owned(),
|
||||
))
|
||||
));
|
||||
}
|
||||
SelectRet::Nonblocking => {}
|
||||
_ => {
|
||||
@@ -1385,13 +1381,13 @@ mod _ssl {
|
||||
#[cfg(target_os = "android")]
|
||||
mod android {
|
||||
use super::convert_openssl_error;
|
||||
use crate::vm::{builtins::PyBaseExceptionRef, VirtualMachine};
|
||||
use crate::vm::{VirtualMachine, builtins::PyBaseExceptionRef};
|
||||
use openssl::{
|
||||
ssl::SslContextBuilder,
|
||||
x509::{store::X509StoreBuilder, X509},
|
||||
x509::{X509, store::X509StoreBuilder},
|
||||
};
|
||||
use std::{
|
||||
fs::{read_dir, File},
|
||||
fs::{File, read_dir},
|
||||
io::Read,
|
||||
path::Path,
|
||||
};
|
||||
@@ -1465,8 +1461,8 @@ mod windows {}
|
||||
mod ossl101 {
|
||||
#[pyattr]
|
||||
use openssl_sys::{
|
||||
SSL_OP_NO_TLSv1_1 as OP_NO_TLSv1_1, SSL_OP_NO_TLSv1_2 as OP_NO_TLSv1_2,
|
||||
SSL_OP_NO_COMPRESSION as OP_NO_COMPRESSION,
|
||||
SSL_OP_NO_COMPRESSION as OP_NO_COMPRESSION, SSL_OP_NO_TLSv1_1 as OP_NO_TLSv1_1,
|
||||
SSL_OP_NO_TLSv1_2 as OP_NO_TLSv1_2,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1484,15 +1480,15 @@ mod windows {
|
||||
use crate::{
|
||||
common::ascii,
|
||||
vm::{
|
||||
PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
builtins::{PyFrozenSet, PyStrRef},
|
||||
convert::ToPyException,
|
||||
PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
},
|
||||
};
|
||||
|
||||
#[pyfunction]
|
||||
fn enum_certificates(store_name: PyStrRef, vm: &VirtualMachine) -> PyResult<Vec<PyObjectRef>> {
|
||||
use schannel::{cert_context::ValidUses, cert_store::CertStore, RawPointer};
|
||||
use schannel::{RawPointer, cert_context::ValidUses, cert_store::CertStore};
|
||||
use windows_sys::Win32::Security::Cryptography;
|
||||
|
||||
// TODO: check every store for it, not just 2 of them:
|
||||
|
||||
@@ -2,7 +2,7 @@ pub(crate) use _statistics::make_module;
|
||||
|
||||
#[pymodule]
|
||||
mod _statistics {
|
||||
use crate::vm::{function::ArgIntoFloat, PyResult, VirtualMachine};
|
||||
use crate::vm::{PyResult, VirtualMachine, function::ArgIntoFloat};
|
||||
|
||||
// See https://github.com/python/cpython/blob/6846d6712a0894f8e1a91716c11dd79f42864216/Modules/_statisticsmodule.c#L28-L120
|
||||
#[allow(clippy::excessive_precision)]
|
||||
|
||||
@@ -6,10 +6,10 @@ pub(crate) use syslog::make_module;
|
||||
mod syslog {
|
||||
use crate::common::lock::PyRwLock;
|
||||
use crate::vm::{
|
||||
PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
builtins::{PyStr, PyStrRef},
|
||||
function::{OptionalArg, OptionalOption},
|
||||
utils::ToCString,
|
||||
PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
use std::{ffi::CStr, os::raw::c_char};
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ pub(crate) use self::termios::make_module;
|
||||
#[pymodule]
|
||||
mod termios {
|
||||
use crate::vm::{
|
||||
PyObjectRef, PyResult, TryFromObject, VirtualMachine,
|
||||
builtins::{PyBaseExceptionRef, PyBytes, PyInt, PyListRef, PyTypeRef},
|
||||
common::os::ErrorExt,
|
||||
convert::ToPyObject,
|
||||
PyObjectRef, PyResult, TryFromObject, VirtualMachine,
|
||||
};
|
||||
use termios::Termios;
|
||||
|
||||
@@ -55,9 +55,9 @@ mod termios {
|
||||
))]
|
||||
#[pyattr]
|
||||
use libc::{
|
||||
FIONCLEX, FIONREAD, TIOCEXCL, TIOCMBIC, TIOCMBIS, TIOCMGET, TIOCMSET, TIOCM_CAR, TIOCM_CD,
|
||||
TIOCM_CTS, TIOCM_DSR, TIOCM_DTR, TIOCM_LE, TIOCM_RI, TIOCM_RNG, TIOCM_RTS, TIOCM_SR,
|
||||
TIOCM_ST, TIOCNXCL, TIOCSCTTY,
|
||||
FIONCLEX, FIONREAD, TIOCEXCL, TIOCM_CAR, TIOCM_CD, TIOCM_CTS, TIOCM_DSR, TIOCM_DTR,
|
||||
TIOCM_LE, TIOCM_RI, TIOCM_RNG, TIOCM_RTS, TIOCM_SR, TIOCM_ST, TIOCMBIC, TIOCMBIS, TIOCMGET,
|
||||
TIOCMSET, TIOCNXCL, TIOCSCTTY,
|
||||
};
|
||||
#[cfg(any(target_os = "android", target_os = "linux"))]
|
||||
#[pyattr]
|
||||
@@ -100,12 +100,6 @@ mod termios {
|
||||
))]
|
||||
#[pyattr]
|
||||
use termios::os::target::TCSASOFT;
|
||||
#[cfg(any(target_os = "android", target_os = "linux"))]
|
||||
#[pyattr]
|
||||
use termios::os::target::{
|
||||
B1000000, B1152000, B1500000, B2000000, B2500000, B3000000, B3500000, B4000000, B500000,
|
||||
B576000, CBAUDEX,
|
||||
};
|
||||
#[cfg(any(
|
||||
target_os = "android",
|
||||
target_os = "freebsd",
|
||||
@@ -116,6 +110,12 @@ mod termios {
|
||||
))]
|
||||
#[pyattr]
|
||||
use termios::os::target::{B460800, B921600};
|
||||
#[cfg(any(target_os = "android", target_os = "linux"))]
|
||||
#[pyattr]
|
||||
use termios::os::target::{
|
||||
B500000, B576000, B1000000, B1152000, B1500000, B2000000, B2500000, B3000000, B3500000,
|
||||
B4000000, CBAUDEX,
|
||||
};
|
||||
#[cfg(any(
|
||||
target_os = "android",
|
||||
target_os = "illumos",
|
||||
@@ -154,16 +154,17 @@ mod termios {
|
||||
use termios::os::target::{VSWTCH, VSWTCH as VSWTC};
|
||||
#[pyattr]
|
||||
use termios::{
|
||||
B0, B50, B75, B110, B134, B150, B200, B300, B600, B1200, B1800, B2400, B4800, B9600,
|
||||
B19200, B38400, BRKINT, CLOCAL, CREAD, CS5, CS6, CS7, CS8, CSIZE, CSTOPB, ECHO, ECHOE,
|
||||
ECHOK, ECHONL, HUPCL, ICANON, ICRNL, IEXTEN, IGNBRK, IGNCR, IGNPAR, INLCR, INPCK, ISIG,
|
||||
ISTRIP, IXANY, IXOFF, IXON, NOFLSH, OCRNL, ONLCR, ONLRET, ONOCR, OPOST, PARENB, PARMRK,
|
||||
PARODD, TCIFLUSH, TCIOFF, TCIOFLUSH, TCION, TCOFLUSH, TCOOFF, TCOON, TCSADRAIN, TCSAFLUSH,
|
||||
TCSANOW, TOSTOP, VEOF, VEOL, VERASE, VINTR, VKILL, VMIN, VQUIT, VSTART, VSTOP, VSUSP,
|
||||
VTIME,
|
||||
os::target::{
|
||||
B115200, B230400, B57600, CRTSCTS, ECHOCTL, ECHOKE, ECHOPRT, EXTA, EXTB, FLUSHO,
|
||||
B57600, B115200, B230400, CRTSCTS, ECHOCTL, ECHOKE, ECHOPRT, EXTA, EXTB, FLUSHO,
|
||||
IMAXBEL, NCCS, PENDIN, VDISCARD, VEOL2, VLNEXT, VREPRINT, VWERASE,
|
||||
},
|
||||
B0, B110, B1200, B134, B150, B1800, B19200, B200, B2400, B300, B38400, B4800, B50, B600,
|
||||
B75, B9600, BRKINT, CLOCAL, CREAD, CS5, CS6, CS7, CS8, CSIZE, CSTOPB, ECHO, ECHOE, ECHOK,
|
||||
ECHONL, HUPCL, ICANON, ICRNL, IEXTEN, IGNBRK, IGNCR, IGNPAR, INLCR, INPCK, ISIG, ISTRIP,
|
||||
IXANY, IXOFF, IXON, NOFLSH, OCRNL, ONLCR, ONLRET, ONOCR, OPOST, PARENB, PARMRK, PARODD,
|
||||
TCIFLUSH, TCIOFF, TCIOFLUSH, TCION, TCOFLUSH, TCOOFF, TCOON, TCSADRAIN, TCSAFLUSH, TCSANOW,
|
||||
TOSTOP, VEOF, VEOL, VERASE, VINTR, VKILL, VMIN, VQUIT, VSTART, VSTOP, VSUSP, VTIME,
|
||||
};
|
||||
|
||||
#[pyfunction]
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
// spell-checker:ignore nfkc unistr unidata
|
||||
|
||||
use crate::vm::{
|
||||
builtins::PyModule, builtins::PyStr, convert::TryFromBorrowedObject, PyObject, PyObjectRef,
|
||||
PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::PyModule,
|
||||
builtins::PyStr, convert::TryFromBorrowedObject,
|
||||
};
|
||||
|
||||
pub fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
|
||||
@@ -61,14 +61,14 @@ impl<'a> TryFromBorrowedObject<'a> for NormalizeForm {
|
||||
#[pymodule]
|
||||
mod unicodedata {
|
||||
use crate::vm::{
|
||||
builtins::PyStrRef, function::OptionalArg, PyObjectRef, PyPayload, PyRef, PyResult,
|
||||
VirtualMachine,
|
||||
PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::PyStrRef,
|
||||
function::OptionalArg,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use ucd::{Codepoint, EastAsianWidth};
|
||||
use unic_char_property::EnumeratedCharProperty;
|
||||
use unic_normal::StrNormalForm;
|
||||
use unic_ucd_age::{Age, UnicodeVersion, UNICODE_VERSION};
|
||||
use unic_ucd_age::{Age, UNICODE_VERSION, UnicodeVersion};
|
||||
use unic_ucd_bidi::BidiClass;
|
||||
use unic_ucd_category::GeneralCategory;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ mod _uuid {
|
||||
use crate::{builtins::PyNone, vm::VirtualMachine};
|
||||
use mac_address::get_mac_address;
|
||||
use once_cell::sync::OnceCell;
|
||||
use uuid::{timestamp::Timestamp, Context, Uuid};
|
||||
use uuid::{Context, Uuid, timestamp::Timestamp};
|
||||
|
||||
fn get_node_id() -> [u8; 6] {
|
||||
match get_mac_address() {
|
||||
|
||||
@@ -5,17 +5,17 @@ pub(crate) use zlib::make_module;
|
||||
#[pymodule]
|
||||
mod zlib {
|
||||
use crate::vm::{
|
||||
PyObject, PyPayload, PyResult, VirtualMachine,
|
||||
builtins::{PyBaseExceptionRef, PyBytesRef, PyIntRef, PyTypeRef},
|
||||
common::lock::PyMutex,
|
||||
convert::TryFromBorrowedObject,
|
||||
function::{ArgBytesLike, ArgPrimitiveIndex, ArgSize, OptionalArg},
|
||||
types::Constructor,
|
||||
PyObject, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
use adler32::RollingAdler32 as Adler32;
|
||||
use flate2::{
|
||||
write::ZlibEncoder, Compress, Compression, Decompress, FlushCompress, FlushDecompress,
|
||||
Status,
|
||||
Compress, Compression, Decompress, FlushCompress, FlushDecompress, Status,
|
||||
write::ZlibEncoder,
|
||||
};
|
||||
use std::io::Write;
|
||||
|
||||
@@ -420,7 +420,7 @@ mod zlib {
|
||||
fn flush(&self, length: OptionalArg<ArgSize>, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
|
||||
let length = match length {
|
||||
OptionalArg::Present(ArgSize { value }) if value <= 0 => {
|
||||
return Err(vm.new_value_error("length must be greater than zero".to_owned()))
|
||||
return Err(vm.new_value_error("length must be greater than zero".to_owned()));
|
||||
}
|
||||
OptionalArg::Present(ArgSize { value }) => value as usize,
|
||||
OptionalArg::Missing => DEF_BUF_SIZE,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::{
|
||||
Py, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine,
|
||||
builtins::{PyIntRef, PyTuple},
|
||||
cformat::cformat_string,
|
||||
convert::TryFromBorrowedObject,
|
||||
function::OptionalOption,
|
||||
Py, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine,
|
||||
};
|
||||
use num_traits::{cast::ToPrimitive, sign::Signed};
|
||||
|
||||
@@ -386,11 +386,7 @@ pub trait AnyStr {
|
||||
b'\n' => (keep, 1),
|
||||
b'\r' => {
|
||||
let is_rn = enumerated.next_if(|(_, ch)| **ch == b'\n').is_some();
|
||||
if is_rn {
|
||||
(keep + keep, 2)
|
||||
} else {
|
||||
(keep, 1)
|
||||
}
|
||||
if is_rn { (keep + keep, 2) } else { (keep, 1) }
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::{
|
||||
PyObjectRef, PyResult, TryFromObject, VirtualMachine,
|
||||
builtins::{PyBaseExceptionRef, PyBytesRef, PyTuple, PyTupleRef, PyTypeRef},
|
||||
common::{static_cell, str::wchar_t},
|
||||
convert::ToPyObject,
|
||||
function::{ArgBytesLike, ArgIntoBool, ArgIntoFloat},
|
||||
PyObjectRef, PyResult, TryFromObject, VirtualMachine,
|
||||
};
|
||||
use half::f16;
|
||||
use itertools::Itertools;
|
||||
@@ -99,8 +99,8 @@ impl fmt::Debug for FormatType {
|
||||
|
||||
impl FormatType {
|
||||
fn info(self, e: Endianness) -> &'static FormatInfo {
|
||||
use mem::{align_of, size_of};
|
||||
use FormatType::*;
|
||||
use mem::{align_of, size_of};
|
||||
macro_rules! native_info {
|
||||
($t:ty) => {{
|
||||
&FormatInfo {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::{PyCode, PyGenericAlias, PyStrRef, PyType, PyTypeRef};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
builtins::PyBaseExceptionRef,
|
||||
class::PyClassImpl,
|
||||
coroutine::Coro,
|
||||
@@ -7,7 +8,6 @@ use crate::{
|
||||
function::OptionalArg,
|
||||
protocol::PyIterReturn,
|
||||
types::{IterNext, Iterable, Representable, SelfIter, Unconstructible},
|
||||
AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
@@ -208,7 +208,7 @@ impl PyAsyncGenASend {
|
||||
AwaitableState::Closed => {
|
||||
return Err(vm.new_runtime_error(
|
||||
"cannot reuse already awaited __anext__()/asend()".to_owned(),
|
||||
))
|
||||
));
|
||||
}
|
||||
AwaitableState::Iter => val, // already running, all good
|
||||
AwaitableState::Init => {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use super::{PyInt, PyStrRef, PyType, PyTypeRef};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject,
|
||||
VirtualMachine,
|
||||
class::PyClassImpl,
|
||||
convert::{IntoPyException, ToPyObject, ToPyResult},
|
||||
function::OptionalArg,
|
||||
identifier,
|
||||
protocol::PyNumberMethods,
|
||||
types::{AsNumber, Constructor, Representable},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject,
|
||||
VirtualMachine,
|
||||
};
|
||||
use malachite_bigint::Sign;
|
||||
use num_traits::Zero;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use super::{type_, PyStrInterned, PyStrRef, PyType};
|
||||
use super::{PyStrInterned, PyStrRef, PyType, type_};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
class::PyClassImpl,
|
||||
convert::TryFromObject,
|
||||
function::{FuncArgs, PyComparisonValue, PyMethodDef, PyMethodFlags, PyNativeFn},
|
||||
types::{Callable, Comparable, PyComparisonOp, Representable, Unconstructible},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
use std::fmt;
|
||||
|
||||
|
||||
@@ -4,12 +4,14 @@ use super::{
|
||||
PyType, PyTypeRef,
|
||||
};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
|
||||
VirtualMachine,
|
||||
anystr::{self, AnyStr},
|
||||
atomic_func,
|
||||
byte::{bytes_from_object, value_from_object},
|
||||
bytesinner::{
|
||||
bytes_decode, ByteInnerFindOptions, ByteInnerNewOptions, ByteInnerPaddingOptions,
|
||||
ByteInnerSplitOptions, ByteInnerTranslateOptions, DecodeArgs, PyBytesInner,
|
||||
ByteInnerFindOptions, ByteInnerNewOptions, ByteInnerPaddingOptions, ByteInnerSplitOptions,
|
||||
ByteInnerTranslateOptions, DecodeArgs, PyBytesInner, bytes_decode,
|
||||
},
|
||||
class::PyClassImpl,
|
||||
common::{
|
||||
@@ -33,8 +35,6 @@ use crate::{
|
||||
DefaultConstructor, Initializer, IterNext, Iterable, PyComparisonOp, Representable,
|
||||
SelfIter, Unconstructible,
|
||||
},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
|
||||
VirtualMachine,
|
||||
};
|
||||
use bstr::ByteSlice;
|
||||
use std::mem::size_of;
|
||||
|
||||
@@ -2,11 +2,13 @@ use super::{
|
||||
PositionIterInternal, PyDictRef, PyIntRef, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef,
|
||||
};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
|
||||
TryFromBorrowedObject, TryFromObject, VirtualMachine,
|
||||
anystr::{self, AnyStr},
|
||||
atomic_func,
|
||||
bytesinner::{
|
||||
bytes_decode, ByteInnerFindOptions, ByteInnerNewOptions, ByteInnerPaddingOptions,
|
||||
ByteInnerSplitOptions, ByteInnerTranslateOptions, DecodeArgs, PyBytesInner,
|
||||
ByteInnerFindOptions, ByteInnerNewOptions, ByteInnerPaddingOptions, ByteInnerSplitOptions,
|
||||
ByteInnerTranslateOptions, DecodeArgs, PyBytesInner, bytes_decode,
|
||||
},
|
||||
class::PyClassImpl,
|
||||
common::{hash::PyHash, lock::PyMutex},
|
||||
@@ -23,8 +25,6 @@ use crate::{
|
||||
AsBuffer, AsMapping, AsNumber, AsSequence, Callable, Comparable, Constructor, Hashable,
|
||||
IterNext, Iterable, PyComparisonOp, Representable, SelfIter, Unconstructible,
|
||||
},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
|
||||
TryFromBorrowedObject, TryFromObject, VirtualMachine,
|
||||
};
|
||||
use bstr::ByteSlice;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use super::{PyBoundMethod, PyStr, PyType, PyTypeRef};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
class::PyClassImpl,
|
||||
common::lock::PyMutex,
|
||||
types::{Constructor, GetDescriptor, Initializer, Representable},
|
||||
AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
/// classmethod(function) -> method
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
use super::{PyStrRef, PyTupleRef, PyType, PyTypeRef};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
builtins::PyStrInterned,
|
||||
bytecode::{self, AsBag, BorrowedConstant, CodeFlags, Constant, ConstantBag},
|
||||
class::{PyClassImpl, StaticType},
|
||||
@@ -12,7 +13,6 @@ use crate::{
|
||||
function::{FuncArgs, OptionalArg},
|
||||
source_code::OneIndexed,
|
||||
types::Representable,
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
use malachite_bigint::BigInt;
|
||||
use num_traits::Zero;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::{float, PyStr, PyType, PyTypeRef};
|
||||
use super::{PyStr, PyType, PyTypeRef, float};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
class::PyClassImpl,
|
||||
convert::{ToPyObject, ToPyResult},
|
||||
function::{
|
||||
@@ -11,7 +12,6 @@ use crate::{
|
||||
protocol::PyNumberMethods,
|
||||
stdlib::warnings,
|
||||
types::{AsNumber, Comparable, Constructor, Hashable, PyComparisonOp, Representable},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
use num_complex::Complex64;
|
||||
use num_traits::Zero;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use super::{PyCode, PyStrRef, PyType};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
class::PyClassImpl,
|
||||
coroutine::Coro,
|
||||
frame::FrameRef,
|
||||
function::OptionalArg,
|
||||
protocol::PyIterReturn,
|
||||
types::{IterNext, Iterable, Representable, SelfIter, Unconstructible},
|
||||
AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
#[pyclass(module = false, name = "coroutine")]
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use super::{PyStr, PyStrInterned, PyType};
|
||||
use crate::{
|
||||
builtins::{builtin_func::PyNativeMethod, type_, PyTypeRef},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
builtins::{PyTypeRef, builtin_func::PyNativeMethod, type_},
|
||||
class::PyClassImpl,
|
||||
function::{FuncArgs, PyMethodDef, PyMethodFlags, PySetterValue},
|
||||
types::{Callable, GetDescriptor, Representable, Unconstructible},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
use rustpython_common::lock::PyRwLock;
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
use super::{
|
||||
set::PySetInner, IterStatus, PositionIterInternal, PyBaseExceptionRef, PyGenericAlias,
|
||||
PyMappingProxy, PySet, PyStr, PyStrRef, PyTupleRef, PyType, PyTypeRef,
|
||||
IterStatus, PositionIterInternal, PyBaseExceptionRef, PyGenericAlias, PyMappingProxy, PySet,
|
||||
PyStr, PyStrRef, PyTupleRef, PyType, PyTypeRef, set::PySetInner,
|
||||
};
|
||||
use crate::{
|
||||
atomic_func,
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, PyResult,
|
||||
TryFromObject, atomic_func,
|
||||
builtins::{
|
||||
PyTuple,
|
||||
iter::{builtins_iter, builtins_reversed},
|
||||
type_::PyAttributes,
|
||||
PyTuple,
|
||||
},
|
||||
class::{PyClassDef, PyClassImpl},
|
||||
common::ascii,
|
||||
@@ -21,8 +22,6 @@ use crate::{
|
||||
Initializer, IterNext, Iterable, PyComparisonOp, Representable, SelfIter, Unconstructible,
|
||||
},
|
||||
vm::VirtualMachine,
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, PyResult,
|
||||
TryFromObject,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
use rustpython_common::lock::PyMutex;
|
||||
|
||||
@@ -3,12 +3,12 @@ use super::{
|
||||
};
|
||||
use crate::common::lock::{PyMutex, PyRwLock};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
class::PyClassImpl,
|
||||
convert::ToPyObject,
|
||||
function::OptionalArg,
|
||||
protocol::{PyIter, PyIterReturn},
|
||||
types::{Constructor, IterNext, Iterable, SelfIter},
|
||||
AsObject, Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
use malachite_bigint::BigInt;
|
||||
use num_traits::Zero;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use super::{PyType, PyTypeRef};
|
||||
use crate::{
|
||||
Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
class::PyClassImpl,
|
||||
protocol::{PyIter, PyIterReturn},
|
||||
types::{Constructor, IterNext, Iterable, SelfIter},
|
||||
Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
#[pyclass(module = false, name = "filter", traverse)]
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
// spell-checker:ignore numer denom
|
||||
|
||||
use super::{
|
||||
try_bigint_to_f64, PyByteArray, PyBytes, PyInt, PyIntRef, PyStr, PyStrRef, PyType, PyTypeRef,
|
||||
PyByteArray, PyBytes, PyInt, PyIntRef, PyStr, PyStrRef, PyType, PyTypeRef, try_bigint_to_f64,
|
||||
};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
|
||||
TryFromBorrowedObject, TryFromObject, VirtualMachine,
|
||||
class::PyClassImpl,
|
||||
common::{float_ops, hash},
|
||||
convert::{IntoPyException, ToPyObject, ToPyResult},
|
||||
@@ -14,8 +16,6 @@ use crate::{
|
||||
},
|
||||
protocol::PyNumberMethods,
|
||||
types::{AsNumber, Callable, Comparable, Constructor, Hashable, PyComparisonOp, Representable},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
|
||||
TryFromBorrowedObject, TryFromObject, VirtualMachine,
|
||||
};
|
||||
use malachite_bigint::{BigInt, ToBigInt};
|
||||
use num_complex::Complex64;
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
|
||||
use super::{PyCode, PyDictRef, PyIntRef, PyStrRef};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObjectRef, PyRef, PyResult, VirtualMachine,
|
||||
class::PyClassImpl,
|
||||
frame::{Frame, FrameRef},
|
||||
function::PySetterValue,
|
||||
types::{Representable, Unconstructible},
|
||||
AsObject, Context, Py, PyObjectRef, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
use num_traits::Zero;
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
mod jitfunc;
|
||||
|
||||
use super::{
|
||||
tuple::PyTupleTyped, PyAsyncGen, PyCode, PyCoroutine, PyDictRef, PyGenerator, PyStr, PyStrRef,
|
||||
PyTupleRef, PyType, PyTypeRef,
|
||||
PyAsyncGen, PyCode, PyCoroutine, PyDictRef, PyGenerator, PyStr, PyStrRef, PyTupleRef, PyType,
|
||||
PyTypeRef, tuple::PyTupleTyped,
|
||||
};
|
||||
#[cfg(feature = "jit")]
|
||||
use crate::common::lock::OnceCell;
|
||||
@@ -12,6 +12,7 @@ use crate::convert::ToPyObject;
|
||||
use crate::function::ArgMapping;
|
||||
use crate::object::{Traverse, TraverseFn};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
bytecode,
|
||||
class::PyClassImpl,
|
||||
frame::Frame,
|
||||
@@ -20,7 +21,6 @@ use crate::{
|
||||
types::{
|
||||
Callable, Comparable, Constructor, GetAttr, GetDescriptor, PyComparisonOp, Representable,
|
||||
},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
#[cfg(feature = "jit")]
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::{
|
||||
builtins::{bool_, float, int, PyBaseExceptionRef, PyDictRef, PyFunction, PyStrInterned},
|
||||
AsObject, Py, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine,
|
||||
builtins::{PyBaseExceptionRef, PyDictRef, PyFunction, PyStrInterned, bool_, float, int},
|
||||
bytecode::CodeFlags,
|
||||
convert::ToPyObject,
|
||||
function::FuncArgs,
|
||||
AsObject, Py, PyObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine,
|
||||
};
|
||||
use num_traits::ToPrimitive;
|
||||
use rustpython_jit::{AbiValue, Args, CompiledCode, JitArgumentError, JitType};
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
use super::{PyCode, PyStrRef, PyType};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
class::PyClassImpl,
|
||||
coroutine::Coro,
|
||||
frame::FrameRef,
|
||||
function::OptionalArg,
|
||||
protocol::PyIterReturn,
|
||||
types::{IterNext, Iterable, Representable, SelfIter, Unconstructible},
|
||||
AsObject, Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
#[pyclass(module = false, name = "generator")]
|
||||
|
||||
@@ -2,7 +2,8 @@ use once_cell::sync::Lazy;
|
||||
|
||||
use super::type_;
|
||||
use crate::{
|
||||
atomic_func,
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
|
||||
VirtualMachine, atomic_func,
|
||||
builtins::{PyList, PyStr, PyTuple, PyTupleRef, PyType, PyTypeRef},
|
||||
class::PyClassImpl,
|
||||
common::hash,
|
||||
@@ -13,8 +14,6 @@ use crate::{
|
||||
AsMapping, AsNumber, Callable, Comparable, Constructor, GetAttr, Hashable, PyComparisonOp,
|
||||
Representable,
|
||||
},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
|
||||
VirtualMachine,
|
||||
};
|
||||
use std::fmt;
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
*/
|
||||
use super::{PyType, PyTypeRef};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
class::PyClassImpl,
|
||||
function::{IntoPyGetterFunc, IntoPySetterFunc, PyGetterFunc, PySetterFunc, PySetterValue},
|
||||
types::{GetDescriptor, Unconstructible},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
#[pyclass(module = false, name = "getset_descriptor")]
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use super::{float, PyByteArray, PyBytes, PyStr, PyType, PyTypeRef};
|
||||
use super::{PyByteArray, PyBytes, PyStr, PyType, PyTypeRef, float};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, PyResult,
|
||||
TryFromBorrowedObject, VirtualMachine,
|
||||
builtins::PyStrRef,
|
||||
bytesinner::PyBytesInner,
|
||||
class::PyClassImpl,
|
||||
@@ -14,8 +16,6 @@ use crate::{
|
||||
},
|
||||
protocol::PyNumberMethods,
|
||||
types::{AsNumber, Comparable, Constructor, Hashable, PyComparisonOp, Representable},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, PyResult,
|
||||
TryFromBorrowedObject, VirtualMachine,
|
||||
};
|
||||
use malachite_bigint::{BigInt, Sign};
|
||||
use num_integer::Integer;
|
||||
@@ -109,11 +109,7 @@ fn inner_pow(int1: &BigInt, int2: &BigInt, vm: &VirtualMachine) -> PyResult {
|
||||
} else if int1.is_zero() {
|
||||
0
|
||||
} else if int1 == &BigInt::from(-1) {
|
||||
if int2.is_odd() {
|
||||
-1
|
||||
} else {
|
||||
1
|
||||
}
|
||||
if int2.is_odd() { -1 } else { 1 }
|
||||
} else {
|
||||
// missing feature: BigInt exp
|
||||
// practically, exp over u64 is not possible to calculate anyway
|
||||
@@ -426,11 +422,7 @@ impl PyInt {
|
||||
// based on rust-num/num-integer#10, should hopefully be published soon
|
||||
fn normalize(a: BigInt, n: &BigInt) -> BigInt {
|
||||
let a = a % n;
|
||||
if a.is_negative() {
|
||||
a + n
|
||||
} else {
|
||||
a
|
||||
}
|
||||
if a.is_negative() { a + n } else { a }
|
||||
}
|
||||
fn inverse(a: BigInt, n: &BigInt) -> Option<BigInt> {
|
||||
use num_integer::*;
|
||||
@@ -642,7 +634,7 @@ impl PyInt {
|
||||
Sign::Minus if !signed => {
|
||||
return Err(
|
||||
vm.new_overflow_error("can't convert negative int to unsigned".to_owned())
|
||||
)
|
||||
);
|
||||
}
|
||||
Sign::NoSign => return Ok(vec![0u8; byte_len].into()),
|
||||
_ => {}
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
|
||||
use super::{PyInt, PyTupleRef, PyType};
|
||||
use crate::{
|
||||
Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
class::PyClassImpl,
|
||||
function::ArgCallable,
|
||||
object::{Traverse, TraverseFn},
|
||||
protocol::{PyIterReturn, PySequence, PySequenceMethods},
|
||||
types::{IterNext, Iterable, SelfIter},
|
||||
Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
use rustpython_common::{
|
||||
lock::{PyMutex, PyRwLock, PyRwLockUpgradableReadGuard},
|
||||
|
||||
@@ -4,6 +4,7 @@ use crate::common::lock::{
|
||||
PyMappedRwLockReadGuard, PyMutex, PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard,
|
||||
};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
|
||||
class::PyClassImpl,
|
||||
convert::ToPyObject,
|
||||
function::{ArgSize, FuncArgs, OptionalArg, PyComparisonValue},
|
||||
@@ -18,7 +19,6 @@ use crate::{
|
||||
},
|
||||
utils::collection_repr,
|
||||
vm::VirtualMachine,
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
|
||||
};
|
||||
use std::{fmt, ops::DerefMut};
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use super::{PyType, PyTypeRef};
|
||||
use crate::{
|
||||
Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
builtins::PyTupleRef,
|
||||
class::PyClassImpl,
|
||||
function::PosArgs,
|
||||
protocol::{PyIter, PyIterReturn},
|
||||
types::{Constructor, IterNext, Iterable, SelfIter},
|
||||
Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
#[pyclass(module = false, name = "map", traverse)]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::{PyDict, PyDictRef, PyGenericAlias, PyList, PyTuple, PyType, PyTypeRef};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
atomic_func,
|
||||
class::PyClassImpl,
|
||||
convert::ToPyObject,
|
||||
@@ -10,7 +11,6 @@ use crate::{
|
||||
AsMapping, AsNumber, AsSequence, Comparable, Constructor, Iterable, PyComparisonOp,
|
||||
Representable,
|
||||
},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@ use super::{
|
||||
PyTupleRef, PyType, PyTypeRef,
|
||||
};
|
||||
use crate::{
|
||||
atomic_func,
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
|
||||
TryFromBorrowedObject, TryFromObject, VirtualMachine, atomic_func,
|
||||
buffer::FormatSpec,
|
||||
bytesinner::bytes_to_hex,
|
||||
class::PyClassImpl,
|
||||
@@ -24,8 +25,6 @@ use crate::{
|
||||
AsBuffer, AsMapping, AsSequence, Comparable, Constructor, Hashable, IterNext, Iterable,
|
||||
PyComparisonOp, Representable, SelfIter, Unconstructible,
|
||||
},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
|
||||
TryFromBorrowedObject, TryFromObject, VirtualMachine,
|
||||
};
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
use itertools::Itertools;
|
||||
@@ -223,14 +222,16 @@ impl PyMemoryView {
|
||||
fn pos_from_multi_index(&self, indexes: &[isize], vm: &VirtualMachine) -> PyResult<usize> {
|
||||
match indexes.len().cmp(&self.desc.ndim()) {
|
||||
Ordering::Less => {
|
||||
return Err(vm.new_not_implemented_error("sub-views are not implemented".to_owned()))
|
||||
return Err(
|
||||
vm.new_not_implemented_error("sub-views are not implemented".to_owned())
|
||||
);
|
||||
}
|
||||
Ordering::Greater => {
|
||||
return Err(vm.new_type_error(format!(
|
||||
"cannot index {}-dimension view with {}-element tuple",
|
||||
self.desc.ndim(),
|
||||
indexes.len()
|
||||
)))
|
||||
)));
|
||||
}
|
||||
Ordering::Equal => (),
|
||||
}
|
||||
@@ -380,11 +381,7 @@ impl PyMemoryView {
|
||||
}
|
||||
};
|
||||
ret = vm.bool_eq(&a_val, &b_val);
|
||||
if let Ok(b) = ret {
|
||||
!b
|
||||
} else {
|
||||
true
|
||||
}
|
||||
if let Ok(b) = ret { !b } else { true }
|
||||
});
|
||||
ret
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use super::{PyDictRef, PyStr, PyStrRef, PyType, PyTypeRef};
|
||||
use crate::{
|
||||
builtins::{pystr::AsPyStr, PyStrInterned},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
builtins::{PyStrInterned, pystr::AsPyStr},
|
||||
class::PyClassImpl,
|
||||
convert::ToPyObject,
|
||||
function::{FuncArgs, PyMethodDef},
|
||||
types::{GetAttr, Initializer, Representable},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
#[pyclass(module = false, name = "module")]
|
||||
@@ -183,11 +183,12 @@ impl Initializer for PyModule {
|
||||
type Args = ModuleInitArgs;
|
||||
|
||||
fn init(zelf: PyRef<Self>, args: Self::Args, vm: &VirtualMachine) -> PyResult<()> {
|
||||
debug_assert!(zelf
|
||||
.class()
|
||||
.slots
|
||||
.flags
|
||||
.has_feature(crate::types::PyTypeFlags::HAS_DICT));
|
||||
debug_assert!(
|
||||
zelf.class()
|
||||
.slots
|
||||
.flags
|
||||
.has_feature(crate::types::PyTypeFlags::HAS_DICT)
|
||||
);
|
||||
zelf.init_dict(vm.ctx.intern_str(args.name.as_str()), args.doc, vm);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::{tuple::IntoPyTuple, PyTupleRef, PyType};
|
||||
use super::{PyTupleRef, PyType, tuple::IntoPyTuple};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
builtins::PyDict,
|
||||
class::PyClassImpl,
|
||||
function::{FuncArgs, PyComparisonValue},
|
||||
@@ -7,7 +8,6 @@ use crate::{
|
||||
types::{
|
||||
Comparable, Constructor, DefaultConstructor, Initializer, PyComparisonOp, Representable,
|
||||
},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
/// A simple attribute-based namespace.
|
||||
|
||||
@@ -2,11 +2,11 @@ use super::{PyDictRef, PyList, PyStr, PyStrRef, PyType, PyTypeRef};
|
||||
use crate::common::hash::PyHash;
|
||||
use crate::types::PyTypeFlags;
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
class::PyClassImpl,
|
||||
convert::ToPyResult,
|
||||
function::{Either, FuncArgs, PyArithmeticValue, PyComparisonValue, PySetterValue},
|
||||
types::{Constructor, PyComparisonOp},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ use super::{PyStrRef, PyType, PyTypeRef};
|
||||
use crate::common::lock::PyRwLock;
|
||||
use crate::function::{IntoFuncArgs, PosArgs};
|
||||
use crate::{
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
class::PyClassImpl,
|
||||
function::{FuncArgs, PySetterValue},
|
||||
types::{Constructor, GetDescriptor, Initializer},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
#[pyclass(module = false, name = "property", traverse)]
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
use super::{
|
||||
builtins_iter, tuple::tuple_hash, PyInt, PyIntRef, PySlice, PyTupleRef, PyType, PyTypeRef,
|
||||
PyInt, PyIntRef, PySlice, PyTupleRef, PyType, PyTypeRef, builtins_iter, tuple::tuple_hash,
|
||||
};
|
||||
use crate::{
|
||||
atomic_func,
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
|
||||
VirtualMachine, atomic_func,
|
||||
class::PyClassImpl,
|
||||
common::hash::PyHash,
|
||||
function::{ArgIndex, FuncArgs, OptionalArg, PyComparisonValue},
|
||||
@@ -11,8 +12,6 @@ use crate::{
|
||||
AsMapping, AsSequence, Comparable, Hashable, IterNext, Iterable, PyComparisonOp,
|
||||
Representable, SelfIter, Unconstructible,
|
||||
},
|
||||
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
|
||||
VirtualMachine,
|
||||
};
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
use malachite_bigint::{BigInt, Sign};
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user