Skip to content

Commit a262b68

Browse files
committed
Merge remote-tracking branch 'servo/master' into aligned-attribute
2 parents 31a4041 + 3ef1a27 commit a262b68

File tree

6 files changed

+76
-5
lines changed

6 files changed

+76
-5
lines changed

bindgen-integration/cpp/Test.cc

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#include "Test.h"
22

3+
const int Test::COUNTDOWN[] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
4+
const int* Test::COUNTDOWN_PTR = Test::COUNTDOWN;
5+
6+
const int* Test::countdown() {
7+
return COUNTDOWN;
8+
}
9+
310
const char* Test::name() {
411
return "Test";
512
}

bindgen-integration/cpp/Test.h

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ class Test {
77
static const char* name();
88
Test(int foo);
99
Test(double foo);
10+
11+
static const int COUNTDOWN[];
12+
static const int* COUNTDOWN_PTR;
13+
static const int* countdown();
1014
};
1115

1216
namespace testing {

bindgen-integration/src/lib.rs

+23
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@ mod bindings {
33
}
44

55
use std::ffi::CStr;
6+
use std::os::raw::c_int;
7+
8+
#[test]
9+
fn test_static_array() {
10+
let mut test = unsafe { bindings::Test_COUNTDOWN.as_ptr() };
11+
let expected = unsafe { bindings::Test_countdown()};
12+
let also_expected = unsafe { bindings::Test_COUNTDOWN_PTR };
13+
assert!(!test.is_null());
14+
assert_eq!(also_expected, expected);
15+
assert_eq!(test, also_expected);
16+
17+
let mut expected = 10;
18+
unsafe {
19+
loop {
20+
assert_eq!(*test, expected);
21+
if *test == 0 {
22+
break;
23+
}
24+
test = test.offset(1);
25+
expected -= 1;
26+
}
27+
}
28+
}
629

730
#[test]
831
fn test_static_method() {

src/codegen/mod.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -2404,31 +2404,48 @@ mod utils {
24042404

24052405
#[inline]
24062406
pub unsafe fn as_slice(&self, len: usize) -> &[T] {
2407-
::std::slice::from_raw_parts(self.as_ptr(), len)
2407+
::$prefix::slice::from_raw_parts(self.as_ptr(), len)
24082408
}
24092409

24102410
#[inline]
24112411
pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] {
2412-
::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
2412+
::$prefix::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
24132413
}
24142414
}
24152415
)
24162416
.unwrap();
24172417

24182418
let incomplete_array_debug_impl = quote_item!(ctx.ext_cx(),
2419-
impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> {
2420-
fn fmt(&self, fmt: &mut ::std::fmt::Formatter)
2421-
-> ::std::fmt::Result {
2419+
impl<T> ::$prefix::fmt::Debug for __IncompleteArrayField<T> {
2420+
fn fmt(&self, fmt: &mut ::$prefix::fmt::Formatter)
2421+
-> ::$prefix::fmt::Result {
24222422
fmt.write_str("__IncompleteArrayField")
24232423
}
24242424
}
24252425
)
24262426
.unwrap();
24272427

2428+
let incomplete_array_clone_impl = quote_item!(&ctx.ext_cx(),
2429+
impl<T> ::$prefix::clone::Clone for __IncompleteArrayField<T> {
2430+
#[inline]
2431+
fn clone(&self) -> Self {
2432+
Self::new()
2433+
}
2434+
}
2435+
)
2436+
.unwrap();
2437+
2438+
let incomplete_array_copy_impl = quote_item!(&ctx.ext_cx(),
2439+
impl<T> ::$prefix::marker::Copy for __IncompleteArrayField<T> {}
2440+
)
2441+
.unwrap();
2442+
24282443
let items = vec![
24292444
incomplete_array_decl,
24302445
incomplete_array_impl,
24312446
incomplete_array_debug_impl,
2447+
incomplete_array_clone_impl,
2448+
incomplete_array_copy_impl,
24322449
];
24332450

24342451
let old_items = mem::replace(result, items);

tests/expectations/tests/class.rs

+15
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ impl <T> ::std::fmt::Debug for __IncompleteArrayField<T> {
3131
fmt.write_str("__IncompleteArrayField")
3232
}
3333
}
34+
impl <T> ::std::clone::Clone for __IncompleteArrayField<T> {
35+
#[inline]
36+
fn clone(&self) -> Self { Self::new() }
37+
}
38+
impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
3439
#[repr(C)]
3540
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
3641
impl <T> __BindgenUnionField<T> {
@@ -112,6 +117,16 @@ fn bindgen_test_layout_WithDtor() {
112117
assert_eq!(::std::mem::align_of::<WithDtor>() , 4usize);
113118
}
114119
#[repr(C)]
120+
pub struct IncompleteArrayNonCopiable {
121+
pub whatever: *mut ::std::os::raw::c_void,
122+
pub incomplete_array: __IncompleteArrayField<C>,
123+
}
124+
#[test]
125+
fn bindgen_test_layout_IncompleteArrayNonCopiable() {
126+
assert_eq!(::std::mem::size_of::<IncompleteArrayNonCopiable>() , 8usize);
127+
assert_eq!(::std::mem::align_of::<IncompleteArrayNonCopiable>() , 8usize);
128+
}
129+
#[repr(C)]
115130
#[derive(Debug, Copy)]
116131
pub struct Union {
117132
pub d: __BindgenUnionField<f32>,

tests/headers/class.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class WithDtor {
3232
~WithDtor() {}
3333
};
3434

35+
class IncompleteArrayNonCopiable {
36+
void* whatever;
37+
C incomplete_array[];
38+
};
39+
3540
union Union {
3641
float d;
3742
int i;

0 commit comments

Comments
 (0)