Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-111178: Avoid calling functions from incompatible pointer types in dictobject.c #112892

Merged
merged 21 commits into from
Jan 2, 2024

Conversation

chrstphrchvz
Copy link
Contributor

@chrstphrchvz chrstphrchvz commented Dec 9, 2023

Proposed separately for review by respective codeowners.

Potential compiler warnings eliminated:
Objects/dictobject.c:2470:5: warning: cast from 'void (*)(PyDictObject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 2470 |     Py_TRASHCAN_BEGIN(mp, dict_dealloc)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/cpython/object.h:482:43: note: expanded from macro 'Py_TRASHCAN_BEGIN'
  481 |     Py_TRASHCAN_BEGIN_CONDITION((op), \
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  482 |         _PyTrash_cond(_PyObject_CAST(op), (destructor)(dealloc)))
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
./Include/cpython/object.h:467:13: note: expanded from macro 'Py_TRASHCAN_BEGIN_CONDITION'
  467 |         if (cond) { \
      |             ^~~~
Objects/dictobject.c:2635:5: warning: cast from 'Py_ssize_t (*)(PyDictObject *)' (aka 'long (*)(PyDictObject *)') to 'lenfunc' (aka 'long (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 2635 |     (lenfunc)dict_length, /*mp_length*/
      |     ^~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:2636:5: warning: cast from 'PyObject *(*)(PyDictObject *, PyObject *)' (aka 'struct _object *(*)(PyDictObject *, struct _object *)') to 'binaryfunc' (aka 'struct _object *(*)(struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 2636 |     (binaryfunc)dict_subscript, /*mp_subscript*/
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:2637:5: warning: cast from 'int (*)(PyDictObject *, PyObject *, PyObject *)' (aka 'int (*)(PyDictObject *, struct _object *, struct _object *)') to 'objobjargproc' (aka 'int (*)(struct _object *, struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 2637 |     (objobjargproc)dict_ass_sub, /*mp_ass_subscript*/
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:2928:52: warning: cast from 'PyObject *(*)(PyDictObject *)' (aka 'struct _object *(*)(PyDictObject *)') to 'getiterfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 2928 |     if (PyDict_Check(b) && (Py_TYPE(b)->tp_iter == (getiterfunc)dict_iter)) {
      |                                                    ^~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:3158:33: warning: cast from 'PyObject *(*)(PyDictObject *)' (aka 'struct _object *(*)(PyDictObject *)') to 'getiterfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 3158 |     if (Py_TYPE(mp)->tp_iter == (getiterfunc)dict_iter &&
      |                                 ^~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:3766:21: warning: cast from 'PyObject *(*)(PyDictObject *, PyObject *)' (aka 'struct _object *(*)(PyDictObject *, struct _object *)') to 'void (*)(void)' converts to incompatible function type [-Wcast-function-type-strict]
 3766 |     {"__getitem__", _PyCFunction_CAST(dict_subscript),        METH_O | METH_COEXIST,
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/methodobject.h:46:27: note: expanded from macro '_PyCFunction_CAST'
   46 |     _Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))
      |     ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/pyport.h:19:31: note: expanded from macro '_Py_CAST'
   19 | #define _Py_CAST(type, expr) ((type)(expr))
      |                               ^
./Include/pyport.h:19:38: note: expanded from macro '_Py_CAST'
   19 | #define _Py_CAST(type, expr) ((type)(expr))
      |                                      ^~~~
Objects/dictobject.c:3766:21: warning: cast from 'void (*)(void)' to 'PyCFunction' (aka 'struct _object *(*)(struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 3766 |     {"__getitem__", _PyCFunction_CAST(dict_subscript),        METH_O | METH_COEXIST,
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/methodobject.h:46:5: note: expanded from macro '_PyCFunction_CAST'
   46 |     _Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/pyport.h:19:31: note: expanded from macro '_Py_CAST'
   19 | #define _Py_CAST(type, expr) ((type)(expr))
      |                               ^~~~~~~~~~~~
Objects/dictobject.c:3768:25: warning: cast from 'PyObject *(*)(PyDictObject *, PyObject *)' (aka 'struct _object *(*)(PyDictObject *, struct _object *)') to 'void (*)(void)' converts to incompatible function type [-Wcast-function-type-strict]
 3768 |     {"__sizeof__",      _PyCFunction_CAST(dict_sizeof),       METH_NOARGS,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/methodobject.h:46:27: note: expanded from macro '_PyCFunction_CAST'
   46 |     _Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))
      |     ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/pyport.h:19:31: note: expanded from macro '_Py_CAST'
   19 | #define _Py_CAST(type, expr) ((type)(expr))
      |                               ^
./Include/pyport.h:19:38: note: expanded from macro '_Py_CAST'
   19 | #define _Py_CAST(type, expr) ((type)(expr))
      |                                      ^~~~
Objects/dictobject.c:3768:25: warning: cast from 'void (*)(void)' to 'PyCFunction' (aka 'struct _object *(*)(struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 3768 |     {"__sizeof__",      _PyCFunction_CAST(dict_sizeof),       METH_NOARGS,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/methodobject.h:46:5: note: expanded from macro '_PyCFunction_CAST'
   46 |     _Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/pyport.h:19:31: note: expanded from macro '_Py_CAST'
   19 | #define _Py_CAST(type, expr) ((type)(expr))
      |                               ^~~~~~~~~~~~
Objects/dictobject.c:3783:25: warning: cast from 'PyObject *(*)(PyDictObject *, PyObject *)' (aka 'struct _object *(*)(PyDictObject *, struct _object *)') to 'PyCFunction' (aka 'struct _object *(*)(struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 3783 |     {"clear",           (PyCFunction)dict_clear,        METH_NOARGS,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:3785:25: warning: cast from 'PyObject *(*)(PyDictObject *, PyObject *)' (aka 'struct _object *(*)(PyDictObject *, struct _object *)') to 'PyCFunction' (aka 'struct _object *(*)(struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 3785 |     {"copy",            (PyCFunction)dict_copy,         METH_NOARGS,
      |                         ^~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:3961:5: warning: cast from 'void (*)(PyDictObject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 3961 |     (destructor)dict_dealloc,                   /* tp_dealloc */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:3966:5: warning: cast from 'PyObject *(*)(PyDictObject *)' (aka 'struct _object *(*)(PyDictObject *)') to 'reprfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 3966 |     (reprfunc)dict_repr,                        /* tp_repr */
      |     ^~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:3984:5: warning: cast from 'PyObject *(*)(PyDictObject *)' (aka 'struct _object *(*)(PyDictObject *)') to 'getiterfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 3984 |     (getiterfunc)dict_iter,                     /* tp_iter */
      |     ^~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4166:25: warning: cast from 'PyObject *(*)(dictiterobject *, PyObject *)' (aka 'struct _object *(*)(dictiterobject *, struct _object *)') to 'void (*)(void)' converts to incompatible function type [-Wcast-function-type-strict]
 4166 |     {"__length_hint__", _PyCFunction_CAST(dictiter_len), METH_NOARGS,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/methodobject.h:46:27: note: expanded from macro '_PyCFunction_CAST'
   46 |     _Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))
      |     ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/pyport.h:19:31: note: expanded from macro '_Py_CAST'
   19 | #define _Py_CAST(type, expr) ((type)(expr))
      |                               ^
./Include/pyport.h:19:38: note: expanded from macro '_Py_CAST'
   19 | #define _Py_CAST(type, expr) ((type)(expr))
      |                                      ^~~~
Objects/dictobject.c:4166:25: warning: cast from 'void (*)(void)' to 'PyCFunction' (aka 'struct _object *(*)(struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 4166 |     {"__length_hint__", _PyCFunction_CAST(dictiter_len), METH_NOARGS,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/methodobject.h:46:5: note: expanded from macro '_PyCFunction_CAST'
   46 |     _Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/pyport.h:19:31: note: expanded from macro '_Py_CAST'
   19 | #define _Py_CAST(type, expr) ((type)(expr))
      |                               ^~~~~~~~~~~~
Objects/dictobject.c:4168:21: warning: cast from 'PyObject *(*)(dictiterobject *, PyObject *)' (aka 'struct _object *(*)(dictiterobject *, struct _object *)') to 'void (*)(void)' converts to incompatible function type [-Wcast-function-type-strict]
 4168 |      {"__reduce__", _PyCFunction_CAST(dictiter_reduce), METH_NOARGS,
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/methodobject.h:46:27: note: expanded from macro '_PyCFunction_CAST'
   46 |     _Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))
      |     ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/pyport.h:19:31: note: expanded from macro '_Py_CAST'
   19 | #define _Py_CAST(type, expr) ((type)(expr))
      |                               ^
./Include/pyport.h:19:38: note: expanded from macro '_Py_CAST'
   19 | #define _Py_CAST(type, expr) ((type)(expr))
      |                                      ^~~~
Objects/dictobject.c:4168:21: warning: cast from 'void (*)(void)' to 'PyCFunction' (aka 'struct _object *(*)(struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 4168 |      {"__reduce__", _PyCFunction_CAST(dictiter_reduce), METH_NOARGS,
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/methodobject.h:46:5: note: expanded from macro '_PyCFunction_CAST'
   46 |     _Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/pyport.h:19:31: note: expanded from macro '_Py_CAST'
   19 | #define _Py_CAST(type, expr) ((type)(expr))
      |                               ^~~~~~~~~~~~
Objects/dictobject.c:4247:5: warning: cast from 'void (*)(dictiterobject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 4247 |     (destructor)dictiter_dealloc,               /* tp_dealloc */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4264:5: warning: cast from 'int (*)(dictiterobject *, visitproc, void *)' (aka 'int (*)(dictiterobject *, int (*)(struct _object *, void *), void *)') to 'traverseproc' (aka 'int (*)(struct _object *, int (*)(struct _object *, void *), void *)') converts to incompatible function type [-Wcast-function-type-strict]
 4264 |     (traverseproc)dictiter_traverse,            /* tp_traverse */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4269:5: warning: cast from 'PyObject *(*)(dictiterobject *)' (aka 'struct _object *(*)(dictiterobject *)') to 'iternextfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 4269 |     (iternextfunc)dictiter_iternextkey,         /* tp_iternext */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4346:5: warning: cast from 'void (*)(dictiterobject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 4346 |     (destructor)dictiter_dealloc,               /* tp_dealloc */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4363:5: warning: cast from 'int (*)(dictiterobject *, visitproc, void *)' (aka 'int (*)(dictiterobject *, int (*)(struct _object *, void *), void *)') to 'traverseproc' (aka 'int (*)(struct _object *, int (*)(struct _object *, void *), void *)') converts to incompatible function type [-Wcast-function-type-strict]
 4363 |     (traverseproc)dictiter_traverse,            /* tp_traverse */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4368:5: warning: cast from 'PyObject *(*)(dictiterobject *)' (aka 'struct _object *(*)(dictiterobject *)') to 'iternextfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 4368 |     (iternextfunc)dictiter_iternextvalue,       /* tp_iternext */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4470:5: warning: cast from 'void (*)(dictiterobject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 4470 |     (destructor)dictiter_dealloc,               /* tp_dealloc */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4487:5: warning: cast from 'int (*)(dictiterobject *, visitproc, void *)' (aka 'int (*)(dictiterobject *, int (*)(struct _object *, void *), void *)') to 'traverseproc' (aka 'int (*)(struct _object *, int (*)(struct _object *, void *), void *)') converts to incompatible function type [-Wcast-function-type-strict]
 4487 |     (traverseproc)dictiter_traverse,            /* tp_traverse */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4492:5: warning: cast from 'PyObject *(*)(dictiterobject *)' (aka 'struct _object *(*)(dictiterobject *)') to 'iternextfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 4492 |     (iternextfunc)dictiter_iternextitem,        /* tp_iternext */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4603:19: warning: cast from 'void (*)(dictiterobject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 4603 |     .tp_dealloc = (destructor)dictiter_dealloc,
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4605:20: warning: cast from 'int (*)(dictiterobject *, visitproc, void *)' (aka 'int (*)(dictiterobject *, int (*)(struct _object *, void *), void *)') to 'traverseproc' (aka 'int (*)(struct _object *, int (*)(struct _object *, void *), void *)') converts to incompatible function type [-Wcast-function-type-strict]
 4605 |     .tp_traverse = (traverseproc)dictiter_traverse,
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4607:20: warning: cast from 'PyObject *(*)(dictiterobject *)' (aka 'struct _object *(*)(dictiterobject *)') to 'iternextfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 4607 |     .tp_iternext = (iternextfunc)dictreviter_iternext,
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4644:19: warning: cast from 'void (*)(dictiterobject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 4644 |     .tp_dealloc = (destructor)dictiter_dealloc,
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4646:20: warning: cast from 'int (*)(dictiterobject *, visitproc, void *)' (aka 'int (*)(dictiterobject *, int (*)(struct _object *, void *), void *)') to 'traverseproc' (aka 'int (*)(struct _object *, int (*)(struct _object *, void *), void *)') converts to incompatible function type [-Wcast-function-type-strict]
 4646 |     .tp_traverse = (traverseproc)dictiter_traverse,
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4648:20: warning: cast from 'PyObject *(*)(dictiterobject *)' (aka 'struct _object *(*)(dictiterobject *)') to 'iternextfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 4648 |     .tp_iternext = (iternextfunc)dictreviter_iternext,
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4656:19: warning: cast from 'void (*)(dictiterobject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 4656 |     .tp_dealloc = (destructor)dictiter_dealloc,
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4658:20: warning: cast from 'int (*)(dictiterobject *, visitproc, void *)' (aka 'int (*)(dictiterobject *, int (*)(struct _object *, void *), void *)') to 'traverseproc' (aka 'int (*)(struct _object *, int (*)(struct _object *, void *), void *)') converts to incompatible function type [-Wcast-function-type-strict]
 4658 |     .tp_traverse = (traverseproc)dictiter_traverse,
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4660:20: warning: cast from 'PyObject *(*)(dictiterobject *)' (aka 'struct _object *(*)(dictiterobject *)') to 'iternextfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 4660 |     .tp_iternext = (iternextfunc)dictreviter_iternext,
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4870:5: warning: cast from 'Py_ssize_t (*)(_PyDictViewObject *)' (aka 'long (*)(_PyDictViewObject *)') to 'lenfunc' (aka 'long (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 4870 |     (lenfunc)dictview_len,              /* sq_length */
      |     ^~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:4877:5: warning: cast from 'int (*)(_PyDictViewObject *, PyObject *)' (aka 'int (*)(_PyDictViewObject *, struct _object *)') to 'objobjproc' (aka 'int (*)(struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 4877 |     (objobjproc)dictkeys_contains,      /* sq_contains */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5208:25: warning: cast from 'PyObject *(*)(_PyDictViewObject *, PyObject *)' (aka 'struct _object *(*)(_PyDictViewObject *, struct _object *)') to 'void (*)(void)' converts to incompatible function type [-Wcast-function-type-strict]
 5208 |     {"__reversed__",    _PyCFunction_CAST(dictkeys_reversed),    METH_NOARGS,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/methodobject.h:46:27: note: expanded from macro '_PyCFunction_CAST'
   46 |     _Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))
      |     ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/pyport.h:19:31: note: expanded from macro '_Py_CAST'
   19 | #define _Py_CAST(type, expr) ((type)(expr))
      |                               ^
./Include/pyport.h:19:38: note: expanded from macro '_Py_CAST'
   19 | #define _Py_CAST(type, expr) ((type)(expr))
      |                                      ^~~~
Objects/dictobject.c:5208:25: warning: cast from 'void (*)(void)' to 'PyCFunction' (aka 'struct _object *(*)(struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 5208 |     {"__reversed__",    _PyCFunction_CAST(dictkeys_reversed),    METH_NOARGS,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/methodobject.h:46:5: note: expanded from macro '_PyCFunction_CAST'
   46 |     _Py_CAST(PyCFunction, _Py_CAST(void(*)(void), (func)))
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/pyport.h:19:31: note: expanded from macro '_Py_CAST'
   19 | #define _Py_CAST(type, expr) ((type)(expr))
      |                               ^~~~~~~~~~~~
Objects/dictobject.c:5219:5: warning: cast from 'void (*)(_PyDictViewObject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 5219 |     (destructor)dictview_dealloc,               /* tp_dealloc */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5224:5: warning: cast from 'PyObject *(*)(_PyDictViewObject *)' (aka 'struct _object *(*)(_PyDictViewObject *)') to 'reprfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 5224 |     (reprfunc)dictview_repr,                    /* tp_repr */
      |     ^~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5236:5: warning: cast from 'int (*)(_PyDictViewObject *, visitproc, void *)' (aka 'int (*)(_PyDictViewObject *, int (*)(struct _object *, void *), void *)') to 'traverseproc' (aka 'int (*)(struct _object *, int (*)(struct _object *, void *), void *)') converts to incompatible function type [-Wcast-function-type-strict]
 5236 |     (traverseproc)dictview_traverse,            /* tp_traverse */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5240:5: warning: cast from 'PyObject *(*)(_PyDictViewObject *)' (aka 'struct _object *(*)(_PyDictViewObject *)') to 'getiterfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 5240 |     (getiterfunc)dictkeys_iter,                 /* tp_iter */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5292:5: warning: cast from 'Py_ssize_t (*)(_PyDictViewObject *)' (aka 'long (*)(_PyDictViewObject *)') to 'lenfunc' (aka 'long (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 5292 |     (lenfunc)dictview_len,              /* sq_length */
      |     ^~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5299:5: warning: cast from 'int (*)(_PyDictViewObject *, PyObject *)' (aka 'int (*)(_PyDictViewObject *, struct _object *)') to 'objobjproc' (aka 'int (*)(struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 5299 |     (objobjproc)dictitems_contains,     /* sq_contains */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5310:25: warning: cast from 'PyObject *(*)(_PyDictViewObject *, PyObject *)' (aka 'struct _object *(*)(_PyDictViewObject *, struct _object *)') to 'PyCFunction' (aka 'struct _object *(*)(struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 5310 |     {"__reversed__",    (PyCFunction)dictitems_reversed,    METH_NOARGS,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5321:5: warning: cast from 'void (*)(_PyDictViewObject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 5321 |     (destructor)dictview_dealloc,               /* tp_dealloc */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5326:5: warning: cast from 'PyObject *(*)(_PyDictViewObject *)' (aka 'struct _object *(*)(_PyDictViewObject *)') to 'reprfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 5326 |     (reprfunc)dictview_repr,                    /* tp_repr */
      |     ^~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5338:5: warning: cast from 'int (*)(_PyDictViewObject *, visitproc, void *)' (aka 'int (*)(_PyDictViewObject *, int (*)(struct _object *, void *), void *)') to 'traverseproc' (aka 'int (*)(struct _object *, int (*)(struct _object *, void *), void *)') converts to incompatible function type [-Wcast-function-type-strict]
 5338 |     (traverseproc)dictview_traverse,            /* tp_traverse */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5342:5: warning: cast from 'PyObject *(*)(_PyDictViewObject *)' (aka 'struct _object *(*)(_PyDictViewObject *)') to 'getiterfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 5342 |     (getiterfunc)dictitems_iter,                /* tp_iter */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5375:5: warning: cast from 'Py_ssize_t (*)(_PyDictViewObject *)' (aka 'long (*)(_PyDictViewObject *)') to 'lenfunc' (aka 'long (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 5375 |     (lenfunc)dictview_len,              /* sq_length */
      |     ^~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5391:25: warning: cast from 'PyObject *(*)(_PyDictViewObject *, PyObject *)' (aka 'struct _object *(*)(_PyDictViewObject *, struct _object *)') to 'PyCFunction' (aka 'struct _object *(*)(struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 5391 |     {"__reversed__",    (PyCFunction)dictvalues_reversed,    METH_NOARGS,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5402:5: warning: cast from 'void (*)(_PyDictViewObject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 5402 |     (destructor)dictview_dealloc,               /* tp_dealloc */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5407:5: warning: cast from 'PyObject *(*)(_PyDictViewObject *)' (aka 'struct _object *(*)(_PyDictViewObject *)') to 'reprfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 5407 |     (reprfunc)dictview_repr,                    /* tp_repr */
      |     ^~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5419:5: warning: cast from 'int (*)(_PyDictViewObject *, visitproc, void *)' (aka 'int (*)(_PyDictViewObject *, int (*)(struct _object *, void *), void *)') to 'traverseproc' (aka 'int (*)(struct _object *, int (*)(struct _object *, void *), void *)') converts to incompatible function type [-Wcast-function-type-strict]
 5419 |     (traverseproc)dictview_traverse,            /* tp_traverse */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/dictobject.c:5423:5: warning: cast from 'PyObject *(*)(_PyDictViewObject *)' (aka 'struct _object *(*)(_PyDictViewObject *)') to 'getiterfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 5423 |     (getiterfunc)dictvalues_iter,               /* tp_iter */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan -fsanitize=function errors eliminated:

Objects/typeobject.c:5581:12: runtime error: call to function dict_repr through pointer to incorrect function type 'struct _object *(*)(struct _object *)'
dictobject.c:2503: note: dict_repr defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/typeobject.c:5581:12 in 
Python/generated_cases.c.h:4872:30: runtime error: call to function dictiter_iternextkey through pointer to incorrect function type 'struct _object *(*)(struct _object *)'
dictobject.c:4175: note: dictiter_iternextkey defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:4872:30 in 
Objects/abstract.c:158:26: runtime error: call to function dict_subscript through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *)'
dictobject.c:2592: note: dict_subscript defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:158:26 in 
Objects/abstract.c:232:19: runtime error: call to function dict_ass_sub through pointer to incorrect function type 'int (*)(struct _object *, struct _object *, struct _object *)'
dictobject.c:2627: note: dict_ass_sub defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:232:19 in 
Python/generated_cases.c.h:2452:21: runtime error: call to function dictiter_dealloc through pointer to incorrect function type 'void (*)(struct _object *)'
dictobject.c:4132: note: dictiter_dealloc defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:2452:21 in 
Python/generated_cases.c.h:1225:13: runtime error: call to function dict_dealloc through pointer to incorrect function type 'void (*)(struct _object *)'
dictobject.c:2454: note: dict_dealloc defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:1225:13 in 
Objects/abstract.c:2371:26: runtime error: call to function dict_length through pointer to incorrect function type 'long (*)(struct _object *)'
dictobject.c:2586: note: dict_length defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:2371:26 in 
Objects/abstract.c:2913:25: runtime error: call to function dictitems_iter through pointer to incorrect function type 'struct _object *(*)(struct _object *)'
dictobject.c:5265: note: dictitems_iter defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:2913:25 in 
Python/generated_cases.c.h:2753:13: runtime error: call to function dictview_dealloc through pointer to incorrect function type 'void (*)(struct _object *)'
dictobject.c:4672: note: dictview_dealloc defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:2753:13 in 
Python/generated_cases.c.h:2440:24: runtime error: call to function dictiter_iternextitem through pointer to incorrect function type 'struct _object *(*)(struct _object *)'
dictobject.c:4375: note: dictiter_iternextitem defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:2440:24 in 
Objects/abstract.c:158:26: runtime error: call to function dict_subscript through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *)'
dictobject.c:2592: note: dict_subscript defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:158:26 in 

Copy link
Member

@methane methane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patch looks good to me.
But I don't catch the discussion in #111178.
Please merge this PR or ping me when they decide to do this type of change in whole CPython.

@encukou encukou merged commit a1eea1d into python:main Jan 2, 2024
33 checks passed
@chrstphrchvz chrstphrchvz deleted the patch-111178-dictobject branch January 2, 2024 23:32
kulikjak pushed a commit to kulikjak/cpython that referenced this pull request Jan 22, 2024
…pes in dictobject.c (python#112892)

Fix undefined behavior warnings (UBSan  -fsanitize=function).
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…pes in dictobject.c (python#112892)

Fix undefined behavior warnings (UBSan  -fsanitize=function).
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
…pes in dictobject.c (python#112892)

Fix undefined behavior warnings (UBSan  -fsanitize=function).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants