Skip to content

Commit 0e1432e

Browse files
committed
---
yaml --- r: 148465 b: refs/heads/try2 c: d049c27 h: refs/heads/master i: 148463: 51428fa v: v3
1 parent 9055d5c commit 0e1432e

39 files changed

+450
-608
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 813db08fe6ffb7795b4c6db59b2f9d149c890242
8+
refs/heads/try2: d049c27f5b7e100ee0a286dfa8886d89b78e03e9
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/guide-ffi.md

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -249,143 +249,6 @@ fn main() {
249249
}
250250
~~~~
251251

252-
# Callbacks from C code to Rust functions
253-
254-
Some external libraries require the usage of callbacks to report back their
255-
current state or intermediate data to the caller.
256-
It is possible to pass functions defined in Rust to an external library.
257-
The requirement for this is that the callback function is marked as `extern`
258-
with the correct calling convention to make it callable from C code.
259-
260-
The callback function that can then be sent to through a registration call
261-
to the C library and afterwards be invoked from there.
262-
263-
A basic example is:
264-
265-
Rust code:
266-
~~~~ {.xfail-test}
267-
extern fn callback(a:i32) {
268-
println!("I'm called from C with value {0}", a);
269-
}
270-
271-
#[link(name = "extlib")]
272-
extern {
273-
fn register_callback(cb: extern "C" fn(i32)) -> i32;
274-
fn trigger_callback();
275-
}
276-
277-
fn main() {
278-
unsafe {
279-
register_callback(callback);
280-
trigger_callback(); // Triggers the callback
281-
}
282-
}
283-
~~~~
284-
285-
C code:
286-
~~~~ {.xfail-test}
287-
typedef void (*rust_callback)(int32_t);
288-
rust_callback cb;
289-
290-
int32_t register_callback(rust_callback callback) {
291-
cb = callback;
292-
return 1;
293-
}
294-
295-
void trigger_callback() {
296-
cb(7); // Will call callback(7) in Rust
297-
}
298-
~~~~
299-
300-
In this example will Rust's `main()` will call `do_callback()` in C,
301-
which would call back to `callback()` in Rust.
302-
303-
304-
## Targetting callbacks to Rust objects
305-
306-
The former example showed how a global function can be called from C-Code.
307-
However it is often desired that the callback is targetted to a special
308-
Rust object. This could be the object that represents the wrapper for the
309-
respective C object.
310-
311-
This can be achieved by passing an unsafe pointer to the object down to the
312-
C library. The C library can then include the pointer to the Rust object in
313-
the notification. This will provide a unsafe possibility to access the
314-
referenced Rust object in callback.
315-
316-
Rust code:
317-
~~~~ {.xfail-test}
318-
319-
struct RustObject {
320-
a: i32,
321-
// other members
322-
}
323-
324-
extern fn callback(target: *RustObject, a:i32) {
325-
println!("I'm called from C with value {0}", a);
326-
(*target).a = a; // Update the value in RustObject with the value received from the callback
327-
}
328-
329-
#[link(name = "extlib")]
330-
extern {
331-
fn register_callback(target: *RustObject, cb: extern "C" fn(*RustObject, i32)) -> i32;
332-
fn trigger_callback();
333-
}
334-
335-
fn main() {
336-
// Create the object that will be referenced in the callback
337-
let rust_object = ~RustObject{a: 5, ...};
338-
339-
unsafe {
340-
// Gets a raw pointer to the object
341-
let target_addr:*RustObject = ptr::to_unsafe_ptr(rust_object);
342-
register_callback(target_addr, callback);
343-
trigger_callback(); // Triggers the callback
344-
}
345-
}
346-
~~~~
347-
348-
C code:
349-
~~~~ {.xfail-test}
350-
typedef void (*rust_callback)(int32_t);
351-
void* cb_target;
352-
rust_callback cb;
353-
354-
int32_t register_callback(void* callback_target, rust_callback callback) {
355-
cb_target = callback_target;
356-
cb = callback;
357-
return 1;
358-
}
359-
360-
void trigger_callback() {
361-
cb(cb_target, 7); // Will call callback(&rustObject, 7) in Rust
362-
}
363-
~~~~
364-
365-
## Asynchronous callbacks
366-
367-
In the already given examples the callbacks are invoked as a direct reaction
368-
to a function call to the external C library.
369-
The control over the current thread switched from Rust to C to Rust for the
370-
execution of the callback, but in the end the callback is executed on the
371-
same thread (and Rust task) that lead called the function which triggered
372-
the callback.
373-
374-
Things get more complicated when the external library spawns it's own threads
375-
and invokes callbacks from there.
376-
In these cases access to Rust data structures inside he callbacks is
377-
especially unsafe and proper synchronization mechanisms must be used.
378-
Besides classical synchronization mechanisms like mutexes one possibility in
379-
Rust is to use channels (in `std::comm`) to forward data from the C thread
380-
that invoked the callback into a Rust task.
381-
382-
If an asychronous callback targets a special object in the Rust address space
383-
it is also absolutely necessary that no more callbacks are performed by the
384-
C library after the respective Rust object get's destroyed.
385-
This can be achieved by unregistering the callback it the object's
386-
destructor and designing the library in a way that guarantees that no
387-
callback will be performed after unregistration.
388-
389252
# Linking
390253

