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
19 changes: 10 additions & 9 deletions Lib/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,16 @@ def _args_from_interpreter_flags():
# -X options
if dev_mode:
args.extend(('-X', 'dev'))
for opt in ('faulthandler', 'tracemalloc', 'importtime',
'frozen_modules', 'showrefcount', 'utf8', 'gil'):
if opt in xoptions:
value = xoptions[opt]
if value is True:
arg = opt
else:
arg = '%s=%s' % (opt, value)
args.extend(('-X', arg))
for opt in sorted(xoptions):
if opt == 'dev':
# handled above via sys.flags.dev_mode
continue
value = xoptions[opt]
if value is True:
arg = opt
else:
arg = '%s=%s' % (opt, value)
args.extend(('-X', arg))

return args

Expand Down
33 changes: 33 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#For test of issue 136154
GLOBAL_136154 = 42

# For frozendict JIT tests
FROZEN_DICT_CONST = frozendict(x=1, y=2)


@contextlib.contextmanager
def clear_executors(func):
# Clear executors in func before and after running a block
Expand Down Expand Up @@ -4155,6 +4159,35 @@ def testfunc(n):
self.assertLessEqual(count_ops(ex, "_POP_TOP_INT"), 1)
self.assertIn("_POP_TOP_NOP", uops)

def test_binary_subscr_frozendict_lowering(self):
def testfunc(n):
x = 0
for _ in range(n):
x += FROZEN_DICT_CONST['x']
return x

res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertEqual(res, TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_INSERT_2_LOAD_CONST_INLINE_BORROW", uops)
self.assertNotIn("_BINARY_OP_SUBSCR_DICT", uops)

def test_binary_subscr_frozendict_const_fold(self):
def testfunc(n):
x = 0
for _ in range(n):
if FROZEN_DICT_CONST['x'] == 1:
x += 1
return x

res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertEqual(res, TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
# lookup result is folded to constant 1, so comparison is optimized away
self.assertNotIn("_COMPARE_OP_INT", uops)

def test_binary_subscr_list_slice(self):
def testfunc(n):
x = 0
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,12 +569,19 @@ def test_args_from_interpreter_flags(self):
# -X options
['-X', 'dev'],
['-Wignore', '-X', 'dev'],
['-X', 'cpu_count=4'],
['-X', 'disable-remote-debug'],
['-X', 'faulthandler'],
['-X', 'importtime'],
['-X', 'importtime=2'],
['-X', 'int_max_str_digits=1000'],
['-X', 'lazy_imports=all'],
['-X', 'no_debug_ranges'],
['-X', 'pycache_prefix=/tmp/pycache'],
['-X', 'showrefcount'],
['-X', 'tracemalloc'],
['-X', 'tracemalloc=3'],
['-X', 'warn_default_encoding'],
):
with self.subTest(opts=opts):
self.check_options(opts, 'args_from_interpreter_flags')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
All :option:`-X` options from the Python command line are now propagated to
child processes spawned by :mod:`multiprocessing`, not just a hard-coded
subset. This makes the behavior consistent between default "spawn" and
"forkserver" start methods and the old "fork" start method. The options
that were previously not propagated are: ``context_aware_warnings``,
``cpu_count``, ``disable-remote-debug``, ``int_max_str_digits``,
``lazy_imports``, ``no_debug_ranges``, ``pathconfig_warnings``, ``perf``,
``perf_jit``, ``presite``, ``pycache_prefix``, ``thread_inherit_context``,
and ``warn_default_encoding``.
14 changes: 7 additions & 7 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3052,7 +3052,7 @@ _PyCode_ConstantKey(PyObject *op)
else if (PyBool_Check(op) || PyBytes_CheckExact(op)) {
/* Make booleans different from integers 0 and 1.
* Avoid BytesWarning from comparing bytes with strings. */
key = PyTuple_Pack(2, Py_TYPE(op), op);
key = _PyTuple_FromPair((PyObject *)Py_TYPE(op), op);
}
else if (PyFloat_CheckExact(op)) {
double d = PyFloat_AS_DOUBLE(op);
Expand All @@ -3062,7 +3062,7 @@ _PyCode_ConstantKey(PyObject *op)
if (d == 0.0 && copysign(1.0, d) < 0.0)
key = PyTuple_Pack(3, Py_TYPE(op), op, Py_None);
else
key = PyTuple_Pack(2, Py_TYPE(op), op);
key = _PyTuple_FromPair((PyObject *)Py_TYPE(op), op);
}
else if (PyComplex_CheckExact(op)) {
Py_complex z;
Expand All @@ -3086,7 +3086,7 @@ _PyCode_ConstantKey(PyObject *op)
key = PyTuple_Pack(3, Py_TYPE(op), op, Py_None);
}
else {
key = PyTuple_Pack(2, Py_TYPE(op), op);
key = _PyTuple_FromPair((PyObject *)Py_TYPE(op), op);
}
}
else if (PyTuple_CheckExact(op)) {
Expand All @@ -3111,7 +3111,7 @@ _PyCode_ConstantKey(PyObject *op)
PyTuple_SET_ITEM(tuple, i, item_key);
}

