Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3edd75a

Browse files
committed
Fix _ctypes.Array base and metacalss
1 parent 2b27cf5 commit 3edd75a

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

extra_tests/snippets/stdlib_ctypes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33

44
from _ctypes import RTLD_LOCAL, RTLD_GLOBAL
55
from _ctypes import sizeof
6-
from _ctypes import _SimpleCData
6+
from _ctypes import _SimpleCData, Array
77
from _ctypes import CFuncPtr as _CFuncPtr
88

99
from struct import calcsize as _calcsize
1010

1111

12+
assert Array.__class__.__name__ == 'PyCArrayType'
13+
assert Array.__base__.__name__ == '_CData'
14+
1215
DEFAULT_MODE = RTLD_LOCAL
1316
if _os.name == "posix" and _sys.platform == "darwin":
1417
# On OS X 10.3, we use RTLD_GLOBAL as default mode

vm/src/stdlib/ctypes/array.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
use crate::builtins::PyBytes;
22
use crate::types::Callable;
33
use crate::{Py, PyObjectRef, PyPayload};
4-
use crate::{PyResult, VirtualMachine, builtins::PyTypeRef, types::Constructor};
4+
use crate::{
5+
PyResult, VirtualMachine,
6+
builtins::{PyType, PyTypeRef},
7+
types::Constructor,
8+
};
59
use crossbeam_utils::atomic::AtomicCell;
610
use rustpython_common::lock::PyRwLock;
7-
use rustpython_vm::stdlib::ctypes::base::PyCSimple;
11+
use rustpython_vm::stdlib::ctypes::base::PyCData;
812

9-
// TODO: make it metaclass
10-
#[pyclass(name = "ArrayType", module = "_ctypes")]
13+
#[pyclass(name = "PyCArrayType", base = "PyType", module = "_ctypes")]
1114
#[derive(PyPayload)]
1215
pub struct PyCArrayType {
1316
pub(super) inner: PyCArray,
@@ -44,7 +47,12 @@ impl Constructor for PyCArrayType {
4447
#[pyclass(flags(IMMUTABLETYPE), with(Callable, Constructor))]
4548
impl PyCArrayType {}
4649

47-
#[pyclass(name = "Array", base = "PyCSimple", module = "_ctypes")]
50+
#[pyclass(
51+
name = "Array",
52+
base = "PyCData",
53+
metaclass = "PyCArrayType",
54+
module = "_ctypes"
55+
)]
4856
#[derive(PyPayload)]
4957
pub struct PyCArray {
5058
pub(super) typ: PyRwLock<PyTypeRef>,

0 commit comments

Comments
 (0)