MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / shared_data_decl

Function shared_data_decl

src/py_class/py_class_impl.py:390–425  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

388 ''')
389
390def shared_data_decl():
391 # the storage type is PySharedRefCell<$data_type>, but unlike plain "data",
392 # its reference type is PySharedRef<'a, $data_type>.
393 generate_case('@shared data $data_name:ident : $data_type:ty;',
394 new_info = ''&#x27;
395 /* info: */ {
396 $base_type,
397 /* size: */ $crate::py_class::data_new_size::<$crate::PySharedRefCell<$data_type>>($size),
398 $class_visibility,
399 $gc,
400 /* data: */ [
401 $($data)*
402 {
403 $crate::py_class::data_offset::<$crate::PySharedRefCell<$data_type>>($size),
404 $data_name,
405 /* data_ty: */ $crate::PySharedRefCell<$data_type>,
406 /* init_expr: */ $crate::PySharedRefCell::<$data_type>::new($data_name),
407 /* init_ty: */ $data_type
408 }
409 ]
410 }
411 ''&#x27;,
412 new_impl=''&#x27;
413 impl $class {
414 fn $data_name<'a>(&'a self, py: $crate::Python<'a>) -> $crate::PySharedRef<'a, $data_type> {
415 unsafe {
416 let data = $crate::py_class::data_get::<$crate::PySharedRefCell<$data_type>>(
417 py,
418 &self._unsafe_inner,
419 $crate::py_class::data_offset::<$crate::PySharedRefCell<$data_type>>($size)
420 );
421 $crate::PySharedRef::new(py, &self._unsafe_inner, data)
422 }
423 }
424 }
425 ''&#x27;)
426
427def generate_class_method(special_name=None, decoration='',
428 slot=None, add_member=False, value_macro=None, value_args=None):

Callers 1

mainFunction · 0.85

Calls 1

generate_caseFunction · 0.85

Tested by

no test coverage detected