[BUG]: Coverity warning: Uncaught exceptions
Open
Nobody has claimed this yet.
triage
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
2.11.1
Problem description
There is a report made for pytypes.h:
CID 323117 (#1 of 1): Uncaught exception (UNCAUGHT_EXCEPT)
exn_spec_violation: An exception of type std::runtime_error is thrown but the
exception specification noexcept doesn't allow it to be thrown. This will result in a call to terminate().
387 object &operator=(object &&other) noexcept {
388 if (this != &other) {
389 handle temp(m_ptr);
390 m_ptr = other.m_ptr;
391 other.m_ptr = nullptr;
fun_call_w_exception: Called function dec_ref throws an exception of type std::runtime_error. [show details]
392 temp.dec_ref();
393 }
394 return *this;
395 }
267 const handle &dec_ref() const & {
268#ifdef PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
269 if (m_ptr != nullptr && !PyGILState_Check()) {
1. fun_call_w_exception: Called function throw_gilstate_error throws an exception of type std::runtime_error.
270 throw_gilstate_error("pybind11::handle::dec_ref()");
271 }
272#endif
273 Py_XDECREF(m_ptr);
274 return *this;
275 }
301 void throw_gilstate_error(const std::string &function_name) const {
302 fprintf(
303 stderr,
304 "%s is being called while the GIL is either not held or invalid. Please see "
305 "https://pybind11.readthedocs.io/en/stable/advanced/"
306 "misc.html#common-sources-of-global-interpreter-lock-errors for debugging advice.\n"
307 "If you are convinced there is no bug in your code, you can #define "
308 "PYBIND11_NO_ASSERT_GIL_HELD_INCREF_DECREF"
309 "to disable this check. In that case you have to ensure this #define is consistently "
310 "used for all translation units linked into a given pybind11 extension, otherwise "
311 "there will be ODR violations.",
312 function_name.c_str());
313 fflush(stderr);
314 if (Py_TYPE(m_ptr)->tp_name != nullptr) {
315 fprintf(stderr,
316 "The failing %s call was triggered on a %s object.\n",
317 function_name.c_str(),
318 Py_TYPE(m_ptr)->tp_name);
319 fflush(stderr);
320 }
1. exception_thrown: An exception of type std::runtime_error is thrown.
321 throw std::runtime_error(function_name + " PyGILState_Check() failure.");
322 }
Reproducible example code
No response
Is this a regression? Put the last known working version here if it is.
Not a regression
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pytypes.h at object::operator=(object&&), then trace handle::dec_ref() and throw_gilstate_error() under PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF. The issue provides no reproducible example or test file; done means addressing the Coverity uncaught-exception report without breaking the GIL assertion behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100