Branch merge
diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst
index 2c7faf0..12816c9 100644
--- a/Doc/c-api/module.rst
+++ b/Doc/c-api/module.rst
@@ -192,7 +192,7 @@
 .. cfunction:: int PyModule_AddIntMacro(PyObject *module, macro)
 
    Add an int constant to *module*. The name and the value are taken from
-   *macro*. For example ``PyModule_AddConstant(module, AF_INET)`` adds the int
+   *macro*. For example ``PyModule_AddIntMacro(module, AF_INET)`` adds the int
    constant *AF_INET* with the value of *AF_INET* to *module*.
    Return ``-1`` on error, ``0`` on success.
 
diff --git a/Doc/includes/email-dir.py b/Doc/includes/email-dir.py
index e67de61..035442b 100644
--- a/Doc/includes/email-dir.py
+++ b/Doc/includes/email-dir.py
@@ -105,7 +105,7 @@
         fp.write(composed)
         fp.close()
     else:
-        s = smtplib.SMTP()
+        s = smtplib.SMTP('localhost')
         s.sendmail(opts.sender, opts.recipients, composed)
         s.quit()
 
diff --git a/Doc/includes/email-mime.py b/Doc/includes/email-mime.py
index f64df83..7b1c028 100644
--- a/Doc/includes/email-mime.py
+++ b/Doc/includes/email-mime.py
@@ -26,6 +26,6 @@
     msg.attach(img)
 
 # Send the email via our own SMTP server.
-s = smtplib.SMTP()
+s = smtplib.SMTP('localhost')
 s.sendmail(me, family, msg.as_string())
 s.quit()
diff --git a/Doc/includes/email-simple.py b/Doc/includes/email-simple.py
index 689511e..29bd078 100644
--- a/Doc/includes/email-simple.py
+++ b/Doc/includes/email-simple.py
@@ -19,6 +19,6 @@
 
 # Send the message via our own SMTP server, but don't include the
 # envelope header.
-s = smtplib.SMTP()
+s = smtplib.SMTP('localhost')
 s.sendmail(me, [you], msg.as_string())
 s.quit()
diff --git a/Doc/library/mmap.rst b/Doc/library/mmap.rst
index 5001d4f..e061088 100644
--- a/Doc/library/mmap.rst
+++ b/Doc/library/mmap.rst
@@ -86,6 +86,10 @@
    defaults to 0.  *offset* must be a multiple of the PAGESIZE or
    ALLOCATIONGRANULARITY.
 
+   To ensure validity of the created memory mapping the file specified
+   by the descriptor *fileno* is internally automatically synchronized
+   with physical backing store on Mac OS X and OpenVMS.
+
    This example shows a simple way of using :class:`mmap`::
 
       import mmap
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index a1a3879..7621eef 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -353,8 +353,8 @@
    for a complete list of code points with the ``Nd`` property.
 
 
-All :class:`numbers.Real` types (:class:`int` and
-:class:`float`) also include the following operations:
+All :class:`numbers.Real` types (:class:`int` and :class:`float`) also include
+the following operations:
 
 +--------------------+------------------------------------+--------+
 | Operation          | Result                             | Notes  |
@@ -438,6 +438,9 @@
 Additional Methods on Integer Types
 -----------------------------------
 
+The int type implements the :class:`numbers.Integral` :term:`abstract base
+class`. In addition, it provides one more method:
+
 .. method:: int.bit_length()
 
     Return the number of bits necessary to represent an integer in binary,
@@ -468,7 +471,8 @@
 Additional Methods on Float
 ---------------------------
 
-The float type has some additional methods.
+The float type implements the :class:`numbers.Real` :term:`abstract base
+class`. float also has the following additional methods.
 
 .. method:: float.as_integer_ratio()
 
diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst
index c61fedb..bb9f920 100644
--- a/Doc/library/sys.rst
+++ b/Doc/library/sys.rst
@@ -450,10 +450,10 @@
    struct sequence  :data:`sys.version_info` may be used for a more human-friendly
    encoding of the same information.
 
-   The ``hexversion`` is a 32-bit number with the following layout
+   The ``hexversion`` is a 32-bit number with the following layout:
 
    +-------------------------+------------------------------------------------+
-   | bits (big endian order) | meaning                                        |
+   | Bits (big endian order) | Meaning                                        |
    +=========================+================================================+
    | :const:`1-8`            |  ``PY_MAJOR_VERSION``  (the ``2`` in           |
    |                         |  ``2.1.0a3``)                                  |
@@ -465,14 +465,14 @@
    |                         |  ``2.1.0a3``)                                  |
    +-------------------------+------------------------------------------------+
    | :const:`25-28`          |  ``PY_RELEASE_LEVEL``  (``0xA`` for alpha,     |
-   |                         |  ``0xB`` for beta, ``0xC`` for gamma and       |
-   |                         |  ``0xF`` for final)                            |
+   |                         |  ``0xB`` for beta, ``0xC`` for release         |
+   |                         |  candidate and ``0xF`` for final)              |
    +-------------------------+------------------------------------------------+
    | :const:`29-32`          |  ``PY_RELEASE_SERIAL``  (the ``3`` in          |
-   |                         |  ``2.1.0a3``)                                  |
+   |                         |  ``2.1.0a3``, zero for final releases)         |
    +-------------------------+------------------------------------------------+
 
-   thus ``2.1.0a3`` is hexversion ``0x020100a3``
+   Thus ``2.1.0a3`` is hexversion ``0x020100a3``.
 
 .. data:: int_info
 
@@ -480,7 +480,7 @@
    internal representation of integers.  The attributes are read only.
 
    +-------------------------+----------------------------------------------+
