Repository navigation
PyDecContextObject and PyDecObject in decimal module are missing PyObject_GC_Track #107994
Copy link
Copy link
Open
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
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:
cpython/Modules/_decimal/_decimal.c
Lines 1334 to 1380 in a794ebe
| 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:
cpython/Modules/_decimal/_decimal.c
Lines 2002 to 2028 in a794ebe
| 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; | |
| } |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
CharlieZhao95 commentedon Aug 16, 2023
Another problem is that when I tried to fix them, I added this code: CharlieZhao95@05cf606.
But there is a segfault when building, which seems to be a buff overflow error, what's wrong here?