Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-107455: ctypes: Improve error messages when converting to an incompatible type #107456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 3, 2023

Conversation

tomasr8
Copy link
Member

@tomasr8 tomasr8 commented Jul 30, 2023

With this code, we get a much more useful error message:

from ctypes import *

printf = CDLL('libc.so.6').printf
printf.argtypes = [c_char_p, c_char_p]
printf(b"Value %s\n", 10)  # call with an incompatible argument
Traceback (most recent call last):
  File "/home/tomas/dev/cpython/error.py", line 5, in <module>
    printf(b"Value: %s\n", 10)
ctypes.ArgumentError: argument 2: TypeError: 'int' object cannot be interpreted as ctypes.c_char_p

Compared to the old one:

ctypes.ArgumentError: argument 2: TypeError: wrong type

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Arch Linux TraceRefs 3.x has failed when building commit 62a3a15.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/484/builds/3783) and take a look at the build logs.
  4. Check if the failure is related to this commit (62a3a15) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/484/builds/3783

Failed tests:

  • test_capi

Summary of the results of the build (if available):

==

Click to see traceback logs
remote: Enumerating objects: 26, done.        
remote: Counting objects:   3% (1/26)        
remote: Counting objects:   7% (2/26)        
remote: Counting objects:  11% (3/26)        
remote: Counting objects:  15% (4/26)        
remote: Counting objects:  19% (5/26)        
remote: Counting objects:  23% (6/26)        
remote: Counting objects:  26% (7/26)        
remote: Counting objects:  30% (8/26)        
remote: Counting objects:  34% (9/26)        
remote: Counting objects:  38% (10/26)        
remote: Counting objects:  42% (11/26)        
remote: Counting objects:  46% (12/26)        
remote: Counting objects:  50% (13/26)        
remote: Counting objects:  53% (14/26)        
remote: Counting objects:  57% (15/26)        
remote: Counting objects:  61% (16/26)        
remote: Counting objects:  65% (17/26)        
remote: Counting objects:  69% (18/26)        
remote: Counting objects:  73% (19/26)        
remote: Counting objects:  76% (20/26)        
remote: Counting objects:  80% (21/26)        
remote: Counting objects:  84% (22/26)        
remote: Counting objects:  88% (23/26)        
remote: Counting objects:  92% (24/26)        
remote: Counting objects:  96% (25/26)        
remote: Counting objects: 100% (26/26)        
remote: Counting objects: 100% (26/26), done.        
remote: Compressing objects:   7% (1/13)        
remote: Compressing objects:  15% (2/13)        
remote: Compressing objects:  23% (3/13)        
remote: Compressing objects:  30% (4/13)        
remote: Compressing objects:  38% (5/13)        
remote: Compressing objects:  46% (6/13)        
remote: Compressing objects:  53% (7/13)        
remote: Compressing objects:  61% (8/13)        
remote: Compressing objects:  69% (9/13)        
remote: Compressing objects:  76% (10/13)        
remote: Compressing objects:  84% (11/13)        
remote: Compressing objects:  92% (12/13)        
remote: Compressing objects: 100% (13/13)        
remote: Compressing objects: 100% (13/13), done.        
remote: Total 14 (delta 12), reused 3 (delta 1), pack-reused 0        
From https://github.com/python/cpython
 * branch                  main       -> FETCH_HEAD
Note: switching to '62a3a15119cf16d216a2cc7dc10d97143017ef62'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 62a3a15119 gh-107455: ctypes: Improve error messages when converting to an incompatible type (#107456)
Switched to and reset branch 'main'

Objects/object.c:2235: _Py_ForgetReference: Assertion failed: invalid object chain
Enable tracemalloc to get the memory block allocation traceback

object address  : 0x7f67408c9a80
object refcount : 0
object type     : 0x5586443e3980
object type name: float
object repr     : <refcnt 0 at 0x7f67408c9a80>

Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed
Python runtime state: initialized

Thread 0x00007f6748a126c0 (most recent call first):
  File "<string>", line 8 in wait
  File "/buildbot/buildarea/3.x.pablogsal-arch-x86_64/build/Lib/threading.py", line 989 in run
  File "/buildbot/buildarea/3.x.pablogsal-arch-x86_64/build/Lib/threading.py", line 1052 in _bootstrap_inner
  File "/buildbot/buildarea/3.x.pablogsal-arch-x86_64/build/Lib/threading.py", line 1009 in _bootstrap

Current thread 0x00007f674a0d6740 (most recent call first):
  File "<string>", line 18 in <module>

Extension modules: _testinternalcapi (total: 1)
Debug memory block at address p=0x7f6749ffde30: API '�'
    18302063728033390045 bytes originally requested
    The 7 pad bytes at p-7 are not all FORBIDDENBYTE (0xfd):
        at p-7: 0xdd *** OUCH
        at p-6: 0xdd *** OUCH
        at p-5: 0xdd *** OUCH
        at p-4: 0xdd *** OUCH
        at p-3: 0xdd *** OUCH
        at p-2: 0xdd *** OUCH
        at p-1: 0xdd *** OUCH
    Because memory is corrupted at the start, the count of bytes requested
       may be bogus, and checking the trailing pad bytes may segfault.
    The 8 pad bytes at tail=0xfdfe7d6547fdbc0d are Fatal Python error: Segmentation fault

Thread 0x00007f6748a126c0 (most recent call first):
  File "<string>", line 8 in wait
  File "/buildbot/buildarea/3.x.pablogsal-arch-x86_64/build/Lib/threading.py", line 989 in run
  File "/buildbot/buildarea/3.x.pablogsal-arch-x86_64/build/Lib/threading.py", line 1052 in _bootstrap_inner
  File "/buildbot/buildarea/3.x.pablogsal-arch-x86_64/build/Lib/threading.py", line 1009 in _bootstrap

Current thread 0x00007f674a0d6740 (most recent call first):
  File "<string>", line 18 in <module>

Extension modules: _testcapi, _testmultiphase, _testsinglephase, _xxsubinterpreters, _testinternalcapi (total: 5)
make: *** [Makefile:2021: buildbottest] Segmentation fault (core dumped)

Cannot open file '/buildbot/buildarea/3.x.pablogsal-arch-x86_64/build/test-results.xml' for upload

@tomasr8 tomasr8 deleted the ctypes-error-msg branch August 3, 2023 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants