Commit Graph

65 Commits

Author SHA1 Message Date
Ben Noordhuis
6121acf97d libnative: fix epoll_event struct layout
Make the definition of epoll_event use natural alignment on all
architectures except x86_64.

Before this commit, the struct was always 12 bytes big, which works okay
on x86 and x86_64 but not on ARM and MIPS, where it should be 16 bytes
big with the `data` field aligned on an 8 byte boundary.
2014-02-02 19:55:41 +01:00
Brendan Zabarauskas
729060dbb9 Remove Times trait
`Times::times` was always a second-class loop because it did not support the `break` and `continue` operations. Its playful appeal was then lost after `do` was disabled for closures. It's time to let this one go.
2014-01-30 14:52:25 +11:00
bors
c3ae182d5c auto merge of #11754 : alexcrichton/rust/unused-result, r=brson
The general consensus is that we want to move away from conditions for I/O, and I propose a two-step plan for doing so:

1. Warn about unused `Result` types. When all of I/O returns `Result`, it will require you inspect the return value for an error *only if* you have a result you want to look at. By default, for things like `write` returning `Result<(), Error>`, these will all go silently ignored. This lint will prevent blind ignorance of these return values, letting you know that there's something you should do about them.

2. Implement a `try!` macro:

```
macro_rules! try( ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) }) )
```

With these two tools combined, I feel that we get almost all the benefits of conditions. The first step (the lint) is a sanity check that you're not ignoring return values at callsites. The second step is to provide a convenience method of returning early out of a sequence of computations. After thinking about this for awhile, I don't think that we need the so-called "do-notation" in the compiler itself because I think it's just *too* specialized. Additionally, the `try!` macro is super lightweight, easy to understand, and works almost everywhere. As soon as you want to do something more fancy, my answer is "use match".

Basically, with these two tools in action, I would be comfortable removing conditions. What do others think about this strategy?

----

This PR specifically implements the `unused_result` lint. I actually added two lints, `unused_result` and `unused_must_use`, and the first commit has the rationale for why `unused_result` is turned off by default.
2014-01-29 09:46:34 -08:00
Alex Crichton
c13a62593c Flag Result as #[must_use] and deal with fallout. 2014-01-29 08:35:49 -08:00
Scott Lawrence
518a5e08c0 Removing do keyword from libnative 2014-01-29 09:15:41 -05:00
xales
e901c4caf3 Set SO_REUSEADDR by default in libnative.
Fixes std::net test error when re-running too quickly.
2014-01-27 20:59:15 -05:00
Salem Talha
cc61fc0994 Removed all instances of XXX in preparation for relaxing of FIXME rule 2014-01-26 14:42:53 -05:00
Huon Wilson
0aef487a5c std,extra: Make some types public and other private.
These are either returned from public functions, and really should
appear in the documentation, but don't since they're private, or are
implementation details that are currently public.
2014-01-26 13:33:05 +11:00
bors
dc48adc69f auto merge of #11748 : brson/rust/timerfdandroid, r=alexcrichton
It doesn't seem to exist.
2014-01-24 16:11:31 -08:00
bors
8de3fab82a auto merge of #11732 : luqmana/rust/native-getaddrinfo, r=alexcrichton
The last bit I needed to be able to use libnative :P
2014-01-24 14:51:36 -08:00
Luqman Aden
adb5128020 libnative: Avoid gai_strerror on windows. 2014-01-24 16:44:16 -05:00
bors
bf9c25562d auto merge of #11686 : mankyKitty/rust/rename-invert-to-flip-issue-10632, r=alexcrichton
Renamed the ```invert()``` function in ```iter.rs``` to ```flip()```, from #10632 

Also renamed the ```Invert<T>``` type to ```Flip<T>```.

Some related code comments changed. Documentation that I could find has
been updated, and all the instances I could locate where the
function/type were called have been updated as well.

This is my first contribution to Rust! Apologies in advance if I've snarfed the 
PR process, I'm not used to rebase.

I initially had issues with the ```codegen``` section of the tests failing, however
the ```make check``` process is not reporting any failures at this time. I think
that was a local env issue more than me facerolling my changes. :)
2014-01-23 19:56:35 -08:00
Sean Chalmers
292ed3e55c Update flip() to be rev().
Consensus leaned in favour of using rev instead of flip.
2014-01-23 22:18:18 +01:00
Sean Chalmers
55d6e0e1b7 Rename Invert to Flip - Issue 10632
Renamed the invert() function in iter.rs to flip().

