Skip to content

Commit fea8db6

Browse files
committed
Merge remote-tracking branch 'upstream/main' into gh-159111
2 parents 488b485 + 1967a87 commit fea8db6

34 files changed

Lines changed: 1011 additions & 599 deletions

‎.github/workflows/mypy.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
7070
with:
7171
persist-credentials: false
72-
- uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0
72+
- uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0
7373
with:
7474
python-version: "3.15"
7575
activate-environment: true

‎.github/workflows/reusable-cifuzz.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
path: ./out/artifacts
4444
- name: Upload SARIF
4545
if: always() && steps.build.outcome == 'success'
46-
uses: github/codeql-action/upload-sarif@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4.38.0
46+
uses: github/codeql-action/upload-sarif@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2
4747
with:
4848
sarif_file: cifuzz-sarif/results.sarif
4949
checkout_path: cifuzz-sarif

‎Doc/c-api/bytes.rst‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,112 @@ Low-level API
464464
return NULL;
465465
}
466466
return (char*)PyBytesWriter_GetData(writer) + pos;
467+
468+
469+
Example creating the string ``b'abc'``
470+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
471+
472+
Example creating the bytes string ``b"abc"``, with a fixed size of 3 bytes::
473+
474+
PyObject* create_abc(void)
475+
{
476+
PyBytesWriter *writer = PyBytesWriter_Create(3);
477+
if (writer == NULL) {
478+
return NULL;
479+
}
480+
481+
char *str = PyBytesWriter_GetData(writer);
482+
memcpy(str, "abc", 3);
483+
return PyBytesWriter_Finish(writer);
484+
}
485+
486+
Variant using a pointer to compute the final size::
487+
488+
PyObject* create_abc_ptr(void)
489+
{
490+
PyBytesWriter *writer = PyBytesWriter_Create(3);
491+
if (writer == NULL) {
492+
return NULL;
493+
}
494+
495+
char *str = PyBytesWriter_GetData(writer);
496+
memcpy(str, "abc", 3);
497+
str += 1;
498+
return PyBytesWriter_FinishWithPointer(writer, str);
499+
}
500+
501+
502+
Update ``PyBytes_FromStringAndSize()`` code
503+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
504+
505+
Example of code using the soft deprecated
506+
``PyBytes_FromStringAndSize(NULL, size)`` API::
507+
508+
int copy_bytes(char *dest, const char *src, Py_ssize_t num_bytes)
509+
{
510+
...
511+
}
512+
513+
PyObject* create_string(const char *start, Py_ssize_t num_bytes)
514+
{
515+
PyObject *result = PyBytes_FromStringAndSize(NULL, num_bytes);
516+
if (result == NULL) {
517+
return NULL;
518+
}
519+
if (copy_bytes(PyBytes_AS_STRING(result), start, num_bytes) < 0) {
520+
Py_CLEAR(result);
521+
}
522+
return result;
523+
}
524+
525+
It can now be updated to::
526+
527+
PyObject* create_string(const char *start, Py_ssize_t num_bytes)
528+
{
529+
PyBytesWriter *writer = PyBytesWriter_Create(num_bytes);
530+
if (writer == NULL) {
531+
return NULL;
532+
}
533+
if (copy_bytes(PyBytesWriter_GetData(writer), start, num_bytes) < 0) {
534+
PyBytesWriter_Discard(writer);
535+
return NULL;
536+
}
537+
return PyBytesWriter_Finish(writer);
538+
}
539+
540+
541+
Update ``_PyBytes_Resize()`` code
542+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
543+
544+
Example of code using the soft deprecated ``_PyBytes_Resize()`` API::
545+
546+
void create_string(Py_ssize_t size)
547+
{
548+
PyObject *bytes = PyBytes_FromStringAndSize(NULL, size);
549+
if (bytes == NULL) {
550+
return NULL;
551+
}
552+
char *str = PyBytes_AS_STRING(bytes);
553+
554+
// ... write data into str ...
555+
556+
if (_PyBytes_Resize(&bytes, (str - PyBytes_AS_STRING(bytes)))) {
557+
return NULL;
558+
}
559+
return bytes;
560+
}
561+
562+
It can now be updated to::
563+
564+
void create_string(Py_ssize_t size)
565+
{
566+
PyBytesWriter *writer = PyBytesWriter_Create(size);
567+
if (writer == NULL) {
568+
return NULL;
569+
}
570+
char *str = PyBytesWriter_GetData(writer);
571+
572+
// ... write data into str ...
573+
574+
return PyBytesWriter_FinishWithPointer(writer, str);
575+
}

‎Doc/c-api/marshal.rst‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ and :exc:`MemoryError` if memory allocation fails.
4343
This function can fail, in which case it sets the error indicator.
4444
Use :c:func:`PyErr_Occurred` to check for that.
4545
46+
.. note::
47+
48+
In Python 3.15 and earlier, this function does not set the error
49+
indicator if writing to *file* fails.
50+
The same caveat applies as for :c:func:`PyMarshal_WriteObjectToFile`.
51+
4652
.. c:function:: void PyMarshal_WriteObjectToFile(PyObject *value, FILE *file, int version)
4753
4854
Marshal a Python object, *value*, to *file*.
@@ -51,6 +57,17 @@ and :exc:`MemoryError` if memory allocation fails.
5157
This function can fail, in which case it sets the error indicator.
5258
Use :c:func:`PyErr_Occurred` to check for that.
5359
60+
.. note::
61+
62+
In Python 3.15 and earlier, this function can write only part of the
63+
data to *file* and return without setting the error indicator, for
64+
example if *value* contains an object which cannot be marshalled or
65+
if writing to *file* fails (see :gh:`155907`).
66+
Code which has to support these versions cannot rely on
67+
:c:func:`PyErr_Occurred` alone to know that all the data was written.
68+
It can use :c:func:`PyMarshal_WriteObjectToString` and write the
69+
result itself, or validate what was written.
70+
5471
.. c:function:: PyObject* PyMarshal_WriteObjectToString(PyObject *value, int version)
5572
5673
Return a bytes object containing the marshalled representation of *value*.

‎Doc/library/idle.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,8 @@ the mainloop call. One then gets a shell prompt immediately and can
931931
interact with the live application. One just has to remember to
932932
re-enable the mainloop call when running in standard Python.
933933

934+
.. _idle-no-subprocess:
935+
934936
Running without a subprocess
935937
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
936938

0 commit comments

Comments
 (0)