Skip to content

Commit b2cbec2

Browse files
committed
base of PyCSimple for PyCArray
1 parent 3477cd9 commit b2cbec2

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

vm/src/stdlib/ctypes/array.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use crate::{Py, PyObjectRef, PyPayload};
33
use crate::{PyResult, VirtualMachine, builtins::PyTypeRef, types::Constructor};
44
use crossbeam_utils::atomic::AtomicCell;
55
use rustpython_common::lock::PyRwLock;
6+
use rustpython_vm::stdlib::ctypes::base::PyCSimple;
67

78
// TODO: make it metaclass
8-
#[pyclass(name = "Array", module = "_ctypes")]
9+
#[pyclass(name = "ArrayType", module = "_ctypes")]
910
#[derive(PyPayload)]
1011
pub struct PyCArrayType {
1112
pub(super) inner: PyCArray,
@@ -34,15 +35,15 @@ impl Callable for PyCArrayType {
3435
impl Constructor for PyCArrayType {
3536
type Args = PyObjectRef;
3637

37-
fn py_new(_cls: PyTypeRef, args: Self::Args, vm: &VirtualMachine) -> PyResult {
38+
fn py_new(_cls: PyTypeRef, _args: Self::Args, _vm: &VirtualMachine) -> PyResult {
3839
unreachable!()
3940
}
4041
}
4142

42-
#[pyclass(flags(IMMUTABLETYPE))]
43+
#[pyclass(flags(IMMUTABLETYPE), with(Callable, Constructor))]
4344
impl PyCArrayType {}
4445

45-
#[pyclass(name = "Array", module = "_ctypes")]
46+
#[pyclass(name = "Array", base = "PyCSimple", module = "_ctypes")]
4647
#[derive(PyPayload)]
4748
pub struct PyCArray {
4849
pub(super) typ: PyRwLock<PyTypeRef>,
@@ -72,7 +73,7 @@ impl Constructor for PyCArray {
7273
}
7374
}
7475

75-
#[pyclass(flags(BASETYPE, IMMUTABLETYPE))]
76+
#[pyclass(flags(BASETYPE, IMMUTABLETYPE), with(Constructor))]
7677
impl PyCArray {
7778
#[pygetset(name = "_type_")]
7879
fn typ(&self) -> PyTypeRef {
@@ -84,12 +85,12 @@ impl PyCArray {
8485
self.length.load()
8586
}
8687

87-
#[pygetset(name = "_value_")]
88+
#[pygetset]
8889
fn value(&self) -> PyObjectRef {
8990
self.value.read().clone()
9091
}
9192

92-
#[pygetset(setter, name = "_value_")]
93+
#[pygetset(setter)]
9394
fn set_value(&self, value: PyObjectRef) {
9495
*self.value.write() = value;
9596
}

0 commit comments

Comments
 (0)