@@ -5,6 +5,7 @@ use crate::Py;
55use crate :: builtins:: { PyType , PyTypeRef } ;
66use crate :: protocol:: PyNumberMethods ;
77use crate :: stdlib:: ctypes:: PyCData ;
8+ use crate :: stdlib:: ctypes:: base:: CDataObject ;
89use crate :: types:: { AsNumber , Constructor } ;
910use crate :: { AsObject , PyObjectRef , PyPayload , PyResult , VirtualMachine } ;
1011
@@ -67,9 +68,20 @@ impl AsNumber for PyCPointerType {
6768) ]
6869#[ derive( Debug ) ]
6970pub 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+
7385impl 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