[New-bugs-announce] [issue40842] _Pickler_CommitFrame() always returns 0 but it's return code is checked

Rémi Lapeyre report at bugs.python.org
Tue Jun 2 07:05:03 EDT 2020

New submission from Rémi Lapeyre <remi.lapeyre at henki.fr>:

I'm currently investigating a SystemError one of our workers returned:

   <method 'dump' of '_pickle.Pickler' objects> returned NULL without setting an error

While doing so I came across the _Pickler_CommitFrame() function:

static int
_Pickler_CommitFrame(PicklerObject *self)
    size_t frame_len;
    char *qdata;

    if (!self->framing || self->frame_start == -1)
        return 0;
    frame_len = self->output_len - self->frame_start - FRAME_HEADER_SIZE;
    qdata = PyBytes_AS_STRING(self->output_buffer) + self->frame_start;
    if (frame_len >= FRAME_SIZE_MIN) {
        qdata[0] = FRAME;
        _write_size64(qdata + 1, frame_len);
    else {
        memmove(qdata, qdata + FRAME_HEADER_SIZE, frame_len);
        self->output_len -= FRAME_HEADER_SIZE;
    self->frame_start = -1;
    return 0;

Is there a reason for this function to return an int if it is always 0? I checked all call sites (_Pickler_GetString(), _Pickler_OpcodeBoundary(), _Pickler_write_bytes() and dump()) and they all check the return code but it seems useless.

components: Library (Lib)
messages: 370603
nosy: remi.lapeyre
priority: normal
severity: normal
status: open
title: _Pickler_CommitFrame() always returns 0 but it's return code is checked
type: enhancement
versions: Python 3.10

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list