GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-111178: Avoid calling functions from incompatible pointer types in dictobject.c by chrstphrchvz · Pull Request #112892 · python/cpython

Conversation

@chrstphrchvz

@chrstphrchvz chrstphrchvz commented Dec 9, 2023 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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 
  • Issue: UBSan: Calling a function through pointer to incorrect function type is undefined behavior #111178

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
chrstphrchvz added 21 commits December 5, 2023 06:21
@chrstphrchvz
Make dict_dealloc() compatible with destructor
c934a0d
@chrstphrchvz
Make dict_repr() compatible with reprfunc
9c1f2fb
@chrstphrchvz
Make dictvalues_iter() compatible with getiterfunc
38efefb
@chrstphrchvz
Make dictview_traverse() compatible with traverseproc
eb37bd9
@chrstphrchvz
Make dictview_len() compatible with lenfunc
da12a9c
@chrstphrchvz
Make dictview_repr() compatible with reprfunc
fad4d95
@chrstphrchvz
Make dictview_dealloc() compatible with destructor
ff04bb8
@chrstphrchvz
Make dictitems_iter() compatible with getiterfunc
4846c79
@chrstphrchvz
Make dict_iter() compatible with getiterfunc
034bbdc
@chrstphrchvz
Make dictiter_iternextkey() compatible with iternextfunc
67904d2
@chrstphrchvz
Make dictiter_traverse() compatible with traverseproc
55d5e54
@chrstphrchvz
Make dictiter_dealloc() compatible with destructor
03badfd
@chrstphrchvz
Make dictiter_iternextvalue() compatible with iternextfunc
d2b1c3f
@chrstphrchvz
Make dict_contains functions compatible with objobjproc
2bea048
@chrstphrchvz
Make dictkeys_iter() compatible with getiterfunc
55683a0
@chrstphrchvz
Make dictreviter_iternext() compatible with iternextfunc
ff5599b
@chrstphrchvz
Make dictiter_iternextitem() compatible with iternextfunc
def1d1a
@chrstphrchvz
Make dict_length() compatible with lenfunc
5001e3f
@chrstphrchvz
Make dict_subscript() compatible with binaryfunc/PyCFunction
ca84b60
@chrstphrchvz
Make dict_ass_sub() compatible with objobjargproc
378dd95
@chrstphrchvz
Make several functions compatible with PyCFunction
fa1f3c4
@chrstphrchvz
chrstphrchvz requested review from markshannon and methane as code owners December 9, 2023 02:31
@bedevere-app bedevere-app Bot added the awaiting review label Dec 9, 2023
@bedevere-app bedevere-app Bot mentioned this pull request Dec 9, 2023
UBSan: Calling a function through pointer to incorrect function type is undefined behavior #111178
Closed
@methane methane added the skip news label Dec 11, 2023
methane
methane approved these changes Dec 11, 2023
View reviewed changes

@methane methane left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

encukou reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Dec 11, 2023
encukou
encukou approved these changes Jan 2, 2024
View reviewed changes
@encukou
encukou merged commit a1eea1d into python:main Jan 2, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Jan 2, 2024
@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
@chrstphrchvz @kulikjak
pythongh-111178: Avoid calling functions from incompatible pointer ty…
3522030
…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
@chrstphrchvz @aisk
pythongh-111178: Avoid calling functions from incompatible pointer ty…
4225401
…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
@chrstphrchvz @Glyphack
pythongh-111178: Avoid calling functions from incompatible pointer ty…
1bf553d
…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

Reviewers

@methane methane methane approved these changes
@encukou encukou encukou approved these changes
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@chrstphrchvz @methane @encukou
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.