Skip to content

Commit

Permalink
Merge branch 'main' into long_export
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Sep 18, 2024
2 parents b2be94a + 0c4884d commit ca98ad1
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Doc/c-api/complex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pointers. This is consistent throughout the API.
If *num* is null and *exp* is not a positive real number,
this method returns zero and sets :c:data:`errno` to :c:macro:`!EDOM`.
Set :c:data:`errno` to :c:macro:`!ERANGE` on overflows.
Complex Numbers as Python Objects
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
3 changes: 3 additions & 0 deletions Doc/c-api/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,7 @@ the variables:
single: PyExc_OverflowError (C var)
single: PyExc_PermissionError (C var)
single: PyExc_ProcessLookupError (C var)
single: PyExc_PythonFinalizationError (C var)
single: PyExc_RecursionError (C var)
single: PyExc_ReferenceError (C var)
single: PyExc_RuntimeError (C var)
Expand Down Expand Up @@ -1096,6 +1097,8 @@ the variables:
+-----------------------------------------+---------------------------------+----------+
| :c:data:`PyExc_ProcessLookupError` | :exc:`ProcessLookupError` | |
+-----------------------------------------+---------------------------------+----------+
| :c:data:`PyExc_PythonFinalizationError` | :exc:`PythonFinalizationError` | |
+-----------------------------------------+---------------------------------+----------+
| :c:data:`PyExc_RecursionError` | :exc:`RecursionError` | |
+-----------------------------------------+---------------------------------+----------+
| :c:data:`PyExc_ReferenceError` | :exc:`ReferenceError` | |
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/long.rst
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
Currently, ``-1`` corresponds to
``Py_ASNATIVEBYTES_NATIVE_ENDIAN | Py_ASNATIVEBYTES_UNSIGNED_BUFFER``.
.. c:namespace:: NULL
============================================= ======
Flag Value
============================================= ======
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ The available slot types are:
Specifies one of the following values:
.. c:namespace:: NULL
.. c:macro:: Py_MOD_GIL_USED
The module depends on the presence of the global interpreter lock (GIL),
Expand Down
34 changes: 31 additions & 3 deletions Doc/c-api/monitoring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Managing the Monitoring State
Monitoring states can be managed with the help of monitoring scopes. A scope
would typically correspond to a python function.
.. :c:function:: int PyMonitoring_EnterScope(PyMonitoringState *state_array, uint64_t *version, const uint8_t *event_types, Py_ssize_t length)
.. c:function:: int PyMonitoring_EnterScope(PyMonitoringState *state_array, uint64_t *version, const uint8_t *event_types, Py_ssize_t length)
Enter a monitored scope. ``event_types`` is an array of the event IDs for
events that may be fired from the scope. For example, the ID of a ``PY_START``
Expand All @@ -158,7 +158,35 @@ would typically correspond to a python function.
execution is paused, such as when emulating a generator, the scope needs to
be exited and re-entered.
.. :c:function:: int PyMonitoring_ExitScope(void)
The macros for *event_types* are:
.. c:namespace:: NULL
.. The table is here to make the docs searchable, and to allow automatic
links to the identifiers.
================================================== =====================================
Macro Event
================================================== =====================================
.. c:macro:: PY_MONITORING_EVENT_BRANCH :monitoring-event:`BRANCH`
.. c:macro:: PY_MONITORING_EVENT_CALL :monitoring-event:`CALL`
.. c:macro:: PY_MONITORING_EVENT_C_RAISE :monitoring-event:`C_RAISE`
.. c:macro:: PY_MONITORING_EVENT_C_RETURN :monitoring-event:`C_RETURN`
.. c:macro:: PY_MONITORING_EVENT_EXCEPTION_HANDLED :monitoring-event:`EXCEPTION_HANDLED`
.. c:macro:: PY_MONITORING_EVENT_INSTRUCTION :monitoring-event:`INSTRUCTION`
.. c:macro:: PY_MONITORING_EVENT_JUMP :monitoring-event:`JUMP`
.. c:macro:: PY_MONITORING_EVENT_LINE :monitoring-event:`LINE`
.. c:macro:: PY_MONITORING_EVENT_PY_RESUME :monitoring-event:`PY_RESUME`
.. c:macro:: PY_MONITORING_EVENT_PY_RETURN :monitoring-event:`PY_RETURN`
.. c:macro:: PY_MONITORING_EVENT_PY_START :monitoring-event:`PY_START`
.. c:macro:: PY_MONITORING_EVENT_PY_THROW :monitoring-event:`PY_THROW`
.. c:macro:: PY_MONITORING_EVENT_PY_UNWIND :monitoring-event:`PY_UNWIND`
.. c:macro:: PY_MONITORING_EVENT_PY_YIELD :monitoring-event:`PY_YIELD`
.. c:macro:: PY_MONITORING_EVENT_RAISE :monitoring-event:`RAISE`
.. c:macro:: PY_MONITORING_EVENT_RERAISE :monitoring-event:`RERAISE`
.. c:macro:: PY_MONITORING_EVENT_STOP_ITERATION :monitoring-event:`STOP_ITERATION`
================================================== =====================================
.. c:function:: int PyMonitoring_ExitScope(void)
Exit the last scope that was entered with ``PyMonitoring_EnterScope``.
4 changes: 4 additions & 0 deletions Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
('c:func', 'vsnprintf'),
# Standard C types
('c:type', 'FILE'),
('c:type', 'int8_t'),
('c:type', 'int16_t'),
('c:type', 'int32_t'),
('c:type', 'int64_t'),
('c:type', 'intmax_t'),
Expand All @@ -143,6 +145,7 @@
('c:type', 'time_t'),
('c:type', 'int8_t'),
('c:type', 'uint8_t'),
('c:type', 'uint16_t'),
('c:type', 'uint32_t'),
('c:type', 'uint64_t'),
('c:type', 'uintmax_t'),
Expand Down Expand Up @@ -246,6 +249,7 @@
('c:data', 'PyExc_OverflowError'),
('c:data', 'PyExc_PermissionError'),
('c:data', 'PyExc_ProcessLookupError'),
('c:data', 'PyExc_PythonFinalizationError'),
('c:data', 'PyExc_RecursionError'),
('c:data', 'PyExc_ReferenceError'),
('c:data', 'PyExc_RuntimeError'),
Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test_capi/test_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ def test_py_c_pow(self):