391254
The `link` attribute on `extern` blocks provides the basic building block for

branches/try2/doc/guide-testing.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
3333
# Unit testing in Rust
3434

3535
Rust has built in support for simple unit testing. Functions can be
36-
marked as unit tests using the `test` attribute.
36+
marked as unit tests using the 'test' attribute.
3737

3838
~~~
3939
#[test]
@@ -44,13 +44,13 @@ fn return_none_if_empty() {
4444

4545
A test function's signature must have no arguments and no return
4646
value. To run the tests in a crate, it must be compiled with the
47-
`--test` flag: `rustc myprogram.rs --test -o myprogram-tests`. Running
47+
'--test' flag: `rustc myprogram.rs --test -o myprogram-tests`. Running
4848
the resulting executable will run all the tests in the crate. A test
4949
is considered successful if its function returns; if the task running
5050
the test fails, through a call to `fail!`, a failed `check` or
5151
`assert`, or some other (`assert_eq`, ...) means, then the test fails.
5252

53-
When compiling a crate with the `--test` flag `--cfg test` is also
53+
When compiling a crate with the '--test' flag '--cfg test' is also
5454
implied, so that tests can be conditionally compiled.
5555

5656
~~~
@@ -64,17 +64,17 @@ mod tests {
6464
~~~
6565

6666
Additionally `#[test]` items behave as if they also have the
67-
`#[cfg(test)]` attribute, and will not be compiled when the `--test` flag
67+
`#[cfg(test)]` attribute, and will not be compiled when the --test flag
6868
is not used.
6969

70-
Tests that should not be run can be annotated with the `ignore`
70+
Tests that should not be run can be annotated with the 'ignore'
7171
attribute. The existence of these tests will be noted in the test
7272
runner output, but the test will not be run. Tests can also be ignored
7373
by configuration so, for example, to ignore a test on windows you can
7474
write `#[ignore(cfg(target_os = "win32"))]`.
7575

7676
Tests that are intended to fail can be annotated with the
77-
`should_fail` attribute. The test will be run, and if it causes its
77+
'should_fail' attribute. The test will be run, and if it causes its
7878
task to fail then the test will be counted as successful; otherwise it
7979
will be counted as a failure. For example:
8080

@@ -87,11 +87,11 @@ fn test_out_of_bounds_failure() {
8787
}
8888
~~~
8989

90-
A test runner built with the `--test` flag supports a limited set of
90+
A test runner built with the '--test' flag supports a limited set of
9191
arguments to control which tests are run: the first free argument
9292
passed to a test runner specifies a filter used to narrow down the set
93-
of tests being run; the `--ignored` flag tells the test runner to run
94-
only tests with the `ignore` attribute.
93+
of tests being run; the '--ignored' flag tells the test runner to run
94+
only tests with the 'ignore' attribute.
9595

9696
## Parallelism
9797

branches/try2/doc/rust.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ include:
484484

485485
* `fmt!` : format data into a string
486486
* `env!` : look up an environment variable's value at compile time
487-
* `file!`: return the path to the file being compiled
488487
* `stringify!` : pretty-print the Rust expression given as an argument
489488
* `include!` : include the Rust expression in the given file
490489
* `include_str!` : include the contents of the given file as a string

branches/try2/src/compiletest/runtest.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
206206
}
207207

208208
fn make_pp_args(config: &config, _testfile: &Path) -> ProcArgs {
209-
let args = ~[~"-", ~"--pretty", ~"normal",
210-
~"--target=" + config.target];
209+
let args = ~[~"-", ~"--pretty", ~"normal"];
211210
// FIXME (#9639): This needs to handle non-utf8 paths
212211
return ProcArgs {prog: config.rustc_path.as_str().unwrap().to_owned(), args: args};
213212
}
@@ -238,15 +237,9 @@ actual:\n\
238237

239238
fn make_typecheck_args(config: &config, props: &TestProps, testfile: &Path) -> ProcArgs {
240239
let aux_dir = aux_output_dir_name(config, testfile);
241-
let target = if props.force_host {
242-
config.host.as_slice()
243-
} else {
244-
config.target.as_slice()
245-
};
246240
// FIXME (#9639): This needs to handle non-utf8 paths
247241
let mut args = ~[~"-",
248242
~"--no-trans", ~"--lib",
249-
~"--target=" + target,
250243
~"-L", config.build_base.as_str().unwrap().to_owned(),
251244
~"-L",
252245
aux_dir.as_str().unwrap().to_owned()];

branches/try2/src/libextra/base64.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,8 @@ impl<'a> FromBase64 for &'a str {
237237
}
238238

239239
for (idx, byte) in it {
240-
match byte as char {
241-
'='|'\r'|'\n' => continue,
242-
_ => return Err(InvalidBase64Character(self.char_at(idx), idx)),
240+
if (byte as char) != '=' {
241+
return Err(InvalidBase64Character(self.char_at(idx), idx));
243242
}
244243
}
245244

@@ -311,8 +310,6 @@ mod test {
311310
fn test_from_base64_newlines() {
312311
assert_eq!("Zm9v\r\nYmFy".from_base64().unwrap(),
313312
"foobar".as_bytes().to_owned());
314-
assert_eq!("Zm9vYg==\r\n".from_base64().unwrap(),
315-
"foob".as_bytes().to_owned());
316313
}
317314
318315
#[test]

branches/try2/src/libextra/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ impl<T : Iterator<char>> Parser<T> {
909909
}
910910
}
911911

912-
let exp: f64 = num::pow(10u as f64, exp);
912+
let exp: f64 = num::pow_with_uint(10u, exp);
913913
if neg_exp {
914914
res /= exp;
915915
} else {

branches/try2/src/libextra/uuid.rs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Examples of string representations:
5757

5858
use std::str;
5959
use std::vec;
60-
use std::num::FromStrRadix;
60+
use std::num::{FromStrRadix, Zero};
6161
use std::char::Char;
6262
use std::container::Container;
6363
use std::to_str::ToStr;
@@ -158,8 +158,9 @@ static UuidGroupLens: [uint, ..5] = [8u, 4u, 4u, 4u, 12u];
158158

159159
/// UUID support
160160
impl Uuid {
161+
161162
/// Returns a nil or empty UUID (containing all zeroes)
162-
pub fn nil() -> Uuid {
163+
pub fn new_nil() -> Uuid {
163164
let uuid = Uuid{ bytes: [0, .. 16] };
164165
uuid
165166
}
@@ -422,17 +423,24 @@ impl Uuid {
422423

423424
Ok(Uuid::from_bytes(ub).unwrap())
424425
}
425-
426-
/// Tests if the UUID is nil
427-
pub fn is_nil(&self) -> bool {
428-
return self.bytes.iter().all(|&b| b == 0);
429-
}
430426
}
431427

432428
impl Default for Uuid {
433429
/// Returns the nil UUID, which is all zeroes
434430
fn default() -> Uuid {
435-
Uuid::nil()
431+
Uuid::new_nil()
432+
}
433+
}
434+
435+
impl Zero for Uuid {
436+
/// Returns the nil UUID, which is all zeroes
437+
fn zero() -> Uuid {
438+
Uuid::new_nil()
439+
}
440+
441+
/// Tests if the UUID is nil or all zeroes
442+
fn is_zero(&self) -> bool {
443+
return self.bytes.iter().all(|&b| b == 0);
436444
}
437445
}
438446

@@ -513,15 +521,24 @@ mod test {
513521
use super::*;
514522
use std::str;
515523
use std::rand;
524+
use std::num::Zero;
516525
use std::io::MemWriter;
517526

518527
#[test]
519-
fn test_nil() {
520-
let nil = Uuid::nil();
521-
let not_nil = Uuid::new_v4();
528+
fn test_new_nil() {
529+
let nil = Uuid::new_nil();
530+
let nb = nil.to_bytes();
531+
532+
assert!(nb.iter().all(|&b| b == 0));
533+
}
534+
535+
#[test]
536+
fn test_zero() {
537+
let uz: Uuid = Zero::zero();
538+
let nz = Uuid::new_v4();
522539

523-
assert!(nil.is_nil());
524-
assert!(!not_nil.is_nil());
540+
assert!(uz.is_zero());
541+
assert!(! nz.is_zero());
525542
}
526543

527544
#[test]
@@ -602,7 +619,7 @@ mod test {
602619
assert!(Uuid::parse_string("urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8").is_ok());
603620

604621
// Nil
605-
let nil = Uuid::nil();
622+
let nil = Uuid::new_nil();
606623
assert!(Uuid::parse_string("00000000000000000000000000000000").unwrap() == nil);
607624
assert!(Uuid::parse_string("00000000-0000-0000-0000-000000000000").unwrap() == nil);
608625

branches/try2/src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,7 @@ impl<'a, 'b> Visitor<()> for MacroDefVisitor<'a, 'b> {
17201720
}
17211721
_ => {}
17221722
}
1723+
visit::walk_item(self, item, ());
17231724
}
17241725
}
17251726

branches/try2/src/librustc/middle/borrowck/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ checker uses a data flow propagation to compute the full set of loans
179179
in scope at each expression and then uses that set to decide whether
180180
that expression is legal. Remember that the scope of loan is defined
181181
by its lifetime LT. We sometimes say that a loan which is in-scope at
182-
a particular point is an "outstanding loan", and the set of
182+
a particular point is an "outstanding loan", aand the set of
183183
restrictions included in those loans as the "outstanding
184184
restrictions".
185185

branches/try2/src/librustc/middle/check_const.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,11 @@ pub fn check_expr(v: &mut CheckCrateVisitor,
177177
}
178178
}
179179
}
180+
ExprParen(e) => { check_expr(v, sess, def_map, method_map,
181+
tcx, e, is_const); }
180182
ExprVstore(_, ExprVstoreSlice) |
181183
ExprVec(_, MutImmutable) |
182184
ExprAddrOf(MutImmutable, _) |
183-
ExprParen(..) |
184185
ExprField(..) |
185186
ExprIndex(..) |
186187
ExprTup(..) |

0 commit comments

Comments
 (0)