Also renamed the Invert<T> type to Flip<T>.

Some related code comments changed. Documentation that I could find has
been updated, and all the instances I could locate where the
function/type were called have been updated as well.
2014-01-23 21:50:18 +01:00
Alex Crichton
aa78da3f45 Handle EINTR in epoll for native timers 2014-01-23 12:34:01 -08:00
Brian Anderson
e70ca23b8d native: Don't use timerfd on Android
It doesn't seem to exist.
2014-01-23 01:08:34 -08:00
bors
19e0cbe420 auto merge of #11682 : thestinger/rust/vector, r=brson
This is just an initial implementation and does not yet fully replace `~[T]`. A generic initialization syntax for containers is missing, and the slice functionality needs to be reworked to make auto-slicing unnecessary.

Traits for supporting indexing properly are also required. This also needs to be fixed to make ring buffers as easy to use as vectors.

The tests and documentation for `~[T]` can be ported over to this type when it is removed. I don't really expect DST to happen for vectors as having both `~[T]` and `Vec<T>` is overcomplicated and changing the slice representation to 3 words is not at all appealing. Unlike with traits, it's possible (and easy) to implement `RcSlice<T>` and `GcSlice<T>` without compiler help.
2014-01-22 23:26:33 -08:00
Daniel Micay
802d41fe23 libc: switch free to the proper signature
This does not attempt to fully propagate the mutability everywhere, but
gives new code a hint to avoid the same issues.
2014-01-22 23:13:53 -05:00
Alex Crichton
b8e43838cf Implement native timers
Native timers are a much hairier thing to deal with than green timers due to the
interface that we would like to expose (both a blocking sleep() and a
channel-based interface). I ended up implementing timers in three different ways
for the various platforms that we supports.

In all three of the implementations, there is a worker thread which does send()s
on channels for timers. This worker thread is initialized once and then
communicated to in a platform-specific manner, but there's always a shared
channel available for sending messages to the worker thread.

* Windows - I decided to use windows kernel timer objects via
  CreateWaitableTimer and SetWaitableTimer in order to provide sleeping
  capabilities. The worker thread blocks via WaitForMultipleObjects where one of
  the objects is an event that is used to wake up the helper thread (which then
  drains the incoming message channel for requests).

* Linux/(Android?) - These have the ideal interface for implementing timers,
  timerfd_create. Each timer corresponds to a timerfd, and the helper thread
  uses epoll to wait for all active timers and then send() for the next one that
  wakes up. The tricky part in this implementation is updating a timerfd, but
  see the implementation for the fun details

* OSX/FreeBSD - These obviously don't have the windows APIs, and sadly don't
  have the timerfd api available to them, so I have thrown together a solution
  which uses select() plus a timeout in order to ad-hoc-ly implement a timer
  solution for threads. The implementation is backed by a sorted array of timers
  which need to fire. As I said, this is an ad-hoc solution which is certainly
  not accurate timing-wise. I have done this implementation due to the lack of
  other primitives to provide an implementation, and I've done it the best that
  I could, but I'm sure that there's room for improvement.

I'm pretty happy with how these implementations turned out. In theory we could
drop the timerfd implementation and have linux use the select() + timeout
implementation, but it's so inaccurate that I would much rather continue to use
timerfd rather than my ad-hoc select() implementation.

The only change that I would make to the API in general is to have a generic
sleep() method on an IoFactory which doesn't require allocating a Timer object.
For everything but windows it's super-cheap to request a blocking sleep for a
set amount of time, and it's probably worth it to provide a sleep() which
doesn't do something like allocate a file descriptor on linux.
2014-01-22 19:31:39 -08:00
Luqman Aden
5aa31c43a0 libnative: Implement get_host_addresses. 2014-01-22 20:05:06 -05:00
Huon Wilson
39713b8295 Remove unnecessary parentheses. 2014-01-21 22:00:18 +11:00
Daniel Micay
ae2a5ecbf6 handle zero-size allocations correctly
The `malloc` family of functions may return a null pointer for a
zero-size allocation, which should not be interpreted as an
out-of-memory error.

If the implementation does not return a null pointer, then handling
this will result in memory savings for zero-size types.

