Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 112765b

Browse filesBrowse files
committed
fix more errors
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
1 parent 3168fed commit 112765b
Copy full SHA for 112765b

File tree

3 files changed

+15
-10
lines changed
Filter options

3 files changed

+15
-10
lines changed

‎vm/src/stdlib/ctypes/array.rs

Copy file name to clipboardExpand all lines: vm/src/stdlib/ctypes/array.rs
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use super::{
33
primitive::{new_simple_type, PyCSimple},
44
};
55
use crate::builtins::{
6-
self,
76
slice::PySlice,
87
PyBytes, PyInt, PyList, PyRange, PyStr, PyType, PyTypeRef,
98
};
@@ -14,7 +13,7 @@ use crate::stdlib::ctypes::basics::{
1413
default_from_param, generic_get_buffer, get_size, BorrowValue as BorrowValueCData,
1514
BorrowValueMut, PyCData, PyCDataFunctions, PyCDataMethods, PyCDataSequenceMethods, RawBuffer,
1615
};
17-
use crate::{AsObject, Context, PyObjectRef, PyRef, PyResult, TryFromObject, VirtualMachine};
16+
use crate::{AsObject, Py, PyObjectRef, PyRef, PyResult, TryFromObject, VirtualMachine};
1817
use rustpython_vm::object::PyPayload;
1918
use num_traits::Signed;
2019
use std::convert::TryInto;
@@ -23,6 +22,7 @@ use widestring::WideCString;
2322
use crate::class::StaticType;
2423
use crate::convert::IntoObject;
2524
use crate::protocol::{PyBuffer, PyIter};
25+
use crate::types::AsBuffer;
2626

2727
// TODO: make sure that this is correct wrt windows and unix wstr
2828
fn slice_to_obj(ty: &str, b: &[u8], vm: &VirtualMachine) -> PyResult {
@@ -256,7 +256,7 @@ fn array_slice_setitem(
256256
//Right now I'm setting one
257257
let size = length.map_or(Ok(1), |v| usize::try_from_object(vm, v))?;
258258

259-
for (i, curr) in PyIterable::try_from_object(vm,_range.into_object(vm))?.iter(vm)?.enumerate() {
259+
for (i, curr) in PyIter::try_from_object(vm,_range.into_object(vm))?.iter(vm)?.enumerate() {
260260
let idx = fix_index(isize::try_from_object(vm, curr?)?, size, vm)? as usize;
261261
let offset = idx * size;
262262
let item = obj.get_item(i, vm)?;
@@ -286,6 +286,7 @@ fn fix_index(index: isize, length: usize, vm: &VirtualMachine) -> PyResult<isize
286286
#[pyclass(module = "_ctypes", name = "PyCArrayType", base = "PyType")]
287287
pub struct PyCArrayMeta {}
288288

289+
#[derive(PyPayload)]
289290
#[pyclass(
290291
module = "_ctypes",
291292
name = "Array",
@@ -327,8 +328,8 @@ impl<'a> BorrowValueMut<'a> for PyCArray {
327328
}
328329
}
329330

330-
impl BufferProtocol for PyCArray {
331-
fn get_buffer(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult<Box<dyn Buffer>> {
331+
impl AsBuffer for PyCArray {
332+
fn as_buffer(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyBuffer> {
332333
generic_get_buffer::<Self>(zelf, vm)
333334
}
334335
}

‎vm/src/stdlib/ctypes/basics.rs

Copy file name to clipboardExpand all lines: vm/src/stdlib/ctypes/basics.rs
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::function::Either;
1717
use crate::builtins::PyTypeRef;
1818
use crate::protocol::PyBuffer;
1919
use crossbeam_utils::atomic::AtomicCell;
20+
use crate::types::AsBuffer;
2021

2122
pub fn get_size(ty: &str) -> usize {
2223
match ty {
@@ -270,7 +271,7 @@ pub trait PyCDataSequenceMethods: PyPayload {
270271
}
271272
}
272273

273-
pub fn generic_get_buffer<T>(zelf: &PyRef<T>, vm: &VirtualMachine) -> PyResult<Box<dyn Buffer>>
274+
pub fn generic_get_buffer<T>(zelf: &Py<T>, vm: &VirtualMachine) -> PyResult<PyBuffer>
274275
where
275276
for<'a> T: PyPayload + fmt::Debug + BorrowValue<'a> + BorrowValueMut<'a>,
276277
{
@@ -312,8 +313,8 @@ impl<'a> BorrowValueMut<'a> for PyCData {
312313
}
313314
}
314315

315-
impl BufferProtocol for PyCData {
316-
fn get_buffer(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult<Box<dyn Buffer>> {
316+
impl AsBuffer for PyCData {
317+
fn as_buffer(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult<PyBuffer> {
317318
generic_get_buffer::<Self>(zelf, vm)
318319
}
319320
}
@@ -371,6 +372,7 @@ unsafe impl Sync for RawBuffer {}
371372
// This Trait is the equivalent of PyCData_Type on tp_base for
372373
// Struct_Type, Union_Type, PyCPointer_Type
373374
// PyCArray_Type, PyCSimple_Type, PyCFuncPtr_Type
375+
#[derive(PyPayload)]
374376
#[pyclass(module = "_ctypes", name = "_CData")]
375377
pub struct PyCData {
376378
_objects: AtomicCell<Vec<PyObjectRef>>,

‎vm/src/stdlib/ctypes/primitive.rs

Copy file name to clipboardExpand all lines: vm/src/stdlib/ctypes/primitive.rs
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::stdlib::ctypes::basics::{
1515
use crate::stdlib::ctypes::function::PyCFuncPtr;
1616
use crate::stdlib::ctypes::pointer::PyCPointer;
1717
use crate::function::Either;
18-
use crate::{PyObjectRef, PyRef, PyResult, VirtualMachine};
18+
use crate::{PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine};
1919
use crate::protocol::PyBuffer;
2020

2121
const SIMPLE_TYPE_CHARS: &str = "cbBhHiIlLdfguzZPqQ?";
@@ -259,20 +259,22 @@ pub fn new_simple_type(
259259
}
260260
}
261261

262+
#[derive(PyPayload)]
262263
#[pyclass(module = "_ctypes", name = "PyCSimpleType", base = "PyType")]
263264
pub struct PySimpleMeta {}
264265

265266
#[pyclass(with(PyCDataMethods), flags(BASETYPE))]
266267
impl PySimpleMeta {
267268
#[pyslot]
268-
fn tp_new(cls: PyTypeRef, _: OptionalArg, vm: &VirtualMachine) -> PyResult {
269+
fn new(cls: PyTypeRef, _: OptionalArg, vm: &VirtualMachine) -> PyResult {
269270
Ok(new_simple_type(Either::B(&cls), vm)?
270271
.into_ref_with_type(vm, cls)?
271272
.as_object()
272273
.clone())
273274
}
274275
}
275276

277+
#[derive(PyPayload)]
276278
#[pyclass(
277279
module = "_ctypes",
278280
name = "_SimpleCData",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.