Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use atomic pointers instead of static mut for DOM proxy handlers
  • Loading branch information
SimonSapin committed Jun 4, 2020
1 parent 3367db6 commit 57d8967
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand All @@ -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
) +
Expand Down

0 comments on commit 57d8967

Please sign in to comment.