Consolidate all array writeability checking in new PyArray_RequireWriteable

This is mostly a code cleanup, but it does have a user-visible effect
in that attempting to write to a unwriteable array now consistently
raises ValueError. (It used to randomly raise either ValueError or
RuntimeError.)

Passes numpy.test("full").
Funnel all assignments to PyArrayObject->base through a single point

This patch removes all direct assignments of non-NULL values to the
'base' field on PyArrayObjects. A new utility function was created to
set up UPDATEIFCOPY arrays, and all assignments to 'base' were
adjusted to use either PyArray_SetBaseObject or the new
PyArray_SetUpdateIfCopyBase.

One advantage of this is that it produces more consistent error
handling. This error handling revealed a bug in the nditer code,
which this patch does *not* yet fix.

The bug is that npyiter_new_temp_array sometimes (when dealing with
reversed axes) creates an array and then returns a view onto it. But,
npyiter_allocate_arrays assumes that the array returned by
npyiter_new_temp_array can have UPDATEIFCOPY set, which requires
reassigning its 'base' field. Previously, this meant that the
temporary array leaked. Now, it produces a ValueError.

This code path doesn't seem to actually be hit very often; only one of
the nditer tests fails because of the change. See
   numpy/core/tests/test_nditer.py:test_iter_array_cast_buggy
Add a test for ndarray.diagonal()

All 'expected' values were computed using numpy 1.5.1, so we can be
pretty sure that the recent rewrite didn't change any results.
Transition scheme for allowing PyArray_Diagonal to return a view

PyArray_Diagonal is changed to return a copy of the diagonal (as in
numpy 1.6 and earlier), but with a new (hidden) WARN_ON_WRITE flag
set. Writes to this array (or views thereof) will continue to work as
normal, but the first write will trigger a DeprecationWarning.

We also issue this warning if someone extracts a non-numpy writeable
view of the array (e.g., by accessing the Python-level .data
attribute). There are likely still places where the data buffer is
exposed that I've missed -- review welcome!

New known-fail test: eye() for maskna arrays was only implemented by
exploiting ndarray.diagonal's view-ness, so it is now unimplemented
again, and the corresponding test is marked known-fail.
Document the PyArray_Diagonal transition scheme.
Typo fix

Thanks to Travis for catching it.
Merge branch 'master' into clean-up-diagonal
Un-KNOWNFAIL the nditer test after merging Mark's fix from master
Fix a C90 compatibility error
Add a missing guard for Python versions <2.6
Clean up PyArray_Diagonal changes based on Chuck's feedback

- NPY_ARRAY_WARN_ON_WRITE flag definition is protected by #ifdef
  _MULTIARRAYMODULE, to make totally sure that we can recycle the flag
  bit later.
- Improve docs for PyArray_SetUpdateIfCopyBase.
- Make the deprecation warning for writes to the diagonal array
  somewhat more terse.
- Use DEPRECATE macro instead of calling PyErr_Warn/PyErr_WarnEx
  directly.
- Comment formatting fixed.
Don't assume ctypes is available, it's not true on Python 2.4
Fix diagonal-related warnings and tests on Python 3
Move internal NPY_ARRAY_WARN_ON_WRITE flag into an internal header.
Rename PyArray_RequireWriteable to PyArray_FailUnlessWriteable

Also clean up its API slightly so that the caller passes in a name
describing the array being checked which is used to generate an error
message, rather than writing an error message from scratch.
Fix dirty handling of internal compiler variable 
__LDBL_DENORM_MIN__ with C11 LDBL_TRUE_MIN
(with help from @jedbrown)
LDBL_TRUE_MIN falls back to __LDBL_DENORM_MIN__ if not defined
ENH: Make internal per-op nditer flags type a typedef

There are 8 flags now, so to add another one requires
bumping up the size. This change makes that easy.
Also, because the internal structure of nditer is
not exposed to the ABI, we can change it at will.
BUG: Add a new flag to nditer to indicate when op uses buffering

Thouis tracked down an intermittently occurring bug in
ticket #2144, where a reduction under certain situations
would produce wrong results. This occurs when the array
data and the nditer's buffer happen to be adjacent in
memory.

This fixes it by replacing the "clever" trick of checking if
the iterator's pointer is in the buffer with an explicit
flag to signal buffer usage. The reason this can't be reliably
handled via the pointer/buffer check is that the pointer updates
are handled by the consumer of the iterator, who may update
them in place or may use local variables instead. Thus, the
pointer could still point to the beginning of the buffer, or
could point at the byte immediately after the buffer. Using
a flag avoids all of this and should be reliable.
ENH: Add kwarg support for vectorize (tickets #2100, #1156, and #1487)

  This is a substantial rewrite of vectorize to remove all introspection and
  caching behaviour.  This greatly simplifies the logic of the code, and allows
  for much more generalized behaviour, simultaneously fixing tickets #1156,
  #1487, and #2100.  There will probably be a performance hit because caching is
  no longer used (but should be able to be reinstated if needed).
  As vectorize is a convenience function with poor performance in general,
  perhaps this is okay.  Rather than trying to inspect the function to determine
  the number of arguments, defaults, and argument names, we just use the
  arguments passed on the call to determine the behaviour on each call.

  All tests pass and code is fully covered

Fixes:
Ticket #2100: kwarg support for vectorize
- API: Optional excluded argument to exclude some args from vectorization.
- Added documentation, examples, and coverage tests
- Added additional coverage test and base case for functions with no args
- Factored original behaviour into _vectorize_call
- Some minor documentation and error message corrections

Ticket #1156: Support vectorizing over instance methods
- No longer an issue since everything is determined by the call.

Ticket: #1487: result depends on execution order
- No longer caching, so the behaviour is as was expected.

ENH: Simple cache for vectorize

- Added simple cache to prevent vectorize from calling pyfunc twice on the first
  argument when determining the output types and added regression test.
- Added documentation for excluded positional arguments.
- Documentation cleanups.
- Cleaned up variable names.

ENH: Performance improvements for backward compatibility of vectorize.

After some simple profiling, I found that the wrapping used to
support the caching of the previous commit wasted more time than
it saved, so I added a flag to allow the user to toggle.  Moral:
caching makes sense only if the function is expensive and is off
by default.

I also compared performance with the original vectorize and opted
for keeping a cache of _ufunc if otypes is specified and there are
no kwargs/excluded vars.  This case is easy to implement, and allows
users to reproduce (almost) the old performance characteristics if
needed. (The new version is about 5% slower in this case).

It would be much more complicated to add a similar cache in the case
where kwargs are used, and since a wrapper is used here, the
performance gain would be negligible (profiling showed that wrapping
was a more significant slowdown than the extra call to frompyfunc).

- API: Added cache kwarg which allows the user to toggle caching
       of the first result.
- DOC: Added Notes section with a discussion of performance and a
       warning that vectorize should not be used for performance.
- Added private _ufunc member to implement old-style of cache for
  special case with no kwargs, excluded, and with otypes specified.
- Modified test case.

Partially address ticket #1982
- I tried to use hasattr(outputs, '__len__') rather than
  isinstance(outputs, tuple) in order to allow for functions to return
  lists.  This, however, means that strings will get vectorized over
  each character which breaks previous behaviour.  Keeping old
  behaviour for now.