@@ -27,14 +27,11 @@ compile if snappy is installed:
27
27
extern crate libc;
28
28
use libc::size_t;
29
29
30
- #[cfg(nope)]
31
30
#[link(name = "snappy")]
32
31
extern {
33
32
fn snappy_max_compressed_length(source_length: size_t) -> size_t;
34
33
}
35
34
36
- # #[cfg(not(nope))] unsafe fn snappy_max_compressed_length(_: size_t) -> size_t { 0 }
37
- #
38
35
fn main() {
39
36
let x = unsafe { snappy_max_compressed_length(100) };
40
37
println!("max compressed length of a 100 byte buffer: {}", x);
@@ -64,7 +61,6 @@ The `extern` block can be extended to cover the entire snappy API:
64
61
extern crate libc;
65
62
use libc::{c_int, size_t};
66
63
67
- # #[cfg(nope)]
68
64
#[link(name = "snappy")]
69
65
extern {
70
66
fn snappy_compress(input: *const u8,
@@ -82,7 +78,6 @@ extern {
82
78
fn snappy_validate_compressed_buffer(compressed: *const u8,
83
79
compressed_length: size_t) -> c_int;
84
80
}
85
-
86
81
# fn main() {}
87
82
```
88
83
@@ -101,11 +96,8 @@ the allocated memory. The length is less than or equal to the capacity.
101
96
# #![feature(libc)]
102
97
# extern crate libc;
103
98
# use libc :: {c_int, size_t};
104
- #
105
99
# unsafe fn snappy_validate_compressed_buffer (_ : * const u8 , _ : size_t ) -> c_int { 0 }
106
- #
107
100
# fn main () {}
108
- #
109
101
pub fn validate_compressed_buffer (src : & [u8 ]) -> bool {
110
102
unsafe {
111
103
snappy_validate_compressed_buffer (src . as_ptr (), src . len () as size_t ) == 0
@@ -129,13 +121,10 @@ the true length after compression for setting the length.
129
121
# #![feature(libc)]
130
122
# extern crate libc;
131
123
# use libc :: {size_t, c_int};
132
- #
133
124
# unsafe fn snappy_compress (a : * const u8 , b : size_t , c : * mut u8 ,
134
125
# d : * mut size_t ) -> c_int { 0 }
135
126
# unsafe fn snappy_max_compressed_length (a : size_t ) -> size_t { a }
136
- #
137
127
# fn main () {}
138
- #
139
128
pub fn compress (src : & [u8 ]) -> Vec <u8 > {
140
129
unsafe {
141
130
let srclen = src . len () as size_t ;
@@ -159,7 +148,6 @@ format and `snappy_uncompressed_length` will retrieve the exact buffer size requ
159
148
# #![feature(libc)]
160
149
# extern crate libc;
161
150
# use libc :: {size_t, c_int};
162
- #
163
151
# unsafe fn snappy_uncompress (compressed : * const u8 ,
164
152
# compressed_length : size_t ,
165
153
# uncompressed : * mut u8 ,
@@ -168,7 +156,6 @@ format and `snappy_uncompressed_length` will retrieve the exact buffer size requ
168
156
# compressed_length : size_t ,
169
157
# result : * mut size_t ) -> c_int { 0 }
170
158
# fn main () {}
171
- #
172
159
pub fn uncompress (src : & [u8 ]) -> Option <Vec <u8 >> {
173
160
unsafe {
174
161
let srclen = src . len () as size_t ;
@@ -221,16 +208,11 @@ extern fn callback(a: i32) {
221
208
println!("I'm called from C with value {0}", a);
222
209
}
223
210
224
- # #[cfg(nope)]
225
211
#[link(name = "extlib")]
226
212
extern {
227
213
fn register_callback(cb: extern fn(i32)) -> i32;
228
214
fn trigger_callback();
229
215
}
230
- #
231
- # #[cfg(not(nope))] static mut CALLBACK: Option<extern fn(i32)> = None;
232
- # #[cfg(not(nope))] unsafe fn register_callback(cb: extern fn(i32)) -> i32 { CALLBACK = Some(cb); 1 }
233
- # #[cfg(not(nope))] unsafe fn trigger_callback() { CALLBACK.unwrap()(7); }
234
216
235
217
fn main() {
236
218
unsafe {
@@ -289,17 +271,12 @@ extern "C" fn callback(target: *mut RustObject, a: i32) {
289
271
}
290
272
}
291
273
292
- # #[cfg(nope)]
293
274
#[link(name = "extlib")]
294
275
extern {
295
276
fn register_callback(target: *mut RustObject,
296
277
cb: extern fn(*mut RustObject, i32)) -> i32;
297
278
fn trigger_callback();
298
279
}
299
- #
300
- # #[cfg(not(nope))] static mut CALLBACK: Option<(*mut RustObject, extern fn(*mut RustObject, i32))> = None;
301
- # #[cfg(not(nope))] unsafe fn register_callback(target: *mut RustObject, cb: extern fn(*mut RustObject, i32)) -> i32 { CALLBACK = Some((target, cb)); 1 }
302
- # #[cfg(not(nope))] unsafe fn trigger_callback() { let (target, cb) = CALLBACK.unwrap(); cb(target, 7); }
303
280
304
281
fn main() {
305
282
// Create the object that will be referenced in the callback
@@ -413,8 +390,6 @@ this:
413
390
414
391
```rust
415
392
unsafe fn kaboom(ptr: *const i32) -> i32 { *ptr }
416
-
417
- # fn main() {}
418
393
```
419
394
420
395
This function can only be called from an ` unsafe ` block or another ` unsafe ` function.
@@ -487,7 +462,6 @@ extern crate libc;
487
462
extern " stdcall" {
488
463
fn SetEnvironmentVariableA (n : * const u8 , v : * const u8 ) -> libc :: c_int ;
489
464
}
490
-
491
465
# fn main () { }
492
466
```
493
467
@@ -562,7 +536,6 @@ fairly easy, but requires a few things:
562
536
pub extern fn hello_rust () -> * const u8 {
563
537
" Hello, world!\ 0" . as_ptr ()
564
538
}
565
-
566
539
# fn main () {}
567
540
```
568
541
@@ -592,7 +565,6 @@ pub extern fn oh_no() -> i32 {
592
565
Err (_ ) => 0 ,
593
566
}
594
567
}
595
-
596
568
# fn main () {}
597
569
```
598
570
@@ -617,7 +589,6 @@ extern "C" {
617
589
pub fn foo(arg: *mut libc::c_void);
618
590
pub fn bar(arg: *mut libc::c_void);
619
591
}
620
-
621
592
# fn main() {}
622
593
```
623
594
@@ -643,7 +614,6 @@ extern "C" {
643
614
pub fn foo(arg: *mut Foo);
644
615
pub fn bar(arg: *mut Bar);
645
616
}
646
-
647
617
# fn main() {}
648
618
```
649
619
0 commit comments