Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace `static mut` with `const`, `static`+`AtomicPtr`, or `static`+`UnsafeCell` #26792

Merged
merged 4 commits into from Jun 5, 2020

Use atomic pointers instead of `static mut` for DOM proxy handlers

  • Loading branch information
SimonSapin committed Jun 4, 2020
commit 57d89675b01b49c573b14c1fd0be413d52b8ccdd
@@ -2750,7 +2750,9 @@ def definition_body(self):
unforgeable = CopyUnforgeablePropertiesToInstance(self.descriptor)
if self.descriptor.proxy:
create = """
let handler = RegisterBindings::proxy_handlers::%(concreteType)s;
let handler: *const libc::c_void =
RegisterBindings::proxy_handlers::%(concreteType)s
.load(std::sync::atomic::Ordering::Acquire);
rooted!(in(*cx) let obj = NewProxyObject(
*cx,
handler,
@@ -6744,7 +6746,10 @@ def __init__(self, descriptors):

def definition_body(self):
return CGList([
CGGeneric("proxy_handlers::%s = Bindings::%s::DefineProxyHandler();"
CGGeneric("proxy_handlers::%s.store(\n"
" Bindings::%s::DefineProxyHandler() as *mut _,\n"
" std::sync::atomic::Ordering::Release,\n"
");"
% (desc.name, '::'.join([desc.name + 'Binding'] * 2)))
for desc in self.descriptors
], "\n")
@@ -6758,7 +6763,8 @@ def __init__(self, config):
"#[allow(non_upper_case_globals)]\n" +
"pub mod proxy_handlers {\n" +
"".join(
" pub static mut %s: *const libc::c_void = std::ptr::null();\n"
" pub static %s: std::sync::atomic::AtomicPtr<libc::c_void> =\n"
" std::sync::atomic::AtomicPtr::new(std::ptr::null_mut());\n"
% desc.name
for desc in descriptors
) +
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.