This also switches some code to `malloc_raw` in order to maintain a
centralized point for handling out-of-memory in `rt::global_heap`.

Closes #11634
2014-01-17 23:41:31 -05:00
Derek Chiang
f98f76e3a7 Fixing a typo: bookeeping -> bookkeeping 2014-01-16 14:17:56 +08:00
Daniel Micay
197fe67e11 register snapshots 2014-01-15 08:22:56 -05:00
Brian Anderson
46905c04f5 Bump version to 0.10-pre 2014-01-12 17:45:22 -08:00
bors
f78293c274 auto merge of #11360 : huonw/rust/stack_bounds, r=alexcrichton
We just approximate with a 2MB stack for native::start.
2014-01-09 20:21:17 -08:00
Alex Crichton
a18282c3d0 Remove eof() from io::Reader 2014-01-09 09:27:10 -08:00
Brian Anderson
da43832034 doc: Add libgreen and libnative to the index 2014-01-07 20:49:13 -08:00
bors
7dbd12a4fa auto merge of #11353 : alexcrichton/rust/improve-logging, r=brson
This will allow capturing of common things like logging messages, stdout prints
(using stdio println), and failure messages (printed to stderr).  Any new prints
added to libstd should be funneled through these task handles to allow capture
as well.

Additionally, this commit redirects logging back through a `Logger` trait so the
log level can be usefully consumed by an arbitrary logger.

This commit also introduces methods to set the task-local stdout handles:

* std::io::stdio::set_stdout
* std::io::stdio::set_stderr
* std::io::logging::set_logger

These methods all return the previous logger just in case it needs to be used
for inspection.

I plan on using this infrastructure for extra::test soon, but we don't quite
have the primitives that I'd like to use for it, so it doesn't migrate
extra::test at this time.

Closes #6369
2014-01-07 09:41:35 -08:00
bors
983f307e12 auto merge of #11348 : alexcrichton/rust/snapshots, r=brson 2014-01-07 07:11:36 -08:00
Huon Wilson
65ce505819 std::rt: require known stack bounds for all tasks.
We just approximate with a 1 or 2 MB stack for native::start.
2014-01-07 15:14:55 +11:00
Alex Crichton
03e91573c7 Don't read forever on a file descriptor
Similarly to the recent commit to do this for networking, there's no reason that
a read on a file descriptor should continue reading until the entire buffer is
full. This makes sense when dealing with literal files, but when dealing with
things like stdin this doesn't make sense.
2014-01-06 16:32:51 -08:00
Alex Crichton
ac2a24ecc9 Support arbitrary stdout/stderr/logger handles
This will allow capturing of common things like logging messages, stdout prints
(using stdio println), and failure messages (printed to stderr).  Any new prints
added to libstd should be funneled through these task handles to allow capture
as well.

Additionally, this commit redirects logging back through a `Logger` trait so the
log level can be usefully consumed by an arbitrary logger.

This commit also introduces methods to set the task-local stdout handles:

* std::io::stdio::set_stdout
* std::io::stdio::set_stderr
* std::io::logging::set_logger

These methods all return the previous logger just in case it needs to be used
for inspection.

I plan on using this infrastructure for extra::test soon, but we don't quite
have the primitives that I'd like to use for it, so it doesn't migrate
extra::test at this time.

Closes #6369
2014-01-06 13:19:53 -08:00
bors
0da105a8b7 auto merge of #11334 : alexcrichton/rust/fix-native-tcp, r=pcwalton
libnative erroneously would attempt to fill the entire buffer in a call to
`read` before returning, when rather it should return immediately because
there's not guaranteed to be any data that will ever be received again.

Close #11328
2014-01-06 10:31:46 -08:00
Alex Crichton
6b2a6cb3fe Register new snapshots 2014-01-06 09:26:47 -08:00
bors
c58bb23521 auto merge of #11315 : alexcrichton/rust/issue-11309, r=huonw
There was a scheduling race where a child may not increment the global task
count before the parent exits, and the parent would then think that there are no
more tasks left.

Closes #11039
2014-01-06 00:31:57 -08:00
Alex Crichton
11e568c886 Don't wait for a full buffer when reading TCP
libnative erroneously would attempt to fill the entire buffer in a call to
`read` before returning, when rather it should return immediately because
there's not guaranteed to be any data that will ever be received again.