-   | attribute               | explanation                                  |
+   | Attribute               | Explanation                                  |
    +=========================+==============================================+
    | :const:`bits_per_digit` | number of bits held in each digit.  Python   |
    |                         | integers are stored internally in base       |
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index bd88f45..aafe428 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4235,6 +4235,22 @@
         with self.assertRaises(AttributeError):
             del X.__abstractmethods__
 
+    def test_proxy_call(self):
+        class FakeStr:
+            __class__ = str
+
+        fake_str = FakeStr()
+        # isinstance() reads __class__
+        self.assertTrue(isinstance(fake_str, str))
+
+        # call a method descriptor
+        with self.assertRaises(TypeError):
+            str.split(fake_str)
+
+        # call a slot wrapper descriptor
+        with self.assertRaises(TypeError):
+            str.__add__(fake_str, "abc")
+
 
 class DictProxyTests(unittest.TestCase):
     def setUp(self):
diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py
index 48ac40a..7593c06 100644
--- a/Lib/test/test_zlib.py
+++ b/Lib/test/test_zlib.py
@@ -74,7 +74,7 @@
         with open(support.TESTFN, "wb+") as f:
             f.seek(_4G)
             f.write(b"asdf")
-        with open(support.TESTFN, "rb") as f:
+            f.flush()
             self.mapping = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
 
     def tearDown(self):
diff --git a/Misc/ACKS b/Misc/ACKS
index 75ad0f9..59b3661 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -777,6 +777,7 @@
 Ken Stox
 Dan Stromberg
 Daniel Stutzbach
+Andreas Stührk
 Pal Subbiah
 Nathan Sullivan
 Mark Summerfield
diff --git a/Misc/NEWS b/Misc/NEWS
index b4ba3b6..8878612 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,11 @@
 Core and Builtins
 -----------------
 
+- Issue #9756: When calling a method descriptor or a slot wrapper descriptor,
+  the check of the object type doesn't read the __class__ attribute anymore.
+  Fix a crash if a class override its __class__ attribute (e.g. a proxy of the
+  str type). Patch written by Andreas Stührk.
+
 - Issue #6780: fix starts/endswith error message to mention that tuples are
   accepted too.
 
@@ -61,6 +66,9 @@
 Library
 -------
 
+- Issue #11277: mmap.mmap() calls fcntl(fd, F_FULLFSYNC) on Mac OS X to get
+  around a mmap bug with sparse files. Patch written by Steffen Daode Nurpmeso.
+
 - Issue #11763: don't use difflib in TestCase.assertMultiLineEqual if the
   strings are too long.
 
diff --git a/Misc/python.man b/Misc/python.man
index 87f1c93..411a43a 100644
--- a/Misc/python.man
+++ b/Misc/python.man
@@ -31,7 +31,7 @@
 .B \-O
 ]
 [
-.B \-O0
+.B \-OO
 ]
 [
 .B -Q
@@ -142,7 +142,7 @@
 .I .pyc
 to \fI.pyo\fP.  Given twice, causes docstrings to be discarded.
 .TP
-.B \-O0
+.B \-OO
 Discard docstrings in addition to the \fB-O\fP optimizations.
 .TP
 .BI "\-Q " argument
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index f484a7a..88da4a0 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -23,6 +23,9 @@
 
 #ifndef MS_WINDOWS
 #define UNIX
+# ifdef __APPLE__
+#  include <fcntl.h>
+# endif
 #endif
 
 #ifdef MS_WINDOWS
@@ -1091,6 +1094,12 @@
                             "mmap invalid access parameter.");
     }
 
+#ifdef __APPLE__
+    /* Issue #11277: fsync(2) is not enough on OS X - a special, OS X specific
+       fcntl(2) is necessary to force DISKSYNC and get around mmap(2) bug */
+    if (fd != -1)
+        (void)fcntl(fd, F_FULLFSYNC);
+#endif
 #ifdef HAVE_FSTAT
 #  ifdef __VMS
     /* on OpenVMS we must ensure that all bytes are written to the file */
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index 5f118ce..9eda4bd 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -226,7 +226,8 @@
         return NULL;
     }
     self = PyTuple_GET_ITEM(args, 0);
-    if (!PyObject_IsInstance(self, (PyObject *)(descr->d_type))) {
+    if (!_PyObject_RealIsSubclass((PyObject *)Py_TYPE(self),
+                                  (PyObject *)(descr->d_type))) {
         PyErr_Format(PyExc_TypeError,
                      "descriptor '%V' "
                      "requires a '%.100s' object "
@@ -284,7 +285,8 @@
         return NULL;
     }
     self = PyTuple_GET_ITEM(args, 0);
-    if (!PyObject_IsInstance(self, (PyObject *)(descr->d_type))) {
+    if (!_PyObject_RealIsSubclass((PyObject *)Py_TYPE(self),
+                                  (PyObject *)(descr->d_type))) {
         PyErr_Format(PyExc_TypeError,
                      "descriptor '%V' "
                      "requires a '%.100s' object "
@@ -1065,7 +1067,8 @@
 
     assert(PyObject_TypeCheck(d, &PyWrapperDescr_Type));
     descr = (PyWrapperDescrObject *)d;
-    assert(PyObject_IsInstance(self, (PyObject *)(descr->d_type)));
+    assert(_PyObject_RealIsSubclass((PyObject *)Py_TYPE(self),
+                                    (PyObject *)(descr->d_type)));
 
     wp = PyObject_GC_New(wrapperobject, &wrappertype);
     if (wp != NULL) {