key = PyTuple_Pack(2, tuple, op);
key = _PyTuple_FromPair(tuple, op);
Py_DECREF(tuple);
}
else if (PyFrozenSet_CheckExact(op)) {
Expand Down Expand Up @@ -3145,7 +3145,7 @@ _PyCode_ConstantKey(PyObject *op)
if (set == NULL)
return NULL;

key = PyTuple_Pack(2, set, op);
key = _PyTuple_FromPair(set, op);
Py_DECREF(set);
return key;
}
Expand Down Expand Up @@ -3176,7 +3176,7 @@ _PyCode_ConstantKey(PyObject *op)
goto slice_exit;
}

key = PyTuple_Pack(2, slice_key, op);
key = _PyTuple_FromPair(slice_key, op);
Py_DECREF(slice_key);
slice_exit:
Py_XDECREF(start_key);
Expand All @@ -3190,7 +3190,7 @@ _PyCode_ConstantKey(PyObject *op)
if (obj_id == NULL)
return NULL;

key = PyTuple_Pack(2, obj_id, op);
key = _PyTuple_FromPair(obj_id, op);
Py_DECREF(obj_id);
}
return key;
Expand Down
28 changes: 8 additions & 20 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5454,7 +5454,7 @@ dictiter_new(PyDictObject *dict, PyTypeObject *itertype)
}
if (itertype == &PyDictIterItem_Type ||
itertype == &PyDictRevIterItem_Type) {
di->di_result = PyTuple_Pack(2, Py_None, Py_None);
di->di_result = _PyTuple_FromPairSteal(Py_None, Py_None);
if (di->di_result == NULL) {
Py_DECREF(di);
return NULL;
Expand Down Expand Up @@ -6020,14 +6020,7 @@ dictiter_iternextitem(PyObject *self)
_PyTuple_Recycle(result);
}
else {
result = PyTuple_New(2);
if (result == NULL) {
Py_DECREF(key);
Py_DECREF(value);
return NULL;
}
PyTuple_SET_ITEM(result, 0, key);
PyTuple_SET_ITEM(result, 1, value);
result = _PyTuple_FromPairSteal(key, value);
}
return result;
}
Expand Down Expand Up @@ -6146,12 +6139,7 @@ dictreviter_iter_lock_held(PyDictObject *d, PyObject *self)
_PyTuple_Recycle(result);
}
else {
result = PyTuple_New(2);
if (result == NULL) {
return NULL;
}
PyTuple_SET_ITEM(result, 0, Py_NewRef(key));
PyTuple_SET_ITEM(result, 1, Py_NewRef(value));
result = _PyTuple_FromPair(key, value);
}
return result;
}
Expand Down Expand Up @@ -6644,18 +6632,22 @@ dictitems_xor_lock_held(PyObject *d1, PyObject *d2)
else {
Py_INCREF(val1);
to_delete = PyObject_RichCompareBool(val1, val2, Py_EQ);
Py_CLEAR(val1);
if (to_delete < 0) {
goto error;
}
}

if (to_delete) {
Py_CLEAR(val2);
if (_PyDict_DelItem_KnownHash(temp_dict, key, hash) < 0) {
goto error;
}
Py_CLEAR(key);
}
else {
PyObject *pair = PyTuple_Pack(2, key, val2);
PyObject *pair = _PyTuple_FromPairSteal(key, val2);
key = val2 = NULL;
if (pair == NULL) {
goto error;
}
Expand All @@ -6665,11 +6657,7 @@ dictitems_xor_lock_held(PyObject *d1, PyObject *d2)
}
Py_DECREF(pair);
}
Py_DECREF(key);
Py_XDECREF(val1);
Py_DECREF(val2);
}
key = val1 = val2 = NULL;

PyObject *remaining_pairs = PyObject_CallMethodNoArgs(
temp_dict, &_Py_ID(items));
Expand Down
22 changes: 3 additions & 19 deletions Objects/enumobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ enum_new_impl(PyTypeObject *type, PyObject *iterable, PyObject *start)
Py_DECREF(en);
return NULL;
}
en->en_result = PyTuple_Pack(2, Py_None, Py_None);
en->en_result = _PyTuple_FromPairSteal(Py_None, Py_None);
if (en->en_result == NULL) {
Py_DECREF(en);
return NULL;
Expand Down Expand Up @@ -226,15 +226,7 @@ enum_next_long(enumobject *en, PyObject* next_item)
_PyTuple_Recycle(result);
return result;
}
result = PyTuple_New(2);
if (result == NULL) {
Py_DECREF(next_index);
Py_DECREF(next_item);
return NULL;
}
PyTuple_SET_ITEM(result, 0, next_index);
PyTuple_SET_ITEM(result, 1, next_item);
return result;
return _PyTuple_FromPairSteal(next_index, next_item);
}

