Skip to content

Commit

Permalink
Merge branch 'main' into allow_initial_keyword_reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
sayandipdutta committed Nov 2, 2024
2 parents 7cc052f + 914356f commit 4130df8
Show file tree
Hide file tree
Showing 21 changed files with 95 additions and 35 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/jit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ concurrency:
jobs:
interpreter:
name: Interpreter (Debug)
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
timeout-minutes: 90
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -85,19 +85,19 @@ jobs:
compiler: clang
- target: x86_64-unknown-linux-gnu/gcc
architecture: x86_64
runner: ubuntu-latest
runner: ubuntu-22.04
compiler: gcc
- target: x86_64-unknown-linux-gnu/clang
architecture: x86_64
runner: ubuntu-latest
runner: ubuntu-22.04
compiler: clang
- target: aarch64-unknown-linux-gnu/gcc
architecture: aarch64
runner: ubuntu-latest
runner: ubuntu-22.04
compiler: gcc
- target: aarch64-unknown-linux-gnu/clang
architecture: aarch64
runner: ubuntu-latest
runner: ubuntu-22.04
compiler: clang
env:
CC: ${{ matrix.compiler }}
Expand Down Expand Up @@ -169,7 +169,7 @@ jobs:
jit-with-disabled-gil:
name: Free-Threaded (Debug)
needs: interpreter
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
llvm:
Expand Down
2 changes: 1 addition & 1 deletion Doc/c-api/conversion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ The following functions provide locale-independent string to number conversions.
If ``s`` represents a value that is too large to store in a float
(for example, ``"1e500"`` is such a string on many platforms) then
if ``overflow_exception`` is ``NULL`` return ``Py_HUGE_VAL`` (with
if ``overflow_exception`` is ``NULL`` return ``Py_INFINITY`` (with
an appropriate sign) and don't set any exception. Otherwise,
``overflow_exception`` must point to a Python exception object;
raise that exception and return ``-1.0``. In both cases, set
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ iterations of the loop.

.. versionadded:: 3.13

.. opcode:: FORMAT_SPEC
.. opcode:: FORMAT_WITH_SPEC

Formats the given value with the given format spec::

Expand Down
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,10 @@ Porting to Python 3.14
Deprecated
----------

* The :c:macro:`!Py_HUGE_VAL` macro is :term:`soft deprecated`,
use :c:macro:`!Py_INFINITY` instead.
(Contributed by Sergey B Kirpichev in :gh:`120026`.)

* Macros :c:macro:`!Py_IS_NAN`, :c:macro:`!Py_IS_INFINITY`
and :c:macro:`!Py_IS_FINITE` are :term:`soft deprecated`,
use instead :c:macro:`!isnan`, :c:macro:`!isinf` and
Expand Down
4 changes: 2 additions & 2 deletions Include/floatobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ PyAPI_DATA(PyTypeObject) PyFloat_Type;
#define Py_RETURN_INF(sign) \
do { \
if (copysign(1., sign) == 1.) { \
return PyFloat_FromDouble(Py_HUGE_VAL); \
return PyFloat_FromDouble(Py_INFINITY); \
} \
else { \
return PyFloat_FromDouble(-Py_HUGE_VAL); \
return PyFloat_FromDouble(-Py_INFINITY); \
} \
} while(0)

Expand Down
6 changes: 3 additions & 3 deletions Include/internal/pycore_pymath.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern "C" {
static inline void _Py_ADJUST_ERANGE1(double x)
{
if (errno == 0) {
if (x == Py_HUGE_VAL || x == -Py_HUGE_VAL) {
if (x == Py_INFINITY || x == -Py_INFINITY) {
errno = ERANGE;
}
}
Expand All @@ -44,8 +44,8 @@ static inline void _Py_ADJUST_ERANGE1(double x)

static inline void _Py_ADJUST_ERANGE2(double x, double y)
{
if (x == Py_HUGE_VAL || x == -Py_HUGE_VAL ||
y == Py_HUGE_VAL || y == -Py_HUGE_VAL)
if (x == Py_INFINITY || x == -Py_INFINITY ||
y == Py_INFINITY || y == -Py_INFINITY)
{
if (errno == 0) {
errno = ERANGE;
Expand Down
2 changes: 1 addition & 1 deletion Include/pymath.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

/* Py_HUGE_VAL should always be the same as Py_INFINITY. But historically
* this was not reliable and Python did not require IEEE floats and C99
* conformity. Prefer Py_INFINITY for new code.
* conformity. The macro was soft deprecated in Python 3.14, use Py_INFINITY instead.
*/
#ifndef Py_HUGE_VAL
# define Py_HUGE_VAL HUGE_VAL
Expand Down
3 changes: 3 additions & 0 deletions Lib/_pyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,7 @@ def __init__(self, file, mode='r', closefd=True, opener=None):
"""
if self._fd >= 0:
# Have to close the existing file first.
self._stat_atopen = None
try:
if self._closefd:
os.close(self._fd)
Expand Down Expand Up @@ -1583,6 +1584,7 @@ def __init__(self, file, mode='r', closefd=True, opener=None):
if e.errno != errno.ESPIPE:
raise
except:
self._stat_atopen = None
if owned_fd is not None:
os.close(owned_fd)
raise
Expand Down Expand Up @@ -1756,6 +1758,7 @@ def close(self):
called more than once without error.
"""
if not self.closed:
self._stat_atopen = None
try:
if self._closefd:
os.close(self._fd)
Expand Down
16 changes: 16 additions & 0 deletions Lib/test/test_cprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ def test_bad_counter_during_dealloc(self):

self.assertEqual(cm.unraisable.exc_type, TypeError)

def test_crash_with_not_enough_args(self):
# gh-126220
import _lsprof

for profile in [_lsprof.Profiler(), cProfile.Profile()]:
for method in [
"_pystart_callback",
"_pyreturn_callback",
"_ccall_callback",
"_creturn_callback",
]:
with self.subTest(profile=profile, method=method):
method_obj = getattr(profile, method)
with self.assertRaises(TypeError):
method_obj() # should not crash

def test_evil_external_timer(self):
# gh-120289
# Disabling profiler in external timer should not crash
Expand Down
5 changes: 4 additions & 1 deletion Lib/test/test_embed.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Run the tests in Programs/_testembed.c (tests for the CPython embedding APIs)
from test import support
from test.libregrtest.utils import get_build_info
from test.support import import_helper, os_helper, threading_helper, MS_WINDOWS
import unittest

Expand Down Expand Up @@ -1780,8 +1781,10 @@ def test_initconfig_api(self):
'perf_profiling': 2,
}
config_dev_mode(preconfig, config)
# Temporarily enable ignore_stderr=True to ignore warnings on JIT builds
# See gh-126255 for more information
self.check_all_configs("test_initconfig_api", config, preconfig,
api=API_ISOLATED)
api=API_ISOLATED, ignore_stderr=True)

def test_initconfig_get_api(self):
self.run_embedded_interpreter("test_initconfig_get_api")
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_perf_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ def test_sys_api_with_existing_trampoline(self):
sys.activate_stack_trampoline("perf")
sys.activate_stack_trampoline("perf")
"""
assert_python_ok("-c", code)
assert_python_ok("-c", code, PYTHON_JIT="0")

def test_sys_api_with_invalid_trampoline(self):
code = """if 1:
import sys
sys.activate_stack_trampoline("invalid")
"""
rc, out, err = assert_python_failure("-c", code)
rc, out, err = assert_python_failure("-c", code, PYTHON_JIT="0")
self.assertIn("invalid backend: invalid", err.decode())

def test_sys_api_get_status(self):
Expand All @@ -228,7 +228,7 @@ def test_sys_api_get_status(self):
sys.deactivate_stack_trampoline()
assert sys.is_stack_trampoline_active() is False
"""
assert_python_ok("-c", code)
assert_python_ok("-c", code, PYTHON_JIT="0")


def is_unwinding_reliable_with_frame_pointers():
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The :c:macro:`!Py_HUGE_VAL` macro is :term:`soft deprecated`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix crash in :class:`!cProfile.Profile` and :class:`!_lsprof.Profiler` when their
callbacks were directly called with 0 arguments.
11 changes: 6 additions & 5 deletions Modules/_io/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ internal_close(fileio *self)
_Py_END_SUPPRESS_IPH
Py_END_ALLOW_THREADS
}
PyMem_Free(self->stat_atopen);
self->stat_atopen = NULL;
if (err < 0) {
errno = save_errno;
PyErr_SetFromErrno(PyExc_OSError);
Expand Down Expand Up @@ -268,8 +270,9 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
if (self->fd >= 0) {
if (self->closefd) {
/* Have to close the existing file first. */
if (internal_close(self) < 0)
if (internal_close(self) < 0) {
return -1;
}
}
else
self->fd = -1;
Expand Down Expand Up @@ -523,10 +526,8 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
internal_close(self);
_PyErr_ChainExceptions1(exc);
}
if (self->stat_atopen != NULL) {
PyMem_Free(self->stat_atopen);
self->stat_atopen = NULL;
}
PyMem_Free(self->stat_atopen);
self->stat_atopen = NULL;

done:
#ifdef MS_WINDOWS
Expand Down
24 changes: 24 additions & 0 deletions Modules/_lsprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,12 @@ setBuiltins(ProfilerObject *pObj, int nvalue)

PyObject* pystart_callback(ProfilerObject* self, PyObject *const *args, Py_ssize_t size)
{
if (size < 2) {
PyErr_Format(PyExc_TypeError,
"_pystart_callback expected 2 arguments, got %zd",
size);
return NULL;
}
PyObject* code = args[0];
ptrace_enter_call((PyObject*)self, (void *)code, (PyObject *)code);

Expand All @@ -616,6 +622,12 @@ PyObject* pystart_callback(ProfilerObject* self, PyObject *const *args, Py_ssize

PyObject* pyreturn_callback(ProfilerObject* self, PyObject *const *args, Py_ssize_t size)
{
if (size < 3) {
PyErr_Format(PyExc_TypeError,
"_pyreturn_callback expected 3 arguments, got %zd",
size);
return NULL;
}
PyObject* code = args[0];
ptrace_leave_call((PyObject*)self, (void *)code);

Expand Down Expand Up @@ -651,6 +663,12 @@ PyObject* get_cfunc_from_callable(PyObject* callable, PyObject* self_arg, PyObje

PyObject* ccall_callback(ProfilerObject* self, PyObject *const *args, Py_ssize_t size)
{
if (size < 4) {
PyErr_Format(PyExc_TypeError,
"_ccall_callback expected 4 arguments, got %zd",
size);
return NULL;
}
if (self->flags & POF_BUILTINS) {
PyObject* callable = args[2];
PyObject* self_arg = args[3];
Expand All @@ -669,6 +687,12 @@ PyObject* ccall_callback(ProfilerObject* self, PyObject *const *args, Py_ssize_t

PyObject* creturn_callback(ProfilerObject* self, PyObject *const *args, Py_ssize_t size)
{
if (size < 4) {
PyErr_Format(PyExc_TypeError,
"_creturn_callback expected 4 arguments, got %zd",
size);
return NULL;
}
if (self->flags & POF_BUILTINS) {
PyObject* callable = args[2];
PyObject* self_arg = args[3];
Expand Down
2 changes: 1 addition & 1 deletion Modules/cmathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ special_type(double d)
#define P14 0.25*Py_MATH_PI
#define P12 0.5*Py_MATH_PI
#define P34 0.75*Py_MATH_PI
#define INF Py_HUGE_VAL
#define INF Py_INFINITY
#define N Py_NAN
#define U -9.5426319407711027e33 /* unlikely value, used as placeholder */

Expand Down
14 changes: 7 additions & 7 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ m_tgamma(double x)
}
else {
errno = ERANGE;
return Py_HUGE_VAL;
return Py_INFINITY;
}
}

Expand Down Expand Up @@ -502,14 +502,14 @@ m_lgamma(double x)
if (isnan(x))
return x; /* lgamma(nan) = nan */
else
return Py_HUGE_VAL; /* lgamma(+-inf) = +inf */
return Py_INFINITY; /* lgamma(+-inf) = +inf */
}

/* integer arguments */
if (x == floor(x) && x <= 2.0) {
if (x <= 0.0) {
errno = EDOM; /* lgamma(n) = inf, divide-by-zero for */
return Py_HUGE_VAL; /* integers n <= 0 */
return Py_INFINITY; /* integers n <= 0 */
}
else {
return 0.0; /* lgamma(1) = lgamma(2) = 0.0 */
Expand Down Expand Up @@ -645,7 +645,7 @@ m_log(double x)
return log(x);
errno = EDOM;
if (x == 0.0)
return -Py_HUGE_VAL; /* log(0) = -inf */
return -Py_INFINITY; /* log(0) = -inf */
else
return Py_NAN; /* log(-ve) = nan */
}
Expand Down Expand Up @@ -688,7 +688,7 @@ m_log2(double x)
}
else if (x == 0.0) {
errno = EDOM;
return -Py_HUGE_VAL; /* log2(0) = -inf, divide-by-zero */
return -Py_INFINITY; /* log2(0) = -inf, divide-by-zero */
}
else {
errno = EDOM;
Expand All @@ -704,7 +704,7 @@ m_log10(double x)
return log10(x);
errno = EDOM;
if (x == 0.0)
return -Py_HUGE_VAL; /* log10(0) = -inf */
return -Py_INFINITY; /* log10(0) = -inf */
else
return Py_NAN; /* log10(-ve) = nan */
}
Expand Down Expand Up @@ -2126,7 +2126,7 @@ math_ldexp_impl(PyObject *module, double x, PyObject *i)
errno = 0;
} else if (exp > INT_MAX) {
/* overflow */
r = copysign(Py_HUGE_VAL, x);
r = copysign(Py_INFINITY, x);
errno = ERANGE;
} else if (exp < INT_MIN) {
/* underflow to +-0 */
Expand Down
2 changes: 1 addition & 1 deletion Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2390,7 +2390,7 @@ PyFloat_Unpack2(const char *data, int le)
if (e == 0x1f) {
if (f == 0) {
/* Infinity */
return sign ? -Py_HUGE_VAL : Py_HUGE_VAL;
return sign ? -Py_INFINITY : Py_INFINITY;
}
else {
/* NaN */
Expand Down
7 changes: 6 additions & 1 deletion Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1310,12 +1310,17 @@ init_interp_main(PyThreadState *tstate)
enabled = *env != '0';
}
if (enabled) {
#ifdef _Py_JIT
// perf profiler works fine with tier 2 interpreter, so
// only checking for a "real JIT".
if (config->perf_profiling > 0) {
(void)PyErr_WarnEx(
PyExc_RuntimeWarning,
"JIT deactivated as perf profiling support is active",
0);
} else {
} else
#endif
{
PyObject *opt = _PyOptimizer_NewUOpOptimizer();
if (opt == NULL) {
return _PyStatus_ERR("can't initialize optimizer");
Expand Down
Loading

0 comments on commit 4130df8

Please sign in to comment.