Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Doc/library/compileall.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,10 @@ Public functions
If *force* is true, modules are re-compiled even if the timestamps are up to
date.

If *rx* is given, its search method is called on the complete path to each
If *rx* is given, its ``search`` method is called on the complete path to each
file considered for compilation, and if it returns a true value, the file
is skipped.
is skipped. This can be used to exclude files matching a regular expression,
given as a :ref:`re.Pattern <re-objects>` object.

If *quiet* is ``False`` or ``0`` (the default), the filenames and other
information are printed to standard out. Set to ``1``, only errors are
Expand Down Expand Up @@ -242,9 +243,10 @@ Public functions
cases where the source file does not exist at the time the byte-code file is
executed.

If *rx* is given, its search method is passed the full path name to the
If *rx* is given, its ``search`` method is passed the full path name to the
file being compiled, and if it returns a true value, the file is not
compiled and ``True`` is returned.
compiled and ``True`` is returned. This can be used to exclude files matching
a regular expression, given as a :ref:`re.Pattern <re-objects>` object.

If *quiet* is ``False`` or ``0`` (the default), the filenames and other
information are printed to standard out. Set to ``1``, only errors are
Expand Down
12 changes: 6 additions & 6 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ def is_dir(self):
if not _ignore_error(e):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
# (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ )
return False
except ValueError:
# Non-encodable path
Expand All @@ -1312,7 +1312,7 @@ def is_file(self):
if not _ignore_error(e):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
# (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ )
return False
except ValueError:
# Non-encodable path
Expand Down Expand Up @@ -1363,7 +1363,7 @@ def is_block_device(self):
if not _ignore_error(e):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
# (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ )
return False
except ValueError:
# Non-encodable path
Expand All @@ -1379,7 +1379,7 @@ def is_char_device(self):
if not _ignore_error(e):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
# (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ )
return False
except ValueError:
# Non-encodable path
Expand All @@ -1395,7 +1395,7 @@ def is_fifo(self):
if not _ignore_error(e):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
# (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ )
return False
except ValueError:
# Non-encodable path
Expand All @@ -1411,7 +1411,7 @@ def is_socket(self):
if not _ignore_error(e):
raise
# Path doesn't exist or is a broken symlink
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
# (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ )
return False
except ValueError:
# Non-encodable path
Expand Down
6 changes: 3 additions & 3 deletions Lib/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,8 @@ def covariance(x, y, /):
raise StatisticsError('covariance requires that both inputs have same number of data points')
if n < 2:
raise StatisticsError('covariance requires at least two data points')
xbar = mean(x)
ybar = mean(y)
xbar = fmean(x)
ybar = fmean(y)
total = fsum((xi - xbar) * (yi - ybar) for xi, yi in zip(x, y))
return total / (n - 1)

Expand Down Expand Up @@ -956,7 +956,7 @@ def linear_regression(regressor, dependent_variable, /):
slope = covariance(regressor, dependent_variable) / variance(regressor)
except ZeroDivisionError:
raise StatisticsError('regressor is constant')
intercept = mean(dependent_variable) - slope * mean(regressor)
intercept = fmean(dependent_variable) - slope * fmean(regressor)
return LinearRegression(intercept=intercept, slope=slope)


Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_deque.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,9 @@ class C(object):