self.assertEqual(_py_c_pow(0j, -1)[1], errno.EDOM)
self.assertEqual(_py_c_pow(0j, 1j)[1], errno.EDOM)
self.assertEqual(_py_c_pow(*[DBL_MAX+1j]*2)[0], complex(*[INF]*2))
max_num = DBL_MAX+1j
self.assertEqual(_py_c_pow(max_num, max_num),
(complex(INF, INF), errno.ERANGE))
self.assertEqual(_py_c_pow(max_num, 2),
(complex(INF, INF), errno.ERANGE))


def test_py_c_abs(self):
Expand Down
15 changes: 7 additions & 8 deletions Lib/test/test_importlib/resources/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,17 @@ def test_implicit_files_submodule(self):
def _compile_importlib(self):
"""
Make a compiled-only copy of the importlib resources package.
Currently only code is copied, as importlib resources doesn't itself
have any resources.
"""
bin_site = self.fixtures.enter_context(os_helper.temp_dir())
c_resources = pathlib.Path(bin_site, 'c_resources')
sources = pathlib.Path(resources.__file__).parent
shutil.copytree(sources, c_resources, ignore=lambda *_: ['__pycache__'])

for dirpath, _, filenames in os.walk(c_resources):
for filename in filenames:
source_path = pathlib.Path(dirpath) / filename
cfile = source_path.with_suffix('.pyc')
py_compile.compile(source_path, cfile)
pathlib.Path.unlink(source_path)

for source_path in sources.glob('**/*.py'):
c_path = c_resources.joinpath(source_path.relative_to(sources)).with_suffix('.pyc')
py_compile.compile(source_path, c_path)
self.fixtures.enter_context(import_helper.DirsOnSysPath(bin_site))

def test_implicit_files_with_compiled_importlib(self):
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_perf_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def compile_trampolines_for_all_functions():
self.assertIn(line, child_perf_file_contents)


def _is_perf_vesion_at_least(major, minor):
def _is_perf_version_at_least(major, minor):
# The output of perf --version looks like "perf version 6.7-3" but
# it can also be perf version "perf version 5.15.143"
try:
Expand All @@ -494,7 +494,7 @@ def _is_perf_vesion_at_least(major, minor):


@unittest.skipUnless(perf_command_works(), "perf command doesn't work")
@unittest.skipUnless(_is_perf_vesion_at_least(6, 6), "perf command may not work due to a perf bug")
@unittest.skipUnless(_is_perf_version_at_least(6, 6), "perf command may not work due to a perf bug")
class TestPerfProfilerWithDwarf(unittest.TestCase, TestPerfProfilerMixin):
def run_perf(self, script_dir, script, activate_trampoline=True):
if activate_trampoline:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Set :data:`errno` in :c:func:`_Py_c_pow` on overflows. Patch by Sergey B
Kirpichev.
4 changes: 3 additions & 1 deletion Objects/complexobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ _Py_c_pow(Py_complex a, Py_complex b)
}
r.real = len*cos(phase);
r.imag = len*sin(phase);

_Py_ADJUST_ERANGE2(r.real, r.imag);
}
return r;
}
Expand Down Expand Up @@ -567,12 +569,12 @@ complex_pow(PyObject *v, PyObject *w, PyObject *z)
// a faster and more accurate algorithm.
if (b.imag == 0.0 && b.real == floor(b.real) && fabs(b.real) <= 100.0) {
p = c_powi(a, (long)b.real);
_Py_ADJUST_ERANGE2(p.real, p.imag);
}
else {
p = _Py_c_pow(a, b);
}

_Py_ADJUST_ERANGE2(p.real, p.imag);
if (errno == EDOM) {
PyErr_SetString(PyExc_ZeroDivisionError,
"zero to a negative or complex power");
Expand Down

0 comments on commit ca98ad1

Please sign in to comment.