Skip to content

Commit fcc20f4

Browse files
committed
Do not add an underscore to the macro if none is needed.
In addition, change `_PyPartialObject_CAST` to `partialobject_CAST` as `_` + capital letter is UB.
1 parent 20069b8 commit fcc20f4

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

Modules/_functoolsmodule.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ typedef struct {
145145
} partialobject;
146146

147147
// cast a PyObject pointer PTR to a partialobject pointer (no type checks)
148-
#define _PyPartialObject_CAST(PTR) ((partialobject *)(PTR))
148+
#define partialobject_CAST(op) ((partialobject *)(op))
149149

150150
static void partial_setvectorcall(partialobject *pto);
151151
static struct PyModuleDef _functools_module;
@@ -312,7 +312,7 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw)
312312
static int
313313
partial_clear(PyObject *self)
314314
{
315-
partialobject *pto = _PyPartialObject_CAST(self);
315+
partialobject *pto = partialobject_CAST(self);
316316
Py_CLEAR(pto->fn);
317317
Py_CLEAR(pto->args);
318318
Py_CLEAR(pto->kw);
@@ -323,7 +323,7 @@ partial_clear(PyObject *self)
323323
static int
324324
partial_traverse(PyObject *self, visitproc visit, void *arg)
325325
{
326-
partialobject *pto = _PyPartialObject_CAST(self);
326+
partialobject *pto = partialobject_CAST(self);
327327
Py_VISIT(Py_TYPE(pto));
328328
Py_VISIT(pto->fn);
329329
Py_VISIT(pto->args);
@@ -338,7 +338,7 @@ partial_dealloc(PyObject *self)
338338
PyTypeObject *tp = Py_TYPE(self);
339339
/* bpo-31095: UnTrack is needed before calling any callbacks */
340340
PyObject_GC_UnTrack(self);
341-
if (_PyPartialObject_CAST(self)->weakreflist != NULL) {
341+
if (partialobject_CAST(self)->weakreflist != NULL) {
342342
PyObject_ClearWeakRefs(self);
343343
}
344344
(void)partial_clear(self);
@@ -372,7 +372,7 @@ static PyObject *
372372
partial_vectorcall(PyObject *self, PyObject *const *args,
373373
size_t nargsf, PyObject *kwnames)
374374
{
375-
partialobject *pto = _PyPartialObject_CAST(self);;
375+
partialobject *pto = partialobject_CAST(self);;
376376
PyThreadState *tstate = _PyThreadState_GET();
377377
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
378378

@@ -482,7 +482,7 @@ partial_setvectorcall(partialobject *pto)
482482
static PyObject *
483483
partial_call(PyObject *self, PyObject *args, PyObject *kwargs)
484484
{
485-
partialobject *pto = _PyPartialObject_CAST(self);
485+
partialobject *pto = partialobject_CAST(self);
486486
assert(PyCallable_Check(pto->fn));
487487
assert(PyTuple_Check(pto->args));
488488
assert(PyDict_Check(pto->kw));
@@ -595,7 +595,7 @@ static PyGetSetDef partial_getsetlist[] = {
595595
static PyObject *
596596
partial_repr(PyObject *self)
597597
{
598-
partialobject *pto = _PyPartialObject_CAST(self);
598+
partialobject *pto = partialobject_CAST(self);
599599
PyObject *result = NULL;
600600
PyObject *arglist;
601601
PyObject *mod;
@@ -668,7 +668,7 @@ partial_repr(PyObject *self)
668668
static PyObject *
669669
partial_reduce(PyObject *self, PyObject *Py_UNUSED(args))
670670
{
671-
partialobject *pto = _PyPartialObject_CAST(self);
671+
partialobject *pto = partialobject_CAST(self);
672672
return Py_BuildValue("O(O)(OOOO)", Py_TYPE(pto), pto->fn, pto->fn,
673673
pto->args, pto->kw,
674674
pto->dict ? pto->dict : Py_None);
@@ -677,7 +677,7 @@ partial_reduce(PyObject *self, PyObject *Py_UNUSED(args))
677677
static PyObject *
678678
partial_setstate(PyObject *self, PyObject *state)
679679
{
680-
partialobject *pto = _PyPartialObject_CAST(self);
680+
partialobject *pto = partialobject_CAST(self);
681681
PyObject *fn, *fnargs, *kw, *dict;
682682

683683
if (!PyTuple_Check(state)) {
@@ -782,12 +782,12 @@ typedef struct {
782782
PyObject *object;
783783
} keyobject;
784784

785-
#define _keyobject_CAST(op) ((keyobject *)(op))
785+
#define keyobject_CAST(op) ((keyobject *)(op))
786786

787787
static int
788788
keyobject_clear(PyObject *op)
789789
{
790-
keyobject *ko = _keyobject_CAST(op);
790+
keyobject *ko = keyobject_CAST(op);
791791
Py_CLEAR(ko->cmp);
792792
Py_CLEAR(ko->object);
793793
return 0;
@@ -806,7 +806,7 @@ keyobject_dealloc(PyObject *ko)
806806
static int
807807
keyobject_traverse(PyObject *op, visitproc visit, void *arg)
808808
{
809-
keyobject *ko = _keyobject_CAST(op);
809+
keyobject *ko = keyobject_CAST(op);
810810
Py_VISIT(Py_TYPE(ko));
811811
Py_VISIT(ko->cmp);
812812
Py_VISIT(ko->object);
@@ -863,7 +863,7 @@ keyobject_call(PyObject *self, PyObject *args, PyObject *kwds)
863863
PyObject *object;
864864
keyobject *result;
865865
static char *kwargs[] = {"obj", NULL};
866-
keyobject *ko = _keyobject_CAST(self);
866+
keyobject *ko = keyobject_CAST(self);
867867

868868
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:K", kwargs, &object))
869869
return NULL;
@@ -886,8 +886,8 @@ keyobject_richcompare(PyObject *self, PyObject *other, int op)
886886
return NULL;
887887
}
888888

889-
keyobject *lhs = _keyobject_CAST(self);
890-
keyobject *rhs = _keyobject_CAST(other);
889+
keyobject *lhs = keyobject_CAST(self);
890+
keyobject *rhs = keyobject_CAST(other);
891891

892892
PyObject *compare = lhs->cmp;
893893
assert(compare != NULL);
@@ -1061,12 +1061,12 @@ typedef struct lru_list_elem {
10611061
PyObject *key, *result;
10621062
} lru_list_elem;
10631063

1064-
#define _lru_list_elem_CAST(op) ((lru_list_elem *)(op))
1064+
#define lru_list_elem_CAST(op) ((lru_list_elem *)(op))
10651065

10661066
static void
10671067
lru_list_elem_dealloc(PyObject *op)
10681068
{
1069-
lru_list_elem *link = _lru_list_elem_CAST(op);
1069+
lru_list_elem *link = lru_list_elem_CAST(op);
10701070
PyTypeObject *tp = Py_TYPE(link);
10711071
Py_XDECREF(link->key);
10721072
Py_XDECREF(link->result);
@@ -1107,7 +1107,7 @@ typedef struct lru_cache_object {
11071107
PyObject *weakreflist;
11081108
} lru_cache_object;
11091109

1110-
#define _lru_cache_object_CAST(op) ((lru_cache_object *)(op))
1110+
#define lru_cache_object_CAST(op) ((lru_cache_object *)(op))
11111111

11121112
static PyObject *
11131113
lru_cache_make_key(PyObject *kwd_mark, PyObject *args,
@@ -1546,7 +1546,7 @@ lru_cache_clear_list(lru_list_elem *link)
15461546
static int
15471547
lru_cache_tp_clear(PyObject *op)
15481548
{
1549-
lru_cache_object *self = _lru_cache_object_CAST(op);
1549+
lru_cache_object *self = lru_cache_object_CAST(op);
15501550
lru_list_elem *list = lru_cache_unlink_list(self);
15511551
Py_CLEAR(self->cache);
15521552
Py_CLEAR(self->func);
@@ -1561,7 +1561,7 @@ lru_cache_tp_clear(PyObject *op)
15611561
static void
15621562
lru_cache_dealloc(PyObject *op)
15631563
{
1564-
lru_cache_object *obj = _lru_cache_object_CAST(op);
1564+
lru_cache_object *obj = lru_cache_object_CAST(op);
15651565
PyTypeObject *tp = Py_TYPE(obj);
15661566
/* bpo-31095: UnTrack is needed before calling any callbacks */
15671567
PyObject_GC_UnTrack(obj);
@@ -1577,7 +1577,7 @@ lru_cache_dealloc(PyObject *op)
15771577
static PyObject *
15781578
lru_cache_call(PyObject *op, PyObject *args, PyObject *kwds)
15791579
{
1580-
lru_cache_object *self = _lru_cache_object_CAST(op);
1580+
lru_cache_object *self = lru_cache_object_CAST(op);
15811581
PyObject *result;
15821582
Py_BEGIN_CRITICAL_SECTION(self);
15831583
result = self->wrapper(self, args, kwds);
@@ -1656,7 +1656,7 @@ lru_cache_deepcopy(PyObject *self, PyObject *unused)
16561656
static int
16571657
lru_cache_tp_traverse(PyObject *op, visitproc visit, void *arg)
16581658
{
1659-
lru_cache_object *self = _lru_cache_object_CAST(op);
1659+
lru_cache_object *self = lru_cache_object_CAST(op);
16601660
Py_VISIT(Py_TYPE(self));
16611661
lru_list_elem *link = self->root.next;
16621662
while (link != &self->root) {

0 commit comments

Comments
 (0)