classification
Title: ctypes: PyErr_WriteUnraisable() called with no exception set on converting callback result failure
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, vstinner
Priority: normal Keywords: patch

Created on 2020-05-27 14:44 by vstinner, last changed 2020-05-27 23:01 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 20452 merged vstinner, 2020-05-27 15:02
PR 20469 merged miss-islington, 2020-05-27 22:38
PR 20470 merged miss-islington, 2020-05-27 22:38
Messages (4)
msg370089 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-05-27 14:44
Example:
---
from ctypes import c_int, CFUNCTYPE

def func():
    return (1, 2, 3)

cb = CFUNCTYPE(c_int)(func)
cb()
---

Output:
---
Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 262, in 'converting callback result'
TypeError: an integer is required (got type tuple)
Exception ignored in: <function func at 0x7f0c267ff1f0>
---

Assertion error in debug mode:
---
Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 262, in 'converting callback result'
TypeError: 'tuple' object cannot be interpreted as an integer
python: Python/errors.c:1435: _PyErr_WriteUnraisableMsg: Assertion `exc_type != NULL' failed.
Abandon (core dumped)
---

Attached PR fix the issue.
msg370145 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-05-27 22:38
New changeset 10228bad0452d94e66c964b625a0b61befa08e59 by Victor Stinner in branch 'master':
bpo-40795: ctypes calls unraisablehook with an exception (GH-20452)
https://github.com/python/cpython/commit/10228bad0452d94e66c964b625a0b61befa08e59
msg370148 - (view) Author: miss-islington (miss-islington) Date: 2020-05-27 22:56
New changeset 45ce0dbc4f8c68fe22ae97860faa8f2ec7faf27b by Miss Islington (bot) in branch '3.8':
bpo-40795: ctypes calls unraisablehook with an exception (GH-20452)
https://github.com/python/cpython/commit/45ce0dbc4f8c68fe22ae97860faa8f2ec7faf27b
msg370149 - (view) Author: miss-islington (miss-islington) Date: 2020-05-27 23:00
New changeset 9e3c583954f75a6396d1935e000df85d89b78a3d by Miss Islington (bot) in branch '3.9':
bpo-40795: ctypes calls unraisablehook with an exception (GH-20452)
https://github.com/python/cpython/commit/9e3c583954f75a6396d1935e000df85d89b78a3d
History
Date User Action Args
2020-05-27 23:01:28vstinnersetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.8
2020-05-27 23:00:05miss-islingtonsetmessages: + msg370149
2020-05-27 22:56:43miss-islingtonsetmessages: + msg370148
2020-05-27 22:38:39miss-islingtonsetpull_requests: + pull_request19722
2020-05-27 22:38:31miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request19721
2020-05-27 22:38:18vstinnersetmessages: + msg370145
2020-05-27 15:02:00vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request19707
2020-05-27 14:44:18vstinnercreate