Skip to content

Commit c864b85

Browse files
committed
Merge branch 'main' into test_capi_file
2 parents 871e239 + 5ab9604 commit c864b85

File tree

89 files changed

+753
-353
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+753
-353
lines changed

.github/workflows/build.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,45 @@ jobs:
527527
config_hash: ${{ needs.check_source.outputs.config_hash }}
528528
free-threading: ${{ matrix.free-threading }}
529529

530+
cross-build-linux:
531+
name: Cross build Linux
532+
runs-on: ubuntu-latest
533+
needs: check_source
534+
if: needs.check_source.outputs.run_tests == 'true'
535+
steps:
536+
- uses: actions/checkout@v4
537+
with:
538+
persist-credentials: false
539+
- name: Runner image version
540+
run: echo "IMAGE_VERSION=${ImageVersion}" >> "$GITHUB_ENV"
541+
- name: Restore config.cache
542+
uses: actions/cache@v4
543+
with:
544+
path: config.cache
545+
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-${{ needs.check_source.outputs.config_hash }}
546+
- name: Register gcc problem matcher
547+
run: echo "::add-matcher::.github/problem-matchers/gcc.json"
548+
- name: Set build dir
549+
run:
550+
# an absolute path outside of the working directoy
551+
echo "BUILD_DIR=$(realpath ${{ github.workspace }}/../build)" >> "$GITHUB_ENV"
552+
- name: Install Dependencies
553+
run: sudo ./.github/workflows/posix-deps-apt.sh
554+
- name: Configure host build
555+
run: ./configure --prefix="$BUILD_DIR/host-python"
556+
- name: Install host Python
557+
run: make -j8 install
558+
- name: Run test subset with host build
559+
run: |
560+
"$BUILD_DIR/host-python/bin/python3" -m test test_sysconfig test_site test_embed
561+
- name: Configure cross build
562+
run: ./configure --prefix="$BUILD_DIR/cross-python" --with-build-python="$BUILD_DIR/host-python/bin/python3"
563+
- name: Install cross Python
564+
run: make -j8 install
565+
- name: Run test subset with host build
566+
run: |
567+
"$BUILD_DIR/cross-python/bin/python3" -m test test_sysconfig test_site test_embed
568+
530569
# CIFuzz job based on https://google.github.io/oss-fuzz/getting-started/continuous-integration/
531570
cifuzz:
532571
name: CIFuzz

Doc/c-api/import.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,24 @@ Importing Modules
325325
If Python is initialized multiple times, :c:func:`PyImport_AppendInittab` or
326326
:c:func:`PyImport_ExtendInittab` must be called before each Python
327327
initialization.
328+
329+
330+
.. c:function:: PyObject* PyImport_ImportModuleAttr(PyObject *mod_name, PyObject *attr_name)
331+
332+
Import the module *mod_name* and get its attribute *attr_name*.
333+
334+
Names must be Python :class:`str` objects.
335+
336+
Helper function combining :c:func:`PyImport_Import` and
337+
:c:func:`PyObject_GetAttr`. For example, it can raise :exc:`ImportError` if
338+
the module is not found, and :exc:`AttributeError` if the attribute doesn't
339+
exist.
340+
341+
.. versionadded:: 3.14
342+
343+
.. c:function:: PyObject* PyImport_ImportModuleAttrString(const char *mod_name, const char *attr_name)
344+
345+
Similar to :c:func:`PyImport_ImportModuleAttr`, but names are UTF-8 encoded
346+
strings instead of Python :class:`str` objects.
347+
348+
.. versionadded:: 3.14

Doc/data/refcounts.dat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3052,3 +3052,11 @@ _Py_c_quot:Py_complex:divisor::
30523052
_Py_c_sum:Py_complex:::
30533053
_Py_c_sum:Py_complex:left::
30543054
_Py_c_sum:Py_complex:right::
3055+
3056+
PyImport_ImportModuleAttr:PyObject*::+1:
3057+
PyImport_ImportModuleAttr:PyObject*:mod_name:0:
3058+
PyImport_ImportModuleAttr:PyObject*:attr_name:0:
3059+
3060+
PyImport_ImportModuleAttrString:PyObject*::+1:
3061+
PyImport_ImportModuleAttrString:const char *:mod_name::
3062+
PyImport_ImportModuleAttrString:const char *:attr_name::

Doc/library/logging.handlers.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ The :class:`SysLogHandler` class, located in the :mod:`logging.handlers` module,
613613
supports sending logging messages to a remote or local Unix syslog.
614614

615615

616-
.. class:: SysLogHandler(address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER, socktype=socket.SOCK_DGRAM)
616+
.. class:: SysLogHandler(address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER, socktype=socket.SOCK_DGRAM, timeout=None)
617617

618618
Returns a new instance of the :class:`SysLogHandler` class intended to
619619
communicate with a remote Unix machine whose address is given by *address* in
@@ -626,6 +626,11 @@ supports sending logging messages to a remote or local Unix syslog.
626626
*socktype* argument, which defaults to :const:`socket.SOCK_DGRAM` and thus
627627
opens a UDP socket. To open a TCP socket (for use with the newer syslog
628628
daemons such as rsyslog), specify a value of :const:`socket.SOCK_STREAM`.
629+
If *timeout* is specified, it sets a timeout (in seconds) for the socket operations.
630+
This can help prevent the program from hanging indefinitely if the syslog server is
631+
unreachable. By default, *timeout* is ``None``, meaning no timeout is applied.
632+
633+
629634

