Branch merge
diff --git a/Doc/ACKS.txt b/Doc/ACKS.txt
index fcdb0b9..81f7c46 100644
--- a/Doc/ACKS.txt
+++ b/Doc/ACKS.txt
@@ -225,6 +225,7 @@
* Collin Winter
* Blake Winton
* Dan Wolfe
+ * Adam Woodbeck
* Steven Work
* Thomas Wouters
* Ka-Ping Yee
diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst
index 0c68b03..afceb8d 100644
--- a/Doc/library/configparser.rst
+++ b/Doc/library/configparser.rst
@@ -865,10 +865,6 @@
Comments can be indented. When *inline_comment_prefixes* is given, it will be
used as the set of substrings that prefix comments in non-empty lines.
- line and inline comments. For backwards compatibility, the default value for
- *comment_prefixes* is a special value that indicates that ``;`` and ``#`` can
- start whole line comments while only ``;`` can start inline comments.
-
When *strict* is ``True`` (the default), the parser won't allow for
any section or option duplicates while reading from a single source (file,
string or dictionary), raising :exc:`DuplicateSectionError` or
diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst
index d462bb7..64b4183 100644
--- a/Doc/library/socket.rst
+++ b/Doc/library/socket.rst
@@ -1014,6 +1014,25 @@
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)
+Running an example several times with too small delay between executions, could
+lead to this error::
+
+ socket.error: [Errno 98] Address already in use
+
+This is because the previous execution has left the socket in a ``TIME_WAIT``
+state, and can't be immediately reused.
+
+There is a :mod:`socket` flag to set, in order to prevent this,
+:data:`socket.SO_REUSEADDR`::
+
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ s.bind((HOST, PORT))
+
+the :data:`SO_REUSEADDR` flag tells the kernel to reuse a local socket in
+``TIME_WAIT`` state, without waiting for its natural timeout to expire.
+
+
.. seealso::
For an introduction to socket programming (in C), see the following papers:
diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py
index 536ea50..e4530d5 100644
--- a/Lib/ctypes/test/test_structures.py
+++ b/Lib/ctypes/test/test_structures.py
@@ -239,6 +239,14 @@
pass
self.assertRaises(TypeError, setattr, POINT, "_fields_", [("x", 1), ("y", 2)])
+ def test_invalid_name(self):
+ # field name must be string
+ def declare_with_name(name):
+ class S(Structure):
+ _fields_ = [(name, c_int)]
+
+ self.assertRaises(TypeError, declare_with_name, b"x")
+
def test_intarray_fields(self):
class SomeInts(Structure):
_fields_ = [("a", c_int * 4)]
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 72c9a2d..0dc9d6d 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -610,6 +610,17 @@
self.assertEqual(rawio.read(2), None)
self.assertEqual(rawio.read(2), b"")
+ def test_types_have_dict(self):
+ test = (
+ self.IOBase(),
+ self.RawIOBase(),
+ self.TextIOBase(),
+ self.StringIO(),
+ self.BytesIO()
+ )
+ for obj in test:
+ self.assertTrue(hasattr(obj, "__dict__"))
+
class CIOTest(IOTest):
def test_IOBase_finalize(self):
diff --git a/Misc/NEWS b/Misc/NEWS
index f9eb1cd..25bbf3f 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -31,6 +31,8 @@
- Issue #8286: The distutils command sdist will print a warning message instead
of crashing when an invalid path is given in the manifest template.
+- Issue #12878: Expose a __dict__ attribute on io.IOBase and its subclasses.
+
- Issue #12636: IDLE reads the coding cookie when executing a Python script.
- Issue #10946: The distutils commands bdist_dumb, bdist_wininst and bdist_msi
@@ -196,6 +198,9 @@
Extension Modules
-----------------
+- Issue #12764: Fix a crash in ctypes when the name of a Structure field is not
+ a string.
+
- Issue #11241: subclasses of ctypes.Array can now be subclassed.
- Issue #9651: Fix a crash when ctypes.create_string_buffer(0) was passed to
diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c
index 105e0df..14dc16f 100644
--- a/Modules/_ctypes/stgdict.c
+++ b/Modules/_ctypes/stgdict.c
@@ -482,8 +482,21 @@
char *fieldfmt = dict->format ? dict->format : "B";
char *fieldname = _PyUnicode_AsString(name);
char *ptr;
- Py_ssize_t len = strlen(fieldname) + strlen(fieldfmt);
- char *buf = alloca(len + 2 + 1);
+ Py_ssize_t len;
+ char *buf;
+
+ if (fieldname == NULL)
+ {
+ PyErr_Format(PyExc_TypeError,
+ "structure field name must be string not %s",
+ name->ob_type->tp_name);
+
+ Py_DECREF(pair);
+ return -1;
+ }
+
+ len = strlen(fieldname) + strlen(fieldfmt);
+ buf = alloca(len + 2 + 1);
sprintf(buf, "%s:%s:", fieldfmt, fieldname);
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c
index f06f562..2c59d42 100644
--- a/Modules/_io/iobase.c
+++ b/Modules/_io/iobase.c
@@ -156,6 +156,19 @@
return PyBool_FromLong(IS_CLOSED(self));
}
+static PyObject *
+iobase_get_dict(PyObject *self)
+{
+ PyObject **dictptr = _PyObject_GetDictPtr(self);
+ PyObject *dict;
+ assert(dictptr);
+ dict = *dictptr;
+ if (dict == NULL)
+ dict = *dictptr = PyDict_New();
+ Py_XINCREF(dict);
+ return dict;
+}
+
PyObject *
_PyIOBase_check_closed(PyObject *self, PyObject *args)
{
@@ -691,6 +704,7 @@
};
static PyGetSetDef iobase_getset[] = {
+ {"__dict__", iobase_get_dict, NULL, NULL},
{"closed", (getter)iobase_closed_get, NULL, NULL},
{NULL}
};