Skip to content

PyDecContextObject and PyDecObject in decimal module are missing PyObject_GC_Track #107994

Open
@CharlieZhao95

Description

@CharlieZhao95

Checklist

  • I am confident this is a bug in CPython, not a bug in a third-party project
  • I have searched the CPython issue tracker,
    and am confident this bug has not been reported before

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

No response

A clear and concise description of the bug:

There are two objects(PyDecContextObject and PyDecObject) using PyObject_GC_New in the decimal module, but PyObject_GC_Track is not added to their constructors.

PyDecContextObject:

static PyObject *
context_new(PyTypeObject *type, PyObject *args UNUSED, PyObject *kwds UNUSED)
{
PyDecContextObject *self = NULL;
mpd_context_t *ctx;
decimal_state *state = get_module_state_by_def(type);
if (type == state->PyDecContext_Type) {
self = PyObject_GC_New(PyDecContextObject, state->PyDecContext_Type);
}
else {
self = (PyDecContextObject *)type->tp_alloc(type, 0);
}
if (self == NULL) {
return NULL;
}
self->traps = PyObject_CallObject((PyObject *)state->PyDecSignalDict_Type, NULL);
if (self->traps == NULL) {
self->flags = NULL;
Py_DECREF(self);
return NULL;
}
self->flags = PyObject_CallObject((PyObject *)state->PyDecSignalDict_Type, NULL);
if (self->flags == NULL) {
Py_DECREF(self);
return NULL;
}
ctx = CTX(self);
if (state->default_context_template) {
*ctx = *CTX(state->default_context_template);
}
else {
*ctx = dflt_ctx;
}
SdFlagAddr(self->traps) = &ctx->traps;
SdFlagAddr(self->flags) = &ctx->status;
CtxCaps(self) = 1;
self->tstate = NULL;
return (PyObject *)self;
}

PyDecObject:

static PyObject *
PyDecType_New(PyTypeObject *type)
{
PyDecObject *dec;
decimal_state *state = get_module_state_by_def(type);
if (type == state->PyDec_Type) {
dec = PyObject_GC_New(PyDecObject, state->PyDec_Type);
}
else {
dec = (PyDecObject *)type->tp_alloc(type, 0);
}
if (dec == NULL) {
return NULL;
}
dec->hash = -1;
MPD(dec)->flags = MPD_STATIC|MPD_STATIC_DATA;
MPD(dec)->exp = 0;
MPD(dec)->digits = 0;
MPD(dec)->len = 0;
MPD(dec)->alloc = _Py_DEC_MINALLOC;
MPD(dec)->data = dec->data;
return (PyObject *)dec;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions