diff --git a/extra_tests/snippets/builtins_ctypes.py b/extra_tests/snippets/stdlib_ctypes.py similarity index 98% rename from extra_tests/snippets/builtins_ctypes.py rename to extra_tests/snippets/stdlib_ctypes.py index 2108ce41a4..95ee9900fb 100644 --- a/extra_tests/snippets/builtins_ctypes.py +++ b/extra_tests/snippets/stdlib_ctypes.py @@ -3,12 +3,15 @@ from _ctypes import RTLD_LOCAL, RTLD_GLOBAL from _ctypes import sizeof -from _ctypes import _SimpleCData +from _ctypes import _SimpleCData, Array from _ctypes import CFuncPtr as _CFuncPtr from struct import calcsize as _calcsize +assert Array.__class__.__name__ == 'PyCArrayType' +assert Array.__base__.__name__ == '_CData' + DEFAULT_MODE = RTLD_LOCAL if _os.name == "posix" and _sys.platform == "darwin": # On OS X 10.3, we use RTLD_GLOBAL as default mode diff --git a/vm/src/stdlib/ctypes.rs b/vm/src/stdlib/ctypes.rs index b6fd150889..736b91dbdf 100644 --- a/vm/src/stdlib/ctypes.rs +++ b/vm/src/stdlib/ctypes.rs @@ -8,16 +8,16 @@ pub(crate) mod union; use crate::builtins::PyModule; use crate::class::PyClassImpl; -use crate::stdlib::ctypes::base::{PyCData, PyCSimple, PySimpleMeta}; +use crate::stdlib::ctypes::base::{PyCData, PyCSimple, PyCSimpleType}; use crate::{Py, PyRef, VirtualMachine}; pub fn extend_module_nodes(vm: &VirtualMachine, module: &Py) { let ctx = &vm.ctx; - PySimpleMeta::make_class(ctx); + PyCSimpleType::make_class(ctx); + array::PyCArrayType::make_class(ctx); extend_module!(vm, module, { "_CData" => PyCData::make_class(ctx), "_SimpleCData" => PyCSimple::make_class(ctx), - "ArrayType" => array::PyCArrayType::make_class(ctx), "Array" => array::PyCArray::make_class(ctx), "CFuncPtr" => function::PyCFuncPtr::make_class(ctx), "_Pointer" => pointer::PyCPointer::make_class(ctx), diff --git a/vm/src/stdlib/ctypes/array.rs b/vm/src/stdlib/ctypes/array.rs index 44d237cd7e..0880c6b63b 100644 --- a/vm/src/stdlib/ctypes/array.rs +++ b/vm/src/stdlib/ctypes/array.rs @@ -1,13 +1,16 @@ use crate::builtins::PyBytes; use crate::types::Callable; use crate::{Py, PyObjectRef, PyPayload}; -use crate::{PyResult, VirtualMachine, builtins::PyTypeRef, types::Constructor}; +use crate::{ + PyResult, VirtualMachine, + builtins::{PyType, PyTypeRef}, + types::Constructor, +}; use crossbeam_utils::atomic::AtomicCell; use rustpython_common::lock::PyRwLock; -use rustpython_vm::stdlib::ctypes::base::PyCSimple; +use rustpython_vm::stdlib::ctypes::base::PyCData; -// TODO: make it metaclass -#[pyclass(name = "ArrayType", module = "_ctypes")] +#[pyclass(name = "PyCArrayType", base = "PyType", module = "_ctypes")] #[derive(PyPayload)] pub struct PyCArrayType { pub(super) inner: PyCArray, @@ -44,7 +47,12 @@ impl Constructor for PyCArrayType { #[pyclass(flags(IMMUTABLETYPE), with(Callable, Constructor))] impl PyCArrayType {} -#[pyclass(name = "Array", base = "PyCSimple", module = "_ctypes")] +#[pyclass( + name = "Array", + base = "PyCData", + metaclass = "PyCArrayType", + module = "_ctypes" +)] #[derive(PyPayload)] pub struct PyCArray { pub(super) typ: PyRwLock, diff --git a/vm/src/stdlib/ctypes/base.rs b/vm/src/stdlib/ctypes/base.rs index d07ccba30b..0ff84a3069 100644 --- a/vm/src/stdlib/ctypes/base.rs +++ b/vm/src/stdlib/ctypes/base.rs @@ -160,10 +160,10 @@ pub struct PyCData { impl PyCData {} #[pyclass(module = "_ctypes", name = "PyCSimpleType", base = "PyType")] -pub struct PySimpleMeta {} +pub struct PyCSimpleType {} #[pyclass(flags(BASETYPE))] -impl PySimpleMeta { +impl PyCSimpleType { #[allow(clippy::new_ret_no_self)] #[pymethod] fn new(cls: PyTypeRef, _: OptionalArg, vm: &VirtualMachine) -> PyResult { @@ -176,10 +176,10 @@ impl PySimpleMeta { } #[pyclass( + module = "_ctypes", name = "_SimpleCData", base = "PyCData", - module = "_ctypes", - metaclass = "PySimpleMeta" + metaclass = "PyCSimpleType" )] #[derive(PyPayload)] pub struct PyCSimple { diff --git a/vm/src/stdlib/ctypes/structure.rs b/vm/src/stdlib/ctypes/structure.rs index c6cf158953..10c1fa3df8 100644 --- a/vm/src/stdlib/ctypes/structure.rs +++ b/vm/src/stdlib/ctypes/structure.rs @@ -1,3 +1,4 @@ +use super::base::PyCData; use crate::builtins::{PyList, PyStr, PyTuple, PyTypeRef}; use crate::function::FuncArgs; use crate::types::GetAttr; @@ -7,7 +8,7 @@ use rustpython_vm::types::Constructor; use std::collections::HashMap; use std::fmt::Debug; -#[pyclass(name = "Structure", module = "_ctypes")] +#[pyclass(module = "_ctypes", name = "Structure", base = "PyCData")] #[derive(PyPayload, Debug)] pub struct PyCStructure { #[allow(dead_code)] diff --git a/vm/src/stdlib/ctypes/union.rs b/vm/src/stdlib/ctypes/union.rs index 5a39d9062e..2d76dbc9ca 100644 --- a/vm/src/stdlib/ctypes/union.rs +++ b/vm/src/stdlib/ctypes/union.rs @@ -1,4 +1,7 @@ -#[pyclass(name = "Union", module = "_ctypes")] +use super::base::PyCData; + +// TODO: metaclass = "UnionType" +#[pyclass(module = "_ctypes", name = "Union", base = "PyCData")] pub struct PyCUnion {} #[pyclass(flags(BASETYPE, IMMUTABLETYPE))] pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy