Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use macro for constevaluatorobject casts
  • Loading branch information
picnixz committed Feb 6, 2025
commit c8cbe9bf8ee4f4b82b4b55b7591d9490535b75b7
16 changes: 10 additions & 6 deletions Objects/typevarobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@ typedef struct {
PyObject *value;
} constevaluatorobject;

#define constevaluatorobject_CAST(op) ((constevaluatorobject *)(op))

static void
constevaluator_dealloc(PyObject *self)
{
PyTypeObject *tp = Py_TYPE(self);
constevaluatorobject *ce = (constevaluatorobject *)self;
constevaluatorobject *ce = constevaluatorobject_CAST(self);

_PyObject_GC_UNTRACK(self);

Expand All @@ -143,36 +145,38 @@ constevaluator_dealloc(PyObject *self)
static int
constevaluator_traverse(PyObject *self, visitproc visit, void *arg)
{
constevaluatorobject *ce = (constevaluatorobject *)self;
constevaluatorobject *ce = constevaluatorobject_CAST(self);
Py_VISIT(ce->value);
return 0;
}

static int
constevaluator_clear(PyObject *self)
{
Py_CLEAR(((constevaluatorobject *)self)->value);
constevaluatorobject *ce = constevaluatorobject_CAST(self);
Py_CLEAR(ce->value);
return 0;
}

static PyObject *
constevaluator_repr(PyObject *self)
{
PyObject *value = ((constevaluatorobject *)self)->value;
return PyUnicode_FromFormat("<constevaluator %R>", value);
constevaluatorobject *ce = constevaluatorobject_CAST(self);
return PyUnicode_FromFormat("<constevaluator %R>", ce->value);
}

static PyObject *
constevaluator_call(PyObject *self, PyObject *args, PyObject *kwargs)
{
constevaluatorobject *ce = constevaluatorobject_CAST(self);
if (!_PyArg_NoKeywords("constevaluator.__call__", kwargs)) {
return NULL;
}
int format;
if (!PyArg_ParseTuple(args, "i:constevaluator.__call__", &format)) {
return NULL;
}
PyObject *value = ((constevaluatorobject *)self)->value;
PyObject *value = ce->value;
if (format == _Py_ANNOTATE_FORMAT_STRING) {
PyUnicodeWriter *writer = PyUnicodeWriter_Create(5); // cannot be <5
if (writer == NULL) {
Expand Down