Issue 28259: Ctypes bug windows (original) (raw)

Created on 2016-09-23 16:25 by PlatonAdCo, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
toxygen_video_test.zip PlatonAdCo,2016-10-25 18:01
Messages (14)
msg277286 - (view) Author: Aristotel (PlatonAdCo) Date: 2016-09-23 16:25
I'm wrapping C function using ctypes. Function has following prototype: bool func(some_struct* pointer, uint32_t a, uint16_t b, uint16_t c, const uint8_t *d, const uint8_t *e, const uint8_t *f, some_enum *e); I tried a lot of variants of wrapper but on windows I always have "access violation reading 0x00000000" in console. On Linux everything works fine. I tested it with different versions of Python, it presents at least in 3.3 - 3.5. I think bug is in passing uint8_t *d, uint8_t *e, uint8_t *f, because wrapper for almost the same function with 1 pointer instead of 3 works as expected.
msg277760 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2016-09-30 16:35
Are you using 64-bit? There was an issue passing structs a while back, but I don't recall when or if we've merged the patch.
msg277762 - (view) Author: Aristotel (PlatonAdCo) Date: 2016-09-30 17:14
I use 32-bit python on 64-bit windows
msg277787 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2016-10-01 01:23
You keep removing the Windows component - is this not actually a bug on Windows?
msg277806 - (view) Author: Aristotel (PlatonAdCo) Date: 2016-10-01 10:44
Oh it's ctypes bug on windows only
msg277957 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-10-03 13:25
Since this is 32-bit, are you using CDLL (cdecl) or WinDLL (stdcall)? Either way, I made a simple test for the given function prototype, and it worked fine in 32-bit 3.5.2 on Windows 10 for both calling conventions. You'll have to provide a minimal example that reproduces the problem.
msg277990 - (view) Author: Aristotel (PlatonAdCo) Date: 2016-10-03 18:52
CDLL. I didn't test it on Python 3.5.2, 3.3 - 3.4 only. And btw my OS is windows 7. Lib is also used by some apps (not Python apps) and there this function works well.
msg277998 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-10-03 19:47
If you want a resolution to this issue, then you need to provide a minimal example that reproduces the problem. It would also be helpful if you could provide a download link for the library that you're wrapping. If not, at least upload a dump file, preferably from 3.5 since 3.4 is no longer actively maintained.
msg278061 - (view) Author: Aristotel (PlatonAdCo) Date: 2016-10-04 17:09
Unfortunately in my case "minimal" example is extremely long. Do you really need it&
msg278122 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2016-10-05 13:13
Ultimately we need something to put in the test suite to make sure it's fixed and doesn't regress in the future. It's asking a lot of our volunteers to investigate a bug on very little information.
msg278143 - (view) Author: Aristotel (PlatonAdCo) Date: 2016-10-05 18:13
I will write (as short as possible) example. Hope to finish it in ~ 1 week.
msg279434 - (view) Author: Aristotel (PlatonAdCo) Date: 2016-10-25 18:01
Sorry for delay. I tried to write as small as possible example. Sorry if it is too big Usage: run 2 consoles, cd to dir with sources. In first console type 'python3 main.py test1.tox', and in second type 'python3 main.py test2.tox'. Wait 1-2 min until apps connect and you will see a lot of "access violation reading 0x0000" when consoles start video call. sometimes apps crashes too. crashes fine on both win 7 an win 8 for me
msg279715 - (view) Author: Aristotel (PlatonAdCo) Date: 2016-10-30 09:40
Any update on this? It blocks development of my project.
msg388162 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-03-05 20:49
I didn't have time to look deeper into this. I'm sorry for not getting back to you. The rather-large example that you uploaded didn't and doesn't run for me, so I wasn't able to reproduce the problem. The one bit of advice I have is to always declare required argument types in the `argtypes` attribute of ctypes functions. It can be very useful to take advantage of the type checking that ctypes provides in order to catch problems before they lead to stack or heap corruption, or bad values that lead to corruption later on. I'm closing this issue as not a bug. ctypes and libffi have been used in a broad range of cases in 32-bit Windows for many years, and I wasn't able to reproduce the problem with a function of the given call signature when I checked in 2016.
History
Date User Action Args
2022-04-11 14:58:37 admin set github: 72446
2021-03-05 20:49:15 eryksun set status: open -> closedresolution: not a bugmessages: + stage: test needed -> resolved
2016-10-30 09:40:56 PlatonAdCo set messages: +
2016-10-25 18:01:41 PlatonAdCo set files: + toxygen_video_test.zipmessages: +
2016-10-05 18:13:11 PlatonAdCo set messages: +
2016-10-05 13:13:20 steve.dower set messages: + stage: test needed
2016-10-04 17:09:31 PlatonAdCo set messages: + versions: + Python 3.5
2016-10-03 19:47:11 eryksun set messages: + versions: - Python 3.5
2016-10-03 18:52:51 PlatonAdCo set messages: +
2016-10-03 13:25:06 eryksun set nosy: + eryksunmessages: +
2016-10-01 10:44:39 PlatonAdCo set messages: +
2016-10-01 10:43:12 PlatonAdCo set components: + Windows, - ctypes
2016-10-01 01:23:40 steve.dower set messages: +
2016-09-30 17:14:23 PlatonAdCo set messages: + components: - Windows
2016-09-30 16:35:50 steve.dower set nosy: + paul.moore, tim.golden, zach.ware, steve.dowermessages: + components: + Windows
2016-09-23 16:25:46 PlatonAdCo create