Skip to content

Commit 278be3f

Browse files
committed
backup
1 parent f9e54d2 commit 278be3f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

crates/vm/src/builtins/type.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,10 @@ impl PyType {
438438
}
439439
debug_assert!(
440440
slots.basicsize >= base.slots.basicsize,
441-
"subclass basicsize ({}) must be >= base basicsize ({})",
441+
"subclass {} basicsize ({}) must be >= base {} basicsize ({}). did you forget to add base payload as first field of subtype payload?",
442+
slots.name,
442443
slots.basicsize,
444+
base.slots.name,
443445
base.slots.basicsize
444446
);
445447

@@ -500,7 +502,7 @@ impl PyType {
500502
}
501503
debug_assert!(
502504
slots.basicsize >= base.slots.basicsize,
503-
"subclass {} basicsize ({}) must be >= base {} basicsize ({})",
505+
"subclass {} basicsize ({}) must be >= base {} basicsize ({}). did you forget to add base payload as first field of subtype payload?",
504506
slots.name,
505507
slots.basicsize,
506508
base.slots.name,

crates/vm/src/stdlib/ctypes/pointer.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::Py;
55
use crate::builtins::{PyType, PyTypeRef};
66
use crate::protocol::PyNumberMethods;
77
use crate::stdlib::ctypes::PyCData;
8+
use crate::stdlib::ctypes::base::CDataObject;
89
use crate::types::{AsNumber, Constructor};
910
use crate::{AsObject, PyObjectRef, PyPayload, PyResult, VirtualMachine};
1011

@@ -67,9 +68,20 @@ impl AsNumber for PyCPointerType {
6768
)]
6869
#[derive(Debug)]
6970
pub struct PyCPointer {
71+
#[allow(dead_code)]
72+
base: PyCData,
7073
contents: PyRwLock<PyObjectRef>,
7174
}
7275

76+
impl PyCPointer {
77+
fn make_base() -> PyCData {
78+
let stg_info = StgInfo::new(std::mem::size_of::<usize>(), std::mem::align_of::<usize>());
79+
PyCData {
80+
cdata: PyRwLock::new(CDataObject::from_stg_info(&stg_info)),
81+
}
82+
}
83+
}
84+
7385
impl Constructor for PyCPointer {
7486
type Args = (crate::function::OptionalArg<PyObjectRef>,);
7587

@@ -79,6 +91,7 @@ impl Constructor for PyCPointer {
7991

8092
// Create a new PyCPointer instance with the provided value
8193
Ok(PyCPointer {
94+
base: Self::make_base(),
8295
contents: PyRwLock::new(initial_contents),
8396
})
8497
}
@@ -122,6 +135,7 @@ impl PyCPointer {
122135
}
123136
// Pointer just stores the address value
124137
let payload = PyCPointer {
138+
base: Self::make_base(),
125139
contents: PyRwLock::new(vm.ctx.new_int(address).into()),
126140
};
127141
payload.into_ref_with_type(vm, cls).map(Into::into)
@@ -165,6 +179,7 @@ impl PyCPointer {
165179
let ptr_val = usize::from_ne_bytes(ptr_bytes.try_into().expect("size is checked above"));
166180

167181
let payload = PyCPointer {
182+
base: Self::make_base(),
168183
contents: PyRwLock::new(vm.ctx.new_int(ptr_val).into()),
169184
};
170185
payload.into_ref_with_type(vm, cls).map(Into::into)
@@ -200,6 +215,7 @@ impl PyCPointer {
200215
let ptr_val = usize::from_ne_bytes(ptr_bytes.try_into().expect("size is checked above"));
201216

202217
let payload = PyCPointer {
218+
base: Self::make_base(),
203219
contents: PyRwLock::new(vm.ctx.new_int(ptr_val).into()),
204220
};
205221
payload.into_ref_with_type(vm, cls).map(Into::into)
@@ -254,6 +270,7 @@ impl PyCPointer {
254270

255271
// For pointer types, we return a pointer to the symbol address
256272
let payload = PyCPointer {
273+
base: Self::make_base(),
257274
contents: PyRwLock::new(vm.ctx.new_int(symbol_address).into()),
258275
};
259276
payload.into_ref_with_type(vm, cls).map(Into::into)

0 commit comments

Comments
 (0)