How to avoid gcc warning in Python C extension when using Py_BEGIN_ALLOW_THREADS

若如初见. 提交于 2019-12-05 05:30:15
  1. Yes, it is possible to suppress uninitialized warnings using the -Wno- prefix.

-Wall -Wno-uninitialized

If you want to remove just this warning, you could simply initialize _save to a null pointer so that it doesn't rely on a function return value... that one line of code and a comment makes sense to me:

PyThreadState *_save; 
_save = 0; /* init as null pointer value */
_save = PyEval_SaveThread();

My two cents:

  1. You can suppress specific warnings, but I guess you already knew that.
  2. It says might be uninitialized :-)
  3. The only reason I can imagine is compatibility with older C compilers.

I tried digging into the source, but couldn't find any good clues.

Ned, you can try one of these:

#pragma GCC diagnostic warning "-Wno-unitialized"
#pragma GCC diagnostic error "-Wno-uninitialized"
#pragma GCC diagnostic ignored "-Wno-uninialized"

Or ignore -Wuninitialized? According to the documentation, you have to do this before any data or functions are defined. Maybe it will let you disable the warning just for that file?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!