Skip to content

Commit

Permalink
style: Generate top-level function and constant declarations for the …
Browse files Browse the repository at this point in the history
…style crate.

This needs mozilla/cbindgen#362, but I expect it to be
uncontroversial. I'll add a patch to this bug when it's merged to update it.

cbindgen historically didn't include these, but it turns out to be pretty useful
to generate constants for the style crate (since the binding crate is
`servo/ports/geckolib`).

An alternative is to get a completely different cbindgen-generated header for
these, but that seems a bit wasteful. This generates the constants with the
Style prefix (so we'll get `StyleMAX_GRID_LINE` for example), which is very
ugly. But we probably want to eventually stop using the Style prefix and use a
namespace instead, plus it's trivial to do `auto kMaxLine = StyleMAX_GRID_LINE`,
for example, so it's probably not a huge deal.

Another alternative would be to use associated consts, which _are_ generated by
cbindgen. Something like:

```
struct GridConstants([u8; 0]);
impl GridConstants {
    const MAX_GRID_LINE: i32 = 10000;
}
```

Which would yield something like:

```
static const int32 StyleGridConstants_MAX_GRID_LINE = 10000;
```

I'm not sure if you find it preferrable, but I'm also happy to change it in a
follow-up to use this.

We need to fix a few manual C++ function signature definitions to match the C++
declaration.

Differential Revision: https://phabricator.services.mozilla.com/D35197
  • Loading branch information
emilio committed Jul 8, 2019
1 parent 9809124 commit 248b2ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions components/servo_arc/lib.rs
Expand Up @@ -182,7 +182,7 @@ impl<T> Arc<T> {
// FIXME(emilio): Would be so amazing to have
// std::intrinsics::type_name() around, so that we could also report
// a real size.
NS_LogCtor(ptr as *const _, b"ServoArc\0".as_ptr() as *const _, 8);
NS_LogCtor(ptr as *mut _, b"ServoArc\0".as_ptr() as *const _, 8);
}

unsafe {
Expand Down Expand Up @@ -315,7 +315,7 @@ impl<T: ?Sized> Arc<T> {
#[cfg(feature = "gecko_refcount_logging")]
unsafe {
NS_LogDtor(
self.ptr() as *const _,
self.ptr() as *mut _,
b"ServoArc\0".as_ptr() as *const _,
8,
);
Expand Down Expand Up @@ -355,12 +355,12 @@ impl<T: ?Sized> Arc<T> {
#[cfg(feature = "gecko_refcount_logging")]
extern "C" {
fn NS_LogCtor(
aPtr: *const std::os::raw::c_void,
aPtr: *mut std::os::raw::c_void,
aTypeName: *const std::os::raw::c_char,
aSize: u32,
);
fn NS_LogDtor(
aPtr: *const std::os::raw::c_void,
aPtr: *mut std::os::raw::c_void,
aTypeName: *const std::os::raw::c_char,
aSize: u32,
);
Expand Down Expand Up @@ -762,7 +762,7 @@ impl<H, T> Arc<HeaderSlice<H, [T]>> {
if !is_static {
// FIXME(emilio): Would be so amazing to have
// std::intrinsics::type_name() around.
NS_LogCtor(ptr as *const _, b"ServoArc\0".as_ptr() as *const _, 8)
NS_LogCtor(ptr as *mut _, b"ServoArc\0".as_ptr() as *const _, 8)
}
}

Expand Down
8 changes: 4 additions & 4 deletions components/style/rule_tree/mod.rs
Expand Up @@ -950,8 +950,8 @@ mod gecko_leak_checking {
use std::os::raw::{c_char, c_void};

extern "C" {
pub fn NS_LogCtor(aPtr: *const c_void, aTypeName: *const c_char, aSize: u32);
pub fn NS_LogDtor(aPtr: *const c_void, aTypeName: *const c_char, aSize: u32);
fn NS_LogCtor(aPtr: *mut c_void, aTypeName: *const c_char, aSize: u32);
fn NS_LogDtor(aPtr: *mut c_void, aTypeName: *const c_char, aSize: u32);
}

static NAME: &'static [u8] = b"RuleNode\0";
Expand All @@ -960,15 +960,15 @@ mod gecko_leak_checking {
pub fn log_ctor(ptr: *const RuleNode) {
let s = NAME as *const [u8] as *const u8 as *const c_char;
unsafe {
NS_LogCtor(ptr as *const c_void, s, size_of::<RuleNode>() as u32);
NS_LogCtor(ptr as *mut c_void, s, size_of::<RuleNode>() as u32);
}
}

/// Logs the destruction of a heap-allocated object to Gecko's leak-checking machinery.
pub fn log_dtor(ptr: *const RuleNode) {
let s = NAME as *const [u8] as *const u8 as *const c_char;
unsafe {
NS_LogDtor(ptr as *const c_void, s, size_of::<RuleNode>() as u32);
NS_LogDtor(ptr as *mut c_void, s, size_of::<RuleNode>() as u32);
}
}

Expand Down

0 comments on commit 248b2ac

Please sign in to comment.