FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix _ctypes.Array base and metaclass by youknowone · Pull Request #5620 · RustPython/RustPython · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rs  (5) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions vm/src/stdlib/ctypes.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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<PyModule>) {
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),
Expand Down
18 changes: 13 additions & 5 deletions vm/src/stdlib/ctypes/array.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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<PyTypeRef>,
Expand Down
8 changes: 4 additions & 4 deletions vm/src/stdlib/ctypes/base.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -176,10 +176,10 @@ impl PySimpleMeta {
}

#[pyclass(
module = "_ctypes",
name = "_SimpleCData",
base = "PyCData",
module = "_ctypes",
metaclass = "PySimpleMeta"
metaclass = "PyCSimpleType"
)]
#[derive(PyPayload)]
pub struct PyCSimple {
Expand Down
3 changes: 2 additions & 1 deletion vm/src/stdlib/ctypes/structure.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::base::PyCData;
use crate::builtins::{PyList, PyStr, PyTuple, PyTypeRef};
use crate::function::FuncArgs;
use crate::types::GetAttr;
Expand All @@ -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)]
Expand Down
5 changes: 4 additions & 1 deletion vm/src/stdlib/ctypes/union.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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))]
Expand Down

Back | FazBrowse Home | New Git URL