cextension

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

99封情书 提交于 2019-12-10 04:19:28
问题 The simplest way to manipulate the GIL in Python C extensions is to use the macros provided: my_awesome_C_function() { blah; Py_BEGIN_ALLOW_THREADS // do stuff that doesn't need the GIL if (should_i_call_back) { Py_BLOCK_THREADS // do stuff that needs the GIL Py_UNBLOCK_THREADS } Py_END_ALLOW_THREADS return blah blah; } This works great, letting me release the GIL for the bulk of my code, but re-grabbing it for small bits of code that need it. The problem is when I compile this with gcc, I

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

若如初见. 提交于 2019-12-05 05:30:15
The simplest way to manipulate the GIL in Python C extensions is to use the macros provided: my_awesome_C_function() { blah; Py_BEGIN_ALLOW_THREADS // do stuff that doesn't need the GIL if (should_i_call_back) { Py_BLOCK_THREADS // do stuff that needs the GIL Py_UNBLOCK_THREADS } Py_END_ALLOW_THREADS return blah blah; } This works great, letting me release the GIL for the bulk of my code, but re-grabbing it for small bits of code that need it. The problem is when I compile this with gcc, I get: ext/engine.c:548: warning: '_save' might be used uninitialized in this function because Py_BEGIN