static PyObject *
Expand Down Expand Up @@ -276,15 +268,7 @@ enum_next(PyObject *op)
_PyTuple_Recycle(result);
return result;
}
result = PyTuple_New(2);
if (result == NULL) {
Py_DECREF(next_index);
Py_DECREF(next_item);
return NULL;
}
PyTuple_SET_ITEM(result, 0, next_index);
PyTuple_SET_ITEM(result, 1, next_item);
return result;
return _PyTuple_FromPairSteal(next_index, next_item);
}

static PyObject *
Expand Down
4 changes: 3 additions & 1 deletion Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_stackref.h" // PyStackRef_AsPyObjectBorrow()
#include "pycore_structseq.h" // _PyStructSequence_FiniBuiltin()
#include "pycore_tuple.h" // _PyTuple_FromPair

#include <float.h> // DBL_MAX
#include <stdlib.h> // strtol()
Expand Down Expand Up @@ -1539,8 +1540,9 @@ float_as_integer_ratio_impl(PyObject *self)
if (denominator == NULL)
goto error;
}
Py_DECREF(py_exponent);

result_pair = PyTuple_Pack(2, numerator, denominator);
return _PyTuple_FromPairSteal(numerator, denominator);

error:
Py_XDECREF(py_exponent);
Expand Down
38 changes: 17 additions & 21 deletions Objects/frameobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#include "pycore_opcode_metadata.h" // _PyOpcode_Caches
#include "pycore_optimizer.h" // _Py_Executors_InvalidateDependency()
#include "pycore_tuple.h" // _PyTuple_FromPair
#include "pycore_unicodeobject.h" // _PyUnicode_Equal()

#include "frameobject.h" // PyFrameLocalsProxyObject
Expand Down Expand Up @@ -630,22 +631,16 @@ framelocalsproxy_items(PyObject *self, PyObject *Py_UNUSED(ignored))
PyObject *value = framelocalsproxy_getval(frame->f_frame, co, i);

if (value) {
PyObject *pair = PyTuple_Pack(2, name, value);
PyObject *pair = _PyTuple_FromPairSteal(Py_NewRef(name), value);
if (pair == NULL) {
Py_DECREF(items);
Py_DECREF(value);
return NULL;
}

if (PyList_Append(items, pair) < 0) {
Py_DECREF(items);
Py_DECREF(pair);
Py_DECREF(value);
return NULL;
goto error;
}

int rc = PyList_Append(items, pair);
Py_DECREF(pair);
Py_DECREF(value);
if (rc < 0) {
goto error;
}
}
}

Expand All @@ -655,23 +650,24 @@ framelocalsproxy_items(PyObject *self, PyObject *Py_UNUSED(ignored))
PyObject *key = NULL;
PyObject *value = NULL;
while (PyDict_Next(frame->f_extra_locals, &j, &key, &value)) {
PyObject *pair = PyTuple_Pack(2, key, value);
PyObject *pair = _PyTuple_FromPair(key, value);
if (pair == NULL) {
Py_DECREF(items);
return NULL;
}

if (PyList_Append(items, pair) < 0) {
Py_DECREF(items);
Py_DECREF(pair);
return NULL;
goto error;
}

int rc = PyList_Append(items, pair);
Py_DECREF(pair);
if (rc < 0) {
goto error;
}
}
}

return items;

error:
Py_DECREF(items);
return NULL;
}

static Py_ssize_t
Expand Down
6 changes: 3 additions & 3 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1437,9 +1437,9 @@ list_extend_dictitems(PyListObject *self, PyDictObject *dict)
PyObject **dest = self->ob_item + m;
Py_ssize_t pos = 0;
Py_ssize_t i = 0;
PyObject *key_value[2];
while (_PyDict_Next((PyObject *)dict, &pos, &key_value[0], &key_value[1], NULL)) {
PyObject *item = PyTuple_FromArray(key_value, 2);
PyObject *key, *value;
while (_PyDict_Next((PyObject *)dict, &pos, &key, &value, NULL)) {
PyObject *item = _PyTuple_FromPair(key, value);
if (item == NULL) {
Py_SET_SIZE(self, m + i);
return -1;
Expand Down
Loading
Loading