Close #11328
2014-01-06 00:08:18 -08:00
Alex Crichton
9c8813f006 Guarantee that native tasks wait for children
There was a scheduling race where a child may not increment the global task
count before the parent exits, and the parent would then think that there are no
more tasks left.
2014-01-05 22:28:23 -08:00
bors
4bca7fdf9b auto merge of #11313 : alexcrichton/rust/fix-native-failure, r=pcwalton 2014-01-05 11:36:46 -08:00
bors
1d9e66c0eb auto merge of #11304 : alexcrichton/rust/eintr, r=brson
Closes #11214
2014-01-05 10:16:44 -08:00
Alex Crichton
eadfe0e3c9 Don't abort the process in native::start
If the main closure failed, then the `exit_code` variable would still be `None`,
and the `unwrap()` was failing (triggering a process abort). This changes the
`unwrap()` to an `unwrap_or()` in order to prevent process abort and detect when
the native task failed.
2014-01-05 09:20:31 -08:00
Alex Crichton
674d24e2e6 Handle EINTR throughout libnative
Closes #11214
2014-01-05 09:19:40 -08:00
bors
b432e82515 auto merge of #11306 : alexcrichton/rust/native-bounds, r=pcwalton
This allows inspection of the current task's bounds regardless of what the
underlying task is.

Closes #11293
2014-01-04 10:16:51 -08:00
Alex Crichton
dcaf10f8de Add a stack_bounds function to the Runtime trait
This allows inspection of the current task's bounds regardless of what the
underlying task is.

Closes #11293
2014-01-04 00:08:03 -08:00
Brian Anderson
56ec9c23a4 Bump version to 0.9 2014-01-02 12:55:20 -08:00
bors
ee634e3ac4 auto merge of #11265 : c-a/rust/byteswap_from, r=alexcrichton
This patchset adds intrinsics similar to the to_[be|le][16|32|64] intrinsics but for going in the reverse direction, e.g. from big/little endian to host endian. Implementation wise they do exactly the same as the corresponding to_* functions but I think it anyway make sense to have them since using the to_* functions in the reverse direction is not entirely intuitive.

The first patch adds the intrinsics and the two following changes instances of bswap* to use the [to|from]_* intrinsics instead.
2014-01-02 00:51:51 -08:00
Carl-Anton Ingmarsson
19d8ab8d5a libnative: Use [from|to]_be16 instead of bswap16 2014-01-01 22:27:49 +01:00
bors
48918fab72 auto merge of #11212 : alexcrichton/rust/local-task-count, r=brson
For libgreen, bookeeping should not be global but rather on a per-pool basis.
Inside libnative, it's known that there must be a global counter with a
mutex/cvar.

The benefit of taking this strategy is to remove this functionality from libstd
to allow fine-grained control of it through libnative/libgreen. Notably, helper
threads in libnative can manually decrement the global count so they don't count
towards the global count of threads. Also, the shutdown process of *all* sched
pools is now dependent on the number of tasks in the pool being 0 rather than
this only being a hardcoded solution for the initial sched pool in libgreen.

This involved adding a Local::try_take() method on the Local trait in order for
the channel wakeup to work inside of libgreen. The channel send was happening
from a SchedTask when there is no Task available in TLS, and now this is
possible to work (remote wakeups are always possible, just a little slower).
2014-01-01 13:21:48 -08:00
Alex Crichton
3f11f87382 Move task count bookeeping out of libstd
For libgreen, bookeeping should not be global but rather on a per-pool basis.
Inside libnative, it's known that there must be a global counter with a
mutex/cvar.

The benefit of taking this strategy is to remove this functionality from libstd
to allow fine-grained control of it through libnative/libgreen. Notably, helper
threads in libnative can manually decrement the global count so they don't count
towards the global count of threads. Also, the shutdown process of *all* sched
pools is now dependent on the number of tasks in the pool being 0 rather than
this only being a hardcoded solution for the initial sched pool in libgreen.

This involved adding a Local::try_take() method on the Local trait in order for
the channel wakeup to work inside of libgreen. The channel send was happening
from a SchedTask when there is no Task available in TLS, and now this is
possible to work (remote wakeups are always possible, just a little slower).
2014-01-01 13:08:09 -08:00
bors
e61937a6bf auto merge of #11187 : alexcrichton/rust/once, r=brson
Rationale can be found in the first commit, but this is basically the same thing as `pthread_once`
2013-12-31 20:41:56 -08:00