Skip to content

Commit

Permalink
Apply better style for passing flags
Browse files Browse the repository at this point in the history
  • Loading branch information
1st1 committed Dec 12, 2024
1 parent 6072c46 commit c62afea
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
14 changes: 10 additions & 4 deletions gel/datatypes/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,21 @@ PyObject * _EdgeGeneric_RenderObject(PyObject *obj);
int _EdgeGeneric_RenderValues(
_PyUnicodeWriter *, PyObject *, PyObject **, Py_ssize_t);

int _EdgeGeneric_RenderItems(_PyUnicodeWriter *,
PyObject *, PyObject *,
PyObject **, Py_ssize_t, int, int, int);

PyObject * _EdgeGeneric_RichCompareValues(PyObject **, Py_ssize_t,
PyObject **, Py_ssize_t,
int);


#define EDGE_RENDER_NAMES 0x1
#define EDGE_RENDER_LINK_PROPS 0x2
#define EDGE_RENDER_IMPLICIT 0x4
#define EDGE_RENDER_DEFAULT 0

int _EdgeGeneric_RenderItems(_PyUnicodeWriter *,
PyObject *, PyObject *,
PyObject **, Py_ssize_t,
int);

#ifndef _PyList_CAST
# define _PyList_CAST(op) (assert(PyList_Check(op)), (PyListObject *)(op))
#endif
Expand Down
3 changes: 2 additions & 1 deletion gel/datatypes/namedtuple.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ namedtuple_repr(PyTupleObject *o)
if (_EdgeGeneric_RenderItems(&writer,
(PyObject *)o,
EdgeNamedTuple_Type_DESC(Py_TYPE(o)),
o->ob_item, Py_SIZE(o), 1, 0, 0) < 0)
o->ob_item, Py_SIZE(o),
EDGE_RENDER_NAMES) < 0)
{
goto error;
}
Expand Down
8 changes: 5 additions & 3 deletions gel/datatypes/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,11 @@ object_repr(EdgeObject *o)
goto error;
}

if (_EdgeGeneric_RenderItems(&writer,
(PyObject *)o, o->desc,
o->ob_item, Py_SIZE(o), 1, 1, 0) < 0)
if (_EdgeGeneric_RenderItems(
&writer,
(PyObject *)o, o->desc,
o->ob_item, Py_SIZE(o),
EDGE_RENDER_NAMES | EDGE_RENDER_LINK_PROPS) < 0)
{
goto error;
}
Expand Down
3 changes: 2 additions & 1 deletion gel/datatypes/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ record_repr(EdgeRecord *o)

if (_EdgeGeneric_RenderItems(&writer,
(PyObject *)o, o->desc,
o->ob_item, Py_SIZE(o), 0, 0, 0) < 0)
o->ob_item, Py_SIZE(o),
EDGE_RENDER_DEFAULT) < 0)
{
goto error;
}
Expand Down
10 changes: 4 additions & 6 deletions gel/datatypes/repr.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ int
_EdgeGeneric_RenderItems(_PyUnicodeWriter *writer,
PyObject *host, PyObject *desc,
PyObject **items, Py_ssize_t len,
int include_names,
int include_link_props,
int include_implicit)
int render_flags)
{
assert(EdgeRecordDesc_GetSize(desc) == len);

Expand Down Expand Up @@ -114,12 +112,12 @@ _EdgeGeneric_RenderItems(_PyUnicodeWriter *writer,
goto error;
}

if (is_implicit && !include_implicit) {
if (is_implicit && !(render_flags & EDGE_RENDER_IMPLICIT)) {
continue;
}

if (is_linkprop) {
if (!include_link_props) {
if (!(render_flags & EDGE_RENDER_LINK_PROPS)) {
continue;
}
}
Expand All @@ -129,7 +127,7 @@ _EdgeGeneric_RenderItems(_PyUnicodeWriter *writer,
goto error;
}

if (include_names) {
if (render_flags & EDGE_RENDER_NAMES) {
item_name = EdgeRecordDesc_PointerName(desc, i);
if (item_name == NULL) {
goto error;
Expand Down

0 comments on commit c62afea

Please sign in to comment.