630635
Note that if your server is not listening on UDP port 514,
631636
:class:`SysLogHandler` may appear not to work. In that case, check what
@@ -645,6 +650,8 @@ supports sending logging messages to a remote or local Unix syslog.
645650
.. versionchanged:: 3.2
646651
*socktype* was added.
647652

653+
.. versionchanged:: 3.14
654+
*timeout* was added.
648655

649656
.. method:: close()
650657

Doc/using/configure.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ General Options
311311

312312
By convention, ``--enable-experimental-jit`` is a shorthand for ``--enable-experimental-jit=yes``.
313313

314+
.. note::
315+
316+
When building CPython with JIT enabled, ensure that your system has Python 3.11 or later installed.
317+
314318
.. versionadded:: 3.13
315319

316320
.. option:: PKG_CONFIG

Doc/whatsnew/3.14.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,11 @@ New features
13221322
* Add :c:func:`PyUnstable_IsImmortal` for determining whether an object is :term:`immortal`,
13231323
for debugging purposes.
13241324

1325+
* Add :c:func:`PyImport_ImportModuleAttr` and
1326+
:c:func:`PyImport_ImportModuleAttrString` helper functions to import a module
1327+
and get an attribute of the module.
1328+
(Contributed by Victor Stinner in :gh:`128911`.)
1329+
13251330

13261331
Limited C API changes
13271332
---------------------

Include/cpython/import.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ struct _frozen {
2121
collection of frozen modules: */
2222

2323
PyAPI_DATA(const struct _frozen *) PyImport_FrozenModules;
24+
25+
PyAPI_FUNC(PyObject*) PyImport_ImportModuleAttr(
26+
PyObject *mod_name,
27+
PyObject *attr_name);
28+
PyAPI_FUNC(PyObject*) PyImport_ImportModuleAttrString(
29+
const char *mod_name,
30+
const char *attr_name);

Include/cpython/longintrepr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ typedef long stwodigits; /* signed variant of twodigits */
7676
- 1: Zero
7777
- 2: Negative
7878
79-
The third lowest bit of lv_tag is reserved for an immortality flag, but is
80-
not currently used.
79+
The third lowest bit of lv_tag is
80+
set to 1 for the small ints.
8181
8282
In a normalized number, ob_digit[ndigits-1] (the most significant
8383
digit) is never zero. Also, in all cases, for all valid i,

Include/cpython/unicodeobject.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ enum PyUnicode_Kind {
240240
PyUnicode_4BYTE_KIND = 4
241241
};
242242

243+
PyAPI_FUNC(int) PyUnicode_KIND(PyObject *op);
244+
243245
// PyUnicode_KIND(): Return one of the PyUnicode_*_KIND values defined above.
244246
//
245247
// gh-89653: Converting this macro to a static inline function would introduce
@@ -264,13 +266,15 @@ static inline void* _PyUnicode_NONCOMPACT_DATA(PyObject *op) {
264266
return data;
265267
}
266268

267-
static inline void* PyUnicode_DATA(PyObject *op) {
269+
PyAPI_FUNC(void*) PyUnicode_DATA(PyObject *op);
270+
271+
static inline void* _PyUnicode_DATA(PyObject *op) {
268272
if (PyUnicode_IS_COMPACT(op)) {
269273
return _PyUnicode_COMPACT_DATA(op);
270274
}
271275
return _PyUnicode_NONCOMPACT_DATA(op);
272276
}
273-
#define PyUnicode_DATA(op) PyUnicode_DATA(_PyObject_CAST(op))
277+
#define PyUnicode_DATA(op) _PyUnicode_DATA(_PyObject_CAST(op))
274278

275279
/* Return pointers to the canonical representation cast to unsigned char,
276280
Py_UCS2, or Py_UCS4 for direct character access.

Include/internal/pycore_frame.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,6 @@ static inline void _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *
159159
// Don't leave a dangling pointer to the old frame when creating generators
160160
// and coroutines:
161161
dest->previous = NULL;
162-
163-
#ifdef Py_GIL_DISABLED
164-
PyCodeObject *co = _PyFrame_GetCode(dest);
165-
for (int i = stacktop; i < co->co_nlocalsplus + co->co_stacksize; i++) {
166-
dest->localsplus[i] = PyStackRef_NULL;
167-
}
168-
#endif
169162
}
170163

171164
#ifdef Py_GIL_DISABLED
@@ -222,16 +215,6 @@ _PyFrame_Initialize(
222215
for (int i = null_locals_from; i < code->co_nlocalsplus; i++) {
223216
frame->localsplus[i] = PyStackRef_NULL;
224217
}
225-
226-
#ifdef Py_GIL_DISABLED
227-
// On GIL disabled, we walk the entire stack in GC. Since stacktop
228-
// is not always in sync with the real stack pointer, we have
229-
// no choice but to traverse the entire stack.
230-
// This just makes sure we don't pass the GC invalid stack values.
231-
for (int i = code->co_nlocalsplus; i < code->co_nlocalsplus + code->co_stacksize; i++) {
232-
frame->localsplus[i] = PyStackRef_NULL;
233-
}
234-
#endif
235218
}
236219

237220
/* Gets the pointer to the locals array
@@ -405,13 +388,6 @@ _PyFrame_PushTrampolineUnchecked(PyThreadState *tstate, PyCodeObject *code, int
405388
frame->lltrace = 0;
406389
#endif
407390
frame->return_offset = 0;
408-
409-
#ifdef Py_GIL_DISABLED
410-
assert(code->co_nlocalsplus == 0);
411-
for (int i = 0; i < code->co_stacksize; i++) {
412-
frame->localsplus[i] = PyStackRef_NULL;
413-
}
414-
#endif
415391
return frame;
416392
}
417393

0 commit comments

Comments
 (0)