contextvar_set in CPython
(zelf: &Py<Self>, value: PyObjectRef, vm: &VirtualMachine)
| 342 | |
| 343 | // contextvar_set in CPython |
| 344 | fn set_inner(zelf: &Py<Self>, value: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> { |
| 345 | let ctx = PyContext::current(vm); |
| 346 | |
| 347 | let mut vars = ctx.borrow_vars_mut(); |
| 348 | vars.insert(zelf.to_owned(), value.clone()); |
| 349 | |
| 350 | zelf.cached_id.store(ctx.get_id(), Ordering::SeqCst); |
| 351 | |
| 352 | let cache = ContextVarCache { |
| 353 | object: value, |
| 354 | idx: ctx.inner.idx.get(), |
| 355 | }; |
| 356 | zelf.cached.store(Some(cache)); |
| 357 | |
| 358 | Ok(()) |
| 359 | } |
| 360 | |
| 361 | fn generate_hash(zelf: &Py<Self>, vm: &VirtualMachine) -> PyHash { |
| 362 | let name_hash = vm.state.hash_secret.hash_str(&zelf.name); |