@support.cpython_only
def test_sizeof(self):
MAXFREEBLOCKS = 16
BLOCKLEN = 64
basesize = support.calcvobjsize('2P4nP')
basesize = support.calcvobjsize('2P5n%dPP' % MAXFREEBLOCKS)
blocksize = struct.calcsize('P%dPP' % BLOCKLEN)
self.assertEqual(object.__sizeof__(deque()), basesize)
check = self.check_sizeof
Expand Down
3 changes: 1 addition & 2 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class SocketCANTest(unittest.TestCase):
the following commands:
# modprobe vcan
# ip link add dev vcan0 type vcan
# ifconfig vcan0 up
# ip link set up vcan0
"""
interface = 'vcan0'
bufsize = 128
Expand Down Expand Up @@ -2085,7 +2085,6 @@ def testSendFrame(self):
cf, addr = self.s.recvfrom(self.bufsize)
self.assertEqual(self.cf, cf)
self.assertEqual(addr[0], self.interface)
self.assertEqual(addr[1], socket.AF_CAN)

def _testSendFrame(self):
self.cf = self.build_can_frame(0x00, b'\x01\x02\x03\x04\x05')
Expand Down
59 changes: 32 additions & 27 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static PyTypeObject tuplegetter_type;

#define BLOCKLEN 64
#define CENTER ((BLOCKLEN - 1) / 2)
#define MAXFREEBLOCKS 16

/* Data for deque objects is stored in a doubly-linked list of fixed
* length blocks. This assures that appends or pops never move any
Expand Down Expand Up @@ -92,6 +93,8 @@ typedef struct {
Py_ssize_t rightindex; /* 0 <= rightindex < BLOCKLEN */
size_t state; /* incremented whenever the indices move */
Py_ssize_t maxlen; /* maxlen is -1 for unbounded deques */
Py_ssize_t numfreeblocks;
block *freeblocks[MAXFREEBLOCKS];
PyObject *weakreflist;
} dequeobject;

Expand Down Expand Up @@ -123,16 +126,12 @@ static PyTypeObject deque_type;
added at about the same rate as old blocks are being freed.
*/

#define MAXFREEBLOCKS 16
static Py_ssize_t numfreeblocks = 0;
static block *freeblocks[MAXFREEBLOCKS];

static block *
newblock(void) {
static inline block *
newblock(dequeobject *deque) {
block *b;
if (numfreeblocks) {
numfreeblocks--;
return freeblocks[numfreeblocks];
if (deque->numfreeblocks) {
deque->numfreeblocks--;
return deque->freeblocks[deque->numfreeblocks];
}
b = PyMem_Malloc(sizeof(block));
if (b != NULL) {
Expand All @@ -142,12 +141,12 @@ newblock(void) {
return NULL;
}

static void
freeblock(block *b)
static inline void
freeblock(dequeobject *deque, block *b)
{
if (numfreeblocks < MAXFREEBLOCKS) {
freeblocks[numfreeblocks] = b;
numfreeblocks++;
if (deque->numfreeblocks < MAXFREEBLOCKS) {
deque->freeblocks[deque->numfreeblocks] = b;
deque->numfreeblocks++;
} else {
PyMem_Free(b);
}
Expand All @@ -164,7 +163,7 @@ deque_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (deque == NULL)
return NULL;

b = newblock();
b = newblock(deque);
if (b == NULL) {
Py_DECREF(deque);
return NULL;
Expand All @@ -180,6 +179,7 @@ deque_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
deque->rightindex = CENTER;
deque->state = 0;
deque->maxlen = -1;
deque->numfreeblocks = 0;
deque->weakreflist = NULL;

return (PyObject *)deque;
Expand All @@ -204,7 +204,7 @@ deque_pop(dequeobject *deque, PyObject *unused)
if (Py_SIZE(deque)) {
prevblock = deque->rightblock->leftlink;
assert(deque->leftblock != deque->rightblock);
freeblock(deque->rightblock);
freeblock(deque, deque->rightblock);
CHECK_NOT_END(prevblock);
MARK_END(prevblock->rightlink);
deque->rightblock = prevblock;
Expand Down Expand Up @@ -242,7 +242,7 @@ deque_popleft(dequeobject *deque, PyObject *unused)
if (Py_SIZE(deque)) {
assert(deque->leftblock != deque->rightblock);
prevblock = deque->leftblock->rightlink;
freeblock(deque->leftblock);
freeblock(deque, deque->leftblock);
CHECK_NOT_END(prevblock);
MARK_END(prevblock->leftlink);
deque->leftblock = prevblock;
Expand Down Expand Up @@ -278,7 +278,7 @@ static inline int
deque_append_internal(dequeobject *deque, PyObject *item, Py_ssize_t maxlen)
{
if (deque->rightindex == BLOCKLEN - 1) {
block *b = newblock();
block *b = newblock(deque);
if (b == NULL)
return -1;
b->leftlink = deque->rightblock;
Expand Down Expand Up @@ -315,7 +315,7 @@ static inline int
deque_appendleft_internal(dequeobject *deque, PyObject *item, Py_ssize_t maxlen)
{
if (deque->leftindex == 0) {
block *b = newblock();
block *b = newblock(deque);
if (b == NULL)
return -1;
b->rightlink = deque->leftblock;
Expand Down Expand Up @@ -584,7 +584,7 @@ deque_clear(dequeobject *deque)
adversary could cause it to never terminate).
*/

b = newblock();
b = newblock(deque);
if (b == NULL) {
PyErr_Clear();
goto alternate_method;
Expand Down Expand Up @@ -623,13 +623,13 @@ deque_clear(dequeobject *deque)
itemptr = leftblock->data;
limit = itemptr + m;
n -= m;
freeblock(prevblock);
freeblock(deque, prevblock);
}
item = *(itemptr++);
Py_DECREF(item);
}
CHECK_END(leftblock->rightlink);
freeblock(leftblock);
freeblock(deque, leftblock);
return 0;

alternate_method:
Expand Down Expand Up @@ -679,7 +679,7 @@ deque_inplace_repeat(dequeobject *deque, Py_ssize_t n)
deque->state++;
for (i = 0 ; i < n-1 ; ) {
if (deque->rightindex == BLOCKLEN - 1) {
block *b = newblock();
block *b = newblock(deque);
if (b == NULL) {
Py_SET_SIZE(deque, Py_SIZE(deque) + i);
return NULL;
Expand Down Expand Up @@ -797,7 +797,7 @@ _deque_rotate(dequeobject *deque, Py_ssize_t n)
while (n > 0) {
if (leftindex == 0) {
if (b == NULL) {
b = newblock();
b = newblock(deque);
if (b == NULL)
goto done;
}
Expand Down Expand Up @@ -841,7 +841,7 @@ _deque_rotate(dequeobject *deque, Py_ssize_t n)
while (n < 0) {
if (rightindex == BLOCKLEN - 1) {
if (b == NULL) {
b = newblock();
b = newblock(deque);
if (b == NULL)
goto done;
}
Expand Down Expand Up @@ -885,7 +885,7 @@ _deque_rotate(dequeobject *deque, Py_ssize_t n)
rv = 0;
done:
if (b != NULL)
freeblock(b);
freeblock(deque, b);
deque->leftblock = leftblock;
deque->rightblock = rightblock;
deque->leftindex = leftindex;
Expand Down Expand Up @@ -1306,16 +1306,21 @@ deque_ass_item(dequeobject *deque, Py_ssize_t i, PyObject *v)
static void
deque_dealloc(dequeobject *deque)
{
Py_ssize_t i;

PyObject_GC_UnTrack(deque);
if (deque->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *) deque);
if (deque->leftblock != NULL) {
deque_clear(deque);
assert(deque->leftblock != NULL);
freeblock(deque->leftblock);
freeblock(deque, deque->leftblock);
}
deque->leftblock = NULL;
deque->rightblock = NULL;
for (i=0 ; i < deque->numfreeblocks ; i++) {
PyMem_Free(deque->freeblocks[i]);
}
Py_TYPE(deque)->tp_free(deque);
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/_randommodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ _random_exec(PyObject *module)
}

/* Look up and save int.__abs__, which is needed in random_seed(). */
PyObject *longval = longval = PyLong_FromLong(0);
PyObject *longval = PyLong_FromLong(0);
if (longval == NULL) {
return -1;
}
Expand Down